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

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

源代码1 项目: doma   文件: DaoMetaFactory.java
private void validateMethod(TypeElement interfaceElement, ExecutableElement methodElement) {
  TypeElement foundAnnotationTypeElement = null;
  for (AnnotationMirror annotation : methodElement.getAnnotationMirrors()) {
    DeclaredType declaredType = annotation.getAnnotationType();
    TypeElement typeElement = ctx.getMoreTypes().toTypeElement(declaredType);
    if (typeElement.getAnnotation(DaoMethod.class) != null) {
      if (foundAnnotationTypeElement != null) {
        throw new AptException(
            Message.DOMA4087,
            methodElement,
            new Object[] {
              foundAnnotationTypeElement.getQualifiedName(), typeElement.getQualifiedName()
            });
      }
      if (methodElement.isDefault()
          || ctx.getMoreElements().isVirtualDefaultMethod(interfaceElement, methodElement)) {
        throw new AptException(
            Message.DOMA4252, methodElement, new Object[] {typeElement.getQualifiedName()});
      }
      foundAnnotationTypeElement = typeElement;
    }
  }
}
 
源代码2 项目: netbeans   文件: TooStrongCast.java
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;
}
 
源代码3 项目: netbeans   文件: JavaSourceHelper.java
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;
    }
 
源代码4 项目: netbeans   文件: AddWsOperationHelper.java
private boolean checkMethodAnnotation( TypeElement element, 
        Element annotationElement ) 
{
    List<ExecutableElement> methods = ElementFilter.methodsIn( 
            element.getEnclosedElements() );
    if ( methods.size() == 0 ){
        return true;
    }
    for (ExecutableElement method : methods) {
        // ignore constructors
        if ( method.getKind() == ElementKind.METHOD ){
            List<? extends AnnotationMirror> annotationMirrors = 
                method.getAnnotationMirrors();
            for (AnnotationMirror annotationMirror : annotationMirrors) {
                DeclaredType annotationType = 
                    annotationMirror.getAnnotationType();
                Element annotation = annotationType.asElement();
                if ( annotationElement.equals( annotation )){
                    return true;
                }
            }
        }
    }
    return false;
}
 
源代码5 项目: netbeans   文件: JavaSourceHelper.java
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, RestConstants.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;
}
 
源代码6 项目: Fourinone   文件: DelegateProcessor.java
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for(TypeElement te:annotations){
          note("annotation:"+te.toString());
      }
      
      Set<? extends Element> elements = roundEnv.getRootElements();
      for(Element e:elements){
	List enclosedElems = e.getEnclosedElements();
	List<ExecutableElement> ees = ElementFilter.methodsIn(enclosedElems);
          for(ExecutableElement ee:ees){
		note("--ExecutableElement name is "+ee.getSimpleName());
              List<? extends AnnotationMirror> as = ee.getAnnotationMirrors();
		note("--as="+as);
              for(AnnotationMirror am:as){
			Map map= am.getElementValues();
			Set<ExecutableElement> ks = map.keySet();
                  for(ExecutableElement k:ks){
                      AnnotationValue av = (AnnotationValue)map.get(k);
                      note("----"+ee.getSimpleName()+"."+k.getSimpleName()+"="+av.getValue());
                  }
              }
          }
      }
      return false;
  }
 
源代码7 项目: litho   文件: WorkingRangesMethodExtractor.java
@Nullable
private static SpecMethodModel<EventMethod, WorkingRangeDeclarationModel>
    generateWorkingRangeMethod(
        Elements elements,
        ExecutableElement executableElement,
        List<Class<? extends Annotation>> permittedInterStageInputAnnotations,
        Messager messager,
        Class<? extends Annotation> annotationType) {
  final List<MethodParamModel> methodParams =
      getMethodParams(
          executableElement,
          messager,
          getPermittedMethodParamAnnotations(permittedInterStageInputAnnotations),
          permittedInterStageInputAnnotations,
          ImmutableList.of());

  final String nameInAnnotation =
      ProcessorUtils.getAnnotationParameter(
          elements, executableElement, annotationType, "name", String.class);

  List<? extends AnnotationMirror> annotationMirrors = executableElement.getAnnotationMirrors();
  AnnotationMirror mirror = null;
  for (AnnotationMirror m : annotationMirrors) {
    if (m.getAnnotationType().toString().equals(annotationType.getCanonicalName())) {
      mirror = m;
      break;
    }
  }

  return SpecMethodModel.<EventMethod, WorkingRangeDeclarationModel>builder()
      .annotations(ImmutableList.of())
      .modifiers(ImmutableList.copyOf(new ArrayList<>(executableElement.getModifiers())))
      .name(executableElement.getSimpleName())
      .returnTypeSpec(generateTypeSpec(executableElement.getReturnType()))
      .typeVariables(ImmutableList.copyOf(getTypeVariables(executableElement)))
      .methodParams(ImmutableList.copyOf(methodParams))
      .representedObject(executableElement)
      .typeModel(new WorkingRangeDeclarationModel(nameInAnnotation, mirror))
      .build();
}
 
源代码8 项目: netbeans   文件: MethodVisitor.java
/**
 *  Determines if the method has a WebMethod annotation and if it does
 *  that the exclude attribute is not set
 */
private boolean hasWebMethodAnnotation(ExecutableElement method){
    boolean isWebMethod = false;
    List<? extends AnnotationMirror> methodAnnotations = method.getAnnotationMirrors();
    for (AnnotationMirror anMirror : methodAnnotations) {
        if (JaxWsUtils.hasFqn(anMirror, "javax.jws.WebMethod")) {       // NOI18N
            //WebMethod found, set boolean to true
            isWebMethod = true;
            //Now determine if "exclude" is present and set to true
            Map<? extends ExecutableElement, 
                    ? extends AnnotationValue> expressions = anMirror.
                        getElementValues();
            for(Entry<? extends ExecutableElement, 
                    ? extends AnnotationValue> entry: expressions.entrySet()) 
            {
                if (entry.getKey().getSimpleName().contentEquals("exclude")) { //NOI18N
                    String value = (String)expressions.get(entry.getKey()).
                        getValue();
                    if ("true".equals(value)){
                        isWebMethod = false;
                        break;
                    }
                }
            }
        }
        break;
    }
    return isWebMethod;
}
 
源代码9 项目: netbeans   文件: MethodVisitor.java
/**
 *  Determines if the WSDL operation is the corresponding Java method
 */
private boolean isMethodFor(ExecutableElement method, String operationName){
    if(method.getSimpleName().toString().equals(operationName)){
        return true;
    }
    
    //if method name is not the same as the operation name, look at WebMethod annotation
    List<? extends AnnotationMirror> methodAnnotations = 
            method.getAnnotationMirrors();
    for (AnnotationMirror anMirror : methodAnnotations) {
        if (JaxWsUtils.hasFqn(anMirror, "javax.jws.WebMethod")) {   // NOI18N
            Map<? extends ExecutableElement, 
                    ? extends AnnotationValue> expressions = 
                            anMirror.getElementValues();
            for(Entry<? extends ExecutableElement, 
                    ? extends AnnotationValue> entry: expressions.entrySet()) 
            {
                if (entry.getKey().getSimpleName().
                        contentEquals("operationName"))  //NOI18N
                {
                    String name = (String)expressions.get(entry.getKey()).
                        getValue();
                    if (operationName.equals(name)){
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
 
源代码10 项目: netbeans   文件: AddWsOperationHelper.java
private String findNewOperationName(TypeElement classEl, CompilationController controller, String suggestedMethodName) 
    throws IOException {
    
    TypeElement methodElement = controller.getElements().getTypeElement("javax.jws.WebMethod"); //NOI18N
    Set<String> operationNames = new HashSet<String>();
    if (methodElement != null) {
        List<ExecutableElement> methods = getMethods(controller,classEl);
        for (ExecutableElement m:methods) {
            String opName = null;
            List<? extends AnnotationMirror> annotations = m.getAnnotationMirrors();
            for (AnnotationMirror anMirror : annotations) {
                if (controller.getTypes().isSameType(methodElement.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("operationName")) { //NOI18N
                            opName = (String) expressions.get(entry.getKey()).getValue();
                            break;
                        }
                    }
                } // end if
                if (opName != null) break;
            } //enfd for
            if (opName == null) opName = m.getSimpleName().toString();
            operationNames.add(opName);
        }
    }
    return findNewOperationName(operationNames, suggestedMethodName);
}
 
源代码11 项目: netbeans   文件: AsynchronousMethodInvocation.java
private static boolean isAsynchronousAnnotated(ExecutableElement method) {
    boolean knownClasses = HintsUtils.isContainingKnownClasses(method);
    for (AnnotationMirror am : method.getAnnotationMirrors()) {
        if (EJBAPIAnnotations.ASYNCHRONOUS.equals(am.getAnnotationType().asElement().toString()) && knownClasses) {
            return true;
        }
    }
    return false;
}
 
源代码12 项目: auto-matter   文件: AutoMatterProcessor.java
private AnnotationMirror nullableAnnotation(final ExecutableElement field) {
  for (AnnotationMirror annotation : field.getAnnotationMirrors()) {
    if (annotation.getAnnotationType().asElement().getSimpleName().contentEquals("Nullable")) {
      return annotation;
    }
  }
  return null;
}
 
private void processAutowiredConstructor(ExecutableElement constructor) {
  List<? extends AnnotationMirror> annotations = constructor.getAnnotationMirrors();
  for (AnnotationMirror annotationMirror : annotations) {

    Element annotationTypeElement = annotationMirror.getAnnotationType().asElement();
    if (annotationTypeElement.equals(this.autowiredTypeElement)) {
      printMessage(SpringConfigurationMessage.AUTOWIRED_CONSTRUCTOR, constructor, annotationMirror);
    }
  }
}
 
源代码14 项目: sundrio   文件: ElementTo.java
public Method apply(ExecutableElement executableElement) {
    Map<AttributeKey, Object> attributes = new HashMap<>();
    if (executableElement.getDefaultValue() != null) {
       attributes.put(Attributeable.DEFAULT_VALUE, executableElement.getDefaultValue().getValue());
    }
    MethodBuilder methodBuilder = new MethodBuilder()
            .withModifiers(TypeUtils.modifiersToInt(executableElement.getModifiers()))
            .withName(executableElement.getSimpleName().toString())
            .withReturnType(MIRROR_TO_TYPEREF.apply(executableElement.getReturnType()))
            .withAttributes(attributes);



    //Populate constructor parameters
    for (VariableElement variableElement : executableElement.getParameters()) {
        methodBuilder = methodBuilder.addToArguments(PROPERTY.apply(variableElement));

        List<ClassRef> exceptionRefs = new ArrayList<ClassRef>();
        for (TypeMirror thrownType : executableElement.getThrownTypes()) {
            if (thrownType instanceof ClassRef) {
                exceptionRefs.add((ClassRef) thrownType);
            }
        }
        methodBuilder = methodBuilder.withExceptions(exceptionRefs);
    }

    List<ClassRef> annotationRefs = new ArrayList<ClassRef>();
    for (AnnotationMirror annotationMirror : executableElement.getAnnotationMirrors()) {
        methodBuilder.withAnnotations(ANNOTATION_REF.apply(annotationMirror));
    }
    return methodBuilder.build();
}
 
private AnnotationMirror getAnnotationMirror(final ExecutableElement methodElement, final String annotationClassName)
{
    for (AnnotationMirror annotationMirror : methodElement.getAnnotationMirrors())
    {
        Element annotationAsElement = annotationMirror.getAnnotationType().asElement();
        if (annotationClassName.equals(getFullyQualifiedName(annotationAsElement)))
        {
            return annotationMirror;
        }
    }
    return null;
}
 
源代码16 项目: auto-value-with   文件: WithMethod.java
private WithMethod(ExecutableElement method, List<Property> properties,
        List<String> methodPropertyNames) {
    this.methodName = method.getSimpleName().toString();
    this.methodModifiers = method.getModifiers();
    this.methodAnnotations = method.getAnnotationMirrors();
    this.properties = properties;
    this.propertyNames = methodPropertyNames;
}
 
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);
}
 
源代码18 项目: FreeBuilder   文件: JacksonSupport.java
private static GenerateAnnotation generateDefaultAnnotations(ExecutableElement getterMethod) {
  for (AnnotationMirror annotationMirror : getterMethod.getAnnotationMirrors()) {
    TypeElement annotationTypeElement =
        (TypeElement) (annotationMirror.getAnnotationType().asElement());
    QualifiedName annotationType = QualifiedName.of(annotationTypeElement);
    if (DISABLE_PROPERTY_ANNOTATIONS.contains(annotationType)) {
      return GenerateAnnotation.NONE;
    }
    if (JSON_ANY_GETTER.equals(annotationType)) {
      return GenerateAnnotation.JSON_ANY;
    }
  }
  return GenerateAnnotation.DEFAULT;
}
 
源代码19 项目: dagger2-sample   文件: MethodSignatureFormatter.java
/**
 * Formats an ExecutableElement as if it were contained within the container, if the container is
 * present.
 */
public String format(ExecutableElement method, Optional<DeclaredType> container) {
  StringBuilder builder = new StringBuilder();
  TypeElement type = MoreElements.asType(method.getEnclosingElement());
  ExecutableType executableType = MoreTypes.asExecutable(method.asType());
  if (container.isPresent()) {
    executableType = MoreTypes.asExecutable(types.asMemberOf(container.get(), method));
    type = MoreElements.asType(container.get().asElement());
  }

  // TODO(cgruber): AnnotationMirror formatter.
  List<? extends AnnotationMirror> annotations = method.getAnnotationMirrors();
  if (!annotations.isEmpty()) {
    Iterator<? extends AnnotationMirror> annotationIterator = annotations.iterator();
    for (int i = 0; annotationIterator.hasNext(); i++) {
      if (i > 0) {
        builder.append(' ');
      }
      builder.append(ErrorMessages.format(annotationIterator.next()));
    }
    builder.append(' ');
  }
  builder.append(nameOfType(executableType.getReturnType()));
  builder.append(' ');
  builder.append(type.getQualifiedName());
  builder.append('.');
  builder.append(method.getSimpleName());
  builder.append('(');
  checkState(method.getParameters().size() == executableType.getParameterTypes().size());
  Iterator<? extends VariableElement> parameters = method.getParameters().iterator();
  Iterator<? extends TypeMirror> parameterTypes = executableType.getParameterTypes().iterator();
  for (int i = 0; parameters.hasNext(); i++) {
    if (i > 0) {
      builder.append(", ");
    }
    appendParameter(builder, parameters.next(), parameterTypes.next());
  }
  builder.append(')');
  return builder.toString();
}
 
源代码20 项目: netbeans   文件: AddWsOperationHelper.java
private String findNewOperationName(TypeElement classEl, 
        CompilationController controller, String suggestedMethodName) 
        throws IOException 
{
    
    TypeElement methodElement = controller.getElements().
        getTypeElement("javax.jws.WebMethod"); //NOI18N
    if ( methodElement == null ){
        isIncomplete = true;
    }
    Set<String> operationNames = new HashSet<String>();
    List<ExecutableElement> methods = getMethods(controller, classEl);
    for (ExecutableElement m : methods) {
        String opName = null;
        List<? extends AnnotationMirror> annotations = m
                .getAnnotationMirrors();
        for (AnnotationMirror anMirror : annotations) {
            if ( methodElement!= null && 
                    controller.getTypes().isSameType(methodElement.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("operationName")) // NOI18N
                    {
                        opName = (String) expressions.get(entry.getKey()).getValue();
                        break;
                    }
                }
            } // end if
            if (opName != null)
                break;
        } // enfd for
        if (opName == null) {
            opName = m.getSimpleName().toString();
        }
        operationNames.add(opName);
    }
    return findNewOperationName(operationNames, suggestedMethodName);
}