protected void recordAnnotationExpressions(JvmAnnotationTarget annotable) { List<JvmAnnotationReference> annotations = annotable.getAnnotations(); recordAnnotationExpressions(annotations); }
protected void computeAnnotationTypes(ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmAnnotationTarget annotable) { List<JvmAnnotationReference> annotations = annotable.getAnnotations(); computeAnnotationTypes(resolvedTypes, featureScopeSession, annotations); }
/** * 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); } }
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 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; }
public AnnotationVisitor visitAnnotation(final String desc, final boolean visible) { return new JvmAnnotationReferenceBuilder((InternalEList<JvmAnnotationReference>) this.getInstance() .getAnnotations(), desc, proxies); }
@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; }
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)); } } }
/** 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; }
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; }
protected void appendAnnotationReferences(JvmAnnotationTarget target) { for(JvmAnnotationReference annotationReference: target.getAnnotations()) { if(annotationRelevance.isRelevant(annotationReference)) append(hashProvider.getHash(annotationReference.getAnnotation())) .append(" "); } }
public AnnotationReference addAnnotation(final AnnotationReference annotationReference) { AnnotationReference _xblockexpression = null; { this.checkMutable(); Preconditions.checkArgument((annotationReference != null), "annotationReference cannot be null"); AnnotationReference _xifexpression = null; if ((annotationReference instanceof JvmAnnotationReferenceImpl)) { AnnotationReference _xblockexpression_1 = null; { final JvmAnnotationReference jvmAnnotationReference = EcoreUtil2.<JvmAnnotationReference>cloneWithProxies(((JvmAnnotationReferenceImpl)annotationReference).getDelegate()); EList<JvmAnnotationReference> _annotations = this.getDelegate().getAnnotations(); _annotations.add(jvmAnnotationReference); _xblockexpression_1 = this.getCompilationUnit().toAnnotationReference(jvmAnnotationReference); } _xifexpression = _xblockexpression_1; } else { StringConcatenation _builder = new StringConcatenation(); _builder.append(annotationReference); _builder.append(" is not annotation reference"); throw new IllegalArgumentException(_builder.toString()); } _xblockexpression = _xifexpression; } return _xblockexpression; }