Search in sources :

Example 6 with JvmEnumerationLiteral

use of org.eclipse.xtext.common.types.JvmEnumerationLiteral in project xtext-xtend by eclipse.

the class JvmModelTests method testEnumLiteralIsStatic.

@Test
public void testEnumLiteralIsStatic() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("enum Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("BAR");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        JvmMember _head = IterableExtensions.<JvmMember>head(this._iXtendJvmAssociations.getInferredEnumerationType(this.enumeration(_builder.toString())).getMembers());
        final JvmEnumerationLiteral inferred = ((JvmEnumerationLiteral) _head);
        Assert.assertTrue(inferred.isStatic());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmEnumerationLiteral(org.eclipse.xtext.common.types.JvmEnumerationLiteral) JvmMember(org.eclipse.xtext.common.types.JvmMember) Test(org.junit.Test)

Example 7 with JvmEnumerationLiteral

use of org.eclipse.xtext.common.types.JvmEnumerationLiteral in project xtext-xtend by eclipse.

the class XtendJvmModelInferrer method transform.

protected void transform(XtendEnumLiteral literal, JvmEnumerationType container) {
    if (literal.getName() == null)
        return;
    JvmEnumerationLiteral jvmLiteral = typesFactory.createJvmEnumerationLiteral();
    associator.associatePrimary(literal, jvmLiteral);
    jvmLiteral.setSimpleName(literal.getName());
    jvmLiteral.setVisibility(JvmVisibility.PUBLIC);
    jvmLiteral.setStatic(true);
    jvmLiteral.setFinal(true);
    jvmTypesBuilder.copyDocumentationTo(literal, jvmLiteral);
    for (XAnnotation anno : literal.getAnnotations()) {
        if (!annotationTranslationFilter.apply(anno))
            continue;
        JvmAnnotationReference annotationReference = jvmTypesBuilder.getJvmAnnotationReference(anno);
        if (annotationReference != null)
            jvmLiteral.getAnnotations().add(annotationReference);
    }
    container.getMembers().add(jvmLiteral);
}
Also used : JvmEnumerationLiteral(org.eclipse.xtext.common.types.JvmEnumerationLiteral) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference)

Example 8 with JvmEnumerationLiteral

use of org.eclipse.xtext.common.types.JvmEnumerationLiteral in project xtext-xtend by eclipse.

the class ConstantExpressionsInterpreter method _internalEvaluate.

protected Object _internalEvaluate(final XFeatureCall it, final Context ctx) {
    Object _eGet = it.eGet(XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, this.isResolveProxies(it));
    final EObject feature = ((EObject) _eGet);
    boolean _eIsProxy = feature.eIsProxy();
    boolean _not = (!_eIsProxy);
    if (_not) {
        Object _switchResult = null;
        boolean _matched = false;
        if (feature instanceof JvmEnumerationLiteral) {
            _matched = true;
            _switchResult = feature;
        }
        if (!_matched) {
            if (feature instanceof JvmField) {
                _matched = true;
                _switchResult = this.evaluateField(it, ((JvmField) feature), ctx);
            }
        }
        if (!_matched) {
            if (feature instanceof JvmType) {
                _matched = true;
                _switchResult = this.toTypeReference(((JvmType) feature), 0);
            }
        }
        return _switchResult;
    }
    final String featureName = it.getConcreteSyntaxFeatureName();
    JvmType _switchResult_1 = null;
    JvmTypeReference _expectedType = ctx.getExpectedType();
    final JvmTypeReference it_1 = _expectedType;
    boolean _matched_1 = false;
    if (it_1 instanceof XComputedTypeReferenceImplCustom) {
        boolean _isEquivalentComputed = ((XComputedTypeReferenceImplCustom) it_1).isEquivalentComputed();
        if (_isEquivalentComputed) {
            _matched_1 = true;
            _switchResult_1 = ((XComputedTypeReferenceImplCustom) it_1).getType();
        }
    }
    if (!_matched_1) {
        if (it_1 instanceof XComputedTypeReference) {
            _matched_1 = true;
        }
        if (!_matched_1) {
            if ((it_1 == null)) {
                _matched_1 = true;
            }
        }
        if (_matched_1) {
            _switchResult_1 = null;
        }
    }
    if (!_matched_1) {
        _switchResult_1 = it_1.getType();
    }
    final JvmType expectedRawType = _switchResult_1;
    Map<String, JvmIdentifiableElement> _xifexpression = null;
    boolean _isEnumExpectationInAnnotationValue = this.isEnumExpectationInAnnotationValue(it, expectedRawType);
    if (_isEnumExpectationInAnnotationValue) {
        HashMap<String, JvmIdentifiableElement> _xblockexpression = null;
        {
            JvmEnumerationType _switchResult_2 = null;
            boolean _matched_2 = false;
            if (expectedRawType instanceof JvmEnumerationType) {
                _matched_2 = true;
                _switchResult_2 = ((JvmEnumerationType) expectedRawType);
            }
            if (!_matched_2) {
                if (expectedRawType instanceof JvmArrayType) {
                    _matched_2 = true;
                    JvmComponentType _componentType = ((JvmArrayType) expectedRawType).getComponentType();
                    _switchResult_2 = ((JvmEnumerationType) _componentType);
                }
            }
            final JvmEnumerationType enumType = _switchResult_2;
            Map<String, JvmIdentifiableElement> _visibleFeatures = ctx.getVisibleFeatures();
            final HashMap<String, JvmIdentifiableElement> copy = new HashMap<String, JvmIdentifiableElement>(_visibleFeatures);
            final Consumer<JvmEnumerationLiteral> _function = (JvmEnumerationLiteral it_2) -> {
                copy.put(it_2.getSimpleName(), it_2);
            };
            enumType.getLiterals().forEach(_function);
            _xblockexpression = copy;
        }
        _xifexpression = _xblockexpression;
    } else {
        _xifexpression = ctx.getVisibleFeatures();
    }
    final Map<String, JvmIdentifiableElement> visibleFeatures = _xifexpression;
    boolean _containsKey = visibleFeatures.containsKey(featureName);
    if (_containsKey) {
        Object _switchResult_2 = null;
        JvmIdentifiableElement _get = visibleFeatures.get(featureName);
        final JvmIdentifiableElement visibleFeature = _get;
        boolean _matched_2 = false;
        if (visibleFeature instanceof JvmEnumerationLiteral) {
            _matched_2 = true;
            JvmEnumerationLiteral _xblockexpression_1 = null;
            {
                this.resolveFeature(it, visibleFeature);
                _xblockexpression_1 = ((JvmEnumerationLiteral) visibleFeature);
            }
            _switchResult_2 = _xblockexpression_1;
        }
        if (!_matched_2) {
            if (visibleFeature instanceof JvmField) {
                _matched_2 = true;
                Object _xblockexpression_1 = null;
                {
                    this.resolveFeature(it, visibleFeature);
                    _xblockexpression_1 = this.evaluateField(it, ((JvmField) visibleFeature), ctx);
                }
                _switchResult_2 = _xblockexpression_1;
            }
        }
        return _switchResult_2;
    }
    final JvmType type = this.findTypeByName(it, featureName);
    if ((type != null)) {
        this.resolveType(it, type);
        return this.toTypeReference(type, 0);
    }
    throw new UnresolvableFeatureException(("Couldn\'t resolve feature " + featureName), it);
}
Also used : JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) HashMap(java.util.HashMap) JvmComponentType(org.eclipse.xtext.common.types.JvmComponentType) XComputedTypeReference(org.eclipse.xtext.xtype.XComputedTypeReference) UnresolvableFeatureException(org.eclipse.xtext.xbase.interpreter.UnresolvableFeatureException) JvmType(org.eclipse.xtext.common.types.JvmType) Consumer(java.util.function.Consumer) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) XComputedTypeReferenceImplCustom(org.eclipse.xtext.xtype.impl.XComputedTypeReferenceImplCustom) JvmEnumerationLiteral(org.eclipse.xtext.common.types.JvmEnumerationLiteral) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) JvmField(org.eclipse.xtext.common.types.JvmField) JvmEnumerationType(org.eclipse.xtext.common.types.JvmEnumerationType) Map(java.util.Map) HashMap(java.util.HashMap) JvmArrayType(org.eclipse.xtext.common.types.JvmArrayType)

Example 9 with JvmEnumerationLiteral

use of org.eclipse.xtext.common.types.JvmEnumerationLiteral in project xtext-xtend by eclipse.

the class CompilationUnitImpl method translate.

protected Object translate(final Object object) {
    if ((object instanceof XAnnotation[])) {
        final AnnotationReference[] result = new AnnotationReference[((Object[]) object).length];
        int _length = ((Object[]) object).length;
        ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _length, true);
        for (final Integer i : _doubleDotLessThan) {
            result[(i).intValue()] = this.translateAnnotation(((XAnnotation[]) object)[(i).intValue()]);
        }
        return result;
    }
    if ((object instanceof XAnnotation)) {
        return this.translateAnnotation(((XAnnotation) object));
    }
    if ((object instanceof JvmTypeReference[])) {
        final TypeReference[] result_1 = new TypeReference[((Object[]) object).length];
        int _length_1 = ((Object[]) object).length;
        ExclusiveRange _doubleDotLessThan_1 = new ExclusiveRange(0, _length_1, true);
        for (final Integer i_1 : _doubleDotLessThan_1) {
            Object _translate = this.translate(((Object[]) object)[(i_1).intValue()]);
            result_1[(i_1).intValue()] = ((TypeReference) _translate);
        }
        return result_1;
    }
    if ((object instanceof JvmTypeReference)) {
        return this.toTypeReference(((JvmTypeReference) object));
    }
    if ((object instanceof JvmEnumerationLiteral[])) {
        final EnumerationValueDeclaration[] result_2 = new EnumerationValueDeclaration[((Object[]) object).length];
        int _length_2 = ((Object[]) object).length;
        ExclusiveRange _doubleDotLessThan_2 = new ExclusiveRange(0, _length_2, true);
        for (final Integer i_2 : _doubleDotLessThan_2) {
            Object _translate_1 = this.translate(((Object[]) object)[(i_2).intValue()]);
            result_2[(i_2).intValue()] = ((EnumerationValueDeclaration) _translate_1);
        }
        return result_2;
    }
    if ((object instanceof JvmEnumerationLiteral)) {
        return this.toMemberDeclaration(((JvmMember) object));
    }
    return object;
}
Also used : ExclusiveRange(org.eclipse.xtext.xbase.lib.ExclusiveRange) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) JvmEnumerationLiteral(org.eclipse.xtext.common.types.JvmEnumerationLiteral) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) AnnotationReference(org.eclipse.xtend.lib.macro.declaration.AnnotationReference) EObject(org.eclipse.emf.ecore.EObject) JvmMember(org.eclipse.xtext.common.types.JvmMember) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) TypeReference(org.eclipse.xtend.lib.macro.declaration.TypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) EnumerationValueDeclaration(org.eclipse.xtend.lib.macro.declaration.EnumerationValueDeclaration)

Example 10 with JvmEnumerationLiteral

use of org.eclipse.xtext.common.types.JvmEnumerationLiteral in project xtext-xtend by eclipse.

the class MutableJvmEnumerationTypeDeclarationImpl method addValue.

@Override
public MutableEnumerationValueDeclaration addValue(final String name, final Procedure1<MutableEnumerationValueDeclaration> initializer) {
    this.checkMutable();
    ConditionUtils.checkJavaIdentifier(name, "name");
    Preconditions.checkArgument((initializer != null), "initializer cannot be null");
    final JvmEnumerationLiteral jvmLiteral = TypesFactory.eINSTANCE.createJvmEnumerationLiteral();
    jvmLiteral.setSimpleName(name);
    jvmLiteral.setVisibility(JvmVisibility.PUBLIC);
    this.getDelegate().getMembers().add(jvmLiteral);
    MemberDeclaration _memberDeclaration = this.getCompilationUnit().toMemberDeclaration(jvmLiteral);
    final MutableEnumerationValueDeclaration mutableEnumerationValueDeclaration = ((MutableEnumerationValueDeclaration) _memberDeclaration);
    initializer.apply(mutableEnumerationValueDeclaration);
    return mutableEnumerationValueDeclaration;
}
Also used : MutableMemberDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableMemberDeclaration) MemberDeclaration(org.eclipse.xtend.lib.macro.declaration.MemberDeclaration) MutableEnumerationValueDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableEnumerationValueDeclaration) JvmEnumerationLiteral(org.eclipse.xtext.common.types.JvmEnumerationLiteral)

Aggregations

JvmEnumerationLiteral (org.eclipse.xtext.common.types.JvmEnumerationLiteral)10 EObject (org.eclipse.emf.ecore.EObject)4 JvmMember (org.eclipse.xtext.common.types.JvmMember)4 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)4 JvmAnnotationReference (org.eclipse.xtext.common.types.JvmAnnotationReference)3 JvmEnumerationType (org.eclipse.xtext.common.types.JvmEnumerationType)3 JvmField (org.eclipse.xtext.common.types.JvmField)3 JvmType (org.eclipse.xtext.common.types.JvmType)3 HashMap (java.util.HashMap)2 InternalEObject (org.eclipse.emf.ecore.InternalEObject)2 AnnotationReference (org.eclipse.xtend.lib.macro.declaration.AnnotationReference)2 EnumerationValueDeclaration (org.eclipse.xtend.lib.macro.declaration.EnumerationValueDeclaration)2 MemberDeclaration (org.eclipse.xtend.lib.macro.declaration.MemberDeclaration)2 TypeReference (org.eclipse.xtend.lib.macro.declaration.TypeReference)2 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)2 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)2 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)2 XAnnotation (org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation)2 Test (org.junit.Test)2 Provider (com.google.inject.Provider)1