Provide instrumentation support for Annotations in all places Java 8 allows to

XMLWordPrintable

      Provide support for instrumentation of annotations in all places where Java 8 allows developer put them. E.g annotation on types or in different parts of method declaration.

      Please note that javac compiler itself does not understand such annotations - it's up to annotation processors to handle them correctly.

      However, as Clover does perform instrumentation "offline" (i.e. not inside the javac process), we must at least allow these annotations to be present (i.e. do not throw parse exceptions); Clover does not need to understand them, however.

          void some (@RequestBody(required = false) String @Nullable [] arguments) { }
      
          static @interface Readonly { }
      
          static @interface NonNull { }
      
          static @interface NonEmpty { }
      
          // annotations for method receivers
          public int size() @Readonly {
              return 0;
          }
      
          // annotations inside generic type arguments
          Map<@NonNull String, @NonEmpty List<@Readonly Document>> files;
      
          // annotations inside arrays
          // docs1 is an unmodifiable one-dimensional array of mutable Documents
          Document[@Readonly] docs1;
          // docs2 is a mutable array whose elements are unmodifiable one-dimensional arrays of mutable Documents
          Document[][@Readonly] docs2 = new Document[2][@Readonly 12];
      
          public void annotationInTypeCast(Object myObject) {
              String myString;
              // annotation in typecast
              myString = (@NonNull String)myObject;
          }
      
          public void annotationInInstanceOf(Object myString) {
              // type tests
              boolean isNonNull = myString instanceof @NonNull String;
          }
      
          public void annotationInObjectCreation() {
              Set myNonEmptyStringSet = new HashSet();
              // object creation
              new @Readonly @NonEmpty ArrayList(myNonEmptyStringSet);
          }
      
      
          //type parameter bounds:
          //class Folder { ... }
          // t.b.d.
      
          // class inheritance
          abstract class UnmodifiableList<T> implements @Readonly List<@Readonly T> { }
      
          // throws clauses
          class TemperatureException extends Exception { }
          @interface Critical { }S
          void monitorTemperature() throws @Critical TemperatureException {
              throw new TemperatureException();
          }
      

      Scope:

      Extend ANTLR grammar (java.g) to handle these constructs

      • method return values, thrown exceptions
      • generic types, including upper and lower bounds, wildcards
      • nested classes
      • arrays and varargs
      • type casting and instanceof
      • "new" keyword - constructors, including nested and generic ones
      • generic methods
      • class/interface inheritance
      • method and constructor references

       

      Out of scope:

      • explicit "this" receiver (if required to handle) - tracked in CLOV-1934

            Assignee:
            Unassigned
            Reporter:
            Grzegorz Lewandowski
            Votes:
            4 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: