Search in sources :

Example 1 with JvmGenericArrayTypeReference

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;
}
Also used : JvmGenericArrayTypeReference(org.eclipse.xtext.common.types.JvmGenericArrayTypeReference) JvmInnerTypeReference(org.eclipse.xtext.common.types.JvmInnerTypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) InternalEList(org.eclipse.emf.ecore.util.InternalEList) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint)

Example 2 with JvmGenericArrayTypeReference

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);
}
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 3 with JvmGenericArrayTypeReference

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);
}
Also used : JvmGenericArrayTypeReference(org.eclipse.xtext.common.types.JvmGenericArrayTypeReference) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference) Test(org.junit.Test)

Example 4 with 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());
}
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 5 with JvmGenericArrayTypeReference

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());
            }
        }
    }
}
Also used : JvmUpperBound(org.eclipse.xtext.common.types.JvmUpperBound) JvmGenericArrayTypeReference(org.eclipse.xtext.common.types.JvmGenericArrayTypeReference) JvmWildcardTypeReference(org.eclipse.xtext.common.types.JvmWildcardTypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint) JvmType(org.eclipse.xtext.common.types.JvmType) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference)

Aggregations

JvmGenericArrayTypeReference (org.eclipse.xtext.common.types.JvmGenericArrayTypeReference)15 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)10 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)10 Test (org.junit.Test)7 JvmArrayType (org.eclipse.xtext.common.types.JvmArrayType)5 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)5 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)5 JvmType (org.eclipse.xtext.common.types.JvmType)3 JvmTypeConstraint (org.eclipse.xtext.common.types.JvmTypeConstraint)3 JvmWildcardTypeReference (org.eclipse.xtext.common.types.JvmWildcardTypeReference)3 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)2 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)2 JvmInnerTypeReference (org.eclipse.xtext.common.types.JvmInnerTypeReference)2 JvmUpperBound (org.eclipse.xtext.common.types.JvmUpperBound)2 IFile (org.eclipse.core.resources.IFile)1 EObject (org.eclipse.emf.ecore.EObject)1 EPackage (org.eclipse.emf.ecore.EPackage)1 InternalEObject (org.eclipse.emf.ecore.InternalEObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1