List of usage examples for javax.lang.model.type TypeKind VOID
TypeKind VOID
To view the source code for javax.lang.model.type TypeKind VOID.
Click Source Link
From source file:com.googlecode.androidannotations.helper.ValidatorHelper.java
public void returnTypeIsVoidOrBoolean(ExecutableElement executableElement, IsValid valid) { TypeMirror returnType = executableElement.getReturnType(); TypeKind returnKind = returnType.getKind(); if (returnKind != TypeKind.BOOLEAN && returnKind != TypeKind.VOID && !returnType.toString().equals("java.lang.Boolean")) { valid.invalidate();//from w ww . ja v a 2s . c o m annotationHelper.printAnnotationError(executableElement, "%s can only be used on a method with a boolean or a void return type"); } }
From source file:org.androidannotations.helper.ValidatorHelper.java
public void returnTypeIsVoidOrBoolean(ExecutableElement executableElement, IsValid valid) { TypeMirror returnType = executableElement.getReturnType(); TypeKind returnKind = returnType.getKind(); if (returnKind != TypeKind.BOOLEAN && returnKind != TypeKind.VOID && !returnType.toString().equals(CanonicalNameConstants.BOOLEAN)) { valid.invalidate();/* w w w . j a va 2 s . com*/ annotationHelper.printAnnotationError(executableElement, "%s can only be used on a method with a boolean or a void return type"); } }
From source file:com.googlecode.androidannotations.helper.ValidatorHelper.java
public void returnTypeIsVoid(ExecutableElement executableElement, IsValid valid) { TypeMirror returnType = executableElement.getReturnType(); if (returnType.getKind() != TypeKind.VOID) { valid.invalidate();/*from w ww . j a v a 2 s. c o m*/ annotationHelper.printAnnotationError(executableElement, "%s can only be used on a method with a void return type"); } }
From source file:org.androidannotations.helper.ValidatorHelper.java
public void doesNotHaveTraceAnnotationAndReturnValue(ExecutableElement executableElement, AnnotationElements validatedElements, IsValid valid) { TypeMirror returnType = executableElement.getReturnType(); if (elementHasAnnotation(Trace.class, executableElement, validatedElements) && returnType.getKind() != TypeKind.VOID) { annotationHelper.printAnnotationError(executableElement, "@WakeLock annotated methods with a return value are not supported by @Trace"); }/*from w ww .ja v a 2s.co m*/ }
From source file:org.androidannotations.helper.ValidatorHelper.java
public void returnTypeIsNotVoid(ExecutableElement executableElement, IsValid valid) { TypeMirror returnType = executableElement.getReturnType(); if (returnType.getKind() == TypeKind.VOID) { valid.invalidate();/* w ww . ja v a 2 s . co m*/ annotationHelper.printAnnotationError(executableElement, "%s can only be used on a method with a return type non void"); } }
From source file:org.jsweet.transpiler.util.Util.java
/** * Returns the literal for a given type inital value. *//*from w w w . j ava 2s .c o m*/ public static String getTypeInitialValue(Type type) { if (type == null) { return "null"; } if (isNumber(type)) { return "0"; } else if (type.getKind() == TypeKind.BOOLEAN) { return "false"; } else if (type.getKind() == TypeKind.VOID) { return null; } else { return "null"; } }
From source file:auto.parse.processor.AutoParseProcessor.java
private List<ExecutableElement> methodsToImplement(List<ExecutableElement> methods, Map<String, Object> vars) throws CompileException { List<ExecutableElement> toImplement = new ArrayList<ExecutableElement>(); boolean errors = false; for (ExecutableElement method : methods) { if (method.getModifiers().contains(Modifier.ABSTRACT) && !isToStringOrEqualsOrHashCode(method) && !isFromParcelable(method)) { if (method.getParameters().isEmpty() && method.getReturnType().getKind() != TypeKind.VOID && (method.getSimpleName().toString().startsWith("get"))) { if (isReferenceArrayType(method.getReturnType())) { reportError("An @AutoParse class cannot define an array-valued property unless it is " + "a byte array", method); errors = true;/*from w w w. j av a2s. c om*/ } toImplement.add(method); } else if ((method.getParameters().size() == 1) && (method.getReturnType().getKind() != TypeKind.VOID) && (method.getSimpleName().toString().startsWith("get"))) { if (!method.getParameters().get(0).asType().equals(method.getReturnType())) { reportError("An @AutoParse class cannot define an default-value that is difference" + "to return-value ", method); errors = true; } toImplement.add(method); } else if ((method.getParameters().size() == 1) && isSuperType(method.getReturnType(), ((TypeElement) vars.get("type")).asType()) && (method.getSimpleName().toString().startsWith("set"))) { if (isReferenceArrayType(method.getParameters().get(0).asType())) { reportError("An @AutoParse class cannot define an array-valued property unless it is " + "a byte array", method); errors = true; } toImplement.add(method); } else { reportError( "@AutoParse classes cannot have abstract methods other than property getters and setters", method); errors = true; } } } if (errors) { throw new CompileException(); } return toImplement; }
From source file:org.kie.workbench.common.forms.adf.processors.FormDefinitionsProcessor.java
private boolean isGetter(final ExecutableElement method) { String name = method.getSimpleName().toString(); if (method.getReturnType().getKind().equals(TypeKind.VOID)) { return false; }/*from www. j av a 2 s . c o m*/ int parameterCount = method.getParameters().size(); if (parameterCount != 0) { return false; } return (name.length() > 3 && name.startsWith("get")); }
From source file:org.versly.rest.wsdoc.AnnotationProcessor.java
String jsonSchemaFromTypeMirror(TypeMirror type) { String serializedSchema = null; if (type.getKind().isPrimitive() || type.getKind() == TypeKind.VOID) { return null; }/*from w w w . ja va 2s.c o m*/ // we need the dto class to generate schema using jackson json-schema module // note: Types.erasure() provides canonical names whereas Class.forName() wants a "regular" name, // so forName will fail for nested and inner classes as "regular" names use $ between parent and child. Class dtoClass = null; StringBuffer erasure = new StringBuffer(_typeUtils.erasure(type).toString()); for (boolean done = false; !done;) { try { dtoClass = Class.forName(erasure.toString()); done = true; } catch (ClassNotFoundException e) { if (erasure.lastIndexOf(".") != -1) { erasure.setCharAt(erasure.lastIndexOf("."), '$'); } else { done = true; } } } // if we were able to figure out the dto class, use jackson json-schema module to serialize it Exception e = null; if (dtoClass != null) { try { ObjectMapper m = new ObjectMapper(); m.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); m.registerModule(new JodaModule()); SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); m.acceptJsonFormatVisitor(m.constructType(dtoClass), visitor); serializedSchema = m.writeValueAsString(visitor.finalSchema()); } catch (Exception ex) { e = ex; } } // report warning if we were not able to generate schema for non-primitive type if (serializedSchema == null) { this.processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, "cannot generate json-schema for class " + type.toString() + " (erasure " + erasure + "), " + ((e != null) ? ("exception: " + e.getMessage()) : "class not found")); } return serializedSchema; }
From source file:org.androidannotations.helper.ValidatorHelper.java
public void unannotatedMethodReturnsRestTemplate(TypeElement typeElement, IsValid valid) { List<? extends Element> enclosedElements = typeElement.getEnclosedElements(); boolean foundGetRestTemplateMethod = false; boolean foundSetRestTemplateMethod = false; boolean foundSetAuthenticationMethod = false; boolean foundSetBearerAuthMethod = false; boolean foundSetRootUrlMethod = false; boolean foundGetCookieMethod = false; boolean foundGetHeaderMethod = false; boolean foundGetRootUrlMethod = false; for (Element enclosedElement : enclosedElements) { if (enclosedElement.getKind() != ElementKind.METHOD) { valid.invalidate();//from ww w.j av a2s . co m annotationHelper.printError(enclosedElement, "Only methods are allowed in a " + TargetAnnotationHelper.annotationName(Rest.class) + " annotated interface"); } else { boolean hasRestAnnotation = false; for (Class<? extends Annotation> annotationClass : REST_ANNOTATION_CLASSES) { if (enclosedElement.getAnnotation(annotationClass) != null) { hasRestAnnotation = true; break; } } if (!hasRestAnnotation) { ExecutableElement executableElement = (ExecutableElement) enclosedElement; TypeMirror returnType = executableElement.getReturnType(); String simpleName = executableElement.getSimpleName().toString(); if (returnType.toString().equals(CanonicalNameConstants.REST_TEMPLATE)) { if (executableElement.getParameters().size() > 0) { valid.invalidate(); annotationHelper.printError(enclosedElement, "The method returning a RestTemplate should not declare any parameter in a " + TargetAnnotationHelper.annotationName(Rest.class) + " annotated interface"); } else { if (foundGetRestTemplateMethod) { valid.invalidate(); annotationHelper.printError(enclosedElement, "Only one method should declare returning a RestTemplate in a " + TargetAnnotationHelper.annotationName(Rest.class) + " annotated interface"); } else { foundGetRestTemplateMethod = true; } } } else if (simpleName.equals(METHOD_NAME_GET_ROOT_URL)) { if (!returnType.toString().equals(CanonicalNameConstants.STRING)) { valid.invalidate(); annotationHelper.printError(enclosedElement, "The method getRootUrl must return String on a " + TargetAnnotationHelper.annotationName(Rest.class) + " annotated interface"); } if (executableElement.getParameters().size() != 0) { valid.invalidate(); annotationHelper.printError(enclosedElement, "The method getRootUrl cannot have parameters on a " + TargetAnnotationHelper.annotationName(Rest.class) + " annotated interface"); } if (!foundGetRootUrlMethod) { foundGetRootUrlMethod = true; } else { valid.invalidate(); annotationHelper.printError(enclosedElement, "The can be only one getRootUrl method on a " + TargetAnnotationHelper.annotationName(Rest.class) + " annotated interface"); } } else if (returnType.getKind() == TypeKind.VOID) { List<? extends VariableElement> parameters = executableElement.getParameters(); if (parameters.size() == 1) { VariableElement firstParameter = parameters.get(0); if (firstParameter.asType().toString().equals(CanonicalNameConstants.REST_TEMPLATE)) { if (!foundSetRestTemplateMethod) { foundSetRestTemplateMethod = true; } else { valid.invalidate(); annotationHelper.printError(enclosedElement, "You can only have oneRestTemplate setter method on a " + TargetAnnotationHelper.annotationName(Rest.class) + " annotated interface"); } } else if (executableElement.getSimpleName().toString().equals(METHOD_NAME_SET_ROOT_URL) && !foundSetRootUrlMethod) { foundSetRootUrlMethod = true; } else if (executableElement.getSimpleName().toString() .equals(METHOD_NAME_SET_AUTHENTICATION) && !foundSetAuthenticationMethod) { foundSetAuthenticationMethod = true; } else if (executableElement.getSimpleName().toString() .equals(METHOD_NAME_SET_BEARER_AUTH) && !foundSetBearerAuthMethod) { foundSetBearerAuthMethod = true; } else { valid.invalidate(); annotationHelper.printError(enclosedElement, "The method to set a RestTemplate should have only one RestTemplate parameter on a " + TargetAnnotationHelper.annotationName(Rest.class) + " annotated interface"); } } else if (parameters.size() == 2) { VariableElement firstParameter = parameters.get(0); VariableElement secondParameter = parameters.get(1); if (!(firstParameter.asType().toString().equals(CanonicalNameConstants.STRING) && secondParameter.asType().toString().equals(CanonicalNameConstants.STRING))) { valid.invalidate(); annotationHelper.printError(enclosedElement, "The method to set headers, cookies, or HTTP Basic Auth should have only String parameters on a " + TargetAnnotationHelper.annotationName(Rest.class) + " annotated interface"); } } else { valid.invalidate(); annotationHelper.printError(enclosedElement, "The method to set a RestTemplate should have only one RestTemplate parameter on a " + TargetAnnotationHelper.annotationName(Rest.class) + " annotated interface"); } } else if (returnType.toString().equals(CanonicalNameConstants.STRING)) { List<? extends VariableElement> parameters = executableElement.getParameters(); if (parameters.size() == 1) { VariableElement firstParameter = parameters.get(0); if (firstParameter.asType().toString().equals(CanonicalNameConstants.STRING)) { if (executableElement.getSimpleName().toString().equals(METHOD_NAME_GET_COOKIE) && !foundGetCookieMethod) { foundGetCookieMethod = true; } else if (executableElement.getSimpleName().toString() .equals(METHOD_NAME_GET_HEADER) && !foundGetHeaderMethod) { foundGetHeaderMethod = true; } else { valid.invalidate(); annotationHelper.printError(enclosedElement, "Only one getCookie(String) and one getHeader(String) method are allowed on a " + TargetAnnotationHelper.annotationName(Rest.class) + " annotated interface"); } } else { valid.invalidate(); annotationHelper.printError(enclosedElement, "Only getCookie(String) and getHeader(String) can return a String on a " + TargetAnnotationHelper.annotationName(Rest.class) + " annotated interface"); } } else { valid.invalidate(); annotationHelper.printError(enclosedElement, "The only methods that can return a String on a " + TargetAnnotationHelper.annotationName(Rest.class) + " annotated interface are getCookie(String) and getHeader(String)"); } } else { valid.invalidate(); annotationHelper.printError(enclosedElement, "All methods should be annotated in a " + TargetAnnotationHelper.annotationName(Rest.class) + " annotated interface, except the ones that returns or set a RestTemplate"); } } } } }