Search in sources :

Example 36 with JvmTypeReference

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

the class XtendValidator method checkSuperTypes.

@Check
public void checkSuperTypes(XtendInterface xtendInterface) {
    for (int i = 0; i < xtendInterface.getExtends().size(); ++i) {
        JvmTypeReference extendedType = xtendInterface.getExtends().get(i);
        if (!isInterface(extendedType.getType()) && !isAnnotation(extendedType.getType())) {
            error("Extended interface must be an interface", XTEND_INTERFACE__EXTENDS, i, INTERFACE_EXPECTED);
        }
        checkWildcardSupertype(xtendInterface, extendedType, XTEND_INTERFACE__EXTENDS, i);
    }
    JvmGenericType inferredType = associations.getInferredType(xtendInterface);
    if (inferredType != null && hasCycleInHierarchy(inferredType, Sets.<JvmGenericType>newHashSet())) {
        error("The inheritance hierarchy of " + notNull(xtendInterface.getName()) + " contains cycles", XTEND_TYPE_DECLARATION__NAME, CYCLIC_INHERITANCE);
    }
}
Also used : JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Check(org.eclipse.xtext.validation.Check)

Example 37 with JvmTypeReference

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

the class XtendJvmModelInferrer method initialize.

protected void initialize(XtendInterface source, JvmGenericType inferredJvmType) {
    inferredJvmType.setVisibility(source.getVisibility());
    inferredJvmType.setStatic(source.isStatic() && !isTopLevel(source));
    inferredJvmType.setAbstract(true);
    inferredJvmType.setStrictFloatingPoint(source.isStrictFloatingPoint());
    translateAnnotationsTo(source.getAnnotations(), inferredJvmType);
    for (JvmTypeReference intf : source.getExtends()) {
        inferredJvmType.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(intf));
    }
    fixTypeParameters(inferredJvmType);
    for (XtendMember member : source.getMembers()) {
        if (member instanceof XtendField || (member instanceof XtendFunction && ((XtendFunction) member).getName() != null)) {
            transform(member, inferredJvmType, false);
        }
    }
    jvmTypesBuilder.copyDocumentationTo(source, inferredJvmType);
    nameClashResolver.resolveNameClashes(inferredJvmType);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) XtendField(org.eclipse.xtend.core.xtend.XtendField)

Example 38 with JvmTypeReference

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

the class XtendReentrantTypeResolver method _doPrepare.

@Override
protected void _doPrepare(ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmOperation operation, Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext) {
    super._doPrepare(resolvedTypes, featureScopeSession, operation, resolvedTypesByContext);
    resolvedTypes = resolvedTypesByContext.get(operation);
    if (dispatchHelper.isDispatcherFunction(operation)) {
        List<JvmFormalParameter> parameters = operation.getParameters();
        for (int i = 0; i < parameters.size(); i++) {
            JvmFormalParameter parameter = parameters.get(i);
            JvmTypeReference parameterType = parameter.getParameterType();
            if (InferredTypeIndicator.isInferred(parameterType)) {
                XComputedTypeReference casted = (XComputedTypeReference) parameterType;
                XComputedTypeReference computedParameterType = getServices().getXtypeFactory().createXComputedTypeReference();
                computedParameterType.setTypeProvider(new DispatchParameterTypeReferenceProvider(operation, i, resolvedTypes, featureScopeSession, this));
                casted.setEquivalent(computedParameterType);
            } else if (parameterType == null) {
                XComputedTypeReference computedParameterType = getServices().getXtypeFactory().createXComputedTypeReference();
                computedParameterType.setTypeProvider(new DispatchParameterTypeReferenceProvider(operation, i, resolvedTypes, featureScopeSession, this));
                parameter.setParameterType(computedParameterType);
            }
        }
    } else if (operation.getParameters().size() >= 1) {
        EObject sourceElement = associations.getPrimarySourceElement(operation);
        if (sourceElement instanceof XtendFunction) {
            XtendFunction function = (XtendFunction) sourceElement;
            if (function.getCreateExtensionInfo() != null) {
                JvmFormalParameter firstParameter = operation.getParameters().get(0);
                JvmTypeReference parameterType = firstParameter.getParameterType();
                if (InferredTypeIndicator.isInferred(parameterType)) {
                    XComputedTypeReference casted = (XComputedTypeReference) parameterType;
                    XComputedTypeReference computedParameterType = getServices().getXtypeFactory().createXComputedTypeReference();
                    computedParameterType.setTypeProvider(new InitializerParameterTypeReferenceProvider(firstParameter, function, resolvedTypesByContext, resolvedTypes, featureScopeSession, this));
                    casted.setEquivalent(computedParameterType);
                }
            }
        }
    }
    doPrepareLocalTypes(resolvedTypes, featureScopeSession, operation, resolvedTypesByContext);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) EObject(org.eclipse.emf.ecore.EObject) XComputedTypeReference(org.eclipse.xtext.xtype.XComputedTypeReference)

Example 39 with JvmTypeReference

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

the class XtendValidator method checkNonRawTypeInferred.

@Check
public void checkNonRawTypeInferred(XtendField field) {
    if (field.getType() == null) {
        JvmField jvmField = associations.getJvmField(field);
        // field could have been removed by AA, thus the resource is possibly null
        if (jvmField != null && jvmField.eResource() != null) {
            JvmTypeReference fieldType = jvmField.getType();
            validateInferredType(fieldType, field, "The inferred field type ", XTEND_FIELD__NAME);
        }
    }
}
Also used : JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmField(org.eclipse.xtext.common.types.JvmField) Check(org.eclipse.xtext.validation.Check)

Example 40 with JvmTypeReference

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

the class UIStringsTest method testReferenceToString_0.

/**
 * Only the simple name of the type is specified.
 * The JvmTypeReference is not a proxy.
 */
@Test
public void testReferenceToString_0() throws Exception {
    XtendFile file = file("package org.eclipse.xtend.core.tests.validation.uistrings\n" + "public interface InterfaceA { }\n" + "public class ClassB implements InterfaceA { }\n" + "public class ClassC extends ClassB {\n" + "}\n" + "class XtendClass1 {\n" + "  def test() {\n" + "    val x = new List<ClassC>\n" + "  }\n" + "}\n");
    XtendClass clazz = (XtendClass) file.getXtendTypes().get(3);
    XBlockExpression block = (XBlockExpression) ((XtendFunction) clazz.getMembers().get(0)).getExpression();
    XVariableDeclaration declaration = (XVariableDeclaration) block.getExpressions().get(0);
    XConstructorCall cons = (XConstructorCall) declaration.getRight();
    JvmTypeReference reference = cons.getTypeArguments().get(0);
    assertNotNull(reference);
    assertNotNull(reference.getType());
    assertFalse(reference.getType().eIsProxy());
    assertNotNull(reference.eResource());
    assertEquals("ClassC", this.uiStrings.referenceToString(reference, "the-default-label"));
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XVariableDeclaration(org.eclipse.xtext.xbase.XVariableDeclaration) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) Test(org.junit.Test)

Aggregations

JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)194 Test (org.junit.Test)98 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)68 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)47 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)46 JvmType (org.eclipse.xtext.common.types.JvmType)43 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)41 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)36 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)27 XExpression (org.eclipse.xtext.xbase.XExpression)22 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)18 JvmUpperBound (org.eclipse.xtext.common.types.JvmUpperBound)18 EObject (org.eclipse.emf.ecore.EObject)17 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)17 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)16 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)15 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)14 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)12 JvmField (org.eclipse.xtext.common.types.JvmField)12 JvmWildcardTypeReference (org.eclipse.xtext.common.types.JvmWildcardTypeReference)12