Search in sources :

Example 31 with Annotation

use of java.lang.annotation.Annotation in project neo4j by neo4j.

the class PluginPointFactoryImpl method createFrom.

public PluginPoint createFrom(ServerPlugin plugin, Method method, Class<?> discovery) {
    ResultConverter result = ResultConverter.get(method.getGenericReturnType());
    Type[] types = method.getGenericParameterTypes();
    Annotation[][] annotations = method.getParameterAnnotations();
    SourceExtractor sourceExtractor = null;
    DataExtractor[] extractors = new DataExtractor[types.length];
    for (int i = 0; i < types.length; i++) {
        Description description = null;
        Parameter param = null;
        Source source = null;
        for (Annotation annotation : annotations[i]) {
            if (annotation instanceof Description) {
                description = (Description) annotation;
            } else if (annotation instanceof Parameter) {
                param = (Parameter) annotation;
            } else if (annotation instanceof Source) {
                source = (Source) annotation;
            }
        }
        if (param != null && source != null) {
            throw new IllegalStateException(String.format("Method parameter %d of %s cannot be retrieved as both Parameter and Source", Integer.valueOf(i), method));
        } else if (source != null) {
            if (types[i] != discovery) {
                throw new IllegalStateException("Source parameter type (" + types[i] + ") must equal the discovery type (" + discovery.getName() + ").");
            }
            if (sourceExtractor != null) {
                throw new IllegalStateException("Server Extension methods may have at most one Source parameter.");
            }
            extractors[i] = sourceExtractor = new SourceExtractor(source, description);
        } else if (param != null) {
            extractors[i] = parameterExtractor(types[i], param, description);
        } else {
            throw new IllegalStateException("Parameters of Server Extension methods must be annotated as either Source or Parameter.");
        }
    }
    return new PluginMethod(nameOf(method), discovery, plugin, result, method, extractors, method.getAnnotation(Description.class));
}
Also used : Annotation(java.lang.annotation.Annotation) GenericArrayType(java.lang.reflect.GenericArrayType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) RelationshipType(org.neo4j.graphdb.RelationshipType)

Example 32 with Annotation

use of java.lang.annotation.Annotation in project jodd by oblac.

the class InvReplTest method testReplacement.

@Test
public void testReplacement() throws IllegalAccessException, InstantiationException, NoSuchMethodException, IOException {
    InvokeProxetta proxetta = initProxetta();
    String className = One.class.getCanonicalName();
    byte[] klazz = proxetta.builder(One.class).create();
    //FileUtil.writeBytes("/Users/igor/OneClone.class", klazz);
    FastByteArrayOutputStream fbaos = new FastByteArrayOutputStream();
    //		PrintStream out = System.out;
    System.setOut(new PrintStream(fbaos));
    One one = (One) ClassLoaderUtil.defineClass((new StringBuilder()).append(className).append(JoddProxetta.invokeProxyClassNameSuffix).toString(), klazz).newInstance();
    // clone ctor calls super ctor,
    assertEquals("one ctor!one ctor!", fbaos.toString());
    fbaos.reset();
    one.example1();
    assertEquals("REPLACED VIRTUAL! jodd.proxetta.inv.Two * one!173>overriden sub", fbaos.toString());
    fbaos.reset();
    one.example2();
    assertEquals("REPLACED STATIC! one * jodd/proxetta/inv/Two * example2 * void example2() * jodd.proxetta.inv.One * jodd.proxetta.inv.One$$Clonetou!15013static: 4", fbaos.toString());
    fbaos.reset();
    one.example3();
    assertEquals("state = REPLACED ctor!", fbaos.toString());
    fbaos.reset();
    assertEquals("jodd.proxetta.inv.One$$Clonetou", one.getClass().getName());
    assertTrue(one instanceof Serializable);
    Annotation[] anns = one.getClass().getAnnotations();
    assertEquals(3, anns.length);
    Method ms = one.getClass().getMethod("example1");
    anns = ms.getAnnotations();
    assertEquals(1, anns.length);
}
Also used : PrintStream(java.io.PrintStream) Serializable(java.io.Serializable) FastByteArrayOutputStream(jodd.io.FastByteArrayOutputStream) Method(java.lang.reflect.Method) InvokeProxetta(jodd.proxetta.impl.InvokeProxetta) Annotation(java.lang.annotation.Annotation) Test(org.junit.Test)

Example 33 with Annotation

use of java.lang.annotation.Annotation in project jodd by oblac.

the class ScopeDataResolver method inspectMethodParameterScopeData.

// ---------------------------------------------------------------- inspect method
/**
	 * Inspects all method parameters for scope type.
	 */
protected ScopeData inspectMethodParameterScopeData(String name, Class type, Annotation[] annotations, ScopeType scopeType) {
    ScopeData sd = new ScopeData();
    int count = 0;
    for (Annotation annotation : annotations) {
        if (annotation instanceof In) {
            ScopeData.In scopeDataIn = inspectIn((In) annotation, scopeType, name, type);
            if (scopeDataIn != null) {
                count++;
                sd.in = new ScopeData.In[] { scopeDataIn };
            }
        } else if (annotation instanceof Out) {
            ScopeData.Out scopeDataOut = inspectOut((Out) annotation, scopeType, name, type);
            if (scopeDataOut != null) {
                count++;
                sd.out = new ScopeData.Out[] { scopeDataOut };
            }
        } else if (annotation instanceof InOut) {
            ScopeData.In scopeDataIn = inspectIn((InOut) annotation, scopeType, name, type);
            if (scopeDataIn != null) {
                count++;
                sd.in = new ScopeData.In[] { scopeDataIn };
            }
            ScopeData.Out scopeDataOut = inspectOut((InOut) annotation, scopeType, name, type);
            if (scopeDataOut != null) {
                count++;
                sd.out = new ScopeData.Out[] { scopeDataOut };
            }
        }
    }
    if (count == 0) {
        return null;
    }
    return sd;
}
Also used : In(jodd.madvoc.meta.In) ScopeData(jodd.madvoc.ScopeData) Annotation(java.lang.annotation.Annotation) InOut(jodd.madvoc.meta.InOut) Out(jodd.madvoc.meta.Out) InOut(jodd.madvoc.meta.InOut)

Example 34 with Annotation

use of java.lang.annotation.Annotation in project java-chassis by ServiceComb.

the class OperationGenerator method scanMethodAnnotation.

protected void scanMethodAnnotation() {
    for (Annotation annotation : providerMethod.getAnnotations()) {
        MethodAnnotationProcessor processor = context.findMethodAnnotationProcessor(annotation.annotationType());
        if (processor == null) {
            continue;
        }
        processor.process(annotation, this);
    }
}
Also used : Annotation(java.lang.annotation.Annotation)

Example 35 with Annotation

use of java.lang.annotation.Annotation in project cradle by BingLau7.

the class TableCreator method create.

private static void create(String[] args) throws Exception {
    if (args.length < 1) {
        System.out.println("arguments: anotated classes");
        System.exit(0);
    }
    for (String className : args) {
        Class<?> cl = Class.forName(className);
        DBTable dbTable = cl.getAnnotation(DBTable.class);
        if (dbTable == null) {
            System.out.println("No DBTable annotations in class " + className);
            continue;
        }
        String tableName = dbTable.name();
        if (tableName.length() < 1)
            tableName = cl.getName().toUpperCase();
        List<String> columnDefs = new ArrayList<String>();
        for (Field field : cl.getDeclaredFields()) {
            String columnName = null;
            Annotation[] anns = field.getDeclaredAnnotations();
            if (anns.length < 1)
                continue;
            if (anns[0] instanceof SQLInteger) {
                SQLInteger sInt = (SQLInteger) anns[0];
                if (sInt.name().length() < 1)
                    columnName = field.getName().toUpperCase();
                else
                    columnName = sInt.name();
                columnDefs.add(columnName + " INT " + getConstraints(sInt.constraints()));
            }
            if (anns[0] instanceof SQLString) {
                SQLString sString = (SQLString) anns[0];
                if (sString.name().length() < 1)
                    columnName = field.getName().toUpperCase();
                else
                    columnName = sString.name();
                columnDefs.add(columnName + " VARCHAR(" + sString.value() + ")" + getConstraints(sString.constraints()));
            }
            StringBuilder createCommand = new StringBuilder("CREATE TABLE " + tableName + "(");
            for (String columnDef : columnDefs) {
                createCommand.append("\n    " + columnDef + ",");
                String tableCreate = createCommand.substring(0, createCommand.length() - 1) + ");";
                System.out.println("Table Creation SQL for " + className + " is :\n" + tableCreate);
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) ArrayList(java.util.ArrayList) Annotation(java.lang.annotation.Annotation)

Aggregations

Annotation (java.lang.annotation.Annotation)1784 Method (java.lang.reflect.Method)412 ArrayList (java.util.ArrayList)245 Field (java.lang.reflect.Field)172 Test (org.junit.Test)164 Type (java.lang.reflect.Type)149 HashMap (java.util.HashMap)146 HashSet (java.util.HashSet)129 Map (java.util.Map)95 List (java.util.List)92 IOException (java.io.IOException)71 Set (java.util.Set)71 ParameterizedType (java.lang.reflect.ParameterizedType)62 InvocationTargetException (java.lang.reflect.InvocationTargetException)53 Collection (java.util.Collection)52 LinkedHashMap (java.util.LinkedHashMap)36 Collectors (java.util.stream.Collectors)36 Constructor (java.lang.reflect.Constructor)33 LinkedHashSet (java.util.LinkedHashSet)32 Optional (java.util.Optional)32