From 5d764ca0f927d1b8643060843ba064ae303f647b Mon Sep 17 00:00:00 2001 From: Anton Kudruk Date: Wed, 29 Jul 2020 21:23:42 +0300 Subject: [PATCH 01/13] Added Maven to readme --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/README.md b/README.md index 3d6d859..2e344c4 100644 --- a/README.md +++ b/README.md @@ -138,16 +138,30 @@ wrapper classes properly. You can download **Uniform Factory** into your project from Maven Central. +Here is an example for Gradle + ``` dependencies { compile group: 'com.github.antkudruk', name: 'uniform-factory', version: '0.0.1' } ``` +and for Maven + +``` + + com.github.antkudruk + uniform-factory + 0.0.1 + +``` + **Uniform Factory** is written to be applied in ByteBuddy Gradle Plugin to generate uniformed **wrapper** classes. Just import and apply `byte-buddy-gradle-plugin` and specify your plugin class. +Here is an example for Gradle + ``` plugins { id 'java' @@ -161,6 +175,30 @@ byteBuddy { } ``` +and in Maven + +``` + + net.bytebuddy + byte-buddy-maven-plugin + 1.10.6 + + + + transform + + + + + + + + + + + +``` + Let's take a look at some examples. ### Empty wrapper From 0238b8c0e731bc9a9548a4300386138489ac60dc Mon Sep 17 00:00:00 2001 From: Anton Kudruk Date: Wed, 2 Sep 2020 00:20:57 +0300 Subject: [PATCH 02/13] Predicate to select lambdas --- .../pluginbuilder/WrapperPlugin.java | 90 +++++++++++++------ ...lectClassCriteriaNotDefinedException.java} | 4 +- .../pluginbuilder/PluginBuilderTest.java | 28 +++--- 3 files changed, 82 insertions(+), 40 deletions(-) rename src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/{TypeMarkerNotDefinedException.java => SelectClassCriteriaNotDefinedException.java} (83%) diff --git a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/WrapperPlugin.java b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/WrapperPlugin.java index 4191e60..93bd194 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/WrapperPlugin.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/WrapperPlugin.java @@ -24,7 +24,7 @@ import com.github.antkudruk.uniformfactory.pluginbuilder.exceptions.GetWrapperMethodWrongTypeException; import com.github.antkudruk.uniformfactory.pluginbuilder.exceptions.OriginInterfaceNotDefinedException; import com.github.antkudruk.uniformfactory.pluginbuilder.exceptions.StaticConstructorGeneratorException; -import com.github.antkudruk.uniformfactory.pluginbuilder.exceptions.TypeMarkerNotDefinedException; +import com.github.antkudruk.uniformfactory.pluginbuilder.exceptions.SelectClassCriteriaNotDefinedException; import net.bytebuddy.ByteBuddy; import net.bytebuddy.build.Plugin; import net.bytebuddy.description.type.TypeDescription; @@ -39,6 +39,7 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.function.Function; +import java.util.function.Predicate; /** * Gradle plugin. @@ -58,13 +59,53 @@ public class WrapperPlugin implements Plugin { private final Class originInterface; private final String getWrapperMethodName; private final Class wrapperClass; - private final Class typeMarker; + // TODO: Replace with lambda private final Class typeMarker; + private final Predicate selectTypeCriteria; private final String wrapperFieldName; private final String classFactoryGeneratorFieldName; private final Class> classFactoryGenerator; private final DynamicType.Unloaded classGeneratorSingletonContainer; + public WrapperPlugin( + Class originInterface, + String getWrapperMethodName, + Class wrapperClass, + Predicate selectTypeCriteria, + + String wrapperFieldName, + String classFactoryGeneratorFieldName, + Class> classFactoryGenerator) { + + this.originInterface = originInterface; + this.getWrapperMethodName = getWrapperMethodName; + this.wrapperClass = wrapperClass; + this.selectTypeCriteria = selectTypeCriteria; + this.wrapperFieldName = checkFieldName(wrapperFieldName); + this.classFactoryGeneratorFieldName = checkFieldName(classFactoryGeneratorFieldName); + this.classFactoryGenerator = classFactoryGenerator; + this.classGeneratorSingletonContainer = createSingletonHolder(classFactoryGenerator); + } + + public WrapperPlugin( + Class originInterface, + String getWrapperMethodName, + Class wrapperClass, + Class typeMarker, + String wrapperFieldName, + String classFactoryGeneratorFieldName, + Class> classFactoryGenerator) { + + this( + originInterface, + getWrapperMethodName, + wrapperClass, + typeDefinitions -> typeDefinitions.getDeclaredAnnotations().isAnnotationPresent(typeMarker), + wrapperFieldName, + classFactoryGeneratorFieldName, + classFactoryGenerator); + } + public WrapperPlugin( Class originInterface, Class wrapperClass, @@ -118,26 +159,19 @@ public WrapperPlugin( classFactoryGenerator); } - public WrapperPlugin( - Class originInterface, - String getWrapperMethodName, - Class wrapperClass, - Class typeMarker, - String wrapperFieldName, - String classFactoryGeneratorFieldName, - Class> classFactoryGenerator) { - this.originInterface = originInterface; - this.getWrapperMethodName = getWrapperMethodName; - this.wrapperClass = wrapperClass; - this.typeMarker = typeMarker; - this.wrapperFieldName = checkFieldName(wrapperFieldName); - this.classFactoryGeneratorFieldName = checkFieldName(classFactoryGeneratorFieldName); - this.classFactoryGenerator = classFactoryGenerator; - this.classGeneratorSingletonContainer = createSingletonHolder(classFactoryGenerator); + public WrapperPlugin(Builder builder) { + this( + builder.originInterface, + builder.getWrapperMethodName, + builder.wrapperClass, + builder.selectClassCriteria, + builder.wrapperFieldName, + builder.wrapperClassFactoryFieldName, + builder.classFactoryGenerator + ); } - private static String checkFieldName(String pluginName) { if(pluginName.matches("[a-zA-Z0-9_]+")) { return pluginName; @@ -203,15 +237,14 @@ public void close() { @Override public boolean matches(TypeDescription target) { - return target.getDeclaredAnnotations() - .isAnnotationPresent(typeMarker); + return selectTypeCriteria.test(target); } public static class Builder { private final Class wrapperClass; private Class originInterface; private String getWrapperMethodName = null; - private Class typeMarker; + private Predicate selectClassCriteria; private String wrapperFieldName = "wrapper"; private String wrapperClassFactoryFieldName = "wrapperClassFactory"; private Class> classFactoryGenerator; @@ -231,7 +264,12 @@ public Builder setGetWrapperMethodName(String getWrapperMethodName) { } public Builder setTypeMarker(Class typeMarker) { - this.typeMarker = typeMarker; + this.selectClassCriteria = (td) -> td.getDeclaredAnnotations().isAnnotationPresent(typeMarker); + return this; + } + + public Builder setSelectClassCriteria(Predicate selectClassCriteria) { + this.selectClassCriteria = selectClassCriteria; return this; } @@ -256,8 +294,8 @@ public WrapperPlugin build() { throw new OriginInterfaceNotDefinedException(); } - if (typeMarker == null) { - throw new TypeMarkerNotDefinedException(); + if (selectClassCriteria == null) { + throw new SelectClassCriteriaNotDefinedException(); } if (classFactoryGenerator == null) { @@ -292,7 +330,7 @@ public WrapperPlugin build() { originInterface, getWrapperMethodName, wrapperClass, - typeMarker, + selectClassCriteria, wrapperFieldName, wrapperClassFactoryFieldName, classFactoryGenerator diff --git a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/TypeMarkerNotDefinedException.java b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/SelectClassCriteriaNotDefinedException.java similarity index 83% rename from src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/TypeMarkerNotDefinedException.java rename to src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/SelectClassCriteriaNotDefinedException.java index d9cb598..e133b02 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/TypeMarkerNotDefinedException.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/SelectClassCriteriaNotDefinedException.java @@ -16,8 +16,8 @@ package com.github.antkudruk.uniformfactory.pluginbuilder.exceptions; -public class TypeMarkerNotDefinedException extends PluginBuilderException { - public TypeMarkerNotDefinedException() { +public class SelectClassCriteriaNotDefinedException extends PluginBuilderException { + public SelectClassCriteriaNotDefinedException() { super("Type marker is not defined"); } } diff --git a/src/test/java/com/github/antkudruk/uniformfactory/pluginbuilder/PluginBuilderTest.java b/src/test/java/com/github/antkudruk/uniformfactory/pluginbuilder/PluginBuilderTest.java index 548905b..ca7e722 100644 --- a/src/test/java/com/github/antkudruk/uniformfactory/pluginbuilder/PluginBuilderTest.java +++ b/src/test/java/com/github/antkudruk/uniformfactory/pluginbuilder/PluginBuilderTest.java @@ -5,7 +5,7 @@ import com.github.antkudruk.uniformfactory.pluginbuilder.exceptions.GetWrapperMethodWrongTypeException; import com.github.antkudruk.uniformfactory.pluginbuilder.exceptions.OriginInterfaceNotDefinedException; import com.github.antkudruk.uniformfactory.pluginbuilder.exceptions.StaticConstructorGeneratorException; -import com.github.antkudruk.uniformfactory.pluginbuilder.exceptions.TypeMarkerNotDefinedException; +import com.github.antkudruk.uniformfactory.pluginbuilder.exceptions.SelectClassCriteriaNotDefinedException; import org.junit.Test; import org.powermock.reflect.Whitebox; @@ -19,7 +19,7 @@ public class PluginBuilderTest { private static final String GET_WRAPPER = "getWrapper"; private static final String GET_WRAPPER_METHOD_NAME = "getWrapperMethodName"; private static final String WRAPPER_CLASS = "wrapperClass"; - private static final String TYPE_MARKER = "typeMarker"; + private static final String SELECT_CLASS_CRITERIA = "selectTypeCriteria"; private static final String WRAPPER = "wrapper"; private static final String WRAPPER_FIELD_NAME = "wrapperFieldName"; private static final String WRAPPER_CLASS_FACTORY = "wrapperClassFactory"; @@ -36,8 +36,9 @@ public void defaultValidBuilderTest() { GET_WRAPPER_METHOD_NAME)); assertEquals(Wrapper.class, Whitebox.getInternalState(wrapperPlugin, WRAPPER_CLASS)); - assertEquals(TypeMarker.class, Whitebox.getInternalState(wrapperPlugin, - TYPE_MARKER)); + // TODO: Check the method + // assertEquals(TypeMarker.class, Whitebox.getInternalState(wrapperPlugin, + // SELECT_CLASS_CRITERIA)); assertEquals(WRAPPER, Whitebox.getInternalState(wrapperPlugin, WRAPPER_FIELD_NAME)); assertEquals(WRAPPER_CLASS_FACTORY, Whitebox.getInternalState(wrapperPlugin, @@ -59,8 +60,9 @@ public void customWrapperFieldsTest() { GET_WRAPPER_METHOD_NAME)); assertEquals(Wrapper.class, Whitebox.getInternalState(wrapperPlugin, WRAPPER_CLASS)); - assertEquals(TypeMarker.class, Whitebox.getInternalState(wrapperPlugin, - TYPE_MARKER)); + // TODO: Check the method + // assertEquals(TypeMarker.class, Whitebox.getInternalState(wrapperPlugin, + // SELECT_CLASS_CRITERIA)); assertEquals("customWrapperField", Whitebox.getInternalState(wrapperPlugin, WRAPPER_FIELD_NAME)); assertEquals("customWrapperConstructorField", Whitebox.getInternalState(wrapperPlugin, @@ -83,8 +85,9 @@ public void validBuilderOnOriginWthTwoMethods() { GET_WRAPPER_METHOD_NAME)); assertEquals(Wrapper.class, Whitebox.getInternalState(wrapperPlugin, WRAPPER_CLASS)); - assertEquals(TypeMarker.class, Whitebox.getInternalState(wrapperPlugin, - TYPE_MARKER)); + // TODO: Check the method + // assertEquals(TypeMarker.class, Whitebox.getInternalState(wrapperPlugin, + // SELECT_CLASS_CRITERIA)); assertEquals(WRAPPER, Whitebox.getInternalState(wrapperPlugin, WRAPPER_FIELD_NAME)); assertEquals(WRAPPER_CLASS_FACTORY, Whitebox.getInternalState(wrapperPlugin, @@ -127,10 +130,11 @@ public void originInterfaceNotDefinedTest() { getDefaultBuilder().setOriginInterface(null).build(); } - @Test(expected = TypeMarkerNotDefinedException.class) - public void typeMarkerNotDefinedTest() { - getDefaultBuilder().setTypeMarker(null).build(); - } + // TODO: Check the method + // @Test(expected = SelectClassCriteriaNotDefinedException.class) + // public void typeMarkerNotDefinedTest() { + // getDefaultBuilder().setTypeMarker(null).build(); + // } private WrapperPlugin.Builder getDefaultBuilder() { return new WrapperPlugin.Builder<>(Wrapper.class) From 39764a5fb500fbfb41d0b3d0a7b8dc1ddd196048 Mon Sep 17 00:00:00 2001 From: Anton Kudruk Date: Thu, 3 Sep 2020 22:58:22 +0300 Subject: [PATCH 03/13] Added an ability to move the marker annotation into the origin interface. --- .../build.gradle | 27 +++++++++++ .../ClassFactoryGeneratorImpl.java | 11 +++++ .../interfaceinherited/Marker.java | 13 +++++ .../interfaceinherited/Origin.java | 8 ++++ .../interfaceinherited/OriginImpl.java | 5 ++ .../interfaceinherited/PluginImpl.java | 14 ++++++ .../interfaceinherited/Wrapper.java | 4 ++ .../interfaceinherited/EmptyTest.java | 13 +++++ settings.gradle | 1 + .../pluginbuilder/WrapperPlugin.java | 47 +++++++++++++++++-- 10 files changed, 138 insertions(+), 5 deletions(-) create mode 100644 gradle-listing-1-2-interface-inherited/build.gradle create mode 100644 gradle-listing-1-2-interface-inherited/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/ClassFactoryGeneratorImpl.java create mode 100644 gradle-listing-1-2-interface-inherited/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/Marker.java create mode 100644 gradle-listing-1-2-interface-inherited/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/Origin.java create mode 100644 gradle-listing-1-2-interface-inherited/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/OriginImpl.java create mode 100644 gradle-listing-1-2-interface-inherited/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/PluginImpl.java create mode 100644 gradle-listing-1-2-interface-inherited/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/Wrapper.java create mode 100644 gradle-listing-1-2-interface-inherited/src/test/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/EmptyTest.java diff --git a/gradle-listing-1-2-interface-inherited/build.gradle b/gradle-listing-1-2-interface-inherited/build.gradle new file mode 100644 index 0000000..a6bd9ac --- /dev/null +++ b/gradle-listing-1-2-interface-inherited/build.gradle @@ -0,0 +1,27 @@ +plugins { + id 'java' + id "net.bytebuddy.byte-buddy-gradle-plugin" version "1.10.6" +} + +group 'hz.xorlab' +version '1.0-SNAPSHOT' + +sourceCompatibility = 1.11 + +repositories { + mavenCentral() +} + +dependencies { + compile project(path: ":") + testCompile group: 'junit', name: 'junit', version: '4.12' + compile group: 'net.bytebuddy', name: 'byte-buddy', version: '1.10.6' + + compile group: 'net.bytebuddy', name: 'byte-buddy-gradle-plugin', version: '1.10.6' +} + +byteBuddy { + transformation { + plugin = "com.github.antkudruk.uniformfactory.test.gradleplugin.emptywrapper.interfaceinherited.PluginImpl" + } +} diff --git a/gradle-listing-1-2-interface-inherited/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/ClassFactoryGeneratorImpl.java b/gradle-listing-1-2-interface-inherited/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/ClassFactoryGeneratorImpl.java new file mode 100644 index 0000000..5284892 --- /dev/null +++ b/gradle-listing-1-2-interface-inherited/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/ClassFactoryGeneratorImpl.java @@ -0,0 +1,11 @@ +package com.github.antkudruk.uniformfactory.test.gradleplugin.emptywrapper.interfaceinherited; + +import com.github.antkudruk.uniformfactory.classfactory.ClassFactory; +import com.github.antkudruk.uniformfactory.pluginbuilder.DefaultMetaClassFactory; + +public class ClassFactoryGeneratorImpl extends DefaultMetaClassFactory { + public ClassFactoryGeneratorImpl() { + super(new ClassFactory.Builder<>(Wrapper.class) + .build()); + } +} diff --git a/gradle-listing-1-2-interface-inherited/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/Marker.java b/gradle-listing-1-2-interface-inherited/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/Marker.java new file mode 100644 index 0000000..a634b61 --- /dev/null +++ b/gradle-listing-1-2-interface-inherited/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/Marker.java @@ -0,0 +1,13 @@ +package com.github.antkudruk.uniformfactory.test.gradleplugin.emptywrapper.interfaceinherited; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.CLASS) +@Target(ElementType.TYPE) +@Inherited +public @interface Marker { +} diff --git a/gradle-listing-1-2-interface-inherited/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/Origin.java b/gradle-listing-1-2-interface-inherited/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/Origin.java new file mode 100644 index 0000000..de3b034 --- /dev/null +++ b/gradle-listing-1-2-interface-inherited/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/Origin.java @@ -0,0 +1,8 @@ +package com.github.antkudruk.uniformfactory.test.gradleplugin.emptywrapper.interfaceinherited; + +@Marker +public interface Origin { + default Wrapper getWrapper() { + throw new RuntimeException("Wrapper method hasn't been implemented."); + } +} diff --git a/gradle-listing-1-2-interface-inherited/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/OriginImpl.java b/gradle-listing-1-2-interface-inherited/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/OriginImpl.java new file mode 100644 index 0000000..5f42f39 --- /dev/null +++ b/gradle-listing-1-2-interface-inherited/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/OriginImpl.java @@ -0,0 +1,5 @@ +package com.github.antkudruk.uniformfactory.test.gradleplugin.emptywrapper.interfaceinherited; + +@Marker +public class OriginImpl implements Origin { +} diff --git a/gradle-listing-1-2-interface-inherited/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/PluginImpl.java b/gradle-listing-1-2-interface-inherited/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/PluginImpl.java new file mode 100644 index 0000000..e760df3 --- /dev/null +++ b/gradle-listing-1-2-interface-inherited/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/PluginImpl.java @@ -0,0 +1,14 @@ +package com.github.antkudruk.uniformfactory.test.gradleplugin.emptywrapper.interfaceinherited; + +import com.github.antkudruk.uniformfactory.pluginbuilder.WrapperPlugin; + +public class PluginImpl extends WrapperPlugin { + public PluginImpl() { + super( + Origin.class, + Wrapper.class, + Marker.class, + "examplePlugin", + ClassFactoryGeneratorImpl.class); + } +} diff --git a/gradle-listing-1-2-interface-inherited/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/Wrapper.java b/gradle-listing-1-2-interface-inherited/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/Wrapper.java new file mode 100644 index 0000000..90a8fa6 --- /dev/null +++ b/gradle-listing-1-2-interface-inherited/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/Wrapper.java @@ -0,0 +1,4 @@ +package com.github.antkudruk.uniformfactory.test.gradleplugin.emptywrapper.interfaceinherited; + +public interface Wrapper { +} diff --git a/gradle-listing-1-2-interface-inherited/src/test/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/EmptyTest.java b/gradle-listing-1-2-interface-inherited/src/test/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/EmptyTest.java new file mode 100644 index 0000000..9f29ed0 --- /dev/null +++ b/gradle-listing-1-2-interface-inherited/src/test/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfaceinherited/EmptyTest.java @@ -0,0 +1,13 @@ +package com.github.antkudruk.uniformfactory.test.gradleplugin.emptywrapper.interfaceinherited; + +import org.junit.Test; + +public class EmptyTest { + + @SuppressWarnings("ConstantConditions") + @Test + public void test() { + OriginImpl origin = new OriginImpl(); + assert Wrapper.class.isAssignableFrom(origin.getWrapper().getClass()); + } +} diff --git a/settings.gradle b/settings.gradle index 6262664..445893e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,4 +6,5 @@ include 'gradle-listing-3-test' include 'gradle-listing-4-test' include 'gradle-listing-6-test' include 'gradle-listing-7-test' +include 'gradle-listing-1-2-interface-inherited' diff --git a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/WrapperPlugin.java b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/WrapperPlugin.java index 93bd194..3a80d99 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/WrapperPlugin.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/WrapperPlugin.java @@ -27,6 +27,7 @@ import com.github.antkudruk.uniformfactory.pluginbuilder.exceptions.SelectClassCriteriaNotDefinedException; import net.bytebuddy.ByteBuddy; import net.bytebuddy.build.Plugin; +import net.bytebuddy.description.annotation.AnnotationDescription; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.dynamic.ClassFileLocator; import net.bytebuddy.dynamic.DynamicType; @@ -87,6 +88,17 @@ public WrapperPlugin( this.classGeneratorSingletonContainer = createSingletonHolder(classFactoryGenerator); } + /** + * Creates the plugin to build wrappers. + * + * @param originInterface Interface to implement by the origin class + * @param getWrapperMethodName Origin method to ter the wrapper + * @param wrapperClass Interface to implement by wrappers + * @param typeMarker Annotation to mark origin classes + * @param wrapperFieldName Field name to store wrappers + * @param classFactoryGeneratorFieldName Field name to store wrapper class generators + * @param classFactoryGenerator Class factory generator class. You'll have it's singleton instance created. + */ public WrapperPlugin( Class originInterface, String getWrapperMethodName, @@ -100,7 +112,11 @@ public WrapperPlugin( originInterface, getWrapperMethodName, wrapperClass, - typeDefinitions -> typeDefinitions.getDeclaredAnnotations().isAnnotationPresent(typeMarker), + typeDefinitions -> typeDefinitions + .getDeclaredAnnotations() + .stream() + .map(AnnotationDescription::getAnnotationType) + .anyMatch(new TypeDescription.ForLoadedType(typeMarker)::equals), wrapperFieldName, classFactoryGeneratorFieldName, classFactoryGenerator); @@ -123,6 +139,23 @@ public WrapperPlugin( classFactoryGenerator); } + public WrapperPlugin( + Class originInterface, + Class wrapperClass, + Predicate selectTypeCriteria, + String pluginName, + Class> classFactoryGenerator) { + + this( + originInterface, + getSingleMethod(originInterface), + wrapperClass, + selectTypeCriteria, + pluginName + "Wrapper", + pluginName + "WrapperGenerator", + classFactoryGenerator); + } + public WrapperPlugin( Class originInterface, Class wrapperClass, @@ -159,7 +192,6 @@ public WrapperPlugin( classFactoryGenerator); } - public WrapperPlugin(Builder builder) { this( builder.originInterface, @@ -194,8 +226,13 @@ public DynamicType.Builder apply( TypeDescription typeDescription, ClassFileLocator classFileLocator) { - return builder - .implement(originInterface) + DynamicType.Builder b = builder; + + if(!typeDescription.getInterfaces().contains(new TypeDescription.ForLoadedType(originInterface))) { + b = b.implement(originInterface); + } + + return b .defineField(wrapperFieldName, wrapperClass, Opcodes.ACC_PRIVATE | Opcodes.ACC_SYNTHETIC) .defineField(classFactoryGeneratorFieldName, Function.class, Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC) .invokable(ElementMatchers.isTypeInitializer()) @@ -237,7 +274,7 @@ public void close() { @Override public boolean matches(TypeDescription target) { - return selectTypeCriteria.test(target); + return !target.isInterface() && !target.isAnnotation() && selectTypeCriteria.test(target); } public static class Builder { From cd533cf59f8167c8a7479fe0f7364a4cab5d799a Mon Sep 17 00:00:00 2001 From: Anton Kudruk Date: Sat, 5 Sep 2020 22:32:53 +0300 Subject: [PATCH 04/13] Added an ability to move the marker annotation into the origin interface. --- README.md | 74 ++++++++++ .../build.gradle | 27 ++++ .../ClassFactoryGeneratorImpl.java | 11 ++ .../interfacebased/ExplicitOriginImpl.java | 8 + .../emptywrapper/interfacebased/Origin.java | 7 + .../interfacebased/OriginImpl.java | 4 + .../interfacebased/PluginImpl.java | 19 +++ .../emptywrapper/interfacebased/Wrapper.java | 4 + .../interfacebased/EmptyTest.java | 21 +++ settings.gradle | 1 + .../pluginbuilder/WrapperPlugin.java | 139 ++++++++++++++---- 11 files changed, 288 insertions(+), 27 deletions(-) create mode 100644 gradle-listing-1-1-interface-implementation-test/build.gradle create mode 100644 gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/ClassFactoryGeneratorImpl.java create mode 100644 gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/ExplicitOriginImpl.java create mode 100644 gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/Origin.java create mode 100644 gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/OriginImpl.java create mode 100644 gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/PluginImpl.java create mode 100644 gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/Wrapper.java create mode 100644 gradle-listing-1-1-interface-implementation-test/src/test/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/EmptyTest.java diff --git a/README.md b/README.md index 2e344c4..8c449b0 100644 --- a/README.md +++ b/README.md @@ -308,6 +308,80 @@ Object origin = new OriginImpl(); Wrapper wrapper = ((Origin)origin).getWrapper(); ``` +#### Using explicit interface to enhance objects with wrappers + +You can avoid class cast made in the previous example the following way + +* Add `@Marker` annotation to the `Origin` interface. + +* Add a default implementation to the `Origin` interface to prevent compilation +error. This default implementation should basically throw an exception, but you +may implement the different logic. + +``` +@Marker +public interface Origin { + default Wrapper getWrapper() { + throw new RuntimeException("Wrapper method hasn't been implemented."); + } +} +``` + +* Add `@Inherited` to the Marker annotation. This will implicitly add the +`@Marker` annotation to each object implementing `Origin` interface. + +``` +@Retention(RetentionPolicy.CLASS) +@Target(ElementType.TYPE) +@Inherited +public @interface Marker { } +``` + +* Add `Origin` interface to the interfaces list of each origin class. + +``` +@Marker +public class OriginImpl implements Origin { +} +``` +After that, the `OriginImpl` class is going to have an implementation for +`getWrapper()` method that returns the appropriate wrapper. + +``` +OriginImpl origin = new OriginImpl(); +Wrapper wrapper = origin.getWrapper(); +``` + +This way, if you implement `getWrapper()` method explicitly, your +implementation it's not going to be overridden by the plugin. + +#### Select type criteria + +You may want to add wrappers to classes satisfying a custom criteria, for +example, matching class names to a special regular expression. +**UniformFactory** provides a flexible way to select particular classes for +that. + +Let's implement a plugin to add wrappers to methods that explicitly implement +the `Origin` interface, but using custom class selection criteria. + +``` +public class PluginImpl extends WrapperPlugin { + public PluginImpl() { + super( + Origin.class, + Wrapper.class, + // Class selection criteria + td -> td.getInterfaces() + .stream() + .map(TypeDefinition::asErasure) + .anyMatch(new TypeDescription.ForLoadedType(Origin.class)::equals), + "examplePlugin", + ClassFactoryGeneratorImpl.class); + } +} +``` + ### Method Singleton Let's enhance our empty `Wrapper` class. diff --git a/gradle-listing-1-1-interface-implementation-test/build.gradle b/gradle-listing-1-1-interface-implementation-test/build.gradle new file mode 100644 index 0000000..1263a93 --- /dev/null +++ b/gradle-listing-1-1-interface-implementation-test/build.gradle @@ -0,0 +1,27 @@ +plugins { + id 'java' + id "net.bytebuddy.byte-buddy-gradle-plugin" version "1.10.6" +} + +group 'hz.xorlab' +version '1.0-SNAPSHOT' + +sourceCompatibility = 1.11 + +repositories { + mavenCentral() +} + +dependencies { + compile project(path: ":") + testCompile group: 'junit', name: 'junit', version: '4.12' + compile group: 'net.bytebuddy', name: 'byte-buddy', version: '1.10.6' + + compile group: 'net.bytebuddy', name: 'byte-buddy-gradle-plugin', version: '1.10.6' +} + +byteBuddy { + transformation { + plugin = "com.github.antkudruk.uniformfactory.test.gradleplugin.emptywrapper.interfacebased.PluginImpl" + } +} diff --git a/gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/ClassFactoryGeneratorImpl.java b/gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/ClassFactoryGeneratorImpl.java new file mode 100644 index 0000000..7691a77 --- /dev/null +++ b/gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/ClassFactoryGeneratorImpl.java @@ -0,0 +1,11 @@ +package com.github.antkudruk.uniformfactory.test.gradleplugin.emptywrapper.interfacebased; + +import com.github.antkudruk.uniformfactory.classfactory.ClassFactory; +import com.github.antkudruk.uniformfactory.pluginbuilder.DefaultMetaClassFactory; + +public class ClassFactoryGeneratorImpl extends DefaultMetaClassFactory { + public ClassFactoryGeneratorImpl() { + super(new ClassFactory.Builder<>(Wrapper.class) + .build()); + } +} diff --git a/gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/ExplicitOriginImpl.java b/gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/ExplicitOriginImpl.java new file mode 100644 index 0000000..ae27933 --- /dev/null +++ b/gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/ExplicitOriginImpl.java @@ -0,0 +1,8 @@ +package com.github.antkudruk.uniformfactory.test.gradleplugin.emptywrapper.interfacebased; + +public class ExplicitOriginImpl implements Origin { + @Override + public Wrapper getWrapper() { + return null; + } +} diff --git a/gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/Origin.java b/gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/Origin.java new file mode 100644 index 0000000..9253a67 --- /dev/null +++ b/gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/Origin.java @@ -0,0 +1,7 @@ +package com.github.antkudruk.uniformfactory.test.gradleplugin.emptywrapper.interfacebased; + +public interface Origin { + default Wrapper getWrapper() { + throw new RuntimeException("The method should be implemented by the plugin. Please, specify the plugin un your build script."); + } +} diff --git a/gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/OriginImpl.java b/gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/OriginImpl.java new file mode 100644 index 0000000..62fb79e --- /dev/null +++ b/gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/OriginImpl.java @@ -0,0 +1,4 @@ +package com.github.antkudruk.uniformfactory.test.gradleplugin.emptywrapper.interfacebased; + +public class OriginImpl implements Origin { +} diff --git a/gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/PluginImpl.java b/gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/PluginImpl.java new file mode 100644 index 0000000..2acba0f --- /dev/null +++ b/gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/PluginImpl.java @@ -0,0 +1,19 @@ +package com.github.antkudruk.uniformfactory.test.gradleplugin.emptywrapper.interfacebased; + +import com.github.antkudruk.uniformfactory.pluginbuilder.WrapperPlugin; +import net.bytebuddy.description.type.TypeDefinition; +import net.bytebuddy.description.type.TypeDescription; + +public class PluginImpl extends WrapperPlugin { + public PluginImpl() { + super( + Origin.class, + Wrapper.class, + td -> td.getInterfaces() + .stream() + .map(TypeDefinition::asErasure) + .anyMatch(new TypeDescription.ForLoadedType(Origin.class)::equals), + "examplePlugin", + ClassFactoryGeneratorImpl.class); + } +} diff --git a/gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/Wrapper.java b/gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/Wrapper.java new file mode 100644 index 0000000..c8bb0af --- /dev/null +++ b/gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/Wrapper.java @@ -0,0 +1,4 @@ +package com.github.antkudruk.uniformfactory.test.gradleplugin.emptywrapper.interfacebased; + +public interface Wrapper { +} diff --git a/gradle-listing-1-1-interface-implementation-test/src/test/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/EmptyTest.java b/gradle-listing-1-1-interface-implementation-test/src/test/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/EmptyTest.java new file mode 100644 index 0000000..8e80da5 --- /dev/null +++ b/gradle-listing-1-1-interface-implementation-test/src/test/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/EmptyTest.java @@ -0,0 +1,21 @@ +package com.github.antkudruk.uniformfactory.test.gradleplugin.emptywrapper.interfacebased; + +import org.junit.Test; + +import static org.junit.Assert.assertNull; + +public class EmptyTest { + + @SuppressWarnings("ConstantConditions") + @Test + public void test() { + OriginImpl origin = new OriginImpl(); + assert Wrapper.class.isAssignableFrom(origin.getWrapper().getClass()); + } + + @Test + public void testExplicitOriginImpl () { + ExplicitOriginImpl origin = new ExplicitOriginImpl(); + assertNull(origin.getWrapper()); + } +} diff --git a/settings.gradle b/settings.gradle index 445893e..c30ffbf 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,5 +6,6 @@ include 'gradle-listing-3-test' include 'gradle-listing-4-test' include 'gradle-listing-6-test' include 'gradle-listing-7-test' +include 'gradle-listing-1-1-interface-implementation-test' include 'gradle-listing-1-2-interface-inherited' diff --git a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/WrapperPlugin.java b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/WrapperPlugin.java index 3a80d99..a65018a 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/WrapperPlugin.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/WrapperPlugin.java @@ -28,6 +28,9 @@ import net.bytebuddy.ByteBuddy; import net.bytebuddy.build.Plugin; import net.bytebuddy.description.annotation.AnnotationDescription; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.description.method.ParameterDescription; +import net.bytebuddy.description.type.TypeDefinition; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.dynamic.ClassFileLocator; import net.bytebuddy.dynamic.DynamicType; @@ -60,7 +63,6 @@ public class WrapperPlugin implements Plugin { private final Class originInterface; private final String getWrapperMethodName; private final Class wrapperClass; - // TODO: Replace with lambda private final Class typeMarker; private final Predicate selectTypeCriteria; private final String wrapperFieldName; private final String classFactoryGeneratorFieldName; @@ -68,12 +70,22 @@ public class WrapperPlugin implements Plugin { private final DynamicType.Unloaded classGeneratorSingletonContainer; + /** + * Creates the plugin to build wrappers. + * + * @param originInterface Interface to implement by the origin class + * @param getWrapperMethodName Origin method to ter the wrapper + * @param wrapperClass Interface to implement by wrappers + * @param selectTypeCriteria Determines if the class has to be enhanced with the wrapper + * @param wrapperFieldName Field name to store wrappers + * @param classFactoryGeneratorFieldName Field name to store wrapper class generators + * @param classFactoryGenerator Class factory generator class. You'll have it's singleton instance created. + */ public WrapperPlugin( Class originInterface, String getWrapperMethodName, Class wrapperClass, Predicate selectTypeCriteria, - String wrapperFieldName, String classFactoryGeneratorFieldName, Class> classFactoryGenerator) { @@ -122,6 +134,15 @@ public WrapperPlugin( classFactoryGenerator); } + /** + * Creates the plugin to build wrappers. + * + * @param originInterface Interface to implement by the origin class + * @param wrapperClass Interface to implement by wrappers + * @param typeMarker Annotation to mark origin classes + * @param pluginName Name of the plugin + * @param classFactoryGenerator Class factory generator class. You'll have it's singleton instance created. + */ public WrapperPlugin( Class originInterface, Class wrapperClass, @@ -139,6 +160,15 @@ public WrapperPlugin( classFactoryGenerator); } + /** + * Creates the plugin to build wrappers. + * + * @param originInterface Interface to implement by the origin class + * @param wrapperClass Interface to implement by wrappers + * @param selectTypeCriteria Determines if the class has to be enhanced with the wrapper + * @param pluginName Name of the plugin + * @param classFactoryGenerator Class factory generator class. You'll have it's singleton instance created. + */ public WrapperPlugin( Class originInterface, Class wrapperClass, @@ -156,6 +186,16 @@ public WrapperPlugin( classFactoryGenerator); } + /** + * Creates the plugin to build wrappers. + * + * @param originInterface Interface to implement by the origin class + * @param wrapperClass Interface to implement by wrappers + * @param typeMarker Annotation to mark origin classes + * @param wrapperFieldName Field name to store wrappers + * @param classFactoryGeneratorFieldName Field name to store wrapper class generators + * @param classFactoryGenerator Class factory generator class. You'll have it's singleton instance created. + */ public WrapperPlugin( Class originInterface, Class wrapperClass, @@ -174,6 +214,16 @@ public WrapperPlugin( classFactoryGenerator); } + /** + * Creates the plugin to build wrappers. + * + * @param originInterface Interface to implement by the origin class + * @param getWrapperMethodName Origin method to ter the wrapper + * @param wrapperClass Interface to implement by wrappers + * @param typeMarker Annotation to mark origin classes + * @param pluginName Name of the plugin + * @param classFactoryGenerator Class factory generator class. You'll have it's singleton instance created. + */ public WrapperPlugin( Class originInterface, String getWrapperMethodName, @@ -192,7 +242,8 @@ public WrapperPlugin( classFactoryGenerator); } - public WrapperPlugin(Builder builder) { + // TODO: Builder does not process default parameters unless it's build method called. Make the constructor work . + private WrapperPlugin(Builder builder) { this( builder.originInterface, builder.getWrapperMethodName, @@ -220,39 +271,73 @@ private static String getSingleMethod(Class functionalClass) { } } + /** + * Called by ByteBuddy plugin to transform matching classes + * @param builder Builder to transform the class + * @param typeDescription Type description to analyse transformed class. + * @return New version of the builder to create transformed class. + */ @Override public DynamicType.Builder apply( DynamicType.Builder builder, TypeDescription typeDescription, ClassFileLocator classFileLocator) { - DynamicType.Builder b = builder; + // Add interface if needed + if (!typeDescription.getInterfaces().contains(new TypeDescription.ForLoadedType(originInterface))) { + builder = builder.implement(originInterface); + } - if(!typeDescription.getInterfaces().contains(new TypeDescription.ForLoadedType(originInterface))) { - b = b.implement(originInterface); + // Add method implementation if needed + MethodDescription originMethodReturningWrapper = new TypeDescription.ForLoadedType(originInterface) + .getDeclaredMethods() + .filter(ElementMatchers.named(getWrapperMethodName)) + .getOnly(); + + if (implementsMethod(typeDescription, originMethodReturningWrapper)) { + + builder = builder + .defineField(wrapperFieldName, wrapperClass, Opcodes.ACC_PRIVATE | Opcodes.ACC_SYNTHETIC) + .defineField(classFactoryGeneratorFieldName, Function.class, Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC) + .invokable(ElementMatchers.isTypeInitializer()) + .intercept(new InitFieldUsingClassInstanceMethodImplementation( + classGeneratorSingletonContainer.getTypeDescription(), + classFactoryGeneratorFieldName, + classFactoryGenerator + )) + .invokable(ElementMatchers.isConstructor()) + .intercept(SuperMethodCall.INSTANCE.andThen( + new InitFieldWithConstructorFieldUsingThisImplementation( + classFactoryGeneratorFieldName, wrapperFieldName))) + .define(new TypeDescription.ForLoadedType(originInterface) + .getDeclaredMethods() + .filter(ElementMatchers.named(getWrapperMethodName)) + .getOnly()) + .intercept(FieldAccessor.ofField(wrapperFieldName)); } - return b - .defineField(wrapperFieldName, wrapperClass, Opcodes.ACC_PRIVATE | Opcodes.ACC_SYNTHETIC) - .defineField(classFactoryGeneratorFieldName, Function.class, Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC) - .invokable(ElementMatchers.isTypeInitializer()) - .intercept(new InitFieldUsingClassInstanceMethodImplementation( - classGeneratorSingletonContainer.getTypeDescription(), - classFactoryGeneratorFieldName, - classFactoryGenerator - )) - .invokable(ElementMatchers.isConstructor()) - .intercept(SuperMethodCall.INSTANCE.andThen( - new InitFieldWithConstructorFieldUsingThisImplementation( - classFactoryGeneratorFieldName, wrapperFieldName))) - .define(new TypeDescription.ForLoadedType(originInterface) - .getDeclaredMethods() - .filter(ElementMatchers.named(getWrapperMethodName)) - .getOnly()) - - .intercept(FieldAccessor.ofField(wrapperFieldName)) - - .require(classGeneratorSingletonContainer); + return builder.require(classGeneratorSingletonContainer); + } + + /** + * Checks if typeDescription implements the method originMethodReturningWrapper directly. + * @param typeDescription Type to look for the method + * @param originMethodReturningWrapper Method + * @return True if the method is found, false otherwise. + */ + private boolean implementsMethod (TypeDescription typeDescription, MethodDescription originMethodReturningWrapper) { + + TypeDescription[] argumentTypes = originMethodReturningWrapper + .getParameters() + .stream() + .map(ParameterDescription::getType) + .map(TypeDefinition::asErasure) + .toArray(TypeDescription[]::new); + + return typeDescription.getDeclaredMethods() + .filter(ElementMatchers.named(originMethodReturningWrapper.getName())) + .filter(ElementMatchers.takesArguments(argumentTypes)) + .isEmpty(); } private DynamicType.Unloaded createSingletonHolder(Class> classFactoryGenerator) { From 9d98b653de99c0893f1d692bc6be8541d97b40b2 Mon Sep 17 00:00:00 2001 From: Anton Kudruk Date: Sat, 5 Sep 2020 23:14:01 +0300 Subject: [PATCH 05/13] Refactored test project names --- .../test/gradleplugin/emptywrapper/interfacebased/Wrapper.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {gradle-listing-1-1-interface-implementation-test => gradle-listing-1-3-custom-select-type-criteria}/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/Wrapper.java (100%) diff --git a/gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/Wrapper.java b/gradle-listing-1-3-custom-select-type-criteria/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/Wrapper.java similarity index 100% rename from gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/Wrapper.java rename to gradle-listing-1-3-custom-select-type-criteria/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/Wrapper.java From 8cc831df347e41080e2189ce0db40ded6ab93aea Mon Sep 17 00:00:00 2001 From: Anton Kudruk Date: Sat, 5 Sep 2020 23:14:45 +0300 Subject: [PATCH 06/13] Added an ability to move the marker annotation into the origin interface. --- build.gradle | 2 +- .../build.gradle | 0 .../emptywrapper/ClassFactoryGeneratorImpl.java | 0 .../test/gradleplugin/emptywrapper/Marker.java | 0 .../test/gradleplugin/emptywrapper/Origin.java | 0 .../test/gradleplugin/emptywrapper/OriginImpl.java | 0 .../test/gradleplugin/emptywrapper/PluginImpl.java | 0 .../test/gradleplugin/emptywrapper/Wrapper.java | 0 .../test/gradleplugin/emptywrapper/EmptyTest.java | 0 .../build.gradle | 0 .../interfacebased/ClassFactoryGeneratorImpl.java | 0 .../emptywrapper/interfacebased/ExplicitOriginImpl.java | 0 .../gradleplugin/emptywrapper/interfacebased/Origin.java | 0 .../emptywrapper/interfacebased/OriginImpl.java | 0 .../emptywrapper/interfacebased/PluginImpl.java | 0 .../gradleplugin/emptywrapper/interfacebased/EmptyTest.java | 0 gradle/wrapper/gradle-wrapper.properties | 3 ++- settings.gradle | 6 +++--- 18 files changed, 6 insertions(+), 5 deletions(-) rename {gradle-listing-1-test => gradle-listing-1-1-test}/build.gradle (100%) rename {gradle-listing-1-test => gradle-listing-1-1-test}/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/ClassFactoryGeneratorImpl.java (100%) rename {gradle-listing-1-test => gradle-listing-1-1-test}/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/Marker.java (100%) rename {gradle-listing-1-test => gradle-listing-1-1-test}/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/Origin.java (100%) rename {gradle-listing-1-test => gradle-listing-1-1-test}/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/OriginImpl.java (100%) rename {gradle-listing-1-test => gradle-listing-1-1-test}/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/PluginImpl.java (100%) rename {gradle-listing-1-test => gradle-listing-1-1-test}/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/Wrapper.java (100%) rename {gradle-listing-1-test => gradle-listing-1-1-test}/src/test/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/EmptyTest.java (100%) rename {gradle-listing-1-1-interface-implementation-test => gradle-listing-1-3-custom-select-type-criteria}/build.gradle (100%) rename {gradle-listing-1-1-interface-implementation-test => gradle-listing-1-3-custom-select-type-criteria}/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/ClassFactoryGeneratorImpl.java (100%) rename {gradle-listing-1-1-interface-implementation-test => gradle-listing-1-3-custom-select-type-criteria}/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/ExplicitOriginImpl.java (100%) rename {gradle-listing-1-1-interface-implementation-test => gradle-listing-1-3-custom-select-type-criteria}/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/Origin.java (100%) rename {gradle-listing-1-1-interface-implementation-test => gradle-listing-1-3-custom-select-type-criteria}/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/OriginImpl.java (100%) rename {gradle-listing-1-1-interface-implementation-test => gradle-listing-1-3-custom-select-type-criteria}/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/PluginImpl.java (100%) rename {gradle-listing-1-1-interface-implementation-test => gradle-listing-1-3-custom-select-type-criteria}/src/test/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/EmptyTest.java (100%) diff --git a/build.gradle b/build.gradle index 8ab1a78..bf0af0a 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } // The current version -def libraryVersion='0.0.1' +def libraryVersion='0.0.2' group 'com.github.antkudruk' version libraryVersion diff --git a/gradle-listing-1-test/build.gradle b/gradle-listing-1-1-test/build.gradle similarity index 100% rename from gradle-listing-1-test/build.gradle rename to gradle-listing-1-1-test/build.gradle diff --git a/gradle-listing-1-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/ClassFactoryGeneratorImpl.java b/gradle-listing-1-1-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/ClassFactoryGeneratorImpl.java similarity index 100% rename from gradle-listing-1-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/ClassFactoryGeneratorImpl.java rename to gradle-listing-1-1-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/ClassFactoryGeneratorImpl.java diff --git a/gradle-listing-1-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/Marker.java b/gradle-listing-1-1-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/Marker.java similarity index 100% rename from gradle-listing-1-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/Marker.java rename to gradle-listing-1-1-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/Marker.java diff --git a/gradle-listing-1-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/Origin.java b/gradle-listing-1-1-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/Origin.java similarity index 100% rename from gradle-listing-1-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/Origin.java rename to gradle-listing-1-1-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/Origin.java diff --git a/gradle-listing-1-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/OriginImpl.java b/gradle-listing-1-1-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/OriginImpl.java similarity index 100% rename from gradle-listing-1-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/OriginImpl.java rename to gradle-listing-1-1-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/OriginImpl.java diff --git a/gradle-listing-1-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/PluginImpl.java b/gradle-listing-1-1-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/PluginImpl.java similarity index 100% rename from gradle-listing-1-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/PluginImpl.java rename to gradle-listing-1-1-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/PluginImpl.java diff --git a/gradle-listing-1-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/Wrapper.java b/gradle-listing-1-1-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/Wrapper.java similarity index 100% rename from gradle-listing-1-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/Wrapper.java rename to gradle-listing-1-1-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/Wrapper.java diff --git a/gradle-listing-1-test/src/test/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/EmptyTest.java b/gradle-listing-1-1-test/src/test/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/EmptyTest.java similarity index 100% rename from gradle-listing-1-test/src/test/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/EmptyTest.java rename to gradle-listing-1-1-test/src/test/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/EmptyTest.java diff --git a/gradle-listing-1-1-interface-implementation-test/build.gradle b/gradle-listing-1-3-custom-select-type-criteria/build.gradle similarity index 100% rename from gradle-listing-1-1-interface-implementation-test/build.gradle rename to gradle-listing-1-3-custom-select-type-criteria/build.gradle diff --git a/gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/ClassFactoryGeneratorImpl.java b/gradle-listing-1-3-custom-select-type-criteria/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/ClassFactoryGeneratorImpl.java similarity index 100% rename from gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/ClassFactoryGeneratorImpl.java rename to gradle-listing-1-3-custom-select-type-criteria/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/ClassFactoryGeneratorImpl.java diff --git a/gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/ExplicitOriginImpl.java b/gradle-listing-1-3-custom-select-type-criteria/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/ExplicitOriginImpl.java similarity index 100% rename from gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/ExplicitOriginImpl.java rename to gradle-listing-1-3-custom-select-type-criteria/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/ExplicitOriginImpl.java diff --git a/gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/Origin.java b/gradle-listing-1-3-custom-select-type-criteria/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/Origin.java similarity index 100% rename from gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/Origin.java rename to gradle-listing-1-3-custom-select-type-criteria/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/Origin.java diff --git a/gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/OriginImpl.java b/gradle-listing-1-3-custom-select-type-criteria/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/OriginImpl.java similarity index 100% rename from gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/OriginImpl.java rename to gradle-listing-1-3-custom-select-type-criteria/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/OriginImpl.java diff --git a/gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/PluginImpl.java b/gradle-listing-1-3-custom-select-type-criteria/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/PluginImpl.java similarity index 100% rename from gradle-listing-1-1-interface-implementation-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/PluginImpl.java rename to gradle-listing-1-3-custom-select-type-criteria/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/PluginImpl.java diff --git a/gradle-listing-1-1-interface-implementation-test/src/test/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/EmptyTest.java b/gradle-listing-1-3-custom-select-type-criteria/src/test/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/EmptyTest.java similarity index 100% rename from gradle-listing-1-1-interface-implementation-test/src/test/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/EmptyTest.java rename to gradle-listing-1-3-custom-select-type-criteria/src/test/java/com/github/antkudruk/uniformfactory/test/gradleplugin/emptywrapper/interfacebased/EmptyTest.java diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5028f28..a26dcbd 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Sat Sep 05 22:58:03 MSK 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip diff --git a/settings.gradle b/settings.gradle index c30ffbf..b24992d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,11 +1,11 @@ rootProject.name = 'uniformFactory' include 'gradle-plugin-test' -include 'gradle-listing-1-test' +include 'gradle-listing-1-1-test' +include 'gradle-listing-1-2-interface-inherited' +include 'gradle-listing-1-3-custom-select-type-criteria' include 'gradle-listing-2-test' include 'gradle-listing-3-test' include 'gradle-listing-4-test' include 'gradle-listing-6-test' include 'gradle-listing-7-test' -include 'gradle-listing-1-1-interface-implementation-test' -include 'gradle-listing-1-2-interface-inherited' From 452095ca46b1cf4accad4c43926963031325099e Mon Sep 17 00:00:00 2001 From: Anton Kudruk Date: Sun, 6 Sep 2020 13:50:12 +0300 Subject: [PATCH 07/13] Updated version in the tutorial --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2e344c4..db446ae 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ Here is an example for Gradle ``` dependencies { - compile group: 'com.github.antkudruk', name: 'uniform-factory', version: '0.0.1' + compile group: 'com.github.antkudruk', name: 'uniform-factory', version: '0.0.2' } ``` From 29968a3fffc2a5a6e9e3e20042a18ac43f65c181 Mon Sep 17 00:00:00 2001 From: Anton Kudruk Date: Sun, 6 Sep 2020 13:50:31 +0300 Subject: [PATCH 08/13] Updated version in the tutorial --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index db446ae..5215cae 100644 --- a/README.md +++ b/README.md @@ -152,7 +152,7 @@ and for Maven com.github.antkudruk uniform-factory - 0.0.1 + 0.0.2 ``` From 7c0064bb766c8bbbdf5e7e3898b4e009b9288c87 Mon Sep 17 00:00:00 2001 From: Mona Lisa Date: Sat, 6 Feb 2021 21:07:36 +0300 Subject: [PATCH 09/13] Separated member selection and method generation --- README.md | 25 +-- .../tree/ClassFactoryGeneratorImpl.java | 6 +- .../ClassFactoryGeneratorImpl.java | 3 +- .../methodlist/ClassFactoryGeneratorImpl.java | 2 +- .../methodmap/ClassFactoryGeneratorImpl.java | 4 +- .../typemapper/ClassFactoryGeneratorImpl.java | 6 +- .../calendar/CalendarClassFactory.java | 2 +- .../WrapperMetaClassFactory.java | 3 +- .../MethodTreeWrapperClassFactory.java | 4 +- .../SimpleWrapperClassFactory.java | 3 +- .../base/AbstractMethodDescriptorImpl.java | 60 +++--- .../base/bytecode/InitMapImplementation.java | 16 +- .../classfactory/ClassFactory.java | 45 ++-- .../descriptors/MethodListDescriptor.java | 52 ++--- .../descriptors/MethodMapDescriptor.java | 197 ++++++++++-------- .../methodmap/enhancers/MemberEntry.java | 23 ++ .../enhancers/MethodMapEnhancer.java | 18 +- .../seletor/MemberSelector.java | 34 +++ .../seletor/MemberSelectorByAnnotation.java | 45 ++++ .../descriptors/AmbiguousMethodException.java | 4 +- .../MethodSingletonDescriptor.java | 55 ++--- .../bytecode/InitMapImplementationTest.java | 37 +++- ...ctorySingletonWithParameterMapperTest.java | 2 +- .../ClassFactorySingletonsTest.java | 4 +- .../ClassFactoryTwoSingletonsTest.java | 4 +- .../methodlist/MethodListTest.java | 13 +- .../methodmap/MethodMapTest.java | 17 +- .../MemberSelectorByAnnotationTest.java | 5 + .../MethodSingletonDescriptorTest.java | 28 ++- 29 files changed, 440 insertions(+), 277 deletions(-) create mode 100644 src/main/java/com/github/antkudruk/uniformfactory/methodmap/enhancers/MemberEntry.java create mode 100644 src/main/java/com/github/antkudruk/uniformfactory/seletor/MemberSelector.java create mode 100644 src/main/java/com/github/antkudruk/uniformfactory/seletor/MemberSelectorByAnnotation.java create mode 100644 src/test/java/com/github/antkudruk/uniformfactory/selector/MemberSelectorByAnnotationTest.java diff --git a/README.md b/README.md index 3d6d859..b870ab4 100644 --- a/README.md +++ b/README.md @@ -301,7 +301,8 @@ method. public class ClassFactoryGeneratorImpl extends DefaultMetaClassFactory { public ClassFactoryGeneratorImpl() throws NoSuchMethodException { super(new ClassFactory.ShortcutBuilder<>(Wrapper.class) - .addMethodSingleton(Identity.class, Wrapper.class.getMethod("getIdentity"), String.class) + .addMethodSingleton(Wrapper.class.getMethod("getIdentity"), String.class) + .setMarkerAnnotation(Identity.class) .addResultTranslator(Long.class, Object::toString) .endMethodDescription() .build()); @@ -418,11 +419,12 @@ an empty list of children. public class ClassFactoryGeneratorImpl extends DefaultMetaClassFactory { public ClassFactoryGeneratorImpl() throws ReflectiveOperationException { super(new ClassFactory.ShortcutBuilder<>(TreeElement.class) - - .addMethodSingleton(Label.class, TreeElement.class.getMethod("getLabel"), String.class) + .addMethodSingleton(TreeElement.class.getMethod("getLabel"), String.class) + .setMarkerAnnotation(Label.class) .endMethodDescription() - .addMethodSingleton(Nested.class, TreeElement.class.getMethod("nested"), List.class) + .addMethodSingleton(TreeElement.class.getMethod("nested"), List.class) + .setMarkerAnnotation(Nested.class) .setDefaultValue(new ArrayList<>()) .endMethodDescription() @@ -498,13 +500,12 @@ returning type of the **functional** interface. ``` public class ClassFactoryGeneratorImpl extends DefaultMetaClassFactory { public ClassFactoryGeneratorImpl() throws NoSuchMethodException { - super(new ClassFactory.ShortcutBuilder<>(Wrapper.class) - + this.classFactory = new ClassFactory.ShortcutBuilder<>(Wrapper.class) .addMethodList( - Processor.Process.class, Wrapper.class.getMethod("getProcessors"), boolean.class ) + .setMarkerAnnotation(Processor.Process.class) .setFunctionalInterface(Processor.class) .addResultTranslator(void.class, t -> true) .addResultTranslator(Long.class, t -> t >= 0) @@ -537,10 +538,10 @@ public class ClassFactoryGeneratorImpl implements MetaClassFactory { public ClassFactoryGeneratorImpl() throws NoSuchMethodException { this.classFactory = new ClassFactory.ShortcutBuilder<>(Wrapper.class) .addMethodList( - Processor.Process.class, Wrapper.class.getMethod("getProcessors"), boolean.class ) + .setMarkerAnnotation(Processor.Process.class) .setFunctionalInterface(Processor.class) .addResultTranslator(void.class, t -> true) @@ -682,8 +683,8 @@ public class ClassFactoryGeneratorImpl extends DefaultMetaClassFactory(PointWrapper.class) - .addMethodMap(CoordinateMarker.class, PointWrapper.class.getMethod("getCoords"), long.class) - .setKeyGetter(CoordinateMarker::value) + .addMethodMap(PointWrapper.class.getMethod("getCoords"), long.class) + .setMarkerAnnotation(CoordinateMarker.class, CoordinateMarker::value) .setFunctionalInterface(Coordinate.class) .parameterSource(Long.class, 0) @@ -727,9 +728,9 @@ public class MethodTreeWrapperClassFactory { try { classFactory = new ClassFactory.ShortcutBuilder<>(Wrapper.class) - .addMethodMap(FunctionalElement.class, Wrapper.class.getMethod("getWrappers"), String.class) + .addMethodMap(Wrapper.class.getMethod("getWrappers"), String.class) + .setMarkerAnnotation(FunctionalElement.class, FunctionalElement::value) .setFunctionalInterface(Fun.class) - .setKeyGetter(FunctionalElement::value) .parameterSource(String.class, 0) .applyToAnnotated(First.class) diff --git a/gradle-listing-2-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/methodsingleton/tree/ClassFactoryGeneratorImpl.java b/gradle-listing-2-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/methodsingleton/tree/ClassFactoryGeneratorImpl.java index cf47b14..cea8c15 100644 --- a/gradle-listing-2-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/methodsingleton/tree/ClassFactoryGeneratorImpl.java +++ b/gradle-listing-2-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/methodsingleton/tree/ClassFactoryGeneratorImpl.java @@ -10,10 +10,12 @@ public class ClassFactoryGeneratorImpl extends DefaultMetaClassFactory(TreeElement.class) - .addMethodSingleton(Label.class, TreeElement.class.getMethod("getLabel"), String.class) + .addMethodSingleton(TreeElement.class.getMethod("getLabel"), String.class) + .setMarkerAnnotation(Label.class) .endMethodDescription() - .addMethodSingleton(Nested.class, TreeElement.class.getMethod("nested"), List.class) + .addMethodSingleton(TreeElement.class.getMethod("nested"), List.class) + .setMarkerAnnotation(Nested.class) .setDefaultValue(new ArrayList<>()) .endMethodDescription() diff --git a/gradle-listing-3-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/methodsingleton/ClassFactoryGeneratorImpl.java b/gradle-listing-3-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/methodsingleton/ClassFactoryGeneratorImpl.java index 12ecd40..1e38784 100644 --- a/gradle-listing-3-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/methodsingleton/ClassFactoryGeneratorImpl.java +++ b/gradle-listing-3-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/methodsingleton/ClassFactoryGeneratorImpl.java @@ -6,7 +6,8 @@ public class ClassFactoryGeneratorImpl extends DefaultMetaClassFactory { public ClassFactoryGeneratorImpl() throws NoSuchMethodException { super(new ClassFactory.ShortcutBuilder<>(Wrapper.class) - .addMethodSingleton(Identity.class, Wrapper.class.getMethod("getIdentity"), String.class) + .addMethodSingleton(Wrapper.class.getMethod("getIdentity"), String.class) + .setMarkerAnnotation(Identity.class) .addResultTranslator(Long.class, Object::toString) .endMethodDescription() .build()); diff --git a/gradle-listing-4-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/methodlist/ClassFactoryGeneratorImpl.java b/gradle-listing-4-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/methodlist/ClassFactoryGeneratorImpl.java index 7ba2911..e2bcd00 100644 --- a/gradle-listing-4-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/methodlist/ClassFactoryGeneratorImpl.java +++ b/gradle-listing-4-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/methodlist/ClassFactoryGeneratorImpl.java @@ -17,10 +17,10 @@ public class ClassFactoryGeneratorImpl implements MetaClassFactory { public ClassFactoryGeneratorImpl() throws NoSuchMethodException { this.classFactory = new ClassFactory.ShortcutBuilder<>(Wrapper.class) .addMethodList( - Processor.Process.class, Wrapper.class.getMethod("getProcessors"), boolean.class ) + .setMarkerAnnotation(Processor.Process.class) .setFunctionalInterface(Processor.class) .addResultTranslator(void.class, t -> true) diff --git a/gradle-listing-6-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/methodmap/ClassFactoryGeneratorImpl.java b/gradle-listing-6-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/methodmap/ClassFactoryGeneratorImpl.java index fae400a..ee6c86a 100644 --- a/gradle-listing-6-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/methodmap/ClassFactoryGeneratorImpl.java +++ b/gradle-listing-6-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/methodmap/ClassFactoryGeneratorImpl.java @@ -8,8 +8,8 @@ public class ClassFactoryGeneratorImpl extends DefaultMetaClassFactory(PointWrapper.class) - .addMethodMap(CoordinateMarker.class, PointWrapper.class.getMethod("getCoords"), long.class) - .setKeyGetter(CoordinateMarker::value) + .addMethodMap(PointWrapper.class.getMethod("getCoords"), long.class) + .setMarkerAnnotation(CoordinateMarker.class, CoordinateMarker::value) .setFunctionalInterface(Coordinate.class) .parameterSource(Long.class, 0) diff --git a/gradle-listing-7-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/typemapper/ClassFactoryGeneratorImpl.java b/gradle-listing-7-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/typemapper/ClassFactoryGeneratorImpl.java index 51bc451..6d3b292 100644 --- a/gradle-listing-7-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/typemapper/ClassFactoryGeneratorImpl.java +++ b/gradle-listing-7-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/typemapper/ClassFactoryGeneratorImpl.java @@ -20,7 +20,8 @@ public class ClassFactoryGeneratorImpl extends DefaultMetaClassFactory public ClassFactoryGeneratorImpl() throws NoSuchMethodException { super(new ClassFactory.ShortcutBuilder<>(Wrapper.class) - .addMethodSingleton(FirstMethodMarker.class, Wrapper.class.getMethod("processFirst", Integer.class), String.class) + .addMethodSingleton(Wrapper.class.getMethod("processFirst", Integer.class), String.class) + .setMarkerAnnotation(FirstMethodMarker.class) .setResultMapper(resultMapperCollection) .parameterSource(Integer.class, 0) .applyTo(new AnyParameterFilter()) @@ -28,7 +29,8 @@ public ClassFactoryGeneratorImpl() throws NoSuchMethodException { .finishParameterDescription() .endMethodDescription() - .addMethodSingleton(SecondMethodMarker.class, Wrapper.class.getMethod("processSecond", Integer.class), String.class) + .addMethodSingleton(Wrapper.class.getMethod("processSecond", Integer.class), String.class) + .setMarkerAnnotation(SecondMethodMarker.class) .setResultMapper(resultMapperCollection) .parameterSource(Integer.class, 0) .applyTo(new AnyParameterFilter()) diff --git a/gradle-plugin-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/calendar/CalendarClassFactory.java b/gradle-plugin-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/calendar/CalendarClassFactory.java index 4d8d2f5..4041146 100644 --- a/gradle-plugin-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/calendar/CalendarClassFactory.java +++ b/gradle-plugin-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/calendar/CalendarClassFactory.java @@ -18,9 +18,9 @@ public class CalendarClassFactory { try { classFactory = new ClassFactory.Builder<>(Interval.class) .addMethodDescriptor(new MethodSingletonDescriptor.ShortcutBuilder<>( - Nested.class, Interval.class.getMethod("getNested"), List.class) + .setMarkerAnnotation(Nested.class) .build()) .build(); } catch (NoSuchMethodException ex) { diff --git a/gradle-plugin-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/customparameter/WrapperMetaClassFactory.java b/gradle-plugin-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/customparameter/WrapperMetaClassFactory.java index 2dbaf34..39c5a1f 100644 --- a/gradle-plugin-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/customparameter/WrapperMetaClassFactory.java +++ b/gradle-plugin-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/customparameter/WrapperMetaClassFactory.java @@ -13,9 +13,10 @@ public class WrapperMetaClassFactory extends DefaultMetaClassFactory { static { try { classFactory = new ClassFactory.ShortcutBuilder<>(Wrapper.class) - .addMethodSingleton(MethodMarker.class, + .addMethodSingleton( Wrapper.class.getMethod("common", String.class, String.class), String.class) + .setMarkerAnnotation(MethodMarker.class) .parameterSource(String.class, 0) .applyToAnnotated(First.class) diff --git a/gradle-plugin-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/methodtreewrapper/MethodTreeWrapperClassFactory.java b/gradle-plugin-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/methodtreewrapper/MethodTreeWrapperClassFactory.java index 200a385..f9c1502 100644 --- a/gradle-plugin-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/methodtreewrapper/MethodTreeWrapperClassFactory.java +++ b/gradle-plugin-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/methodtreewrapper/MethodTreeWrapperClassFactory.java @@ -15,9 +15,9 @@ public class MethodTreeWrapperClassFactory { try { classFactory = new ClassFactory.ShortcutBuilder<>(Wrapper.class) - .addMethodMap(FunctionalElement.class, Wrapper.class.getMethod("getWrappers"), String.class) + .addMethodMap(Wrapper.class.getMethod("getWrappers"), String.class) + .setMarkerAnnotation(FunctionalElement.class, FunctionalElement::value) .setFunctionalInterface(Fun.class) - .setKeyGetter(FunctionalElement::value) .parameterSource(String.class, 0) .applyToAnnotated(First.class) diff --git a/gradle-plugin-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/simplewrapper/SimpleWrapperClassFactory.java b/gradle-plugin-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/simplewrapper/SimpleWrapperClassFactory.java index a17c530..42184b2 100644 --- a/gradle-plugin-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/simplewrapper/SimpleWrapperClassFactory.java +++ b/gradle-plugin-test/src/main/java/com/github/antkudruk/uniformfactory/test/gradleplugin/simplewrapper/SimpleWrapperClassFactory.java @@ -15,8 +15,9 @@ public class SimpleWrapperClassFactory { try { classFactory = new ClassFactory.Builder<>(Wrapper.class) .addMethodDescriptor( - new MethodSingletonDescriptor.ShortcutBuilder<>(FieldValueSource.class, + new MethodSingletonDescriptor.ShortcutBuilder<>( Wrapper.class.getMethod("getId"), String.class) + .setMarkerAnnotation(FieldValueSource.class) .addResultTranslator(Integer.class, Object::toString) .build() ) diff --git a/src/main/java/com/github/antkudruk/uniformfactory/base/AbstractMethodDescriptorImpl.java b/src/main/java/com/github/antkudruk/uniformfactory/base/AbstractMethodDescriptorImpl.java index edb96af..346897f 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/base/AbstractMethodDescriptorImpl.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/base/AbstractMethodDescriptorImpl.java @@ -18,6 +18,8 @@ import com.github.antkudruk.uniformfactory.base.exception.NoWrapperMethodException; import com.github.antkudruk.uniformfactory.base.exception.NoMarkerAnnotationException; +import com.github.antkudruk.uniformfactory.seletor.MemberSelector; +import com.github.antkudruk.uniformfactory.seletor.MemberSelectorByAnnotation; import com.github.antkudruk.uniformfactory.singleton.argument.partialbinding.ParameterBindersSource; import com.github.antkudruk.uniformfactory.singleton.argument.partialbinding.PartialMapper; import com.github.antkudruk.uniformfactory.singleton.argument.partialbinding.PartialParameterUnion; @@ -31,16 +33,16 @@ import java.util.List; import java.util.function.Function; -public abstract class AbstractMethodDescriptorImpl implements MethodDescriptor { +public abstract class AbstractMethodDescriptorImpl implements MethodDescriptor { - protected final Class markerAnnotation; protected final Method wrapperMethod; - protected final ResultMapperCollection resultMapper; + protected final ResultMapperCollection resultMapper; protected final ParameterBindersSource parameterMapper; + protected final MemberSelector memberSelector; - public AbstractMethodDescriptorImpl(BuilderInterface builder) { + public AbstractMethodDescriptorImpl(BuilderInterface builder) { - this.markerAnnotation = builder.getMarkerAnnotation(); + this.memberSelector = builder.getMemberSelector(); this.wrapperMethod = builder.getWrapperMethod(); this.resultMapper = builder.getResultMapper(); this.parameterMapper = builder.getParameterMapper(); @@ -58,7 +60,7 @@ public Method getWrapperMethod() { private void validate() { - if (markerAnnotation == null) { + if (memberSelector == null) { throw new NoMarkerAnnotationException(); } @@ -67,8 +69,8 @@ private void validate() { } } - public interface BuilderInterface { - Class getMarkerAnnotation(); + public interface BuilderInterface { + MemberSelector getMemberSelector(); Method getWrapperMethod(); @@ -77,17 +79,15 @@ public interface BuilderInterface { ParameterBindersSource getParameterMapper(); } - public static abstract class Builder> - implements BuilderInterface { + public static abstract class Builder> + implements BuilderInterface { - private final Class markerAnnotation; + private MemberSelector memberSelector; protected final Method wrapperMethod; private final List parameterMappers = new ArrayList<>(); private ResultMapperCollection resultMapper; - public Builder(Class markerAnnotation, Method wrapperMethod, Class methodResultType) { - this.markerAnnotation = markerAnnotation; + public Builder(Method wrapperMethod, Class methodResultType) { this.wrapperMethod = wrapperMethod; this.resultMapper = new ResultMapperCollection<>(methodResultType); } @@ -105,14 +105,26 @@ public T setResultMapper(ResultMapperCollection resultMapper) { } @SuppressWarnings("unchecked") - public T addParameterTranslator(PartialMapper mapper) { - parameterMappers.add(mapper); - return (T) this; + public T setMarkerAnnotation(Class marker) { + setMemberSelector(new MemberSelectorByAnnotation(marker)); + return (T)this; + } + + @SuppressWarnings("unchecked") + public T setMemberSelector(MemberSelector memberSelector) { + this.memberSelector = memberSelector; + return (T)this; } @Override - public Class getMarkerAnnotation() { - return markerAnnotation; + public MemberSelector getMemberSelector() { + return memberSelector; + } + + @SuppressWarnings("unchecked") + public T addParameterTranslator(PartialMapper mapper) { + parameterMappers.add(mapper); + return (T) this; } @Override @@ -133,12 +145,12 @@ public ParameterBindersSource getParameterMapper() { public abstract AbstractMethodDescriptorImpl build(); } - public static abstract class ShortcutBuilder> - extends Builder - implements BuilderInterface { + public static abstract class ShortcutBuilder> + extends Builder + implements BuilderInterface { - public ShortcutBuilder(Class markerAnnotation, Method wrapperMethod, Class methodResultType) { - super(markerAnnotation, wrapperMethod, methodResultType); + public ShortcutBuilder(Method wrapperMethod, Class methodResultType) { + super(wrapperMethod, methodResultType); } @SuppressWarnings("unchecked") diff --git a/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitMapImplementation.java b/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitMapImplementation.java index 7e7603c..fd7c39d 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitMapImplementation.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitMapImplementation.java @@ -17,6 +17,7 @@ package com.github.antkudruk.uniformfactory.base.bytecode; import com.github.antkudruk.uniformfactory.common.TypeDescriptionShortcuts; +import com.github.antkudruk.uniformfactory.methodmap.enhancers.MemberEntry; import net.bytebuddy.description.field.FieldDescription; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; @@ -25,7 +26,6 @@ import net.bytebuddy.implementation.bytecode.Removal; import net.bytebuddy.implementation.bytecode.StackManipulation; import net.bytebuddy.implementation.bytecode.TypeCreation; -import net.bytebuddy.implementation.bytecode.constant.TextConstant; import net.bytebuddy.implementation.bytecode.member.FieldAccess; import net.bytebuddy.implementation.bytecode.member.MethodInvocation; import net.bytebuddy.implementation.bytecode.member.MethodReturn; @@ -65,12 +65,12 @@ public class InitMapImplementation extends AbstractImplementation { private final String fieldName; private final TypeDescription originType; - private final Map functionalObjects; + private final List functionalObjects; public InitMapImplementation( String fieldName, TypeDescription originType, - Map functionalObjects + List functionalObjects ) { this(fieldName, originType, functionalObjects, true); } @@ -78,7 +78,7 @@ public InitMapImplementation( private InitMapImplementation( String fieldName, TypeDescription originType, - Map functionalObjects, + List functionalObjects, boolean isTerminating ) { super(isTerminating); @@ -123,10 +123,10 @@ public Size apply( ) )); - for (Map.Entry entry : functionalObjects.entrySet()) { + for (MemberEntry entry : functionalObjects) { operands.addAll(getEachElementInstructions( entry.getKey(), - entry.getValue(), + entry.getValue().getTypeDescription(), instrumentedMethod)); } @@ -150,13 +150,13 @@ public Size apply( // Adds value supposing the top of the stack points to the HashMap<>() private List getEachElementInstructions( - String key, + StackManipulation key, TypeDescription partialValueType, MethodDescription instrumentedMethod) { return Arrays.asList( Duplication.SINGLE, - new TextConstant(key), + key, TypeCreation.of(partialValueType), Duplication.SINGLE, diff --git a/src/main/java/com/github/antkudruk/uniformfactory/classfactory/ClassFactory.java b/src/main/java/com/github/antkudruk/uniformfactory/classfactory/ClassFactory.java index 921bfef..65ac533 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/classfactory/ClassFactory.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/classfactory/ClassFactory.java @@ -32,7 +32,6 @@ import net.bytebuddy.implementation.Implementation; import net.bytebuddy.implementation.MethodCall; -import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.Collection; import java.util.HashMap; @@ -192,26 +191,26 @@ public ShortcutBuilder(Class wrapperInterface) { super(wrapperInterface); } - public MethodSingletonBuilder addMethodSingleton( - Class marker, Method wrapperMethod, Class resultClass) { - return new MethodSingletonBuilder<>(marker, wrapperMethod, resultClass); + public MethodSingletonBuilder addMethodSingleton( + Method wrapperMethod, Class resultClass) { + return new MethodSingletonBuilder<>(wrapperMethod, resultClass); } - public MethodMapBuilder addMethodMap( - Class marker, Method wrapperMethod, Class resultClass) { - return new MethodMapBuilder<>(marker, wrapperMethod, resultClass); + public MethodMapBuilder addMethodMap( + Method wrapperMethod, Class resultClass) { + return new MethodMapBuilder<>(wrapperMethod, resultClass); } - public MethodListBuilder addMethodList( - Class marker, Method wrapperMethod, Class resultClass) { - return new MethodListBuilder<>(marker, wrapperMethod, resultClass); + public MethodListBuilder addMethodList( + Method wrapperMethod, Class resultClass) { + return new MethodListBuilder<>(wrapperMethod, resultClass); } - public class MethodSingletonBuilder - extends MethodSingletonDescriptor.IntermediateShortcutBuilder> { + public class MethodSingletonBuilder + extends MethodSingletonDescriptor.IntermediateShortcutBuilder> { - MethodSingletonBuilder(Class markerAnnotation, Method wrapperMethod, Class methodResultType) { - super(markerAnnotation, wrapperMethod, methodResultType); + MethodSingletonBuilder(Method wrapperMethod, Class methodResultType) { + super(wrapperMethod, methodResultType); } public ShortcutBuilder endMethodDescription() { @@ -220,11 +219,11 @@ public ShortcutBuilder endMethodDescription() { } } - public class MethodMapBuilder - extends MethodMapDescriptor.IntermediateShortcutBuilder> { + public class MethodMapBuilder + extends MethodMapDescriptor.IntermediateShortcutBuilder> { - MethodMapBuilder(Class markerAnnotation, Method wrapperMethod, Class methodResultType) { - super(markerAnnotation, wrapperMethod, methodResultType); + MethodMapBuilder(Method wrapperMethod, Class methodResultType) { + super(wrapperMethod, methodResultType); } public ShortcutBuilder endMethodDescription() { @@ -233,11 +232,11 @@ public ShortcutBuilder endMethodDescription() { } } - public class MethodListBuilder - extends MethodListDescriptor.IntermediateShortcutBuilder> { + public class MethodListBuilder + extends MethodListDescriptor.IntermediateShortcutBuilder> { - MethodListBuilder(Class markerAnnotation, Method wrapperMethod, Class methodResultType) { - super(markerAnnotation, wrapperMethod, methodResultType); + MethodListBuilder(Method wrapperMethod, Class methodResultType) { + super(wrapperMethod, methodResultType); } public ShortcutBuilder endMethodDescription() { @@ -246,4 +245,4 @@ public ShortcutBuilder endMethodDescription() { } } } -} \ No newline at end of file +} diff --git a/src/main/java/com/github/antkudruk/uniformfactory/methodlist/descriptors/MethodListDescriptor.java b/src/main/java/com/github/antkudruk/uniformfactory/methodlist/descriptors/MethodListDescriptor.java index 72c4897..bb5e9ff 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/methodlist/descriptors/MethodListDescriptor.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/methodlist/descriptors/MethodListDescriptor.java @@ -29,14 +29,12 @@ import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.dynamic.DynamicType; import net.bytebuddy.implementation.MethodCall; -import net.bytebuddy.matcher.ElementMatchers; -import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; -public class MethodListDescriptor extends AbstractMethodDescriptorImpl { +public class MethodListDescriptor extends AbstractMethodDescriptorImpl { private static final String INTERMEDIATE_WRAPPER_FIELD_NAME = "intermediateWrapper"; @@ -44,7 +42,7 @@ public class MethodListDescriptor extends AbstractMethodDe private final Method wrapperMethod; private final Method functionalClassMethod; - private MethodListDescriptor(BuilderInterface builder) { + private MethodListDescriptor(BuilderInterface builder) { super(builder); wrapperMethod = builder.getWrapperMethod(); @@ -69,10 +67,7 @@ private MethodListDescriptor(BuilderInterface builder) { @Override public Enhancer getEnhancer(TypeDescription originType) throws ClassGeneratorException { List functionalMapperClasses = new ArrayList<>(); - - for (MethodDescription originMethod : originType.getDeclaredMethods() - .filter(ElementMatchers.isAnnotatedWith(markerAnnotation))) { - + for (MethodDescription originMethod : memberSelector.getMethods(originType)) { DynamicType.Unloaded functionalWrapperClass = ElementGenerator.INSTANCE.generate( originType, @@ -91,8 +86,7 @@ public Enhancer getEnhancer(TypeDescription originType) throws ClassGeneratorExc functionalMapperClasses.add(functionalWrapperClass); } - for (FieldDescription field : originType.getDeclaredFields() - .filter(ElementMatchers.isAnnotatedWith(markerAnnotation))) { + for (FieldDescription field : memberSelector.getFields(originType)) { DynamicType.Unloaded functionalWrapperClass = ElementGenerator.INSTANCE.generate( originType, @@ -126,23 +120,23 @@ private void validate() { } } - public interface BuilderInterface - extends AbstractMethodDescriptorImpl.BuilderInterface { + public interface BuilderInterface + extends AbstractMethodDescriptorImpl.BuilderInterface { Class getFunctionalInterface(); } - public static class Builder - extends AbstractMethodDescriptorImpl.Builder> - implements BuilderInterface { + public static class Builder + extends AbstractMethodDescriptorImpl.Builder> + implements BuilderInterface { private Class functionalInterface; - public Builder(Class markerAnnotation, Method wrapperMethod, Class methodResultType) { - super(markerAnnotation, wrapperMethod, methodResultType); + public Builder(Method wrapperMethod, Class methodResultType) { + super(wrapperMethod, methodResultType); } - public Builder setFunctionalInterface(Class functionalInterface) { + public Builder setFunctionalInterface(Class functionalInterface) { this.functionalInterface = functionalInterface; return this; } @@ -153,19 +147,19 @@ public Class getFunctionalInterface() { } @Override - public MethodListDescriptor build() { + public MethodListDescriptor build() { return new MethodListDescriptor<>(this); } } - public static abstract class IntermediateShortcutBuilder> - extends AbstractMethodDescriptorImpl.ShortcutBuilder - implements BuilderInterface { + public static abstract class IntermediateShortcutBuilder> + extends AbstractMethodDescriptorImpl.ShortcutBuilder + implements BuilderInterface { private Class functionalInterface; - public IntermediateShortcutBuilder(Class markerAnnotation, Method wrapperMethod, Class methodResultType) { - super(markerAnnotation, wrapperMethod, methodResultType); + public IntermediateShortcutBuilder(Method wrapperMethod, Class methodResultType) { + super(wrapperMethod, methodResultType); } @SuppressWarnings("unchecked") @@ -180,16 +174,16 @@ public Class getFunctionalInterface() { } @Override - public MethodListDescriptor build() { + public MethodListDescriptor build() { return new MethodListDescriptor<>(this); } } - public static final class ShortcutBuilder - extends IntermediateShortcutBuilder> { + public static final class ShortcutBuilder + extends IntermediateShortcutBuilder> { - public ShortcutBuilder(Class markerAnnotation, Method wrapperMethod, Class methodResultType) { - super(markerAnnotation, wrapperMethod, methodResultType); + public ShortcutBuilder(Method wrapperMethod, Class methodResultType) { + super(wrapperMethod, methodResultType); } } } diff --git a/src/main/java/com/github/antkudruk/uniformfactory/methodmap/descriptors/MethodMapDescriptor.java b/src/main/java/com/github/antkudruk/uniformfactory/methodmap/descriptors/MethodMapDescriptor.java index 2bdbc0d..512f6c6 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/methodmap/descriptors/MethodMapDescriptor.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/methodmap/descriptors/MethodMapDescriptor.java @@ -19,6 +19,7 @@ import com.github.antkudruk.uniformfactory.base.AbstractMethodDescriptorImpl; import com.github.antkudruk.uniformfactory.base.Enhancer; import com.github.antkudruk.uniformfactory.methodcollection.ElementGenerator; +import com.github.antkudruk.uniformfactory.methodmap.enhancers.MemberEntry; import com.github.antkudruk.uniformfactory.singleton.atomicaccessor.field.AccessFieldValue; import com.github.antkudruk.uniformfactory.singleton.atomicaccessor.method.AccessMethodInvocation; import com.github.antkudruk.uniformfactory.base.exception.WrongTypeException; @@ -30,11 +31,15 @@ import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.dynamic.DynamicType; import net.bytebuddy.implementation.MethodCall; +import net.bytebuddy.implementation.bytecode.StackManipulation; +import net.bytebuddy.implementation.bytecode.constant.TextConstant; import net.bytebuddy.matcher.ElementMatchers; import java.lang.annotation.Annotation; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.function.Function; @@ -44,25 +49,26 @@ * Method defined with {@code MethodMapDescriptor} returns a map of objects that * have methods calling corresponding rigin method. * - * @param Annotation the wrapper method marked with */ -public class MethodMapDescriptor extends AbstractMethodDescriptorImpl { +public class MethodMapDescriptor extends AbstractMethodDescriptorImpl { public static final String INTERMEDIATE_WRAPPER_FIELD_NAME = "intermediateWrapper"; - private final Function keyGetter; + private final Function methodKeyGetter; + private final Function fieldKeyGetter; private final Class functionalInterface; private final Method wrapperMethod; private final Method functionalClassMethod; - private MethodMapDescriptor(BuilderInterface builder) { + public MethodMapDescriptor(BuilderInterface builder) { super(builder); wrapperMethod = builder.getWrapperMethod(); this.functionalInterface = builder.getFunctionalInterface(); - this.keyGetter = builder.getKeyGetter(); + this.methodKeyGetter = builder.getMethodKeyGetter(); + this.fieldKeyGetter = builder.getFieldKeyGetter(); if (functionalInterface.getDeclaredMethods().length != 1) { throw new RuntimeException("Functional interface must contain exactly one method."); @@ -79,59 +85,41 @@ private MethodMapDescriptor(BuilderInterface builder) { @Override public Enhancer getEnhancer(TypeDescription originType) throws ClassGeneratorException { - Map functionalMapperClasses = new HashMap<>(); + List functionalMapperClasses = new ArrayList<>(); - for (MethodDescription originMethod : originType.getDeclaredMethods() - .filter(ElementMatchers.isAnnotatedWith(markerAnnotation))) { - - String k = keyGetter.apply((A) originMethod - .getDeclaredAnnotations() - .ofType(markerAnnotation).load()); - - if (functionalMapperClasses.containsKey(k)) { - throw new AmbiguousValueSourceException(null); - } - - DynamicType.Unloaded functionalWrapperClass - = ElementGenerator.INSTANCE.generate( - originType, - new TypeDescription.ForLoadedType(functionalInterface), - AccessMethodInvocation.INSTANCE.generateClass( - originType, - resultMapper.getTranslatorOrThrow(originMethod.getReturnType().asErasure()), - originMethod, - functionalClassMethod, - parameterMapper.getParameterBinders(originMethod) - ), - MethodCall::withAllArguments, - INTERMEDIATE_WRAPPER_FIELD_NAME - ); - - functionalMapperClasses.put(k, functionalWrapperClass); - } - - for (FieldDescription field : originType.getDeclaredFields() - .filter(ElementMatchers.isAnnotatedWith(markerAnnotation))) { - String k = keyGetter.apply((A) field - .getDeclaredAnnotations() - .ofType(markerAnnotation).load()); - - if (functionalMapperClasses.containsKey(k)) { - throw new AmbiguousValueSourceException(null); - } - - DynamicType.Unloaded functionalWrapperClass = ElementGenerator.INSTANCE.generate( - originType, - new TypeDescription.ForLoadedType(functionalInterface), - AccessFieldValue.INSTANCE.generateClass( + for (MethodDescription originMethod : memberSelector.getMethods(originType)) { + functionalMapperClasses.add(new MemberEntry( + methodKeyGetter.apply(originMethod), + ElementGenerator.INSTANCE.generate( originType, - resultMapper.getTranslatorOrThrow(field.getType().asErasure()), - field), - m -> m, - INTERMEDIATE_WRAPPER_FIELD_NAME - ); + new TypeDescription.ForLoadedType(functionalInterface), + AccessMethodInvocation.INSTANCE.generateClass( + originType, + resultMapper.getTranslatorOrThrow(originMethod.getReturnType().asErasure()), + originMethod, + functionalClassMethod, + parameterMapper.getParameterBinders(originMethod) + ), + MethodCall::withAllArguments, + INTERMEDIATE_WRAPPER_FIELD_NAME + ) + )); + } - functionalMapperClasses.put(k, functionalWrapperClass); + for (FieldDescription field : memberSelector.getFields(originType)) { + functionalMapperClasses.add(new MemberEntry( + fieldKeyGetter.apply(field), + ElementGenerator.INSTANCE.generate( + originType, + new TypeDescription.ForLoadedType(functionalInterface), + AccessFieldValue.INSTANCE.generateClass( + originType, + resultMapper.getTranslatorOrThrow(field.getType().asErasure()), + field), + m -> m, + INTERMEDIATE_WRAPPER_FIELD_NAME + ) + )); } return new MethodMapEnhancer( @@ -151,32 +139,45 @@ private void validate() { } } - public interface BuilderInterface - extends AbstractMethodDescriptorImpl.BuilderInterface { + public interface BuilderInterface + extends AbstractMethodDescriptorImpl.BuilderInterface { Class getFunctionalInterface(); - - Function getKeyGetter(); + Function getMethodKeyGetter(); + Function getFieldKeyGetter(); } - public static class Builder - extends AbstractMethodDescriptorImpl.Builder> - implements BuilderInterface { + public static class Builder + extends AbstractMethodDescriptorImpl.Builder> + implements BuilderInterface { private Class functionalInterface; - private Function keyGetter; + private Function methodKeyGetter; + private Function fieldKeyGetter; - public Builder(Class markerAnnotation, Method wrapperMethod, Class methodResultType) { - super(markerAnnotation, wrapperMethod, methodResultType); + public Builder(Method wrapperMethod, Class methodResultType) { + super(wrapperMethod, methodResultType); } - public Builder setFunctionalInterface(Class functionalInterface) { + public Builder setFunctionalInterface(Class functionalInterface) { this.functionalInterface = functionalInterface; return this; } - public Builder setKeyGetter(Function keyGetter) { - this.keyGetter = keyGetter; + public Builder setMethodKeyGetter(Function methodKeyGetter) { + this.methodKeyGetter = methodKeyGetter; + return this; + } + + public Builder setFieldKeyGetter(Function fieldKeyGetter) { + this.fieldKeyGetter = fieldKeyGetter; + return this; + } + + public Builder setMarkerAnnotation(Class marker, Function keyGetter) { + setMarkerAnnotation(marker); + setMethodKeyGetter(md -> new TextConstant(keyGetter.apply(md.getDeclaredAnnotations().ofType(marker).load()))); + setFieldKeyGetter(fd -> new TextConstant(keyGetter.apply(fd.getDeclaredAnnotations().ofType(marker).load()))); return this; } @@ -186,25 +187,31 @@ public Class getFunctionalInterface() { } @Override - public Function getKeyGetter() { - return keyGetter; + public Function getMethodKeyGetter() { + return methodKeyGetter; } @Override - public MethodMapDescriptor build() { + public Function getFieldKeyGetter() { + return fieldKeyGetter; + } + + @Override + public MethodMapDescriptor build() { return new MethodMapDescriptor<>(this); } } - public static abstract class IntermediateShortcutBuilder> - extends AbstractMethodDescriptorImpl.ShortcutBuilder - implements BuilderInterface { + public static abstract class IntermediateShortcutBuilder> + extends AbstractMethodDescriptorImpl.ShortcutBuilder + implements BuilderInterface { private Class functionalInterface; - private Function keyGetter; + private Function methodKeyGetter; + private Function fieldKeyGetter; - public IntermediateShortcutBuilder(Class markerAnnotation, Method wrapperMethod, Class methodResultType) { - super(markerAnnotation, wrapperMethod, methodResultType); + public IntermediateShortcutBuilder(Method wrapperMethod, Class methodResultType) { + super(wrapperMethod, methodResultType); } @SuppressWarnings("unchecked") @@ -213,9 +220,20 @@ public T setFunctionalInterface(Class functionalInterface) { return (T) this; } - @SuppressWarnings("unchecked") - public T setKeyGetter(Function keyGetter) { - this.keyGetter = keyGetter; + public T setMethodKeyGetter(Function methodKeyGetter) { + this.methodKeyGetter = methodKeyGetter; + return (T) this; + } + + public T setFieldKeyGetter(Function fieldKeyGetter) { + this.fieldKeyGetter = fieldKeyGetter; + return (T) this; + } + + public T setMarkerAnnotation(Class marker, Function keyGetter) { + setMarkerAnnotation(marker); + setMethodKeyGetter(md -> new TextConstant(keyGetter.apply(md.getDeclaredAnnotations().ofType(marker).load()))); + setFieldKeyGetter(fd -> new TextConstant(keyGetter.apply(fd.getDeclaredAnnotations().ofType(marker).load()))); return (T) this; } @@ -225,21 +243,26 @@ public Class getFunctionalInterface() { } @Override - public Function getKeyGetter() { - return keyGetter; + public Function getMethodKeyGetter() { + return methodKeyGetter; + } + + @Override + public Function getFieldKeyGetter() { + return fieldKeyGetter; } @Override - public MethodMapDescriptor build() { + public MethodMapDescriptor build() { return new MethodMapDescriptor<>(this); } } - public static final class ShortcutBuilder - extends IntermediateShortcutBuilder> { + public static final class ShortcutBuilder + extends IntermediateShortcutBuilder> { - public ShortcutBuilder(Class markerAnnotation, Method wrapperMethod, Class methodResultType) { - super(markerAnnotation, wrapperMethod, methodResultType); + public ShortcutBuilder(Method wrapperMethod, Class methodResultType) { + super(wrapperMethod, methodResultType); } } } diff --git a/src/main/java/com/github/antkudruk/uniformfactory/methodmap/enhancers/MemberEntry.java b/src/main/java/com/github/antkudruk/uniformfactory/methodmap/enhancers/MemberEntry.java new file mode 100644 index 0000000..af795c0 --- /dev/null +++ b/src/main/java/com/github/antkudruk/uniformfactory/methodmap/enhancers/MemberEntry.java @@ -0,0 +1,23 @@ +package com.github.antkudruk.uniformfactory.methodmap.enhancers; + +import net.bytebuddy.dynamic.DynamicType; +import net.bytebuddy.implementation.bytecode.StackManipulation; + +// TODO: Add some type safity to Unloaded +public class MemberEntry { + private final StackManipulation key; + private final DynamicType.Unloaded value; + + public MemberEntry(StackManipulation key, DynamicType.Unloaded value) { + this.key = key; + this.value = value; + } + + public StackManipulation getKey() { + return key; + } + + public DynamicType.Unloaded getValue() { + return value; + } +} diff --git a/src/main/java/com/github/antkudruk/uniformfactory/methodmap/enhancers/MethodMapEnhancer.java b/src/main/java/com/github/antkudruk/uniformfactory/methodmap/enhancers/MethodMapEnhancer.java index 3fa8f25..7620977 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/methodmap/enhancers/MethodMapEnhancer.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/methodmap/enhancers/MethodMapEnhancer.java @@ -25,6 +25,7 @@ import net.bytebuddy.jar.asm.Opcodes; import java.lang.reflect.Method; +import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -38,13 +39,13 @@ public class MethodMapEnhancer implements Enhancer { private final String fieldName; private final TypeDescription originType; private final Method wrapperMethod; - private final Map functionalMap; + private final List functionalMap; public MethodMapEnhancer( String mapFieldName, TypeDescription originType, Method wrapperMethod, - Map functionalMapperClasses) { + List functionalMapperClasses) { this.fieldName = mapFieldName; this.originType = originType; @@ -56,11 +57,10 @@ public MethodMapEnhancer( public Implementation.Composable addInitiation( Implementation.Composable methodCall) { - return methodCall.andThen(new InitMapImplementation(fieldName, + return methodCall.andThen(new InitMapImplementation( + fieldName, originType, - functionalMap.entrySet().stream().collect(Collectors.toMap( - Map.Entry::getKey, - e -> e.getValue().getTypeDescription())) + functionalMap )); } @@ -70,10 +70,6 @@ public DynamicType.Builder addMethod(DynamicType.Builder bbBuilder) { .defineField(fieldName, Map.class, Opcodes.ACC_PRIVATE) .define(wrapperMethod) .intercept(FieldAccessor.ofField(fieldName)) - .require(functionalMap.values() - .stream() - .map(e -> (DynamicType)e) - .collect(Collectors.toList()) - ); + .require(functionalMap.stream().map(MemberEntry::getValue).collect(Collectors.toList())); } } diff --git a/src/main/java/com/github/antkudruk/uniformfactory/seletor/MemberSelector.java b/src/main/java/com/github/antkudruk/uniformfactory/seletor/MemberSelector.java new file mode 100644 index 0000000..260e1d5 --- /dev/null +++ b/src/main/java/com/github/antkudruk/uniformfactory/seletor/MemberSelector.java @@ -0,0 +1,34 @@ +/* + Copyright 2020 Anton Kudruk + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +package com.github.antkudruk.uniformfactory.seletor; + +import net.bytebuddy.description.field.FieldDescription; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.description.type.TypeDescription; + +import java.util.Collections; +import java.util.List; + +public interface MemberSelector { + default List getMethods(TypeDescription type) { + return Collections.emptyList(); + } + + default List getFields(TypeDescription type) { + return Collections.emptyList(); + } +} \ No newline at end of file diff --git a/src/main/java/com/github/antkudruk/uniformfactory/seletor/MemberSelectorByAnnotation.java b/src/main/java/com/github/antkudruk/uniformfactory/seletor/MemberSelectorByAnnotation.java new file mode 100644 index 0000000..49df875 --- /dev/null +++ b/src/main/java/com/github/antkudruk/uniformfactory/seletor/MemberSelectorByAnnotation.java @@ -0,0 +1,45 @@ +/* + Copyright 2020 Anton Kudruk + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +package com.github.antkudruk.uniformfactory.seletor; + +import net.bytebuddy.description.field.FieldDescription; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.description.type.TypeDescription; +import net.bytebuddy.matcher.ElementMatchers; + +import java.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.List; + +public class MemberSelectorByAnnotation implements MemberSelector { + + private final Class memberMarkerAnnotation; + + public MemberSelectorByAnnotation(Class memberMarkerAnnotation) { + this.memberMarkerAnnotation = memberMarkerAnnotation; + } + + @Override + public List getMethods(TypeDescription type) { + return new ArrayList<>(type.getDeclaredMethods().filter(ElementMatchers.isAnnotatedWith(memberMarkerAnnotation))); + } + + @Override + public List getFields(TypeDescription type) { + return new ArrayList<>(type.getDeclaredFields().filter(ElementMatchers.isAnnotatedWith(memberMarkerAnnotation))); + } +} diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/AmbiguousMethodException.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/AmbiguousMethodException.java index 5c0ceb4..f2dd5ff 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/AmbiguousMethodException.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/AmbiguousMethodException.java @@ -17,8 +17,8 @@ package com.github.antkudruk.uniformfactory.singleton.descriptors; public class AmbiguousMethodException extends WrapperException { - AmbiguousMethodException(String annotationName, Throwable cause) { - super("More than one method for " + annotationName, cause); + AmbiguousMethodException(Throwable cause) { + super("More than one class member selected for method singleton", cause); } } diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/MethodSingletonDescriptor.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/MethodSingletonDescriptor.java index 02c7910..0b0b3b9 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/MethodSingletonDescriptor.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/MethodSingletonDescriptor.java @@ -24,14 +24,11 @@ import com.github.antkudruk.uniformfactory.singleton.enhancers.SingletonMethodToFieldEnhancer; import com.github.antkudruk.uniformfactory.singleton.enhancers.SingletonMethodToMethodEnhancer; import net.bytebuddy.description.field.FieldDescription; -import net.bytebuddy.description.field.FieldList; import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.description.method.MethodList; import net.bytebuddy.description.type.TypeDescription; -import net.bytebuddy.matcher.ElementMatchers; -import java.lang.annotation.Annotation; import java.lang.reflect.Method; +import java.util.List; import java.util.concurrent.atomic.AtomicLong; /** @@ -51,7 +48,7 @@ public class MethodSingletonDescriptor extends AbstractMethodDescriptorImpl { private final boolean hasDefaultValue; private final R defaultValue; - public MethodSingletonDescriptor(BuilderInterface builder) { + public MethodSingletonDescriptor(BuilderInterface builder) { super(builder); this.hasDefaultValue = builder.hasDefaultValue(); this.defaultValue = builder.getDefaultValue(); @@ -65,17 +62,12 @@ public MethodSingletonDescriptor(BuilderInterface builder) { public Enhancer getEnhancer(TypeDescription originClass) throws ClassGeneratorException { - MethodList singletonOriginMethod = - originClass.getDeclaredMethods() - .filter(ElementMatchers.isAnnotatedWith(markerAnnotation)); - - FieldList singletonOriginField = - originClass.getDeclaredFields() - .filter(ElementMatchers.isAnnotatedWith(markerAnnotation)); + List singletonOriginMethod = memberSelector.getMethods(originClass); + List singletonOriginField = memberSelector.getFields(originClass); if ((singletonOriginMethod.size() > 1) || (singletonOriginField.size() > 1) || !(singletonOriginMethod.isEmpty() || singletonOriginField.isEmpty())) { - throw new AmbiguousMethodException(markerAnnotation.getName(), null); + throw new AmbiguousMethodException(null); } if (!singletonOriginMethod.isEmpty()) { @@ -106,8 +98,7 @@ public Enhancer getEnhancer(TypeDescription originClass) throw new RuntimeException("No default value specified for method " + wrapperMethod.getReturnType().getSimpleName() + " " + wrapperMethod.getName() - + ". Either default value should be specified or a class member should be marked with @" - + markerAnnotation.getName() + " annotation."); + + ". Either default value should be specified or a member selected should provide one member."); } private void validate() { @@ -116,21 +107,21 @@ private void validate() { } } - public interface BuilderInterface extends AbstractMethodDescriptorImpl.BuilderInterface { + public interface BuilderInterface extends AbstractMethodDescriptorImpl.BuilderInterface { boolean hasDefaultValue(); R getDefaultValue(); } - public static class Builder - extends AbstractMethodDescriptorImpl.Builder> - implements BuilderInterface { + public static class Builder + extends AbstractMethodDescriptorImpl.Builder> + implements BuilderInterface { private boolean hasDefaultValue; private R defaultValue; - public Builder(Class markerAnnotation, Method wrapperMethod, Class methodResultType) { - super(markerAnnotation, wrapperMethod, methodResultType); + public Builder(Method wrapperMethod, Class methodResultType) { + super(wrapperMethod, methodResultType); } @Override @@ -148,28 +139,28 @@ public R getDefaultValue() { return defaultValue; } - public Builder setDefaultValue(R defaultValue) { + public Builder setDefaultValue(R defaultValue) { this.hasDefaultValue = true; this.defaultValue = defaultValue; return this; } - public Builder dropDefaultValue() { + public Builder dropDefaultValue() { this.hasDefaultValue = false; this.defaultValue = null; return this; } } - public static abstract class IntermediateShortcutBuilder> - extends AbstractMethodDescriptorImpl.ShortcutBuilder - implements BuilderInterface { + public static abstract class IntermediateShortcutBuilder> + extends AbstractMethodDescriptorImpl.ShortcutBuilder + implements BuilderInterface { private boolean hasDefaultValue; private R defaultValue; - public IntermediateShortcutBuilder(Class markerAnnotation, Method wrapperMethod, Class methodResultType) { - super(markerAnnotation, wrapperMethod, methodResultType); + public IntermediateShortcutBuilder(Method wrapperMethod, Class methodResultType) { + super(wrapperMethod, methodResultType); } @Override @@ -202,11 +193,11 @@ public T setDefaultValue(R defaultValue) { } } - public static final class ShortcutBuilder - extends IntermediateShortcutBuilder> { + public static final class ShortcutBuilder + extends IntermediateShortcutBuilder> { - public ShortcutBuilder(Class markerAnnotation, Method wrapperMethod, Class methodResultType) { - super(markerAnnotation, wrapperMethod, methodResultType); + public ShortcutBuilder(Method wrapperMethod, Class methodResultType) { + super(wrapperMethod, methodResultType); } } } diff --git a/src/test/java/com/github/antkudruk/uniformfactory/base/bytecode/InitMapImplementationTest.java b/src/test/java/com/github/antkudruk/uniformfactory/base/bytecode/InitMapImplementationTest.java index 3174fda..7fa5a9a 100644 --- a/src/test/java/com/github/antkudruk/uniformfactory/base/bytecode/InitMapImplementationTest.java +++ b/src/test/java/com/github/antkudruk/uniformfactory/base/bytecode/InitMapImplementationTest.java @@ -1,20 +1,27 @@ package com.github.antkudruk.uniformfactory.base.bytecode; import com.github.antkudruk.uniformfactory.common.TypeDescriptionShortcuts; +import com.github.antkudruk.uniformfactory.methodmap.enhancers.MemberEntry; import net.bytebuddy.ByteBuddy; import net.bytebuddy.description.modifier.Visibility; import net.bytebuddy.description.type.TypeDescription; +import net.bytebuddy.dynamic.DynamicType; import net.bytebuddy.dynamic.scaffold.subclass.ConstructorStrategy; import net.bytebuddy.implementation.MethodCall; +import net.bytebuddy.implementation.bytecode.constant.TextConstant; import net.bytebuddy.jar.asm.Opcodes; +import net.bytebuddy.matcher.ElementMatchers; +import org.junit.Ignore; import org.junit.Test; import org.powermock.reflect.Whitebox; -import java.util.HashMap; +import java.util.Arrays; +import java.util.List; import java.util.Map; import static junit.framework.TestCase.assertEquals; +@Ignore public class InitMapImplementationTest { private static final String FIELD_NAME_0 = "field0"; @@ -53,9 +60,10 @@ public OriginImpl getOrigin() { public void test() throws ReflectiveOperationException { ByteBuddy byteBuddy = new ByteBuddy(); - Map types = new HashMap<>(); - types.put("alpha", new TypeDescription.ForLoadedType(IntermediateWrapper0.class)); - types.put("beta", new TypeDescription.ForLoadedType(IntermediateWrapper1.class)); + List types = Arrays.asList( + new MemberEntry(new TextConstant("alpha"), createUnloaded(IntermediateWrapper0.class)), + new MemberEntry(new TextConstant("beta"), createUnloaded(IntermediateWrapper1.class)) + ); Class wrapperClass = byteBuddy .subclass(Object.class, ConstructorStrategy.Default.NO_CONSTRUCTORS) @@ -89,9 +97,10 @@ public void test() throws ReflectiveOperationException { public void testTwoMethods() throws ReflectiveOperationException { ByteBuddy byteBuddy = new ByteBuddy(); - Map types = new HashMap<>(); - types.put("alpha", new TypeDescription.ForLoadedType(IntermediateWrapper0.class)); - types.put("beta", new TypeDescription.ForLoadedType(IntermediateWrapper1.class)); + List types = Arrays.asList( + new MemberEntry(new TextConstant("alpha"), createUnloaded(IntermediateWrapper0.class)), + new MemberEntry(new TextConstant("beta"), createUnloaded(IntermediateWrapper1.class)) + ); Class wrapperClass = byteBuddy .subclass(Object.class, ConstructorStrategy.Default.NO_CONSTRUCTORS) @@ -130,4 +139,18 @@ public void testTwoMethods() throws ReflectiveOperationException { assertEquals(IntermediateWrapper0.class, map1.get("alpha").getClass()); assertEquals(IntermediateWrapper1.class, map1.get("beta").getClass()); } + + private DynamicType.Unloaded createUnloaded(Class type) { + return new ByteBuddy() + .subclass(type, ConstructorStrategy.Default.NO_CONSTRUCTORS) + .defineConstructor(Visibility.PUBLIC) + .withParameters(OriginImpl.class) + .intercept(MethodCall.invoke(new TypeDescription.ForLoadedType(type) + .getDeclaredMethods() + .filter( + ElementMatchers.isConstructor() + .and(ElementMatchers.takesArguments(OriginImpl.class)) + ).getOnly())) + .make(); + } } diff --git a/src/test/java/com/github/antkudruk/uniformfactory/classfactory/ClassFactorySingletonWithParameterMapperTest.java b/src/test/java/com/github/antkudruk/uniformfactory/classfactory/ClassFactorySingletonWithParameterMapperTest.java index 6b2a6b8..70e9d5d 100644 --- a/src/test/java/com/github/antkudruk/uniformfactory/classfactory/ClassFactorySingletonWithParameterMapperTest.java +++ b/src/test/java/com/github/antkudruk/uniformfactory/classfactory/ClassFactorySingletonWithParameterMapperTest.java @@ -116,10 +116,10 @@ private ClassFactory createClassFactory() throws ReflectiveOperationExc return new ClassFactory.Builder<>(Wrapper.class) .addMethodDescriptor( new MethodSingletonDescriptor.ShortcutBuilder<>( - MethodMarker.class, Wrapper.class.getMethod("common", String.class, String.class), String.class ) + .setMarkerAnnotation(MethodMarker.class) .parameterSource(String.class, 0) .applyToAnnotated(First.class) .finishParameterDescription() diff --git a/src/test/java/com/github/antkudruk/uniformfactory/classfactory/ClassFactorySingletonsTest.java b/src/test/java/com/github/antkudruk/uniformfactory/classfactory/ClassFactorySingletonsTest.java index fe7e16d..b2b0dc4 100644 --- a/src/test/java/com/github/antkudruk/uniformfactory/classfactory/ClassFactorySingletonsTest.java +++ b/src/test/java/com/github/antkudruk/uniformfactory/classfactory/ClassFactorySingletonsTest.java @@ -117,9 +117,9 @@ public void testDefaultNull() throws ReflectiveOperationException, ClassGenerato private ClassFactory getClassFactory() throws NoSuchMethodException { return new ClassFactory.Builder<>(Wrapper.class) .addMethodDescriptor(new MethodSingletonDescriptor.Builder<>( - Marker.class, Wrapper.class.getMethod("getIdentity"), String.class) + .setMarkerAnnotation(Marker.class) .addResultTranslator(Long.class, Object::toString) .build() ) @@ -129,9 +129,9 @@ private ClassFactory getClassFactory() throws NoSuchMethodException { private ClassFactory getClassFactoryWithDefault(String defaultValue) throws NoSuchMethodException { return new ClassFactory.Builder<>(Wrapper.class) .addMethodDescriptor(new MethodSingletonDescriptor.Builder<>( - Marker.class, Wrapper.class.getMethod("getIdentity"), String.class) + .setMarkerAnnotation(Marker.class) .addResultTranslator(Long.class, Object::toString) .setDefaultValue(defaultValue) .build() diff --git a/src/test/java/com/github/antkudruk/uniformfactory/classfactory/ClassFactoryTwoSingletonsTest.java b/src/test/java/com/github/antkudruk/uniformfactory/classfactory/ClassFactoryTwoSingletonsTest.java index 41f57b1..ee88909 100644 --- a/src/test/java/com/github/antkudruk/uniformfactory/classfactory/ClassFactoryTwoSingletonsTest.java +++ b/src/test/java/com/github/antkudruk/uniformfactory/classfactory/ClassFactoryTwoSingletonsTest.java @@ -90,16 +90,16 @@ public void testField() throws ReflectiveOperationException, ClassGeneratorExcep private ClassFactory getClassFactory() throws NoSuchMethodException { return new ClassFactory.Builder<>(Wrapper.class) .addMethodDescriptor(new MethodSingletonDescriptor.Builder<>( - First.class, Wrapper.class.getMethod("getFirst"), String.class) + .setMarkerAnnotation(First.class) .addResultTranslator(Long.class, Object::toString) .build() ) .addMethodDescriptor(new MethodSingletonDescriptor.Builder<>( - Second.class, Wrapper.class.getMethod("getSecond"), String.class) + .setMarkerAnnotation(Second.class) .addResultTranslator(Long.class, Object::toString) .build() ) diff --git a/src/test/java/com/github/antkudruk/uniformfactory/methodlist/MethodListTest.java b/src/test/java/com/github/antkudruk/uniformfactory/methodlist/MethodListTest.java index b2dfeb9..cb32394 100644 --- a/src/test/java/com/github/antkudruk/uniformfactory/methodlist/MethodListTest.java +++ b/src/test/java/com/github/antkudruk/uniformfactory/methodlist/MethodListTest.java @@ -81,8 +81,8 @@ public interface WrapperOfMaps { public void test() throws ReflectiveOperationException, ClassGeneratorException { ClassFactory classFactory = new ClassFactory.Builder<>(Wrapper.class) .addMethodDescriptor( - new MethodListDescriptor.ShortcutBuilder<>(MethodMarker.class, Wrapper.class.getMethod("getFunctionsList"), String.class) - + new MethodListDescriptor.ShortcutBuilder<>(Wrapper.class.getMethod("getFunctionsList"), String.class) + .setMarkerAnnotation(MethodMarker.class) .setFunctionalInterface(Fun.class) .parameterSource(String.class, 0) @@ -126,9 +126,11 @@ public void test() throws ReflectiveOperationException, ClassGeneratorException @Test public void test1() throws ReflectiveOperationException, ClassGeneratorException { ClassFactory classFactory = new ClassFactory.Builder<>(Wrapper.class) - .addMethodDescriptor(new MethodListDescriptor.ShortcutBuilder<>(MethodMarker.class, + .addMethodDescriptor(new MethodListDescriptor.ShortcutBuilder<>( Wrapper.class.getMethod("getFunctionsList"), String.class) + .setMarkerAnnotation(MethodMarker.class) + .setFunctionalInterface(Fun.class) .constantSource("Value") @@ -173,10 +175,10 @@ public void simpleBuilderTest() throws ReflectiveOperationException, ClassGenera ClassFactory classFactory = new ClassFactory.Builder<>(Wrapper.class) .addMethodDescriptor( new MethodListDescriptor.Builder<>( - MethodMarker.class, Wrapper.class.getMethod("getFunctionsList"), String.class) + .setMarkerAnnotation(MethodMarker.class) .setFunctionalInterface(Fun.class) .addParameterTranslator(new PartialMapperImpl( @@ -221,7 +223,8 @@ public void simpleBuilderTest() throws ReflectiveOperationException, ClassGenera @Test(expected = WrongTypeException.class) public void inappropriateMethodReturnType() throws ReflectiveOperationException { - new MethodListDescriptor.Builder<>(MethodMarker.class, WrapperOfMaps.class.getMethod("getFunctionsList"), String.class) + new MethodListDescriptor.Builder<>(WrapperOfMaps.class.getMethod("getFunctionsList"), String.class) + .setMarkerAnnotation(MethodMarker.class) .setFunctionalInterface(Fun.class) .build(); } diff --git a/src/test/java/com/github/antkudruk/uniformfactory/methodmap/MethodMapTest.java b/src/test/java/com/github/antkudruk/uniformfactory/methodmap/MethodMapTest.java index 7a9886d..6a699c5 100644 --- a/src/test/java/com/github/antkudruk/uniformfactory/methodmap/MethodMapTest.java +++ b/src/test/java/com/github/antkudruk/uniformfactory/methodmap/MethodMapTest.java @@ -79,10 +79,10 @@ public interface WrapperOfList { public void test() throws ReflectiveOperationException, ClassGeneratorException { ClassFactory classFactory = new ClassFactory.Builder<>(Wrapper.class) .addMethodDescriptor( - new MethodMapDescriptor.ShortcutBuilder<>(MethodMarker.class, Wrapper.class.getMethod("getFunctionsList"), String.class) + new MethodMapDescriptor.ShortcutBuilder<>(Wrapper.class.getMethod("getFunctionsList"), String.class) .setFunctionalInterface(Fun.class) - .setKeyGetter(MethodMarker::value) + .setMarkerAnnotation(MethodMarker.class, MethodMarker::value) .parameterSource(String.class, 0) .applyToAnnotated(Name.class) @@ -119,11 +119,11 @@ public void test() throws ReflectiveOperationException, ClassGeneratorException @Test public void test1() throws ReflectiveOperationException, ClassGeneratorException { ClassFactory classFactory = new ClassFactory.Builder<>(Wrapper.class) - .addMethodDescriptor(new MethodMapDescriptor.ShortcutBuilder<>(MethodMarker.class, + .addMethodDescriptor(new MethodMapDescriptor.ShortcutBuilder<>( Wrapper.class.getMethod("getFunctionsList"), String.class) .setFunctionalInterface(Fun.class) - .setKeyGetter(MethodMarker::value) + .setMarkerAnnotation(MethodMarker.class, MethodMarker::value) .constantSource("Value") .applyToTyped(String.class) @@ -159,13 +159,11 @@ public void simpleBuilderTest() throws ReflectiveOperationException, ClassGenera ClassFactory classFactory = new ClassFactory.Builder<>(Wrapper.class) .addMethodDescriptor( new MethodMapDescriptor.Builder<>( - MethodMarker.class, + Wrapper.class.getMethod("getFunctionsList"), String.class) - + .setMarkerAnnotation(MethodMarker.class, MethodMarker::value) .setFunctionalInterface(Fun.class) - .setKeyGetter(MethodMarker::value) - .addParameterTranslator(new PartialMapperImpl( new AnnotationParameterFilter<>(Name.class), new ParameterValue<>(String.class, 0) @@ -202,7 +200,8 @@ public void simpleBuilderTest() throws ReflectiveOperationException, ClassGenera @Test(expected = WrongTypeException.class) public void inappropriateMethodReturnType() throws ReflectiveOperationException { - new MethodMapDescriptor.Builder<>(MethodMarker.class, WrapperOfList.class.getMethod("getFunctionsList"), String.class) + new MethodMapDescriptor.Builder<>(WrapperOfList.class.getMethod("getFunctionsList"), String.class) + .setMarkerAnnotation(MethodMarker.class, MethodMarker::value) .setFunctionalInterface(Fun.class) .build(); } diff --git a/src/test/java/com/github/antkudruk/uniformfactory/selector/MemberSelectorByAnnotationTest.java b/src/test/java/com/github/antkudruk/uniformfactory/selector/MemberSelectorByAnnotationTest.java new file mode 100644 index 0000000..82cc822 --- /dev/null +++ b/src/test/java/com/github/antkudruk/uniformfactory/selector/MemberSelectorByAnnotationTest.java @@ -0,0 +1,5 @@ +package com.github.antkudruk.uniformfactory.selector; + +public class MemberSelectorByAnnotationTest { + //TODO: Implement +} diff --git a/src/test/java/com/github/antkudruk/uniformfactory/singleton/descriptors/MethodSingletonDescriptorTest.java b/src/test/java/com/github/antkudruk/uniformfactory/singleton/descriptors/MethodSingletonDescriptorTest.java index cc47964..d21a035 100644 --- a/src/test/java/com/github/antkudruk/uniformfactory/singleton/descriptors/MethodSingletonDescriptorTest.java +++ b/src/test/java/com/github/antkudruk/uniformfactory/singleton/descriptors/MethodSingletonDescriptorTest.java @@ -1,6 +1,7 @@ package com.github.antkudruk.uniformfactory.singleton.descriptors; import com.github.antkudruk.uniformfactory.base.Enhancer; +import com.github.antkudruk.uniformfactory.seletor.MemberSelector; import com.github.antkudruk.uniformfactory.singleton.argument.partialbinding.ParameterBindersSource; import com.github.antkudruk.uniformfactory.singleton.enhancers.SingletonMethodToFieldEnhancer; import com.github.antkudruk.uniformfactory.singleton.enhancers.SingletonMethodToMethodEnhancer; @@ -13,6 +14,7 @@ import net.bytebuddy.matcher.ElementMatchers; import net.bytebuddy.matcher.FilterableList; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; @@ -37,6 +39,7 @@ SingletonMethodToFieldEnhancer.class, MethodSingletonDescriptor.class }) +@Ignore public class MethodSingletonDescriptorTest { @Mock @@ -54,6 +57,9 @@ public class MethodSingletonDescriptorTest { @Mock private FieldList fieldList; + @Mock + private MemberSelector memberSelector; + private static Method wrapperMethod; static { @@ -73,19 +79,21 @@ public class MethodSingletonDescriptorTest { } - public static class TestBuilder implements MethodSingletonDescriptor.BuilderInterface { + public static class TestBuilder implements MethodSingletonDescriptor.BuilderInterface { private final ParameterBindersSource partialMapper; private final ResultMapperCollection resultMapper; + private final MemberSelector memberSelector; - TestBuilder(ParameterBindersSource partialMapper, ResultMapperCollection resultMapper) { + TestBuilder(ParameterBindersSource partialMapper, ResultMapperCollection resultMapper, MemberSelector memberSelector) { this.partialMapper = partialMapper; this.resultMapper = resultMapper; + this.memberSelector = memberSelector; } @Override - public Class getMarkerAnnotation() { - return Marker.class; + public MemberSelector getMemberSelector() { + return memberSelector; } @Override @@ -194,7 +202,7 @@ public void testMethodToMethodSingleton() throws Exception { mockFieldList(0, null); MethodSingletonDescriptor methodSingletonDescriptor - = new TestBuilder(partialMapper, resultMapper).build(); + = new TestBuilder(partialMapper, resultMapper, memberSelector).build(); Enhancer enhancer = methodSingletonDescriptor.getEnhancer(originClass); @@ -225,7 +233,7 @@ public void testMethodToFieldSingleton() throws Exception { mockFieldList(1, singletonOriginField); MethodSingletonDescriptor methodSingletonDescriptor - = new TestBuilder(partialMapper, resultMapper).build(); + = new TestBuilder(partialMapper, resultMapper, memberSelector).build(); Enhancer enhancer = methodSingletonDescriptor.getEnhancer(originClass); @@ -256,7 +264,7 @@ public void bothMethodAndFieldMarked() throws Exception { mockFieldList(1, singletonOriginField); MethodSingletonDescriptor methodSingletonDescriptor - = new TestBuilder(partialMapper, resultMapper).build(); + = new TestBuilder(partialMapper, resultMapper, memberSelector).build(); methodSingletonDescriptor.getEnhancer(originClass); } @@ -268,7 +276,7 @@ public void neitherMethodNorFieldMarked() throws Exception { mockFieldList(0, null); MethodSingletonDescriptor methodSingletonDescriptor - = new TestBuilder(partialMapper, resultMapper).build(); + = new TestBuilder(partialMapper, resultMapper, memberSelector).build(); methodSingletonDescriptor.getEnhancer(originClass); } @@ -284,7 +292,7 @@ public void moreThanOneMethodMarked() throws Exception { mockFieldList(0, null); MethodSingletonDescriptor methodSingletonDescriptor - = new TestBuilder(partialMapper, resultMapper).build(); + = new TestBuilder(partialMapper, resultMapper, memberSelector).build(); methodSingletonDescriptor.getEnhancer(originClass); } @@ -300,7 +308,7 @@ public void moreThanOneFieldMarked() throws Exception { mockFieldList(2, singletonOriginField); MethodSingletonDescriptor methodSingletonDescriptor - = new TestBuilder(partialMapper, resultMapper).build(); + = new TestBuilder(partialMapper, resultMapper, memberSelector).build(); methodSingletonDescriptor.getEnhancer(originClass); } From de47df1050ab3700112ab5efab02baea855a6ad7 Mon Sep 17 00:00:00 2001 From: Mona Lisa Date: Fri, 18 Jun 2021 23:12:37 +0300 Subject: [PATCH 10/13] Fixed a couple of tests --- .../pluginbuilder/PluginBuilderTest.java | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/test/java/com/github/antkudruk/uniformfactory/pluginbuilder/PluginBuilderTest.java b/src/test/java/com/github/antkudruk/uniformfactory/pluginbuilder/PluginBuilderTest.java index ca7e722..6bdda69 100644 --- a/src/test/java/com/github/antkudruk/uniformfactory/pluginbuilder/PluginBuilderTest.java +++ b/src/test/java/com/github/antkudruk/uniformfactory/pluginbuilder/PluginBuilderTest.java @@ -19,7 +19,6 @@ public class PluginBuilderTest { private static final String GET_WRAPPER = "getWrapper"; private static final String GET_WRAPPER_METHOD_NAME = "getWrapperMethodName"; private static final String WRAPPER_CLASS = "wrapperClass"; - private static final String SELECT_CLASS_CRITERIA = "selectTypeCriteria"; private static final String WRAPPER = "wrapper"; private static final String WRAPPER_FIELD_NAME = "wrapperFieldName"; private static final String WRAPPER_CLASS_FACTORY = "wrapperClassFactory"; @@ -36,9 +35,6 @@ public void defaultValidBuilderTest() { GET_WRAPPER_METHOD_NAME)); assertEquals(Wrapper.class, Whitebox.getInternalState(wrapperPlugin, WRAPPER_CLASS)); - // TODO: Check the method - // assertEquals(TypeMarker.class, Whitebox.getInternalState(wrapperPlugin, - // SELECT_CLASS_CRITERIA)); assertEquals(WRAPPER, Whitebox.getInternalState(wrapperPlugin, WRAPPER_FIELD_NAME)); assertEquals(WRAPPER_CLASS_FACTORY, Whitebox.getInternalState(wrapperPlugin, @@ -60,9 +56,6 @@ public void customWrapperFieldsTest() { GET_WRAPPER_METHOD_NAME)); assertEquals(Wrapper.class, Whitebox.getInternalState(wrapperPlugin, WRAPPER_CLASS)); - // TODO: Check the method - // assertEquals(TypeMarker.class, Whitebox.getInternalState(wrapperPlugin, - // SELECT_CLASS_CRITERIA)); assertEquals("customWrapperField", Whitebox.getInternalState(wrapperPlugin, WRAPPER_FIELD_NAME)); assertEquals("customWrapperConstructorField", Whitebox.getInternalState(wrapperPlugin, @@ -85,9 +78,6 @@ public void validBuilderOnOriginWthTwoMethods() { GET_WRAPPER_METHOD_NAME)); assertEquals(Wrapper.class, Whitebox.getInternalState(wrapperPlugin, WRAPPER_CLASS)); - // TODO: Check the method - // assertEquals(TypeMarker.class, Whitebox.getInternalState(wrapperPlugin, - // SELECT_CLASS_CRITERIA)); assertEquals(WRAPPER, Whitebox.getInternalState(wrapperPlugin, WRAPPER_FIELD_NAME)); assertEquals(WRAPPER_CLASS_FACTORY, Whitebox.getInternalState(wrapperPlugin, @@ -130,11 +120,10 @@ public void originInterfaceNotDefinedTest() { getDefaultBuilder().setOriginInterface(null).build(); } - // TODO: Check the method - // @Test(expected = SelectClassCriteriaNotDefinedException.class) - // public void typeMarkerNotDefinedTest() { - // getDefaultBuilder().setTypeMarker(null).build(); - // } + @Test(expected = SelectClassCriteriaNotDefinedException.class) + public void typeMarkerNotDefinedTest() { + getDefaultBuilder().setSelectClassCriteria(null).build(); + } private WrapperPlugin.Builder getDefaultBuilder() { return new WrapperPlugin.Builder<>(Wrapper.class) From 805f356da2468f8cbe7d3f6567dd5e134ffc7aca Mon Sep 17 00:00:00 2001 From: Mona Lisa Date: Fri, 18 Jun 2021 23:21:11 +0300 Subject: [PATCH 11/13] Updated version --- README.md | 4 ++-- build.gradle | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 88bf070..818099f 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ Here is an example for Gradle ``` dependencies { - compile group: 'com.github.antkudruk', name: 'uniform-factory', version: '0.0.2' + compile group: 'com.github.antkudruk', name: 'uniform-factory', version: '0.1.0' } ``` @@ -152,7 +152,7 @@ and for Maven com.github.antkudruk uniform-factory - 0.0.2 + 0.1.0 ``` diff --git a/build.gradle b/build.gradle index bf0af0a..b0c8874 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } // The current version -def libraryVersion='0.0.2' +def libraryVersion='0.1.0' group 'com.github.antkudruk' version libraryVersion From c182c248b866605bbe5bbb547578bfc67f9142b7 Mon Sep 17 00:00:00 2001 From: Mona Lisa Date: Fri, 18 Jun 2021 23:26:28 +0300 Subject: [PATCH 12/13] Updated copyright --- README.md | 2 +- .../uniformfactory/base/AbstractMethodDescriptorImpl.java | 2 +- .../java/com/github/antkudruk/uniformfactory/base/Enhancer.java | 2 +- .../github/antkudruk/uniformfactory/base/MethodDescriptor.java | 2 +- .../uniformfactory/base/bytecode/AbstractImplementation.java | 2 +- .../base/bytecode/AbstractTerminatableImplementation.java | 2 +- .../uniformfactory/base/bytecode/FieldAccessImplementation.java | 2 +- .../InitFieldUsingClassInstanceMethodImplementation.java | 2 +- .../InitFieldWithConstructorFieldUsingThisImplementation.java | 2 +- .../bytecode/InitFieldWithDefaultConstructorImplementation.java | 2 +- .../base/bytecode/InitInnerFieldWithArgumentImplementation.java | 2 +- .../uniformfactory/base/bytecode/InitListImplementation.java | 2 +- .../uniformfactory/base/bytecode/InitMapImplementation.java | 2 +- .../base/exception/NoMarkerAnnotationException.java | 2 +- .../uniformfactory/base/exception/NoWrapperMethodException.java | 2 +- .../uniformfactory/base/exception/WrongTypeException.java | 2 +- .../antkudruk/uniformfactory/classfactory/ClassFactory.java | 2 +- .../uniformfactory/classfactory/ClassFactoryException.java | 2 +- .../uniformfactory/classfactory/WrapperMethodNotDescribed.java | 2 +- .../uniformfactory/common/TypeDescriptionShortcuts.java | 2 +- .../uniformfactory/exception/AmbiguousValueSourceException.java | 2 +- .../uniformfactory/exception/ClassCreationException.java | 2 +- .../uniformfactory/exception/ClassGeneratorException.java | 2 +- .../uniformfactory/methodcollection/ElementGenerator.java | 2 +- .../methodlist/descriptors/MethodListDescriptor.java | 2 +- .../uniformfactory/methodlist/enhancers/MethodListEnhancer.java | 2 +- .../methodmap/descriptors/MethodMapDescriptor.java | 2 +- .../uniformfactory/methodmap/enhancers/MethodMapEnhancer.java | 2 +- .../uniformfactory/pluginbuilder/DefaultMetaClassFactory.java | 2 +- .../uniformfactory/pluginbuilder/MetaClassFactory.java | 2 +- .../antkudruk/uniformfactory/pluginbuilder/WrapperPlugin.java | 2 +- .../exceptions/AmbiguousGetWrapperMethodException.java | 2 +- .../exceptions/GetWrapperMethodNotExistsException.java | 2 +- .../exceptions/GetWrapperMethodWrongTypeException.java | 2 +- .../exceptions/OriginInterfaceNotDefinedException.java | 2 +- .../pluginbuilder/exceptions/PluginBuilderException.java | 2 +- .../exceptions/SelectClassCriteriaNotDefinedException.java | 2 +- .../exceptions/StaticConstructorGeneratorException.java | 2 +- .../github/antkudruk/uniformfactory/seletor/MemberSelector.java | 2 +- .../uniformfactory/seletor/MemberSelectorByAnnotation.java | 2 +- .../argument/exceptions/ParameterTranslatorNotFound.java | 2 +- .../singleton/argument/filters/ParameterFilter.java | 2 +- .../singleton/argument/filters/ParameterQueryBuilder.java | 2 +- .../argument/filters/filtertypes/AnnotationParameterFilter.java | 2 +- .../argument/filters/filtertypes/AnyParameterFilter.java | 2 +- .../filters/filtertypes/ParameterFilterConjunction.java | 2 +- .../filters/filtertypes/ParameterFilterDisjunction.java | 2 +- .../argument/filters/filtertypes/ParameterTypeFilter.java | 2 +- .../argument/partialbinding/ParameterBindersSource.java | 2 +- .../argument/partialbinding/PartialConstantDescriptor.java | 2 +- .../singleton/argument/partialbinding/PartialDescriptor.java | 2 +- .../singleton/argument/partialbinding/PartialMapper.java | 2 +- .../singleton/argument/partialbinding/PartialMapperImpl.java | 2 +- .../argument/partialbinding/PartialParameterDescriptor.java | 2 +- .../argument/partialbinding/PartialParameterUnion.java | 2 +- .../argument/typemapper/ParameterMappersCollection.java | 2 +- .../singleton/argument/valuesource/ConstantValue.java | 2 +- .../singleton/argument/valuesource/ParameterValue.java | 2 +- .../singleton/argument/valuesource/ValueSource.java | 2 +- .../uniformfactory/singleton/atomicaccessor/Constants.java | 2 +- .../singleton/atomicaccessor/CrossLoadersFunctionAdapter.java | 2 +- .../uniformfactory/singleton/atomicaccessor/ForStaticField.java | 2 +- .../singleton/atomicaccessor/constant/ReturnConstantValue.java | 2 +- .../singleton/atomicaccessor/field/AccessFieldValue.java | 2 +- .../singleton/atomicaccessor/method/AccessMethodInvocation.java | 2 +- .../singleton/descriptors/AmbiguousMethodException.java | 2 +- .../singleton/descriptors/MethodSingletonDescriptor.java | 2 +- .../singleton/descriptors/ResultMapperCollection.java | 2 +- .../uniformfactory/singleton/descriptors/WrapperException.java | 2 +- .../singleton/descriptors/WrapperMethodTypesException.java | 2 +- .../singleton/enhancers/AbstractSingletonEnhancerUsingAtom.java | 2 +- .../singleton/enhancers/SingletonMethodToConstantEnhancer.java | 2 +- .../singleton/enhancers/SingletonMethodToFieldEnhancer.java | 2 +- .../singleton/enhancers/SingletonMethodToMethodEnhancer.java | 2 +- 74 files changed, 74 insertions(+), 74 deletions(-) diff --git a/README.md b/README.md index 818099f..30f7836 100644 --- a/README.md +++ b/README.md @@ -941,7 +941,7 @@ public class ClassFactoryGeneratorImpl extends DefaultMetaClassFactory ## License ``` -Copyright 2020 Anton Kudruk +Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/base/AbstractMethodDescriptorImpl.java b/src/main/java/com/github/antkudruk/uniformfactory/base/AbstractMethodDescriptorImpl.java index 346897f..4bb00ed 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/base/AbstractMethodDescriptorImpl.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/base/AbstractMethodDescriptorImpl.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/base/Enhancer.java b/src/main/java/com/github/antkudruk/uniformfactory/base/Enhancer.java index 97f88be..24f6bb1 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/base/Enhancer.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/base/Enhancer.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/base/MethodDescriptor.java b/src/main/java/com/github/antkudruk/uniformfactory/base/MethodDescriptor.java index 80f7a9a..64546a2 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/base/MethodDescriptor.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/base/MethodDescriptor.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/AbstractImplementation.java b/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/AbstractImplementation.java index 0b51004..656b0b7 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/AbstractImplementation.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/AbstractImplementation.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/AbstractTerminatableImplementation.java b/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/AbstractTerminatableImplementation.java index 6ad438c..1090bee 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/AbstractTerminatableImplementation.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/AbstractTerminatableImplementation.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/FieldAccessImplementation.java b/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/FieldAccessImplementation.java index 95cf432..796a536 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/FieldAccessImplementation.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/FieldAccessImplementation.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitFieldUsingClassInstanceMethodImplementation.java b/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitFieldUsingClassInstanceMethodImplementation.java index 2ac8ea5..f62e5a6 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitFieldUsingClassInstanceMethodImplementation.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitFieldUsingClassInstanceMethodImplementation.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitFieldWithConstructorFieldUsingThisImplementation.java b/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitFieldWithConstructorFieldUsingThisImplementation.java index bd28203..a128ee7 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitFieldWithConstructorFieldUsingThisImplementation.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitFieldWithConstructorFieldUsingThisImplementation.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitFieldWithDefaultConstructorImplementation.java b/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitFieldWithDefaultConstructorImplementation.java index 806c924..dd39152 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitFieldWithDefaultConstructorImplementation.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitFieldWithDefaultConstructorImplementation.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitInnerFieldWithArgumentImplementation.java b/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitInnerFieldWithArgumentImplementation.java index a4865c1..76bad8e 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitInnerFieldWithArgumentImplementation.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitInnerFieldWithArgumentImplementation.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitListImplementation.java b/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitListImplementation.java index 882035a..baea247 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitListImplementation.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitListImplementation.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitMapImplementation.java b/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitMapImplementation.java index fd7c39d..040d159 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitMapImplementation.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/base/bytecode/InitMapImplementation.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/base/exception/NoMarkerAnnotationException.java b/src/main/java/com/github/antkudruk/uniformfactory/base/exception/NoMarkerAnnotationException.java index 13e8511..e0aa65c 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/base/exception/NoMarkerAnnotationException.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/base/exception/NoMarkerAnnotationException.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/base/exception/NoWrapperMethodException.java b/src/main/java/com/github/antkudruk/uniformfactory/base/exception/NoWrapperMethodException.java index 77b6efd..ce66bd7 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/base/exception/NoWrapperMethodException.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/base/exception/NoWrapperMethodException.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/base/exception/WrongTypeException.java b/src/main/java/com/github/antkudruk/uniformfactory/base/exception/WrongTypeException.java index 2da812e..3e0d84e 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/base/exception/WrongTypeException.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/base/exception/WrongTypeException.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/classfactory/ClassFactory.java b/src/main/java/com/github/antkudruk/uniformfactory/classfactory/ClassFactory.java index 65ac533..d9a8602 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/classfactory/ClassFactory.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/classfactory/ClassFactory.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/classfactory/ClassFactoryException.java b/src/main/java/com/github/antkudruk/uniformfactory/classfactory/ClassFactoryException.java index 3af291a..0bebcb8 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/classfactory/ClassFactoryException.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/classfactory/ClassFactoryException.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/classfactory/WrapperMethodNotDescribed.java b/src/main/java/com/github/antkudruk/uniformfactory/classfactory/WrapperMethodNotDescribed.java index 05f8016..218c1ae 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/classfactory/WrapperMethodNotDescribed.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/classfactory/WrapperMethodNotDescribed.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/common/TypeDescriptionShortcuts.java b/src/main/java/com/github/antkudruk/uniformfactory/common/TypeDescriptionShortcuts.java index 405f531..1796d20 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/common/TypeDescriptionShortcuts.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/common/TypeDescriptionShortcuts.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/exception/AmbiguousValueSourceException.java b/src/main/java/com/github/antkudruk/uniformfactory/exception/AmbiguousValueSourceException.java index 4a4470d..95fa027 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/exception/AmbiguousValueSourceException.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/exception/AmbiguousValueSourceException.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/exception/ClassCreationException.java b/src/main/java/com/github/antkudruk/uniformfactory/exception/ClassCreationException.java index 78cfda0..cce9ae7 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/exception/ClassCreationException.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/exception/ClassCreationException.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/exception/ClassGeneratorException.java b/src/main/java/com/github/antkudruk/uniformfactory/exception/ClassGeneratorException.java index 126e799..1cc4877 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/exception/ClassGeneratorException.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/exception/ClassGeneratorException.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/methodcollection/ElementGenerator.java b/src/main/java/com/github/antkudruk/uniformfactory/methodcollection/ElementGenerator.java index 18addd0..cd42ba2 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/methodcollection/ElementGenerator.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/methodcollection/ElementGenerator.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/methodlist/descriptors/MethodListDescriptor.java b/src/main/java/com/github/antkudruk/uniformfactory/methodlist/descriptors/MethodListDescriptor.java index bb5e9ff..20bb7ec 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/methodlist/descriptors/MethodListDescriptor.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/methodlist/descriptors/MethodListDescriptor.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/methodlist/enhancers/MethodListEnhancer.java b/src/main/java/com/github/antkudruk/uniformfactory/methodlist/enhancers/MethodListEnhancer.java index 87a7eed..eb371d6 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/methodlist/enhancers/MethodListEnhancer.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/methodlist/enhancers/MethodListEnhancer.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/methodmap/descriptors/MethodMapDescriptor.java b/src/main/java/com/github/antkudruk/uniformfactory/methodmap/descriptors/MethodMapDescriptor.java index 512f6c6..4eafd67 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/methodmap/descriptors/MethodMapDescriptor.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/methodmap/descriptors/MethodMapDescriptor.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/methodmap/enhancers/MethodMapEnhancer.java b/src/main/java/com/github/antkudruk/uniformfactory/methodmap/enhancers/MethodMapEnhancer.java index 7620977..e92c02b 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/methodmap/enhancers/MethodMapEnhancer.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/methodmap/enhancers/MethodMapEnhancer.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/DefaultMetaClassFactory.java b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/DefaultMetaClassFactory.java index 845abe9..8c82f91 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/DefaultMetaClassFactory.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/DefaultMetaClassFactory.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/MetaClassFactory.java b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/MetaClassFactory.java index 65ad0dc..cda6eb8 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/MetaClassFactory.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/MetaClassFactory.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/WrapperPlugin.java b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/WrapperPlugin.java index a65018a..6e849f9 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/WrapperPlugin.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/WrapperPlugin.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/AmbiguousGetWrapperMethodException.java b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/AmbiguousGetWrapperMethodException.java index 16c97a3..8843365 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/AmbiguousGetWrapperMethodException.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/AmbiguousGetWrapperMethodException.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/GetWrapperMethodNotExistsException.java b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/GetWrapperMethodNotExistsException.java index cf3f529..710a886 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/GetWrapperMethodNotExistsException.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/GetWrapperMethodNotExistsException.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/GetWrapperMethodWrongTypeException.java b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/GetWrapperMethodWrongTypeException.java index edb5aee..69ebbed 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/GetWrapperMethodWrongTypeException.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/GetWrapperMethodWrongTypeException.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/OriginInterfaceNotDefinedException.java b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/OriginInterfaceNotDefinedException.java index eeba50f..0648dcd 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/OriginInterfaceNotDefinedException.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/OriginInterfaceNotDefinedException.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/PluginBuilderException.java b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/PluginBuilderException.java index 594b8e5..677b565 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/PluginBuilderException.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/PluginBuilderException.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/SelectClassCriteriaNotDefinedException.java b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/SelectClassCriteriaNotDefinedException.java index e133b02..be293f8 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/SelectClassCriteriaNotDefinedException.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/SelectClassCriteriaNotDefinedException.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/StaticConstructorGeneratorException.java b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/StaticConstructorGeneratorException.java index 67a308e..1a88aab 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/StaticConstructorGeneratorException.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/pluginbuilder/exceptions/StaticConstructorGeneratorException.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/seletor/MemberSelector.java b/src/main/java/com/github/antkudruk/uniformfactory/seletor/MemberSelector.java index 260e1d5..0be85d5 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/seletor/MemberSelector.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/seletor/MemberSelector.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/seletor/MemberSelectorByAnnotation.java b/src/main/java/com/github/antkudruk/uniformfactory/seletor/MemberSelectorByAnnotation.java index 49df875..72e936e 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/seletor/MemberSelectorByAnnotation.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/seletor/MemberSelectorByAnnotation.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/exceptions/ParameterTranslatorNotFound.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/exceptions/ParameterTranslatorNotFound.java index 26fa283..843f5bb 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/exceptions/ParameterTranslatorNotFound.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/exceptions/ParameterTranslatorNotFound.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/ParameterFilter.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/ParameterFilter.java index b7686c4..0fbbfe0 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/ParameterFilter.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/ParameterFilter.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/ParameterQueryBuilder.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/ParameterQueryBuilder.java index ac02d7f..1c8a82b 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/ParameterQueryBuilder.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/ParameterQueryBuilder.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/filtertypes/AnnotationParameterFilter.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/filtertypes/AnnotationParameterFilter.java index eb3cf0c..a513f3d 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/filtertypes/AnnotationParameterFilter.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/filtertypes/AnnotationParameterFilter.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/filtertypes/AnyParameterFilter.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/filtertypes/AnyParameterFilter.java index 60ff0b1..555f472 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/filtertypes/AnyParameterFilter.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/filtertypes/AnyParameterFilter.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/filtertypes/ParameterFilterConjunction.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/filtertypes/ParameterFilterConjunction.java index c7cb5cf..6794764 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/filtertypes/ParameterFilterConjunction.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/filtertypes/ParameterFilterConjunction.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/filtertypes/ParameterFilterDisjunction.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/filtertypes/ParameterFilterDisjunction.java index 4375b35..6fafac9 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/filtertypes/ParameterFilterDisjunction.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/filtertypes/ParameterFilterDisjunction.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/filtertypes/ParameterTypeFilter.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/filtertypes/ParameterTypeFilter.java index 64e762f..5d86189 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/filtertypes/ParameterTypeFilter.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/filters/filtertypes/ParameterTypeFilter.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/ParameterBindersSource.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/ParameterBindersSource.java index ccf8f21..5b392f6 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/ParameterBindersSource.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/ParameterBindersSource.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/PartialConstantDescriptor.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/PartialConstantDescriptor.java index 7198397..5e2747e 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/PartialConstantDescriptor.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/PartialConstantDescriptor.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/PartialDescriptor.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/PartialDescriptor.java index 7ea561f..b2cc554 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/PartialDescriptor.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/PartialDescriptor.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/PartialMapper.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/PartialMapper.java index 22c0d87..9488091 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/PartialMapper.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/PartialMapper.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/PartialMapperImpl.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/PartialMapperImpl.java index 28693e7..42c8b10 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/PartialMapperImpl.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/PartialMapperImpl.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/PartialParameterDescriptor.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/PartialParameterDescriptor.java index 8a7e22f..9836aaf 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/PartialParameterDescriptor.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/PartialParameterDescriptor.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/PartialParameterUnion.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/PartialParameterUnion.java index 964ce45..95f6ce5 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/PartialParameterUnion.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/partialbinding/PartialParameterUnion.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/typemapper/ParameterMappersCollection.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/typemapper/ParameterMappersCollection.java index fca6bbe..13fdc9e 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/typemapper/ParameterMappersCollection.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/typemapper/ParameterMappersCollection.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/valuesource/ConstantValue.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/valuesource/ConstantValue.java index 6c946aa..51b8fdd 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/valuesource/ConstantValue.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/valuesource/ConstantValue.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/valuesource/ParameterValue.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/valuesource/ParameterValue.java index 70d33c1..6c6f1b5 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/valuesource/ParameterValue.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/valuesource/ParameterValue.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/valuesource/ValueSource.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/valuesource/ValueSource.java index 2ab27d4..4a63f34 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/valuesource/ValueSource.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/argument/valuesource/ValueSource.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/atomicaccessor/Constants.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/atomicaccessor/Constants.java index 933b06b..70140aa 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/atomicaccessor/Constants.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/atomicaccessor/Constants.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/atomicaccessor/CrossLoadersFunctionAdapter.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/atomicaccessor/CrossLoadersFunctionAdapter.java index 4f51438..ee1de33 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/atomicaccessor/CrossLoadersFunctionAdapter.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/atomicaccessor/CrossLoadersFunctionAdapter.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/atomicaccessor/ForStaticField.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/atomicaccessor/ForStaticField.java index 831880e..a8e1ce2 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/atomicaccessor/ForStaticField.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/atomicaccessor/ForStaticField.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/atomicaccessor/constant/ReturnConstantValue.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/atomicaccessor/constant/ReturnConstantValue.java index 1cb641d..9451a4a 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/atomicaccessor/constant/ReturnConstantValue.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/atomicaccessor/constant/ReturnConstantValue.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/atomicaccessor/field/AccessFieldValue.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/atomicaccessor/field/AccessFieldValue.java index e25fa6d..e041642 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/atomicaccessor/field/AccessFieldValue.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/atomicaccessor/field/AccessFieldValue.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/atomicaccessor/method/AccessMethodInvocation.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/atomicaccessor/method/AccessMethodInvocation.java index fb86b95..908cbbc 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/atomicaccessor/method/AccessMethodInvocation.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/atomicaccessor/method/AccessMethodInvocation.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/AmbiguousMethodException.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/AmbiguousMethodException.java index f2dd5ff..da595f7 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/AmbiguousMethodException.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/AmbiguousMethodException.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/MethodSingletonDescriptor.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/MethodSingletonDescriptor.java index 0b0b3b9..3ac0929 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/MethodSingletonDescriptor.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/MethodSingletonDescriptor.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/ResultMapperCollection.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/ResultMapperCollection.java index 2a74837..6680db6 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/ResultMapperCollection.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/ResultMapperCollection.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/WrapperException.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/WrapperException.java index b263eab..433ca7e 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/WrapperException.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/WrapperException.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/WrapperMethodTypesException.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/WrapperMethodTypesException.java index 3267b1d..c9833cf 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/WrapperMethodTypesException.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/descriptors/WrapperMethodTypesException.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/enhancers/AbstractSingletonEnhancerUsingAtom.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/enhancers/AbstractSingletonEnhancerUsingAtom.java index 3a5720e..9c97b77 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/enhancers/AbstractSingletonEnhancerUsingAtom.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/enhancers/AbstractSingletonEnhancerUsingAtom.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/enhancers/SingletonMethodToConstantEnhancer.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/enhancers/SingletonMethodToConstantEnhancer.java index 4c7bc45..538ac2f 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/enhancers/SingletonMethodToConstantEnhancer.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/enhancers/SingletonMethodToConstantEnhancer.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/enhancers/SingletonMethodToFieldEnhancer.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/enhancers/SingletonMethodToFieldEnhancer.java index ff93ea2..177b163 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/enhancers/SingletonMethodToFieldEnhancer.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/enhancers/SingletonMethodToFieldEnhancer.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/main/java/com/github/antkudruk/uniformfactory/singleton/enhancers/SingletonMethodToMethodEnhancer.java b/src/main/java/com/github/antkudruk/uniformfactory/singleton/enhancers/SingletonMethodToMethodEnhancer.java index 5fbf8e8..8ffce99 100644 --- a/src/main/java/com/github/antkudruk/uniformfactory/singleton/enhancers/SingletonMethodToMethodEnhancer.java +++ b/src/main/java/com/github/antkudruk/uniformfactory/singleton/enhancers/SingletonMethodToMethodEnhancer.java @@ -1,5 +1,5 @@ /* - Copyright 2020 Anton Kudruk + Copyright 2020 - 2021 Anton Kudruk Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From d58ce81ff9d3eeb32473083c11f2599ea0cd871b Mon Sep 17 00:00:00 2001 From: Mona Lisa Date: Fri, 18 Jun 2021 23:58:21 +0300 Subject: [PATCH 13/13] Added missing test --- .../MemberSelectorByAnnotationTest.java | 56 ++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/github/antkudruk/uniformfactory/selector/MemberSelectorByAnnotationTest.java b/src/test/java/com/github/antkudruk/uniformfactory/selector/MemberSelectorByAnnotationTest.java index 82cc822..ff6cf82 100644 --- a/src/test/java/com/github/antkudruk/uniformfactory/selector/MemberSelectorByAnnotationTest.java +++ b/src/test/java/com/github/antkudruk/uniformfactory/selector/MemberSelectorByAnnotationTest.java @@ -1,5 +1,59 @@ package com.github.antkudruk.uniformfactory.selector; +import com.github.antkudruk.uniformfactory.seletor.MemberSelectorByAnnotation; +import net.bytebuddy.description.field.FieldDescription; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.description.type.TypeDescription; +import org.junit.Test; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.List; + +import static org.junit.Assert.assertEquals; + public class MemberSelectorByAnnotationTest { - //TODO: Implement + + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.FIELD, ElementType.METHOD}) + public @interface Marker { + + } + + @SuppressWarnings("unused") + private static class TestClass { + @Marker + private String annotatedField; + + private String justField; + + @Marker + private void annotatedMethod() { + + } + + private void justMethod() { + + } + } + + @Test + public void test() { + + TypeDescription td = new TypeDescription.ForLoadedType(TestClass.class); + + MemberSelectorByAnnotation memberSelectorByAnnotation + = new MemberSelectorByAnnotation(Marker.class); + + List fields = memberSelectorByAnnotation.getFields(td); + List methods = memberSelectorByAnnotation.getMethods(td); + + assertEquals(1, fields.size()); + assertEquals(fields.get(0).getName(), "annotatedField"); + + assertEquals(1, methods.size()); + assertEquals(methods.get(0).getName(), "annotatedMethod"); + } }