javax.lang.model.element.AnnotationMirror#getElementValues ( )源码实例Demo

下面列出了javax.lang.model.element.AnnotationMirror#getElementValues ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: DataLoader   文件: DataLoaderProcessor.java
private <T> T getAnnotation(Element element, Class<? extends Annotation> type, String name) {
    String canonicalName = type.getCanonicalName();
    List<? extends AnnotationMirror> annotationMirrors = elements.getAllAnnotationMirrors(element);
    if (annotationMirrors != null && annotationMirrors.size() > 0) {
        for (AnnotationMirror annotationMirror : annotationMirrors) {
            if (canonicalName.equals(annotationMirror.getAnnotationType().toString())) {
                if (annotationMirror.getElementValues() != null) {
                    for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry :
                            annotationMirror.getElementValues().entrySet()) {
                        ExecutableElement annotationName = entry.getKey();
                        AnnotationValue annotationValue = entry.getValue();
                        if (annotationName.getSimpleName().toString().equals(name)) {
                            return (T) annotationValue.getValue();
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
源代码2 项目: netbeans   文件: DeclaredIBindingsAnalyzer.java
private boolean isSame( AnnotationMirror first,
        AnnotationMirror second , CompilationController controller )
{
    Element firstElement = first.getAnnotationType().asElement();
    Element secondElement = second.getAnnotationType().asElement();
    if ( !firstElement.equals(secondElement)){
        return false;
    }
    Map<? extends ExecutableElement, ? extends AnnotationValue> firstValues = first.getElementValues();
    Map<? extends ExecutableElement, ? extends AnnotationValue> secondValues = second.getElementValues();
    if ( firstValues.size() != secondValues.size() ){
        return false;
    }
    for (Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : 
        firstValues.entrySet()) 
    {
        AnnotationValue secondValue = secondValues.get(entry.getKey());
        AnnotationValue firstValue = entry.getValue();
        if ( !isSame( firstValue, secondValue, controller )){
            return false;
        }
    }
    return true;
}
 
源代码3 项目: SmartEventBus   文件: InvokingMessageProcessor.java
private String getEventType(Element element1) {
    List<? extends AnnotationMirror> annotationMirrors = elements.getAllAnnotationMirrors(element1);
    if (annotationMirrors != null && annotationMirrors.size() > 0) {
        for (AnnotationMirror annotationMirror : annotationMirrors) {
            if (ANNOTATION_NAME.equals(annotationMirror.getAnnotationType().toString())) {
                System.out.println(TAG + "annotationMirror: " + annotationMirror.getAnnotationType().toString());
                if (annotationMirror.getElementValues() != null) {
                    for (AnnotationValue annotationValue : annotationMirror.getElementValues().values()) {
                        return annotationValue.getValue().toString();
                    }
                }
            }
        }
    }
    return null;
}
 
源代码4 项目: netbeans   文件: JaxWsAddOperation.java
private boolean isJaxWsImplementationClass(TypeElement classEl, CompilationController controller) {
    TypeElement wsElement = controller.getElements().getTypeElement("javax.jws.WebService"); //NOI18N
    if (wsElement != null) {
        List<? extends AnnotationMirror> annotations = classEl.getAnnotationMirrors();
        for (AnnotationMirror anMirror : annotations) {
            if (controller.getTypes().isSameType(wsElement.asType(), anMirror.getAnnotationType())) {
                Map<? extends ExecutableElement, ? extends AnnotationValue> expressions = anMirror.getElementValues();
                for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : expressions.entrySet()) {
                    if (entry.getKey().getSimpleName().contentEquals("wsdlLocation")) { //NOI18N
                        return false;
                    }
                }
                return true;
            }
        }
    }
    return false;
}
 
源代码5 项目: 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;
}
 
源代码6 项目: netbeans   文件: AbstractScopedAnalyzer.java
protected boolean isPassivatingScope( TypeElement scope, WebBeansModel model ) {
    AnnotationMirror normalScope = AnnotationUtil.getAnnotationMirror(
            scope, model.getCompilationController(), AnnotationUtil.NORMAL_SCOPE_FQN);
    if ( normalScope==null){
        return false;
    }
    Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = 
        normalScope.getElementValues();
    boolean isPassivating = false;
    for (Entry<? extends ExecutableElement, ? extends AnnotationValue> entry: 
        elementValues.entrySet()) 
    {
        ExecutableElement key = entry.getKey();
        if ( key.getSimpleName().contentEquals(AnnotationUtil.PASSIVATING)){
            isPassivating = Boolean.TRUE.toString().equals(entry.getValue().toString());
        }
    }
    return isPassivating;
}
 
源代码7 项目: netbeans   文件: JaxWsNode.java
private String getServiceName(CompilationController controller, TypeElement classElement) {
     // check service name
    AnnotationMirror anMirror = _RetoucheUtil.getAnnotation(controller,
            classElement, "javax.jws.WebService");          // NOI18N
    if ( anMirror == null ){
        return null;
    }
    java.util.Map<? extends ExecutableElement, ? extends AnnotationValue> expressions = 
            anMirror.getElementValues();
    for (java.util.Map.Entry<? extends ExecutableElement, 
            ? extends AnnotationValue> entry : expressions.entrySet())
    {
        if (entry.getKey().getSimpleName().contentEquals("serviceName")) { // NOI18N
            return (String) expressions.get(entry.getKey()).getValue();
        }
    }
    return null;
}
 
源代码8 项目: picocli   文件: ParameterConsumerMetaData.java
/**
 * Returns the type converters from the annotations present on the specified element.
 * @param element the method or field annotated with {@code @Option} or {@code @Parameters}
 * @return the type converters or an empty array if not found
 */
@SuppressWarnings("unchecked")
public static ParameterConsumerMetaData extract(Element element) {
    List<? extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors();
    for (AnnotationMirror mirror : annotationMirrors) {
        DeclaredType annotationType = mirror.getAnnotationType();
        if (TypeUtil.isOption(annotationType) || TypeUtil.isParameter(annotationType)) {
            Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = mirror.getElementValues();
            for (ExecutableElement attribute : elementValues.keySet()) {
                if ("parameterConsumer".equals(attribute.getSimpleName().toString())) {
                    AnnotationValue parameterConsumer = elementValues.get(attribute);
                    TypeMirror typeMirror = (TypeMirror) parameterConsumer.getValue();
                    if (typeMirror != null) {
                        return new ParameterConsumerMetaData(typeMirror);
                    }
                }
            }
        }
    }
    return null;
}
 
源代码9 项目: picocli   文件: CompletionCandidatesMetaData.java
/**
 * Returns the completion candidates from the annotations present on the specified element.
 * @param element the method or field annotated with {@code @Option} or {@code @Parameters}
 * @return the completion candidates or {@code null} if not found
 */
public static Iterable<String> extract(Element element) {
    List<? extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors();
    for (AnnotationMirror mirror : annotationMirrors) {
        DeclaredType annotationType = mirror.getAnnotationType();
        if (TypeUtil.isOption(annotationType) || TypeUtil.isParameter(annotationType)) {
            Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = mirror.getElementValues();
            for (ExecutableElement attribute : elementValues.keySet()) {
                if ("completionCandidates".equals(attribute.getSimpleName().toString())) {
                    AnnotationValue typeMirror = elementValues.get(attribute);
                    return new CompletionCandidatesMetaData((TypeMirror) typeMirror);
                }
            }
        }
    }
    return null;
}
 
源代码10 项目: netbeans   文件: StereotypeAnalyzer.java
private void checkName( TypeElement element, WebBeansModel model,
        Result result  )
{
    AnnotationMirror named = AnnotationUtil.getAnnotationMirror(element, 
            AnnotationUtil.NAMED , model.getCompilationController());
    if ( named == null ){
        return;
    }
    Map<? extends ExecutableElement, ? extends AnnotationValue> members = 
        named.getElementValues();
    for (Entry<? extends ExecutableElement, ? extends AnnotationValue> entry: 
        members.entrySet()) 
    {
        ExecutableElement member = entry.getKey();
        if ( member.getSimpleName().contentEquals(AnnotationUtil.VALUE)){ 
            result.addError( element, model,  
                NbBundle.getMessage(StereotypeAnalyzer.class, 
                        "ERR_NonEmptyNamedStereotype"));            // NOI18N
        }
    }
}
 
源代码11 项目: openjdk-jdk9   文件: 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;
}
 
源代码12 项目: 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;
}
 
源代码13 项目: 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
    }
}
 
源代码14 项目: ApiManager   文件: ApiImplProcessor.java
private ApiContract<ClassName> getApiClassNameContract(TypeElement apiImplElement) {
    String apiClassSymbol = null;
    List<? extends AnnotationMirror> annotationMirrors = apiImplElement.getAnnotationMirrors();
    for (AnnotationMirror annotationMirror : annotationMirrors) {
        Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = annotationMirror.getElementValues();
        for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : elementValues.entrySet()) {
            apiClassSymbol = entry.getValue().accept(annotationValueVisitor, null);
        }
    }
    ClassName apiName = ClassName.get(elements.getTypeElement(apiClassSymbol));
    ClassName apiImplName = ClassName.get(apiImplElement);
    return new ApiContract<>(apiName, apiImplName);
}
 
源代码15 项目: netbeans   文件: AddWsOperationHelper.java
private String getEndpointInterface(TypeElement classEl, 
        CompilationController controller)  
{
    TypeElement wsElement = controller.getElements().
        getTypeElement("javax.jws.WebService");                 //NOI18N
    if ( wsElement == null ){
        isIncomplete = true;
        return null;
    }
    List<? extends AnnotationMirror> annotations = classEl.getAnnotationMirrors();
    for (AnnotationMirror anMirror : annotations) {
        if (controller.getTypes().isSameType(wsElement.asType(),
                anMirror.getAnnotationType()))
        {
            Map<? extends ExecutableElement, ? extends AnnotationValue> expressions = 
                anMirror.getElementValues();
            for (Map.Entry<? extends ExecutableElement, 
                    ? extends AnnotationValue> entry : expressions.entrySet())
            {
                if (entry.getKey().getSimpleName()
                        .contentEquals("endpointInterface")) // NOI18N
                {
                    String value = (String) expressions.get(entry.getKey())
                            .getValue();
                    if (value != null) {
                        TypeElement seiEl = controller.getElements()
                                .getTypeElement(value);
                        if (seiEl != null) {
                            return seiEl.getQualifiedName().toString();
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
源代码16 项目: netbeans   文件: JUnit4TestGenerator.java
/**
 * Checks that the given annotation is of type
 * <code>{@value #ANN_SUITE}.{@value #ANN_SUITE_MEMBERS}</code>
 * and contains the given list of classes as (the only) argument,
 * in the same order.
 * 
 * @param  annMirror  annotation to be checked
 * @param  suiteMembers  list of fully qualified class names denoting
 *                       content of the test suite
 * @return  {@code true} if the annotation meets the described criteria,
 *          {@code false} otherwise
 */
private boolean checkSuiteMembersAnnotation(AnnotationMirror annMirror,
                                            List<String> suiteMembers,
                                            WorkingCopy workingCopy) {
    Map<? extends ExecutableElement,? extends AnnotationValue> annParams
            = annMirror.getElementValues();
    
    if (annParams.size() != 1) {
        return false;
    }
    
    AnnotationValue annValue = annParams.values().iterator().next();
    Object value = annValue.getValue();
    if (value instanceof java.util.List) {
        List<? extends AnnotationValue> items
                = (List<? extends AnnotationValue>) value;
        
        if (items.size() != suiteMembers.size()) {
            return false;
        }
        
        Types types = workingCopy.getTypes();
        Iterator<String> suiteMembersIt = suiteMembers.iterator();
        for (AnnotationValue item : items) {
            Name suiteMemberName = getAnnotationValueClassName(item, types);
            if (suiteMemberName == null) {
                return false;
            }
            if (!suiteMemberName.contentEquals(suiteMembersIt.next())) {
                return false;
            }
        }
        return true;
    }
    
    return false;
}
 
源代码17 项目: spring-init   文件: ElementUtils.java
public List<TypeElement> getTypesFromAnnotation(AnnotationMirror annotationMirror,
		String fieldname) {
	List<TypeElement> collected = new ArrayList<>();
	if (annotationMirror != null) {
		Map<? extends ExecutableElement, ? extends AnnotationValue> values = annotationMirror
				.getElementValues();
		for (ExecutableElement element : values.keySet()) {
			if (element.getSimpleName().toString().equals(fieldname)) {
				values.get(element).accept(typeCollector, collected);
			}
		}
	}
	return collected;
}
 
源代码18 项目: spring-init   文件: ElementUtils.java
public List<String> getStringsFromAnnotation(AnnotationMirror annotationMirror,
		String fieldname) {
	List<String> collected = new ArrayList<>();
	if (annotationMirror != null) {
		Map<? extends ExecutableElement, ? extends AnnotationValue> values = annotationMirror
				.getElementValues();
		for (ExecutableElement element : values.keySet()) {
			if (element.getSimpleName().toString().equals(fieldname)) {
				values.get(element).accept(stringCollector, collected);
			}
		}
	}
	return collected;
}
 
源代码19 项目: netbeans   文件: MethodVisitor.java
/**
 *  Determines if the WSDL operation is the corresponding Java method
 */
private boolean isMethodFor(ExecutableElement method, String operationName){
    if(method.getSimpleName().toString().equals(operationName)){
        return true;
    }
    
    //if method name is not the same as the operation name, look at WebMethod annotation
    List<? extends AnnotationMirror> methodAnnotations = 
            method.getAnnotationMirrors();
    for (AnnotationMirror anMirror : methodAnnotations) {
        if (JaxWsUtils.hasFqn(anMirror, "javax.jws.WebMethod")) {   // NOI18N
            Map<? extends ExecutableElement, 
                    ? extends AnnotationValue> expressions = 
                            anMirror.getElementValues();
            for(Entry<? extends ExecutableElement, 
                    ? extends AnnotationValue> entry: expressions.entrySet()) 
            {
                if (entry.getKey().getSimpleName().
                        contentEquals("operationName"))  //NOI18N
                {
                    String name = (String)expressions.get(entry.getKey()).
                        getValue();
                    if (operationName.equals(name)){
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
 
源代码20 项目: netbeans   文件: BindingsPanel.java
private void appendBindingParamters( AnnotationMirror mirror,
        StringBuilder builder )
{
    Map<? extends ExecutableElement, ? extends AnnotationValue> 
        elementValues = mirror.getElementValues();
    StringBuilder params = new StringBuilder();
    for ( Entry<? extends ExecutableElement, ? extends AnnotationValue> 
        entry :  elementValues.entrySet()) 
    {
        ExecutableElement key = entry.getKey();
        AnnotationValue value = entry.getValue();
        List<? extends AnnotationMirror> annotationMirrors = 
            key.getAnnotationMirrors();
        boolean nonBinding = false;
        for (AnnotationMirror annotationMirror : annotationMirrors) {
            DeclaredType annotationType = annotationMirror.getAnnotationType();
            Element element = annotationType.asElement();
            if ( ( element instanceof TypeElement ) && 
                    ((TypeElement)element).getQualifiedName().
                    contentEquals(NON_BINDING_MEMBER_ANNOTATION))
            {
                nonBinding = true;
                break;
            }
        }
        if ( !nonBinding ){
            params.append( key.getSimpleName().toString() );
            params.append( "=" );               // NOI18N
            if ( value.getValue() instanceof String ){
                params.append('"');
                params.append( value.getValue().toString());
                params.append('"');
            }
            else {
                params.append( value.getValue().toString());
            }
            params.append(", ");                // NOI18N
        }
    }
    if ( params.length() >0 ){
        builder.append( "(" );                   // NOI18N
        builder.append( params.substring(0 , params.length() -2 ));
        builder.append( ")" );                   // NOI18N
    }
}