Search in sources :

Example 6 with JvmGenericType

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

the class XtendValidator method checkDefaultSuperConstructor.

@Check
public void checkDefaultSuperConstructor(XtendClass xtendClass) {
    JvmGenericType inferredType = associations.getInferredType(xtendClass);
    if (inferredType == null)
        return;
    Iterable<JvmConstructor> constructors = filter(inferredType.getMembers(), JvmConstructor.class);
    if (inferredType.getExtendedClass() != null) {
        JvmType superType = inferredType.getExtendedClass().getType();
        if (superType instanceof JvmGenericType) {
            Iterable<JvmConstructor> superConstructors = ((JvmGenericType) superType).getDeclaredConstructors();
            for (JvmConstructor superConstructor : superConstructors) {
                if (superConstructor.getParameters().isEmpty())
                    // there is a default super constructor. nothing more to check
                    return;
            }
            if (size(constructors) == 1 && typeExtensions.isSingleSyntheticDefaultConstructor(constructors.iterator().next())) {
                List<String> issueData = newArrayList();
                for (JvmConstructor superConstructor : superConstructors) {
                    issueData.add(EcoreUtil.getURI(superConstructor).toString());
                    issueData.add(doGetReadableSignature(xtendClass.getName(), superConstructor.getParameters()));
                }
                error("No default constructor in super type " + superType.getSimpleName() + "." + xtendClass.getName() + " must define an explicit constructor.", xtendClass, XTEND_TYPE_DECLARATION__NAME, MISSING_CONSTRUCTOR, toArray(issueData, String.class));
            } else {
                for (JvmConstructor constructor : constructors) {
                    XExpression expression = containerProvider.getAssociatedExpression(constructor);
                    if (expression instanceof XBlockExpression) {
                        List<XExpression> expressions = ((XBlockExpression) expression).getExpressions();
                        if (expressions.isEmpty() || !isDelegateConstructorCall(expressions.get(0))) {
                            EObject source = associations.getPrimarySourceElement(constructor);
                            error("No default constructor in super type " + superType.getSimpleName() + ". Another constructor must be invoked explicitly.", source, null, MUST_INVOKE_SUPER_CONSTRUCTOR);
                        }
                    }
                }
            }
        }
    }
}
Also used : XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) EObject(org.eclipse.emf.ecore.EObject) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) XExpression(org.eclipse.xtext.xbase.XExpression) JvmType(org.eclipse.xtext.common.types.JvmType) RichString(org.eclipse.xtend.core.xtend.RichString) Check(org.eclipse.xtext.validation.Check)

Example 7 with JvmGenericType

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

the class XtendValidator method checkDuplicateAndOverriddenFunctions.

@Check
public void checkDuplicateAndOverriddenFunctions(XtendTypeDeclaration xtendType) {
    final JvmDeclaredType inferredType = associations.getInferredType(xtendType);
    if (inferredType instanceof JvmGenericType) {
        JavaVersion targetVersion = getGeneratorConfig(xtendType).getJavaSourceVersion();
        ResolvedFeatures resolvedFeatures = overrideHelper.getResolvedFeatures(inferredType, targetVersion);
        Set<EObject> flaggedOperations = Sets.newHashSet();
        doCheckDuplicateExecutables((JvmGenericType) inferredType, resolvedFeatures, flaggedOperations);
        doCheckOverriddenMethods(xtendType, (JvmGenericType) inferredType, resolvedFeatures, flaggedOperations);
        doCheckFunctionOverrides(resolvedFeatures, flaggedOperations);
    }
}
Also used : ResolvedFeatures(org.eclipse.xtext.xbase.typesystem.override.ResolvedFeatures) EObject(org.eclipse.emf.ecore.EObject) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JavaVersion(org.eclipse.xtext.util.JavaVersion) Check(org.eclipse.xtext.validation.Check)

Example 8 with JvmGenericType

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

the class XtendValidator method checkFinalFieldInitialization.

@Check
public void checkFinalFieldInitialization(XtendInterface xtendInterface) {
    JvmGenericType inferredType = associations.getInferredType(xtendInterface);
    if (inferredType == null)
        return;
    super.checkFinalFieldInitialization(inferredType);
}
Also used : JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) Check(org.eclipse.xtext.validation.Check)

Example 9 with JvmGenericType

use of org.eclipse.xtext.common.types.JvmGenericType 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())) {
            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 10 with JvmGenericType

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

the class TypeReferenceProviderImpl method createTypeRef.

public JvmParameterizedTypeReference createTypeRef(final JvmType type, final JvmTypeReference... typeArgs) {
    if ((type == null)) {
        throw new NullPointerException("type");
    }
    final JvmParameterizedTypeReference reference = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference();
    reference.setType(type);
    for (final JvmTypeReference typeArg : typeArgs) {
        reference.getArguments().add(EcoreUtil2.<JvmTypeReference>cloneIfContained(typeArg));
    }
    if ((type instanceof JvmGenericType)) {
        final EList<JvmTypeParameter> list = ((JvmGenericType) type).getTypeParameters();
        if (((!reference.getArguments().isEmpty()) && (list.size() != reference.getArguments().size()))) {
            String _identifier = ((JvmGenericType) type).getIdentifier();
            String _plus = ("The type " + _identifier);
            String _plus_1 = (_plus + " expects ");
            int _size = list.size();
            String _plus_2 = (_plus_1 + Integer.valueOf(_size));
            String _plus_3 = (_plus_2 + " type arguments, but was ");
            int _size_1 = reference.getArguments().size();
            String _plus_4 = (_plus_3 + Integer.valueOf(_size_1));
            String _plus_5 = (_plus_4 + ". Either pass zero arguments (raw type) or the correct number.");
            throw new IllegalArgumentException(_plus_5);
        }
    }
    return reference;
}
Also used : JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference)

Aggregations

JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)155 Test (org.junit.Test)106 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)71 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)64 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)56 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)33 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)30 EObject (org.eclipse.emf.ecore.EObject)23 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)23 JvmMember (org.eclipse.xtext.common.types.JvmMember)21 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)19 JvmField (org.eclipse.xtext.common.types.JvmField)19 JvmType (org.eclipse.xtext.common.types.JvmType)13 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)11 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)11 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)11 DispatchHelper (org.eclipse.xtend.core.jvmmodel.DispatchHelper)10 Resource (org.eclipse.emf.ecore.resource.Resource)9 Check (org.eclipse.xtext.validation.Check)9 DispatchSignature (org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature)8