Search in sources :

Example 11 with XtendConstructor

use of org.eclipse.xtend.core.xtend.XtendConstructor in project xtext-xtend by eclipse.

the class XtendValidationTest method testDuplicateConstructorParameter.

@Test
public void testDuplicateConstructorParameter() throws Exception {
    XtendConstructor constructor = constructor("new(int x, int x) {null}");
    helper.assertError(constructor, XTEND_CONSTRUCTOR, DUPLICATE_PARAMETER_NAME, "duplicate", "x");
}
Also used : XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) Test(org.junit.Test)

Example 12 with XtendConstructor

use of org.eclipse.xtend.core.xtend.XtendConstructor in project xtext-xtend by eclipse.

the class XtendValidationTest method testVarArgMustBeLast_2.

@Test
public void testVarArgMustBeLast_2() throws Exception {
    XtendConstructor constr = constructor("new(String... myParam) { }");
    helper.assertNoErrors(constr);
}
Also used : XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) Test(org.junit.Test)

Example 13 with XtendConstructor

use of org.eclipse.xtend.core.xtend.XtendConstructor in project xtext-xtend by eclipse.

the class XtendHoverSignatureProvider method getSimpleSignature.

@Override
protected String getSimpleSignature(EObject container) {
    if (container instanceof XtendFunction) {
        XtendFunction function = (XtendFunction) container;
        JvmOperation inferredOperation = associations.getDirectlyInferredOperation(function);
        if (inferredOperation != null) {
            return function.getName() + uiStrings.parameters(inferredOperation);
        }
    } else if (container instanceof XtendConstructor) {
        XtendConstructor constructor = (XtendConstructor) container;
        XtendClass xtendClazz = EcoreUtil2.getContainerOfType(constructor, XtendClass.class);
        JvmConstructor inferredConstructor = associations.getInferredConstructor(constructor);
        return xtendClazz.getName() + " " + uiStrings.parameters(inferredConstructor);
    }
    return super.getSimpleSignature(container);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor)

Example 14 with XtendConstructor

use of org.eclipse.xtend.core.xtend.XtendConstructor in project xtext-xtend by eclipse.

the class XtendReentrantTypeResolver method computeTypes.

protected void computeTypes(ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, XtendMember member) {
    XExpression expression = null;
    if (member instanceof XtendFunction) {
        XtendFunction function = (XtendFunction) member;
        expression = function.getExpression();
        CreateExtensionInfo createInfo = function.getCreateExtensionInfo();
        if (createInfo != null) {
            computeDanglingExpressionType(resolvedTypes, featureScopeSession, function, createInfo.getCreateExpression());
        }
        for (XtendParameter parameter : function.getParameters()) {
            computeXtendAnnotationTypes(resolvedTypes, featureScopeSession, parameter.getAnnotations());
        }
    } else if (member instanceof XtendConstructor) {
        XtendConstructor constructor = (XtendConstructor) member;
        expression = constructor.getExpression();
        for (XtendParameter parameter : constructor.getParameters()) {
            computeXtendAnnotationTypes(resolvedTypes, featureScopeSession, parameter.getAnnotations());
        }
    } else if (member instanceof XtendField) {
        expression = ((XtendField) member).getInitialValue();
    }
    if (expression != null) {
        computeDanglingExpressionType(resolvedTypes, featureScopeSession, member, expression);
    }
    computeXtendAnnotationTypes(resolvedTypes, featureScopeSession, member.getAnnotations());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) XExpression(org.eclipse.xtext.xbase.XExpression) CreateExtensionInfo(org.eclipse.xtend.core.xtend.CreateExtensionInfo) XtendField(org.eclipse.xtend.core.xtend.XtendField)

Example 15 with XtendConstructor

use of org.eclipse.xtend.core.xtend.XtendConstructor in project xtext-xtend by eclipse.

the class XtendJvmModelInferrer method inferLocalClass.

/**
 * Anonymous classes are not inferred in the type inference phase, but later during type resolution.
 */
public void inferLocalClass(AnonymousClass anonymousClass, String localClassName, JvmFeature container) {
    final JvmGenericType inferredType = typesFactory.createJvmGenericType();
    inferredType.setSimpleName(localClassName);
    inferredType.setAnonymous(!hasAdditionalMembers(anonymousClass));
    inferredType.setFinal(true);
    inferredType.setVisibility(JvmVisibility.DEFAULT);
    inferredType.getSuperTypes().add(jvmTypesBuilder.inferredType(anonymousClass));
    container.getLocalClasses().add(inferredType);
    associator.associatePrimary(anonymousClass, inferredType);
    for (XtendMember member : anonymousClass.getMembers()) {
        if (member instanceof XtendField || (member instanceof XtendFunction && ((XtendFunction) member).getName() != null) || member instanceof XtendConstructor) {
            transform(member, inferredType, true);
        }
    }
    appendSyntheticDispatchMethods(anonymousClass, inferredType);
    nameClashResolver.resolveNameClashes(inferredType);
    final XConstructorCall constructorCall = anonymousClass.getConstructorCall();
    for (XExpression actualParameter : constructorCall.getArguments()) {
        associator.associateLogicalContainer(actualParameter, container);
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) XExpression(org.eclipse.xtext.xbase.XExpression) XtendField(org.eclipse.xtend.core.xtend.XtendField)

Aggregations

XtendConstructor (org.eclipse.xtend.core.xtend.XtendConstructor)28 Test (org.junit.Test)18 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)9 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)9 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)7 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)7 XExpression (org.eclipse.xtext.xbase.XExpression)7 XtendField (org.eclipse.xtend.core.xtend.XtendField)6 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)6 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)5 XtendEnumLiteral (org.eclipse.xtend.core.xtend.XtendEnumLiteral)3 EObject (org.eclipse.emf.ecore.EObject)2 XtendAnnotationType (org.eclipse.xtend.core.xtend.XtendAnnotationType)2 XtendParameter (org.eclipse.xtend.core.xtend.XtendParameter)2 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)2 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)2 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)2 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)2