Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
martinlippert opened this issue Oct 24, 2024 · 4 comments · Fixed by #3159
Assignees
Milestone

Comments

@martinlippert
Copy link

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
Copy link
Contributor

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){
  }
}
}

stephan-herrmann added a commit to stephan-herrmann/eclipse.jdt.core that referenced this issue Oct 25, 2024
altogether when on method parameters

recover incomplete annotation on argument

fixes eclipse-jdt#3155
@stephan-herrmann
Copy link
Contributor

This looks like another iteration of https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 (2006-2008) :)

@stephan-herrmann
Copy link
Contributor

Thanks @martinlippert this was a good one :)

@stephan-herrmann stephan-herrmann added this to the 4.34 M3 milestone Oct 25, 2024
@stephan-herrmann stephan-herrmann self-assigned this Oct 25, 2024
@martinlippert
Copy link
Author

Wow, that was quick! So many thanks @stephan-herrmann, very much appreciated!!!

stephan-herrmann added a commit that referenced this issue Oct 25, 2024
…ue when there is a . at the end (#3161)

detect the situation during Parser.consumeZeroTypeAnnotations() (similar to #3155) and recover accordingly in RecoveredAnnotation.updateFromParserState()

fixes #3156
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants