List of usage examples for javax.lang.model.type TypeMirror getKind
TypeKind getKind();
From source file:org.androidannotations.helper.IntentBuilder.java
private JMethod addPutExtraMethod(TypeMirror elementType, String parameterName, JFieldVar extraKeyField) { boolean castToSerializable = false; boolean castToParcelable = false; if (elementType.getKind() == TypeKind.DECLARED) { Elements elementUtils = holder.processingEnvironment().getElementUtils(); TypeMirror parcelableType = elementUtils.getTypeElement(PARCELABLE).asType(); if (!typeUtils.isSubtype(elementType, parcelableType)) { TypeMirror stringType = elementUtils.getTypeElement(STRING).asType(); if (!typeUtils.isSubtype(elementType, stringType)) { castToSerializable = true; }/*from w w w. ja va 2s. c o m*/ } else { TypeMirror serializableType = elementUtils.getTypeElement(SERIALIZABLE).asType(); if (typeUtils.isSubtype(elementType, serializableType)) { castToParcelable = true; } } } JMethod method = holder.getIntentBuilderClass().method(PUBLIC, holder.getIntentBuilderClass(), parameterName); JClass parameterClass = codeModelHelper.typeMirrorToJClass(elementType, holder); JVar extraParameterVar = method.param(parameterClass, parameterName); JBlock body = method.body(); JInvocation invocation = body.invoke(holder.getIntentField(), "putExtra").arg(extraKeyField); if (castToSerializable) { invocation.arg(cast(holder.classes().SERIALIZABLE, extraParameterVar)); } else if (castToParcelable) { invocation.arg(cast(holder.classes().PARCELABLE, extraParameterVar)); } else { invocation.arg(extraParameterVar); } body._return(_this()); return method; }
From source file:com.rgeldmacher.leash.LeashAnnotationProcessor.java
private String getPrimitiveDefault(TypeMirror typeMirror) { TypeKind kind = typeMirror.getKind(); if (kind == TypeKind.BOOLEAN) { return "false"; } else if (kind == TypeKind.BYTE) { return "0"; } else if (kind == TypeKind.CHAR) { return "'\\u0000'"; } else if (kind == TypeKind.DOUBLE) { return "0.0d"; } else if (kind == TypeKind.FLOAT) { return "0.0f"; } else if (kind == TypeKind.INT) { return "0"; } else if (kind == TypeKind.LONG) { return "0L"; } else if (kind == TypeKind.SHORT) { return "0"; }//from w w w . j av a 2s .c om return ""; }
From source file:info.archinnov.achilles.internals.parser.FieldInfoParser.java
protected List<String> deriveGetterName(VariableElement elm) { final String fieldName = elm.getSimpleName().toString(); final TypeMirror typeMirror = elm.asType(); String camelCase = fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); if (typeMirror.getKind() == TypeKind.BOOLEAN) { return asList("is" + camelCase, "get" + camelCase); } else {// www . j ava2 s .c o m return asList("get" + camelCase); } }
From source file:org.leandreck.endpoints.processor.model.TypeNodeFactory.java
private TypeNodeKind defineKind(final TypeMirror typeMirror) { if (typeMirror == null) { return TypeNodeKind.NULL; }//from w w w . ja v a2 s . c o m final TypeKind kind = typeMirror.getKind(); final TypeNodeKind typeNodeKind; switch (kind) { case ARRAY: typeNodeKind = TypeNodeKind.ARRAY; break; case TYPEVAR: typeNodeKind = TypeNodeKind.TYPEVAR; break; case DECLARED: typeNodeKind = defineDeclaredTypeNodeKind(typeMirror); break; default: if (TypeNodeKind.containsMapping(kind.name())) { typeNodeKind = TypeNodeKind.MAPPED; } else { typeNodeKind = TypeNodeKind.SIMPLE; } break; } return typeNodeKind; }
From source file:org.leandreck.endpoints.processor.model.TypeNodeFactory.java
private TypeNode initType(final String fieldName, final String parameterName, final boolean optional, final TypeNodeKind typeNodeKind, final TypeMirror typeMirror, final DeclaredType containingType) { final String key = typeMirror.toString(); if (nodes.containsKey(key) && !TypeKind.TYPEVAR.equals(typeMirror.getKind())) { final ProxyNode proxyNode = new ProxyNode(fieldName, parameterName, optional); proxyNode.setNode(nodes.get(key)); return proxyNode; }/*from w ww .ja va 2 s. c o m*/ try { final ProxyNode proxyNode = new ProxyNode(fieldName, parameterName, optional); nodes.put(key, proxyNode); final ConcreteTypeNodeFactory nodeFactory = factories.get(typeNodeKind); final TypeNode newTypeNode = nodeFactory.createTypeNode(fieldName, parameterName, optional, typeMirror, containingType); proxyNode.setNode(newTypeNode); nodes.put(key, newTypeNode); return newTypeNode; } catch (Exception e) { throw new UnkownTypeProcessingException(e); } }
From source file:org.mule.devkit.apt.model.AnnotationProcessorIdentifiable.java
private boolean isArrayOrList(TypeMirror type) { if (type.toString().equals("byte[]")) { return false; }//from www . j a va2s . c o m if (type.getKind() == TypeKind.ARRAY) { return true; } if (type.toString().startsWith(List.class.getName())) { return true; } List<? extends TypeMirror> inherits = types.directSupertypes(type); for (TypeMirror inherit : inherits) { if (isArrayOrList(inherit)) { return true; } } return false; }
From source file:info.archinnov.achilles.internals.parser.FunctionParamParser.java
public FunctionParamSignature parseParam(GlobalParsingContext context, AnnotationTree annotationTree, TypeName parentType, String methodName, String paramName) { final TypeMirror currentTypeMirror = annotationTree.getCurrentType(); final TypeName sourceType = TypeName.get(currentTypeMirror).box(); boolean isUDT = currentTypeMirror.getKind() == TypeKind.DECLARED && aptUtils.getAnnotationOnClass(currentTypeMirror, UDT.class).isPresent(); if (containsAnnotation(annotationTree, JSON.class)) { return new FunctionParamSignature(paramName, sourceType, STRING, "text"); } else if (containsAnnotation(annotationTree, Computed.class)) { throw new AchillesBeanMappingException( format("Cannot have @Computed annotation on param '%s' of method '%s' on class '%s'", paramName, methodName));//w w w. j ava 2s .co m } else if (aptUtils.isAssignableFrom(Tuple1.class, currentTypeMirror)) { return parseTuple1(context, annotationTree, parentType, methodName, paramName); } else if (aptUtils.isAssignableFrom(Tuple2.class, currentTypeMirror)) { return parseTuple2(context, annotationTree, parentType, methodName, paramName); } else if (aptUtils.isAssignableFrom(Tuple3.class, currentTypeMirror)) { return parseTuple3(context, annotationTree, parentType, methodName, paramName); } else if (aptUtils.isAssignableFrom(Tuple4.class, currentTypeMirror)) { return parseTuple4(context, annotationTree, parentType, methodName, paramName); } else if (aptUtils.isAssignableFrom(Tuple5.class, currentTypeMirror)) { return parseTuple5(context, annotationTree, parentType, methodName, paramName); } else if (aptUtils.isAssignableFrom(Tuple6.class, currentTypeMirror)) { return parseTuple6(context, annotationTree, parentType, methodName, paramName); } else if (aptUtils.isAssignableFrom(Tuple7.class, currentTypeMirror)) { return parseTuple7(context, annotationTree, parentType, methodName, paramName); } else if (aptUtils.isAssignableFrom(Tuple8.class, currentTypeMirror)) { return parseTuple8(context, annotationTree, parentType, methodName, paramName); } else if (aptUtils.isAssignableFrom(Tuple9.class, currentTypeMirror)) { return parseTuple9(context, annotationTree, parentType, methodName, paramName); } else if (aptUtils.isAssignableFrom(Tuple10.class, currentTypeMirror)) { return parseTuple10(context, annotationTree, parentType, methodName, paramName); } else if (aptUtils.isAssignableFrom(List.class, currentTypeMirror)) { return parseList(context, annotationTree, parentType, methodName, paramName); } else if (aptUtils.isAssignableFrom(Set.class, currentTypeMirror)) { return parseSet(context, annotationTree, parentType, methodName, paramName); } else if (aptUtils.isAssignableFrom(Map.class, currentTypeMirror)) { return parseMap(context, annotationTree, parentType, methodName, paramName); } else if (aptUtils.isAssignableFrom(java.util.Optional.class, currentTypeMirror)) { return parseOptional(context, annotationTree, parentType, methodName, paramName); } else if (isUDT) { return parseUDT(context, annotationTree, paramName); } else { return parseSimpleType(context, annotationTree, parentType, methodName, paramName); } }
From source file:info.archinnov.achilles.internals.parser.FieldInfoParser.java
protected CodeBlock buildIndexInfo(AnnotationTree annotationTree, VariableElement elm, EntityParsingContext context) {/* w w w .ja v a2 s . com*/ final CodeBlock.Builder builder = CodeBlock.builder(); final TypeMirror currentType = aptUtils.erasure(annotationTree.getCurrentType()); final Optional<TypedMap> indexAnnot = extractTypedMap(annotationTree, Index.class); final Name fieldName = elm.getSimpleName(); final Name className = enclosingClass(elm).getQualifiedName(); final boolean isFrozen = containsAnnotation(annotationTree, Frozen.class); final boolean hasJSON = containsAnnotation(annotationTree, JSON.class); if (currentType.getKind().isPrimitive()) { if (indexAnnot.isPresent()) { final IndexInfoContext indexInfo = indexAnnot.get().<IndexInfoContext>getTyped("indexInfoContext") .computeIndexName(elm, context); builder.add("new $T($T.$L, $S, $S, $S)", INDEX_INFO, INDEX_TYPE, IndexType.NORMAL, indexInfo.indexName, indexInfo.indexClassName, indexInfo.indexOptions); } else { noIndex(builder); } return builder.build(); } if (aptUtils.isAssignableFrom(List.class, currentType) || aptUtils.isAssignableFrom(Set.class, currentType)) { final AnnotationTree next = hasJSON ? annotationTree : annotationTree.next(); if (indexAnnot.isPresent()) { final IndexInfoContext indexInfo = indexAnnot.get().<IndexInfoContext>getTyped("indexInfoContext") .computeIndexName(elm, context); buildIndexForListOrSet(builder, isFrozen, indexInfo); } else if (containsAnnotation(next, Index.class)) { final TypedMap typedMap = extractTypedMap(next, Index.class).get(); buildIndexForListOrSet(builder, isFrozen, typedMap.<IndexInfoContext>getTyped("indexInfoContext").computeIndexName(elm, context)); } else { noIndex(builder); } } else if (aptUtils.isAssignableFrom(Map.class, currentType)) { final AnnotationTree keyAnnotationTree = hasJSON ? annotationTree : annotationTree.next(); final AnnotationTree valueAnnotationTree = hasJSON ? annotationTree : annotationTree.next().next(); if (indexAnnot.isPresent()) { final IndexInfoContext indexInfo = indexAnnot.get().<IndexInfoContext>getTyped("indexInfoContext") .computeIndexName(elm, context); if (isFrozen) { IndexType indexType = isBlank(indexInfo.indexClassName) ? IndexType.FULL : IndexType.CUSTOM; builder.add("new $T($T.$L, $S, $S, $S)", INDEX_INFO, INDEX_TYPE, indexType, indexInfo.indexName, indexInfo.indexClassName, indexInfo.indexOptions); } else { IndexType indexType = isBlank(indexInfo.indexClassName) ? IndexType.MAP_ENTRY : IndexType.CUSTOM; builder.add("new $T($T.$L, $S, $S, $S)", INDEX_INFO, INDEX_TYPE, indexType, indexInfo.indexName, indexInfo.indexClassName, indexInfo.indexOptions); } aptUtils.validateFalse(containsAnnotation(keyAnnotationTree, Index.class), "Cannot have @Index on Map AND key type in field '%s' of class '%s'", fieldName, className); aptUtils.validateFalse(containsAnnotation(valueAnnotationTree, Index.class), "Cannot have @Index on Map AND value type in field '%s' of class '%s'", fieldName, className); } else if (containsAnnotation(keyAnnotationTree, Index.class)) { aptUtils.validateFalse(containsAnnotation(valueAnnotationTree, Index.class), "Cannot have @Index on Map key AND value type in field '%s' of class '%s'", fieldName, className); IndexInfoContext indexInfo = extractTypedMap(keyAnnotationTree, Index.class).get() .<IndexInfoContext>getTyped("indexInfoContext").computeIndexName(elm, context); IndexType indexType = isBlank(indexInfo.indexClassName) ? IndexType.MAP_KEY : IndexType.CUSTOM; builder.add("new $T($T.$L, $S, $S, $S)", INDEX_INFO, INDEX_TYPE, indexType, indexInfo.indexName, indexInfo.indexClassName, indexInfo.indexOptions); } else if (containsAnnotation(valueAnnotationTree, Index.class)) { aptUtils.validateFalse(containsAnnotation(keyAnnotationTree, Index.class), "Cannot have @Index on Map key AND value type in field '%s' of class '%s'", fieldName, className); IndexInfoContext indexInfo = extractTypedMap(valueAnnotationTree, Index.class).get() .<IndexInfoContext>getTyped("indexInfoContext").computeIndexName(elm, context); IndexType indexType = isBlank(indexInfo.indexClassName) ? IndexType.COLLECTION : IndexType.CUSTOM; builder.add("new $T($T.$L, $S, $S, $S)", INDEX_INFO, INDEX_TYPE, indexType, indexInfo.indexName, indexInfo.indexClassName, indexInfo.indexOptions); } else { noIndex(builder); } } else if (indexAnnot.isPresent()) { final IndexInfoContext indexInfo = indexAnnot.get().<IndexInfoContext>getTyped("indexInfoContext") .computeIndexName(elm, context); IndexType indexType = isBlank(indexInfo.indexClassName) ? IndexType.NORMAL : IndexType.CUSTOM; builder.add("new $T($T.$L, $S, $S, $S)", INDEX_INFO, INDEX_TYPE, indexType, indexInfo.indexName, indexInfo.indexClassName, indexInfo.indexOptions); } else { noIndex(builder); } return builder.build(); }
From source file:org.versly.rest.wsdoc.AnnotationProcessor.java
private boolean isJsonPrimitive(TypeMirror typeMirror) { return (typeMirror.getKind().isPrimitive() || JsonPrimitive.isPrimitive(typeMirror.toString())); }
From source file:org.versly.rest.wsdoc.AnnotationProcessor.java
private TypeMirror unwrapReturnType(TypeMirror originalReturnType) { if (originalReturnType.getKind() != TypeKind.DECLARED) { return originalReturnType; }//w w w . ja va 2 s . com DeclaredType declaredType = (DeclaredType) originalReturnType; if (declaredType.getTypeArguments().size() == 0) { return originalReturnType; } TypeElement element = (TypeElement) declaredType.asElement(); // For Spring's Async Support if ("org.springframework.web.context.request.async.DeferredResult" .equalsIgnoreCase(element.getQualifiedName().toString())) { return declaredType.getTypeArguments().get(0); } // For Spring's Async Support if ("java.util.concurrent.Callable".equalsIgnoreCase(element.getQualifiedName().toString())) { return declaredType.getTypeArguments().get(0); } return originalReturnType; }