本文整理汇总了Java中javax.lang.model.element.VariableElement.getAnnotationMirrors方法的典型用法代码示例。如果您正苦于以下问题:Java VariableElement.getAnnotationMirrors方法的具体用法?Java VariableElement.getAnnotationMirrors怎么用?Java VariableElement.getAnnotationMirrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.element.VariableElement
的用法示例。
在下文中一共展示了VariableElement.getAnnotationMirrors方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isRequiredField
import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
/**
* Checks if the field is annotated as required.
* @param field target field.
* @return {@code true} if the field is annotated as required, {@code false} otherwise.
*/
private boolean isRequiredField(VariableElement field) {
if (hasRequiredAnnotation(field)) {
return true;
}
if (ignoreKotlinNullability) {
return false;
}
// Kotlin uses the `org.jetbrains.annotations.NotNull` annotation to mark non-null fields.
// In order to fully support the Kotlin type system we interpret `@NotNull` as an alias
// for `@Required`
for (AnnotationMirror annotation : field.getAnnotationMirrors()) {
if (annotation.getAnnotationType().toString().equals("org.jetbrains.annotations.NotNull")) {
return true;
}
}
return false;
}
示例2: getAnnotations
import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
private static List<AnnotationSpec> getAnnotations(VariableElement element) {
List<AnnotationSpec> result = new ArrayList<>();
for (AnnotationMirror mirror : element.getAnnotationMirrors()) {
result.add(AnnotationSpec.get(mirror));
}
return result;
}
示例3: getParameterAnnotations
import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
/**
* Get an array of lists containing the annotations of the arguments.
*/
@Transition(from = "MethodTool", end = true)
public List<? extends AnnotationMirror>[] getParameterAnnotations() {
@SuppressWarnings("unchecked")
List<? extends AnnotationMirror>[] annotationMirrorss = new List[getTheNumberOfParameters()];
int i = 0;
for (VariableElement parameterElement : methodElement.getParameters()) {
annotationMirrorss[i] = parameterElement.getAnnotationMirrors();
i++;
}
return annotationMirrorss;
}
示例4: getAnnotations
import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
private ImmutableSet<String> getAnnotations(VariableElement element) {
ImmutableSet.Builder<String> builder = ImmutableSet.builder();
for (AnnotationMirror annotation : element.getAnnotationMirrors()) {
builder.add(annotation.getAnnotationType().asElement().getSimpleName().toString());
}
return builder.build();
}
示例5: collectFields
import javax.lang.model.element.VariableElement; //导入方法依赖的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;
}
示例6: parse
import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
static Value parse(Element element, ProcessingEnvironment processingEnv) {
Messager messager = processingEnv.getMessager();
if (element.getKind() != ElementKind.METHOD) {
messager.printMessage(
Diagnostic.Kind.ERROR,
String.format(
"Value specs must be methods, found %s: %s",
element.getKind().toString().toLowerCase(), element),
element);
return null;
}
ExecutableElement methodElement = (ExecutableElement) element;
if (!isValueSpecMarker(methodElement.getReturnType(), processingEnv)) {
messager.printMessage(
Diagnostic.Kind.ERROR,
String.format(
"Value specs must return dataenum_case, found %s: %s",
methodElement.getReturnType(), element),
element);
return null;
}
if (methodElement.getTypeParameters().size() != 0) {
messager.printMessage(
Diagnostic.Kind.ERROR,
String.format(
"Type parameters must be specified on the top-level interface, found: %s", element),
element);
return null;
}
if (methodElement.isVarArgs()) {
messager.printMessage(
Diagnostic.Kind.ERROR,
String.format("Vararg parameters not permitted: %s", element),
element);
return null;
}
List<Parameter> parameters = new ArrayList<>();
for (VariableElement parameterElement : methodElement.getParameters()) {
String parameterName = parameterElement.getSimpleName().toString();
TypeName parameterType = TypeName.get(parameterElement.asType());
boolean nullable = false;
for (AnnotationMirror annotation : parameterElement.getAnnotationMirrors()) {
if (isNullableAnnotation(annotation)) {
nullable = true;
break;
}
}
parameters.add(new Parameter(parameterName, parameterType, nullable));
}
String valueSimpleName = methodElement.getSimpleName().toString();
return new Value(valueSimpleName, parameters);
}
示例7: scanFields
import javax.lang.model.element.VariableElement; //导入方法依赖的package包/类
private void scanFields(TypeElement node) {
TypeElement currentClazz = node;
do {
for (VariableElement field : ElementFilter.fieldsIn(currentClazz.getEnclosedElements())) {
Set<Modifier> modifiers = field.getModifiers();
if (modifiers.contains(STATIC) || modifiers.contains(TRANSIENT)) {
continue;
}
List<? extends AnnotationMirror> annotations = field.getAnnotationMirrors();
boolean isNonOptionalInput = findAnnotationMirror(annotations, Input) != null;
boolean isOptionalInput = findAnnotationMirror(annotations, OptionalInput) != null;
boolean isSuccessor = findAnnotationMirror(annotations, Successor) != null;
if (isNonOptionalInput || isOptionalInput) {
if (findAnnotationMirror(annotations, Successor) != null) {
throw new ElementException(field, "Field cannot be both input and successor");
} else if (isNonOptionalInput && isOptionalInput) {
throw new ElementException(field, "Inputs must be either optional or non-optional");
} else if (isAssignableWithErasure(field, NodeInputList)) {
if (modifiers.contains(FINAL)) {
throw new ElementException(field, "Input list field must not be final");
}
if (modifiers.contains(PUBLIC)) {
throw new ElementException(field, "Input list field must not be public");
}
} else {
if (!isAssignableWithErasure(field, Node) && field.getKind() == ElementKind.INTERFACE) {
throw new ElementException(field, "Input field type must be an interface or assignable to Node");
}
if (modifiers.contains(FINAL)) {
throw new ElementException(field, "Input field must not be final");
}
if (modifiers.contains(PUBLIC)) {
throw new ElementException(field, "Input field must not be public");
}
}
} else if (isSuccessor) {
if (isAssignableWithErasure(field, NodeSuccessorList)) {
if (modifiers.contains(FINAL)) {
throw new ElementException(field, "Successor list field must not be final");
}
if (modifiers.contains(PUBLIC)) {
throw new ElementException(field, "Successor list field must not be public");
}
} else {
if (!isAssignableWithErasure(field, Node)) {
throw new ElementException(field, "Successor field must be a Node type");
}
if (modifiers.contains(FINAL)) {
throw new ElementException(field, "Successor field must not be final");
}
if (modifiers.contains(PUBLIC)) {
throw new ElementException(field, "Successor field must not be public");
}
}
} else {
if (isAssignableWithErasure(field, Node) && !field.getSimpleName().contentEquals("Null")) {
throw new ElementException(field, "Node field must be annotated with @" + Input.getSimpleName() + ", @" + OptionalInput.getSimpleName() + " or @" + Successor.getSimpleName());
}
if (isAssignableWithErasure(field, NodeInputList)) {
throw new ElementException(field, "NodeInputList field must be annotated with @" + Input.getSimpleName() + " or @" + OptionalInput.getSimpleName());
}
if (isAssignableWithErasure(field, NodeSuccessorList)) {
throw new ElementException(field, "NodeSuccessorList field must be annotated with @" + Successor.getSimpleName());
}
if (modifiers.contains(PUBLIC) && !modifiers.contains(FINAL)) {
throw new ElementException(field, "Data field must be final if public");
}
}
}
currentClazz = getSuperType(currentClazz);
} while (!isObject(getSuperType(currentClazz).asType()));
}