org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotationElementValuePair Java Examples
The following examples show how to use
org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotationElementValuePair.
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: XAnnotationImpl.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @SuppressWarnings("unchecked") @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case XAnnotationsPackage.XANNOTATION__ELEMENT_VALUE_PAIRS: getElementValuePairs().clear(); getElementValuePairs().addAll((Collection<? extends XAnnotationElementValuePair>)newValue); return; case XAnnotationsPackage.XANNOTATION__ANNOTATION_TYPE: setAnnotationType((JvmType)newValue); return; case XAnnotationsPackage.XANNOTATION__VALUE: setValue((XExpression)newValue); return; } super.eSet(featureID, newValue); }
Example #2
Source File: Utils.java From sarl with Apache License 2.0 | 6 votes |
private static void addAnnotationToSignature(StringBuilder textRepresentation, SARLGrammarKeywordAccess elements, ISerializer serializer, ImportManager importManager, XAnnotation annotation) { textRepresentation.append(elements.getCommercialAtKeyword()); textRepresentation.append(getSignatureType(annotation.getAnnotationType(), importManager)); final XExpression value = annotation.getValue(); if (value != null) { textRepresentation.append(elements.getLeftParenthesisKeyword()); textRepresentation.append(serializer.serialize(value).trim()); textRepresentation.append(elements.getRightParenthesisKeyword()); } else if (!annotation.getElementValuePairs().isEmpty()) { textRepresentation.append(elements.getLeftParenthesisKeyword()); boolean addComa = false; for (final XAnnotationElementValuePair pair : annotation.getElementValuePairs()) { if (addComa) { textRepresentation.append(elements.getCommaKeyword()); } else { addComa = true; } textRepresentation.append(elements.getEqualsSignKeyword()); textRepresentation.append(serializer.serialize(pair.getValue()).trim()); } textRepresentation.append(elements.getRightParenthesisKeyword()); } }
Example #3
Source File: XtendAnnotationReferenceImpl.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected XExpression findValue(final String property) { XExpression _xblockexpression = null; { if ((Objects.equal(property, "value") && (this.getDelegate().getValue() != null))) { return this.getDelegate().getValue(); } final Function1<XAnnotationElementValuePair, Boolean> _function = (XAnnotationElementValuePair it) -> { String _simpleName = it.getElement().getSimpleName(); return Boolean.valueOf(Objects.equal(_simpleName, property)); }; XAnnotationElementValuePair _findFirst = IterableExtensions.<XAnnotationElementValuePair>findFirst(this.getDelegate().getElementValuePairs(), _function); XExpression _value = null; if (_findFirst!=null) { _value=_findFirst.getValue(); } _xblockexpression = _value; } return _xblockexpression; }
Example #4
Source File: ConstantExpressionsInterpreter.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
private boolean isEnumExpectationInAnnotationValue(final XFeatureCall it, final JvmType expectedRawType) { if (((expectedRawType instanceof JvmEnumerationType) || ((expectedRawType instanceof JvmArrayType) && (((JvmArrayType) expectedRawType).getComponentType() instanceof JvmEnumerationType)))) { EObject container = it.eContainer(); if ((container instanceof XAnnotationElementValuePair)) { return true; } if ((container instanceof XAnnotation)) { return true; } if ((container instanceof XListLiteral)) { container = ((XListLiteral)container).eContainer(); if ((container instanceof XAnnotationElementValuePair)) { return true; } if ((container instanceof XAnnotation)) { return true; } } } return false; }
Example #5
Source File: ConstantExpressionsInterpreterTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testAnnotationValues() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("@test.Annotation([email protected](\'foo\'))"); _builder.newLine(); _builder.append("class C { "); _builder.newLine(); _builder.append("}"); _builder.newLine(); final XtendFile file = this.file(_builder.toString()); final XAnnotationElementValuePair pair = IterableExtensions.<XAnnotationElementValuePair>head(IterableExtensions.<XAnnotation>head(IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes()).getAnnotations()).getElementValuePairs()); Object _evaluate = this.interpreter.evaluate(pair.getValue(), pair.getElement().getReturnType()); final XAnnotation anno = ((XAnnotation) _evaluate); Assert.assertEquals("test.Annotation2", anno.getAnnotationType().getIdentifier()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example #6
Source File: JvmTypesBuilderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@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); } }
Example #7
Source File: JvmTypesBuilderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@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); } }
Example #8
Source File: XbaseCompiler.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
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(")"); } }
Example #9
Source File: XAnnotationsPackageImpl.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
/** * 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); }
Example #10
Source File: XAnnotationImpl.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public EList<XAnnotationElementValuePair> getElementValuePairs() { if (elementValuePairs == null) { elementValuePairs = new EObjectContainmentEList<XAnnotationElementValuePair>(XAnnotationElementValuePair.class, this, XAnnotationsPackage.XANNOTATION__ELEMENT_VALUE_PAIRS); } return elementValuePairs; }
Example #11
Source File: AbstractXbaseWithAnnotationsSemanticSequencer.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
/** * Contexts: * XAnnotationElementValuePair returns XAnnotationElementValuePair * * Constraint: * (element=[JvmOperation|ValidID] value=XAnnotationElementValue) */ protected void sequence_XAnnotationElementValuePair(ISerializationContext context, XAnnotationElementValuePair semanticObject) { if (errorAcceptor != null) { if (transientValues.isValueTransient(semanticObject, XAnnotationsPackage.Literals.XANNOTATION_ELEMENT_VALUE_PAIR__ELEMENT) == ValueTransient.YES) errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XAnnotationsPackage.Literals.XANNOTATION_ELEMENT_VALUE_PAIR__ELEMENT)); if (transientValues.isValueTransient(semanticObject, XAnnotationsPackage.Literals.XANNOTATION_ELEMENT_VALUE_PAIR__VALUE) == ValueTransient.YES) errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XAnnotationsPackage.Literals.XANNOTATION_ELEMENT_VALUE_PAIR__VALUE)); } SequenceFeeder feeder = createSequencerFeeder(context, semanticObject); feeder.accept(grammarAccess.getXAnnotationElementValuePairAccess().getElementJvmOperationValidIDParserRuleCall_0_0_0_0_1(), semanticObject.eGet(XAnnotationsPackage.Literals.XANNOTATION_ELEMENT_VALUE_PAIR__ELEMENT, false)); feeder.accept(grammarAccess.getXAnnotationElementValuePairAccess().getValueXAnnotationElementValueParserRuleCall_1_0(), semanticObject.getValue()); feeder.finish(); }
Example #12
Source File: XAnnotationUtil.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
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; }
Example #13
Source File: XbaseWithAnnotationsProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public void completeXFeatureCall_Feature(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { if (model instanceof XAnnotation) { createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.WITHIN, context, acceptor); return; } else if (model instanceof XAnnotationElementValuePair) { XAnnotationElementValuePair pair = (XAnnotationElementValuePair) model; XAnnotation annotation = (XAnnotation) pair.eContainer(); createLocalVariableAndImplicitProposals(annotation, IExpressionScope.Anchor.WITHIN, context, acceptor); return; } super.completeXFeatureCall_Feature(model, assignment, context, acceptor); }
Example #14
Source File: XbaseWithAnnotationsTypeComputer.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
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); } } }
Example #15
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 #16
Source File: JvmTypesBuilder.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
/** * 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; }
Example #17
Source File: ErrorTest.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Test public void testErrorModel_01() throws Exception { XAnnotation annotation = processWithoutException("estdata.Annotation2(value = 'foo')"); XAnnotationElementValuePair singleValuePair = Iterables.getFirst(annotation.getElementValuePairs(), null); Assert.assertNotNull(batchTypeResolver.resolveTypes(annotation).getActualType(singleValuePair.getValue())); }
Example #18
Source File: AbstractXbaseWithAnnotationsSemanticSequencer.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Deprecated protected void sequence_XAnnotationElementValuePair(EObject context, XAnnotationElementValuePair semanticObject) { sequence_XAnnotationElementValuePair(createContext(context, semanticObject), semanticObject); }