Skip to content

Commit

Permalink
Additional changes in annotations source from EP project
Browse files Browse the repository at this point in the history
  • Loading branch information
gurappa committed Jun 23, 2020
1 parent 14c55a5 commit aa2162b
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,10 +16,16 @@
@Target(value = TYPE)
public @interface AutoProxy {
/** Type generator class. */
Class<? extends AutoProxyClassGenerator> value() default AutoProxy.Default.class;
Class<? extends AutoProxyClassGenerator> 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. */
Expand All @@ -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<? extends AutoProxyClassGenerator> 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<String, Object> asMap() {
final Map<String, Object> 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<String, Object> asMap() {
final Map<String, Object> map = new HashMap<>();

map.put("adapter", Returns.class);
map.put("value", Returns.THROWS);

return map;
}

}
}
Original file line number Diff line number Diff line change
@@ -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. */
Expand All @@ -12,4 +15,10 @@ public interface AutoProxyClassGenerator {
/** Get errors captured during processing. */
@NonNull
String getErrors();

@NonNull
String getName();

@NonNull
List<Element> getOriginating();
}
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand All @@ -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";
}


0 comments on commit aa2162b

Please sign in to comment.