Java 类javax.lang.model.element.AnnotationMirror 实例源码

项目:openjdk-jdk10    文件:InlineAnnotationReaderImpl.java   
/**
 * Gets all the annotations on the given declaration.
 */
private Annotation[] getAllAnnotations(Element decl, Locatable srcPos) {
    List<Annotation> r = new ArrayList<Annotation>();

    for( AnnotationMirror m : decl.getAnnotationMirrors() ) {
        try {
            String fullName = ((TypeElement) m.getAnnotationType().asElement()).getQualifiedName().toString();
            Class<? extends Annotation> type =
                SecureLoader.getClassClassLoader(getClass()).loadClass(fullName).asSubclass(Annotation.class);
            Annotation annotation = decl.getAnnotation(type);
            if(annotation!=null)
                r.add( LocatableAnnotation.create(annotation,srcPos) );
        } catch (ClassNotFoundException e) {
            // just continue
        }
    }

    return r.toArray(new Annotation[r.size()]);
}
项目:openjdk-jdk10    文件:LinkFactory.java   
public Content getTypeAnnotationLinks(LinkInfo linkInfo) {
    Utils utils = ((LinkInfoImpl)linkInfo).utils;
    Content links = newContent();
    if (!utils.isAnnotated(linkInfo.type))
        return links;

    List<? extends AnnotationMirror> annotations = linkInfo.type.getAnnotationMirrors();
    boolean needSpace = false;
    for (AnnotationMirror anno : annotations) {
        if (needSpace) {
            links.addContent(" ");
        }
        links.addContent(getTypeAnnotationLink(linkInfo, anno));
        needSpace = true;
    }

    links.addContent(" ");
    return links;
}
项目:Spyglass    文件:TypeValidator.java   
@Override
public Result checkElement(final ExecutableElement element) {
    if (!ValueHandlerAnnoRetriever.hasAnnotation(element)) {
        return Result.createSuccessful();
    }

    final AnnotationMirror anno = ValueHandlerAnnoRetriever.getAnnotation(element);

    final MethodSpec supplier = getValueMethodGenerator.generateFor(anno);
    final TypeMirror suppliedType = returnTypeToTypeMirror(supplier);
    final TypeMirror recipientType = getParameterWithoutUseAnnotation(element).asType();

    if (!isAssignableOrConvertible(suppliedType, recipientType)) {
        return Result.createFailure(
                "Misused handler annotation found. \'%1$s\' cannot be cast to \'%2$s\'.",
                suppliedType,
                recipientType);
    }

    return Result.createSuccessful();
}
项目:incubator-netbeans    文件:EntityMappingsUtilities.java   
public static List<JoinColumn> getJoinColumns(final AnnotationModelHelper helper, Map<String, ? extends AnnotationMirror> annByType) {
    final List<JoinColumn> result = new ArrayList<JoinColumn>();
    AnnotationMirror joinColumnAnn = annByType.get("javax.persistence.JoinColumn"); // NOI18N
    if (joinColumnAnn != null) {
        result.add(new JoinColumnImpl(helper, joinColumnAnn));
    } else {
        AnnotationMirror joinColumnsAnnotation = annByType.get("javax.persistence.JoinColumns"); // NOI18N
        if (joinColumnsAnnotation != null) {
            AnnotationParser jcParser = AnnotationParser.create(helper);
            jcParser.expectAnnotationArray("value", helper.resolveType("javax.persistence.JoinColumn"), new ArrayValueHandler() { // NOI18N
                public Object handleArray(List<AnnotationValue> arrayMembers) {
                    for (AnnotationValue arrayMember : arrayMembers) {
                        AnnotationMirror joinColumnAnnotation = (AnnotationMirror)arrayMember.getValue();
                        result.add(new JoinColumnImpl(helper, joinColumnAnnotation));
                    }
                    return null;
                }
            }, null);
            jcParser.parse(joinColumnsAnnotation);
        }
    }
    return result;
}
项目:incubator-netbeans    文件:AnnotationScannerTest.java   
public void testScanAnnotationsOnFields() throws Exception {
    final AnnotationModelHelper helper = AnnotationModelHelper.create(createClasspathInfoForScanningAnnotations());
    final Set<String> elements = new HashSet<String>();

    helper.runJavaSourceTask(new Callable<Void>() {
        public Void call() throws InterruptedException {
            helper.getAnnotationScanner().findAnnotations(
                    "javax.annotation.Resource",
                    EnumSet.of(ElementKind.FIELD),
                    new AnnotationHandler() {
                        public void handleAnnotation(TypeElement typeElement, Element element, AnnotationMirror annotationMirror) {
                            assertEquals("foo.MyClass", typeElement.getQualifiedName().toString());
                            elements.add(element.getSimpleName().toString());
                        }
                    });
            return null;
        }
    });
    assertEquals(1, elements.size());
    assertTrue(elements.contains("myDS"));
}
项目:OpenJSharp    文件:InlineAnnotationReaderImpl.java   
/**
 * Gets all the annotations on the given declaration.
 */
private Annotation[] getAllAnnotations(Element decl, Locatable srcPos) {
    List<Annotation> r = new ArrayList<Annotation>();

    for( AnnotationMirror m : decl.getAnnotationMirrors() ) {
        try {
            String fullName = ((TypeElement) m.getAnnotationType().asElement()).getQualifiedName().toString();
            Class<? extends Annotation> type =
                SecureLoader.getClassClassLoader(getClass()).loadClass(fullName).asSubclass(Annotation.class);
            Annotation annotation = decl.getAnnotation(type);
            if(annotation!=null)
                r.add( LocatableAnnotation.create(annotation,srcPos) );
        } catch (ClassNotFoundException e) {
            // just continue
        }
    }

    return r.toArray(new Annotation[r.size()]);
}
项目:incubator-netbeans    文件:ManyToManyImpl.java   
public ManyToManyImpl(final AnnotationModelHelper helper, final Element element, AnnotationMirror manyToManyAnnotation, String name, Map<String, ? extends AnnotationMirror> annByType) {
    this.name = name;
    AnnotationParser parser = AnnotationParser.create(helper);
    parser.expectClass("targetEntity", new DefaultProvider() { // NOI18N
        public Object getDefaultValue() {
            return EntityMappingsUtilities.getCollectionArgumentTypeName(helper, element);
        }
    });
    parser.expectEnumConstantArray("cascade", helper.resolveType("javax.persistence.CascadeType"), new ArrayValueHandler() { // NOI18N
        public Object handleArray(List<AnnotationValue> arrayMembers) {
            return new CascadeTypeImpl(arrayMembers);
        }
    }, parser.defaultValue(new CascadeTypeImpl()));
    parser.expectEnumConstant("fetch", helper.resolveType("javax.persistence.FetchType"), parser.defaultValue("LAZY")); // NOI18N
    parser.expectString("mappedBy", parser.defaultValue("")); // NOI18N
    parseResult = parser.parse(manyToManyAnnotation);

    joinTable = new JoinTableImpl(helper, annByType.get("javax.persistence.JoinTable")); // NOI18N
}
项目:arez    文件:ArezProcessor.java   
private boolean isDaggerRequired( @Nonnull final TypeElement typeElement,
                                  @Nullable final AnnotationMirror scopeAnnotation )
{
  final VariableElement daggerParameter = (VariableElement)
    ProcessorUtil.getAnnotationValue( processingEnv.getElementUtils(),
                                      typeElement,
                                      Constants.COMPONENT_ANNOTATION_CLASSNAME,
                                      "dagger" ).getValue();
  switch ( daggerParameter.getSimpleName().toString() )
  {
    case "ENABLE":
      return true;
    case "DISABLE":
      return false;
    default:
      return null != scopeAnnotation &&
             null != processingEnv.getElementUtils().getTypeElement( Constants.DAGGER_MODULE_CLASSNAME );
  }
}
项目:incubator-netbeans    文件:AnnotationScannerTest.java   
public void testScanAnnotationsOnMethods() throws Exception {
    final AnnotationModelHelper helper = AnnotationModelHelper.create(createClasspathInfoForScanningAnnotations());
    final Set<String> elements = new HashSet<String>();

    helper.runJavaSourceTask(new Callable<Void>() {
        public Void call() throws InterruptedException {
            helper.getAnnotationScanner().findAnnotations(
                    "javax.annotation.Resource",
                    EnumSet.of(ElementKind.METHOD),
                    new AnnotationHandler() {
                        public void handleAnnotation(TypeElement typeElement, Element element, AnnotationMirror annotationMirror) {
                            assertEquals("foo.YourClass", typeElement.getQualifiedName().toString());
                            elements.add(element.getSimpleName().toString());
                        }
                    });
            return null;
        }
    });
    assertEquals(1, elements.size());
    assertTrue(elements.contains("setYourDataSource"));
}
项目:Spyglass    文件:GetDefaultMethodGenerator.java   
@Override
public MethodSpec supplyFor(final AnnotationMirror anno) {
    final CodeBlock body = CodeBlock
            .builder()
            .addStatement(
                    "return $T.getColorStateList($N(), $L)",
                    AndroidClassNames.CONTEXT_COMPAT,
                    CallerDef.GET_CONTEXT,
                    getLiteralFromAnnotation(anno, "resId"))
            .build();

    return getBaseMethodSpec()
            .returns(AndroidClassNames.COLOR_STATE_LIST)
            .addCode(body)
            .build();
}
项目:incubator-netbeans    文件:OneToOneImpl.java   
public OneToOneImpl(final AnnotationModelHelper helper, final Element element, AnnotationMirror oneToOneAnnotation, String name, Map<String, ? extends AnnotationMirror> annByType) {
    this.name = name;
    AnnotationParser parser = AnnotationParser.create(helper);
    parser.expectClass("targetEntity", new DefaultProvider() { // NOI18N
        public Object getDefaultValue() {
            return EntityMappingsUtilities.getElementTypeName(element);
        }
    });
    parser.expectEnumConstantArray("cascade", helper.resolveType("javax.persistence.CascadeType"), new ArrayValueHandler() { // NOI18N
        public Object handleArray(List<AnnotationValue> arrayMembers) {
            return new CascadeTypeImpl(arrayMembers);
        }
    }, parser.defaultValue(new CascadeTypeImpl()));
    parser.expectEnumConstant("fetch", helper.resolveType("javax.persistence.FetchType"), parser.defaultValue("EAGER")); // NOI18N
    parser.expectPrimitive("optional", Boolean.class, parser.defaultValue(true)); // NOI18N
    parser.expectString("mappedBy", parser.defaultValue("")); // NOI18N
    parseResult = parser.parse(oneToOneAnnotation);

    joinTable = new JoinTableImpl(helper, annByType.get("javax.persistence.JoinTable")); // NOI18N
    joinColumnList = EntityMappingsUtilities.getJoinColumns(helper, annByType);
    pkJoinColumnList = EntityMappingsUtilities.getPrimaryKeyJoinColumns(helper, annByType);
}
项目:incubator-netbeans    文件:JpaControllerUtil.java   
private static Boolean findAnnotationValueAsBoolean(Element fieldElement, String[] fieldAnnotationFqns, String annotationKey) {
    Boolean isFieldXable = null;
    for (int i = 0; i < fieldAnnotationFqns.length; i++) {
        String fieldAnnotationFqn = fieldAnnotationFqns[i];
        AnnotationMirror fieldAnnotation = JpaControllerUtil.findAnnotation(fieldElement, fieldAnnotationFqn); //NOI18N
        if (fieldAnnotation != null) {  
            String annotationValueString = JpaControllerUtil.findAnnotationValueAsString(fieldAnnotation, annotationKey); //NOI18N
            if (annotationValueString != null) {
                isFieldXable = Boolean.valueOf(annotationValueString);
            }
            else {
                isFieldXable = Boolean.TRUE;
            }
            break;
        }
    }
    return isFieldXable;
}
项目:Spyglass    文件:TestGetDefaultMethodGenerator.java   
@Test
public void testGenerateFor_defaultToBooleanAnnotationSupplied() {
    final Element element = avatarRule.getElementWithUniqueId("boolean");
    final AnnotationMirror mirror = AnnotationMirrorHelper.getAnnotationMirror(element, DefaultToBoolean.class);

    final MethodSpec generatedMethod = generator.generateFor(mirror);

    assertThat(generatedMethod, is(notNullValue()));
    checkMethodSignature(generatedMethod, ClassName.BOOLEAN.box());
    checkCompiles(generatedMethod);
}
项目:Spyglass    文件:GetPlaceholderMethodGenerator.java   
@Override
public MethodSpec supplyFor(final AnnotationMirror useAnno, final int position) {
    return getBaseMethodSpec(position)
            .returns(Object.class)
            .addCode(CodeBlock
                    .builder()
                    .addStatement("return null")
                    .build())
            .build();
}
项目:arez    文件:ComponentDescriptor.java   
private void addOnStale( @Nonnull final AnnotationMirror annotation, @Nonnull final ExecutableElement method )
  throws ArezProcessorException
{
  final String name =
    deriveHookName( method,
                    ComputedDescriptor.ON_STALE_PATTERN,
                    "Stale",
                    getAnnotationParameter( annotation, "name" ) );
  findOrCreateComputed( name ).setOnStale( method );
}
项目:inspector    文件:Property.java   
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();
}
项目:react4j    文件:ProcessorUtil.java   
static void copyDocumentedAnnotations( @Nonnull final AnnotatedConstruct element,
                                       @Nonnull final MethodSpec.Builder builder )
{
  for ( final AnnotationMirror annotation : element.getAnnotationMirrors() )
  {
    final DeclaredType annotationType = annotation.getAnnotationType();
    if ( !annotationType.toString().startsWith( "react4j.annotations." ) &&
         null != annotationType.asElement().getAnnotation( Documented.class ) )
    {
      builder.addAnnotation( AnnotationSpec.get( annotation ) );
    }
  }
}
项目:incubator-netbeans    文件:QueriesProperlyDefined.java   
private static AnnotationMirror getFirstAnnotationFromGivenSet(TypeElement subject,
        Collection<String> annotationClasses) {

    for (String annClass : annotationClasses) {
        AnnotationMirror foundAnn = Utilities.findAnnotation(subject, annClass);

        if (foundAnn != null) {
            return foundAnn;
        }
    }

    return null;
}
项目:auto-value-json    文件:JsonProperty.java   
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();
}
项目:Spyglass    文件:TestGetValueMethodGenerator.java   
@Test
public void testGenerateFor_stringHandlerAnnotationSupplied() {
    final Element element = avatarRule.getElementWithUniqueId("string");
    final AnnotationMirror mirror = AnnotationMirrorHelper.getAnnotationMirror(element, StringHandler.class);

    final MethodSpec generatedMethod = generator.generateFor(mirror);

    checkSignature(generatedMethod, ClassName.get(String.class));
    checkCompiles(generatedMethod);
}
项目:auto-value-bundle    文件:BundleExtension.java   
private static Set<String> getAnnotations(List<? extends AnnotationMirror> annotations) {
    Set<String> set = new LinkedHashSet<>();

    for (AnnotationMirror annotation : annotations) {
        set.add(annotation.getAnnotationType().asElement().getSimpleName().toString());
    }

    return Collections.unmodifiableSet(set);
}
项目:glimpse    文件:RClassUtil.java   
static StyleableAnnotationValues getStyleableAnnotationValues(final Trees trees, final Elements elementUtils, final Types typeUtils, final Messager messager, final Element annotatedElement) {
    RClassReference styleableReference = null;
    RClassReference defaultValueReference = null;
    AnnotationMirror annotationMirror = null;

    for (final AnnotationMirror mirror : annotatedElement.getAnnotationMirrors()) {
        if (mirror.getAnnotationType().toString().equals(Styleable.class.getCanonicalName())) {
            annotationMirror = mirror;
            break;
        }
    }

    AnnotationValue value = null;
    AnnotationValue defaultValue = null;

    //noinspection ConstantConditions
    for (final Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotationMirror.getElementValues().entrySet()) {
        if (entry.getKey().getSimpleName().toString().equals("value")) {
            value = entry.getValue();
        } else if (entry.getKey().getSimpleName().toString().equals("defaultRes")) {
            defaultValue = entry.getValue();
        }
    }

    styleableReference = getRClassReference(trees, elementUtils, typeUtils, messager, annotatedElement, annotationMirror, value, StyleableField.VALUE_FIELD);

    if (defaultValue != null) {
        defaultValueReference = getRClassReference(trees, elementUtils, typeUtils, messager, annotatedElement, annotationMirror, defaultValue, StyleableField.DEFAULT_RES_FIELD);
    }

    return new StyleableAnnotationValues(styleableReference, defaultValueReference);
}
项目:Spyglass    文件:TestDefaultAnnotationRetriever.java   
@Test
public void testGetAnnotation_defaultToDimensionResourceAnnotationPresent() {
    final ExecutableElement element = avatarRule.getElementWithUniqueId("dimension resource");

    final AnnotationMirror mirror = DefaultAnnoRetriever.getAnnotation(element);

    assertThat(mirror, is(notNullValue()));
    assertThat(mirror.getAnnotationType().toString(), is(DefaultToDimensionResource.class.getName()));
}
项目:annotation-processor-toolkit    文件:AnnotationUtils.java   
public static TypeMirror[] getClassArrayAttributeFromAnnotationAsTypeMirror(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 new TypeMirror[0];
        } else {
            return AnnotationValueUtils.getTypeAttributeValueArray(annotationAttributeValue);
        }

    }
项目:Spyglass    文件:TestGetValueMethodGenerator.java   
@Test
public void testGenerateFor_dimensionHandlerAnnotationSupplied() {
    final Element element = avatarRule.getElementWithUniqueId("dimension");
    final AnnotationMirror mirror = AnnotationMirrorHelper.getAnnotationMirror(element, DimensionHandler.class);

    final MethodSpec generatedMethod = generator.generateFor(mirror);

    checkSignature(generatedMethod, ClassName.get(Number.class));
    checkCompiles(generatedMethod);
}
项目:java-code-templates    文件:AnnotationHelper.java   
private static Stream<AnnotationMirror> annotationMirrorSearch(final String typeName, final Collection<? extends AnnotationMirror> mirrors) {
    return Stream.concat(
            mirrors.stream().filter(mirror -> Objects.equals(typeName, mirror.getAnnotationType().toString())),
            mirrors.stream()
                // Only annotations with at least one array parameter
                .filter(mirror -> mirror.getElementValues().values().stream().anyMatch(AnnotationHelper::isArray))

                .flatMap(mirror -> mirror.getElementValues().values().stream()
                        .filter(AnnotationHelper::isArray) // only array parameters...
                        .map(AnnotationHelper::asArray)
                        .filter(list -> list.stream().allMatch(AnnotationHelper::isAnnotation)) // ...whose values are annotations
                        .map(list -> list.stream().map(AnnotationHelper::asAnnotation).collect(Collectors.toList()))
                        .flatMap(list -> annotationMirrorSearch(typeName, list))));
}
项目:incubator-netbeans    文件:CompletionFilter.java   
@Override
public TreePath getPath(Element elmnt, AnnotationMirror am, AnnotationValue av) {
    if (elmnt == null) {
        return null;
    }
    return delegate.getPath(elmnt, am, av);
}
项目:arez    文件:ProcessorUtil.java   
@Nullable
private static AnnotationValue findAnnotationValue( @Nonnull final Elements elements,
                                                    @Nonnull final Element typeElement,
                                                    @Nonnull final String annotationClassName,
                                                    @Nonnull final String parameterName )
{
  final AnnotationMirror mirror = getAnnotationByType( typeElement, annotationClassName );
  return findAnnotationValue( elements, mirror, parameterName );
}
项目:openjdk-jdk10    文件:MatchProcessor.java   
private void processMatchRule(EconomicMap<TypeElement, MatchRuleDescriptor> map, Element element, AnnotationMirror mirror) {
    if (!processedMatchRule.contains(element)) {
        try {
            processedMatchRule.add(element);

            // The annotation element type should ensure this is true.
            assert element instanceof ExecutableElement;

            findMatchableNodes(element);

            TypeElement topDeclaringType = topDeclaringType(element);
            MatchRuleDescriptor info = map.get(topDeclaringType);
            if (info == null) {
                info = new MatchRuleDescriptor(topDeclaringType);
                map.put(topDeclaringType, info);
            }
            List<AnnotationMirror> mirrors = null;
            if (typeUtils().isSameType(mirror.getAnnotationType(), matchRulesTypeMirror)) {
                // Unpack the mirrors for a repeatable annotation
                mirrors = getAnnotationValueList(AnnotationMirror.class, mirror, "value");
            }
            int i = 0;
            for (MatchRule matchRule : element.getAnnotationsByType(MatchRule.class)) {
                processMethodMatchRule((ExecutableElement) element, info, matchRule, mirrors != null ? mirrors.get(i++) : mirror);
            }
        } catch (Throwable t) {
            reportExceptionThrow(element, t);
        }
    }
}
项目:convalida    文件:ConvalidaProcessor.java   
private static AnnotationMirror getMirror(Element element, Class<? extends Annotation> annotation) {
    for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) {
        if (annotationMirror.getAnnotationType().toString().equals(annotation.getCanonicalName())) {
            return annotationMirror;
        }
    }
    return null;
}
项目:Spyglass    文件:TestGetPlaceholderMethodGenerator.java   
@Test
public void testGenerateFor_parameterWithUseString() {
    final VariableElement parameter = avatarRule.getElementWithUniqueId("string");
    final AnnotationMirror useAnnotation = UseAnnoRetriever.getAnnotation(parameter);

    final MethodSpec generatedMethod = generator.generateFor(useAnnotation, 0);

    checkSignature(generatedMethod, ClassName.get(String.class));
    checkCompiles(generatedMethod);
}
项目:incubator-netbeans    文件:GenerationUtilsTest.java   
public void testCreateAnnotationBooleanArgumentIssue89230() throws Exception {
    TestUtilities.copyStringToFileObject(testFO,
            "package foo;" +
            "@interface Column {" +
            "   boolean nullable();" +
            "}" +
            "public class TestClass {" +
            "}");
    runModificationTask(testFO, new Task<WorkingCopy>() {
        public void run(WorkingCopy copy) throws Exception {
            GenerationUtils genUtils = GenerationUtils.newInstance(copy);
            ClassTree classTree = SourceUtils.getPublicTopLevelTree(copy);
            AnnotationTree annotationTree = genUtils.createAnnotation("foo.Column", Collections.singletonList(genUtils.createAnnotationArgument("nullable", true)));
            ClassTree newClassTree = genUtils.addAnnotation(classTree, annotationTree);
            copy.rewrite(classTree, newClassTree);
        }
    }).commit();
    runUserActionTask(testFO, new Task<CompilationController>() {
        public void run(CompilationController controller) throws Exception {
            TypeElement typeElement = SourceUtils.getPublicTopLevelElement(controller);
            assertEquals(1, typeElement.getAnnotationMirrors().size());
            AnnotationMirror columnAnn = typeElement.getAnnotationMirrors().get(0);
            assertEquals(1, columnAnn.getElementValues().size());
            Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> columnAnnNullableElement = columnAnn.getElementValues().entrySet().iterator().next();
            assertEquals("nullable", columnAnnNullableElement.getKey().getSimpleName().toString());
            assertEquals(true, columnAnn.getElementValues().values().iterator().next().getValue());
        }
    });
}
项目:openjdk-jdk10    文件:ClassSubstitutionVerifier.java   
@Override
public void verify(Element element, AnnotationMirror classSubstitution, PluginGenerator generator) {
    if (!element.getKind().isClass()) {
        assert false : "Element is guaranteed to be a class.";
        return;
    }
    TypeElement type = (TypeElement) element;

    TypeElement substitutionType = resolveOriginalType(env, type, classSubstitution);
    if (substitutionType == null) {
        return;
    }
}
项目:openjdk-jdk10    文件:MethodSubstitutionVerifier.java   
private TypeMirror[] originalSignature(TypeElement originalType, ExecutableElement method, AnnotationMirror annotation, boolean isStatic) {
    AnnotationValue signatureValue = findAnnotationValue(annotation, ORIGINAL_SIGNATURE);
    String signatureString = resolveAnnotationValue(String.class, signatureValue);
    List<TypeMirror> parameters = new ArrayList<>();
    if (signatureString.equals(ORIGINAL_SIGNATURE_DEFAULT)) {
        for (int i = 0; i < method.getParameters().size(); i++) {
            parameters.add(method.getParameters().get(i).asType());
        }
        if (!isStatic) {
            if (parameters.isEmpty()) {
                env.getMessager().printMessage(Kind.ERROR, "Method signature must be a static method with the 'this' object as its first parameter", method, annotation);
                return null;
            } else {
                TypeMirror thisParam = parameters.remove(0);
                if (!isSubtype(originalType.asType(), thisParam)) {
                    Name thisName = method.getParameters().get(0).getSimpleName();
                    env.getMessager().printMessage(Kind.ERROR, String.format("The type of %s must assignable from %s", thisName, originalType), method, annotation);
                }
            }
        }
        parameters.add(0, method.getReturnType());
    } else {
        try {
            APHotSpotSignature signature = new APHotSpotSignature(signatureString);
            parameters.add(signature.getReturnType(env));
            for (int i = 0; i < signature.getParameterCount(false); i++) {
                parameters.add(signature.getParameterType(env, i));
            }
        } catch (Exception e) {
            /*
             * That's not good practice and should be changed after APHotSpotSignature has
             * received a cleanup.
             */
            env.getMessager().printMessage(Kind.ERROR, String.format("Parsing the signature failed: %s", e.getMessage() != null ? e.getMessage() : e.toString()), method, annotation,
                            signatureValue);
            return null;
        }
    }
    return parameters.toArray(new TypeMirror[parameters.size()]);
}
项目:arez    文件:ComponentDescriptor.java   
private void addOnDeactivate( @Nonnull final AnnotationMirror annotation, @Nonnull final ExecutableElement method )
  throws ArezProcessorException
{
  final String name =
    deriveHookName( method,
                    ComputedDescriptor.ON_DEACTIVATE_PATTERN,
                    "Deactivate",
                    getAnnotationParameter( annotation, "name" ) );
  findOrCreateComputed( name ).setOnDeactivate( method );
}
项目:GitHub    文件:RequestOptionsGenerator.java   
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();
}
项目:arez    文件:ComponentDescriptor.java   
private void addAction( @Nonnull final AnnotationMirror annotation,
                        @Nonnull final ExecutableElement method,
                        @Nonnull final ExecutableType methodType )
  throws ArezProcessorException
{
  MethodChecks.mustBeOverridable( Constants.ACTION_ANNOTATION_CLASSNAME, method );

  final String name = deriveActionName( method, annotation );
  checkNameUnique( name, method, Constants.ACTION_ANNOTATION_CLASSNAME );
  final boolean mutation = getAnnotationParameter( annotation, "mutation" );
  final boolean reportParameters = getAnnotationParameter( annotation, "reportParameters" );
  final ActionDescriptor action = new ActionDescriptor( this, name, mutation, reportParameters, method, methodType );
  _actions.put( action.getName(), action );
}
项目:Spyglass    文件:TestUseAnnotationRetriever.java   
@Test
public void testGetAnnotation_useBooleanAnnotationPresent() {
    final VariableElement element = avatarRule.getElementWithUniqueId("boolean");

    final AnnotationMirror mirror = UseAnnoRetriever.getAnnotation(element);

    assertThat(mirror, is(notNullValue()));
    assertThat(mirror.getAnnotationType().toString(), is(UseBoolean.class.getName()));
}
项目:incubator-netbeans    文件:EmbeddableImpl.java   
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.Embeddable"); // NOI18N
    return embeddableAnn != null;
}
项目:Spyglass    文件:GetDefaultMethodGenerator.java   
@Override
public MethodSpec supplyFor(final AnnotationMirror anno) {
    final CodeBlock body = CodeBlock
            .builder()
            .addStatement("return $L", getLiteralFromAnnotation(anno, "value"))
            .build();

    return getBaseMethodSpec()
            .returns(Number.class)
            .addCode(body)
            .build();
}