Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 313808

Summary: "Organize Imports" on inter-type constructor declaration with this() in body complains "Compilation unit has parse errors"
Product: [Tools] AJDT Reporter: Thomas Wieger <thomas.wieger>
Component: UIAssignee: AJDT-inbox <AJDT-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: andrew.eisenberg
Version: 2.0.2   
Target Milestone: 2.1.0   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Attachments:
Description Flags
mini project with problematic inter-type constructor declaration none

Description Thomas Wieger CLA 2010-05-20 16:14:58 EDT
Created attachment 169412 [details]
mini project with problematic inter-type constructor declaration

i have an aspect with an inter-type declaration, which looks like this:

package de.wieger.sample;

public aspect Person_ITD {
    public Person.new() {
        this();
        // intentionally left blank
    }
}


When i invoke "Organize Imports" in eclipse, i get the following error:
"Compilation unit has parse errors: Constructor call must be the first statement in a constructor".

From my prospective, it seems like the method AjOrganizeImportsOperation#collectReferences is a little bit too strict about what should be considered as a relevant parsing error.

I have seen, that AjCompilationUnitProblemFinder#isARealProblem filters out a lot of problems like the one causing trouble when invoking "organize imports". The method conains an explicit snippet, dealing with the problematic syntactic construct:

if (numArgs == 0 && id == IProblem.InvalidExplicitConstructorCall) {
    // ITD constructor making explicit this() call.
    // lots of potential for false negatives
    return false;
}

Maybe this could indicate the direction for a fix?

I have attached an archive with a mini project containing the source code, which demonstrates the problem when invoking "organize imports" on the inter-type declaration.

regards,

Thomas Wieger
Comment 1 Andrew Eisenberg CLA 2010-05-20 19:51:36 EDT
Fix is available in the latest dev build.  Thanks for the sample project.
Comment 2 Andrew Eisenberg CLA 2010-05-20 19:51:57 EDT
fixed.