List of usage examples for org.eclipse.jdt.internal.compiler.lookup TypeBinding getTypeAnnotations
final public AnnotationBinding[] getTypeAnnotations()
From source file:info.archinnov.achilles.internals.parser.AnnotationTree.java
License:Apache License
public static AnnotationTree buildFromMethodForReturnType(AptUtils aptUtils, ExecutableElement method) { if (isJavaCompiler(method)) { final TypeMirror returnType = method.getReturnType(); final SymbolMetadata metadata = ((Symbol.MethodSymbol) method).getMetadata(); final List<Attribute.TypeCompound> typeAttributes = metadata == null ? Arrays.asList() : metadata.getTypeAttributes(); final Map<Class<? extends Annotation>, TypedMap> annotationInfo = typeAttributes.stream().filter( x -> x.getPosition().type == TargetType.METHOD_RETURN && x.getPosition().location.size() == 0) .map(x -> (AnnotationMirror) x).collect(Collectors.toMap(x -> toAnnotation_Javac(aptUtils, x), x -> inspectSupportedAnnotation_Javac(aptUtils, returnType, x))); final AnnotationTree annotationTree = new AnnotationTree(returnType, annotationInfo, 1); final List<? extends TypeMirror> nestedTypes = returnType.getKind() == TypeKind.DECLARED ? MoreTypes.asDeclared(returnType).getTypeArguments() : Arrays.asList(); final List<Attribute.TypeCompound> nestedTypeAttributes = typeAttributes.stream().filter( x -> x.getPosition().type == TargetType.METHOD_RETURN && x.getPosition().location.size() > 0) .collect(toList());/*from w w w . ja v a 2 s .c o m*/ buildTree_Javac(aptUtils, annotationTree, 1, nestedTypes, nestedTypeAttributes); return annotationTree; } else if (isEclipseCompiler(method)) { final TypeMirror returnType = method.getReturnType(); final List<? extends TypeMirror> nestedTypes = returnType.getKind() == TypeKind.DECLARED ? MoreTypes.asDeclared(returnType).getTypeArguments() : Arrays.asList(); final TypeBinding binding = (TypeBinding) DeclaredTypeImplContainer.from((TypeMirrorImpl) returnType) .getBinding(); final List<AnnotationBinding> annotationBindings = Arrays.asList(binding.getTypeAnnotations()); final Map<Class<? extends Annotation>, TypedMap> annotationInfo = annotationBindings.stream() .filter(annotBinding -> { final String annotationName = annotBinding.getAnnotationType().debugName(); return JSON.class.getCanonicalName().equals(annotationName) || EmptyCollectionIfNull.class.getCanonicalName().equals(annotationName) || Enumerated.class.getCanonicalName().equals(annotationName) || Frozen.class.getCanonicalName().equals(annotationName) || Computed.class.getCanonicalName().equals(annotationName) || Counter.class.getCanonicalName().equals(annotationName) || TimeUUID.class.getCanonicalName().equals(annotationName) || ASCII.class.getCanonicalName().equals(annotationName) || Codec.class.getCanonicalName().equals(annotationName) || RuntimeCodec.class.getCanonicalName().equals(annotationName) || Index.class.getCanonicalName().equals(annotationName) || PartitionKey.class.getCanonicalName().equals(annotationName) || ClusteringColumn.class.getCanonicalName().equals(annotationName); }).map(x -> inspectSupportedAnnotation_Ecj(aptUtils, returnType, x)) .collect(Collectors.toMap(Tuple2::_1, Tuple2::_2)); final AnnotationTree annotationTree = new AnnotationTree(returnType, annotationInfo, 1); List<TypeBinding> typeBindings = new ArrayList<>(); if (binding instanceof ParameterizedTypeBinding) { typeBindings = Arrays.asList(((ParameterizedTypeBinding) binding).typeArguments()); } buildTree_Ecj(aptUtils, annotationTree, 1, nestedTypes, typeBindings); return annotationTree; } else { aptUtils.printError( "Unknown compiler, only standard Java compiler and Eclipse ECJ compiler are supported"); return null; } }
From source file:info.archinnov.achilles.internals.parser.AnnotationTree.java
License:Apache License
public static List<AnnotationTree> buildFromMethodForParam(AptUtils aptUtils, ExecutableElement method) { if (isJavaCompiler(method)) { final List<AnnotationTree> annotationTrees = new ArrayList<>(method.getParameters().size()); final SymbolMetadata metadata = ((Symbol.MethodSymbol) method).getMetadata(); final List<Attribute.TypeCompound> typeAttributes = metadata == null ? Arrays.asList() : metadata.getTypeAttributes(); final List<? extends VariableElement> parameters = method.getParameters(); for (int i = 0; i < parameters.size(); i++) { final int finalI = i; final VariableElement parameter = parameters.get(i); final TypeMirror typeMirror = parameter.asType(); final Map<Class<? extends Annotation>, TypedMap> annotationInfo = typeAttributes.stream() .filter(x -> x.getPosition().parameter_index == finalI && x.getPosition().location.size() == 0) .map(x -> (AnnotationMirror) x) .collect(Collectors.toMap(x -> toAnnotation_Javac(aptUtils, x), x -> inspectSupportedAnnotation_Javac(aptUtils, typeMirror, x))); final AnnotationTree annotationTree = new AnnotationTree(typeMirror, annotationInfo, 1); final List<? extends TypeMirror> nestedTypes = typeMirror.getKind() == TypeKind.DECLARED ? MoreTypes.asDeclared(typeMirror).getTypeArguments() : Arrays.asList(); final List<Attribute.TypeCompound> nestedTypeAttributes = typeAttributes.stream().filter( x -> x.getPosition().parameter_index == finalI && x.getPosition().location.size() > 0) .collect(toList());//w w w. j a v a2 s. com buildTree_Javac(aptUtils, annotationTree, 1, nestedTypes, nestedTypeAttributes); annotationTrees.add(annotationTree); } return annotationTrees; } else if (isEclipseCompiler(method)) { final List<AnnotationTree> annotationTrees = new ArrayList<>(method.getParameters().size()); for (VariableElement varElm : method.getParameters()) { final TypeMirror currentType = varElm.asType(); final List<? extends TypeMirror> nestedTypes = currentType.getKind() == TypeKind.DECLARED ? MoreTypes.asDeclared(currentType).getTypeArguments() : Arrays.asList(); final TypeBinding binding = (TypeBinding) DeclaredTypeImplContainer .from((TypeMirrorImpl) currentType).getBinding(); final List<AnnotationBinding> annotationBindings = Arrays.asList(binding.getTypeAnnotations()); final Map<Class<? extends Annotation>, TypedMap> annotationInfo = annotationBindings.stream() .filter(annotBinding -> { final String annotationName = annotBinding.getAnnotationType().debugName(); return JSON.class.getCanonicalName().equals(annotationName) || EmptyCollectionIfNull.class.getCanonicalName().equals(annotationName) || Enumerated.class.getCanonicalName().equals(annotationName) || Frozen.class.getCanonicalName().equals(annotationName) || Computed.class.getCanonicalName().equals(annotationName) || Counter.class.getCanonicalName().equals(annotationName) || TimeUUID.class.getCanonicalName().equals(annotationName) || ASCII.class.getCanonicalName().equals(annotationName) || Codec.class.getCanonicalName().equals(annotationName) || RuntimeCodec.class.getCanonicalName().equals(annotationName) || Index.class.getCanonicalName().equals(annotationName) || PartitionKey.class.getCanonicalName().equals(annotationName) || ClusteringColumn.class.getCanonicalName().equals(annotationName); }).map(x -> inspectSupportedAnnotation_Ecj(aptUtils, currentType, x)) .collect(Collectors.toMap(Tuple2::_1, Tuple2::_2)); final AnnotationTree annotationTree = new AnnotationTree(currentType, annotationInfo, 1); List<TypeBinding> typeBindings = new ArrayList<>(); if (binding instanceof ParameterizedTypeBinding) { typeBindings = Arrays.asList(((ParameterizedTypeBinding) binding).typeArguments()); } buildTree_Ecj(aptUtils, annotationTree, 1, nestedTypes, typeBindings); annotationTrees.add(annotationTree); } return annotationTrees; } else { aptUtils.printError( "Unknown compiler, only standard Java compiler and Eclipse ECJ compiler are supported"); return null; } }
From source file:info.archinnov.achilles.internals.parser.AnnotationTree.java
License:Apache License
private static AnnotationTree buildTree_Ecj(AptUtils aptUtils, AnnotationTree annotationTree, int depth, List<? extends TypeMirror> nestedTypes, List<TypeBinding> typeBindings) { final TypeMirror currentType = annotationTree.currentType; if (containsAnnotation(annotationTree, JSON.class)) { return annotationTree; }/*from ww w.j a v a 2 s . c om*/ if (isPrimitive(currentType) || isArray(currentType) || isAnEnum(currentType) || nestedTypes.size() == 0) { return annotationTree; } else if (aptUtils.isAssignableFrom(Tuple1.class, currentType) || aptUtils.isAssignableFrom(List.class, currentType) || aptUtils.isAssignableFrom(Set.class, currentType) || aptUtils.isAssignableFrom(java.util.Optional.class, currentType)) { final TypeMirror typeMirror = nestedTypes.get(0); final TypeBinding nestedTypeBinding = typeBindings.get(0); final Map<Class<? extends Annotation>, TypedMap> annotationsInfo = Arrays .asList(nestedTypeBinding.getTypeAnnotations()).stream() .map(annotBinding -> inspectSupportedAnnotation_Ecj(aptUtils, currentType, annotBinding)) .collect(Collectors.toMap(pair -> pair._1(), pair -> pair._2())); final AnnotationTree newTree = annotationTree .addNext(new AnnotationTree(typeMirror, annotationsInfo, depth + 1)); List<TypeBinding> nestedBindings = new ArrayList<>(); if (nestedTypeBinding instanceof ParameterizedTypeBinding) { nestedBindings = Arrays.asList(((ParameterizedTypeBinding) nestedTypeBinding).typeArguments()); } return buildTree_Ecj(aptUtils, newTree, depth + 1, getTypeArguments(typeMirror), nestedBindings); } else if (aptUtils.isAssignableFrom(Tuple2.class, currentType) || aptUtils.isAssignableFrom(Map.class, annotationTree.currentType)) { return buildTreeForTuple_Ecj(aptUtils, currentType, annotationTree, depth, 2, nestedTypes, typeBindings); } else if (aptUtils.isAssignableFrom(Tuple3.class, currentType)) { return buildTreeForTuple_Ecj(aptUtils, currentType, annotationTree, depth, 3, nestedTypes, typeBindings); } else if (aptUtils.isAssignableFrom(Tuple4.class, currentType)) { return buildTreeForTuple_Ecj(aptUtils, currentType, annotationTree, depth, 4, nestedTypes, typeBindings); } else if (aptUtils.isAssignableFrom(Tuple5.class, currentType)) { return buildTreeForTuple_Ecj(aptUtils, currentType, annotationTree, depth, 5, nestedTypes, typeBindings); } else if (aptUtils.isAssignableFrom(Tuple6.class, currentType)) { return buildTreeForTuple_Ecj(aptUtils, currentType, annotationTree, depth, 6, nestedTypes, typeBindings); } else if (aptUtils.isAssignableFrom(Tuple7.class, currentType)) { return buildTreeForTuple_Ecj(aptUtils, currentType, annotationTree, depth, 7, nestedTypes, typeBindings); } else if (aptUtils.isAssignableFrom(Tuple8.class, currentType)) { return buildTreeForTuple_Ecj(aptUtils, currentType, annotationTree, depth, 8, nestedTypes, typeBindings); } else if (aptUtils.isAssignableFrom(Tuple9.class, currentType)) { return buildTreeForTuple_Ecj(aptUtils, currentType, annotationTree, depth, 9, nestedTypes, typeBindings); } else if (aptUtils.isAssignableFrom(Tuple10.class, currentType)) { return buildTreeForTuple_Ecj(aptUtils, currentType, annotationTree, depth, 10, nestedTypes, typeBindings); } else if (aptUtils.getAnnotationOnClass(currentType, UDT.class).isPresent()) { return annotationTree; } else { throw new IllegalStateException("Unknown current type : " + currentType.toString()); } }
From source file:info.archinnov.achilles.internals.parser.AnnotationTree.java
License:Apache License
private static AnnotationTree buildTreeForTuple_Ecj(AptUtils aptUtils, TypeMirror currentType, AnnotationTree annotationTree, int depth, int cardinality, List<? extends TypeMirror> nestedTypes, List<TypeBinding> typeBindings) { AnnotationTree newTreeN;/*from w ww . j a v a2s . co m*/ AnnotationTree recursiveTreeN = annotationTree; for (int i = 0; i < cardinality; i++) { final TypeMirror typeMirrorN = nestedTypes.get(i); final TypeBinding typeBinding = typeBindings.get(i); final Map<Class<? extends Annotation>, TypedMap> annotationsInfo = Arrays .asList(typeBinding.getTypeAnnotations()).stream() .map(annotBinding -> inspectSupportedAnnotation_Ecj(aptUtils, currentType, annotBinding)) .collect(Collectors.toMap(pair -> pair._1(), pair -> pair._2())); List<TypeBinding> nestedBindings = new ArrayList<>(); if (typeBinding instanceof ParameterizedTypeBinding) { nestedBindings = Arrays.asList(((ParameterizedTypeBinding) typeBinding).typeArguments()); } newTreeN = recursiveTreeN.addNext(new AnnotationTree(typeMirrorN, annotationsInfo, depth + 1)); recursiveTreeN = buildTree_Ecj(aptUtils, newTreeN, depth + 1, getTypeArguments(typeMirrorN), nestedBindings); } return recursiveTreeN; }
From source file:spoon.support.compiler.jdt.JDTTreeBuilder.java
License:Open Source License
private boolean isContainsInTypeAnnotation(TypeBinding binding, Annotation a) { return !binding.hasTypeAnnotations() || !containsInTypeAnnotation(a, binding.getTypeAnnotations()); }