本文整理匯總了Java中javax.lang.model.element.AnnotationValue.getValue方法的典型用法代碼示例。如果您正苦於以下問題:Java AnnotationValue.getValue方法的具體用法?Java AnnotationValue.getValue怎麽用?Java AnnotationValue.getValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.lang.model.element.AnnotationValue
的用法示例。
在下文中一共展示了AnnotationValue.getValue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getProviderInterface
import javax.lang.model.element.AnnotationValue; //導入方法依賴的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();
}
示例2: getClassAttributeFromAnnotationAsTypeMirror
import javax.lang.model.element.AnnotationValue; //導入方法依賴的package包/類
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();
}
}
示例3: convertOutputType
import javax.lang.model.element.AnnotationValue; //導入方法依賴的package包/類
OutputType convertOutputType(AnnotationValue outputTypeValue) {
return (outputTypeValue != null
&& outputTypeValue.getValue() != null
&& Arrays.stream(OutputType.values()).anyMatch(x -> x.name().equals(outputTypeValue.getValue().toString())))
? OutputType.valueOf(outputTypeValue.getValue().toString())
:null;
}
示例4: checkMembers
import javax.lang.model.element.AnnotationValue; //導入方法依賴的package包/類
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;
}
示例5: getAnnotationValueClassName
import javax.lang.model.element.AnnotationValue; //導入方法依賴的package包/類
/**
* Returns fully qualified class name of a class given to an annotation
* as (the only) argument.
*
* @param annValue annotation value
* @return fully qualified name of a class represented by the given
* annotation value, or {@code null} if the annotation value
* does not represent a class
*/
private Name getAnnotationValueClassName(AnnotationValue annValue,
Types types) {
Object value = annValue.getValue();
if (value instanceof TypeMirror) {
TypeMirror typeMirror = (TypeMirror) value;
Element typeElement = types.asElement(typeMirror);
if (typeElement.getKind() == ElementKind.CLASS) {
return ((TypeElement) typeElement).getQualifiedName();
}
}
return null;
}
示例6: getGroupClassType
import javax.lang.model.element.AnnotationValue; //導入方法依賴的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());
// }
}
}
}
示例7: getValue
import javax.lang.model.element.AnnotationValue; //導入方法依賴的package包/類
public Object getValue(AnnotationValue elementValue) {
Object value = elementValue.getValue();
if (value instanceof TypeMirror) {
TypeMirror type = (TypeMirror)value;
if (TypeKind.DECLARED.equals(type.getKind())) {
return ((TypeElement)(((DeclaredType)value).asElement())).getQualifiedName().toString();
}
}
return getDefaultValue();
}
示例8: getClassMetaDataFromModule
import javax.lang.model.element.AnnotationValue; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private Set<String> getClassMetaDataFromModule(Element classElement) {
AnnotationMirror annotationMirror = getAnnotationMirror(classElement);
AnnotationValue annotationValue = getAnnotationValue(annotationMirror);
Set<String> classes = new HashSet<String>();
List<? extends AnnotationValue> moduleClasses = (List<? extends AnnotationValue>) annotationValue.getValue();
for (AnnotationValue classMirror : moduleClasses) {
String fullyQualifiedClassName = classMirror.getValue().toString();
classes.add(fullyQualifiedClassName);
}
return classes;
}
示例9: warnUndocumented
import javax.lang.model.element.AnnotationValue; //導入方法依賴的package包/類
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);
}
示例10: checkSuiteMembersAnnotation
import javax.lang.model.element.AnnotationValue; //導入方法依賴的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;
}
示例11: getAnnoType
import javax.lang.model.element.AnnotationValue; //導入方法依賴的package包/類
/** Get the annoType value from an @Test annotation mirror. */
static String getAnnoType(AnnotationMirror test) {
AnnotationValue v = getValue(test, "annoType");
TypeMirror m = (TypeMirror) v.getValue();
return m.toString();
}
示例12: getExpect
import javax.lang.model.element.AnnotationValue; //導入方法依賴的package包/類
/** Get the expect value from an @Test annotation mirror. */
static String getExpect(AnnotationMirror test) {
AnnotationValue v = getValue(test, "expect");
return (String) v.getValue();
}
示例13: getIntegerValue
import javax.lang.model.element.AnnotationValue; //導入方法依賴的package包/類
/**
* Tries to get the annotationValues value as Integer.
*
* @param annotationValue the value to get the value from.
* @return the annotationValues value casted as Integer, or null if value has not the correct type.
*/
public static Integer getIntegerValue(AnnotationValue annotationValue) {
return !isInteger(annotationValue) ? null : (Integer) annotationValue.getValue();
}
示例14: getFloatValue
import javax.lang.model.element.AnnotationValue; //導入方法依賴的package包/類
/**
* Tries to get the annotationValues value as Float.
*
* @param annotationValue the value to get the value from.
* @return the annotationValues value casted as Long, or null if value has not the correct type.
*/
public static Float getFloatValue(AnnotationValue annotationValue) {
return !isFloat(annotationValue) ? null : (Float) annotationValue.getValue();
}
示例15: getDoubleValue
import javax.lang.model.element.AnnotationValue; //導入方法依賴的package包/類
/**
* Tries to get the annotationValues value as Double.
*
* @param annotationValue the value to get the value from.
* @return the annotationValues value casted as Long, or null if value has not the correct type.
*/
public static Double getDoubleValue(AnnotationValue annotationValue) {
return !isDouble(annotationValue) ? null : (Double) annotationValue.getValue();
}