Search in sources :

Example 6 with JvmArrayType

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

the class AbstractTypeProviderTest method testFindTypeByName_int_array_03.

@Test
public void testFindTypeByName_int_array_03() {
    String typeName = int[][][].class.getName();
    JvmType type = getTypeProvider().findTypeByName(typeName);
    assertNotNull(type);
    assertTrue(type instanceof JvmArrayType);
    assertEquals("int[][][]", type.getIdentifier());
    diagnose(type);
    Resource resource = type.eResource();
    getAndResolveAllFragments(resource);
    recomputeAndCheckIdentifiers(resource);
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) JvmType(org.eclipse.xtext.common.types.JvmType) JvmArrayType(org.eclipse.xtext.common.types.JvmArrayType) Test(org.junit.Test)

Example 7 with JvmArrayType

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

the class AbstractTypeProviderTest method test_ParameterizedTypes_Inner_08.

@Test
public void test_ParameterizedTypes_Inner_08() {
    String typeName = ParameterizedTypes.Inner.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmOperation methodV = getMethodFromType(type, ParameterizedTypes.Inner.class, "methodZArray_02()");
    JvmTypeReference listZ = methodV.getReturnType();
    assertEquals("java.util.List<Z[]>[]", listZ.getIdentifier());
    JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) ((JvmGenericArrayTypeReference) listZ).getComponentType();
    assertEquals(1, listType.getArguments().size());
    JvmTypeReference typeArgument = listType.getArguments().get(0);
    JvmType argumentType = typeArgument.getType();
    assertTrue(argumentType instanceof JvmArrayType);
    JvmComponentType componentType = ((JvmArrayType) argumentType).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 8 with JvmArrayType

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

the class AbstractTypeProviderTest method test_ParameterizedTypes_Inner_06.

@Test
public void test_ParameterizedTypes_Inner_06() {
    String typeName = ParameterizedTypes.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmOperation methodV = getMethodFromType(type, ParameterizedTypes.Inner.class, "methodVArray_02()");
    JvmTypeReference listV = methodV.getReturnType();
    assertEquals("java.util.List<? extends V[]>", listV.getIdentifier());
    JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) listV;
    assertEquals(1, listType.getArguments().size());
    JvmTypeReference typeArgument = listType.getArguments().get(0);
    assertTrue(typeArgument instanceof JvmWildcardTypeReference);
    JvmWildcardTypeReference wildcardTypeArgument = (JvmWildcardTypeReference) typeArgument;
    assertEquals("? extends V[]", wildcardTypeArgument.getIdentifier());
    assertEquals(1, wildcardTypeArgument.getConstraints().size());
    JvmUpperBound upperBound = (JvmUpperBound) wildcardTypeArgument.getConstraints().get(0);
    JvmType upperBoundType = upperBound.getTypeReference().getType();
    assertTrue(upperBoundType instanceof JvmArrayType);
    assertTrue(((JvmArrayType) upperBoundType).getComponentType() instanceof JvmTypeParameter);
    JvmTypeParameter v = type.getTypeParameters().get(3);
    assertSame(v, ((JvmArrayType) upperBoundType).getComponentType());
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmUpperBound(org.eclipse.xtext.common.types.JvmUpperBound) JvmWildcardTypeReference(org.eclipse.xtext.common.types.JvmWildcardTypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) 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 9 with JvmArrayType

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

the class AbstractTypeProviderTest method testFindTypeByName_int_array_01.

@Test
public void testFindTypeByName_int_array_01() {
    String typeName = "int[]";
    JvmType type = getTypeProvider().findTypeByName(typeName);
    assertNotNull(type);
    assertTrue(type instanceof JvmArrayType);
    assertEquals(typeName, type.getIdentifier());
    diagnose(type);
    Resource resource = type.eResource();
    getAndResolveAllFragments(resource);
    recomputeAndCheckIdentifiers(resource);
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) JvmType(org.eclipse.xtext.common.types.JvmType) JvmArrayType(org.eclipse.xtext.common.types.JvmArrayType) Test(org.junit.Test)

Example 10 with JvmArrayType

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

the class ConstantExpressionsInterpreter method getJavaType.

protected Class<?> getJavaType(final JvmType type, final ClassFinder classFinder) throws ClassNotFoundException {
    if ((type instanceof JvmArrayType)) {
        JvmType t = type;
        String dimensions = "";
        while ((t instanceof JvmArrayType)) {
            {
                dimensions = (dimensions + "[]");
                t = ((JvmArrayType) t).getComponentType();
            }
        }
        final Class<?> componentClass = this.getJavaType(t, classFinder);
        String _name = componentClass.getName();
        String _plus = (_name + dimensions);
        return classFinder.forName(_plus);
    }
    String _identifier = type.getIdentifier();
    boolean _equals = Objects.equal(_identifier, "java.lang.Class");
    if (_equals) {
        return JvmTypeReference.class;
    }
    if ((type instanceof JvmEnumerationType)) {
        return JvmEnumerationLiteral.class;
    }
    if ((type instanceof JvmAnnotationType)) {
        return XAnnotation.class;
    }
    return classFinder.forName(type.getIdentifier());
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmEnumerationLiteral(org.eclipse.xtext.common.types.JvmEnumerationLiteral) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) JvmType(org.eclipse.xtext.common.types.JvmType) JvmEnumerationType(org.eclipse.xtext.common.types.JvmEnumerationType) JvmArrayType(org.eclipse.xtext.common.types.JvmArrayType)

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