Java Code Examples for org.eclipse.xtext.common.types.JvmAnnotationTarget#getAnnotations()

The following examples show how to use org.eclipse.xtext.common.types.JvmAnnotationTarget#getAnnotations() . 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: JdtBasedTypeFactory.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void createAnnotationValues(IBinding annotated, JvmAnnotationTarget result) {
	try {
		resolveAnnotations.start();
		IAnnotationBinding[] annotationBindings = annotated.getAnnotations();
		if (annotationBindings.length != 0) {
			InternalEList<JvmAnnotationReference> annotations = (InternalEList<JvmAnnotationReference>)result.getAnnotations();
			for (IAnnotationBinding annotation : annotationBindings) {
				annotations.addUnique(createAnnotationReference(annotation));
			}
		}
	} catch(AbortCompilation aborted) {
		if (aborted.problem.getID() == IProblem.IsClassPathCorrect) {
			// ignore
		} else {
			log.info("Couldn't resolve annotations of "+annotated, aborted);
		}
	} finally {
		resolveAnnotations.stop();
	}
}
 
Example 2
Source File: XExpressionHelper.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example 3
Source File: XAnnotationUtil.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @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;
}
 
Example 4
Source File: ReflectionTypeFactory.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
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));
		}
	}
}
 
Example 5
Source File: AnnotationLookup.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public JvmAnnotationReference findAnnotation(/* @NonNull */ JvmAnnotationTarget annotationTarget, /* @NonNull */ 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(JvmAnnotationReference annotation: annotationTarget.getAnnotations()) {
			JvmAnnotationType annotationType = annotation.getAnnotation();
			if (annotationType != null && lookupType.equals(annotationType.getQualifiedName())) {
				return annotation;
			}
		}
	}
	return null;
}
 
Example 6
Source File: JvmDeclaredTypeSignatureHashProvider.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void appendAnnotationReferences(JvmAnnotationTarget target) {
	for(JvmAnnotationReference annotationReference: target.getAnnotations()) {
		if(annotationRelevance.isRelevant(annotationReference)) 
			append(hashProvider.getHash(annotationReference.getAnnotation()))
				.append(" ");
	}
}
 
Example 7
Source File: XtendJvmModelInferrer.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example 8
Source File: SARLAnnotationUtil.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** 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;
}
 
Example 9
Source File: LogicalContainerAwareReentrantTypeResolver.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected void recordAnnotationExpressions(JvmAnnotationTarget annotable) {
	List<JvmAnnotationReference> annotations = annotable.getAnnotations();
	recordAnnotationExpressions(annotations);
}
 
Example 10
Source File: LogicalContainerAwareReentrantTypeResolver.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected void computeAnnotationTypes(ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmAnnotationTarget annotable) {
	List<JvmAnnotationReference> annotations = annotable.getAnnotations();
	computeAnnotationTypes(resolvedTypes, featureScopeSession, annotations);
}