Search in sources :

Example 11 with JvmGenericArrayTypeReference

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

the class XtendJvmModelInferrer method computeFieldName.

/* @Nullable */
protected String computeFieldName(XtendField field) {
    if (field.getName() != null)
        return field.getName();
    JvmTypeReference type = field.getType();
    String name = null;
    if (type != null) {
        while (type instanceof JvmGenericArrayTypeReference) {
            type = ((JvmGenericArrayTypeReference) type).getComponentType();
        }
        if (type instanceof JvmParameterizedTypeReference) {
            List<INode> nodes = NodeModelUtils.findNodesForFeature(type, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
            if (!nodes.isEmpty()) {
                String typeName = nodes.get(0).getText().trim();
                int lastDot = typeName.lastIndexOf('.');
                if (lastDot != -1) {
                    typeName = typeName.substring(lastDot + 1);
                }
                name = "_" + Strings.toFirstLower(typeName);
            }
        }
    }
    return name;
}
Also used : JvmGenericArrayTypeReference(org.eclipse.xtext.common.types.JvmGenericArrayTypeReference) INode(org.eclipse.xtext.nodemodel.INode) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint)

Example 12 with JvmGenericArrayTypeReference

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

the class AbstractTypeProviderTest method test_arrayParameterized_02.

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

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

the class AbstractTypeProviderTest method testVarArgs_02.

@Test
public void testVarArgs_02() {
    String typeName = ClassWithVarArgs.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmOperation method = getMethodFromType(type, ClassWithVarArgs.class, "method(java.lang.String[])");
    assertTrue(method.isVarArgs());
    assertEquals(1, method.getParameters().size());
    assertTrue(method.getParameters().get(0).getParameterType() instanceof JvmGenericArrayTypeReference);
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmGenericArrayTypeReference(org.eclipse.xtext.common.types.JvmGenericArrayTypeReference) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Test(org.junit.Test)

Example 14 with JvmGenericArrayTypeReference

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

the class AbstractTypeProviderTest method test_arrayWildcard_02.

@Test
public void test_arrayWildcard_02() {
    JvmOperation arrayWildcard = getMethodFromParameterizedMethods("arrayWildcard(java.util.List[])");
    JvmTypeReference paramType = arrayWildcard.getParameters().get(0).getParameterType();
    assertEquals("java.util.List<? extends java.lang.Object>[]", paramType.getIdentifier());
    assertTrue(paramType.getType() instanceof JvmArrayType);
    JvmArrayType arrayType = (JvmArrayType) paramType.getType();
    assertTrue(arrayType.getComponentType() instanceof JvmDeclaredType);
    assertTrue(paramType instanceof JvmGenericArrayTypeReference);
    assertTrue(((JvmGenericArrayTypeReference) paramType).getComponentType() instanceof JvmParameterizedTypeReference);
}
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 15 with JvmGenericArrayTypeReference

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

the class XtypeProposalProvider method appendParameters.

protected void appendParameters(StyledString result, JvmExecutable executable, int insignificantParameters, LightweightTypeReferenceFactory ownedConverter) {
    List<JvmFormalParameter> declaredParameters = executable.getParameters();
    List<JvmFormalParameter> relevantParameters = declaredParameters.subList(Math.min(insignificantParameters, declaredParameters.size()), declaredParameters.size());
    for (int i = 0; i < relevantParameters.size(); i++) {
        JvmFormalParameter parameter = relevantParameters.get(i);
        if (i != 0)
            result.append(", ");
        if (i == relevantParameters.size() - 1 && executable.isVarArgs() && parameter.getParameterType() instanceof JvmGenericArrayTypeReference) {
            JvmGenericArrayTypeReference parameterType = (JvmGenericArrayTypeReference) parameter.getParameterType();
            result.append(ownedConverter.toLightweightReference(parameterType.getComponentType()).getHumanReadableName());
            result.append("...");
        } else {
            if (parameter.getParameterType() != null) {
                String simpleName = ownedConverter.toLightweightReference(parameter.getParameterType()).getHumanReadableName();
                if (// is null if the file is not on the class path
                simpleName != null)
                    result.append(simpleName);
            }
        }
        result.append(' ');
        result.append(notNull(parameter.getName()));
    }
}
Also used : JvmGenericArrayTypeReference(org.eclipse.xtext.common.types.JvmGenericArrayTypeReference) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) StyledString(org.eclipse.jface.viewers.StyledString)

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