List of usage examples for org.eclipse.jdt.internal.compiler.lookup AnnotationBinding getAnnotationType
public ReferenceBinding getAnnotationType()
From source file:com.android.build.gradle.tasks.annotations.Extractor.java
License:Apache License
@SuppressWarnings("unused") static boolean hasSourceRetention(@NonNull AnnotationBinding a) { if (new String(a.getAnnotationType().readableName()).equals("java.lang.annotation.Retention")) { ElementValuePair[] pairs = a.getElementValuePairs(); if (pairs == null || pairs.length != 1) { warning("Expected exactly one parameter passed to @Retention"); return false; }/* ww w .ja va2 s . c om*/ ElementValuePair pair = pairs[0]; Object value = pair.getValue(); if (value instanceof FieldBinding) { FieldBinding field = (FieldBinding) value; if ("SOURCE".equals(new String(field.readableName()))) { return true; } } } return false; }
From source file:com.codenvy.ide.ext.java.server.TypeBindingConvector.java
License:Open Source License
private static JsonElement toJsonAnnotation(AnnotationBinding annotation) { JsonObject object = new JsonObject(); object.add("typeName", annotation.getAnnotationType() == null ? JsonNull.INSTANCE : new JsonPrimitive(new String(annotation.getAnnotationType().constantPoolName()))); object.add("elementValuePairs", toJsonElementValuePairs(annotation.getElementValuePairs())); return object; }
From source file:com.google.gwt.dev.javac.JdtUtil.java
License:Apache License
static AnnotationBinding getAnnotation(AnnotationBinding[] annotations, String nameToFind) { if (annotations != null) { for (AnnotationBinding a : annotations) { ReferenceBinding annBinding = a.getAnnotationType(); String annName = CharOperation.toString(annBinding.compoundName); if (nameToFind.equals(annName)) { return a; }/*from w ww. j a v a 2s.c o m*/ } } return null; }
From source file:com.google.gwt.dev.javac.JdtUtil.java
License:Apache License
static AnnotationBinding getAnnotation(Annotation[] annotations, String nameToFind) { if (annotations != null) { for (Annotation a : annotations) { AnnotationBinding annBinding = a.getCompilerAnnotation(); if (annBinding != null) { String annName = CharOperation.toString(annBinding.getAnnotationType().compoundName); if (nameToFind.equals(annName)) { return annBinding; }/*from ww w . j a va 2 s . c o m*/ } } } return null; }
From source file:com.redhat.ceylon.eclipse.core.model.loader.JDTUtils.java
License:Open Source License
public static Map<String, AnnotationMirror> getAnnotations(AnnotationBinding[] annotations, LookupEnvironment lookupEnvironment) { HashMap<String, AnnotationMirror> result = new HashMap<String, AnnotationMirror>(); for (AnnotationBinding annotation : annotations) { result.put(getFullyQualifiedName(annotation.getAnnotationType()), new JDTAnnotation(annotation, lookupEnvironment)); }/*w w w . j a v a2 s . com*/ return result; }
From source file:com.redhat.ceylon.eclipse.core.model.mirror.JDTUtils.java
License:Open Source License
public static Map<String, AnnotationMirror> getAnnotations(AnnotationBinding[] annotations) { HashMap<String, AnnotationMirror> result = new HashMap<String, AnnotationMirror>(); for (AnnotationBinding annotation : annotations) { result.put(getFullyQualifiedName(annotation.getAnnotationType()), new JDTAnnotation(annotation)); }/*www. j av a 2s . c o m*/ return result; }
From source file:com.redhat.ceylon.eclipse.core.model.mirror.JDTUtils.java
License:Open Source License
public static boolean hasAnnotation(MethodBinding inheritedMethod, String ceylonIgnoreAnnotation) { for (AnnotationBinding annotation : inheritedMethod.getAnnotations()) { if (getFullyQualifiedName(annotation.getAnnotationType()).equals(ceylonIgnoreAnnotation)) return true; }//from w ww . ja va 2 s .co m return false; }
From source file:info.archinnov.achilles.internals.parser.AnnotationTree.java
License:Apache License
private static Tuple2<Class<? extends Annotation>, TypedMap> inspectSupportedAnnotation_Ecj(AptUtils aptUtils, TypeMirror currentType, AnnotationBinding annotationBinding) { final TypedMap typedMap = new TypedMap(); final String annotationName = annotationBinding.getAnnotationType().debugName(); if (JSON.class.getCanonicalName().equals(annotationName)) { return Tuple2.of(JSON.class, typedMap); } else if (EmptyCollectionIfNull.class.getCanonicalName().equals(annotationName)) { return Tuple2.of(EmptyCollectionIfNull.class, typedMap); } else if (Enumerated.class.getCanonicalName().equals(annotationName)) { final Enumerated.Encoding encoding = Arrays.asList(annotationBinding.getElementValuePairs()).stream() .filter(pair -> new String(pair.getName()).equals("value")).map(pair -> pair.getValue()) .filter(value -> value instanceof FieldBinding).map(value -> (FieldBinding) value) .filter(value -> Enumerated.Encoding.class.getCanonicalName().equals(value.type.debugName())) .map(value -> Enumerated.Encoding.valueOf(Enumerated.Encoding.class, new String(value.name))) .findFirst().orElse(Enumerated.Encoding.NAME); typedMap.put("value", encoding); return Tuple2.of(Enumerated.class, typedMap); } else if (Frozen.class.getCanonicalName().equals(annotationName)) { return Tuple2.of(Frozen.class, typedMap); } else if (Computed.class.getCanonicalName().equals(annotationName)) { final List<ElementValuePair> pairs = Arrays.asList(annotationBinding.getElementValuePairs()); final String functionName = ((StringConstant) pairs.stream() .filter(pair -> new String(pair.getName()).equals("function")).findFirst().get().getValue()) .stringValue();/* w w w.ja v a 2 s .c om*/ final String alias = ((StringConstant) pairs.stream() .filter(pair -> new String(pair.getName()).equals("alias")).findFirst().get().getValue()) .stringValue(); final String cqlClassName = ((ReferenceBinding) pairs.stream() .filter(pair -> new String(pair.getName()).equals("cqlClass")).findFirst().get().getValue()) .debugName(); Class<?> cqlClass = null; try { cqlClass = Class.forName(cqlClassName); } catch (ClassNotFoundException e) { aptUtils.printError("Cannot find CQL class %s", cqlClassName); } final List<String> targetColumns = Arrays .asList((Object[]) pairs.stream() .filter(pair -> new String(pair.getName()).equals("targetColumns")).findFirst().get() .getValue()) .stream().map(object -> (StringConstant) object) .map(stringConstant -> stringConstant.stringValue()).collect(toList()); typedMap.put("function", functionName); typedMap.put("alias", alias); typedMap.put("cqlClass", cqlClass); typedMap.put("targetColumns", targetColumns); return Tuple2.of(Computed.class, typedMap); } else if (Counter.class.getCanonicalName().equals(annotationName)) { return Tuple2.of(Counter.class, typedMap); } else if (TimeUUID.class.getCanonicalName().equals(annotationName)) { return Tuple2.of(TimeUUID.class, typedMap); } else if (ASCII.class.getCanonicalName().equals(annotationName)) { return Tuple2.of(ASCII.class, typedMap); } else if (Codec.class.getCanonicalName().equals(annotationName)) { final Optional<String> codecClassName = Arrays.asList(annotationBinding.getElementValuePairs()).stream() .filter(pair -> new String(pair.getName()).equals("value")).map(pair -> pair.getValue()) .filter(value -> value instanceof ReferenceBinding) .map(value -> ((ReferenceBinding) value).debugName()).findFirst(); aptUtils.validateTrue(codecClassName.isPresent(), "Cannot find codec class on '%s' for type '%s", Codec.class.getCanonicalName(), currentType); final CodecContext codecContext = CodecFactory.buildCodecContext(aptUtils, codecClassName.get()); typedMap.put("codecContext", codecContext); return Tuple2.of(Codec.class, typedMap); } else if (RuntimeCodec.class.getCanonicalName().equals(annotationName)) { final List<ElementValuePair> pairs = Arrays.asList(annotationBinding.getElementValuePairs()); final Optional<String> codecName = pairs.stream() .filter(pair -> new String(pair.getName()).equals("codecName")).findFirst() .map(x -> (StringConstant) x.getValue()).map(x -> x.stringValue()); final String targetTypeName = ((ReferenceBinding) pairs.stream() .filter(pair -> new String(pair.getName()).equals("cqlClass")).findFirst().get().getValue()) .debugName(); Class<?> targetType = null; try { targetType = Class.forName(targetTypeName); } catch (ClassNotFoundException e) { aptUtils.printError("Cannot find CQL class %s", targetTypeName); } final RuntimeCodecContext runtimeCodecContext = new RuntimeCodecContext(TypeName.get(currentType), TypeName.get(targetType), codecName); typedMap.put("runtimeCodecContext", runtimeCodecContext); return Tuple2.of(RuntimeCodec.class, typedMap); } else if (Index.class.getCanonicalName().equals(annotationName)) { final List<ElementValuePair> pairs = Arrays.asList(annotationBinding.getElementValuePairs()); final String name = pairs.stream().filter(pair -> new String(pair.getName()).equals("name")) .map(pair -> ((StringConstant) pair.getValue()).stringValue()).findFirst().orElse(""); final String indexClassName = pairs.stream() .filter(pair -> new String(pair.getName()).equals("indexClassName")) .map(pair -> ((StringConstant) pair.getValue()).stringValue()).findFirst().orElse(""); final String indexOptions = pairs.stream() .filter(pair -> new String(pair.getName()).equals("indexOptions")) .map(pair -> ((StringConstant) pair.getValue()).stringValue()).findFirst().orElse(""); typedMap.put("indexInfoContext", new IndexInfoContext(name, indexClassName, indexOptions)); return Tuple2.of(Index.class, typedMap); } else if (SASI.class.getCanonicalName().equals(annotationName)) { final List<ElementValuePair> pairs = Arrays.asList(annotationBinding.getElementValuePairs()); final String indexName = pairs.stream().filter(pair -> new String(pair.getName()).equals("name")) .map(pair -> ((StringConstant) pair.getValue()).stringValue()).findFirst().orElse(""); final IndexMode indexMode = pairs.stream() .filter(pair -> new String(pair.getName()).equals("indexMode")).map(pair -> pair.getValue()) .filter(value -> value instanceof FieldBinding).map(value -> (FieldBinding) value) .filter(value -> IndexMode.class.getCanonicalName().equals(value.type.debugName())) .map(value -> IndexMode.valueOf(IndexMode.class, new String(value.name))).findFirst() .orElse(IndexMode.PREFIX); final boolean analyzed = pairs.stream().filter(pair -> new String(pair.getName()).equals("analyzed")) .map(pair -> ((BooleanConstant) pair.getValue()).booleanValue()).findFirst().orElse(false); final Analyzer analyzerClass = pairs.stream() .filter(pair -> new String(pair.getName()).equals("analyzerClass")).map(pair -> pair.getValue()) .filter(value -> value instanceof FieldBinding).map(value -> (FieldBinding) value) .filter(value -> Analyzer.class.getCanonicalName().equals(value.type.debugName())) .map(value -> Analyzer.valueOf(Analyzer.class, new String(value.name))).findFirst() .orElse(Analyzer.NO_OP_ANALYZER); final int maxCompactionFlushMemoryInMb = pairs.stream() .filter(pair -> new String(pair.getName()).equals("maxCompactionFlushMemoryInMb")) .map(pair -> ((IntConstant) pair.getValue()).intValue()).findFirst().orElse(1024); final Normalization normalization = pairs.stream() .filter(pair -> new String(pair.getName()).equals("normalization")).map(pair -> pair.getValue()) .filter(value -> value instanceof FieldBinding).map(value -> (FieldBinding) value) .filter(value -> Normalization.class.getCanonicalName().equals(value.type.debugName())) .map(value -> Analyzer.valueOf(Normalization.class, new String(value.name))).findFirst() .orElse(Normalization.NONE); final String locale = pairs.stream().filter(pair -> new String(pair.getName()).equals("locale")) .map(pair -> ((StringConstant) pair.getValue()).stringValue()).findFirst().orElse("en"); final boolean enableStemming = pairs.stream() .filter(pair -> new String(pair.getName()).equals("enableStemming")) .map(pair -> ((BooleanConstant) pair.getValue()).booleanValue()).findFirst().orElse(false); final boolean skipStopWords = pairs.stream() .filter(pair -> new String(pair.getName()).equals("skipStopWords")) .map(pair -> ((BooleanConstant) pair.getValue()).booleanValue()).findFirst().orElse(false); typedMap.put("sasiInfoContext", new SASIInfoContext(indexName, indexMode, analyzed, analyzerClass, maxCompactionFlushMemoryInMb, normalization, locale, enableStemming, skipStopWords)); return Tuple2.of(SASI.class, typedMap); } else if (DSE_Search.class.getCanonicalName().equals(annotationName)) { final List<ElementValuePair> pairs = Arrays.asList(annotationBinding.getElementValuePairs()); final boolean fullTextSearchEnabled = pairs.stream() .filter(pair -> new String(pair.getName()).equals("fullTextSearchEnabled")) .map(pair -> ((BooleanConstant) pair.getValue()).booleanValue()).findFirst().orElse(false); typedMap.put("dseSearchInfoContext", new DSESearchInfoContext(fullTextSearchEnabled)); return Tuple2.of(DSE_Search.class, typedMap); } else if (PartitionKey.class.getCanonicalName().equals(annotationName)) { final List<ElementValuePair> pairs = Arrays.asList(annotationBinding.getElementValuePairs()); final Integer order = pairs.stream().filter(pair -> new String(pair.getName()).equals("value")) .map(pair -> ((IntConstant) pair.getValue()).intValue()).findFirst().orElse(1); typedMap.put("order", order); return Tuple2.of(PartitionKey.class, typedMap); } else if (ClusteringColumn.class.getCanonicalName().equals(annotationName)) { final List<ElementValuePair> pairs = Arrays.asList(annotationBinding.getElementValuePairs()); final Integer order = pairs.stream().filter(pair -> new String(pair.getName()).equals("value")) .map(pair -> ((IntConstant) pair.getValue()).intValue()).findFirst().orElse(1); final Boolean asc = pairs.stream().filter(pair -> new String(pair.getName()).equals("asc")) .map(pair -> ((BooleanConstant) pair.getValue()).booleanValue()).findFirst().orElse(true); typedMap.put("order", order); typedMap.put("asc", asc); return Tuple2.of(ClusteringColumn.class, typedMap); } else { aptUtils.printError("Unsupported annotation : " + annotationName); throw new IllegalArgumentException("Unsupported annotation : " + annotationName.toString()); } }
From source file:lombok.eclipse.agent.PatchDelegate.java
License:Open Source License
private static void failIfContainsAnnotation(TypeBinding parent, Binding[] bindings) throws DelegateRecursion { if (bindings == null) return;/*from w w w . j a v a 2 s . co m*/ for (Binding b : bindings) { AnnotationBinding[] anns = null; if (b instanceof MethodBinding) anns = ((MethodBinding) b).getAnnotations(); if (b instanceof FieldBinding) anns = ((FieldBinding) b).getAnnotations(); // anns = b.getAnnotations() would make a heck of a lot more sense, but that is a late addition to ecj, so would cause NoSuchMethodErrors! Don't use that! if (anns == null) continue; for (AnnotationBinding ann : anns) { char[][] name = null; try { name = ann.getAnnotationType().compoundName; } catch (Exception ignore) { } if (name == null || name.length < 2 || name.length > 3) continue; if (!Arrays.equals(STRING_LOMBOK, name[0])) continue; if (!Arrays.equals(STRING_DELEGATE, name[name.length - 1])) continue; if (name.length == 3 && !Arrays.equals(STRING_EXPERIMENTAL, name[1])) continue; throw new DelegateRecursion(parent.readableName(), b.readableName()); } } }
From source file:lombok.eclipse.agent.PatchVisibleForTesting.java
License:Open Source License
private static MethodBinding handleVisibleForTestingOnMethod(final Scope scope, final MethodBinding methodBinding) { if ((methodBinding == null) || (methodBinding.declaringClass == null)) return methodBinding; for (AnnotationBinding annotation : Each.elementIn(methodBinding.getAnnotations())) { if (!As.string(annotation.getAnnotationType()).contains("VisibleForTesting")) continue; ClassScope classScope = scope.outerMostClassScope(); if (classScope == null) continue; TypeDeclaration decl = classScope.referenceContext; if ((methodBinding.declaringClass == decl.binding) || As.string(decl.name).contains("Test")) continue; return new ProblemMethodBinding(methodBinding, methodBinding.selector, methodBinding.parameters, ProblemReasons.NotVisible); }//w ww. j a va 2 s . co m return methodBinding; }