@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); } }
@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); }
protected void _toJavaExpression(final XAnnotation annotation, final ITreeAppendable b) { b.append("@"); b.append(annotation.getAnnotationType()); XExpression value = annotation.getValue(); if (value != null) { b.append("("); internalToJavaExpression(value, b); b.append(")"); } else { EList<XAnnotationElementValuePair> valuePairs = annotation.getElementValuePairs(); if (valuePairs.isEmpty()) return; b.append("("); for (int i = 0; i < valuePairs.size(); i++) { XAnnotationElementValuePair pair = valuePairs.get(i); b.append(pair.getElement().getSimpleName()); b.append(" = "); internalToJavaExpression(pair.getValue(), b); if (i < valuePairs.size()-1) { b.append(", "); } } b.append(")"); } }
protected boolean isValidAnnotationValue(final XExpression expression) { if (expression instanceof XListLiteral) { return _isValidAnnotationValue((XListLiteral)expression); } else if (expression instanceof XAbstractFeatureCall) { return _isValidAnnotationValue((XAbstractFeatureCall)expression); } else if (expression instanceof XAnnotation) { return _isValidAnnotationValue((XAnnotation)expression); } else if (expression != null) { return _isValidAnnotationValue(expression); } else if (expression == null) { return _isValidAnnotationValue((Void)null); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(expression).toString()); } }
public Object internalEvaluate(final XExpression it, final Context ctx) { if (it instanceof XBinaryOperation) { return _internalEvaluate((XBinaryOperation)it, ctx); } else if (it instanceof XUnaryOperation) { return _internalEvaluate((XUnaryOperation)it, ctx); } else if (it instanceof XBooleanLiteral) { return _internalEvaluate((XBooleanLiteral)it, ctx); } else if (it instanceof XCastedExpression) { return _internalEvaluate((XCastedExpression)it, ctx); } else if (it instanceof XStringLiteral) { return _internalEvaluate((XStringLiteral)it, ctx); } else if (it instanceof XTypeLiteral) { return _internalEvaluate((XTypeLiteral)it, ctx); } else if (it instanceof XAnnotation) { return _internalEvaluate((XAnnotation)it, ctx); } else if (it != null) { return _internalEvaluate(it, ctx); } else if (it == null) { return _internalEvaluate((Void)null, ctx); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(it, ctx).toString()); } }
@Test public void testConstantExpression_6() throws Exception { XAnnotation annotation = annotation("@testdata.Annotation3(" + "booleanValue = true," + "intValue = 1," + "longValue = 42," + "stringValue = 'foo'," + "booleanArrayValue = #[true]," + "intArrayValue = #[1]," + "longArrayValue = #[42]," + "stringArrayValue = #['foo']," + "typeValue = String," + "typeArrayValue = #[String]," + "annotation2Value = @testdata.Annotation2(#['foo'])," + "annotation2ArrayValue = #[@testdata.Annotation2(#['foo'])]," + "enumValue = testdata.Enum1.RED," + "enumArrayValue = #[testdata.Enum1.RED]" + ")", false); validator.assertNoErrors(annotation); }
@Test public void testConstantExpression_7() throws Exception { XAnnotation annotation = annotation("@testdata.Annotation3(" + "intValue = 1 + 4 + 6 * 42 - 4 / 45," + "longValue = 42 + 4 + 6 * 42 - testdata.Constants1.INT_CONSTANT / 45," + "stringValue = 'foo' + 'baz'," + "booleanArrayValue = #[true, false]," + "intArrayValue = #[ -1, 34 + 45, 2 - 6 ]," + "longArrayValue = #[42, 5 * -3]," + "stringArrayValue = #['foo', 'bla' + 'buzz']," + "typeValue = String," + "typeArrayValue = #[String, Integer]," + "annotation2Value = @testdata.Annotation2(#['foo' + 'wuppa'])," + "annotation2ArrayValue = #[@testdata.Annotation2(#['foo']), @testdata.Annotation2(#['foo'+'wuppa'])]" + ")", false); validator.assertNoErrors(annotation); }
@Test public void testStringAnnotation() { try { final XAnnotationsFactory f = XAnnotationsFactory.eINSTANCE; final XExpression e = this.expression("\'Foo\'"); final XAnnotation anno = f.createXAnnotation(); JvmType _findDeclaredType = this.references.findDeclaredType(Inject.class, e); anno.setAnnotationType(((JvmAnnotationType) _findDeclaredType)); anno.setValue(e); final JvmGenericType type = this.typesFactory.createJvmGenericType(); this._jvmTypesBuilder.addAnnotation(type, anno); Assert.assertEquals(anno.getAnnotationType(), IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getAnnotation()); JvmAnnotationValue _head = IterableExtensions.<JvmAnnotationValue>head(IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getValues()); EObject _head_1 = IterableExtensions.<EObject>head(((JvmCustomAnnotationValue) _head).getValues()); Assert.assertTrue((_head_1 instanceof XStringLiteral)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Test public void testAnnotationDefaultValue() { try { final XAnnotationsFactory f = XAnnotationsFactory.eINSTANCE; final XExpression e = this.expression("\'Foo\'"); final XAnnotation anno = f.createXAnnotation(); JvmType _findDeclaredType = this.references.findDeclaredType(Named.class, e); anno.setAnnotationType(((JvmAnnotationType) _findDeclaredType)); anno.setValue(e); final JvmGenericType type = this.typesFactory.createJvmGenericType(); this._jvmTypesBuilder.addAnnotation(type, anno); Assert.assertEquals(anno.getAnnotationType(), IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getAnnotation()); JvmAnnotationValue _head = IterableExtensions.<JvmAnnotationValue>head(IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getValues()); EObject _head_1 = IterableExtensions.<EObject>head(((JvmCustomAnnotationValue) _head).getValues()); Assert.assertTrue((_head_1 instanceof XStringLiteral)); Assert.assertNull(IterableExtensions.<JvmAnnotationValue>head(IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getValues()).getOperation()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Test public void testStringAnnotationWithNullExpression() { try { final XAnnotationsFactory f = XAnnotationsFactory.eINSTANCE; final XExpression context = this.expression("\'Foo\'"); final XAnnotation anno = f.createXAnnotation(); JvmType _findDeclaredType = this.references.findDeclaredType(Inject.class, context); anno.setAnnotationType(((JvmAnnotationType) _findDeclaredType)); final XAnnotationElementValuePair pair = f.createXAnnotationElementValuePair(); EList<XAnnotationElementValuePair> _elementValuePairs = anno.getElementValuePairs(); this._jvmTypesBuilder.<XAnnotationElementValuePair>operator_add(_elementValuePairs, pair); final JvmGenericType type = this.typesFactory.createJvmGenericType(); this._jvmTypesBuilder.addAnnotation(type, anno); Assert.assertEquals(anno.getAnnotationType(), IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getAnnotation()); Assert.assertTrue(IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getExplicitValues().isEmpty()); Assert.assertFalse(IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getValues().isEmpty()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Test public void testIntegerAnnotation() { try { final XAnnotationsFactory f = XAnnotationsFactory.eINSTANCE; final XExpression e = this.expression("\'Foo\'"); final XAnnotation anno = f.createXAnnotation(); JvmType _findDeclaredType = this.references.findDeclaredType(TestAnnotation3.class, e); final JvmAnnotationType annotatiomType = ((JvmAnnotationType) _findDeclaredType); anno.setAnnotationType(annotatiomType); final XAnnotationElementValuePair pair = f.createXAnnotationElementValuePair(); pair.setElement(IterableExtensions.<JvmOperation>head(annotatiomType.getDeclaredOperations())); pair.setValue(this.expression("10")); EList<XAnnotationElementValuePair> _elementValuePairs = anno.getElementValuePairs(); this._jvmTypesBuilder.<XAnnotationElementValuePair>operator_add(_elementValuePairs, pair); final JvmGenericType type = this.typesFactory.createJvmGenericType(); this._jvmTypesBuilder.addAnnotation(type, anno); Assert.assertEquals(anno.getAnnotationType(), IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getAnnotation()); Assert.assertEquals(1, IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getValues().size()); JvmAnnotationValue _head = IterableExtensions.<JvmAnnotationValue>head(IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getValues()); final JvmCustomAnnotationValue value = ((JvmCustomAnnotationValue) _head); EObject _head_1 = IterableExtensions.<EObject>head(value.getValues()); Assert.assertTrue((_head_1 instanceof XNumberLiteral)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @SuppressWarnings("unchecked") @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case CheckPackage.MEMBER__ANNOTATIONS: getAnnotations().clear(); getAnnotations().addAll((Collection<? extends XAnnotation>)newValue); return; case CheckPackage.MEMBER__TYPE: setType((JvmTypeReference)newValue); return; case CheckPackage.MEMBER__NAME: setName((String)newValue); return; case CheckPackage.MEMBER__VALUE: setValue((XExpression)newValue); return; } super.eSet(featureID, newValue); }
/** * Translates {@link XAnnotation XAnnotations} to {@link JvmAnnotationReference JvmAnnotationReferences} * and adds them to the given {@link JvmAnnotationTarget}. * * @param target the annotation target. If <code>null</code> this method does nothing. * @param annotations the annotations. If <code>null</code> this method does nothing. */ public void addAnnotations(/* @Nullable */ JvmAnnotationTarget target, /* @Nullable */ Iterable<? extends XAnnotation> annotations) { if(annotations == null || target == null) return; for (XAnnotation annotation : annotations) { addAnnotation(target, annotation); } }
/** * 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); } }
/** * Translates a single {@link XAnnotation} to {@link JvmAnnotationReference} that can be added to a {@link JvmAnnotationTarget}. * * @param anno the source annotation * * @return a {@link JvmAnnotationReference} that can be attached to some {@link JvmAnnotationTarget} */ /* @Nullable */ public JvmAnnotationReference getJvmAnnotationReference(/* @Nullable */ XAnnotation anno) { if(anno == null) return null; JvmAnnotationReference reference = typesFactory.createJvmAnnotationReference(); final JvmType annotation = (JvmType) anno.eGet( XAnnotationsPackage.Literals.XANNOTATION__ANNOTATION_TYPE, false); if (annotation.eIsProxy()) { JvmAnnotationType copiedProxy = TypesFactory.eINSTANCE.createJvmAnnotationType(); ((InternalEObject)copiedProxy).eSetProxyURI(EcoreUtil.getURI(annotation)); reference.setAnnotation(copiedProxy); } else if (annotation instanceof JvmAnnotationType){ reference.setAnnotation((JvmAnnotationType) annotation); } for (XAnnotationElementValuePair val : anno.getElementValuePairs()) { XExpression valueExpression = val.getValue(); JvmAnnotationValue annotationValue = toJvmAnnotationValue(valueExpression); if (annotationValue != null) { JvmOperation op = (JvmOperation) val.eGet( XAnnotationsPackage.Literals.XANNOTATION_ELEMENT_VALUE_PAIR__ELEMENT, false); annotationValue.setOperation(op); reference.getExplicitValues().add(annotationValue); } } if (anno.getValue() != null) { JvmAnnotationValue value = toJvmAnnotationValue(anno.getValue()); if (value != null) { reference.getExplicitValues().add(value); } } associate(anno, reference); return reference; }
/** * @return whether the expression itself (not its children) possibly causes a side-effect */ public boolean hasSideEffects(XExpression expr) { if (expr instanceof XClosure || expr instanceof XStringLiteral || expr instanceof XTypeLiteral || expr instanceof XBooleanLiteral || expr instanceof XNumberLiteral || expr instanceof XNullLiteral || expr instanceof XAnnotation ) return false; if(expr instanceof XCollectionLiteral) { for(XExpression element: ((XCollectionLiteral)expr).getElements()) { if(hasSideEffects(element)) return true; } return false; } if (expr instanceof XAbstractFeatureCall) { XAbstractFeatureCall featureCall = (XAbstractFeatureCall) expr; return hasSideEffects(featureCall, true); } if (expr instanceof XConstructorCall) { XConstructorCall constrCall = (XConstructorCall) expr; return findPureAnnotation(constrCall.getConstructor()) == null; } return true; }
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; }
@Override public void computeTypes(XExpression expression, ITypeComputationState state) { if (expression instanceof XAnnotation) { _computeTypes((XAnnotation)expression, state); } else { super.computeTypes(expression, state); } }
protected void computeChildTypesForUnknownAnnotation(XAnnotation object, ITypeComputationState state) { XExpression expression = object.getValue(); if (expression != null) state.withNonVoidExpectation().computeTypes(expression); else { List<XAnnotationElementValuePair> valuePairs = object.getElementValuePairs(); for(XAnnotationElementValuePair pair: valuePairs) { computeTypes(object, pair.getElement(), pair.getValue(), state); } } }
public XExpression findValue(XAnnotation annotation, JvmOperation jvmOperation) { if (jvmOperation.getSimpleName().equals("value") && annotation.getValue() != null) { return annotation.getValue(); } for (XAnnotationElementValuePair pair : annotation.getElementValuePairs()) { if (pair.getElement() == jvmOperation) return pair.getValue(); } return null; }
@Override protected void internalToConvertedExpression(XExpression obj, ITreeAppendable appendable) { if (obj instanceof XBlockExpression) { _toJavaExpression((XBlockExpression) obj, appendable); } else if (obj instanceof XCastedExpression) { _toJavaExpression((XCastedExpression) obj, appendable); } else if (obj instanceof XClosure) { _toJavaExpression((XClosure) obj, appendable); } else if (obj instanceof XAnnotation) { _toJavaExpression((XAnnotation) obj, appendable); } else if (obj instanceof XConstructorCall) { _toJavaExpression((XConstructorCall) obj, appendable); } else if (obj instanceof XIfExpression) { _toJavaExpression((XIfExpression) obj, appendable); } else if (obj instanceof XInstanceOfExpression) { _toJavaExpression((XInstanceOfExpression) obj, appendable); } else if (obj instanceof XSwitchExpression) { _toJavaExpression((XSwitchExpression) obj, appendable); } else if (obj instanceof XTryCatchFinallyExpression) { _toJavaExpression((XTryCatchFinallyExpression) obj, appendable); } else if (obj instanceof XListLiteral) { _toJavaExpression((XListLiteral) obj, appendable); } else if (obj instanceof XSetLiteral) { _toJavaExpression((XSetLiteral) obj, appendable); } else if (obj instanceof XSynchronizedExpression) { _toJavaExpression((XSynchronizedExpression) obj, appendable); } else if (obj instanceof XReturnExpression) { _toJavaExpression((XReturnExpression) obj, appendable); } else if (obj instanceof XThrowExpression) { _toJavaExpression((XThrowExpression) obj, appendable); } else { super.internalToConvertedExpression(obj, appendable); } }
/** * Complete the initialization of the package and its meta-model. This * method is guarded to have no affect on any invocation but its first. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void initializePackageContents() { if (isInitialized) return; isInitialized = true; // Initialize package setName(eNAME); setNsPrefix(eNS_PREFIX); setNsURI(eNS_URI); // Obtain other dependent packages XbasePackage theXbasePackage = (XbasePackage)EPackage.Registry.INSTANCE.getEPackage(XbasePackage.eNS_URI); TypesPackage theTypesPackage = (TypesPackage)EPackage.Registry.INSTANCE.getEPackage(TypesPackage.eNS_URI); // Create type parameters // Set bounds for type parameters // Add supertypes to classes xAnnotationEClass.getESuperTypes().add(theXbasePackage.getXExpression()); // Initialize classes and features; add operations and parameters initEClass(xAnnotationEClass, XAnnotation.class, "XAnnotation", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); initEReference(getXAnnotation_ElementValuePairs(), this.getXAnnotationElementValuePair(), null, "elementValuePairs", null, 0, -1, XAnnotation.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); initEReference(getXAnnotation_AnnotationType(), theTypesPackage.getJvmType(), null, "annotationType", null, 0, 1, XAnnotation.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); initEReference(getXAnnotation_Value(), theXbasePackage.getXExpression(), null, "value", null, 0, 1, XAnnotation.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); initEClass(xAnnotationElementValuePairEClass, XAnnotationElementValuePair.class, "XAnnotationElementValuePair", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); initEReference(getXAnnotationElementValuePair_Value(), theXbasePackage.getXExpression(), null, "value", null, 0, 1, XAnnotationElementValuePair.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); initEReference(getXAnnotationElementValuePair_Element(), theTypesPackage.getJvmOperation(), null, "element", null, 0, 1, XAnnotationElementValuePair.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); // Create resource createResource(eNS_URI); }
public Object internalEvaluate(final XExpression it, final Context ctx) { if (it instanceof XBinaryOperation) { return _internalEvaluate((XBinaryOperation)it, ctx); } else if (it instanceof XUnaryOperation) { return _internalEvaluate((XUnaryOperation)it, ctx); } else if (it instanceof XAbstractFeatureCall) { return _internalEvaluate((XAbstractFeatureCall)it, ctx); } else if (it instanceof XBooleanLiteral) { return _internalEvaluate((XBooleanLiteral)it, ctx); } else if (it instanceof XCastedExpression) { return _internalEvaluate((XCastedExpression)it, ctx); } else if (it instanceof XNumberLiteral) { return _internalEvaluate((XNumberLiteral)it, ctx); } else if (it instanceof XStringLiteral) { return _internalEvaluate((XStringLiteral)it, ctx); } else if (it instanceof XTypeLiteral) { return _internalEvaluate((XTypeLiteral)it, ctx); } else if (it instanceof XAnnotation) { return _internalEvaluate((XAnnotation)it, ctx); } else if (it != null) { return _internalEvaluate(it, ctx); } else if (it == null) { return _internalEvaluate((Void)null, ctx); } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(it, ctx).toString()); } }
public void visit(final EObject jvmType, final INode originNode, final ImportsAcceptor acceptor) { if (jvmType instanceof JvmGenericType) { _visit((JvmGenericType)jvmType, originNode, acceptor); return; } else if (jvmType instanceof JvmDeclaredType) { _visit((JvmDeclaredType)jvmType, originNode, acceptor); return; } else if (jvmType instanceof XFeatureCall) { _visit((XFeatureCall)jvmType, originNode, acceptor); return; } else if (jvmType instanceof XMemberFeatureCall) { _visit((XMemberFeatureCall)jvmType, originNode, acceptor); return; } else if (jvmType instanceof XAbstractFeatureCall) { _visit((XAbstractFeatureCall)jvmType, originNode, acceptor); return; } else if (jvmType instanceof XConstructorCall) { _visit((XConstructorCall)jvmType, originNode, acceptor); return; } else if (jvmType instanceof XTypeLiteral) { _visit((XTypeLiteral)jvmType, originNode, acceptor); return; } else if (jvmType instanceof XAnnotation) { _visit((XAnnotation)jvmType, originNode, acceptor); return; } else if (jvmType instanceof JvmTypeReference) { _visit((JvmTypeReference)jvmType, originNode, acceptor); return; } else if (jvmType != null) { _visit(jvmType, originNode, acceptor); return; } else if (jvmType == null) { _visit((Void)null, originNode, acceptor); return; } else { throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(jvmType, originNode, acceptor).toString()); } }
@Override protected boolean highlightElement(EObject object, IHighlightedPositionAcceptor acceptor, CancelIndicator cancelIndicator) { if (object instanceof XAbstractFeatureCall) { if (((XAbstractFeatureCall) object).isPackageFragment()) { return true; } if (SPECIAL_FEATURE_NAMES.contains(((XAbstractFeatureCall) object).getConcreteSyntaxFeatureName())) { return false; } operationCanceledManager.checkCanceled(cancelIndicator); computeFeatureCallHighlighting((XAbstractFeatureCall) object, acceptor); } else if (object instanceof JvmTypeParameter) { highlightTypeParameter((JvmTypeParameter) object, acceptor); } else if (object instanceof JvmFormalParameter) { highlightFormalParameter((JvmFormalParameter) object, acceptor); } else if (object instanceof XVariableDeclaration) { highlightVariableDeclaration((XVariableDeclaration) object, acceptor); } else if (object instanceof XNumberLiteral) { highlightNumberLiterals((XNumberLiteral) object, acceptor); } else if (object instanceof XConstructorCall) { highlightConstructorCall((XConstructorCall) object, acceptor); } else if (object instanceof XAnnotation) { // Handle XAnnotation in a special way because we want the @ highlighted too highlightAnnotation((XAnnotation) object, acceptor); } else { computeReferencedJvmTypeHighlighting(acceptor, object, cancelIndicator); } return false; }
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); } }
@Test public void testNoOperationFound() throws Exception { XAnnotation annotation = annotation("@testdata.Annotation2(toString = true)", false); validator.assertNoError(annotation, IssueCodes.INCOMPATIBLE_TYPES); // TODO use better error message like in Java (e.g. Annotation A does not define an attribute b) validator.assertError(annotation, XAnnotationsPackage.Literals.XANNOTATION_ELEMENT_VALUE_PAIR, Diagnostic.LINKING_DIAGNOSTIC); validator.assertError(annotation, XAnnotationsPackage.Literals.XANNOTATION, IssueCodes.ANNOTATIONS_MISSING_ATTRIBUTE_DEFINITION, "attribute 'value'"); }
@Test public void testReferencedTypeIsNoEnum() throws Exception { XAnnotation annotation = annotation("@java.lang.Object(unknown = #[ new String() ])", false); List<Issue> issues = validator.validate(annotation); assertEquals(issues.toString(), 1, issues.size()); Issue singleIssue = issues.get(0); assertEquals(IssueCodes.INCOMPATIBLE_TYPES, singleIssue.getCode()); assertEquals(1, singleIssue.getOffset().intValue()); assertEquals("java.lang.Object".length(), singleIssue.getLength().intValue()); }
@Test public void testEmptyAnnotation() { try { final XAnnotationsFactory f = XAnnotationsFactory.eINSTANCE; final XExpression e = this.expression("\'Foo\'"); final XAnnotation anno = f.createXAnnotation(); JvmType _findDeclaredType = this.references.findDeclaredType(Inject.class, e); anno.setAnnotationType(((JvmAnnotationType) _findDeclaredType)); final JvmGenericType type = this.typesFactory.createJvmGenericType(); this._jvmTypesBuilder.addAnnotations(type, Collections.<XAnnotation>unmodifiableList(CollectionLiterals.<XAnnotation>newArrayList(anno))); Assert.assertEquals(anno.getAnnotationType(), IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getAnnotation()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Test public void testErrorModel_01() throws Exception { StringConcatenation _builder = new StringConcatenation(); _builder.append("estdata.Annotation2(value = \'foo\')"); _builder.newLine(); final XAnnotation annotation = this.processWithoutException(_builder); final XAnnotationElementValuePair singleValuePair = IterableExtensions.<XAnnotationElementValuePair>head(annotation.getElementValuePairs()); Assert.assertNotNull(this.batchTypeResolver.resolveTypes(annotation).getActualType(singleValuePair.getValue())); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public EList<XAnnotation> getAnnotations() { if (annotations == null) { annotations = new EObjectContainmentEList<XAnnotation>(XAnnotation.class, this, CheckPackage.MEMBER__ANNOTATIONS); } return annotations; }
@Deprecated protected void sequence_XAnnotation(EObject context, XAnnotation semanticObject) { sequence_XAnnotation(createContext(context, semanticObject), semanticObject); }
@Override protected boolean isVariableDeclarationRequired(XExpression expr, ITreeAppendable b, boolean recursive) { if (expr instanceof XAnnotation) { return false; } if (expr instanceof XListLiteral) { return false; } if (expr instanceof XSetLiteral) { return false; } if (expr instanceof XCastedExpression) { return false; } if (expr instanceof XInstanceOfExpression) { return false; } if (expr instanceof XMemberFeatureCall && isVariableDeclarationRequired((XMemberFeatureCall) expr, b)) return true; EObject container = expr.eContainer(); if ((container instanceof XVariableDeclaration) || (container instanceof XReturnExpression) || (container instanceof XThrowExpression)) { return false; } if (container instanceof XIfExpression) { XIfExpression ifExpression = (XIfExpression) container; if (ifExpression.getThen() == expr || ifExpression.getElse() == expr) { return false; } } if (container instanceof XCasePart) { XCasePart casePart = (XCasePart) container; if (casePart.getThen() == expr) { return false; } } if (container instanceof XSwitchExpression) { XSwitchExpression switchExpression = (XSwitchExpression) container; if (switchExpression.getDefault() == expr) { return false; } } if (container instanceof XBlockExpression) { List<XExpression> siblings = ((XBlockExpression) container).getExpressions(); if (siblings.get(siblings.size() - 1) == expr) { return isVariableDeclarationRequired(getFeatureCall(expr), expr, b); } } if (container instanceof XClosure) { if (((XClosure) container).getExpression() == expr) { return false; } } if (expr instanceof XAssignment) { XAssignment a = (XAssignment) expr; for (XExpression arg : getActualArguments(a)) { if (isVariableDeclarationRequired(arg, b, recursive)) { return true; } } } return super.isVariableDeclarationRequired(expr, b, recursive); }
protected boolean _isValidAnnotationValue(final XAnnotation expression) { return true; }
protected Object _internalEvaluate(final XAnnotation literal, final Context ctx) { return literal; }
protected void _visit(final XAnnotation semanticElement, final INode originNode, final ImportsAcceptor acceptor) { this.visit(semanticElement.getAnnotationType(), originNode, acceptor); }
protected void highlightAnnotation(XAnnotation annotation, IHighlightedPositionAcceptor acceptor) { highlightAnnotation(annotation, acceptor, ANNOTATION); }
@Test public void testTypeConformance_01() throws Exception { XAnnotation annotation = annotation("@testdata.Annotation2('foo')", false); validator.assertNoErrors(annotation); }
@Test public void testTypeConformance_02() throws Exception { XAnnotation annotation = annotation("@testdata.Annotation2(value = 'foo')", false); validator.assertNoErrors(annotation); }
@Test public void testTypeConformance_05() throws Exception { XAnnotation annotation = annotation("@testdata.Annotation2(true)", false); validator.assertError(annotation, XbasePackage.Literals.XBOOLEAN_LITERAL, IssueCodes.INCOMPATIBLE_TYPES, "cannot convert from boolean to String | String[]"); }