Java 类javax.lang.model.element.AnnotationValue 实例源码

项目:auto-value-step-builder    文件:AnnotationOutput.java   
@Override
public Void visitAnnotation(AnnotationMirror a, StringBuilder sb) {
  sb.append('@').append(typeSimplifier.simplify(a.getAnnotationType()));
  Map<ExecutableElement, AnnotationValue> map =
      ImmutableMap.<ExecutableElement, AnnotationValue>copyOf(a.getElementValues());
  if (!map.isEmpty()) {
    sb.append('(');
    String sep = "";
    for (Map.Entry<ExecutableElement, AnnotationValue> entry : map.entrySet()) {
      sb.append(sep).append(entry.getKey().getSimpleName()).append(" = ");
      sep = ", ";
      this.visit(entry.getValue(), sb);
    }
    sb.append(')');
  }
  return null;
}
项目:openjdk-jdk10    文件:AbstractVerifier.java   
protected static AnnotationValue findAnnotationValue(AnnotationMirror mirror, String name) {
    ExecutableElement valueMethod = null;
    for (ExecutableElement method : ElementFilter.methodsIn(mirror.getAnnotationType().asElement().getEnclosedElements())) {
        if (method.getSimpleName().toString().equals(name)) {
            valueMethod = method;
            break;
        }
    }

    if (valueMethod == null) {
        return null;
    }

    AnnotationValue value = mirror.getElementValues().get(valueMethod);
    if (value == null) {
        value = valueMethod.getDefaultValue();
    }

    return value;
}
项目:DUnit    文件:DUnitModelUtil.java   
/*************当注解的参数为Class类型时,如果使用的apt技术,直接去获取Class会报异常,因为,此时jvm还没有运行,Class尚未加载*****************/
    public void getClassType(TypeElement type, DUnit dUnit) {
        if (dUnit != null){
//          mErrorReporter.reportWaring("asType:" + type.asType() + "     |getNestingKind:" + type.getNestingKind() + "     |getAnnotation:" + type.getAnnotation(DUnitGroup.class) + "    |getAnnotationMirrors:" + type.getAnnotationMirrors());
            List<? extends AnnotationMirror> mirrors = type.getAnnotationMirrors();
            AnnotationMirror mirror = mirrors.get(0);
            Map<? extends ExecutableElement, ? extends AnnotationValue> map = mirror.getElementValues();
            Set<? extends Map.Entry<? extends ExecutableElement, ? extends AnnotationValue>> entries = map.entrySet();
            for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry :
                    entries) {
                ExecutableElement executableElement = entry.getKey();
                mErrorReporter.reportWaring("executableElement" + executableElement);
                AnnotationValue annotationValue = entry.getValue();
                Object object = annotationValue.getValue();
//              boolean isClassType = object instanceof Type.ClassType;
//              if (isClassType){
//                  Type.ClassType classType = (Type.ClassType) object;
//                  mErrorReporter.reportWaring(classType.toString() + "  |  " + classType.getOriginalType() + "  |  "  + classType.getKind() + "  |  "  + classType.getReturnType()  +  "   |  "  + classType.getUpperBound());
//              }
            }

        }
    }
项目:openjdk-jdk10    文件:MatchProcessor.java   
private static AnnotationValue getAnnotationValue(AnnotationMirror mirror, String name) {
    ExecutableElement valueMethod = null;
    for (ExecutableElement method : ElementFilter.methodsIn(mirror.getAnnotationType().asElement().getEnclosedElements())) {
        if (method.getSimpleName().toString().equals(name)) {
            valueMethod = method;
            break;
        }
    }

    if (valueMethod == null) {
        return null;
    }

    AnnotationValue value = mirror.getElementValues().get(valueMethod);
    if (value == null) {
        value = valueMethod.getDefaultValue();
    }

    return value;
}
项目:openjdk-jdk10    文件:MatchProcessor.java   
@SuppressWarnings({"unchecked"})
private static <T> T resolveAnnotationValue(Class<T> expectedType, AnnotationValue value) {
    if (value == null) {
        return null;
    }

    Object unboxedValue = value.accept(new AnnotationValueVisitorImpl(), null);
    if (unboxedValue != null) {
        if (expectedType == TypeMirror.class && unboxedValue instanceof String) {
            return null;
        }
        if (!expectedType.isAssignableFrom(unboxedValue.getClass())) {
            throw new ClassCastException(unboxedValue.getClass().getName() + " not assignable from " + expectedType.getName());
        }
    }
    return (T) unboxedValue;
}
项目:react4j    文件:ProcessorUtil.java   
@Nullable
private static AnnotationValue findAnnotationValue( @Nonnull final Elements elements,
                                                    @Nonnull final Element typeElement,
                                                    @Nonnull final String annotationClassName,
                                                    @Nonnull final String parameterName )
{
  final AnnotationMirror mirror = getAnnotationByType( typeElement, annotationClassName );
  final Map<? extends ExecutableElement, ? extends AnnotationValue> values =
    elements.getElementValuesWithDefaults( mirror );
  final ExecutableElement annotationKey = values.keySet().stream().
    filter( k -> parameterName.equals( k.getSimpleName().toString() ) ).findFirst().orElse( null );
  return values.get( annotationKey );
}
项目:incubator-netbeans    文件:CodeGenerator.java   
private AnnotationTree computeAnnotationTree(AnnotationMirror am) {
    List<ExpressionTree> params = new LinkedList<ExpressionTree>();

    for (Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : am.getElementValues().entrySet()) {
        ExpressionTree val = createTreeForAnnotationValue(make, entry.getValue());

        if (val == null) {
            LOG.log(Level.WARNING, "Cannot create annotation for: {0}", entry.getValue());
            continue;
        }

        ExpressionTree vt = make.Assignment(make.Identifier(entry.getKey().getSimpleName()), val);

        params.add(vt);
    }

    return make.Annotation(make.Type(am.getAnnotationType()), params);
}
项目:openjdk-jdk10    文件:ElementStructureTest.java   
private void writeAnnotations(Iterable<? extends AnnotationMirror> annotations) throws IOException {
    for (AnnotationMirror ann : annotations) {
        out.write("@");
        write(ann.getAnnotationType());
        if (!ann.getElementValues().isEmpty()) {
            out.write("(");
            Map<ExecutableElement, AnnotationValue> valuesMap = new TreeMap<>((a1, a2) -> a1.getSimpleName().toString().compareTo(a2.getSimpleName().toString()));
            valuesMap.putAll(ann.getElementValues());
            for (Entry<? extends ExecutableElement, ? extends AnnotationValue> ev : valuesMap.entrySet()) {
                out.write(ev.getKey().getSimpleName().toString());
                out.write(" = ");
                out.write(ev.getValue().toString());
            }
            out.write(")");
        }
    }
}
项目:incubator-netbeans    文件:ElementJavadoc.java   
private void appendAnnotation(StringBuilder sb, AnnotationMirror annotationDesc, boolean topLevel) {
    DeclaredType annotationType = annotationDesc.getAnnotationType();
    if (annotationType != null && (!topLevel || isDocumented(annotationType))) {
        appendType(sb, annotationType, false, false, true);
        Map<? extends ExecutableElement, ? extends AnnotationValue> values = annotationDesc.getElementValues();
        if (!values.isEmpty()) {
            sb.append('('); //NOI18N
            for (Iterator<? extends Map.Entry<? extends ExecutableElement, ? extends AnnotationValue>> it = values.entrySet().iterator(); it.hasNext();) {
                Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> value = it.next();
                createLink(sb, value.getKey(), value.getKey().getSimpleName());
                sb.append('='); //NOI18N
                appendAnnotationValue(sb, value.getValue());
                if (it.hasNext())
                    sb.append(","); //NOI18N
            }
            sb.append(')'); //NOI18N
        }
        if (topLevel)
            sb.append("<br>"); //NOI18N
    }
}
项目:incubator-netbeans    文件:ElementJavadoc.java   
private void appendAnnotationValue(StringBuilder sb, AnnotationValue av) {
    Object value = av.getValue();
    if (value instanceof List) {
        List<? extends AnnotationValue> list = (List<? extends AnnotationValue>)value;            
        if (list.size() > 1)
            sb.append('{'); //NOI18N
        for (Iterator<? extends AnnotationValue> it = list.iterator(); it.hasNext();) {
            AnnotationValue val = it.next();
            appendAnnotationValue(sb, val);
            if (it.hasNext())
                sb.append(","); //NOI18N
        }
        if (list.size() > 1)
            sb.append('}'); //NOI18N
    } else if (value instanceof String) {
        sb.append('"').append(value).append('"'); //NOI18N
    } else if (value instanceof TypeMirror) {
        appendType(sb, (TypeMirror)value, false, false, false);
    } else if (value instanceof VariableElement) {
        createLink(sb, (VariableElement)value, ((VariableElement)value).getSimpleName());
    } else if (value instanceof AnnotationMirror) {
        appendAnnotation(sb, (AnnotationMirror)value, false);
    } else {
        sb.append(value.toString());
    }
}
项目:jtsgen    文件:TSModuleHandler.java   
List<Pattern> convertExclusion(AnnotationValue exclAnnotationValue, Element element) {
    if (exclAnnotationValue == null) return null;
    return new SimpleAnnotationValueVisitor8<List<Pattern>, Void>() {
        @Override
        public List<Pattern> visitArray(List<? extends AnnotationValue> vals, Void aVoid) {
            return vals.stream()
                    .map(x -> {
                        String value = (String) x.getValue();
                        Optional<Pattern> result = compileToPattern(value);
                        if (!result.isPresent())
                            env.getMessager().printMessage(Diagnostic.Kind.ERROR, "param not valid. Expecting a regular Expression. Got:" + x, element);
                        return result;
                    })
                    .filter(Optional::isPresent)
                    .map(Optional::get)
                    .collect(Collectors.toList());
        }

    }.visit(exclAnnotationValue);
}
项目:incubator-netbeans    文件:JUnit4TestGenerator.java   
/**
 * Checks that the given annotation is of type
 * <code>{@value #ANN_RUN_WITH}</code> and contains argument
 * <code>{@value #ANN_SUITE}{@literal .class}</code>.
 * 
 * @param  annMirror  annotation to be checked
 * @return  {@code true} if the annotation meets the described criteria,
 *          {@code false} otherwise
 */
private boolean checkRunWithSuiteAnnotation(AnnotationMirror annMirror,
                                            WorkingCopy workingCopy) {
    Map<? extends ExecutableElement,? extends AnnotationValue> annParams
            = annMirror.getElementValues();

    if (annParams.size() != 1) {
        return false;
    }

    AnnotationValue annValue = annParams.values().iterator().next();
    Name annValueClsName = getAnnotationValueClassName(annValue,
                                                       workingCopy.getTypes());
    return annValueClsName != null
           ? annValueClsName.contentEquals(ANN_SUITE)
           : false;
}
项目:incubator-netbeans    文件:MappedSuperclassImpl.java   
boolean refresh(TypeElement typeElement) {
    class2 = typeElement.getQualifiedName().toString();
    AnnotationModelHelper helper = getHelper();
    Map<String, ? extends AnnotationMirror> annByType = helper.getAnnotationsByType(typeElement.getAnnotationMirrors());
    AnnotationMirror embeddableAnn = annByType.get("javax.persistence.MappedSuperclass"); // NOI18N
    AnnotationMirror entityAcc = annByType.get("javax.persistence.Access"); // NOI18N
    if (entityAcc != null) {
        entityAcc.getElementValues();
        AnnotationParser parser = AnnotationParser.create(helper);
        parser.expect("value", new ValueProvider() {
            @Override
            public Object getValue(AnnotationValue elementValue) {
                return elementValue.toString();
            }

            @Override
            public Object getDefaultValue() {
                return null;
            }
        });//NOI18N
        ParseResult parseResult = parser.parse(entityAcc);
        accessType = parseResult.get("value", String.class);
    }
    return embeddableAnn != null;
}
项目:openjdk-jdk10    文件:Utils.java   
/**
 * Return true if the given Element is deprecated for removal.
 *
 * @param e the Element to check.
 * @return true if the given Element is deprecated for removal.
 */
public boolean isDeprecatedForRemoval(Element e) {
    List<? extends AnnotationMirror> annotationList = e.getAnnotationMirrors();
    JavacTypes jctypes = ((DocEnvImpl) configuration.docEnv).toolEnv.typeutils;
    for (AnnotationMirror anno : annotationList) {
        if (jctypes.isSameType(anno.getAnnotationType().asElement().asType(), getDeprecatedType())) {
            Map<? extends ExecutableElement, ? extends AnnotationValue> pairs = anno.getElementValues();
            if (!pairs.isEmpty()) {
                for (ExecutableElement element : pairs.keySet()) {
                    if (element.getSimpleName().contentEquals("forRemoval")) {
                        return Boolean.parseBoolean((pairs.get(element)).toString());
                    }
                }
            }
        }
    }
    return false;
}
项目:incubator-netbeans    文件:EntityMappingsUtilities.java   
public static List<JoinColumn> getJoinColumns(final AnnotationModelHelper helper, Map<String, ? extends AnnotationMirror> annByType) {
    final List<JoinColumn> result = new ArrayList<JoinColumn>();
    AnnotationMirror joinColumnAnn = annByType.get("javax.persistence.JoinColumn"); // NOI18N
    if (joinColumnAnn != null) {
        result.add(new JoinColumnImpl(helper, joinColumnAnn));
    } else {
        AnnotationMirror joinColumnsAnnotation = annByType.get("javax.persistence.JoinColumns"); // NOI18N
        if (joinColumnsAnnotation != null) {
            AnnotationParser jcParser = AnnotationParser.create(helper);
            jcParser.expectAnnotationArray("value", helper.resolveType("javax.persistence.JoinColumn"), new ArrayValueHandler() { // NOI18N
                public Object handleArray(List<AnnotationValue> arrayMembers) {
                    for (AnnotationValue arrayMember : arrayMembers) {
                        AnnotationMirror joinColumnAnnotation = (AnnotationMirror)arrayMember.getValue();
                        result.add(new JoinColumnImpl(helper, joinColumnAnnotation));
                    }
                    return null;
                }
            }, null);
            jcParser.parse(joinColumnsAnnotation);
        }
    }
    return result;
}
项目:incubator-netbeans    文件:EntityMappingsUtilities.java   
public static List<PrimaryKeyJoinColumn> getPrimaryKeyJoinColumns(final AnnotationModelHelper helper, Map<String, ? extends AnnotationMirror> annByType) {
    final List<PrimaryKeyJoinColumn> result = new ArrayList<PrimaryKeyJoinColumn>();
    AnnotationMirror pkJoinColumnAnn = annByType.get("javax.persistence.PrimaryKeyJoinColumn"); // NOI18N
    if (pkJoinColumnAnn != null) {
        result.add(new PrimaryKeyJoinColumnImpl(helper, pkJoinColumnAnn));
    } else {
        AnnotationMirror pkJoinColumnsAnnotation = annByType.get("javax.persistence.PrimaryKeyJoinColumns"); // NOI18N
        if (pkJoinColumnsAnnotation != null) {
            AnnotationParser pkjcParser = AnnotationParser.create(helper);
            pkjcParser.expectAnnotationArray("value", helper.resolveType("javax.persistence.PrimaryKeyJoinColumn"), new ArrayValueHandler() { // NOI18N
                public Object handleArray(List<AnnotationValue> arrayMembers) {
                    for (AnnotationValue arrayMember : arrayMembers) {
                        AnnotationMirror joinColumnAnnotation = (AnnotationMirror)arrayMember.getValue();
                        result.add(new PrimaryKeyJoinColumnImpl(helper, joinColumnAnnotation));
                    }
                    return null;
                }
            }, null);
            pkjcParser.parse(pkJoinColumnsAnnotation);
        }
    }
    return result;
}
项目:incubator-netbeans    文件:ManyToOneImpl.java   
public ManyToOneImpl(final AnnotationModelHelper helper, final Element element, AnnotationMirror manyToOneAnnotation, String name, Map<String, ? extends AnnotationMirror> annByType) {
    this.name = name;
    AnnotationParser parser = AnnotationParser.create(helper);
    parser.expectClass("targetEntity", new DefaultProvider() { // NOI18N
        public Object getDefaultValue() {
            return EntityMappingsUtilities.getElementTypeName(element);
        }
    });
    parser.expectEnumConstantArray("cascade", helper.resolveType("javax.persistence.CascadeType"), new ArrayValueHandler() { // NOI18N
        public Object handleArray(List<AnnotationValue> arrayMembers) {
            return new CascadeTypeImpl(arrayMembers);
        }
    }, parser.defaultValue(new CascadeTypeImpl()));
    parser.expectEnumConstant("fetch", helper.resolveType("javax.persistence.FetchType"), parser.defaultValue("EAGER")); // NOI18N
    parser.expectPrimitive("optional", Boolean.class, parser.defaultValue(true)); // NOI18N
    parseResult = parser.parse(manyToOneAnnotation);

    joinTable = new JoinTableImpl(helper, annByType.get("javax.persistence.JoinTable")); // NOI18N
    joinColumnList = EntityMappingsUtilities.getJoinColumns(helper, annByType);
}
项目:incubator-netbeans    文件:FxClassUtils.java   
/**
 * Attempts to find the {@code @DefaultProperty} annotation on the type, and returns
 * the default property name. Returns null, if @DefaultProperty is not defined
 * 
 * @param te type to inspect
 * @return default property name, or {@code null} if default property is not defined for the type.
 */
public static String getDefaultProperty(TypeElement te) {
    for (AnnotationMirror an : te.getAnnotationMirrors()) {
        if (!((TypeElement)an.getAnnotationType().asElement()).getQualifiedName().contentEquals(DEFAULT_PROPERTY_TYPE_NAME)) {
            continue;
        }
        Map<? extends ExecutableElement, ? extends AnnotationValue> m =  an.getElementValues();
        for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> en : m.entrySet()) {
            if (en.getKey().getSimpleName().contentEquals(DEFAULT_PROPERTY_VALUE_NAME)) {
                Object v = en.getValue().getValue();
                return v == null ? null : v.toString();
            }
        }
    }
    return null;
}
项目:jtsgen    文件:TSModuleHandlerTest.java   
@Before
public void init() {
    Messager messenger = mock(Messager.class);

    this.annotationValue = mock(AnnotationValue.class);

    this.annotationTypeMirror = mock(TypeMirror.class);
    this.executableElement = mock(ExecutableElement.class);

    this.annotationElement = mock(TypeElement.class);
    when(this.annotationElement.asType()).thenReturn(this.annotationTypeMirror);

    this.elementUtils = mock(Elements.class);
    when(this.elementUtils.getTypeElement(any())).thenReturn(this.annotationElement);

    this.processingEnv = mock(ProcessingEnvironment.class);
    when(processingEnv.getMessager()).thenReturn(messenger);
    when(processingEnv.getElementUtils()).thenReturn(this.elementUtils);

    // finally....
    this.testee = new TSModuleHandler(processingEnv);
}
项目:Spyglass    文件:GetPlaceholderMethodGenerator.java   
@Override
public MethodSpec supplyFor(final AnnotationMirror useAnno, final int position) {
    final AnnotationValue rawValue = annoMirrorHelper.getValueUsingDefaults(useAnno, "value");

    return getBaseMethodSpec(position)
            .returns(String.class)
            .addCode(CodeBlock
                    .builder()
                    .addStatement("return ($T) $L", String.class, rawValue.toString())
                    .build())
            .build();
}
项目:jtsgen    文件:TSModuleHandler.java   
NameSpaceMappingStrategy convertNameSpaceMappingStrategy(AnnotationValue value) {
    return (value != null
            && value.getValue() != null
            && Arrays.stream(NameSpaceMappingStrategy.values()).anyMatch(x -> x.name().equals(value.getValue().toString())))
            ? NameSpaceMappingStrategy.valueOf(value.getValue().toString())
            :null;
}
项目:annotation-processor-toolkit    文件:AnnotationUtils.java   
/**
 * Gets the AnnotationValue for the passed key.
 * Only explicitly set AnnotationValues will be found.
 *
 * @param annotationMirror the annotation mirror to get the value from
 * @param key              the attribute key to search for
 * @return the AnnotationValue,  or null if the AnnotationValue with passed key cannot be found
 */
public static AnnotationValue getAnnotationValueOfAttribute(AnnotationMirror annotationMirror, String key) {
    for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotationMirror.getElementValues().entrySet()) {
        if (entry.getKey().getSimpleName().toString().equals(key)) {
            return entry.getValue();
        }
    }
    return null;
}
项目:Pogamut3    文件:ClassCrawler.java   
/**
 * Extract {@link PrimitiveData} information about the class.
 *
 * @param classFQN
 * @param annotation
 * @return
 */
private PrimitiveData getInfo(String classFQN, TypeElement classType, AnnotationMirror annotation) {
    String name = null;
    String description = null;
    List<String> tags = Collections.EMPTY_LIST;

    for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotation.getElementValues().entrySet()) {
        // name
        Name entryName = entry.getKey().getSimpleName();
        AnnotationValue entryValue = entry.getValue();
        if (entryName.contentEquals("name")) {
            name = getAnnotationValue(String.class, classFQN, "name", entryValue);
        } else if (entryName.contentEquals("description")) {
            description = getAnnotationValue(String.class, classFQN, "description", entryValue);
        } else if (entryName.contentEquals("tags")) {
            List<AnnotationValue> tagList = getAnnotationValue(List.class, classFQN, "tags", entryValue);
            if (tagList != null) {
                tags = new ArrayList<String>(tagList.size());
                for (AnnotationValue tagValue : tagList) {
                    String tag = getAnnotationValue(String.class, classFQN, "tags", tagValue);
                    if (tag != null) {
                        tags.add(tag);
                    }
                }
            }
        }
    }
    Set<ParamInfo> primitiveParams = getAnnotatedParams(classType);

    return new PrimitiveData(classFQN, name, description, tags.toArray(new String[tags.size()]), primitiveParams);
}
项目:annotation-processor-toolkit    文件:AnnotationUtils.java   
/**
 * Get all optional attribute value names
 * @param annotationMirror the annotation mirror to get the mandatory attribute names from
 * @return an array containing all mandatory attribute names
 */
public static String[] getOptionalAttributeValueNames( AnnotationMirror annotationMirror) {

    List<String> result = new ArrayList<String>();
    for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : ToolingProvider.getTooling().getElements().getElementValuesWithDefaults(annotationMirror).entrySet()) {
        if (entry.getKey().getDefaultValue() != null ) {
            result.add(entry.getKey().getSimpleName().toString());
        }
    }
    return result.toArray(new String[result.size()]);

}
项目:annotation-processor-toolkit    文件:AnnotationUtils.java   
/**
 * Gets the AnnotationValue for the passed key.
 * Also implicitly set default values will be found.
 *
 * @param annotationMirror     the annotation mirror to get the value from
 * @param key                  the attribute key to search for
 * @return the AnnotationValue,  or null if the AnnotationValue with passed key cannot be found
 */
public static AnnotationValue getAnnotationValueOfAttributeWithDefaults( AnnotationMirror annotationMirror, String key) {
    for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : ToolingProvider.getTooling().getElements().getElementValuesWithDefaults(annotationMirror).entrySet()) {
        if (entry.getKey().getSimpleName().toString().equals(key)) {
            return entry.getValue();
        }
    }
    return null;
}
项目:annotation-processor-toolkit    文件:AnnotationUtils.java   
public static TypeMirror getClassAttributeFromAnnotationAsTypeMirror(Element element, Class<? extends Annotation> annotationType, String attributeName) {

        AnnotationMirror annotationMirror = getAnnotationMirror(element, annotationType);
        if (annotationMirror == null) {
            return null;
        }
        AnnotationValue annotationAttributeValue = getAnnotationValueOfAttribute(annotationMirror, attributeName);
        if (annotationAttributeValue == null) {
            return null;
        } else {
            return (TypeMirror) annotationAttributeValue.getValue();
        }

    }
项目:sql-first-mapper    文件:SqlFirstAnnotationProcessor.java   
/**
 * At compile time classes can not be obtained from annotation directly.
 * This method extracts class information from annotation mirrors.
 *
 * @param element element annotated with {@link SqlSource} annotation
 * @param isReq   true for request, false for result parameters
 * @return list of class names from {@link SqlSource} annotation
 */
private List<String> getTypesFromAnnotation(Element element, boolean isReq) {
    TypeMirror sqlSourceTypeMirror = processingEnv.getElementUtils().getTypeElement(SqlSource.class.getName()).asType();
    //method names from SqlSource annotation
    String methodName = isReq ? "reqImpl" : "resImpl";
    List<? extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors();
    List<String> typeNames = new ArrayList<>();
    for (AnnotationMirror am : annotationMirrors) {
        if (!am.getAnnotationType().equals(sqlSourceTypeMirror)) {
            continue;
        }
        for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : am.getElementValues().entrySet()) {
            if (!methodName.equals(entry.getKey().getSimpleName().toString())) {
                continue;
            }
            AnnotationValue impResVal = entry.getValue();
            impResVal.accept(new SimpleAnnotationValueVisitor8<Void, Void>() {
                @Override
                public Void visitArray(List<? extends AnnotationValue> list, Void s) {
                    for (AnnotationValue val : list) {
                        TypeMirror typeMirror = (TypeMirror) val.getValue();
                        typeNames.add(typeMirror.toString());
                    }
                    return null;
                }
            }, null);
            break;
        }
    }
    return typeNames;
}
项目:glimpse    文件:RClassUtil.java   
static StyleableAnnotationValues getStyleableAnnotationValues(final Trees trees, final Elements elementUtils, final Types typeUtils, final Messager messager, final Element annotatedElement) {
    RClassReference styleableReference = null;
    RClassReference defaultValueReference = null;
    AnnotationMirror annotationMirror = null;

    for (final AnnotationMirror mirror : annotatedElement.getAnnotationMirrors()) {
        if (mirror.getAnnotationType().toString().equals(Styleable.class.getCanonicalName())) {
            annotationMirror = mirror;
            break;
        }
    }

    AnnotationValue value = null;
    AnnotationValue defaultValue = null;

    //noinspection ConstantConditions
    for (final Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotationMirror.getElementValues().entrySet()) {
        if (entry.getKey().getSimpleName().toString().equals("value")) {
            value = entry.getValue();
        } else if (entry.getKey().getSimpleName().toString().equals("defaultRes")) {
            defaultValue = entry.getValue();
        }
    }

    styleableReference = getRClassReference(trees, elementUtils, typeUtils, messager, annotatedElement, annotationMirror, value, StyleableField.VALUE_FIELD);

    if (defaultValue != null) {
        defaultValueReference = getRClassReference(trees, elementUtils, typeUtils, messager, annotatedElement, annotationMirror, defaultValue, StyleableField.DEFAULT_RES_FIELD);
    }

    return new StyleableAnnotationValues(styleableReference, defaultValueReference);
}
项目:incubator-netbeans    文件:AnnotationParser.java   
protected boolean checkMembers(List<AnnotationValue> arrayMembers) {
    for (AnnotationValue arrayMember : arrayMembers) {
        Object value = arrayMember.getValue();
        if (!(value instanceof TypeMirror)) {
            return false;
        }
        TypeMirror type = (TypeMirror)value;
        if (!TypeKind.DECLARED.equals(type.getKind())) {
            return false;
        }
    }
    return true;
}
项目:react4j    文件:ProcessorUtil.java   
@SuppressWarnings( "SameParameterValue" )
@Nullable
static DeclaredType getTypeMirrorAnnotationParameter( @Nonnull final Elements elements,
                                                      @Nonnull final Element typeElement,
                                                      @Nonnull final String annotationClassName,
                                                      @Nonnull final String parameterName )
{
  final AnnotationValue annotationValue =
    findAnnotationValue( elements, typeElement, annotationClassName, parameterName );
  return null == annotationValue ? null : (DeclaredType) annotationValue.getValue();
}
项目:Pogamut3    文件:ClassCrawler.java   
private PrimitiveData getInfo(String classFQN, AnnotationMirror annotation) {
    String name = null;
    String description = null;
    List<String> tags = Collections.EMPTY_LIST;

    for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotation.getElementValues().entrySet()) {
        // name
        Name entryName = entry.getKey().getSimpleName();
        AnnotationValue entryValue = entry.getValue();
        if (entryName.contentEquals("name")) {
            name = getAnnotationValue(String.class, classFQN, "name", entryValue);
        } else if (entryName.contentEquals("description")) {
            description = getAnnotationValue(String.class, classFQN, "description", entryValue);
        } else if (entryName.contentEquals("tags")) {
            List<AnnotationValue> tagList = getAnnotationValue(List.class, classFQN, "tags", entryValue) ;
            if (tagList != null) {
                tags = new ArrayList<String>(tagList.size());
                for (AnnotationValue tagValue : tagList) {
                    String tag = getAnnotationValue(String.class, classFQN, "tags", tagValue);
                    if (tag != null) {
                        tags.add(tag);
                    }
                }
            }
        }
    }
    return new PrimitiveData(classFQN, name, description, tags.toArray(new String[tags.size()]));
}
项目:incubator-netbeans    文件:Utilities.java   
/**
 * @return the value of annotation attribute, null if the attribute
 * was not found or when ann was null
 */
public static AnnotationValue getAnnotationAttrValue(AnnotationMirror ann, String attrName){
    if (ann != null){
        for (ExecutableElement attr : ann.getElementValues().keySet()){
            if (attrName.equals(attr.getSimpleName().toString())){
                return ann.getElementValues().get(attr);
            }
        }
    }

    return null;
}
项目:incubator-netbeans    文件:NbBundleProcessor.java   
private void warnUndocumented(int i, Element e, String key) {
    AnnotationMirror mirror = null;
    AnnotationValue value = null;
    if (e != null) {
        for (AnnotationMirror _mirror : e.getAnnotationMirrors()) {
            if (_mirror.getAnnotationType().toString().equals(NbBundle.Messages.class.getCanonicalName())) {
                mirror = _mirror;
                for (Map.Entry<? extends ExecutableElement,? extends AnnotationValue> entry : mirror.getElementValues().entrySet()) {
                    if (entry.getKey().getSimpleName().contentEquals("value")) {
                        // SimpleAnnotationValueVisitor6 unusable here since we need to determine the AnnotationValue in scope when visitString is called:
                        Object v = entry.getValue().getValue();
                        if (v instanceof String) {
                            if (((String) v).startsWith(key + "=")) {
                                value = entry.getValue();
                            }
                        } else {
                            for (AnnotationValue subentry : NbCollections.checkedListByCopy((List<?>) v, AnnotationValue.class, true)) {
                                v = subentry.getValue();
                                if (v instanceof String) {
                                    if (((String) v).startsWith(key + "=")) {
                                        value = subentry;
                                        break;
                                    }
                                }
                            }
                        }
                        break;
                    }
                }
                break;
            }
        }
    }
    processingEnv.getMessager().printMessage(Kind.WARNING, "Undocumented format parameter {" + i + "}", e, mirror, value);
}
项目:Java-9-Programming-By-Example    文件:Aptools.java   
private AnnotationValue getAnnotationValue(String name) {
  Map<? extends ExecutableElement, ? extends AnnotationValue> map = annotationMirror.getElementValues();
  for (ExecutableElement annotationElement : map.keySet()) {
    if (annotationElement.getSimpleName().toString().equals(name)) {
      return map.get(annotationElement);
    }
  }
  return null;
}
项目:arez    文件:ProcessorUtil.java   
@Nonnull
static AnnotationValue getAnnotationValue( @Nonnull final Elements elements,
                                           @Nonnull final Element typeElement,
                                           @Nonnull final String annotationClassName,
                                           @Nonnull final String parameterName )
{
  final AnnotationValue value = findAnnotationValue( elements, typeElement, annotationClassName, parameterName );
  assert null != value;
  return value;
}
项目:java-code-templates    文件:Util.java   
@SuppressWarnings("unchecked")
static ImmutableSet<TypeElement> typeAnnotationTargets(final Descriptor descriptor, final TypeElement element) {
    final AnnotationMirror descriptorMirror = descriptorMirror(descriptor, element);
    final AnnotationValue classes = AnnotationMirrors.getAnnotationValue(descriptorMirror, "copyTypeAnnotationsTo");
    final ImmutableSet.Builder<TypeElement> builder = ImmutableSet.builder();

    for (final AnnotationValue value: (List<? extends AnnotationValue>)classes) {
        final DeclaredType declared = MoreTypes.asDeclared((TypeMirror)value);
        builder.add(MoreElements.asType(declared.asElement()));
    }

    return builder.build();
}
项目:GitHub    文件:CachingElements.java   
@Override
public AnnotationValue getDefaultValue() {
  AnnotationValue dv = defaultValue;
  if (dv == null) {
    dv = delegate.getDefaultValue();
    defaultValue = dv;
  }
  return dv;
}
项目:incubator-netbeans    文件:JavaSourceHelper.java   
public static boolean annotationHasAttributeValue(AnnotationMirror am, String value) {
    if (am != null) {
        for (AnnotationValue av : am.getElementValues().values()) {
            if (value.equals(av.getValue())) {
                return true;
            }
        }
    }
    return false;
}
项目:inspector    文件:Property.java   
private static AnnotationValue getAnnotationValue(AnnotationMirror annotationMirror, String key) {
  Map<? extends ExecutableElement, ? extends AnnotationValue> values =
      annotationMirror.getElementValues();
  for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : values
      .entrySet()) {
    if (entry.getKey()
        .getSimpleName()
        .toString()
        .equals(key)) {
      return entry.getValue();
    }
  }
  return null;
}
项目:GitHub    文件:ModuleMetaData.java   
private AnnotationValue getAnnotationValue(AnnotationMirror annotationMirror) {
    if (annotationMirror == null) {
        return null;
    }
    AnnotationValue annotationValue = null;
    for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotationMirror.getElementValues().entrySet()) {
        if (entry.getKey().getSimpleName().toString().equals("classes")) {
            annotationValue = entry.getValue();
            break;
        }
    }
    return annotationValue;
}