javax.lang.model.element.Element.getAnnotation()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(231)

本文整理了Java中javax.lang.model.element.Element.getAnnotation()方法的一些代码示例,展示了Element.getAnnotation()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.getAnnotation()方法的具体详情如下:
包路径:javax.lang.model.element.Element
类名称:Element
方法名:getAnnotation

Element.getAnnotation介绍

暂无

代码示例

代码示例来源:origin: androidannotations/androidannotations

public boolean hasOneOfClassAnnotations(Element element, List<Class<? extends Annotation>> validAnnotations) {
    for (Class<? extends Annotation> validAnnotation : validAnnotations) {
      if (element.getAnnotation(validAnnotation) != null) {
        return true;
      }
    }
    return false;
  }
}

代码示例来源:origin: bumptech/glide

List<ExecutableElement> findAnnotatedElementsInClasses(
  Set<String> classNames, Class<? extends Annotation> annotationClass) {
 List<ExecutableElement> result = new ArrayList<>();
 for (String glideExtensionClassName : classNames) {
  TypeElement glideExtension = processingEnv.getElementUtils()
    .getTypeElement(glideExtensionClassName);
  for (Element element : glideExtension.getEnclosedElements()) {
   if (element.getAnnotation(annotationClass) != null) {
    result.add((ExecutableElement) element);
   }
  }
 }
 return result;
}

代码示例来源:origin: androidannotations/androidannotations

@Override
protected String getUrlSuffix(Element element) {
  Options annotation = element.getAnnotation(Options.class);
  return annotation.value();
}

代码示例来源:origin: androidannotations/androidannotations

@Override
  protected String getUrlSuffix(Element element) {
    Put annotation = element.getAnnotation(Put.class);
    return annotation.value();
  }
}

代码示例来源:origin: androidannotations/androidannotations

@Override
  protected String getUrlSuffix(Element element) {
    Get annotation = element.getAnnotation(Get.class);
    return annotation.value();
  }
}

代码示例来源:origin: androidannotations/androidannotations

public boolean requiredAuthentication(ExecutableElement executableElement) {
  RequiresAuthentication basicAuthAnnotation = executableElement.getAnnotation(RequiresAuthentication.class);
  if (basicAuthAnnotation == null) {
    basicAuthAnnotation = executableElement.getEnclosingElement().getAnnotation(RequiresAuthentication.class);
  }
  return basicAuthAnnotation != null;
}

代码示例来源:origin: androidannotations/androidannotations

@Override
  protected String getUrlSuffix(Element element) {
    Post annotation = element.getAnnotation(Post.class);
    return annotation.value();
  }
}

代码示例来源:origin: androidannotations/androidannotations

private String extractTag(Element element) {
    WakeLock annotation = element.getAnnotation(WakeLock.class);
    String tag = annotation.tag();
    if (WakeLock.DEFAULT_TAG.equals(tag)) {
      tag = element.getEnclosingElement().getSimpleName().toString() + "." + element.getSimpleName().toString();
    }
    return tag;
  }
}

代码示例来源:origin: androidannotations/androidannotations

private String extractTag(Element element) {
    Trace annotation = element.getAnnotation(Trace.class);
    String tag = annotation.tag();
    if (Trace.DEFAULT_TAG.equals(tag)) {
      tag = element.getEnclosingElement().getSimpleName().toString();
    }
    return trimLogTag(tag);
  }
}

代码示例来源:origin: androidannotations/androidannotations

public void hasValidLogLevel(Element element, ElementValidation valid) {
  Trace annotation = element.getAnnotation(Trace.class);
  Integer level = annotation.level();
  if (!VALID_LOG_LEVELS.contains(level)) {
    valid.addError("Unrecognized log level.");
  }
}

代码示例来源:origin: androidannotations/androidannotations

public String acceptedHeaders(ExecutableElement executableElement) {
  Accept acceptAnnotation = executableElement.getAnnotation(Accept.class);
  if (acceptAnnotation == null) {
    acceptAnnotation = executableElement.getEnclosingElement().getAnnotation(Accept.class);
  }
  if (acceptAnnotation != null) {
    return acceptAnnotation.value();
  } else {
    return null;
  }
}

代码示例来源:origin: androidannotations/androidannotations

public String[] requiredCookies(ExecutableElement executableElement) {
  RequiresCookie cookieAnnotation = executableElement.getAnnotation(RequiresCookie.class);
  if (cookieAnnotation == null) {
    cookieAnnotation = executableElement.getEnclosingElement().getAnnotation(RequiresCookie.class);
  }
  if (cookieAnnotation != null) {
    return cookieAnnotation.value();
  } else {
    return null;
  }
}

代码示例来源:origin: androidannotations/androidannotations

public String[] requiredUrlCookies(ExecutableElement executableElement) {
  RequiresCookieInUrl cookieAnnotation = executableElement.getAnnotation(RequiresCookieInUrl.class);
  if (cookieAnnotation == null) {
    cookieAnnotation = executableElement.getEnclosingElement().getAnnotation(RequiresCookieInUrl.class);
  }
  if (cookieAnnotation != null) {
    return cookieAnnotation.value();
  } else {
    return null;
  }
}

代码示例来源:origin: androidannotations/androidannotations

public String[] settingCookies(ExecutableElement executableElement) {
  SetsCookie cookieAnnotation = executableElement.getAnnotation(SetsCookie.class);
  if (cookieAnnotation == null) {
    cookieAnnotation = executableElement.getEnclosingElement().getAnnotation(SetsCookie.class);
  }
  if (cookieAnnotation != null) {
    return cookieAnnotation.value();
  } else {
    return null;
  }
}

代码示例来源:origin: androidannotations/androidannotations

@Override
  protected IJExpression getFragmentId(Element element, String fieldName) {
    FragmentByTag annotation = element.getAnnotation(FragmentByTag.class);
    String tagValue = annotation.value();
    if (tagValue.equals("")) {
      tagValue = fieldName;
    }
    return lit(tagValue);
  }
}

代码示例来源:origin: androidannotations/androidannotations

public void elementHasAnnotation(Class<? extends Annotation> annotation, Element element, ElementValidation valid, String error) {
  if (!elementHasAnnotation(annotation, element)) {
    if (element.getAnnotation(annotation) == null) {
      valid.addError("%s " + error + " @" + annotation.getName());
    }
  }
}

代码示例来源:origin: bumptech/glide

@SuppressWarnings("unchecked")
private FoundIndexedClassNames getIndexedClassNames(PackageElement glideGenPackage) {
 Set<String> glideModules = new HashSet<>();
 Set<String> extensions = new HashSet<>();
 List<? extends Element> glideGeneratedElements = glideGenPackage.getEnclosedElements();
 for (Element indexer : glideGeneratedElements) {
  Index annotation = indexer.getAnnotation(Index.class);
  // If the annotation is null, it means we've come across another class in the same package
  // that we can safely ignore.
  if (annotation != null) {
   Collections.addAll(glideModules, annotation.modules());
   Collections.addAll(extensions, annotation.extensions());
  }
 }
 processorUtil.debugLog("Found GlideModules: " + glideModules);
 return new FoundIndexedClassNames(glideModules, extensions);
}

代码示例来源:origin: androidannotations/androidannotations

public void copyNonAAAnnotations(IJAnnotatable annotatable, List<? extends AnnotationMirror> annotationMirrors) {
  for (AnnotationMirror annotationMirror : annotationMirrors) {
    if (annotationMirror.getAnnotationType().asElement().getAnnotation(Inherited.class) == null) {
      AbstractJClass annotationClass = typeMirrorToJClass(annotationMirror.getAnnotationType());
      if (!environment.isAndroidAnnotation(annotationClass.fullName()) && !IGNORED_ANNOTATIONS.contains(annotationClass.fullName())) {
        copyAnnotation(annotatable, annotationMirror);
      }
    }
  }
}

代码示例来源:origin: androidannotations/androidannotations

public JInvocation newBeanOrEBean(DeclaredType beanType, JVar contextVar) {
  if (beanType.asElement().getAnnotation(EBean.class) != null) {
    String typeQualifiedName = beanType.toString();
    AbstractJClass injectedClass = environment.getJClass(typeQualifiedName + classSuffix());
    return injectedClass.staticInvoke(EBeanHolder.GET_INSTANCE_METHOD_NAME).arg(contextVar);
  } else {
    return _new(environment.getJClass(beanType.toString()));
  }
}

代码示例来源:origin: androidannotations/androidannotations

@Override
  public void process(Element element, EBeanHolder holder) {
    EBean eBeanAnnotation = element.getAnnotation(EBean.class);
    EBean.Scope eBeanScope = eBeanAnnotation.scope();
    boolean hasSingletonScope = eBeanScope == EBean.Scope.Singleton;

    holder.createFactoryMethod(hasSingletonScope);

    if (!hasSingletonScope) {
      holder.invokeInitInConstructor();
      holder.createRebindMethod();
    }
  }
}

相关文章