eclipse-jdt / eclipse.jdt.core

Eclipse Public License 2.0
161 stars 129 forks source link

missing pieces in the AST: parser seems to skip broken annotation altogether when on method parameters #3155

Open martinlippert opened 3 hours ago

martinlippert commented 3 hours ago

I am parsing (somewhat broken) Java source code using the ASTParser and came across several situations in which the parser seems to not include information about the parsed code anymore.

The concrete case here is this constructor (for example):

public TestDependsOnClass(@Qualifier(value= ) Object mybean) {
}

In this case, the value for the attribute value behind the = is missing from the source code. As a result, the annotation gets removed from the AST altogether. The MethodDeclaration node in the parsed AST looks like this:

public TestDependsOnClass() {
}

Since I would like to implement some code completion based on the parsed AST, I somewhat depend some information being still around for the annotation.

This seems to happen for annotations on method parameters only. The same broken annotation code on a type declaration results in a DOM that got a $missing$ node inserted nicely:

@Qualifier(value=$missing$)

(@mickaelistria, this is one of the cases that we talked about)

mickaelistria commented 2 hours ago

Using Javac parser and the converter from https://github.com/eclipse-jdtls/eclipse-jdt-core-incubator/tree/dom-with-javac , the annotation seems to remain:

{CompilationUnit: /eclipsecon-demo-jdt-with-javac/src/main/java/snippet/Snippet.java=package snippet;
public class Snippet {
  public void TestDependsOnClass(  @Qualifier(value=$missing$) Object mybean){
  }
}
}