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

FASTJava importer fails on Annotated methods #115

Open
NicolasAnquetil opened this issue Oct 26, 2023 · 4 comments · Fixed by #116
Open

FASTJava importer fails on Annotated methods #115

NicolasAnquetil opened this issue Oct 26, 2023 · 4 comments · Fixed by #116
Labels

Comments

@NicolasAnquetil
Copy link
Contributor

visit method calls #expression

visitAnnotation: anAnnotation
	self create: FASTJavaAnnotation from: anAnnotation.
	currentFASTEntity expression: (self clone accept: anAnnotation name).

but anAnnotation name is not an expression

@NicolasAnquetil
Copy link
Contributor Author

The FASTJavaAnnotation class should be redesign.
May be inspired on FamixJavaAnnotation ?

@Gabriel-Darbord
Copy link
Member

Gabriel-Darbord commented Oct 26, 2023

I don't see this method failing when I try it, even with multiple annotations, when executing something like:

JavaSmaCCProgramNodeImporterVisitor parseCodeMethodString: '@MyAnnotation int f() { }'.

anAnnotation name is a JavaNameNode, but self clone accept: anAnnotation name gives a FASTJavaVariableExpression, resulting in:

FASTJavaAnnotation new
  expression: (FASTJavaVariableExpression new name: 'MyAnnotation')

However, I think it should be similar to a class-type expression:

JavaSmaCCProgramNodeImporterVisitor parseCodeMethodString: 'Class f() { return MyClass.class; }'.

Where the MyClass token gives:

FASTJavaClassTypeExpression new
  typeName: (FASTJavaTypeName new name: 'MyClass')

This is even necessary to correctly represent the annotation name being fully qualified.
Parsing @com.MyAnnotation int f() { } incorrectly gives a class property of the com type:

FASTJavaAnnotation new
  expression: (FASTJavaClassProperty new
    type: (FASTJavaVariableExpression new name: 'com');
    fieldName: 'MyAnnotation')

While parsing Class f() { return com.MyClass.class; } handles it correctly and gives a qualified name:

FASTJavaClassTypeExpression new
  typeName: (FASTJavaQualifiedTypeName new
    namespace: (FASTJavaTypeName new name: 'com');
    name: 'MyClass')

@Gabriel-Darbord
Copy link
Member

Gabriel-Darbord commented Oct 26, 2023

Now parsing @com.MyAnnotation int f() { } completely ignores the com. part.

FASTJavaAnnotation new name: 'MyAnnotation'

@Gabriel-Darbord
Copy link
Member

Gabriel-Darbord commented Oct 27, 2023

Also the parser fails when the argument is an array literal:

@Tags({"Java", "Annotations", "Testing"}) // slot 'argumentOwner' not found
public class AnnotatedClass { }

Also failing when an interface is annotated:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface MyMethodAnnotation { }

And the annotation is ignored when it is on a parameter:

int f(@Tag int foo) { }

Ideally, even this extreme case should be parsable:

@interface MyAnnotations {
	I[] value();
}

@java.lang.annotation.Repeatable(MyAnnotations.class)
@interface I {
}

@I
public @I class WeirdStuff<@I T extends @I Number & @I Comparable<@I ? super @I T> & java.io.@I Serializable> {
	@I
	java.util.@I @I ArrayList<@I ? extends @I T> mylist;

	@I
	public @I int @I [] myMethod(fr.WeirdStuff<@I T> this, @I java.util.@I ArrayList<java.lang.@I String> mylist) @I [] {
		@I int i @I [] = new @I int @I ['a'];
		return new @I int @I [] @I [] { { 1, 2, 3 }, i, };
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants