Java 类org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotationElementValuePair 实例源码

项目:xtext-extras    文件:XbaseCompiler.java   
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(")");
    }
}
项目:xtext-extras    文件:XAnnotationImpl.java   
/**
 * <!-- 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);
}
项目:xtext-extras    文件:JvmTypesBuilderTest.java   
@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);
  }
}
项目:xtext-extras    文件:JvmTypesBuilderTest.java   
@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);
  }
}
项目:xtext-extras    文件:AbstractXbaseWithAnnotationsSemanticSequencer.java   
/**
 * 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();
}
项目:xtext-extras    文件:JvmTypesBuilder.java   
/**
 * 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;
}
项目:xtext-extras    文件:UnresolvedAnnotationTypeAwareMessageProvider.java   
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;
}
项目:xtext-extras    文件:XbaseWithAnnotationsTypeComputer.java   
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);
        }
    }
}
项目:xtext-extras    文件:XAnnotationUtil.java   
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;
}
项目:xtext-extras    文件:XAnnotationsPackageImpl.java   
/**
 * 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);
}
项目:xtext-extras    文件:XAnnotationImpl.java   
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public EList<XAnnotationElementValuePair> getElementValuePairs()
{
    if (elementValuePairs == null)
    {
        elementValuePairs = new EObjectContainmentEList<XAnnotationElementValuePair>(XAnnotationElementValuePair.class, this, XAnnotationsPackage.XANNOTATION__ELEMENT_VALUE_PAIRS);
    }
    return elementValuePairs;
}
项目:xtext-extras    文件:ErrorTest.java   
@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()));
}
项目:dsl-devkit    文件:AbstractCheckSemanticSequencer.java   
/**
 * Constraint:
 *     (element=[JvmOperation|ValidID] value=XAnnotationElementValue)
 */
protected void sequence_XAnnotationElementValuePair(EObject context, XAnnotationElementValuePair semanticObject) {
    if(errorAcceptor != null) {
        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));
        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));
    }
    INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
    SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
    feeder.accept(grammarAccess.getXAnnotationElementValuePairAccess().getElementJvmOperationValidIDParserRuleCall_0_0_0_0_1(), semanticObject.getElement());
    feeder.accept(grammarAccess.getXAnnotationElementValuePairAccess().getValueXAnnotationElementValueParserRuleCall_1_0(), semanticObject.getValue());
    feeder.finish();
}
项目:xtext-extras    文件:AbstractXbaseWithAnnotationsSemanticSequencer.java   
@Deprecated
protected void sequence_XAnnotationElementValuePair(EObject context, XAnnotationElementValuePair semanticObject) {
    sequence_XAnnotationElementValuePair(createContext(context, semanticObject), semanticObject);
}