Java Code Examples for org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation#getAnnotationType()
The following examples show how to use
org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation#getAnnotationType() .
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: XbaseWithAnnotationsValidator.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Check public void checkAllAttributesConfigured(XAnnotation annotation) { JvmType annotationType = annotation.getAnnotationType(); if (annotationType == null || annotationType.eIsProxy() || !(annotationType instanceof JvmAnnotationType)) return; Iterable<JvmOperation> attributes = ((JvmAnnotationType) annotationType).getDeclaredOperations(); for (JvmOperation jvmOperation : attributes) { XExpression value = annotationUtil.findValue(annotation, jvmOperation); if(value == null) { if (jvmOperation.getDefaultValue() == null) { error("The annotation must define the attribute '"+jvmOperation.getSimpleName()+"'.", annotation, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, ANNOTATIONS_MISSING_ATTRIBUTE_DEFINITION); } } else annotationValueValidator.validateAnnotationValue(value, this); } }
Example 2
Source File: XbaseWithAnnotationsBatchScopeProvider.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public IScope getScope(EObject context, EReference reference) { if (reference == XAnnotationsPackage.Literals.XANNOTATION_ELEMENT_VALUE_PAIR__ELEMENT) { XAnnotation annotation = EcoreUtil2.getContainerOfType(context, XAnnotation.class); JvmType annotationType = annotation.getAnnotationType(); if (annotationType == null || annotationType.eIsProxy() || !(annotationType instanceof JvmAnnotationType)) { return IScope.NULLSCOPE; } Iterable<JvmOperation> operations = ((JvmAnnotationType) annotationType).getDeclaredOperations(); Iterable<IEObjectDescription> descriptions = transform(operations, new Function<JvmOperation, IEObjectDescription>() { @Override public IEObjectDescription apply(JvmOperation from) { return EObjectDescription.create(QualifiedName.create(from.getSimpleName()), from); } }); return MapBasedScope.createScope(IScope.NULLSCOPE, descriptions); } return super.getScope(context, reference); }
Example 3
Source File: XtendHighlightingCalculator.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected void highlightDeprecatedXtendAnnotationTarget(IHighlightedPositionAcceptor acceptor, XtendAnnotationTarget target, XAnnotation annotation){ JvmType annotationType = annotation.getAnnotationType(); if(annotationType instanceof JvmAnnotationType && DeprecationUtil.isDeprecatedAnnotation((JvmAnnotationType) annotationType)){ if (target instanceof XtendConstructor) { ICompositeNode compositeNode = NodeModelUtils.getNode(target); for(ILeafNode leaf: compositeNode.getLeafNodes()) { if (leaf.getGrammarElement() == xtendGrammarAccess.getMemberAccess().getNewKeyword_2_2_2()) { highlightNode(acceptor, leaf, XbaseHighlightingStyles.DEPRECATED_MEMBERS); highlightNode(acceptor, leaf, HighlightingStyles.KEYWORD_ID); return; } } } else { EStructuralFeature nameFeature = target.eClass().getEStructuralFeature("name"); if (nameFeature!=null) { highlightFeature(acceptor, target, nameFeature, XbaseHighlightingStyles.DEPRECATED_MEMBERS); } } } }
Example 4
Source File: XtendValidator.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Check public void checkAnnotationTarget(XAnnotation annotation) { JvmType annotationType = annotation.getAnnotationType(); if (annotationType == null || annotationType.eIsProxy() || !(annotationType instanceof JvmAnnotationType)) { return; } Set<ElementType> targets = annotationUtil.getAnnotationTargets((JvmAnnotationType) annotationType); if (targets.isEmpty()) return; final EObject eContainer = getContainingAnnotationTarget(annotation); Class<? extends EObject> clazz = eContainer.getClass(); if (eContainer instanceof XtendField && eContainer.eContainer() instanceof XtendAnnotationType) { clazz = XtendFunction.class; } for (Entry<Class<?>, Collection<ElementType>> mapping : targetInfos.asMap().entrySet()) { if (mapping.getKey().isAssignableFrom(clazz)) { targets.retainAll(mapping.getValue()); if (targets.isEmpty()) { error("The annotation @" + annotation.getAnnotationType().getSimpleName() + " is disallowed for this location.", annotation, null, INSIGNIFICANT_INDEX, ANNOTATION_WRONG_TARGET); } } } }
Example 5
Source File: XtendValidator.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected void doCheckFunctionOverrides(IResolvedOperation operation, Set<EObject> flaggedOperations) { EObject sourceElement = findPrimarySourceElement(operation); if (sourceElement != null) { List<IResolvedOperation> allInherited = operation.getOverriddenAndImplementedMethods(); if (allInherited.isEmpty()) { if (sourceElement instanceof XtendFunction && flaggedOperations.add(sourceElement)) { XtendFunction function = (XtendFunction) sourceElement; if (function.isOverride()) { error("The method "+ operation.getSimpleSignature() +" of type "+getDeclaratorName(operation.getDeclaration())+" must override a superclass method.", function, XTEND_MEMBER__MODIFIERS, function.getModifiers().indexOf("override"), OBSOLETE_OVERRIDE); } else { for (XAnnotation anno : function.getAnnotations()) { if (anno != null && anno.getAnnotationType() != null && Override.class.getName().equals(anno.getAnnotationType().getIdentifier())) { error("Superfluous @Override annotation", anno, null, OBSOLETE_ANNOTATION_OVERRIDE); } } } } } else if (flaggedOperations.add(sourceElement)) { doCheckFunctionOverrides(sourceElement, operation, allInherited); } } }
Example 6
Source File: SARLValidator.java From sarl with Apache License 2.0 | 6 votes |
/** Check for {@code @Inline} annotation usage. * * @param annotationTarget thee target to test. */ @Check public void checkManualInlineDefinition(XtendAnnotationTarget annotationTarget) { if (!isIgnored(MANUAL_INLINE_DEFINITION)) { if (annotationTarget.getAnnotations().isEmpty() || !isRelevantAnnotationTarget(annotationTarget)) { return; } final String inlineAnnotation = Inline.class.getName(); for (final XAnnotation annotation : annotationTarget.getAnnotations()) { final JvmType type = annotation.getAnnotationType(); if (type != null && !type.eIsProxy()) { if (Objects.equal(type.getIdentifier(), inlineAnnotation)) { addIssue( Messages.SARLValidator_16, annotation, MANUAL_INLINE_DEFINITION); } } } } }
Example 7
Source File: UnresolvedAnnotationTypeAwareMessageProvider.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected boolean isPropertyOfUnresolvedAnnotation(ILinkingDiagnosticContext context) { EObject object = context.getContext(); if (object instanceof XAnnotationElementValuePair && context.getReference() == XAnnotationsPackage.Literals.XANNOTATION_ELEMENT_VALUE_PAIR__ELEMENT) { XAnnotation annotation = EcoreUtil2.getContainerOfType(object, XAnnotation.class); if (annotation != null) { JvmType annotationType = annotation.getAnnotationType(); if (annotationType == null || annotationType.eIsProxy() || !(annotationType instanceof JvmAnnotationType)) { return true; } } } return false; }
Example 8
Source File: XbaseHighlightingCalculator.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void highlightAnnotation(XAnnotation annotation, IHighlightedPositionAcceptor acceptor, String highlightingConfiguration) { JvmType annotationType = annotation.getAnnotationType(); if (annotationType != null && !annotationType.eIsProxy() && annotationType instanceof JvmAnnotationType) { ICompositeNode xannotationNode = NodeModelUtils.findActualNodeFor(annotation); if (xannotationNode != null) { ILeafNode firstLeafNode = NodeModelUtils.findLeafNodeAtOffset(xannotationNode, xannotationNode.getOffset() ); if(firstLeafNode != null) highlightNode(acceptor, firstLeafNode, highlightingConfiguration); } highlightReferenceJvmType(acceptor, annotation, XAnnotationsPackage.Literals.XANNOTATION__ANNOTATION_TYPE, annotationType, highlightingConfiguration); } }
Example 9
Source File: XtendUIValidator.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Check protected void checkAnnotationInSameProject(XAnnotation annotation) throws JavaModelException { try { if (annotationExtensions.isProcessed(annotation)) { JvmType annotationType = annotation.getAnnotationType(); if (isSameProject(annotation, annotationType)) { error("The referenced active annotation cannot be used from within the same project.",XAnnotationsPackage.Literals.XANNOTATION__ANNOTATION_TYPE, -1, ACTIVE_ANNOTATION_IN_SAME_CONTAINER); } } } catch(JavaModelException e) { if (!e.isDoesNotExist()) { throw e; } } }
Example 10
Source File: XtendHighlightingCalculator.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void highlightElement(XtendAnnotationType xtendType, IHighlightedPositionAcceptor acceptor, CancelIndicator cancelIndicator) { for(XAnnotation annotation: xtendType.getAnnotations()) { JvmType annotationType = annotation.getAnnotationType(); if (annotationType != null && !annotationType.eIsProxy() && Active.class.getName().equals(annotationType.getIdentifier())) { highlightFeature(acceptor, annotation, XtendPackage.Literals.XTEND_TYPE_DECLARATION__NAME, ACTIVE_ANNOTATION); break; } } }
Example 11
Source File: XtendHighlightingCalculator.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override protected void highlightAnnotation(XAnnotation annotation, IHighlightedPositionAcceptor acceptor) { JvmType annotationType = annotation.getAnnotationType(); if (annotationType instanceof JvmAnnotationTarget) { for(JvmAnnotationReference annotationReference: ((JvmAnnotationTarget) annotationType).getAnnotations()) { JvmAnnotationType otherAnnotation = annotationReference.getAnnotation(); if (otherAnnotation != null && !otherAnnotation.eIsProxy() && Active.class.getName().equals(otherAnnotation.getIdentifier())) { highlightAnnotation(annotation, acceptor, ACTIVE_ANNOTATION); return; } } } super.highlightAnnotation(annotation, acceptor); }
Example 12
Source File: XtendValidator.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected boolean hasAnnotation(XtendAnnotationTarget source, Class<?> class1) { for (XAnnotation anno : source.getAnnotations()) { if (anno != null && anno.getAnnotationType() != null && class1.getName().equals(anno.getAnnotationType().getIdentifier())) return true; } return false; }
Example 13
Source File: XtendValidator.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected boolean hasAnnotation(Iterable<? extends XAnnotation> annotations, Class<?> annotationType) { for (XAnnotation anno : annotations) { if (anno.getAnnotationType() != null && annotationType.getName().equals(anno.getAnnotationType().getIdentifier())) return true; } return false; }
Example 14
Source File: XtendJvmModelInferrer.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public boolean apply(/* @Nullable */ XAnnotation annotation) { if (annotation == null || annotation.getAnnotationType() == null) return false; JvmType annotationType = annotation.getAnnotationType(); if (annotationType instanceof JvmAnnotationType && DisableCodeGenerationAdapter.isDisabled((JvmDeclaredType) annotationType)) return false; return true; }
Example 15
Source File: XtendMemberDeclarationImpl.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public boolean isDeprecated() { final Function1<XAnnotation, Boolean> _function = (XAnnotation it) -> { String _name = Deprecated.class.getName(); JvmType _annotationType = it.getAnnotationType(); String _identifier = null; if (_annotationType!=null) { _identifier=_annotationType.getIdentifier(); } return Boolean.valueOf(Objects.equal(_name, _identifier)); }; return IterableExtensions.<XAnnotation>exists(this.getDelegate().getAnnotations(), _function); }
Example 16
Source File: SARLValidator.java From sarl with Apache License 2.0 | 5 votes |
/** Check for reserved annotations. * * @param annotationTarget thee target to test. */ @Check public void checkReservedAnnotation(XtendAnnotationTarget annotationTarget) { if (!isIgnored(USED_RESERVED_SARL_ANNOTATION)) { if (annotationTarget.getAnnotations().isEmpty() || !isRelevantAnnotationTarget(annotationTarget)) { return; } final QualifiedName reservedPackage = this.qualifiedNameConverter.toQualifiedName( EarlyExit.class.getPackage().getName()); final String earlyExitAnnotation = EarlyExit.class.getName(); final String errorOnCallAnnotation = ErrorOnCall.class.getName(); final String warningOnCallAnnotation = WarningOnCall.class.getName(); final String infoOnCallAnnotation = InfoOnCall.class.getName(); for (final XAnnotation annotation : annotationTarget.getAnnotations()) { final JvmType type = annotation.getAnnotationType(); if (type != null && !type.eIsProxy()) { if (Objects.equal(type.getIdentifier(), earlyExitAnnotation)) { // Special case: EarlyExit is allowed on events for declaring early-exit events if (!(annotationTarget instanceof SarlEvent)) { addIssue( MessageFormat.format(Messages.SARLValidator_87, type.getSimpleName()), annotation, USED_RESERVED_SARL_ANNOTATION); } } else if (!Objects.equal(type.getIdentifier(), errorOnCallAnnotation) && !Objects.equal(type.getIdentifier(), warningOnCallAnnotation) && !Objects.equal(type.getIdentifier(), infoOnCallAnnotation)) { final QualifiedName annotationName = this.qualifiedNameConverter.toQualifiedName( type.getIdentifier()); if (annotationName.startsWith(reservedPackage)) { addIssue( MessageFormat.format(Messages.SARLValidator_87, type.getSimpleName()), annotation, USED_RESERVED_SARL_ANNOTATION); } } } } } }