List of usage examples for org.eclipse.jdt.internal.compiler.lookup AnnotationBinding getElementValuePairs
public ElementValuePair[] getElementValuePairs()
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; }// w w w.j a v a 2 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
public static String getAnnotationParameterString(AnnotationBinding a, String paramName) { if (a != null) { for (ElementValuePair maybeValue : a.getElementValuePairs()) { if (maybeValue.getValue() instanceof StringConstant && paramName.equals(String.valueOf(maybeValue.getName()))) { return ((StringConstant) maybeValue.getValue()).stringValue(); }/*from w ww . jav a2 s . co m*/ } } return null; }
From source file:com.google.gwt.dev.javac.JdtUtil.java
License:Apache License
public static boolean getAnnotationParameterBoolean(AnnotationBinding a, String paramName) { if (a != null) { for (ElementValuePair maybeValue : a.getElementValuePairs()) { if (maybeValue.getValue() instanceof BooleanConstant && paramName.equals(String.valueOf(maybeValue.getName()))) { return ((BooleanConstant) maybeValue.getValue()).booleanValue(); }/*from w w w . j a v a 2 s .com*/ } } return false; }
From source file:com.google.gwt.dev.javac.JdtUtil.java
License:Apache License
public static TypeBinding getAnnotationParameterTypeBinding(AnnotationBinding a, String paramName) { if (a != null) { for (ElementValuePair maybeValue : a.getElementValuePairs()) { if (maybeValue.getValue() instanceof Class && paramName.equals(String.valueOf(maybeValue.getName()))) { return (TypeBinding) maybeValue.getValue(); }//from www .j av a 2s. com } } return null; }
From source file:com.google.gwt.dev.javac.JdtUtil.java
License:Apache License
public static TypeBinding[] getAnnotationParameterTypeBindingArray(AnnotationBinding annotationBinding, String paramName) {/*from w w w. j a v a 2s. c o m*/ if (annotationBinding == null) { return null; } for (ElementValuePair maybeValue : annotationBinding.getElementValuePairs()) { Object value = maybeValue.getValue(); if (!paramName.equals(String.valueOf(maybeValue.getName()))) { continue; } if (value instanceof Object[]) { Object[] values = (Object[]) value; TypeBinding bindings[] = new TypeBinding[values.length]; System.arraycopy(values, 0, bindings, 0, values.length); return bindings; } assert value instanceof TypeBinding; return new TypeBinding[] { (TypeBinding) value }; } return null; }
From source file:com.redhat.ceylon.eclipse.core.model.mirror.JDTAnnotation.java
License:Open Source License
public JDTAnnotation(AnnotationBinding annotation) { values = new HashMap<String, Object>(); ElementValuePair[] annotationVaues = annotation.getElementValuePairs(); for (ElementValuePair annotationValue : annotationVaues) { String name = new String(annotationValue.getName()); MethodBinding elementMethod = annotationValue.getMethodBinding(); Object value = null;/*from ww w.ja v a 2 s .c o m*/ if (elementMethod != null) { value = convertValue(annotationValue.getMethodBinding().returnType, annotationValue.getValue()); } else { value = JDTType.UNKNOWN_TYPE; } values.put(name, value); } }
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 . j av a 2 s .co m 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:org.eclipse.objectteams.otdt.internal.core.compiler.model.RoleModel.java
License:Open Source License
public static Lifting.InstantiationPolicy getInstantiationPolicy(ReferenceBinding roleClassBinding) { if ((roleClassBinding.getAnnotationTagBits() & TagBits.AnnotationInstantiation) != 0) { for (AnnotationBinding annotation : roleClassBinding.getAnnotations()) { if (annotation.getAnnotationType().id == IOTConstants.T_OrgObjectTeamsInstantiation) { for (ElementValuePair pair : annotation.getElementValuePairs()) { if (pair.value instanceof FieldBinding) { String name = String.valueOf(((FieldBinding) pair.value).name); try { return InstantiationPolicy.valueOf(name); } catch (IllegalArgumentException iae) { return InstantiationPolicy.ERROR; }/*from w w w . j a v a 2 s . co m*/ } } } } } return InstantiationPolicy.ONDEMAND; // default }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.AstConverter.java
License:Open Source License
public static FieldDeclaration createField(FieldBinding fieldBinding, TypeDeclaration roleDeclaration, AstGenerator gen) {/*from w w w. j a v a2 s . c o m*/ if (fieldBinding == null) return null; FieldDeclaration fieldDeclaration = new FieldDeclaration(); fieldDeclaration.type = gen.typeReference(fieldBinding.type); fieldDeclaration.modifiers = (fieldBinding.modifiers & ~ExtraCompilerModifiers.AccBlankFinal); // this modifier is not used on fieldDecl (AST), overlaps with AccReadOnly fieldDeclaration.name = fieldBinding.name; if (fieldBinding.copyInheritanceSrc != null) fieldDeclaration.copyInheritanceSrc = fieldBinding.copyInheritanceSrc; else fieldDeclaration.copyInheritanceSrc = fieldBinding; AnnotationBinding[] annotBindings = fieldBinding.getAnnotations(); if (annotBindings != Binding.NO_ANNOTATIONS) { ProblemReporter pr = fieldBinding.isStatic() ? roleDeclaration.staticInitializerScope.problemReporter() : roleDeclaration.initializerScope.problemReporter(); Annotation[] annotDecls = new Annotation[annotBindings.length]; boolean hasAnnotationError = false; for (int i = 0; i < annotBindings.length; i++) { AnnotationBinding binding = annotBindings[i]; ElementValuePair[] elementValuePairs = binding.getElementValuePairs(); char[][] annotTypeName = binding.getAnnotationType().compoundName; if (elementValuePairs == Binding.NO_ELEMENT_VALUE_PAIRS) { annotDecls[i] = gen.markerAnnotation(annotTypeName); } else { int numPairs = elementValuePairs.length; char[][] names = new char[numPairs][]; Expression[] values = new Expression[numPairs]; for (int j = 0; j < names.length; j++) { names[j] = elementValuePairs[j].getName(); Object elementValue = elementValuePairs[j].getValue(); values[j] = annotationValues(elementValue, gen, pr); } if (values.length == 0 || values[0] == null) { pr.unexpectedAnnotationStructure(annotTypeName, fieldBinding.name, gen.sourceStart, gen.sourceEnd); hasAnnotationError = true; } else if (numPairs == 1 && CharOperation.equals(names[0], TypeConstants.VALUE)) { annotDecls[i] = gen.singleMemberAnnotation(annotTypeName, values[0]); } else { annotDecls[i] = gen.normalAnnotation(annotTypeName, names, values); } } } if (!hasAnnotationError) fieldDeclaration.annotations = annotDecls; } //field initializations are copied using a RoleInitializationMethod return fieldDeclaration; }