Details

    • Type: Sub-task
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.6.0-alpha-1
    • Component/s: None
    • Labels:
      None

      Description

      Potential cases to consider.

      Known to pass with the current grammar:

      // method receiver parameters (works with existing grammar)
      void tempCalc(@ReadOnly Weather this){ ... }
      
      // on arrays
      // Annotating the int type:
      @ReadOnly int [] nums;
      

      Fail with `unexpected token: @ at line: xx, column: yy`:

      // constructor usage
      Forecast currentForecast = new @Interned Forecast()
      
      // type casts
      Object myObject = (@NotNull Object) obj
      
      // exception in catch block
      catch (@Critical Exception e) { ... }
      
      // on arrays
      // Annotating the array type int[]:
      int @ReadOnly [] nums
      // Annotating the array type int[][]:
      int @ReadOnly [][] nums
      // Annotating the type int[], which is a component type of int[][]:
      int [] @ReadOnly [] nums
      

      Fail with `unexpected token: < at line: xx, column: yy`:

      // generics
      List<@NonNull Integer> nums = []
      List<? extends @NonNull File> fileList = null
      

      Fail with 'expecting an identifier, found '@' at line: xx, column: yy':

      // inheritance
      class MyForecast<T> implements @NonEmpty List<T>
      

      Fails with 'unexpected token: throws at line: xx, column: yy':

      // exception in method declaration
      def foo() throws @NonNull Exception { }
      

      Adapted mostly from: http://www.oracle.com/technetwork/articles/java/ma14-architect-annotations-2177655.html

        Activity

        Hide
        daniel_sun Daniel Sun added a comment -
        Show
        daniel_sun Daniel Sun added a comment - Another nice article on JSR308: https://dzone.com/articles/java-8-type-annotations
        Hide
        daniel_sun Daniel Sun added a comment -
        Show
        daniel_sun Daniel Sun added a comment - Support JSR308 partly(TODO support array types): https://github.com/danielsun1106/groovy-parser/commit/2883b80523508025ad1f5574610802540465f571
        Hide
        daniel_sun Daniel Sun added a comment - - edited
        Show
        daniel_sun Daniel Sun added a comment - - edited Refined the test: https://github.com/danielsun1106/groovy-parser/blob/jsr308/src/test/resources/bugs/GROOVY-8228.groovy Note: the test is executable, not just parsable
        Hide
        daniel_sun Daniel Sun added a comment - - edited

        Strongly recommend the article, which is actually a specification in detail: https://checkerframework.org/jsr308/specification/java-annotation-design.html

        Show
        daniel_sun Daniel Sun added a comment - - edited Strongly recommend the article, which is actually a specification in detail: https://checkerframework.org/jsr308/specification/java-annotation-design.html
        Hide
        paulk Paul King added a comment -

        Yes, that article looks good!

        Show
        paulk Paul King added a comment - Yes, that article looks good!
        Hide
        daniel_sun Daniel Sun added a comment -

        Annotated array type is supported now:

        String @JSR308 [] @JSR308 [] strs2 = new String[][] { new String[] {'a', 'b'} }
        

        but I'm not sure whether the following code is valid:

        String @JSR308 [] @JSR308 [] strs2 = new String @JSR308 [] @JSR308 [] { new String[] {'a', 'b'} }
        
        Show
        daniel_sun Daniel Sun added a comment - Annotated array type is supported now: String @JSR308 [] @JSR308 [] strs2 = new String [][] { new String [] {'a', 'b'} } but I'm not sure whether the following code is valid: String @JSR308 [] @JSR308 [] strs2 = new String @JSR308 [] @JSR308 [] { new String [] {'a', 'b'} }
        Hide
        daniel_sun Daniel Sun added a comment -

        The following code is valid:

        @Readonly Document [][] docs1 = new @Readonly Document [2][12]; // array of arrays of read-only documents
        Document @Readonly [][] docs2 = new Document @Readonly [2][12]; // read-only array of arrays of documents
        Document[] @Readonly [] docs3 = new Document[2] @Readonly [12]; // array of read-only arrays of documents
        
        Show
        daniel_sun Daniel Sun added a comment - The following code is valid: @Readonly Document [][] docs1 = new @Readonly Document [2][12]; // array of arrays of read-only documents Document @Readonly [][] docs2 = new Document @Readonly [2][12]; // read-only array of arrays of documents Document[] @Readonly [] docs3 = new Document[2] @Readonly [12]; // array of read-only arrays of documents
        Hide
        paulk Paul King added a comment -

        Just clarifying. When you say "is valid" are you meaning now working in experimental branch? Or did you mean valid in Java?

        Show
        paulk Paul King added a comment - Just clarifying. When you say "is valid" are you meaning now working in experimental branch? Or did you mean valid in Java?
        Hide
        daniel_sun Daniel Sun added a comment -

        I mean it is valid in Java.

        Show
        daniel_sun Daniel Sun added a comment - I mean it is valid in Java.
        Hide
        daniel_sun Daniel Sun added a comment -

        Paul, I created a new branch jsr on apache/groovy fork.
        You can find it at https://github.com/apache/groovy/tree/jsr308

        Show
        daniel_sun Daniel Sun added a comment - Paul, I created a new branch jsr on apache/groovy fork. You can find it at https://github.com/apache/groovy/tree/jsr308
        Hide
        daniel_sun Daniel Sun added a comment -

        The cases describled in the issue have been supported:
        https://github.com/apache/groovy/commit/bc2f4eb50a56b2d1a336734448f145f629fe4ab8

        Show
        daniel_sun Daniel Sun added a comment - The cases describled in the issue have been supported: https://github.com/apache/groovy/commit/bc2f4eb50a56b2d1a336734448f145f629fe4ab8
        Show
        daniel_sun Daniel Sun added a comment - Same code, different result travis-ci succeeds: https://travis-ci.org/apache/groovy/builds/262506189 teamcity fails: http://ci.groovy-lang.org/viewLog.html?buildId=41265&tab=buildResultsDiv&buildTypeId=Groovy_Jdk8Build_PlusSnapshotDeploy http://ci.groovy-lang.org/viewLog.html?buildId=41260&tab=buildResultsDiv&buildTypeId=Groovy_Jdk8Build_PlusSnapshotDeploy http://ci.groovy-lang.org/viewLog.html?buildId=41257&tab=buildResultsDiv&buildTypeId=Groovy_Jdk8Build_PlusSnapshotDeploy I guess the difference is related to the version of JDK8 deployed(Maybe it is a bug of Java8)

          People

          • Assignee:
            daniel_sun Daniel Sun
            Reporter:
            paulk Paul King
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development