Search in sources :

Example 1 with JvmGenericType

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

the class JdtBasedTypeFactory method createType.

/**
 * @since 2.4
 */
protected JvmDeclaredType createType(ITypeBinding typeBinding, String handleIdentifier, List<String> path, StringBuilder fqn) {
    if (typeBinding.isAnonymous() || typeBinding.isSynthetic())
        throw new IllegalStateException("Cannot create type for anonymous or synthetic classes");
    // Creates the right type of instance based on the type of binding.
    // 
    JvmGenericType jvmGenericType;
    JvmDeclaredType result;
    if (typeBinding.isAnnotation()) {
        jvmGenericType = null;
        result = TypesFactory.eINSTANCE.createJvmAnnotationType();
    } else if (typeBinding.isEnum()) {
        jvmGenericType = null;
        result = TypesFactory.eINSTANCE.createJvmEnumerationType();
    } else {
        result = jvmGenericType = TypesFactory.eINSTANCE.createJvmGenericType();
        jvmGenericType.setInterface(typeBinding.isInterface());
    }
    // Populate the information computed from the modifiers.
    // 
    int modifiers = typeBinding.getModifiers();
    setTypeModifiers(result, modifiers);
    result.setDeprecated(typeBinding.isDeprecated());
    setVisibility(result, modifiers);
    // Determine the simple name and compose the fully qualified name and path, remembering the fqn length and path size so we can reset them.
    // 
    String simpleName = typeBinding.getName();
    fqn.append(simpleName);
    int length = fqn.length();
    int size = path.size();
    path.add(simpleName);
    String qualifiedName = fqn.toString();
    result.internalSetIdentifier(qualifiedName);
    result.setSimpleName(simpleName);
    // Traverse the nested types using '$' as the qualified name separator.
    // 
    fqn.append('$');
    createNestedTypes(typeBinding, result, handleIdentifier, path, fqn);
    // Traverse the methods using '.'as the qualifed name separator.
    // 
    fqn.setLength(length);
    fqn.append('.');
    createMethods(typeBinding, handleIdentifier, path, fqn, result);
    createFields(typeBinding, fqn, result);
    // Set the super types.
    // 
    setSuperTypes(typeBinding, qualifiedName, result);
    // 
    if (jvmGenericType != null) {
        ITypeBinding[] typeParameterBindings = typeBinding.getTypeParameters();
        if (typeParameterBindings.length > 0) {
            InternalEList<JvmTypeParameter> typeParameters = (InternalEList<JvmTypeParameter>) jvmGenericType.getTypeParameters();
            for (ITypeBinding variable : typeParameterBindings) {
                typeParameters.addUnique(createTypeParameter(variable, result));
            }
        }
    }
    // Populate the annotation values.
    // 
    createAnnotationValues(typeBinding, result);
    // Restore the path.
    // 
    path.remove(size);
    return result;
}
Also used : ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) InternalEList(org.eclipse.emf.ecore.util.InternalEList) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint)

Example 2 with JvmGenericType

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

the class XbaseReferenceProposalCreator method computeImage.

protected Image computeImage(JvmFeature feature) {
    int flags = 0;
    int decorator = 0;
    switch(feature.getVisibility()) {
        case PUBLIC:
            flags = Flags.AccPublic;
            break;
        case PROTECTED:
            flags = Flags.AccProtected;
            break;
        case PRIVATE:
            flags = Flags.AccPrivate;
            break;
        case DEFAULT:
            flags = Flags.AccDefault;
            break;
    }
    JvmDeclaredType declaringType = feature.getDeclaringType();
    boolean interfaceOrAnnotation = false;
    if (declaringType instanceof JvmGenericType) {
        interfaceOrAnnotation = ((JvmGenericType) declaringType).isInterface();
    } else if (declaringType instanceof JvmAnnotationType) {
        interfaceOrAnnotation = true;
    }
    if (feature instanceof JvmConstructor) {
        decorator = JavaElementImageDescriptor.CONSTRUCTOR;
        if (declaringType.isAbstract()) {
            flags |= Flags.AccAbstract;
            decorator |= JavaElementImageDescriptor.ABSTRACT;
        }
        return computeConstructorImage(declaringType.getDeclaringType() != null, interfaceOrAnnotation, flags, decorator);
    } else if (feature instanceof JvmOperation) {
        JvmOperation operation = (JvmOperation) feature;
        if (operation.isStatic()) {
            flags |= Flags.AccStatic;
            decorator |= JavaElementImageDescriptor.STATIC;
        }
        if (operation.isAbstract()) {
            flags |= Flags.AccAbstract;
            decorator |= JavaElementImageDescriptor.ABSTRACT;
        }
        if (operation.isFinal()) {
            flags |= Flags.AccFinal;
            decorator |= JavaElementImageDescriptor.FINAL;
        }
        return computeMethodImage(interfaceOrAnnotation, flags, decorator);
    } else if (feature instanceof JvmField) {
        JvmField field = (JvmField) feature;
        if (field.isStatic()) {
            flags |= Flags.AccStatic;
            decorator |= JavaElementImageDescriptor.STATIC;
        }
        if (field.isFinal()) {
            flags |= Flags.AccFinal;
            decorator |= JavaElementImageDescriptor.FINAL;
        }
        if (declaringType instanceof JvmEnumerationType)
            flags |= Flags.AccEnum;
        return computeFieldImage(interfaceOrAnnotation, flags, decorator);
    }
    return null;
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmField(org.eclipse.xtext.common.types.JvmField) JvmEnumerationType(org.eclipse.xtext.common.types.JvmEnumerationType)

Example 3 with JvmGenericType

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

the class AbstractTypeProviderTest method publicNativeMethod.

@Test
public void publicNativeMethod() {
    String typeName = Methods.class.getName();
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmOperation method = getMethodFromType(type, Methods.class, "publicStrictFpMethod()");
    assertSame(type, method.getDeclaringType());
    assertFalse(method.isAbstract());
    assertFalse(method.isFinal());
    assertFalse(method.isStatic());
    assertFalse(method.isSynchronized());
    assertTrue(method.isStrictFloatingPoint());
    assertFalse(method.isNative());
    assertEquals(JvmVisibility.PUBLIC, method.getVisibility());
    JvmType methodType = method.getReturnType().getType();
    assertEquals("void", methodType.getIdentifier());
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmType(org.eclipse.xtext.common.types.JvmType) Test(org.junit.Test)

Example 4 with JvmGenericType

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

the class AbstractTypeProviderTest method testTypeParamEndsWithDollar_02.

@Test
public void testTypeParamEndsWithDollar_02() {
    String typeName = "org.eclipse.xtext.common.types.testSetups.TypeParamEndsWithDollar";
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmOperation function = (JvmOperation) type.findAllFeaturesByName("function2").iterator().next();
    JvmFormalParameter parameter = function.getParameters().get(0);
    JvmType parameterType = parameter.getParameterType().getType();
    assertEquals(function.getTypeParameters().get(0), parameterType);
    JvmFormalParameter secondParameter = function.getParameters().get(1);
    JvmType secondParameterType = secondParameter.getParameterType().getType();
    assertEquals(type.getTypeParameters().get(0), secondParameterType);
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmType(org.eclipse.xtext.common.types.JvmType) Test(org.junit.Test)

Example 5 with JvmGenericType

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

the class AbstractTypeProviderTest method doTestConstantValue.

protected JvmField doTestConstantValue(String fieldName, Object fieldValue) {
    String typeName = "org.eclipse.xtext.common.types.testSetups.TestConstants";
    JvmGenericType type = (JvmGenericType) getTypeProvider().findTypeByName(typeName);
    JvmField field = getFieldFromType(type, TestConstants.class, fieldName);
    assertTrue(field.isSetConstant());
    assertTrue(field.isConstant());
    assertEquals(fieldValue, field.getConstantValue());
    return field;
}
Also used : JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmField(org.eclipse.xtext.common.types.JvmField)

Aggregations

JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)297 Test (org.junit.Test)237 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)117 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)64 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)56 JvmType (org.eclipse.xtext.common.types.JvmType)49 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)47 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)33 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)33 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)33 JvmField (org.eclipse.xtext.common.types.JvmField)31 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)30 EObject (org.eclipse.emf.ecore.EObject)28 Resource (org.eclipse.emf.ecore.resource.Resource)28 JvmMember (org.eclipse.xtext.common.types.JvmMember)25 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)24 JvmTypeConstraint (org.eclipse.xtext.common.types.JvmTypeConstraint)21 JvmUpperBound (org.eclipse.xtext.common.types.JvmUpperBound)17 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)15 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)15