Search in sources :

Example 26 with ElementType

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

the class ActionControllerTest method testCallPublicMethodWithElementTypeParams.

/**
 * End UUID Type Related Integration Test
 */
/**
 * Start ElementType Type Related Integration Test
 */
@Test(dataProvider = ENDPOINTS_DATAPROVIDER, description = "Tests if an public action method with ElementType param can be called")
public void testCallPublicMethodWithElementTypeParams(String containerType, String endpoint) {
    final ElementType value = ElementType.PARAMETER;
    performActionForElementType(containerType, endpoint, PUBLIC_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)

Example 27 with ElementType

use of java.lang.annotation.ElementType in project wire by square.

the class JavaGenerator method generateOptionType.

// Example:
// 
// @Retention(RetentionPolicy.RUNTIME)
// @Target(ElementType.FIELD)
// public @interface MyFieldOption {
// String value();
// }
@Nullable
public TypeSpec generateOptionType(Extend extend, Field field) {
    checkArgument(extend.getFields().contains(field));
    if (!emitDeclaredOptions)
        return null;
    ElementType elementType = annotationTargetType(extend);
    if (elementType == null)
        return null;
    if (!eligibleAsAnnotationMember(schema, field))
        return null;
    TypeName returnType = typeName(field.getType());
    ClassName javaType = generatedTypeName(field);
    TypeSpec.Builder builder = TypeSpec.annotationBuilder(javaType.simpleName()).addModifiers(PUBLIC).addAnnotation(AnnotationSpec.builder(Retention.class).addMember("value", "$T.$L", RetentionPolicy.class, RetentionPolicy.RUNTIME).build()).addAnnotation(AnnotationSpec.builder(Target.class).addMember("value", "$T.$L", ElementType.class, elementType).build());
    if (!field.getDocumentation().isEmpty()) {
        builder.addJavadoc("$L\n", field.getDocumentation());
    }
    builder.addMethod(MethodSpec.methodBuilder("value").returns(returnType).addModifiers(PUBLIC, ABSTRACT).build());
    return builder.build();
}
Also used : ElementType(java.lang.annotation.ElementType) TypeName(com.squareup.javapoet.TypeName) WildcardTypeName(com.squareup.javapoet.WildcardTypeName) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) Target(java.lang.annotation.Target) ClassName(com.squareup.javapoet.ClassName) RetentionPolicy(java.lang.annotation.RetentionPolicy) TypeSpec(com.squareup.javapoet.TypeSpec) Nullable(javax.annotation.Nullable)

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