Extract method doesn't generate proper signature when return type is XXX.YYY where XXX is not in the class you are refactoring

Issue #1983 resolved
Eric Kintzer created an issue

This could be by design but I found it counterintuitive

Given this code fragment in class Foo

protected PatientsService.GenomicPatientRequest getGenomicPatientRequest() {
            PatientsService.GenomicPatientRequest request = new PatientsService.GenomicPatientRequest();
            for (Asset recollectableAsset: this.dropshipRecollectAssets) {
                request.withRequestKey(new PatientsService.GenomicPatientRequestKey()
                    .withSourceId(recollectableAsset.Product2.Kit_Partner_Id__c)
                    .withUserId(recollectableAsset.UserId__c));
            }
            return request;
        }

If I refactor (Extract Method) the expression:

new PatientsService.GenomicPatientRequestKey()
        .withSourceId(recollectableAsset.Product2.Kit_Partner_Id__c)
        .withUserId(recollectableAsset.UserId__c)

The dialog shows the proper return type as PatientsService.GenomicPatientRequestKey but the emitted code omits the top level class PatientsService and generates this (omitting the top level class name PatientsService as part of the return type):

private GenomicPatientRequestKey getGenomicPatientRequestKey(Asset recollectableAsset) {
            return new PatientsService.GenomicPatientRequestKey()
                .withSourceId(recollectableAsset.Product2.Kit_Partner_Id__c)
                .withUserId(recollectableAsset.UserId__c);
        }

Comments (5)

  1. Scott Wells repo owner

    Hmmmm...it should only omit the top-level class portion if the inner class is accessible by that name from the point of insertion, i.e., either in the same top-level class or in a subclass where the inner class is visible. Sounds like that's not the case here, though, no? Assuming it's not, hopefully this will be easy to reproduce and fix.

  2. Eric Kintzer reporter

    The point of insertion is in an inner class Foo.Bar, the referenced return type is an inner class in a separate outer class PatientsService.cls

  3. Scott Wells repo owner

    Yeah, that would be a bug. Let me play with it a bit and see why it's not using the fully-qualified name from that point of insertion.

  4. Scott Wells repo owner

    Easily reproduced. Fix committed for inclusion in the next build. Currently planning on releasing tomorrow morning, but if that doesn't happen for some reason, it'll push to next Monday due to a Thursday-Sunday outage this week.

  5. Log in to comment