List of usage examples for javax.lang.model.type TypeKind ARRAY
TypeKind ARRAY
To view the source code for javax.lang.model.type TypeKind ARRAY.
Click Source Link
From source file:org.mule.devkit.apt.model.AnnotationProcessorIdentifiable.java
private boolean isArrayOrList(TypeMirror type) { if (type.toString().equals("byte[]")) { return false; }//from w ww . j a v a 2 s . com 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:cop.raml.mocks.MockUtils.java
private static TypeElementMock createArrayElement(@NotNull Class<?> cls) throws ClassNotFoundException { TypeElementMock element = new TypeElementMock("Array", ElementKind.CLASS); TypeMirrorMock type = new TypeMirrorMock(element, TypeKind.ARRAY); if (cls.isPrimitive()) type.setElementType(createPrimitiveElement(cls).asType()); else if (cls.isEnum()) type.setElementType(createEnumElement(cls).asType()); else//from w w w . j a v a 2 s . co m type.setElementType(createClassElement(cls).asType()); element.setType(type); return element; }
From source file:info.archinnov.achilles.internals.parser.CodecFactory.java
public CodecInfo createCodec(TypeName sourceType, AnnotationTree annotationTree, FieldParsingContext context, Optional<CodecInfo> codecFromRegistry) { final String fieldName = context.fieldName; final String className = context.className; TypeName targetType = sourceType;/*from ww w . j av a 2s. com*/ TypeMirror typeMirror = annotationTree.getCurrentType(); final Optional<TypedMap> jsonTransform = extractTypedMap(annotationTree, JSON.class); final Optional<TypedMap> enumerated = extractTypedMap(annotationTree, Enumerated.class); final Optional<TypedMap> codecFromType = extractTypedMap(annotationTree, Codec.class); final Optional<TypedMap> runtimeCodec = extractTypedMap(annotationTree, RuntimeCodec.class); final Optional<TypedMap> computed = extractTypedMap(annotationTree, Computed.class); final Optional<TypeName> computedCQLClass = computed.map(x -> x.<Class<?>>getTyped("cqlClass")) .map(ClassName::get); final boolean isCounter = extractTypedMap(annotationTree, Counter.class).isPresent(); CodeBlock codec; if (jsonTransform.isPresent()) { codec = CodeBlock.builder().add("new $T<>($T.class, $L)", JSON_CODEC, getRawType(sourceType).box(), buildJavaTypeForJackson(sourceType)).build(); targetType = ClassName.get(String.class); return new CodecInfo(codec, sourceType, targetType); } else if (codecFromType.isPresent()) { final Tuple2<TypeName, CodeBlock> tuple2 = codecCodeGen(codecFromType.get(), sourceType, computedCQLClass, isCounter); targetType = tuple2._1(); codec = tuple2._2(); return new CodecInfo(codec, sourceType, targetType); } else if (runtimeCodec.isPresent()) { final Tuple2<TypeName, CodeBlock> tuple2 = runtimeCodecCodeGen(runtimeCodec.get(), computedCQLClass, isCounter); targetType = tuple2._1(); codec = tuple2._2(); return new CodecInfo(codec, sourceType, targetType); } else if (enumerated.isPresent()) { final Tuple2<TypeName, CodeBlock> tuple2 = enumeratedCodecCodeGen(enumerated.get(), sourceType, fieldName, className); codec = tuple2._2(); targetType = tuple2._1(); return new CodecInfo(codec, sourceType, targetType); } else if (typeMirror.getKind() == TypeKind.ARRAY && typeMirror.toString().equals("byte[]")) { if (codecFromRegistry.isPresent()) { return codecFromRegistry.get(); } else { codec = CodeBlock.builder().add("new $T()", BYTE_ARRAY_PRIMITIVE_CODEC).build(); return new CodecInfo(codec, sourceType, BYTE_BUFFER); } } else if (typeMirror.getKind() == TypeKind.ARRAY && typeMirror.toString().equals("java.lang.Byte[]")) { if (codecFromRegistry.isPresent()) { return codecFromRegistry.get(); } else { codec = CodeBlock.builder().add("new $T()", BYTE_ARRAY_CODEC).build(); return new CodecInfo(codec, sourceType, BYTE_BUFFER); } } else { if (codecFromRegistry.isPresent()) { return codecFromRegistry.get(); } else { if (computedCQLClass.isPresent()) { aptUtils.validateTrue(sourceType.equals(computedCQLClass.get()), "CQL class '%s' of @Computed field '%s' of class '%s' should be same as field class '%s'", computedCQLClass.get(), fieldName, className, sourceType); } validateAllowedTypes(aptUtils, sourceType, sourceType); codec = CodeBlock.builder() .add("new $T<>($T.class)", FALL_THROUGH_CODEC, getRawType(sourceType).box()).build(); return new CodecInfo(codec, sourceType, targetType); } } }
From source file:com.googlecode.androidannotations.helper.ValidatorHelper.java
public void doesNotReturnArray(ExecutableElement element, IsValid valid) { if (element.getReturnType().getKind() == TypeKind.ARRAY) { valid.invalidate();//from ww w .j ava 2 s .c o m annotationHelper.printAnnotationError(element, "%s cannot return array"); } }
From source file:android.databinding.tool.store.SetterStore.java
private static boolean hasTypeVar(TypeMirror typeMirror) { TypeKind kind = typeMirror.getKind(); if (kind == TypeKind.TYPEVAR) { return true; } else if (kind == TypeKind.ARRAY) { return hasTypeVar(((ArrayType) typeMirror).getComponentType()); } else if (kind == TypeKind.DECLARED) { DeclaredType declaredType = (DeclaredType) typeMirror; List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments(); if (typeArguments == null || typeArguments.isEmpty()) { return false; }/*from w ww . j a va 2 s. co m*/ for (TypeMirror arg : typeArguments) { if (hasTypeVar(arg)) { return true; } } return false; } else { return false; } }
From source file:org.lambdamatic.mongodb.apt.template.TemplateType.java
/** * Returns the {@link TemplateType} for the given {@link VariableType}, or throws a * {@link MetadataGenerationException} if it was not a known or supported type. * /*from w w w. j a v a2s. co m*/ * @param variableType the variable to analyze * @return the corresponding {@link TemplateType} * @throws MetadataGenerationException if the given variable type is not supported */ private static TemplateType getMetadataFieldType(final TypeMirror variableType, final BiFunction<PrimitiveType, ProcessingEnvironment, TemplateType> primitiveTypeToTemplateType, final Function<DeclaredType, TemplateType> embeddedDocumentToTemplateType, final BiFunction<TypeMirror, ProcessingEnvironment, TemplateType> collectionToTemplateType, final BiFunction<DeclaredType, ProcessingEnvironment, TemplateType> mapToTemplateType, final Function<DeclaredType, TemplateType> declaredTypeToTemplateType, final ProcessingEnvironment processingEnv) throws MetadataGenerationException { if (variableType instanceof PrimitiveType) { return primitiveTypeToTemplateType.apply((PrimitiveType) variableType, processingEnv); } else if (variableType instanceof DeclaredType) { final DeclaredType declaredType = (DeclaredType) variableType; final TypeElement declaredElement = (TypeElement) declaredType.asElement(); if (declaredElement.getAnnotation(EmbeddedDocument.class) != null) { // embedded documents return embeddedDocumentToTemplateType.apply(declaredType); } else if (ElementUtils.isAssignable(declaredType, Collection.class)) { // collections (list/set) return collectionToTemplateType.apply(declaredType.getTypeArguments().get(0), processingEnv); } else if (ElementUtils.isAssignable(declaredType, Map.class)) { // map return mapToTemplateType.apply(declaredType, processingEnv); } else { return declaredTypeToTemplateType.apply(declaredType); } } else if (variableType.getKind() == TypeKind.ARRAY) { final TypeMirror componentType = ((ArrayType) variableType).getComponentType(); if (componentType instanceof PrimitiveType) { final PrimitiveType primitiveType = (PrimitiveType) componentType; final TypeElement boxedClass = processingEnv.getTypeUtils().boxedClass(primitiveType); return collectionToTemplateType.apply(boxedClass.asType(), processingEnv); } return collectionToTemplateType.apply(componentType, processingEnv); } throw new MetadataGenerationException("Unexpected variable type: " + variableType); }
From source file:android.databinding.tool.store.SetterStore.java
private static String getQualifiedName(TypeMirror type) { if (type.getKind() == TypeKind.ARRAY) { return getQualifiedName(((ArrayType) type).getComponentType()) + "[]"; } else {/*w w w . java 2 s. c o m*/ return type.toString(); } }
From source file:info.archinnov.achilles.internals.parser.CodecFactory.java
public TypeName determineTargetCQLType(AnnotationTree annotationTree, TypeName parentType, TypeName sourceType, String methodName, String paramName, Optional<CodecInfo> codecFromRegistry) { TypeName targetType = sourceType;/* ww w . j a v a 2 s . c o m*/ TypeMirror typeMirror = annotationTree.getCurrentType(); final Optional<TypedMap> jsonTransform = extractTypedMap(annotationTree, JSON.class); final Optional<TypedMap> enumerated = extractTypedMap(annotationTree, Enumerated.class); final Optional<TypedMap> codecFromType = extractTypedMap(annotationTree, Codec.class); final Optional<TypedMap> runtimeCodec = extractTypedMap(annotationTree, RuntimeCodec.class); final Optional<TypedMap> computed = extractTypedMap(annotationTree, Computed.class); final Optional<TypeName> computedCQLClass = computed.map(x -> x.<Class<?>>getTyped("cqlClass")) .map(ClassName::get); final boolean isCounter = extractTypedMap(annotationTree, Counter.class).isPresent(); if (jsonTransform.isPresent()) { return ClassName.get(String.class); } else if (codecFromType.isPresent()) { final CodecContext codecContext = codecFromType.get().getTyped("codecContext"); validateCodec(aptUtils, codecContext, sourceType, computedCQLClass, isCounter); return codecContext.targetType.box(); } else if (runtimeCodec.isPresent()) { final RuntimeCodecContext runtimeCodecContext = runtimeCodec.get().getTyped("runtimeCodecContext"); validateCodec(aptUtils, runtimeCodecContext, runtimeCodecContext.sourceType, computedCQLClass, isCounter); return runtimeCodecContext.targetType.box(); } else if (enumerated.isPresent()) { final TypedMap typedMap = enumerated.get(); final Object value = typedMap.getTyped("value"); aptUtils.validateTrue(isAnEnum(value), "The type '%s' on param '%s' of method '%s' in class '%s' is not a java.lang.Enum type", sourceType.toString(), paramName, methodName, parentType); final Encoding encoding = typedMap.getTyped("value"); if (encoding == Encoding.NAME) { return STRING; } else { return OBJECT_INT; } } else if (typeMirror.getKind() == TypeKind.ARRAY && typeMirror.toString().equals("byte[]")) { if (codecFromRegistry.isPresent()) { return codecFromRegistry.get().targetType.box(); } else { return BYTE_BUFFER; } } else if (typeMirror.getKind() == TypeKind.ARRAY && typeMirror.toString().equals("java.lang.Byte[]")) { if (codecFromRegistry.isPresent()) { return codecFromRegistry.get().targetType.box(); } else { return BYTE_BUFFER; } } else { if (codecFromRegistry.isPresent()) { return codecFromRegistry.get().targetType.box(); } else { TypeValidator.validateAllowedTypesForFunction(aptUtils, parentType.toString(), methodName, sourceType); return targetType; } } }
From source file:org.versly.rest.wsdoc.AnnotationProcessor.java
private JsonType jsonTypeFromTypeMirror(TypeMirror typeMirror, Collection<String> typeRecursionGuard) { JsonType type;/* w w w.j av a2 s .c o m*/ if (_memoizedTypeMirrors.containsKey(typeMirror)) { return _memoizedTypeMirrors.get(typeMirror); } if (isJsonPrimitive(typeMirror)) { type = new JsonPrimitive(typeMirror.toString()); } else if (typeMirror.getKind() == TypeKind.DECLARED) { // some sort of object... walk it DeclaredType declaredType = (DeclaredType) typeMirror; type = jsonTypeForDeclaredType(declaredType, declaredType.getTypeArguments(), typeRecursionGuard); } else if (typeMirror.getKind() == TypeKind.VOID) { type = null; } else if (typeMirror.getKind() == TypeKind.ARRAY) { TypeMirror componentType = ((ArrayType) typeMirror).getComponentType(); type = jsonTypeFromTypeMirror(componentType, typeRecursionGuard); } else if (typeMirror.getKind() == TypeKind.ERROR) { type = new JsonPrimitive("(unresolvable type)"); } else { throw new UnsupportedOperationException(typeMirror.toString()); } _memoizedTypeMirrors.put(typeMirror, type); return type; }