Java 类javax.lang.model.AnnotatedConstruct 实例源码

项目: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 ) );
    }
  }
}
项目:react4j    文件:ProcessorUtil.java   
static void copyDocumentedAnnotations( @Nonnull final AnnotatedConstruct element,
                                       @Nonnull final ParameterSpec.Builder builder )
{
  for ( final AnnotationMirror annotation : element.getAnnotationMirrors() )
  {
    if ( null != annotation.getAnnotationType().asElement().getAnnotation( Documented.class ) )
    {
      builder.addAnnotation( AnnotationSpec.get( annotation ) );
    }
  }
}
项目:openjdk-jdk10    文件:JavacElements.java   
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public Origin getOrigin(AnnotatedConstruct c, AnnotationMirror a) {
    Compound ac = cast(Compound.class, a);
    if (ac.isSynthesized())
        return Origin.MANDATED;
    return Origin.EXPLICIT;
}
项目:openjdk-jdk10    文件:BasicAnnoTests.java   
/**
 * Get a specific annotation mirror from an annotated construct.
 */
static AnnotationMirror getAnnotation(AnnotatedConstruct e, String name) {
    for (AnnotationMirror m: e.getAnnotationMirrors()) {
        TypeElement te = (TypeElement) m.getAnnotationType().asElement();
        if (te.getQualifiedName().contentEquals(name)) {
            return m;
        }
    }
    return null;
}
项目:arez    文件: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( "arez.annotations." ) &&
         null != annotationType.asElement().getAnnotation( Documented.class ) )
    {
      builder.addAnnotation( AnnotationSpec.get( annotation ) );
    }
  }
}
项目:arez    文件:ProcessorUtil.java   
static void copyDocumentedAnnotations( @Nonnull final AnnotatedConstruct element,
                                       @Nonnull final ParameterSpec.Builder builder )
{
  for ( final AnnotationMirror annotation : element.getAnnotationMirrors() )
  {
    if ( null != annotation.getAnnotationType().asElement().getAnnotation( Documented.class ) )
    {
      builder.addAnnotation( AnnotationSpec.get( annotation ) );
    }
  }
}
项目:openjdk9    文件:BasicAnnoTests.java   
/**
 * Get a specific annotation mirror from an annotated construct.
 */
static AnnotationMirror getAnnotation(AnnotatedConstruct e, String name) {
    for (AnnotationMirror m: e.getAnnotationMirrors()) {
        TypeElement te = (TypeElement) m.getAnnotationType().asElement();
        if (te.getQualifiedName().contentEquals(name)) {
            return m;
        }
    }
    return null;
}
项目:listing    文件:JavaMirrors.java   
/** Create {@link ClassType} based on {@link javax.lang.model.type.DeclaredType} instance. */
static ClassType of(javax.lang.model.type.DeclaredType type) {
  ClassType classType = new ClassType();
  // extract package name
  Element packageElement = type.asElement();
  while (packageElement.getKind() != ElementKind.PACKAGE) {
    packageElement = packageElement.getEnclosingElement();
  }
  PackageElement casted = (PackageElement) packageElement;
  classType.setPackageName(casted.getQualifiedName().toString());
  // extract simple names and type arguments
  TypeMirror actualType = type;
  for (Element element = type.asElement();
      element.getKind().isClass() || element.getKind().isInterface();
      element = element.getEnclosingElement()) {
    ClassName name = new ClassName(); // annotate(new ClassName(), element); // element.asType());
    name.setName(element.getSimpleName().toString());
    classType.getNames().add(0, name);
    if ((actualType instanceof javax.lang.model.type.DeclaredType)) {
      javax.lang.model.type.DeclaredType dt = (javax.lang.model.type.DeclaredType) actualType;
      annotate(name, dt);
      for (TypeMirror ta : dt.getTypeArguments()) {
        AnnotatedConstruct annotatedConstruct = ta;
        if (ta instanceof javax.lang.model.type.DeclaredType) {
          annotatedConstruct = ((javax.lang.model.type.DeclaredType) ta).asElement();
        }
        JavaType javaType = annotate(JavaMirrors.of(ta), annotatedConstruct);
        name.getTypeArguments().add(TypeArgument.of(javaType));
      }
      actualType = dt.getEnclosingType();
    }
  }
  return classType;
}
项目:lookaside_java-1.8.0-openjdk    文件:BasicAnnoTests.java   
/**
 * Get a specific annotation mirror from an annotated construct.
 */
static AnnotationMirror getAnnotation(AnnotatedConstruct e, String name) {
    for (AnnotationMirror m: e.getAnnotationMirrors()) {
        TypeElement te = (TypeElement) m.getAnnotationType().asElement();
        if (te.getQualifiedName().contentEquals(name)) {
            return m;
        }
    }
    return null;
}
项目:jsr308-langtools    文件:BasicAnnoTests.java   
/**
 * Get a specific annotation mirror from an annotated construct.
 */
static AnnotationMirror getAnnotation(AnnotatedConstruct e, String name) {
    for (AnnotationMirror m: e.getAnnotationMirrors()) {
        TypeElement te = (TypeElement) m.getAnnotationType().asElement();
        if (te.getQualifiedName().contentEquals(name)) {
            return m;
        }
    }
    return null;
}
项目:infobip-open-jdk-8    文件:BasicAnnoTests.java   
/**
 * Get a specific annotation mirror from an annotated construct.
 */
static AnnotationMirror getAnnotation(AnnotatedConstruct e, String name) {
    for (AnnotationMirror m: e.getAnnotationMirrors()) {
        TypeElement te = (TypeElement) m.getAnnotationType().asElement();
        if (te.getQualifiedName().contentEquals(name)) {
            return m;
        }
    }
    return null;
}
项目:OLD-OpenJDK8    文件:BasicAnnoTests.java   
/**
 * Get a specific annotation mirror from an annotated construct.
 */
static AnnotationMirror getAnnotation(AnnotatedConstruct e, String name) {
    for (AnnotationMirror m: e.getAnnotationMirrors()) {
        TypeElement te = (TypeElement) m.getAnnotationType().asElement();
        if (te.getQualifiedName().contentEquals(name)) {
            return m;
        }
    }
    return null;
}
项目:revapi    文件:Util.java   
@Nonnull
public static String toHumanReadableString(@Nonnull AnnotatedConstruct construct) {
    StringBuilderAndState<TypeMirror> state = new StringBuilderAndState<>();

    if (construct instanceof Element) {
        ((Element) construct).accept(toHumanReadableStringElementVisitor, state);
    } else if (construct instanceof TypeMirror) {
        ((TypeMirror) construct).accept(toHumanReadableStringVisitor, state);
    }
    return state.bld.toString();
}
项目:listing    文件:JavaMirrors.java   
static <A extends Annotatable> A annotate(A target, AnnotatedConstruct source) {
  source.getAnnotationMirrors().forEach(m -> target.addAnnotation(of(m)));
  return target;
}
项目:xapi    文件:ElementUtil.java   
public static <T extends AnnotatedConstruct> Predicate<T> withAnnotation(Class<? extends Annotation> cls) {
  return annotated->annotated.getAnnotation(cls) != null;
}
项目:buck    文件:TreeBackedAnnotatedConstruct.java   
public TreeBackedAnnotatedConstruct(AnnotatedConstruct underlyingConstruct) {
  this.underlyingConstruct = underlyingConstruct;
}
项目:openjdk-jdk10    文件:Elements.java   
/**
 * Returns the <em>origin</em> of the given annotation mirror.
 *
 * An annotation mirror is {@linkplain Origin#MANDATED mandated}
 * if it is an implicitly declared <em>container annotation</em>
 * used to hold repeated annotations of a repeatable annotation
 * type.
 *
 * <p>Note that if this method returns {@link Origin#EXPLICIT
 * EXPLICIT} and the annotation mirror was created from a class
 * file, then the element may not, in fact, correspond to an
 * explicitly declared construct in source code. This is due to
 * limitations of the fidelity of the class file format in
 * preserving information from source code. For example, at least
 * some versions of the class file format do not preserve whether
 * an annotation was explicitly declared by the programmer or was
 * implicitly declared as a <em>container annotation</em>.
 *
 * @implSpec The default implementation of this method returns
 * {@link Origin#EXPLICIT EXPLICIT}.
 *
 * @param c the construct the annotation mirror modifies
 * @param a the annotation mirror being examined
 * @return the origin of the given annotation mirror
 * @jls 9.6.3 Repeatable Annotation Types
 * @jls 9.7.5 Multiple Annotations of the Same Type
 * @since 9
 */
default Origin getOrigin(AnnotatedConstruct c,
                         AnnotationMirror a) {
    return Origin.EXPLICIT;
}