protected void recordAnnotationExpressions(JvmAnnotationTarget annotable) { List<JvmAnnotationReference> annotations = annotable.getAnnotations(); recordAnnotationExpressions(annotations); }
public JvmAnnotationReference findAnnotation(/* @NonNull */ JvmAnnotationTarget annotationTarget, /* @NonNull */ Class<? extends Annotation> lookupType) { // avoid creating an empty list for all given targets but check for #eIsSet first if (annotationTarget.eIsSet(TypesPackage.Literals.JVM_ANNOTATION_TARGET__ANNOTATIONS)) { for(JvmAnnotationReference annotation: annotationTarget.getAnnotations()) { JvmAnnotationType annotationType = annotation.getAnnotation(); if (annotationType != null && lookupType.getCanonicalName().equals(annotationType.getQualifiedName())) { return annotation; } } } return null; }
/** Replies if ambiguity could be removed for the given feature. * * @param candidate the candidate. * @return {@code true} if ambiguity could be removed. */ @SuppressWarnings({"checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity"}) protected boolean isIgnorableCallToFeature(ILinkingCandidate candidate) { final JvmIdentifiableElement feature = candidate.getFeature(); // // @Deprecated // if (feature instanceof JvmOperation) { JvmAnnotationTarget target = (JvmOperation) feature; JvmAnnotationReference reference = this.annotationLookup.findAnnotation(target, Deprecated.class); if (reference == null) { do { target = EcoreUtil2.getContainerOfType(target.eContainer(), JvmAnnotationTarget.class); if (target != null) { reference = this.annotationLookup.findAnnotation(target, Deprecated.class); } } while (reference == null && target != null); } if (reference != null) { return true; } } return false; }
protected void computeAnnotationTypes(ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmAnnotationTarget annotable) { List<JvmAnnotationReference> annotations = annotable.getAnnotations(); computeAnnotationTypes(resolvedTypes, featureScopeSession, annotations); }
/** Find an annotation. * * @param annotationTarget the annotation target. * @param lookupType the name of the type to look for. * @return the annotation or {@code null}. * @see AnnotationLookup#findAnnotation(JvmAnnotationTarget, Class) */ @SuppressWarnings("static-method") public JvmAnnotationReference findAnnotation(JvmAnnotationTarget annotationTarget, String lookupType) { // avoid creating an empty list for all given targets but check for #eIsSet first if (annotationTarget.eIsSet(TypesPackage.Literals.JVM_ANNOTATION_TARGET__ANNOTATIONS)) { for (final JvmAnnotationReference annotation: annotationTarget.getAnnotations()) { final JvmAnnotationType annotationType = annotation.getAnnotation(); if (annotationType != null && Objects.equals(lookupType, annotationType.getQualifiedName())) { return annotation; } } } return null; }
/** * Translates an {@link XAnnotation} to a {@link JvmAnnotationReference} * and adds them to the given {@link JvmAnnotationTarget}. * * @param target the annotation target. If <code>null</code> this method does nothing. * @param annotation the annotation. If <code>null</code> this method does nothing. */ public void addAnnotation(/* @Nullable */ JvmAnnotationTarget target, /* @Nullable */ XAnnotation annotation) { if(annotation == null || target == null) return; JvmAnnotationReference annotationReference = getJvmAnnotationReference(annotation); if(annotationReference != null) { target.getAnnotations().add(annotationReference); } }
@Nullable public JvmAnnotationReference findAnnotation(@NonNull JvmAnnotationTarget annotationTarget, @NonNull Class<? extends Annotation> lookupType) { // avoid creating an empty list for all given targets but check for #eIsSet first if (annotationTarget.eIsSet(TypesPackage.Literals.JVM_ANNOTATION_TARGET__ANNOTATIONS)) { for(JvmAnnotationReference annotation: annotationTarget.getAnnotations()) { JvmAnnotationType annotationType = annotation.getAnnotation(); if (annotationType != null && lookupType.getCanonicalName().equals(annotationType.getQualifiedName())) { return annotation; } } } return null; }
private boolean containsAnnotation(JvmAnnotationTarget annotationTarget, Class<? extends Annotation> annotationClass) { for (JvmAnnotationReference annotationRef : annotationTarget.getAnnotations()) { if (annotationClass.getName().equals(annotationRef.getAnnotation().getIdentifier())) { return true; } } return false; }
protected JvmAnnotationReference findAnnotation(JvmAnnotationTarget feature, String annotationType) { if (feature == null) return null; if (annotationType == null) throw new NullPointerException(); List<JvmAnnotationReference> annotations = feature.getAnnotations(); for (JvmAnnotationReference annotation : annotations) { if (annotationType.equals(annotation.getAnnotation().getQualifiedName())) { return annotation; } } return null; }
/** Add annotation safely. * * <p>This function creates an annotation reference. If the type for the annotation is not found; * no annotation is added. * * @param target the receiver of the annotation. * @param annotationType the type of the annotation. * @param values the annotations values. * @return the annotation reference or <code>null</code> if the annotation cannot be added. */ private JvmAnnotationReference addAnnotationSafe(JvmAnnotationTarget target, Class<?> annotationType, String... values) { assert target != null; assert annotationType != null; try { final JvmAnnotationReference annotationRef = this._annotationTypesBuilder.annotationRef(annotationType, values); if (annotationRef != null) { if (target.getAnnotations().add(annotationRef)) { return annotationRef; } } } catch (IllegalArgumentException exception) { // Ignore } return null; }
/** Copy the annotations, except the ones given as parameters. * * @param annotations the annotations to copy. * @param target the target. * @param exceptions the annotations to skip. */ @SuppressWarnings("static-method") protected void translateAnnotationsTo(List<JvmAnnotationReference> annotations, JvmAnnotationTarget target, Class<?>... exceptions) { final Set<String> excepts = new HashSet<>(); for (final Class<?> type : exceptions) { excepts.add(type.getName()); } final List<JvmAnnotationReference> addition = new ArrayList<>(); for (final JvmAnnotationReference annotation : Iterables.filter(annotations, an -> { if (!ANNOTATION_TRANSLATION_FILTER.apply(an)) { return false; } return !excepts.contains(an.getAnnotation().getIdentifier()); })) { addition.add(annotation); } target.getAnnotations().addAll(addition); }
public JvmAnnotationReference removeAnnotation(/* @NonNull */ JvmAnnotationTarget annotationTarget, /* @NonNull */ Class<? extends Annotation> type) { JvmAnnotationReference result = findAnnotation(annotationTarget, type); if (result != null) { annotationTarget.getAnnotations().remove(result); return result; } return null; }
public AnnotationVisitor visitAnnotation(final String desc, final boolean visible) { return new JvmAnnotationReferenceBuilder((InternalEList<JvmAnnotationReference>) this.getInstance() .getAnnotations(), desc, proxies); }
/** * @param qualifiedNames * The annotations' qualified names to search for. * * @param annotationTarget * The element the annotations are search on. * * @return The annotations that are applied on the <i>annotationTarget</i> * and their qualified names appear in the <i>qualifiedNames</i> set. * The annotations are returned in the order of their appearance. * * @since 2.15 */ public List<JvmAnnotationReference> findAnnotations(Set<String> qualifiedNames, JvmAnnotationTarget annotationTarget) { List<JvmAnnotationReference> result = new ArrayList<>(); if (annotationTarget != null) { for (JvmAnnotationReference annotation : annotationTarget.getAnnotations()) { String id = annotation.getAnnotation().getIdentifier(); if (qualifiedNames.contains(id)) { result.add(annotation); } } } return result; } }
protected void createAnnotationValues(final AnnotatedElement annotated, final JvmAnnotationTarget result) { Annotation[] declaredAnnotations = annotated.getDeclaredAnnotations(); if (declaredAnnotations.length != 0) { InternalEList<JvmAnnotationReference> annotations = (InternalEList<JvmAnnotationReference>)result.getAnnotations(); for (Annotation annotation : declaredAnnotations) { annotations.addUnique(createAnnotationReference(annotation)); } } }
@Nullable public JvmAnnotationReference removeAnnotation(@NonNull JvmAnnotationTarget annotationTarget, @NonNull Class<? extends Annotation> type) { JvmAnnotationReference result = findAnnotation(annotationTarget, type); if (result != null) { annotationTarget.getAnnotations().remove(result); return result; } return null; }
public Iterable<? extends AnnotationReference> getAnnotations() { final Function1<JvmAnnotationReference, AnnotationReference> _function = (JvmAnnotationReference it) -> { return this.getCompilationUnit().toAnnotationReference(it); }; return ImmutableList.<AnnotationReference>copyOf(ListExtensions.<JvmAnnotationReference, AnnotationReference>map(this.getDelegate().getAnnotations(), _function)); }
protected void createAnnotationValues(final AnnotatedElement annotated, final JvmAnnotationTarget result) { Annotation[] declaredAnnotations = annotated.getDeclaredAnnotations(); if (declaredAnnotations.length != 0) { InternalEList<JvmAnnotationReference> annotations = (InternalEList<JvmAnnotationReference>)result.getAnnotations(); for (Annotation annotation : declaredAnnotations) { annotations.addUnique(createAnnotationReference(annotation)); } } }
public static boolean isDeprecated(JvmAnnotationTarget jvmAnnotationTarget) { for (JvmAnnotationReference ref : jvmAnnotationTarget.getAnnotations()) { if (ref != null && !ref.eIsProxy()) { JvmAnnotationType annotation = ref.getAnnotation(); if(annotation != null && !annotation.eIsProxy() && isDeprecated(annotation)) return true; } } return false; }
public boolean removeAnnotation(final AnnotationReference annotationReference) { this.checkMutable(); if ((annotationReference instanceof JvmAnnotationReferenceImpl)) { return this.getDelegate().getAnnotations().remove(((JvmAnnotationReferenceImpl)annotationReference).getDelegate()); } return false; }