javax.lang.model.AnnotatedConstruct Java Examples
The following examples show how to use
javax.lang.model.AnnotatedConstruct.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TreeBackedAnnotationFactory.java From buck with Apache License 2.0 | 6 votes |
public static <A extends Annotation> A createOrGetUnderlying( TreeBackedAnnotatedConstruct annotatedConstruct, AnnotatedConstruct underlyingConstruct, Class<A> annotationType) { for (AnnotationMirror mirror : underlyingConstruct.getAnnotationMirrors()) { if (mirror.getAnnotationType().toString().equals(annotationType.getName())) return annotationType.cast( Proxy.newProxyInstance( annotationType.getClassLoader(), new Class[] {annotationType}, new Handler(annotatedConstruct, annotationType, mirror))); } // Either the annotation doesn't exist or name comparison failed in some weird way. // Either way, fall back to the underlying construct. return annotatedConstruct.getAnnotationWithBetterErrors(annotationType); }
Example #2
Source File: BasicAnnoTests.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example #3
Source File: Util.java From revapi with Apache License 2.0 | 5 votes |
/** * Constructs a human readable representation of the supplied element or type mirror. Note that in some cases * the representation might be "surprising". Especially for {@link ExecutableType} for which there is no way * of getting reliably at the method name or the type declaring the method. * * @param construct the element or type mirror to render * @return a human readable representation of the construct */ @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(); }
Example #4
Source File: ElementUtil.java From j2objc with Apache License 2.0 | 5 votes |
/** Similar to the above but matches against a pattern. */ public static boolean hasNamedAnnotation(AnnotatedConstruct ac, Pattern pattern) { for (AnnotationMirror annotation : getAllAnnotations(ac)) { if (pattern.matcher(getName(annotation.getAnnotationType().asElement())).matches()) { return true; } } return false; }
Example #5
Source File: ElementUtil.java From j2objc with Apache License 2.0 | 5 votes |
/** * Less strict version of the above where we don't care about the annotation's package. */ public static boolean hasNamedAnnotation(AnnotatedConstruct ac, String name) { for (AnnotationMirror annotation : getAllAnnotations(ac)) { if (getName(annotation.getAnnotationType().asElement()).equals(name)) { return true; } } return false; }
Example #6
Source File: BasicAnnoTests.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example #7
Source File: BasicAnnoTests.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example #8
Source File: BasicAnnoTests.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example #9
Source File: BasicAnnoTests.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example #10
Source File: JavacElements.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@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; }
Example #11
Source File: JsInteropAnnotationUtils.java From j2cl with Apache License 2.0 | 5 votes |
/** The namespace specified on a package, type, method or field. */ public static String getJsNamespace(AnnotatedConstruct typeBinding) { AnnotationMirror annotation = getJsTypeAnnotation(typeBinding); if (annotation == null) { annotation = getJsEnumAnnotation(typeBinding); } if (annotation == null) { annotation = getJsPackageAnnotation(typeBinding); } return getJsNamespace(annotation); }
Example #12
Source File: JsInteropAnnotationUtils.java From j2cl with Apache License 2.0 | 5 votes |
public static boolean isUnusableByJsSuppressed(AnnotatedConstruct binding) { AnnotationMirror suppressWarningsBinding = AnnotationUtils.findAnnotationBindingByName( binding.getAnnotationMirrors(), SUPPRESS_WARNINGS_ANNOTATION_NAME); if (suppressWarningsBinding == null) { return false; } List<?> suppressions = AnnotationUtils.getAnnotationParameterArray(suppressWarningsBinding, "value"); return suppressions.stream().map(Object::toString).anyMatch("\"unusable-by-js\""::equals); }
Example #13
Source File: BasicAnnoTests.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example #14
Source File: BasicAnnoTests.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example #15
Source File: JavacElements.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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; }
Example #16
Source File: BasicAnnoTests.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example #17
Source File: JsInteropAnnotationUtils.java From j2cl with Apache License 2.0 | 4 votes |
public static boolean hasCustomValue(AnnotatedConstruct typeBinding) { return hasCustomValue(getJsEnumAnnotation(typeBinding)); }
Example #18
Source File: TreeBackedAnnotatedConstruct.java From buck with Apache License 2.0 | 4 votes |
public TreeBackedAnnotatedConstruct(AnnotatedConstruct underlyingConstruct) { this.underlyingConstruct = underlyingConstruct; }
Example #19
Source File: ExternalAnnotations.java From j2objc with Apache License 2.0 | 4 votes |
public static List<GeneratedAnnotationMirror> get(AnnotatedConstruct construct) { return annotations.getOrDefault(construct, ImmutableList.of()); }
Example #20
Source File: ExternalAnnotations.java From j2objc with Apache License 2.0 | 4 votes |
public static void add(AnnotatedConstruct construct, GeneratedAnnotationMirror annotation) { annotations.computeIfAbsent(construct, k -> new ArrayList<>()).add(annotation); }
Example #21
Source File: ElementUtil.java From j2objc with Apache License 2.0 | 4 votes |
private static Iterable<? extends AnnotationMirror> getAllAnnotations(AnnotatedConstruct ac) { return Iterables.concat(ac.getAnnotationMirrors(), ExternalAnnotations.get(ac)); }
Example #22
Source File: ExternalAnnotationInjector.java From j2objc with Apache License 2.0 | 4 votes |
private void recordAnnotations(AnnotatedConstruct construct, Set<Annotation> annotations) { for (Annotation annotation : annotations) { ExternalAnnotations.add(construct, generateAnnotationMirror(annotation)); } }
Example #23
Source File: AnnotationUtils.java From j2cl with Apache License 2.0 | 4 votes |
/** Returns true if the construct is annotated with {@code annotationSourceName}. */ static boolean hasAnnotation(AnnotatedConstruct construct, String annotationSourceName) { return findAnnotationBindingByName(construct.getAnnotationMirrors(), annotationSourceName) != null; }
Example #24
Source File: JsInteropUtils.java From j2cl with Apache License 2.0 | 4 votes |
public static boolean isJsAsync(AnnotatedConstruct method) { return JsInteropAnnotationUtils.getJsAsyncAnnotation(method) != null; }
Example #25
Source File: JsInteropUtils.java From j2cl with Apache License 2.0 | 4 votes |
public static boolean isJsOverlay(AnnotatedConstruct method) { return JsInteropAnnotationUtils.getJsOverlayAnnotation(method) != null; }
Example #26
Source File: JsInteropUtils.java From j2cl with Apache License 2.0 | 4 votes |
public static boolean isJsType(AnnotatedConstruct type) { return JsInteropAnnotationUtils.getJsTypeAnnotation(type) != null; }
Example #27
Source File: JavaEnvironment.java From j2cl with Apache License 2.0 | 4 votes |
private static boolean isDeprecated(AnnotatedConstruct binding) { return AnnotationUtils.hasAnnotation(binding, Deprecated.class.getName()); }
Example #28
Source File: JsInteropUtils.java From j2cl with Apache License 2.0 | 4 votes |
public static boolean isJsFunction(AnnotatedConstruct type) { return JsInteropAnnotationUtils.getJsFunctionAnnotation(type) != null; }
Example #29
Source File: JsInteropAnnotationUtils.java From j2cl with Apache License 2.0 | 4 votes |
public static AnnotationMirror getJsPackageAnnotation(AnnotatedConstruct methodBinding) { return AnnotationUtils.findAnnotationBindingByName( methodBinding.getAnnotationMirrors(), JS_PACKAGE_ANNOTATION_NAME); }
Example #30
Source File: JsInteropAnnotationUtils.java From j2cl with Apache License 2.0 | 4 votes |
public static AnnotationMirror getJsAsyncAnnotation(AnnotatedConstruct methodBinding) { return AnnotationUtils.findAnnotationBindingByName( methodBinding.getAnnotationMirrors(), JS_ASYNC_ANNOTATION_NAME); }