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


Java ExecutableElement.getAnnotationMirrors方法代码示例

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


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

示例1: generateRequestManagerRequestBuilderMethodOverride

import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
/**
 * Generates overrides of existing RequestManager methods so that they return our generated
 * RequestBuilder subtype.
 */
private MethodSpec generateRequestManagerRequestBuilderMethodOverride(
    ExecutableElement methodToOverride) {
   // We've already verified that this method returns a RequestBuilder and RequestBuilders have
  // exactly one type argument, so this is safe unless those assumptions change.
  TypeMirror typeArgument =
      ((DeclaredType) methodToOverride.getReturnType()).getTypeArguments().get(0);

  ParameterizedTypeName generatedRequestBuilderOfType =
      ParameterizedTypeName.get(generatedRequestBuilderClassName, ClassName.get(typeArgument));

  MethodSpec.Builder builder = ProcessorUtil.overriding(methodToOverride)
      .returns(generatedRequestBuilderOfType)
      .addCode(
          ProcessorUtil.generateCastingSuperCall(
              generatedRequestBuilderOfType, methodToOverride));

  for (AnnotationMirror mirror : methodToOverride.getAnnotationMirrors()) {
    builder.addAnnotation(AnnotationSpec.get(mirror));
  }
  return builder.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:RequestManagerGenerator.java

示例2: isPolymorphicSignature

import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private static boolean isPolymorphicSignature(CompilationInfo info, TreePath path) {
    TypeElement polymorphicEl=  info.getElements().getTypeElement("java.lang.invoke.MethodHandle.PolymorphicSignature"); // NOI18N
    if (polymorphicEl == null) {
        // unsuitable platform
        return false;
    }
    TypeMirror polyType = polymorphicEl.asType();
    Element target = info.getTrees().getElement(path);
    if (target == null || target.getKind() != ElementKind.METHOD) {
        return false;
    }
    if (target.getEnclosingElement() == null || !target.getEnclosingElement().getKind().isClass()) {
        return false;
    }
    ExecutableElement ee = (ExecutableElement)target;
    TypeElement parent = (TypeElement)target.getEnclosingElement();
    if (!parent.getQualifiedName().toString().startsWith("java.lang.invoke.")) { // NOI18N
        return false;
    }
    for (AnnotationMirror am : ee.getAnnotationMirrors()) {
        if (info.getTypes().isSameType(polyType, am.getAnnotationType())) {
            return true;
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:TooStrongCast.java

示例3: getXmlRepresentationClass

import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
public static TypeElement getXmlRepresentationClass(TypeElement typeElement, String defaultSuffix) {

        List<ExecutableElement> methods = ElementFilter.methodsIn(typeElement.getEnclosedElements());
        for (ExecutableElement method : methods) {
            List<? extends AnnotationMirror> anmirs = method.getAnnotationMirrors();

            AnnotationMirror mirrorHttpMethod = findAnnotation(anmirs, Constants.GET);
            if (mirrorHttpMethod != null) {
                TypeMirror tm = method.getReturnType();
                if (tm != null && tm.getKind() == TypeKind.DECLARED) {
                    TypeElement returnType = (TypeElement) ((DeclaredType) tm).asElement();
                    if (returnType.getSimpleName().toString().endsWith(defaultSuffix)) {
                        return returnType;
                    }
                }
            }
        }
        return null;
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:JavaSourceHelper.java

示例4: generateRequestOptionOverride

import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private MethodSpec generateRequestOptionOverride(ExecutableElement methodToOverride) {
  MethodSpec.Builder result = ProcessorUtil.overriding(methodToOverride)
      .returns(glideOptionsName)
      .addModifiers(Modifier.FINAL)
      .addCode(CodeBlock.builder()
          .add("return ($T) super.$N(", glideOptionsName, methodToOverride.getSimpleName())
          .add(FluentIterable.from(methodToOverride.getParameters())
              .transform(new Function<VariableElement, String>() {
                @Override
                public String apply(VariableElement input) {
                  return input.getSimpleName().toString();
                }
              })
              .join(Joiner.on(", ")))
          .add(");\n")
          .build());

  if (methodToOverride.getSimpleName().toString().equals("transforms")) {
    result
        .addAnnotation(SafeVarargs.class)
        .addAnnotation(
            AnnotationSpec.builder(SuppressWarnings.class)
                .addMember("value", "$S", "varargs")
                .build());
  }

  for (AnnotationMirror mirror : methodToOverride.getAnnotationMirrors()) {
    result.addAnnotation(AnnotationSpec.get(mirror));
  }

  return result.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:33,代码来源:RequestOptionsGenerator.java

示例5: buildAnnotations

import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private ImmutableSet<String> buildAnnotations(ExecutableElement element) {
  ImmutableSet.Builder<String> builder = ImmutableSet.builder();

  List<? extends AnnotationMirror> annotations = element.getAnnotationMirrors();
  for (AnnotationMirror annotation : annotations) {
    builder.add(annotation.getAnnotationType().asElement().getSimpleName().toString());
  }

  return builder.build();
}
 
开发者ID:setheclark,项目名称:auto-value-json,代码行数:11,代码来源:JsonProperty.java

示例6: getAnnotations

import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private static Set<String> getAnnotations(ExecutableElement element) {
    Set<String> set = new LinkedHashSet<>();
    List<? extends AnnotationMirror> annotations = element.getAnnotationMirrors();
    for (AnnotationMirror annotation : annotations) {
        set.add(annotation.getAnnotationType().asElement().getSimpleName().toString());
    }

    return Collections.unmodifiableSet(set);
}
 
开发者ID:ccheptea,项目名称:auto-value-variant,代码行数:10,代码来源:AutoValueVariantExtension.java

示例7: getAlias

import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
/**
 * On an executable element (that is a value holder on annotation) extract any
 * direct uses of @AlaisFor
 * 
 * @param annotationParameter the annotation's parameter to inspect for uses of @AliasFor
 * @return an AliasData if the the annotation is found, null otherwise.
 */
private static AliasData getAlias(ExecutableElement annotationParameter) {
  AliasData output = null;
  for (AnnotationMirror am : annotationParameter.getAnnotationMirrors()) {
    if (ALIAS_TYPE.equals(am.getAnnotationType().asElement().toString())) {
      output = new AliasData();
      for (Entry<? extends ExecutableElement, ? extends AnnotationValue> ev : am.getElementValues().entrySet()) {
        String fieldName = ev.getKey().getSimpleName().toString();
        if (ALIAS_TARGET_TYPE.equals(fieldName)) {
          if (ev.getValue() != null && ev.getValue().getValue() != null) {
            output.targetAnnotation = ev.getValue().getValue().toString();
          } else {
            return null;
          }
        }
        if (ALIAS_TARGET_FIELD.equals(fieldName) 
            && ev.getValue() != null && ev.getValue().getValue() != null) {
          output.targetField = ev.getValue().getValue().toString();
        }
        if (DEFAULT_ANNOTATION_VALUE.equals(fieldName)
            && (ev.getValue() != null && ev.getValue().getValue() != null)) {
          output.targetField = ev.getValue().getValue().toString();
        }
      }
    }
  }
  return output;
}
 
开发者ID:salesforce,项目名称:AptSpring,代码行数:35,代码来源:AnnotationValueExtractor.java

示例8: buildAnnotations

import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private ImmutableSet<String> buildAnnotations(ExecutableElement element) {
  ImmutableSet.Builder<String> builder = ImmutableSet.builder();

  List<? extends AnnotationMirror> annotations = element.getAnnotationMirrors();
  for (AnnotationMirror annotation : annotations) {
    builder.add(annotation.getAnnotationType()
        .asElement()
        .getSimpleName()
        .toString());
  }

  return builder.build();
}
 
开发者ID:hzsweers,项目名称:inspector,代码行数:14,代码来源:Property.java

示例9: overrideGlideStaticMethod

import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private MethodSpec overrideGlideStaticMethod(ExecutableElement methodToOverride) {
  List<? extends VariableElement> parameters = methodToOverride.getParameters();

  TypeElement element =
      (TypeElement) processingEnv.getTypeUtils().asElement(methodToOverride.getReturnType());

  MethodSpec.Builder builder =
      MethodSpec.methodBuilder(methodToOverride.getSimpleName().toString())
          .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
          .addJavadoc(processorUtil.generateSeeMethodJavadoc(methodToOverride))
          .addParameters(Lists.transform(parameters,
              new Function<VariableElement, ParameterSpec>() {
                @Override
                public ParameterSpec apply(VariableElement input) {
                  return ParameterSpec.get(input);
                }
          }));


  for (AnnotationMirror mirror : methodToOverride.getAnnotationMirrors()) {
    builder.addAnnotation(AnnotationSpec.get(mirror));
  }

  boolean returnsValue = element != null;
  if (returnsValue) {
    builder.returns(ClassName.get(element));
  }

  String code = returnsValue ? "return " : "";
  code += "$T.$N(";
  List<Object> args = new ArrayList<>();
  args.add(ClassName.get(glideType));
  args.add(methodToOverride.getSimpleName());
  if (!parameters.isEmpty()) {
    for (VariableElement param : parameters) {
      code += "$L, ";
      args.add(param.getSimpleName());
    }
    code = code.substring(0, code.length() - 2);
  }
  code += ")";
  builder.addStatement(code, args.toArray(new Object[0]));
  return builder.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:45,代码来源:GlideGenerator.java

示例10: collectPresenterProviders

import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private List<PresenterProvider> collectPresenterProviders(TypeElement presentersContainer) {
	List<PresenterProvider> providers = new ArrayList<>();

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

		final ExecutableElement providerMethod = (ExecutableElement) element;

		for (AnnotationMirror annotationMirror : providerMethod.getAnnotationMirrors()) {
			if (annotationMirror.getAnnotationType().asElement().toString().equals(PROVIDE_PRESENTER)) {
				if (providerMethod.getReturnType().getKind() != TypeKind.DECLARED) {
					continue;
				}

				DeclaredType kind = ((DeclaredType) providerMethod.getReturnType());
				String type = null;
				String tag = null;
				String presenterId = null;

				final String name = providerMethod.getSimpleName().toString();

				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();
					}
				}
				PresenterProvider provider = new PresenterProvider(kind, name, type, tag, presenterId);
				providers.add(provider);
				continue outer;
			}
		}
	}
	return providers;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:48,代码来源:PresenterBinderClassGenerator.java

示例11: overrideGlideStaticMethod

import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
private MethodSpec overrideGlideStaticMethod(ExecutableElement methodToOverride) {
  List<? extends VariableElement> parameters = methodToOverride.getParameters();

  TypeElement element =
      (TypeElement) processingEnv.getTypeUtils().asElement(methodToOverride.getReturnType());

  MethodSpec.Builder builder =
      MethodSpec.methodBuilder(methodToOverride.getSimpleName().toString())
          .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
          .addJavadoc(processorUtil.generateSeeMethodJavadoc(methodToOverride))
          .addParameters(Lists.transform(parameters,
              new Function<VariableElement, ParameterSpec>() {
                @Override
                public ParameterSpec apply(VariableElement input) {
                  return ParameterSpec.get(input);
                }
          }));

  String visibleForTestingTypeQualifiedName =
      processingEnv
          .getElementUtils()
          .getTypeElement(VISIBLE_FOR_TESTING_QUALIFIED_NAME)
          .toString();
  for (AnnotationMirror mirror : methodToOverride.getAnnotationMirrors()) {
    builder.addAnnotation(AnnotationSpec.get(mirror));

    // Suppress a lint warning if we're overriding a VisibleForTesting method.
    // See #1977.
    String annotationQualfiedName = mirror.getAnnotationType().toString();
    if (annotationQualfiedName.equals(visibleForTestingTypeQualifiedName)) {
      builder.addAnnotation(
          AnnotationSpec.builder(
              ClassName.get(SUPPRESS_LINT_PACKAGE_NAME, SUPPRESS_LINT_CLASS_NAME))
              .addMember("value", "$S", "VisibleForTests")
              .build());
    }
  }

  boolean returnsValue = element != null;
  if (returnsValue) {
    builder.returns(ClassName.get(element));
  }

  StringBuilder code = new StringBuilder(returnsValue ? "return " : "");
  code.append("$T.$N(");
  List<Object> args = new ArrayList<>();
  args.add(ClassName.get(glideType));
  args.add(methodToOverride.getSimpleName());
  if (!parameters.isEmpty()) {
    for (VariableElement param : parameters) {
      code.append("$L, ");
      args.add(param.getSimpleName());
    }
    code = new StringBuilder(code.substring(0, code.length() - 2));
  }
  code.append(")");
  builder.addStatement(code.toString(), args.toArray(new Object[0]));
  return builder.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:60,代码来源:GlideGenerator.java

示例12: generateRequestBuilderOverride

import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
/**
 * Generates an override of a particular method in {@code com.bumptech.glide.RequestBuilder} that
 * returns {@code com.bumptech.glide.RequestBuilder} so that it returns our generated subclass
 * instead.
 */
private MethodSpec generateRequestBuilderOverride(ExecutableElement methodToOverride) {
  // We've already verified that this method returns a RequestBuilder and RequestBuilders have
  // exactly one type argument, so this is safe unless those assumptions change.
  TypeMirror typeArgument =
      ((DeclaredType) methodToOverride.getReturnType()).getTypeArguments().get(0);

  ParameterizedTypeName generatedRequestBuilderOfType =
      ParameterizedTypeName.get(generatedRequestBuilderClassName, ClassName.get(typeArgument));

  MethodSpec.Builder builder = ProcessorUtil.overriding(methodToOverride)
      .returns(generatedRequestBuilderOfType)
      .addCode(CodeBlock.builder()
          .add("return ($T) super.$N(",
              generatedRequestBuilderOfType, methodToOverride.getSimpleName())
          .add(FluentIterable.from(methodToOverride.getParameters())
              .transform(new Function<VariableElement, String>() {
                @Override
                public String apply(VariableElement input) {
                  return input.getSimpleName().toString();
                }
              })
              .join(Joiner.on(", ")))
          .add(");\n")
          .build());

  for (AnnotationMirror mirror : methodToOverride.getAnnotationMirrors()) {
    builder = builder.addAnnotation(AnnotationSpec.get(mirror));
  }

  if (methodToOverride.isVarArgs()) {
    builder = builder
        .addModifiers(Modifier.FINAL)
        .addAnnotation(SafeVarargs.class)
        .addAnnotation(
            AnnotationSpec.builder(SuppressWarnings.class)
                .addMember("value", "$S", "varargs")
                .build());
  }

  return builder.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:47,代码来源:RequestBuilderGenerator.java

示例13: run

import javax.lang.model.element.ExecutableElement; //导入方法依赖的package包/类
@TriggerTreeKind(Kind.METHOD)
public static ErrorDescription run(HintContext ctx) {
    CompilationInfo compilationInfo = ctx.getInfo();
    TreePath treePath = ctx.getPath();
    TypeElement el = compilationInfo.getElements().getTypeElement("java.lang.Override"); //NOI18N

    if (el == null || !GeneratorUtils.supportsOverride(compilationInfo))
        return null;

    Element e = compilationInfo.getTrees().getElement(treePath);

    if (e != null && e.getKind() == ElementKind.METHOD) {
        ExecutableElement ee = (ExecutableElement) e;
        List<ElementDescription> result = new ArrayList<ElementDescription>();

        Element enclEl = ee.getEnclosingElement();
        if (!enclEl.getKind().isClass() && !enclEl.getKind().isInterface())
            return null;

        AnnotationType type = ComputeOverriding.detectOverrides(compilationInfo, (TypeElement) enclEl, ee, result);

        boolean hasOverriddenAnnotation = false;

        for (AnnotationMirror am : ee.getAnnotationMirrors()) {
            if (compilationInfo.getTypes().isSameType(am.getAnnotationType(), el.asType())) {
                hasOverriddenAnnotation = true;
                break;
            }
        }

        if (hasOverriddenAnnotation) {
            return null;
        }

        boolean addHint = false;

        if (type == AnnotationType.OVERRIDES) {
            addHint = true;
        } else {
            if (type == AnnotationType.IMPLEMENTS) {
                addHint = compilationInfo.getSourceVersion() != SourceVersion.RELEASE_5;
            }
        }

        if (addHint) {
            String desc = NbBundle.getMessage(AddOverrideAnnotation.class, "HINT_AddOverrideAnnotation");
            return ErrorDescriptionFactory.forName(ctx, treePath, desc, new FixImpl(compilationInfo, treePath).toEditorFix());
        }
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:53,代码来源:AddOverrideAnnotation.java


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