Search in sources :

Example 16 with XConstructorCall

use of org.eclipse.xtext.xbase.XConstructorCall 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)

Example 17 with XConstructorCall

use of org.eclipse.xtext.xbase.XConstructorCall in project xtext-xtend by eclipse.

the class AnonymousClassImpl method basicSetConstructorCall.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetConstructorCall(XConstructorCall newConstructorCall, NotificationChain msgs) {
    XConstructorCall oldConstructorCall = constructorCall;
    constructorCall = newConstructorCall;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, XtendPackage.ANONYMOUS_CLASS__CONSTRUCTOR_CALL, oldConstructorCall, newConstructorCall);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall)

Example 18 with XConstructorCall

use of org.eclipse.xtext.xbase.XConstructorCall in project xtext-xtend by eclipse.

the class CreateMemberQuickfixes method addQuickfixes.

@Override
public void addQuickfixes(Issue issue, IssueResolutionAcceptor issueResolutionAcceptor, IXtextDocument xtextDocument, XtextResource resource, EObject referenceOwner, EReference unresolvedReference) throws Exception {
    if (referenceOwner instanceof XAbstractFeatureCall) {
        XAbstractFeatureCall call = (XAbstractFeatureCall) referenceOwner;
        String newMemberName = (issue.getData() != null && issue.getData().length > 0) ? issue.getData()[0] : null;
        if (newMemberName != null) {
            if (call instanceof XMemberFeatureCall) {
                if (!call.isExplicitOperationCallOrBuilderSyntax()) {
                    newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
                    newGetterQuickfixes(newMemberName, call, issue, issueResolutionAcceptor);
                }
                newMethodQuickfixes(newMemberName, call, issue, issueResolutionAcceptor);
            } else if (call instanceof XFeatureCall) {
                if (!call.isExplicitOperationCallOrBuilderSyntax()) {
                    if (logicalContainerProvider.getNearestLogicalContainer(call) instanceof JvmExecutable)
                        newLocalVariableQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
                    newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
                    newGetterQuickfixes(newMemberName, call, issue, issueResolutionAcceptor);
                }
                newMethodQuickfixes(newMemberName, call, issue, issueResolutionAcceptor);
            } else if (call instanceof XAssignment) {
                newSetterQuickfix(issue, issueResolutionAcceptor, newMemberName, call);
                XAssignment assigment = (XAssignment) call;
                if (assigment.getAssignable() == null) {
                    newLocalVariableQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
                    newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
                } else if (isThis(assigment)) {
                    newFieldQuickfix(newMemberName, call, issue, issueResolutionAcceptor);
                }
            }
        }
        if (call.isOperation()) {
            JvmIdentifiableElement feature = call.getFeature();
            if (feature.eIsProxy()) {
                String operatorMethodName = getOperatorMethodName(call);
                if (operatorMethodName != null)
                    newMethodQuickfixes(operatorMethodName, call, issue, issueResolutionAcceptor);
            }
        }
        if (call instanceof XFeatureCall && call.getFeature() instanceof JvmConstructor) {
            newConstructorQuickfix(issue, issueResolutionAcceptor, (XFeatureCall) call);
        }
    }
    if (referenceOwner instanceof XConstructorCall) {
        newConstructorQuickfix(issue, issueResolutionAcceptor, (XConstructorCall) referenceOwner);
    }
}
Also used : JvmExecutable(org.eclipse.xtext.common.types.JvmExecutable) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) XAssignment(org.eclipse.xtext.xbase.XAssignment)

Example 19 with XConstructorCall

use of org.eclipse.xtext.xbase.XConstructorCall in project xtext-xtend by eclipse.

the class XtendHoverSignatureProviderTest method testSignatureXtendConstructorWithGenerics_01.

@Test
public void testSignatureXtendConstructorWithGenerics_01() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.append("class Foo<S extends CharSequence> {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def bar() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("new Foo()");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        final XtendClass clazz = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class));
        XtendMember _get = clazz.getMembers().get(0);
        final XtendFunction xtendFunction = ((XtendFunction) _get);
        XExpression _expression = xtendFunction.getExpression();
        XExpression _get_1 = ((XBlockExpression) _expression).getExpressions().get(0);
        final XConstructorCall constructorCall = ((XConstructorCall) _get_1);
        final String signature = this.signatureProvider.getSignature(constructorCall.getConstructor());
        Assert.assertEquals("Foo<S extends CharSequence>()", signature);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 20 with XConstructorCall

use of org.eclipse.xtext.xbase.XConstructorCall in project xtext-xtend by eclipse.

the class UIStringsTest method testReferenceToString_3.

/**
 * The qualified name of the type is specified.
 * The JvmTypeReference is proxy.
 */
@Test
public void testReferenceToString_3() throws Exception {
    XtendFile file1 = 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");
    assertNotNull(file1);
    XtendFile file2 = file("package org.eclipse.xtend.core.tests.validation.uistrings\n" + "class XtendClass1 {\n" + "  def test() {\n" + "    val x = new List<org.eclipse.xtend.core.tests.validation.uistrings.ClassC>\n" + "  }\n" + "}\n");
    XtendClass clazz = (XtendClass) file2.getXtendTypes().get(0);
    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());
    assertTrue(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

XConstructorCall (org.eclipse.xtext.xbase.XConstructorCall)24 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)12 Test (org.junit.Test)11 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)9 XExpression (org.eclipse.xtext.xbase.XExpression)9 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)8 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)8 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)7 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)6 EObject (org.eclipse.emf.ecore.EObject)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)5 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)5 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)4 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)3 XVariableDeclaration (org.eclipse.xtext.xbase.XVariableDeclaration)3 RichString (org.eclipse.xtend.core.xtend.RichString)2 XtendField (org.eclipse.xtend.core.xtend.XtendField)2 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)2 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)2