Java Code Examples for org.eclipse.xtext.common.types.JvmUpperBound#getTypeReference()
The following examples show how to use
org.eclipse.xtext.common.types.JvmUpperBound#getTypeReference() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void test_ParameterizedTypes_U_01() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmTypeParameter typeVariable = type.getTypeParameters().get(2); assertEquals("U", typeVariable.getIdentifier()); assertSame(type, typeVariable.getDeclarator()); assertEquals(1, typeVariable.getConstraints().size()); JvmTypeConstraint typeConstraint = typeVariable.getConstraints().get(0); assertTrue(typeConstraint instanceof JvmUpperBound); JvmUpperBound upperBound = (JvmUpperBound) typeConstraint; assertNotNull(upperBound.getTypeReference()); assertFalse(upperBound.getTypeReference().toString(), upperBound.getTypeReference().eIsProxy()); assertEquals("java.util.List<S>", upperBound.getTypeReference().getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) upperBound.getTypeReference(); assertEquals(1, listType.getArguments().size()); JvmTypeReference typeArgument = listType.getArguments().get(0); JvmTypeParameter s = type.getTypeParameters().get(0); assertSame(s, typeArgument.getType()); }
Example 2
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void test_ParameterizedTypes_W_01() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmTypeParameter typeParameterW = type.getTypeParameters().get(4); assertEquals("W", typeParameterW.getIdentifier()); assertSame(type, typeParameterW.getDeclarator()); assertEquals(2, typeParameterW.getConstraints().size()); JvmTypeConstraint firstTypeConstraint = typeParameterW.getConstraints().get(0); assertTrue(firstTypeConstraint instanceof JvmUpperBound); JvmUpperBound firstUpperBound = (JvmUpperBound) firstTypeConstraint; assertNotNull(firstUpperBound.getTypeReference()); assertFalse(firstUpperBound.getTypeReference().toString(), firstUpperBound.getTypeReference().eIsProxy()); assertEquals("java.lang.Comparable<S>", firstUpperBound.getTypeReference().getIdentifier()); JvmParameterizedTypeReference comparableType = (JvmParameterizedTypeReference) firstUpperBound .getTypeReference(); assertEquals(1, comparableType.getArguments().size()); JvmTypeReference typeArgument = comparableType.getArguments().get(0); assertEquals("S", typeArgument.getIdentifier()); JvmTypeParameter s = type.getTypeParameters().get(0); assertSame(s, typeArgument.getType()); }
Example 3
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void test_ParameterizedTypes_Inner_Y_01() { String typeName = ParameterizedTypes.Inner.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmTypeParameter typeParameterY = type.getTypeParameters().get(1); assertEquals("Y", typeParameterY.getIdentifier()); assertSame(type, typeParameterY.getDeclarator()); assertEquals(1, typeParameterY.getConstraints().size()); JvmTypeConstraint typeConstraint = typeParameterY.getConstraints().get(0); assertTrue(typeConstraint instanceof JvmUpperBound); JvmUpperBound upperBound = (JvmUpperBound) typeConstraint; assertNotNull(upperBound.getTypeReference()); assertEquals("java.util.List<X>", upperBound.getTypeReference().getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) upperBound.getTypeReference(); assertEquals(1, listType.getArguments().size()); JvmTypeReference typeArgument = listType.getArguments().get(0); assertEquals("X", typeArgument.getIdentifier()); JvmTypeParameter x = type.getTypeParameters().get(0); assertSame(x, typeArgument.getType()); }
Example 4
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void test_ParameterizedTypes_Inner_Z_01() { String typeName = ParameterizedTypes.Inner.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmTypeParameter typeParameterZ = type.getTypeParameters().get(2); assertEquals("Z", typeParameterZ.getIdentifier()); assertSame(type, typeParameterZ.getDeclarator()); assertEquals(1, typeParameterZ.getConstraints().size()); JvmTypeConstraint typeConstraint = typeParameterZ.getConstraints().get(0); assertTrue(typeConstraint instanceof JvmUpperBound); JvmUpperBound upperBound = (JvmUpperBound) typeConstraint; assertNotNull(upperBound.getTypeReference()); assertEquals("java.util.List<W>", upperBound.getTypeReference().getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) upperBound.getTypeReference(); assertEquals(1, listType.getArguments().size()); JvmTypeReference typeArgument = listType.getArguments().get(0); assertEquals("W", typeArgument.getIdentifier()); JvmTypeParameter w = ((JvmTypeParameterDeclarator) type.getDeclaringType()).getTypeParameters().get(4); assertSame(w, typeArgument.getType()); }
Example 5
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void test_ParameterizedTypes_U_01() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmTypeParameter typeVariable = type.getTypeParameters().get(2); assertEquals("U", typeVariable.getIdentifier()); assertSame(type, typeVariable.getDeclarator()); assertEquals(1, typeVariable.getConstraints().size()); JvmTypeConstraint typeConstraint = typeVariable.getConstraints().get(0); assertTrue(typeConstraint instanceof JvmUpperBound); JvmUpperBound upperBound = (JvmUpperBound) typeConstraint; assertNotNull(upperBound.getTypeReference()); assertFalse(upperBound.getTypeReference().toString(), upperBound.getTypeReference().eIsProxy()); assertEquals("java.util.List<S>", upperBound.getTypeReference().getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) upperBound.getTypeReference(); assertEquals(1, listType.getArguments().size()); JvmTypeReference typeArgument = listType.getArguments().get(0); JvmTypeParameter s = type.getTypeParameters().get(0); assertSame(s, typeArgument.getType()); }
Example 6
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void test_ParameterizedTypes_W_01() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmTypeParameter typeParameterW = type.getTypeParameters().get(4); assertEquals("W", typeParameterW.getIdentifier()); assertSame(type, typeParameterW.getDeclarator()); assertEquals(2, typeParameterW.getConstraints().size()); JvmTypeConstraint firstTypeConstraint = typeParameterW.getConstraints().get(0); assertTrue(firstTypeConstraint instanceof JvmUpperBound); JvmUpperBound firstUpperBound = (JvmUpperBound) firstTypeConstraint; assertNotNull(firstUpperBound.getTypeReference()); assertFalse(firstUpperBound.getTypeReference().toString(), firstUpperBound.getTypeReference().eIsProxy()); assertEquals("java.lang.Comparable<S>", firstUpperBound.getTypeReference().getIdentifier()); JvmParameterizedTypeReference comparableType = (JvmParameterizedTypeReference) firstUpperBound .getTypeReference(); assertEquals(1, comparableType.getArguments().size()); JvmTypeReference typeArgument = comparableType.getArguments().get(0); assertEquals("S", typeArgument.getIdentifier()); JvmTypeParameter s = type.getTypeParameters().get(0); assertSame(s, typeArgument.getType()); }
Example 7
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void test_ParameterizedTypes_Inner_Y_01() { String typeName = ParameterizedTypes.Inner.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmTypeParameter typeParameterY = type.getTypeParameters().get(1); assertEquals("Y", typeParameterY.getIdentifier()); assertSame(type, typeParameterY.getDeclarator()); assertEquals(1, typeParameterY.getConstraints().size()); JvmTypeConstraint typeConstraint = typeParameterY.getConstraints().get(0); assertTrue(typeConstraint instanceof JvmUpperBound); JvmUpperBound upperBound = (JvmUpperBound) typeConstraint; assertNotNull(upperBound.getTypeReference()); assertEquals("java.util.List<X>", upperBound.getTypeReference().getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) upperBound.getTypeReference(); assertEquals(1, listType.getArguments().size()); JvmTypeReference typeArgument = listType.getArguments().get(0); assertEquals("X", typeArgument.getIdentifier()); JvmTypeParameter x = type.getTypeParameters().get(0); assertSame(x, typeArgument.getType()); }
Example 8
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Test public void test_ParameterizedTypes_Inner_Z_01() { String typeName = ParameterizedTypes.Inner.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmTypeParameter typeParameterZ = type.getTypeParameters().get(2); assertEquals("Z", typeParameterZ.getIdentifier()); assertSame(type, typeParameterZ.getDeclarator()); assertEquals(1, typeParameterZ.getConstraints().size()); JvmTypeConstraint typeConstraint = typeParameterZ.getConstraints().get(0); assertTrue(typeConstraint instanceof JvmUpperBound); JvmUpperBound upperBound = (JvmUpperBound) typeConstraint; assertNotNull(upperBound.getTypeReference()); assertEquals("java.util.List<W>", upperBound.getTypeReference().getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) upperBound.getTypeReference(); assertEquals(1, listType.getArguments().size()); JvmTypeReference typeArgument = listType.getArguments().get(0); assertEquals("W", typeArgument.getIdentifier()); JvmTypeParameter w = ((JvmTypeParameterDeclarator) type.getDeclaringType()).getTypeParameters().get(4); assertSame(w, typeArgument.getType()); }
Example 9
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void test_ParameterizedTypes_U_01() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmTypeParameter typeVariable = type.getTypeParameters().get(2); assertEquals("U", typeVariable.getIdentifier()); assertSame(type, typeVariable.getDeclarator()); assertEquals(1, typeVariable.getConstraints().size()); JvmTypeConstraint typeConstraint = typeVariable.getConstraints().get(0); assertTrue(typeConstraint instanceof JvmUpperBound); JvmUpperBound upperBound = (JvmUpperBound) typeConstraint; assertNotNull(upperBound.getTypeReference()); assertFalse(upperBound.getTypeReference().toString(), upperBound.getTypeReference().eIsProxy()); assertEquals("java.util.List<S>", upperBound.getTypeReference().getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) upperBound.getTypeReference(); assertEquals(1, listType.getArguments().size()); JvmTypeReference typeArgument = listType.getArguments().get(0); JvmTypeParameter s = type.getTypeParameters().get(0); assertSame(s, typeArgument.getType()); }
Example 10
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void test_ParameterizedTypes_W_01() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmTypeParameter typeParameterW = type.getTypeParameters().get(4); assertEquals("W", typeParameterW.getIdentifier()); assertSame(type, typeParameterW.getDeclarator()); assertEquals(2, typeParameterW.getConstraints().size()); JvmTypeConstraint firstTypeConstraint = typeParameterW.getConstraints().get(0); assertTrue(firstTypeConstraint instanceof JvmUpperBound); JvmUpperBound firstUpperBound = (JvmUpperBound) firstTypeConstraint; assertNotNull(firstUpperBound.getTypeReference()); assertFalse(firstUpperBound.getTypeReference().toString(), firstUpperBound.getTypeReference().eIsProxy()); assertEquals("java.lang.Comparable<S>", firstUpperBound.getTypeReference().getIdentifier()); JvmParameterizedTypeReference comparableType = (JvmParameterizedTypeReference) firstUpperBound .getTypeReference(); assertEquals(1, comparableType.getArguments().size()); JvmTypeReference typeArgument = comparableType.getArguments().get(0); assertEquals("S", typeArgument.getIdentifier()); JvmTypeParameter s = type.getTypeParameters().get(0); assertSame(s, typeArgument.getType()); }
Example 11
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void test_ParameterizedTypes_Inner_Y_01() { String typeName = ParameterizedTypes.Inner.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmTypeParameter typeParameterY = type.getTypeParameters().get(1); assertEquals("Y", typeParameterY.getIdentifier()); assertSame(type, typeParameterY.getDeclarator()); assertEquals(1, typeParameterY.getConstraints().size()); JvmTypeConstraint typeConstraint = typeParameterY.getConstraints().get(0); assertTrue(typeConstraint instanceof JvmUpperBound); JvmUpperBound upperBound = (JvmUpperBound) typeConstraint; assertNotNull(upperBound.getTypeReference()); assertEquals("java.util.List<X>", upperBound.getTypeReference().getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) upperBound.getTypeReference(); assertEquals(1, listType.getArguments().size()); JvmTypeReference typeArgument = listType.getArguments().get(0); assertEquals("X", typeArgument.getIdentifier()); JvmTypeParameter x = type.getTypeParameters().get(0); assertSame(x, typeArgument.getType()); }
Example 12
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Test public void test_ParameterizedTypes_Inner_Z_01() { String typeName = ParameterizedTypes.Inner.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmTypeParameter typeParameterZ = type.getTypeParameters().get(2); assertEquals("Z", typeParameterZ.getIdentifier()); assertSame(type, typeParameterZ.getDeclarator()); assertEquals(1, typeParameterZ.getConstraints().size()); JvmTypeConstraint typeConstraint = typeParameterZ.getConstraints().get(0); assertTrue(typeConstraint instanceof JvmUpperBound); JvmUpperBound upperBound = (JvmUpperBound) typeConstraint; assertNotNull(upperBound.getTypeReference()); assertEquals("java.util.List<W>", upperBound.getTypeReference().getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) upperBound.getTypeReference(); assertEquals(1, listType.getArguments().size()); JvmTypeReference typeArgument = listType.getArguments().get(0); assertEquals("W", typeArgument.getIdentifier()); JvmTypeParameter w = ((JvmTypeParameterDeclarator) type.getDeclaringType()).getTypeParameters().get(4); assertSame(w, typeArgument.getType()); }
Example 13
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void test_ParameterizedTypes_V_01() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmTypeParameter typeParameterV = type.getTypeParameters().get(3); assertEquals("V", typeParameterV.getIdentifier()); assertSame(type, typeParameterV.getDeclarator()); assertEquals(1, typeParameterV.getConstraints().size()); JvmTypeConstraint typeConstraint = typeParameterV.getConstraints().get(0); assertTrue(typeConstraint instanceof JvmUpperBound); JvmUpperBound upperBound = (JvmUpperBound) typeConstraint; assertNotNull(upperBound.getTypeReference()); assertFalse(upperBound.getTypeReference().toString(), upperBound.getTypeReference().eIsProxy()); assertEquals("java.util.List<java.util.List<? extends V>>", upperBound.getTypeReference().getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) upperBound.getTypeReference(); assertEquals(1, listType.getArguments().size()); JvmTypeReference typeArgument = listType.getArguments().get(0); assertEquals("java.util.List<? extends V>", typeArgument.getIdentifier()); JvmParameterizedTypeReference nestedListType = (JvmParameterizedTypeReference) typeArgument; assertEquals(1, nestedListType.getArguments().size()); JvmTypeReference nestedArgument = nestedListType.getArguments().get(0); assertTrue(nestedArgument instanceof JvmWildcardTypeReference); assertEquals(1, ((JvmWildcardTypeReference) nestedArgument).getConstraints().size()); JvmUpperBound nestedUpperBound = (JvmUpperBound) ((JvmWildcardTypeReference) nestedArgument).getConstraints() .get(0); assertSame(typeParameterV, nestedUpperBound.getTypeReference().getType()); }
Example 14
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void test_ParameterizedTypes_V_01() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmTypeParameter typeParameterV = type.getTypeParameters().get(3); assertEquals("V", typeParameterV.getIdentifier()); assertSame(type, typeParameterV.getDeclarator()); assertEquals(1, typeParameterV.getConstraints().size()); JvmTypeConstraint typeConstraint = typeParameterV.getConstraints().get(0); assertTrue(typeConstraint instanceof JvmUpperBound); JvmUpperBound upperBound = (JvmUpperBound) typeConstraint; assertNotNull(upperBound.getTypeReference()); assertFalse(upperBound.getTypeReference().toString(), upperBound.getTypeReference().eIsProxy()); assertEquals("java.util.List<java.util.List<? extends V>>", upperBound.getTypeReference().getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) upperBound.getTypeReference(); assertEquals(1, listType.getArguments().size()); JvmTypeReference typeArgument = listType.getArguments().get(0); assertEquals("java.util.List<? extends V>", typeArgument.getIdentifier()); JvmParameterizedTypeReference nestedListType = (JvmParameterizedTypeReference) typeArgument; assertEquals(1, nestedListType.getArguments().size()); JvmTypeReference nestedArgument = nestedListType.getArguments().get(0); assertTrue(nestedArgument instanceof JvmWildcardTypeReference); assertEquals(1, ((JvmWildcardTypeReference) nestedArgument).getConstraints().size()); JvmUpperBound nestedUpperBound = (JvmUpperBound) ((JvmWildcardTypeReference) nestedArgument).getConstraints() .get(0); assertSame(typeParameterV, nestedUpperBound.getTypeReference().getType()); }
Example 15
Source File: Primitives.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public boolean isWrapperType(JvmType type) { if (typeReferences.is(type, Byte.class)) { return true; } else if (typeReferences.is(type, Short.class)) { return true; } else if (typeReferences.is(type, Character.class)) { return true; } else if (typeReferences.is(type, Integer.class)) { return true; } else if (typeReferences.is(type, Long.class)) { return true; } else if (typeReferences.is(type, Float.class)) { return true; } else if (typeReferences.is(type, Double.class)) { return true; } else if (typeReferences.is(type, Boolean.class)) { return true; } else if (typeReferences.is(type, Void.class)) { return true; } if (type instanceof JvmTypeParameter) { EList<JvmTypeConstraint> constraints = ((JvmTypeParameter)type).getConstraints(); for(JvmUpperBound upperBound: filter(constraints, JvmUpperBound.class)) { JvmTypeReference upperBoundType = upperBound.getTypeReference(); if (isWrapperType(upperBoundType)) return true; } } return false; }
Example 16
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void test_ParameterizedTypes_V_01() { String typeName = ParameterizedTypes.class.getName(); JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName); JvmTypeParameter typeParameterV = type.getTypeParameters().get(3); assertEquals("V", typeParameterV.getIdentifier()); assertSame(type, typeParameterV.getDeclarator()); assertEquals(1, typeParameterV.getConstraints().size()); JvmTypeConstraint typeConstraint = typeParameterV.getConstraints().get(0); assertTrue(typeConstraint instanceof JvmUpperBound); JvmUpperBound upperBound = (JvmUpperBound) typeConstraint; assertNotNull(upperBound.getTypeReference()); assertFalse(upperBound.getTypeReference().toString(), upperBound.getTypeReference().eIsProxy()); assertEquals("java.util.List<java.util.List<? extends V>>", upperBound.getTypeReference().getIdentifier()); JvmParameterizedTypeReference listType = (JvmParameterizedTypeReference) upperBound.getTypeReference(); assertEquals(1, listType.getArguments().size()); JvmTypeReference typeArgument = listType.getArguments().get(0); assertEquals("java.util.List<? extends V>", typeArgument.getIdentifier()); JvmParameterizedTypeReference nestedListType = (JvmParameterizedTypeReference) typeArgument; assertEquals(1, nestedListType.getArguments().size()); JvmTypeReference nestedArgument = nestedListType.getArguments().get(0); assertTrue(nestedArgument instanceof JvmWildcardTypeReference); assertEquals(1, ((JvmWildcardTypeReference) nestedArgument).getConstraints().size()); JvmUpperBound nestedUpperBound = (JvmUpperBound) ((JvmWildcardTypeReference) nestedArgument).getConstraints() .get(0); assertSame(typeParameterV, nestedUpperBound.getTypeReference().getType()); }