Search in sources :

Example 21 with ElementType

use of java.lang.annotation.ElementType in project querydsl by querydsl.

the class ScalaWriterTest method Annotation_With_ArrayMethod.

@Test
public void Annotation_With_ArrayMethod() throws IOException {
    Target annotation = new Target() {

        @Override
        public ElementType[] value() {
            return new ElementType[] { ElementType.FIELD, ElementType.METHOD };
        }

        @Override
        public Class<? extends Annotation> annotationType() {
            return Target.class;
        }
    };
    writer.imports(Target.class.getPackage());
    writer.annotation(annotation);
    assertTrue(w.toString().contains("@Target(Array(FIELD, METHOD))"));
}
Also used : Target(java.lang.annotation.Target) ElementType(java.lang.annotation.ElementType) Test(org.junit.Test)

Example 22 with ElementType

use of java.lang.annotation.ElementType in project querydsl by querydsl.

the class JavaWriterTest method Annotation_With_ArrayMethod.

@Test
public void Annotation_With_ArrayMethod() throws IOException {
    Target annotation = new Target() {

        @Override
        public ElementType[] value() {
            return new ElementType[] { ElementType.FIELD, ElementType.METHOD };
        }

        @Override
        public Class<? extends Annotation> annotationType() {
            return Target.class;
        }
    };
    writer.imports(Target.class.getPackage());
    writer.annotation(annotation);
    assertTrue(w.toString().contains("@Target({FIELD, METHOD})"));
}
Also used : Target(java.lang.annotation.Target) ElementType(java.lang.annotation.ElementType) Test(org.junit.Test)

Example 23 with ElementType

use of java.lang.annotation.ElementType in project groovy-core by groovy.

the class Java5 method configureAnnotationFromDefinition.

public static void configureAnnotationFromDefinition(AnnotationNode definition, AnnotationNode root) {
    ClassNode type = definition.getClassNode();
    if ("java.lang.annotation.Retention".equals(type.getName())) {
        Expression exp = definition.getMember("value");
        if (!(exp instanceof PropertyExpression))
            return;
        PropertyExpression pe = (PropertyExpression) exp;
        String name = pe.getPropertyAsString();
        RetentionPolicy policy = RetentionPolicy.valueOf(name);
        setRetentionPolicy(policy, root);
    } else if ("java.lang.annotation.Target".equals(type.getName())) {
        Expression exp = definition.getMember("value");
        if (!(exp instanceof ListExpression))
            return;
        ListExpression le = (ListExpression) exp;
        int bitmap = 0;
        for (Expression e : le.getExpressions()) {
            if (!(e instanceof PropertyExpression))
                return;
            PropertyExpression element = (PropertyExpression) e;
            String name = element.getPropertyAsString();
            ElementType value = ElementType.valueOf(name);
            bitmap |= getElementCode(value);
        }
        root.setAllowedTargets(bitmap);
    }
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) ElementType(java.lang.annotation.ElementType) ListExpression(org.codehaus.groovy.ast.expr.ListExpression) PropertyExpression(org.codehaus.groovy.ast.expr.PropertyExpression) ConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression) Expression(org.codehaus.groovy.ast.expr.Expression) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression) ListExpression(org.codehaus.groovy.ast.expr.ListExpression) PropertyExpression(org.codehaus.groovy.ast.expr.PropertyExpression) RetentionPolicy(java.lang.annotation.RetentionPolicy)

Example 24 with ElementType

use of java.lang.annotation.ElementType in project dolphin-platform by canoo.

the class ActionTestControllerTest method callPublicMethodWithElementTypeParam.

/**
 * End UUID Type Related Action Test
 */
/**
 * Start ElementType Type Related Action Test
 */
@Test
public void callPublicMethodWithElementTypeParam() {
    Assert.assertNull(controller.getModel().getEnumValue());
    final ElementType value = ElementType.FIELD;
    controller.invoke(PUBLIC_WITH_ELEMENT_TYPE_PARAM_ACTION, new Param(PARAM_NAME, value));
    Assert.assertEquals(controller.getModel().getEnumValue(), value);
}
Also used : ElementType(java.lang.annotation.ElementType) Param(com.canoo.platform.remoting.client.Param) Test(org.testng.annotations.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SpringTestNGControllerTest(com.canoo.platform.spring.test.SpringTestNGControllerTest) ControllerUnderTest(com.canoo.platform.spring.test.ControllerUnderTest)

Example 25 with ElementType

use of java.lang.annotation.ElementType in project dolphin-platform by canoo.

the class ActionControllerTest method testCallPrivateMethodWithElementTypeParams.

@Test(dataProvider = ENDPOINTS_DATAPROVIDER, description = "Tests if an private action method with ElementType param can be called")
public void testCallPrivateMethodWithElementTypeParams(String containerType, String endpoint) {
    final ElementType value = ElementType.METHOD;
    performActionForElementType(containerType, endpoint, PRIVATE_WITH_ELEMENT_TYPE_PARAM_ACTION, value, new Param(PARAM_NAME, value));
}
Also used : ElementType(java.lang.annotation.ElementType) Param(com.canoo.platform.remoting.client.Param) Test(org.testng.annotations.Test)

Aggregations

ElementType (java.lang.annotation.ElementType)27 Target (java.lang.annotation.Target)15 RetentionPolicy (java.lang.annotation.RetentionPolicy)7 ClassExpression (org.codehaus.groovy.ast.expr.ClassExpression)6 ConstantExpression (org.codehaus.groovy.ast.expr.ConstantExpression)6 Expression (org.codehaus.groovy.ast.expr.Expression)6 ListExpression (org.codehaus.groovy.ast.expr.ListExpression)6 PropertyExpression (org.codehaus.groovy.ast.expr.PropertyExpression)6 Param (com.canoo.platform.remoting.client.Param)4 Retention (java.lang.annotation.Retention)4 Method (java.lang.reflect.Method)4 Test (org.testng.annotations.Test)4 ClassNode (org.codehaus.groovy.ast.ClassNode)3 ControllerUnderTest (com.canoo.platform.spring.test.ControllerUnderTest)2 SpringTestNGControllerTest (com.canoo.platform.spring.test.SpringTestNGControllerTest)2 ClassName (com.squareup.javapoet.ClassName)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Nullable (javax.annotation.Nullable)2