Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Class body of annotation class is not correctly parsed #182

Open

Description

@felixhao28

Description

In the class body of an annotation class, parameters are not parsed as a method/field/parameter declaration as it should be. This results in scope errors like mistaking wildcard generic parameter as ternary conditional operator.

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.METHOD })
@Documented
public @interface EventListener {
    Class<?>[] events() default {};
    int order() default Integer.MAX_VALUE;
    boolean async() default false;
    String condition() default "";
}

class A {
    Class<?>[] events() {
        
    }
    int order() {
        
    }
    boolean async() {
        
    }
    String condition() {
        
    }
}

image

image

Expected behavior: [What you expect to happen]

Both events should be parsed as some kind of declaration. But it is actually parsed as "method-call" in annotation, along with other errors like "?".

Versions

d48e713

Activity

  1. sadikovi commented on Dec 5, 2018

    @sadikovi
    Contributor

    It does work correctly. We just don't support the following syntax:

    public @interface EventListener {
      ...
    }

    I don't think it is correct to mark interface as @interface in Java.
    Is this new feature in JDK to have interface to be prefixed with @?

  2. felixhao28 commented on Dec 6, 2018

    @felixhao28
    Author

    This syntax is used to create a custom annotation class.

    Here is a quick tutorial: https://www.javatpoint.com/custom-annotation

    For the official Java language specification, please take look at this: https://docs.oracle.com/javase/specs/jls/se8/html/jls-9.html#jls-9.6.1

  3. sadikovi commented on Dec 6, 2018

    @sadikovi
    Contributor

    I see. It looks like we support these annotation declarations, but the code does not explicitly handle this case that you mentioned. I will try reworking that in the next couple of days.

  4. self-assigned this
    on Dec 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions