本文整理汇总了Java中javax.lang.model.AnnotatedConstruct类的典型用法代码示例。如果您正苦于以下问题:Java AnnotatedConstruct类的具体用法?Java AnnotatedConstruct怎么用?Java AnnotatedConstruct使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AnnotatedConstruct类属于javax.lang.model包,在下文中一共展示了AnnotatedConstruct类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copyDocumentedAnnotations
import javax.lang.model.AnnotatedConstruct; //导入依赖的package包/类
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 ) );
}
}
}
示例2: getOrigin
import javax.lang.model.AnnotatedConstruct; //导入依赖的package包/类
@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;
}
示例3: getAnnotation
import javax.lang.model.AnnotatedConstruct; //导入依赖的package包/类
/**
* 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;
}
示例4: copyDocumentedAnnotations
import javax.lang.model.AnnotatedConstruct; //导入依赖的package包/类
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 ) );
}
}
}
示例5: of
import javax.lang.model.AnnotatedConstruct; //导入依赖的package包/类
/** 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;
}
示例6: toHumanReadableString
import javax.lang.model.AnnotatedConstruct; //导入依赖的package包/类
@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();
}
示例7: annotate
import javax.lang.model.AnnotatedConstruct; //导入依赖的package包/类
static <A extends Annotatable> A annotate(A target, AnnotatedConstruct source) {
source.getAnnotationMirrors().forEach(m -> target.addAnnotation(of(m)));
return target;
}
示例8: withAnnotation
import javax.lang.model.AnnotatedConstruct; //导入依赖的package包/类
public static <T extends AnnotatedConstruct> Predicate<T> withAnnotation(Class<? extends Annotation> cls) {
return annotated->annotated.getAnnotation(cls) != null;
}
示例9: TreeBackedAnnotatedConstruct
import javax.lang.model.AnnotatedConstruct; //导入依赖的package包/类
public TreeBackedAnnotatedConstruct(AnnotatedConstruct underlyingConstruct) {
this.underlyingConstruct = underlyingConstruct;
}
示例10: getOrigin
import javax.lang.model.AnnotatedConstruct; //导入依赖的package包/类
/**
* 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;
}