From aa2162b433064971533f493ec1f7de63dcadfbe3 Mon Sep 17 00:00:00 2001 From: Gurappa Chenchugari Date: Tue, 23 Jun 2020 07:47:11 +0200 Subject: [PATCH] Additional changes in annotations source from EP project --- .../java/com/olku/annotations/AutoProxy.java | 89 ++++++++++++++++++- .../annotations/AutoProxyClassGenerator.java | 15 +++- .../java/com/olku/annotations/RetBool.java | 6 +- .../java/com/olku/annotations/RetNumber.java | 6 +- .../java/com/olku/annotations/Returns.java | 8 +- 5 files changed, 109 insertions(+), 15 deletions(-) diff --git a/autoproxy-annotations/src/main/java/com/olku/annotations/AutoProxy.java b/autoproxy-annotations/src/main/java/com/olku/annotations/AutoProxy.java index fccf9f5..034b5ff 100644 --- a/autoproxy-annotations/src/main/java/com/olku/annotations/AutoProxy.java +++ b/autoproxy-annotations/src/main/java/com/olku/annotations/AutoProxy.java @@ -1,8 +1,12 @@ -package com.olku.annotations; +package net.easypark.annotations; + +import androidx.annotation.NonNull; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.Target; +import java.util.HashMap; +import java.util.Map; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.CLASS; @@ -12,10 +16,16 @@ @Target(value = TYPE) public @interface AutoProxy { /** Type generator class. */ - Class value() default AutoProxy.Default.class; + Class value() default Common.class; + + /** Ask generator to compose static methods for simplified instance creation. */ + int flags() default Flags.NONE; + + /** Default Yield return policy. */ + String defaultYield() default Returns.THROWS; /** Represents DEFAULT class generator. CommonClassGenerator class in processors module. */ - abstract class Default implements AutoProxyClassGenerator { + abstract class Common implements AutoProxyClassGenerator { } /** Customize return value of the method if call was canceled by predicate. Only for PUBLIC methods. */ @@ -34,4 +44,77 @@ abstract class Default implements AutoProxyClassGenerator { @Target(value = ElementType.METHOD) @interface AfterCall { } + + /** Special code generation modifier flags. */ + @interface Flags { + /** Default value. */ + int NONE = 0x0000; + /** Compose static method for easier instance creation. */ + int CREATOR = 0x0001; + /** Compose afterCall(...) method for all methods in class. */ + int AFTER_CALL = 0x0002; + /** Compose callByName(...) method that maps string name to a method call. */ + int MAPPING = 0x004; + } + + /** + * Default implementation of annotation interface. Used for simplified extraction of default values of + * annotation during code generation. + */ + @SuppressWarnings("ClassExplicitlyAnnotation") + abstract class DefaultAutoProxy implements AutoProxy { + @Override + public final Class value() { + return Common.class; + } + + @Override + public final int flags() { + return Flags.NONE; + } + + @Override + public final String defaultYield() { + return Returns.THROWS; + } + + /** create instance with field-to-default mapping. */ + @NonNull + public static Map asMap() { + final Map map = new HashMap<>(); + + // map field name to default value + map.put("value", Common.class); + map.put("flags", AutoProxy.Flags.NONE); + map.put("defaultYield", Returns.THROWS); + + return map; + } + } + + /** Default implementation of Yield annotation interface. Used for simplifying default annotations values extracting. */ + @SuppressWarnings("ClassExplicitlyAnnotation") + abstract class DefaultYield implements Yield { + @Override + public final Class adapter() { + return Returns.class; + } + + @Override + public final String value() { + return Returns.THROWS; + } + + /** create instance with field-to-default mapping. */ + @NonNull + public static Map asMap() { + final Map map = new HashMap<>(); + + map.put("adapter", Returns.class); + map.put("value", Returns.THROWS); + + return map; + } + + } } diff --git a/autoproxy-annotations/src/main/java/com/olku/annotations/AutoProxyClassGenerator.java b/autoproxy-annotations/src/main/java/com/olku/annotations/AutoProxyClassGenerator.java index 895c2df..8abd638 100644 --- a/autoproxy-annotations/src/main/java/com/olku/annotations/AutoProxyClassGenerator.java +++ b/autoproxy-annotations/src/main/java/com/olku/annotations/AutoProxyClassGenerator.java @@ -1,9 +1,12 @@ -package com.olku.annotations; - -import javax.annotation.processing.Filer; +package net.easypark.annotations; import androidx.annotation.NonNull; +import java.util.List; + +import javax.annotation.processing.Filer; +import javax.lang.model.element.Element; + /** interface that all custom class generators should support. */ public interface AutoProxyClassGenerator { /** Compose java class. */ @@ -12,4 +15,10 @@ public interface AutoProxyClassGenerator { /** Get errors captured during processing. */ @NonNull String getErrors(); + + @NonNull + String getName(); + + @NonNull + List getOriginating(); } diff --git a/autoproxy-annotations/src/main/java/com/olku/annotations/RetBool.java b/autoproxy-annotations/src/main/java/com/olku/annotations/RetBool.java index 6adcde5..372f75e 100644 --- a/autoproxy-annotations/src/main/java/com/olku/annotations/RetBool.java +++ b/autoproxy-annotations/src/main/java/com/olku/annotations/RetBool.java @@ -1,8 +1,8 @@ -package com.olku.annotations; +package net.easypark.annotations; -import java.lang.annotation.Retention; +import androidx.annotation.*; -import androidx.annotation.StringDef; +import java.lang.annotation.Retention; import static java.lang.annotation.RetentionPolicy.SOURCE; diff --git a/autoproxy-annotations/src/main/java/com/olku/annotations/RetNumber.java b/autoproxy-annotations/src/main/java/com/olku/annotations/RetNumber.java index 842ffaa..8cc5249 100644 --- a/autoproxy-annotations/src/main/java/com/olku/annotations/RetNumber.java +++ b/autoproxy-annotations/src/main/java/com/olku/annotations/RetNumber.java @@ -1,8 +1,8 @@ -package com.olku.annotations; +package net.easypark.annotations; -import java.lang.annotation.Retention; +import androidx.annotation.*; -import androidx.annotation.StringDef; +import java.lang.annotation.Retention; import static java.lang.annotation.RetentionPolicy.SOURCE; diff --git a/autoproxy-annotations/src/main/java/com/olku/annotations/Returns.java b/autoproxy-annotations/src/main/java/com/olku/annotations/Returns.java index 23d5d19..4694156 100644 --- a/autoproxy-annotations/src/main/java/com/olku/annotations/Returns.java +++ b/autoproxy-annotations/src/main/java/com/olku/annotations/Returns.java @@ -1,9 +1,9 @@ -package com.olku.annotations; - -import java.lang.annotation.Retention; +package net.easypark.annotations; import androidx.annotation.StringDef; +import java.lang.annotation.Retention; + import static java.lang.annotation.RetentionPolicy.SOURCE; /** @@ -20,6 +20,8 @@ String NULL = "null"; /** Direct call with ignore of predicate method result. */ String DIRECT = "direct"; + /** Default value is reference on current instance. */ + String THIS = "this"; }