當前位置: 首頁>>代碼示例>>Java>>正文


Java VariableElement.getAnnotationMirrors方法代碼示例

本文整理匯總了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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:26,代碼來源:ClassMetaData.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:8,代碼來源:ProcessorUtil.java

示例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;
}
 
開發者ID:PacktPublishing,項目名稱:Java-9-Programming-By-Example,代碼行數:15,代碼來源:Aptools.java

示例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();
}
 
開發者ID:foodora,項目名稱:android-auto-mapper,代碼行數:9,代碼來源:AutoMappperProcessor.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:44,代碼來源:PresenterBinderClassGenerator.java

示例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);
}
 
開發者ID:spotify,項目名稱:dataenum,代碼行數:61,代碼來源:ValueParser.java

示例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()));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:77,代碼來源:GraphNodeVerifier.java


注:本文中的javax.lang.model.element.VariableElement.getAnnotationMirrors方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。