use of org.eclipse.xtext.common.types.JvmGenericArrayTypeReference in project xtext-eclipse by eclipse.
the class JdtBasedTypeFactory method createTypeReference.
/**
* Returns a type reference for the given type binding. If the binding is null, an {@link JvmUnknownTypeReference unknown}
* type reference is returned.
*/
// @NonNull
protected JvmTypeReference createTypeReference(/* @Nullable */
ITypeBinding typeBinding) {
if (typeBinding == null) {
return TypesFactory.eINSTANCE.createJvmUnknownTypeReference();
}
if (typeBinding.isArray()) {
ITypeBinding componentType = typeBinding.getComponentType();
JvmTypeReference componentTypeReference = createTypeReference(componentType);
JvmGenericArrayTypeReference typeReference = TypesFactory.eINSTANCE.createJvmGenericArrayTypeReference();
typeReference.setComponentType(componentTypeReference);
return typeReference;
}
ITypeBinding outer = null;
if (typeBinding.isMember() && !Modifier.isStatic(typeBinding.getModifiers())) {
outer = typeBinding.getDeclaringClass();
}
JvmParameterizedTypeReference result;
if (outer != null) {
JvmParameterizedTypeReference outerReference = (JvmParameterizedTypeReference) createTypeReference(outer);
result = TypesFactory.eINSTANCE.createJvmInnerTypeReference();
((JvmInnerTypeReference) result).setOuter(outerReference);
} else {
result = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference();
}
ITypeBinding[] typeArguments = typeBinding.getTypeArguments();
if (typeArguments.length != 0) {
ITypeBinding erasure = typeBinding.getErasure();
result.setType(createProxy(erasure));
InternalEList<JvmTypeReference> arguments = (InternalEList<JvmTypeReference>) result.getArguments();
for (int i = 0; i < typeArguments.length; i++) {
JvmTypeReference argument = createTypeArgument(typeArguments[i]);
arguments.addUnique(argument);
}
} else {
result.setType(createProxy(typeBinding));
}
return result;
}
use of org.eclipse.xtext.common.types.JvmGenericArrayTypeReference 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);
}
use of org.eclipse.xtext.common.types.JvmGenericArrayTypeReference in project xtext-eclipse by eclipse.
the class AbstractTypeProviderTest method testVarArgs_03.
@Test
public void testVarArgs_03() {
String typeName = ClassWithVarArgs.class.getName();
JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
JvmConstructor constructor = getConstructorFromType(type, ClassWithVarArgs.class, "ClassWithVarArgs(int,java.lang.String[])");
assertTrue(constructor.isVarArgs());
assertEquals(2, constructor.getParameters().size());
assertTrue(constructor.getParameters().get(0).getParameterType() instanceof JvmParameterizedTypeReference);
assertTrue(constructor.getParameters().get(1).getParameterType() instanceof JvmGenericArrayTypeReference);
}
use of org.eclipse.xtext.common.types.JvmGenericArrayTypeReference 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());
}
use of org.eclipse.xtext.common.types.JvmGenericArrayTypeReference in project xtext-eclipse by eclipse.
the class DomainmodelLabelProvider method append.
protected void append(final StringBuilder builder, final JvmTypeReference typeRef) {
if ((typeRef instanceof JvmParameterizedTypeReference)) {
final JvmType type = ((JvmParameterizedTypeReference) typeRef).getType();
this.append(builder, type);
EList<JvmTypeReference> arguments = ((JvmParameterizedTypeReference) typeRef).getArguments();
boolean _isEmpty = arguments.isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
builder.append("<");
Iterator<JvmTypeReference> iterator = arguments.iterator();
while (iterator.hasNext()) {
{
JvmTypeReference jvmTypeReference = iterator.next();
this.append(builder, jvmTypeReference);
boolean _hasNext = iterator.hasNext();
if (_hasNext) {
builder.append(",");
}
}
}
builder.append(">");
}
} else {
if ((typeRef instanceof JvmWildcardTypeReference)) {
builder.append("?");
Iterator<JvmTypeConstraint> iterator_1 = ((JvmWildcardTypeReference) typeRef).getConstraints().iterator();
while (iterator_1.hasNext()) {
{
JvmTypeConstraint constraint = iterator_1.next();
if ((constraint instanceof JvmUpperBound)) {
builder.append(" extends ");
} else {
builder.append(" super ");
}
this.append(builder, constraint.getTypeReference());
boolean _hasNext = iterator_1.hasNext();
if (_hasNext) {
builder.append(" & ");
}
}
}
} else {
if ((typeRef instanceof JvmGenericArrayTypeReference)) {
this.append(builder, ((JvmGenericArrayTypeReference) typeRef).getType());
}
}
}
}
Aggregations