Search in sources :

Example 1 with JvmArrayType

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

the class AbstractTypeProviderTest method test_nestedArrayWildcard_02.

@Test
public void test_nestedArrayWildcard_02() {
    JvmOperation nestedArrayWildcard = getMethodFromParameterizedMethods("nestedArrayWildcard(java.util.List[][])");
    JvmTypeReference paramType = nestedArrayWildcard.getParameters().get(0).getParameterType();
    assertTrue(paramType.getType() instanceof JvmArrayType);
    JvmArrayType arrayType = (JvmArrayType) paramType.getType();
    assertTrue(arrayType.getComponentType() instanceof JvmArrayType);
    arrayType = (JvmArrayType) arrayType.getComponentType();
    assertTrue(arrayType.getComponentType() instanceof JvmDeclaredType);
    assertTrue(paramType instanceof JvmGenericArrayTypeReference);
    JvmGenericArrayTypeReference paramTypeAsArray = (JvmGenericArrayTypeReference) paramType;
    assertTrue(paramTypeAsArray.getComponentType() instanceof JvmGenericArrayTypeReference);
    paramTypeAsArray = (JvmGenericArrayTypeReference) paramTypeAsArray.getComponentType();
    assertTrue(paramTypeAsArray.getComponentType() instanceof JvmParameterizedTypeReference);
    JvmParameterizedTypeReference listWithWildcard = (JvmParameterizedTypeReference) paramTypeAsArray.getComponentType();
    assertTrue(listWithWildcard.getArguments().get(0) instanceof JvmWildcardTypeReference);
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmGenericArrayTypeReference(org.eclipse.xtext.common.types.JvmGenericArrayTypeReference) JvmWildcardTypeReference(org.eclipse.xtext.common.types.JvmWildcardTypeReference) 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 2 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 3 with JvmArrayType

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

the class AbstractTypeProviderTest method test_nestedArrayParameterized_02.

@Test
public void test_nestedArrayParameterized_02() {
    JvmOperation nestedArrayParameterized = getMethodFromParameterizedMethods("nestedArrayParameterized(java.util.List[][])");
    JvmTypeReference paramType = nestedArrayParameterized.getParameters().get(0).getParameterType();
    assertTrue(paramType.getType() instanceof JvmArrayType);
    JvmArrayType arrayType = (JvmArrayType) paramType.getType();
    assertTrue(arrayType.getComponentType() instanceof JvmArrayType);
    arrayType = (JvmArrayType) arrayType.getComponentType();
    assertTrue(arrayType.getComponentType() instanceof JvmDeclaredType);
    assertTrue(paramType instanceof JvmGenericArrayTypeReference);
    JvmGenericArrayTypeReference paramTypeAsArray = (JvmGenericArrayTypeReference) paramType;
    assertTrue(paramTypeAsArray.getComponentType() instanceof JvmGenericArrayTypeReference);
    paramTypeAsArray = (JvmGenericArrayTypeReference) paramTypeAsArray.getComponentType();
    assertTrue(paramTypeAsArray.getComponentType() instanceof JvmParameterizedTypeReference);
    JvmParameterizedTypeReference listWithT = (JvmParameterizedTypeReference) paramTypeAsArray.getComponentType();
    assertTrue(listWithT.getArguments().get(0) instanceof JvmParameterizedTypeReference);
    assertEquals("T", listWithT.getArguments().get(0).getType().getSimpleName());
}
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 4 with JvmArrayType

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

the class AbstractTypeProviderTest method testFindTypeByName_int_array_04.

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

Example 5 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)

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