Search in sources :

Example 11 with JvmArrayType

use of org.eclipse.xtext.common.types.JvmArrayType 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 12 with JvmArrayType

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

the class AbstractTypeProviderTest method testFindTypeByName_javaLangNumber_02.

@Test
public void testFindTypeByName_javaLangNumber_02() {
    String typeName = Number[][].class.getName();
    JvmArrayType type = (JvmArrayType) getTypeProvider().findTypeByName(typeName);
    JvmOperation longValue = (JvmOperation) type.eResource().getEObject("java.lang.Number.longValue()");
    assertNotNull(longValue);
    JvmDeclaredType number = longValue.getDeclaringType();
    assertNotNull(number.getArrayType());
    assertSame(type, number.getArrayType().getArrayType());
    assertNull(type.eGet(TypesPackage.Literals.JVM_COMPONENT_TYPE__ARRAY_TYPE));
    // array will created on the fly
    assertNotNull(type.getArrayType());
    diagnose(type);
    Resource resource = type.eResource();
    getAndResolveAllFragments(resource);
    recomputeAndCheckIdentifiers(resource);
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) Resource(org.eclipse.emf.ecore.resource.Resource) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmArrayType(org.eclipse.xtext.common.types.JvmArrayType) Test(org.junit.Test)

Example 13 with JvmArrayType

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

the class AbstractTypeProviderTest method test_ParameterizedTypes_Inner_07.

@Test
public void test_ParameterizedTypes_Inner_07() {
    String typeName = ParameterizedTypes.Inner.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmOperation methodV = getMethodFromType(type, ParameterizedTypes.Inner.class, "methodZArray_01()");
    JvmTypeReference listZ = methodV.getReturnType();
    assertEquals("java.util.List<Z[][]>", listZ.getIdentifier());
    JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) listZ;
    assertEquals(1, listType.getArguments().size());
    JvmTypeReference typeArgument = listType.getArguments().get(0);
    JvmType argumentType = typeArgument.getType();
    assertTrue(argumentType instanceof JvmArrayType);
    assertTrue(((JvmArrayType) argumentType).getComponentType() instanceof JvmArrayType);
    JvmComponentType componentType = ((JvmArrayType) ((JvmArrayType) argumentType).getComponentType()).getComponentType();
    JvmTypeParameter z = type.getTypeParameters().get(2);
    assertSame(z, componentType);
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmComponentType(org.eclipse.xtext.common.types.JvmComponentType) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmType(org.eclipse.xtext.common.types.JvmType) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference) ParameterizedTypes(org.eclipse.xtext.common.types.testSetups.ParameterizedTypes) JvmArrayType(org.eclipse.xtext.common.types.JvmArrayType) Test(org.junit.Test)

Example 14 with JvmArrayType

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

the class AbstractTypeProviderTest method test_arrayParameterized_02.

@Test
public void test_arrayParameterized_02() {
    JvmOperation arrayParameterized = getMethodFromParameterizedMethods("arrayParameterized(java.util.List[])");
    JvmTypeReference paramType = arrayParameterized.getParameters().get(0).getParameterType();
    assertEquals("java.util.List<T>[]", paramType.getIdentifier());
    assertTrue(paramType.getType() instanceof JvmArrayType);
    JvmArrayType arrayType = (JvmArrayType) paramType.getType();
    assertTrue(arrayType.getComponentType() instanceof JvmDeclaredType);
    assertTrue(paramType instanceof JvmGenericArrayTypeReference);
    assertTrue(((JvmGenericArrayTypeReference) paramType).getComponentType() instanceof JvmParameterizedTypeReference);
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmGenericArrayTypeReference(org.eclipse.xtext.common.types.JvmGenericArrayTypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference) JvmArrayType(org.eclipse.xtext.common.types.JvmArrayType) Test(org.junit.Test)

Example 15 with JvmArrayType

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

the class AbstractTypeProviderTest method testFindTypeByName_int_array_02.

@Test
public void testFindTypeByName_int_array_02() {
    String typeName = int[].class.getName();
    JvmType type = getTypeProvider().findTypeByName(typeName);
    assertNotNull(type);
    assertTrue(type instanceof JvmArrayType);
    assertEquals("int[]", type.getIdentifier());
}
Also used : JvmType(org.eclipse.xtext.common.types.JvmType) JvmArrayType(org.eclipse.xtext.common.types.JvmArrayType) Test(org.junit.Test)

Aggregations

JvmArrayType (org.eclipse.xtext.common.types.JvmArrayType)18 Test (org.junit.Test)16 JvmType (org.eclipse.xtext.common.types.JvmType)13 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)10 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)10 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)8 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)6 Resource (org.eclipse.emf.ecore.resource.Resource)5 JvmGenericArrayTypeReference (org.eclipse.xtext.common.types.JvmGenericArrayTypeReference)5 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)5 JvmComponentType (org.eclipse.xtext.common.types.JvmComponentType)3 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)3 ParameterizedTypes (org.eclipse.xtext.common.types.testSetups.ParameterizedTypes)3 IFile (org.eclipse.core.resources.IFile)2 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2 JvmEnumerationLiteral (org.eclipse.xtext.common.types.JvmEnumerationLiteral)2 JvmEnumerationType (org.eclipse.xtext.common.types.JvmEnumerationType)2 JvmWildcardTypeReference (org.eclipse.xtext.common.types.JvmWildcardTypeReference)2 IJvmTypeProvider (org.eclipse.xtext.common.types.access.IJvmTypeProvider)2 HashMap (java.util.HashMap)1