javax.lang.model.element.TypeElement#getAnnotationMirrors ( )源码实例Demo

下面列出了javax.lang.model.element.TypeElement#getAnnotationMirrors ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: spring-init   文件: ElementUtils.java
public List<TypeElement> getTypesFromAnnotation(TypeElement type, String annotation,
		String attribute) {
	Set<TypeElement> list = new LinkedHashSet<>();
	for (AnnotationMirror mirror : type.getAnnotationMirrors()) {
		if (((TypeElement) mirror.getAnnotationType().asElement()).getQualifiedName()
				.toString().equals(annotation)) {
			list.addAll(getTypesFromAnnotation(mirror, attribute));
		}
		Set<AnnotationMirror> metas = getAnnotations(
				mirror.getAnnotationType().asElement(), annotation);
		for (AnnotationMirror meta : metas) {
			list.addAll(getTypesFromAnnotation(meta, attribute));
		}
	}
	return new ArrayList<>(list);
}
 
源代码2 项目: netbeans   文件: JaxWsAddOperation.java
private boolean isJaxWsImplementationClass(TypeElement classEl, CompilationController controller) {
    TypeElement wsElement = controller.getElements().getTypeElement("javax.jws.WebService"); //NOI18N
    if (wsElement != null) {
        List<? extends AnnotationMirror> annotations = classEl.getAnnotationMirrors();
        for (AnnotationMirror anMirror : annotations) {
            if (controller.getTypes().isSameType(wsElement.asType(), anMirror.getAnnotationType())) {
                Map<? extends ExecutableElement, ? extends AnnotationValue> expressions = anMirror.getElementValues();
                for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : expressions.entrySet()) {
                    if (entry.getKey().getSimpleName().contentEquals("wsdlLocation")) { //NOI18N
                        return false;
                    }
                }
                return true;
            }
        }
    }
    return false;
}
 
源代码3 项目: netbeans   文件: AbstractTestGenerator.java
/**
 * Checks whether is given method declared by no-interface Bean or by interface annotated by
 * {@code @javax.ejb.Remote} or {@code @javax.ejb.Local}
 *
 * @param srcClass class for which are generated test cases
 * @param srcMethod method of interest
 * @return {@code true} if the bean is no-interface or method is declared by
 * respectively annotated interface, {@code false} otherwise
 */
private static boolean isMethodInContainerLookup(TypeElement srcClass, ExecutableElement srcMethod) {
    // check for no-interface LocalBean
    List<? extends AnnotationMirror> annotations = srcClass.getAnnotationMirrors();
    for (AnnotationMirror annotationMirror : annotations) {
        String annotation = ((TypeElement)annotationMirror.getAnnotationType().asElement()).getQualifiedName().toString();
        if (annotation.equals("javax.ejb.LocalBean"))   // NOI18N
            return true;
    }
    // check if the class has empty implements clause or given method is declared by @Remote, @Local interface
    List<? extends TypeMirror> interfaces = srcClass.getInterfaces();
    if (interfaces.isEmpty()
            || areAllowedInterfacesForLocalBean(interfaces)
            || getEjbInterfaceDeclaringMethod(srcMethod, interfaces) != null) {
        return true;
    }
    return false;
}
 
源代码4 项目: jackdaw   文件: JRepeatableCodeGenerator.java
@Override
protected final void generateBody(
    final CodeGeneratorContext context, final TypeSpec.Builder builder
) throws Exception {
    final TypeElement typeElement = context.getTypeElement();
    final List<? extends AnnotationMirror> annotations = typeElement.getAnnotationMirrors();
    final String repeatableClassName = JRepeatable.class.getCanonicalName();

    for (final AnnotationMirror annotation : annotations) {
        final String annotationName = ModelUtils.getName(annotation);
        if (!annotationName.equals(repeatableClassName)
            && !SourceCodeUtils.hasAnnotation(builder, annotation))
        {
            builder.addAnnotation(createAnnotation(annotation));
        }
    }

    builder.addMethod(
        MethodSpec.methodBuilder("value")
            .returns(TypeUtils.getArrayTypeName(typeElement))
            .addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
            .build()
    );
}
 
源代码5 项目: RetroFacebook   文件: GwtCompatibility.java
GwtCompatibility(TypeElement type) {
  Optional<AnnotationMirror> gwtCompatibleAnnotation = Optional.absent();
  List<? extends AnnotationMirror> annotations = type.getAnnotationMirrors();
  for (AnnotationMirror annotation : annotations) {
    Name name = annotation.getAnnotationType().asElement().getSimpleName();
    if (name.contentEquals("GwtCompatible")) {
      gwtCompatibleAnnotation = Optional.of(annotation);
    }
  }
  this.gwtCompatibleAnnotation = gwtCompatibleAnnotation;
}
 
源代码6 项目: netbeans   文件: FlowScopedBeanWithoutCdi.java
@TriggerTreeKind(Tree.Kind.CLASS)
public static Collection<ErrorDescription> run(HintContext hintContext) {
    List<ErrorDescription> problems = new ArrayList<>();
    final JsfHintsContext ctx = JsfHintsUtils.getOrCacheContext(hintContext);

    Project project = ctx.getProject();
    if (project == null) {
        return problems;
    }

    CompilationInfo info = hintContext.getInfo();
    for (TypeElement typeElement : info.getTopLevelElements()) {
        for (AnnotationMirror annotationMirror : typeElement.getAnnotationMirrors()) {
            if (FLOW_SCOPED.equals(annotationMirror.getAnnotationType().toString())) {
                // it's FlowScoped bean -> check the CDI
                CdiUtil cdiUtil = project.getLookup().lookup(CdiUtil.class);
                if (cdiUtil == null || !cdiUtil.isCdiEnabled()) {
                    Tree tree = info.getTrees().getTree(typeElement, annotationMirror);
                    problems.add(JsfHintsUtils.createProblem(
                            tree,
                            info,
                            Bundle.FlowScopedBeanWithoutCdi_display_name(),
                            Severity.WARNING,
                            Arrays.<Fix>asList(new FixCdiAvailability(project))));
                }
            }
        }
    }
    return problems;
}
 
源代码7 项目: netbeans   文件: BeansCompletor.java
private static boolean isAlternative(TypeElement te) {
    List<? extends AnnotationMirror> annotationMirrors = te.getAnnotationMirrors();
    for (AnnotationMirror annotation : annotationMirrors) {
        if (annotation.getAnnotationType().asElement() instanceof TypeElement) {
            String typeName = ((TypeElement) annotation.getAnnotationType().asElement()).getQualifiedName().toString();
            if (AnnotationUtil.ALTERNATVE.equals(typeName)) {
                return true;
            }
        }
    }
    return false;
}
 
源代码8 项目: litho   文件: AnnotationExtractor.java
public static ImmutableList<AnnotationSpec> extractValidAnnotations(TypeElement element) {
  final List<AnnotationSpec> annotations = new ArrayList<>();
  for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) {
    if (isValidAnnotation(annotationMirror)) {
      annotations.add(AnnotationSpec.get(annotationMirror));
    }
  }

  return ImmutableList.copyOf(annotations);
}
 
源代码9 项目: auto   文件: GwtCompatibility.java
GwtCompatibility(TypeElement type) {
  Optional<AnnotationMirror> gwtCompatibleAnnotation = Optional.empty();
  List<? extends AnnotationMirror> annotations = type.getAnnotationMirrors();
  for (AnnotationMirror annotation : annotations) {
    Name name = annotation.getAnnotationType().asElement().getSimpleName();
    if (name.contentEquals("GwtCompatible")) {
      gwtCompatibleAnnotation = Optional.of(annotation);
    }
  }
  this.gwtCompatibleAnnotation = gwtCompatibleAnnotation;
}
 
源代码10 项目: netbeans   文件: AbstractTestGenerator.java
/**
 * Checks whether is interface annotated as {@code @javax.ejb.Remote} or {@code @javax.ejb.Local}
 *
 * @param trgInterface interface which should be annotated
 * @return {@code true} if the interface is annotated, {@code false} otherwise
 */
private static boolean isLocalOrRemoteInterface(TypeElement trgInterface) {
    List<? extends AnnotationMirror> annotations = trgInterface.getAnnotationMirrors();
    for (AnnotationMirror am : annotations) {
        String annotation = ((TypeElement)am.getAnnotationType().asElement()).getQualifiedName().toString();
        if (annotation.equals("javax.ejb.Local") ||  // NOI18N
            annotation.equals("javax.ejb.Remote")) { // NOI18N
            // interface is @Local or @Remote
            return true;
        }
    }
    return false;
}
 
@TriggerTreeKind(Tree.Kind.CLASS)
public static Collection<ErrorDescription> run(HintContext hintContext) {
    List<ErrorDescription> problems = new ArrayList<>();
    final JsfHintsContext ctx = JsfHintsUtils.getOrCacheContext(hintContext);

    if (ctx.getJsfVersion() == null || !ctx.getJsfVersion().isAtLeast(JSFVersion.JSF_2_2)) {
        return problems;
    }

    CompilationInfo info = hintContext.getInfo();
    for (TypeElement typeElement : info.getTopLevelElements()) {
        for (AnnotationMirror annotationMirror : typeElement.getAnnotationMirrors()) {
            if (annotationMirror.getAnnotationType().toString().startsWith(JAVAX_FACES_BEAN)) {
                // it's javax.faces.bean annotation
                Tree tree = info.getTrees().getTree(typeElement, annotationMirror);
                List<Fix> fixes = getFixesForType(info, typeElement, annotationMirror);
                problems.add(JsfHintsUtils.createProblem(
                        tree,
                        info,
                        Bundle.JavaxFacesBeanIsGonnaBeDeprecated_display_name(),
                        Severity.HINT,
                        fixes));
            }
        }
    }
    return problems;
}
 
源代码12 项目: openjdk-jdk9   文件: DependenciesTest.java
Collection<AnnotationMirror> getTriggersCompleteAnnotation(TypeElement te) {
    for (AnnotationMirror am : te.getAnnotationMirrors()) {
        if (triggersCompleteAnnotation.equals(am.getAnnotationType().asElement())) {
            return Collections.singletonList(am);
        }
        if (triggersCompleteRepeatAnnotation.equals(am.getAnnotationType().asElement())) {
            return (Collection<AnnotationMirror>) findAttribute(am, "value").getValue();
        }
    }
    return Collections.emptyList();
}
 
源代码13 项目: netbeans   文件: PersistentObjectManagerTest.java
private boolean refresh(TypeElement typeElement) {
    AnnotationParser parser = AnnotationParser.create(getHelper());
    parser.expectString("name", AnnotationParser.defaultValue(typeElement.getSimpleName()));
    List<? extends AnnotationMirror> annotations = typeElement.getAnnotationMirrors();
    if (annotations.size() == 0) {
        return false;
    }
    name = parser.parse(annotations.get(0)).get("name", String.class);
    return true;
}
 
源代码14 项目: netbeans   文件: TypeUtil.java
public static String getAnnotationValueName(CompilationController controller, TypeElement classElement, TypeElement annotationElement) {
    List<? extends AnnotationMirror> annotations = classElement.getAnnotationMirrors();
    for (AnnotationMirror anMirror : annotations) {
        if (controller.getTypes().isSameType(annotationElement.asType(), anMirror.getAnnotationType())) {
            Map<? extends ExecutableElement, ? extends AnnotationValue> expressions = anMirror.getElementValues();
            for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry: expressions.entrySet()) {
                if (entry.getKey().getSimpleName().contentEquals("name")) { //NOI18N
                    return (String) expressions.get(entry.getKey()).getValue();
                }
            }
        }
    }
    return null;
}
 
public boolean isInjectionTarget(CompilationController controller, TypeElement typeElement) {
    if (controller == null || typeElement==null) {
        throw new NullPointerException("Passed null to WSInjectionTargetQueryImplementation.isInjectionTarget(CompilationController, TypeElement)"); // NOI18N
    }
    FileObject fo = controller.getFileObject();
    Project project = FileOwnerQuery.getOwner(fo);
    
    if (ProjectUtil.isJavaEE5orHigher(project) && !isTomcatTargetServer(project) && !(ElementKind.INTERFACE==typeElement.getKind())) {
        
        List<? extends AnnotationMirror> annotations = typeElement.getAnnotationMirrors();
        boolean found = false;

        for (AnnotationMirror m : annotations) {
            Name qualifiedName = ((TypeElement)m.getAnnotationType().asElement()).getQualifiedName();
            if (qualifiedName.contentEquals("javax.jws.WebService")) { //NOI18N
                found = true;
                break;
            }
            if (qualifiedName.contentEquals("javax.jws.WebServiceProvider")) { //NOI18N
                found = true;
                break;
            }
        }
        if (found) return true;
    }
    return false;
}
 
源代码16 项目: netbeans   文件: JaxWsNode.java
private boolean resolveServiceUrl(CompilationController controller, 
        TypeElement targetElement, String[] serviceName, String[] name) 
            throws IOException 
{
    boolean foundWsAnnotation = false;
    List<? extends AnnotationMirror> annotations = targetElement.getAnnotationMirrors();
    for (AnnotationMirror anMirror : annotations) {
        boolean isWebMethodAnnotation = JaxWsUtils.hasFqn(anMirror, 
                "javax.jws.WebService");   // NOI18N
        if (isWebMethodAnnotation) {
            foundWsAnnotation = true;
            Map<? extends ExecutableElement, ? extends AnnotationValue> 
                expressions = anMirror.getElementValues();
            for (Map.Entry<? extends ExecutableElement, 
                    ? extends AnnotationValue> entry : expressions.entrySet()) 
            {
                if (entry.getKey().getSimpleName().contentEquals("serviceName")) { //NOI18N
                    serviceName[0] = (String) expressions.get(entry.getKey()).
                        getValue();
                    if (serviceName[0] != null) {
                        serviceName[0] = URLEncoder.encode(serviceName[0], 
                                "UTF-8"); //NOI18N
                    }
                } else if (entry.getKey().getSimpleName().
                        contentEquals("name"))  //NOI18N
                {
                    name[0] = (String) expressions.get(entry.getKey()).getValue();
                    if (name[0] != null) {
                        name[0] = URLEncoder.encode(name[0], "UTF-8"); //NOI18N
                    }
                }
                if (serviceName[0] != null && name[0] != null) {
                    break;
                }
            }
            break;
        } // end if
    } // end for
    return foundWsAnnotation;
}
 
源代码17 项目: RetroFacebook   文件: GwtCompatibility.java
GwtCompatibility(TypeElement type) {
  Optional<AnnotationMirror> gwtCompatibleAnnotation = Optional.absent();
  List<? extends AnnotationMirror> annotations = type.getAnnotationMirrors();
  for (AnnotationMirror annotation : annotations) {
    Name name = annotation.getAnnotationType().asElement().getSimpleName();
    if (name.contentEquals("GwtCompatible")) {
      gwtCompatibleAnnotation = Optional.of(annotation);
    }
  }
  this.gwtCompatibleAnnotation = gwtCompatibleAnnotation;
}
 
源代码18 项目: netbeans   文件: AddWsOperationHelper.java
private String getEndpointInterface(TypeElement classEl, 
        CompilationController controller)  
{
    TypeElement wsElement = controller.getElements().
        getTypeElement("javax.jws.WebService");                 //NOI18N
    if ( wsElement == null ){
        isIncomplete = true;
        return null;
    }
    List<? extends AnnotationMirror> annotations = classEl.getAnnotationMirrors();
    for (AnnotationMirror anMirror : annotations) {
        if (controller.getTypes().isSameType(wsElement.asType(),
                anMirror.getAnnotationType()))
        {
            Map<? extends ExecutableElement, ? extends AnnotationValue> expressions = 
                anMirror.getElementValues();
            for (Map.Entry<? extends ExecutableElement, 
                    ? extends AnnotationValue> entry : expressions.entrySet())
            {
                if (entry.getKey().getSimpleName()
                        .contentEquals("endpointInterface")) // NOI18N
                {
                    String value = (String) expressions.get(entry.getKey())
                            .getValue();
                    if (value != null) {
                        TypeElement seiEl = controller.getElements()
                                .getTypeElement(value);
                        if (seiEl != null) {
                            return seiEl.getQualifiedName().toString();
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
源代码19 项目: quarkus   文件: ConfigDocItemScanner.java
/**
 * Record a configuration root class. It will later be visited to find configuration items.
 */
public void addConfigRoot(final PackageElement pkg, TypeElement clazz) {
    if (Constants.SKIP_DOCS_GENERATION) {
        return;
    }

    if (pkg.toString().startsWith(IO_QUARKUS_TEST_EXTENSION_PACKAGE)) {
        return;
    }

    ConfigPhase configPhase = ConfigPhase.BUILD_TIME;

    for (AnnotationMirror annotationMirror : clazz.getAnnotationMirrors()) {
        String annotationName = annotationMirror.getAnnotationType().toString();
        if (annotationName.equals(Constants.ANNOTATION_CONFIG_ROOT)) {
            final Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = annotationMirror
                    .getElementValues();
            String name = Constants.EMPTY;
            for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : elementValues.entrySet()) {
                final String key = entry.getKey().toString();
                final String value = entry.getValue().getValue().toString();
                if ("name()".equals(key)) {
                    name = Constants.QUARKUS + Constants.DOT + value;
                } else if ("phase()".equals(key)) {
                    configPhase = ConfigPhase.valueOf(value);
                }
            }

            if (name.isEmpty()) {
                name = deriveConfigRootName(clazz.getSimpleName().toString(), configPhase);
            } else if (name.endsWith(Constants.DOT + Constants.PARENT)) {
                // take into account the root case which would contain characters that can't be used to create the final file
                name = name.replace(Constants.DOT + Constants.PARENT, "");
            }

            final Matcher pkgMatcher = Constants.PKG_PATTERN.matcher(pkg.toString());
            final String fileName;
            if (pkgMatcher.find()) {
                fileName = DocGeneratorUtil.computeExtensionDocFileName(clazz.toString());
            } else {
                fileName = name.replace(Constants.DOT, Constants.DASH.charAt(0)) + Constants.ADOC_EXTENSION;
            }

            ConfigRootInfo configRootInfo = new ConfigRootInfo(name, clazz, configPhase, fileName);
            configRoots.add(configRootInfo);
            break;
        }
    }
}
 
private String getCategory(final TypeElement e)
{
    Elements elementUtils = processingEnv.getElementUtils();
    TypeElement annotationElement = elementUtils.getTypeElement(MANAGED_OBJECT_CANONICAL_NAME);
    String category = null;
    List<? extends AnnotationMirror> annotationMirrors = e.getAnnotationMirrors();
    if(annotationMirrors != null)
    {
        for (AnnotationMirror a : annotationMirrors)
        {
            if (a.getAnnotationType().asElement().equals(annotationElement))
            {
                category = e.getSimpleName().toString().toLowerCase();

                for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : a.getElementValues()
                        .entrySet())
                {
                    if (entry.getKey().getSimpleName().toString().equals("category"))
                    {
                        if (!Boolean.TRUE.equals(entry.getValue().getValue()))
                        {
                            category = null;
                        }

                        break;
                    }
                }
                break;
            }
        }
    }

    if (category == null)
    {
        for (TypeMirror interfaceMirror : e.getInterfaces())
        {
            category = getCategory((TypeElement) processingEnv.getTypeUtils().asElement(interfaceMirror));
            if (category != null)
            {
                break;
            }
        }
    }

    if (category == null && e.getSuperclass() != null)
    {
        TypeElement parent = (TypeElement) processingEnv.getTypeUtils().asElement(e.getSuperclass());
        if(parent != null)
        {
            category = getCategory(parent);
        }
    }

    return category;

}