New posts
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
-- retention: annotations reflection can see on Base
|
||||
[@com.ankurm.demo.annotations.Tracked(priority=5, value="", level=NORMAL, tags={})]
|
||||
-- members and defaults
|
||||
default value="" priority=5 level=NORMAL tags=[]
|
||||
explicit value="billing" priority=9 level=HIGH tags=[pci, money]
|
||||
-- @Inherited: Child extends Base, Child itself has no annotations
|
||||
getAnnotation(Tracked) = true
|
||||
getDeclaredAnnotation(Tracked) = false
|
||||
-- @Repeatable
|
||||
Staff direct getAnnotations().length = 1 (Roles container)
|
||||
Staff getAnnotationsByType(Role) = [admin, auditor]
|
||||
Solo getAnnotation(Role) != null = true
|
||||
Solo getAnnotation(Roles) != null = false
|
||||
Solo getAnnotationsByType(Role) = [admin]
|
||||
@@ -0,0 +1,2 @@
|
||||
[]
|
||||
[email: must not be blank, name: name is required]
|
||||
@@ -0,0 +1,6 @@
|
||||
javap -v -p -cp demo/target/classes com.ankurm.demo.RetentionDemo$Base (filtered)
|
||||
RuntimeVisibleAnnotations:
|
||||
com.ankurm.demo.annotations.Tracked
|
||||
RuntimeInvisibleAnnotations:
|
||||
com.ankurm.demo.annotations.ClassOnly
|
||||
occurrences of SourceOnly in the class file: 0
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.ankurm.demo;
|
||||
|
||||
// Generated by com.ankurm.builder.BuilderProcessor - do not edit.
|
||||
public final class PersonBuilder {
|
||||
|
||||
private java.lang.String name;
|
||||
private int age;
|
||||
private java.util.List<java.lang.String> nicknames;
|
||||
|
||||
public PersonBuilder name(java.lang.String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PersonBuilder age(int age) {
|
||||
this.age = age;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PersonBuilder nicknames(java.util.List<java.lang.String> nicknames) {
|
||||
this.nicknames = nicknames;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PersonBuilder addToNicknames(java.lang.String element) {
|
||||
java.util.List<java.lang.String> copy = this.nicknames == null ? new java.util.ArrayList<>() : new java.util.ArrayList<>(this.nicknames);
|
||||
copy.add(element);
|
||||
this.nicknames = copy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public com.ankurm.demo.Person build() {
|
||||
return new com.ankurm.demo.Person(name, age, nicknames);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
Person[name=Asha, age=34, nicknames=[Ash, A]]
|
||||
Pizza[size=large, extraCheese=true, toppings=[olives]]
|
||||
Person[name=null, age=0, nicknames=null]
|
||||
@@ -0,0 +1,6 @@
|
||||
$ javac -processorpath processor/target/classes -d <tmp> bad/Shape.java
|
||||
bad/Shape.java:5: error: @GenerateBuilder can only be applied to a class or a record, not to interface
|
||||
public interface Shape {
|
||||
^
|
||||
1 error
|
||||
exit=1
|
||||
@@ -0,0 +1,30 @@
|
||||
$ javac -version
|
||||
javac 25.0.5
|
||||
|
||||
$ javac -cp processor/target/classes -d <tmp> Person.java Pizza.java BuilderUsageDemo.java
|
||||
demo/src/main/java/com/ankurm/demo/BuilderUsageDemo.java:6: error: cannot find symbol
|
||||
Person p = new PersonBuilder()
|
||||
^
|
||||
symbol: class PersonBuilder
|
||||
location: class BuilderUsageDemo
|
||||
demo/src/main/java/com/ankurm/demo/BuilderUsageDemo.java:14: error: cannot find symbol
|
||||
Pizza pizza = new PizzaMaker()
|
||||
^
|
||||
symbol: class PizzaMaker
|
||||
location: class BuilderUsageDemo
|
||||
demo/src/main/java/com/ankurm/demo/BuilderUsageDemo.java:22: error: cannot find symbol
|
||||
System.out.println(new PersonBuilder().build());
|
||||
^
|
||||
symbol: class PersonBuilder
|
||||
location: class BuilderUsageDemo
|
||||
3 errors
|
||||
exit=1
|
||||
|
||||
$ javac -Xlint:all -cp processor/target/classes -d <tmp> Person.java
|
||||
exit=0 (no output at all: nothing warned that a processor was skipped)
|
||||
|
||||
$ javac -cp processor/target/classes -proc:full -d <tmp> Person.java Pizza.java BuilderUsageDemo.java
|
||||
exit=0
|
||||
|
||||
$ javac -cp processor/target/classes -processorpath processor/target/classes -d <tmp> Person.java Pizza.java BuilderUsageDemo.java
|
||||
exit=0
|
||||
@@ -0,0 +1,13 @@
|
||||
$ mvn -B clean compile -Pclasspath-only # no annotationProcessorPaths
|
||||
[INFO] Compiling 2 source files with javac [debug release 25] to target/classes
|
||||
[INFO] Compiling 12 source files with javac [debug release 25] to target/classes
|
||||
[ERROR] COMPILATION ERROR :
|
||||
[ERROR] demo/src/main/java/com/ankurm/demo/BuilderUsageDemo.java:[6,24] cannot find symbol
|
||||
[ERROR] demo/src/main/java/com/ankurm/demo/BuilderUsageDemo.java:[14,27] cannot find symbol
|
||||
[ERROR] demo/src/main/java/com/ankurm/demo/BuilderUsageDemo.java:[22,32] cannot find symbol
|
||||
[INFO] BUILD FAILURE
|
||||
|
||||
$ mvn -B clean compile -Pclasspath-proc-full # same, plus <proc>full</proc>
|
||||
[INFO] Compiling 2 source files with javac [debug release 25] to target/classes
|
||||
[INFO] Compiling 12 source files with javac [debug release 25] to target/classes
|
||||
[INFO] BUILD SUCCESS
|
||||
@@ -0,0 +1,26 @@
|
||||
== 1. in-memory compile: Person + Main, BuilderProcessor supplied directly
|
||||
success=true generated=[com.acme.PersonBuilder]
|
||||
classes=[com.acme.Main, com.acme.Person, com.acme.PersonBuilder]
|
||||
|
||||
== 2. error cases: javac diagnostics produced via Messager
|
||||
interface -> ERROR /com/acme/Shape.java:4: @GenerateBuilder can only be applied to a class or a record, not to interface
|
||||
abstract class -> ERROR /com/acme/Animal.java:4: @GenerateBuilder cannot be applied to abstract class Animal
|
||||
two constructors -> ERROR /com/acme/Point.java:4: Point must have exactly one non-private constructor, but has 2
|
||||
generic class -> ERROR /com/acme/Box.java:4: @GenerateBuilder does not support generic types such as Box
|
||||
|
||||
== 3. rounds, with -Abuilder.debug=true
|
||||
builder round 1: annotations=[com.ankurm.builder.GenerateBuilder] roots=[com.acme.Person] processingOver=false
|
||||
builder round 2: annotations=[] roots=[com.acme.PersonBuilder] processingOver=false
|
||||
builder round 3: annotations=[] roots=[] processingOver=true
|
||||
|
||||
== 4. no setProcessors(): discovered through META-INF/services via -processorpath
|
||||
success=true generated=[com.acme.PersonBuilder]
|
||||
|
||||
== 5. -proc:none: the processor never runs
|
||||
success=false generated=[]
|
||||
ERROR /com/acme/Main.java:5: cannot find symbol
|
||||
|
||||
== 6. a processor that forgot @SupportedSourceVersion
|
||||
WARNING: No SupportedSourceVersion annotation found on com.ankurm.builder.LazyProcessor, returning RELEASE_6.
|
||||
WARNING: Supported source version 'RELEASE_6' from annotation processor 'com.ankurm.builder.LazyProcessor' less than -source '25'
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
-------------------------------------------------------------------------------
|
||||
Test set: com.ankurm.builder.ProcessorCompileTest
|
||||
-------------------------------------------------------------------------------
|
||||
Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.268 s -- in com.ankurm.builder.ProcessorCompileTest
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
Test set: com.ankurm.demo.GeneratedBuilderTest
|
||||
-------------------------------------------------------------------------------
|
||||
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.131 s -- in com.ankurm.demo.GeneratedBuilderTest
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
Test set: com.ankurm.demo.RetentionReflectionTest
|
||||
-------------------------------------------------------------------------------
|
||||
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.351 s -- in com.ankurm.demo.RetentionReflectionTest
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
$ javac -cp demo/target/classes -d <tmp> bad/WrongTarget.java
|
||||
bad/WrongTarget.java:4: error: annotation interface not applicable to this kind of declaration
|
||||
@NotBlank
|
||||
^
|
||||
1 error
|
||||
exit=1
|
||||
Reference in New Issue
Block a user