use of org.eclipse.xtext.common.types.JvmUpperBound in project xtext-eclipse by eclipse.
the class JdtBasedTypeFactory method createTypeParameter.
protected JvmTypeParameter createTypeParameter(ITypeBinding parameter, JvmMember container) {
resolveTypeParams.start();
JvmTypeParameter result = TypesFactory.eINSTANCE.createJvmTypeParameter();
result.setName(parameter.getName());
InternalEList<JvmTypeConstraint> constraints = (InternalEList<JvmTypeConstraint>) result.getConstraints();
ITypeBinding[] typeBounds = parameter.getTypeBounds();
if (typeBounds.length != 0) {
for (ITypeBinding bound : typeBounds) {
JvmUpperBound upperBound = TypesFactory.eINSTANCE.createJvmUpperBound();
upperBound.setTypeReference(createTypeReference(bound));
constraints.addUnique(upperBound);
}
} else {
JvmUpperBound upperBound = TypesFactory.eINSTANCE.createJvmUpperBound();
upperBound.setTypeReference(createObjectClassReference());
constraints.addUnique(upperBound);
}
resolveTypeParams.stop();
return result;
}
use of org.eclipse.xtext.common.types.JvmUpperBound in project xtext-eclipse by eclipse.
the class JdtBasedTypeFactory method createTypeArgument.
protected JvmTypeReference createTypeArgument(ITypeBinding argument) {
if (argument.isWildcardType()) {
JvmWildcardTypeReference result = TypesFactory.eINSTANCE.createJvmWildcardTypeReference();
InternalEList<JvmTypeConstraint> constraints = (InternalEList<JvmTypeConstraint>) result.getConstraints();
JvmUpperBound upperBound = TypesFactory.eINSTANCE.createJvmUpperBound();
ITypeBinding bound = argument.getBound();
if (argument.isUpperbound()) {
JvmTypeReference reference = createTypeReference(bound);
upperBound.setTypeReference(reference);
constraints.addUnique(upperBound);
} else {
JvmTypeReference objectReference = createObjectClassReference();
upperBound.setTypeReference(objectReference);
constraints.addUnique(upperBound);
if (bound != null) {
JvmLowerBound lowerBound = TypesFactory.eINSTANCE.createJvmLowerBound();
JvmTypeReference reference = createTypeReference(bound);
lowerBound.setTypeReference(reference);
constraints.addUnique(lowerBound);
}
}
return result;
} else {
return createTypeReference(argument);
}
}
use of org.eclipse.xtext.common.types.JvmUpperBound in project xtext-eclipse by eclipse.
the class AbstractTypeProviderTest method testFindTypeByName_javaUtilList_01.
@Test
public void testFindTypeByName_javaUtilList_01() {
String typeName = List.class.getName();
JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
assertNotNull(type);
assertEquals(typeName, type.getIdentifier());
assertEquals(1, type.getTypeParameters().size());
JvmTypeParameter typeVariable = type.getTypeParameters().get(0);
assertEquals("E", typeVariable.getName());
assertEquals(1, typeVariable.getConstraints().size());
JvmTypeConstraint typeConstraint = typeVariable.getConstraints().get(0);
assertTrue(typeConstraint instanceof JvmUpperBound);
JvmUpperBound upperBound = (JvmUpperBound) typeConstraint;
assertSame(typeVariable, upperBound.getOwner());
assertNotNull(upperBound.getTypeReference());
assertFalse(upperBound.getTypeReference().getType().eIsProxy());
assertEquals(Object.class.getName(), upperBound.getTypeReference().getIdentifier());
diagnose(type);
Resource resource = type.eResource();
getAndResolveAllFragments(resource);
recomputeAndCheckIdentifiers(resource);
}
use of org.eclipse.xtext.common.types.JvmUpperBound in project xtext-eclipse by eclipse.
the class AbstractTypeProviderTest method test_ParameterizedTypes_W_01.
@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());
}
use of org.eclipse.xtext.common.types.JvmUpperBound in project xtext-eclipse by eclipse.
the class AbstractTypeProviderTest method test_ParameterizedTypes_S_01.
@Test
public void test_ParameterizedTypes_S_01() {
String typeName = ParameterizedTypes.class.getName();
JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
JvmTypeParameter typeVariable = type.getTypeParameters().get(0);
assertEquals("S", 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());
assertEquals("java.lang.Object", upperBound.getTypeReference().getIdentifier());
}
Aggregations