当前位置: 首页>>代码示例>>Java>>正文


Java AnnotationMirror.getElementValues方法代码示例

本文整理汇总了Java中javax.lang.model.element.AnnotationMirror.getElementValues方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotationMirror.getElementValues方法的具体用法?Java AnnotationMirror.getElementValues怎么用?Java AnnotationMirror.getElementValues使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.lang.model.element.AnnotationMirror的用法示例。


在下文中一共展示了AnnotationMirror.getElementValues方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visitAnnotation

import javax.lang.model.element.AnnotationMirror; //导入方法依赖的package包/类
@Override
public Void visitAnnotation(AnnotationMirror a, Void p) {
  builder.append('@').append(a.getAnnotationType());

  Map<? extends ExecutableElement, ? extends AnnotationValue> values = a.getElementValues();
  if (!values.isEmpty()) {
    builder.append('(');
    boolean notFirst = false;
    for (Entry<? extends ExecutableElement, ? extends AnnotationValue> e : values.entrySet()) {
      if (notFirst) {
        builder.append(", ");
      }
      notFirst = true;
      Name name = e.getKey().getSimpleName();
      boolean onlyValue = values.size() == 1 && name.contentEquals(ATTRIBUTE_VALUE);
      if (!onlyValue) {
        builder.append(name).append(" = ");
      }
      printValue(e.getValue());
    }
    builder.append(')');
  }
  return null;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:AnnotationMirrors.java

示例2: appendAnnotation

import javax.lang.model.element.AnnotationMirror; //导入方法依赖的package包/类
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
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:ElementJavadoc.java

示例3: getProviderInterface

import javax.lang.model.element.AnnotationMirror; //导入方法依赖的package包/类
private DeclaredType getProviderInterface(AnnotationMirror providerAnnotation) {

        // The very simplest of way of doing this, is also unfortunately unworkable.
        // We'd like to do:
        //    ServiceProvider provider = e.getAnnotation(ServiceProvider.class);
        //    Class<?> providerInterface = provider.value();
        //
        // but unfortunately we can't load the arbitrary class at annotation
        // processing time. So, instead, we have to use the mirror to get at the
        // value (much more painful).

        Map<? extends ExecutableElement, ? extends AnnotationValue> valueIndex =
                providerAnnotation.getElementValues();
        AnnotationValue value = valueIndex.values().iterator().next();
        return (DeclaredType) value.getValue();
    }
 
开发者ID:zillachan,项目名称:AndZilla,代码行数:17,代码来源:LifecycleProcessor.java

示例4: refresh

import javax.lang.model.element.AnnotationMirror; //导入方法依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:MappedSuperclassImpl.java

示例5: getDefaultProperty

import javax.lang.model.element.AnnotationMirror; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:FxClassUtils.java

示例6: getClassType

import javax.lang.model.element.AnnotationMirror; //导入方法依赖的package包/类
/*************当注解的参数为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());
//				}
			}

		}
	}
 
开发者ID:tik5213,项目名称:DUnit,代码行数:24,代码来源:DUnitModelUtil.java

示例7: processAnnotated

import javax.lang.model.element.AnnotationMirror; //导入方法依赖的package包/类
@Override public void processAnnotated(Element element, Metaqualifier metaqualifier) {
    if (!metaqualifier.value(autoMethods).isPresent()) {
        metaqualifier.put(autoMethods).value(new ArrayList<>());
    }
    if (!metaqualifier.value(autoAnnotations).isPresent()) {
        metaqualifier.put(autoAnnotations).value(new HashSet<>());
    }
    for (AnnotationMirror aMirror : getAnnotatedAnnotations(element, Qualify.Auto.class)) {
        String packageName = elements().getPackageOf(aMirror.getAnnotationType().asElement()).toString();
        String aUCName = aMirror.getAnnotationType().asElement().getSimpleName().toString();
        String aLCName = UPPER_CAMEL.converterTo(LOWER_CAMEL).convert(aUCName);
        Map<? extends ExecutableElement, ? extends AnnotationValue> values = aMirror.getElementValues();
        for (ExecutableElement e : values.keySet()) {
            metaqualifier.value(autoMethods).ifPresent(am -> {
                String pLCName = e.getSimpleName().toString();
                String pUCName = LOWER_CAMEL.converterTo(UPPER_CAMEL).convert(pLCName);
                TypeMirror pRetType = e.getReturnType();
                if (pRetType.getKind().isPrimitive()) {
                    pRetType = types().boxedClass((PrimitiveType) pRetType).asType();
                }
                boolean isLink = e.getAnnotation(Link.class) != null && isTypeOf(Class.class, pRetType);

                String key = aLCName + "." + pLCName;

                if (!isLink) {
                    metaqualifier.literal(key, annotationFieldAsCodeBlock(getProcessingEnv(), e, values.get(e)));
                } else {
                    String valType = getFlatName((TypeElement) types().asElement((DeclaredType) values.get(e).getValue()));
                    metaqualifier.literal(key, "$T.self", ClassName.bestGuess(getQualifierName(valType)));
                }
            });
            metaqualifier.value(autoAnnotations).ifPresent(aq ->
                    aq.add(ClassName.bestGuess(packageName + "." + aUCName + "Qualifier")));
        }
    }
}
 
开发者ID:intendia-oss,项目名称:qualifier,代码行数:37,代码来源:AutoQualifierProcessorProvider.java

示例8: getValue

import javax.lang.model.element.AnnotationMirror; //导入方法依赖的package包/类
/**
 * Get a specific value from an annotation mirror.
 */
static AnnotationValue getValue(AnnotationMirror anno, String name) {
    Map<? extends ExecutableElement, ? extends AnnotationValue> map = anno.getElementValues();
    for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> e: map.entrySet()) {
        if (e.getKey().getSimpleName().contentEquals(name)) {
            return e.getValue();
        }
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:BasicAnnoTests.java

示例9: findAnnotationValueAsString

import javax.lang.model.element.AnnotationMirror; //导入方法依赖的package包/类
public static String findAnnotationValueAsString(AnnotationMirror annotation, String annotationKey) {
    String value = null;
    Map<? extends ExecutableElement,? extends AnnotationValue> annotationMap = annotation.getElementValues();
    for (ExecutableElement key : annotationMap.keySet()) {
        if (annotationKey.equals(key.getSimpleName().toString())) {
            AnnotationValue annotationValue = annotationMap.get(key);
            value = annotationValue.getValue().toString();
            break;
        }
    }
    return value;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:JpaControllerUtil.java

示例10: findNestedAnnotationsInternal

import javax.lang.model.element.AnnotationMirror; //导入方法依赖的package包/类
private static void findNestedAnnotationsInternal(Object object, String annotationFqn, List<AnnotationMirror> result) {
    Collection<? extends AnnotationValue> annotationValueCollection = null;
    if (object instanceof AnnotationMirror) {
        AnnotationMirror annotationMirror = (AnnotationMirror)object;
        String annotationQualifiedName = getAnnotationQualifiedName(annotationMirror);
        if (annotationQualifiedName.equals(annotationFqn)) {
            result.add(annotationMirror);
        }
        else {
            //prepare to recurse
            Map<? extends ExecutableElement,? extends AnnotationValue> annotationMap = annotationMirror.getElementValues();
            annotationValueCollection = annotationMap.values();
        }
    }
    else if (object instanceof List) {
        //prepare to recurse
        annotationValueCollection = (Collection<? extends AnnotationValue>)object;
    }

    //recurse
    if (annotationValueCollection != null) {
        for (AnnotationValue annotationValue : annotationValueCollection) {
            Object value = annotationValue.getValue();
            findNestedAnnotationsInternal(value, annotationFqn, result);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:JpaControllerUtil.java

示例11: checkSuiteMembersAnnotation

import javax.lang.model.element.AnnotationMirror; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:49,代码来源:TestGenerator.java

示例12: getAnnotationValue

import javax.lang.model.element.AnnotationMirror; //导入方法依赖的package包/类
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;
}
 
开发者ID:hzsweers,项目名称:inspector,代码行数:15,代码来源:Property.java

示例13: getGroupClassType

import javax.lang.model.element.AnnotationMirror; //导入方法依赖的package包/类
public void getGroupClassType(TypeElement type, DUnitGroup dUnitGroup) {
		if (dUnitGroup != null) {
			mErrorReporter.reportWaring("asType:" + type.asType() + "     |getNestingKind:" + type.getNestingKind() + "     |getAnnotation:" + type.getAnnotation(DUnitGroup.class) + "    |getAnnotationMirrors:" + type.getAnnotationMirrors());
			mErrorReporter.reportWaring("------------>" + getRealClassName(type));
			List<? extends AnnotationMirror> mirrors = type.getAnnotationMirrors();
			if (mirrors.isEmpty()){
				return;
			}
			AnnotationMirror mirror = mirrors.get(0);
			mErrorReporter.reportWaring("----->mirror:" + mirror);
			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());
//				}
			}

		}
	}
 
开发者ID:tik5213,项目名称:DUnit,代码行数:28,代码来源:DUnitModelUtil.java

示例14: getValueIgnoringDefaults

import javax.lang.model.element.AnnotationMirror; //导入方法依赖的package包/类
public AnnotationValue getValueIgnoringDefaults(final AnnotationMirror mirror, final String valueKey) {
	checkNotNull(mirror, "Argument \'mirror\' cannot be null.");
	checkNotNull(valueKey, "Argument \'valueKey\' cannot be null.");

	final Map<? extends ExecutableElement, ? extends AnnotationValue> values = mirror.getElementValues();

	for (final ExecutableElement mapKey : values.keySet()) {
		if (mapKey.getSimpleName().toString().equals(valueKey)) {
			return values.get(mapKey);
		}
	}

	return null;
}
 
开发者ID:MatthewTamlin,项目名称:Spyglass,代码行数:15,代码来源:AnnotationMirrorHelper.java

示例15: collectFields

import javax.lang.model.element.AnnotationMirror; //导入方法依赖的package包/类
private List<Field> collectFields(TypeElement presentersContainer) {
	List<Field> fields = new ArrayList<>();

	outer:
	for (Element element : presentersContainer.getEnclosedElements()) {
		if (!(element instanceof VariableElement)) {
			continue;
		}

		final VariableElement presenterFieldElement = (VariableElement) element;

		for (AnnotationMirror annotationMirror : presenterFieldElement.getAnnotationMirrors()) {
			if (annotationMirror.getAnnotationType().asElement().toString().equals(PRESENTER_FIELD_ANNOTATION)) {
				String type = null;
				String tag = null;
				String presenterId = null;

				final String name = element.toString();
				TypeMirror clazz = ((DeclaredType) element.asType()).asElement().asType();

				final Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = annotationMirror.getElementValues();

				final Set<? extends ExecutableElement> keySet = elementValues.keySet();

				for (ExecutableElement executableElement : keySet) {
					String key = executableElement.getSimpleName().toString();

					if ("type".equals(key)) {
						type = elementValues.get(executableElement).getValue().toString();
					} else if ("tag".equals(key)) {
						tag = elementValues.get(executableElement).toString();
					} else if ("presenterId".equals(key)) {
						presenterId = elementValues.get(executableElement).toString();
					}
				}
				Field field = new Field(clazz, name, type, tag, presenterId);
				fields.add(field);
				continue outer;
			}
		}
	}
	return fields;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:44,代码来源:PresenterBinderClassGenerator.java


注:本文中的javax.lang.model.element.AnnotationMirror.getElementValues方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。