Search in sources :

Example 11 with AnonymousClass

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

the class ValidationBug433213Test method test_05.

@Test
public void test_05() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class C {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def <T> m() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("new Object {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("def m2() {");
        _builder.newLine();
        _builder.append("\t\t\t\t");
        _builder.append("new Object {");
        _builder.newLine();
        _builder.append("\t\t\t\t\t");
        _builder.append("def T m3() {}");
        _builder.newLine();
        _builder.append("\t\t\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile file = this.parser.parse(_builder);
        final XtendTypeDeclaration c = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
        XtendMember _head = IterableExtensions.<XtendMember>head(c.getMembers());
        final XtendFunction m = ((XtendFunction) _head);
        XExpression _expression = m.getExpression();
        final XBlockExpression body = ((XBlockExpression) _expression);
        XExpression _head_1 = IterableExtensions.<XExpression>head(body.getExpressions());
        final AnonymousClass anon = ((AnonymousClass) _head_1);
        XtendMember _head_2 = IterableExtensions.<XtendMember>head(anon.getMembers());
        final XtendFunction m2 = ((XtendFunction) _head_2);
        XExpression _expression_1 = m2.getExpression();
        final XBlockExpression body2 = ((XBlockExpression) _expression_1);
        XExpression _head_3 = IterableExtensions.<XExpression>head(body2.getExpressions());
        final AnonymousClass anon2 = ((AnonymousClass) _head_3);
        XtendMember _head_4 = IterableExtensions.<XtendMember>head(anon2.getMembers());
        final XtendFunction m3 = ((XtendFunction) _head_4);
        final JvmTypeReference returnType = m3.getReturnType();
        final JvmType t = returnType.getType();
        Assert.assertNotNull("notNull", t);
        Assert.assertFalse("t.eIsProxy", t.eIsProxy());
        this.helper.assertNoErrors(file);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) JvmType(org.eclipse.xtext.common.types.JvmType) Test(org.junit.Test)

Example 12 with AnonymousClass

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

the class ValidationBug433213Test method test_02.

@Test
public void test_02() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class C {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def <T> m() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("new Object {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("def T m2() {}");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile file = this.parser.parse(_builder);
        final XtendTypeDeclaration c = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
        XtendMember _head = IterableExtensions.<XtendMember>head(c.getMembers());
        final XtendFunction m = ((XtendFunction) _head);
        XExpression _expression = m.getExpression();
        final XBlockExpression body = ((XBlockExpression) _expression);
        XExpression _head_1 = IterableExtensions.<XExpression>head(body.getExpressions());
        final AnonymousClass anon = ((AnonymousClass) _head_1);
        XtendMember _head_2 = IterableExtensions.<XtendMember>head(anon.getMembers());
        final XtendFunction m2 = ((XtendFunction) _head_2);
        final JvmTypeReference returnType = m2.getReturnType();
        final JvmType t = returnType.getType();
        Assert.assertNotNull("notNull", t);
        Assert.assertFalse("t.eIsProxy", t.eIsProxy());
        this.helper.assertNoErrors(file);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) JvmType(org.eclipse.xtext.common.types.JvmType) Test(org.junit.Test)

Example 13 with AnonymousClass

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

the class LinkingTest method testQualifiedSuperOuter.

@Test
public void testQualifiedSuperOuter() throws Exception {
    XtendFile file = file("class B<T> { def T m1() {} }\n" + "class C extends B<String> {\n" + "  def void m2() { new Object { def m3() { C.super.m1.subSequence(1, 1) } } }\n" + "}");
    XtendClass c = (XtendClass) file.getXtendTypes().get(1);
    XtendFunction m = (XtendFunction) c.getMembers().get(0);
    XBlockExpression outer = (XBlockExpression) m.getExpression();
    AnonymousClass anonymousClass = (AnonymousClass) outer.getExpressions().get(0);
    XtendFunction m3 = (XtendFunction) anonymousClass.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) m3.getExpression();
    XMemberFeatureCall featureCall = (XMemberFeatureCall) body.getExpressions().get(0);
    JvmIdentifiableElement feature = featureCall.getFeature();
    assertEquals("java.lang.String.subSequence(int,int)", feature.getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) Test(org.junit.Test)

Example 14 with AnonymousClass

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

the class XtendProposalProvider method completeType_Members.

@Override
public void completeType_Members(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    if (isValidTypeForOverriding(model)) {
        INode node = context.getCurrentNode();
        EObject eObject = NodeModelUtils.findActualSemanticObjectFor(node);
        if (!(eObject instanceof AnonymousClass)) {
            // due to some optimizations in the CA parser, we get some bogus context here and have to
            // double check that an override proposal would be valid at this location
            // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=370955
            EObject prevModel = context.getPreviousModel();
            if (prevModel instanceof XExpression) {
                XtendMember containingMember = EcoreUtil2.getContainerOfType(prevModel, XtendMember.class);
                XBlockExpression blockExpression = EcoreUtil2.getContainerOfType(prevModel, XBlockExpression.class);
                if (blockExpression != null && blockExpression != prevModel) {
                    if (EcoreUtil.isAncestor(containingMember, blockExpression)) {
                        // still inside block
                        return;
                    }
                }
            }
            overrideAssist.createOverrideProposals((XtendTypeDeclaration) model, context, acceptor, getConflictHelper());
        }
    }
    super.completeType_Members(model, assignment, context, acceptor);
}
Also used : XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) INode(org.eclipse.xtext.nodemodel.INode) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) EObject(org.eclipse.emf.ecore.EObject) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 15 with AnonymousClass

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

the class XtendEObjectAtOffsetHelper method resolveCrossReferencedElement.

@Override
protected EObject resolveCrossReferencedElement(INode node) {
    EObject referencedElement = super.resolveCrossReferencedElement(node);
    EObject referenceOwner = NodeModelUtils.findActualSemanticObjectFor(node);
    if (referenceOwner instanceof XConstructorCall) {
        if (referenceOwner.eContainer() instanceof AnonymousClass) {
            AnonymousClass anon = (AnonymousClass) referenceOwner.eContainer();
            JvmGenericType superType = anonymousClassUtil.getSuperType(anon);
            if (superType != null) {
                if (referencedElement instanceof JvmGenericType)
                    return superType;
                else if (referencedElement instanceof JvmConstructor) {
                    if (superType.isInterface())
                        return superType;
                    JvmConstructor superConstructor = anonymousClassUtil.getSuperTypeConstructor(anon);
                    if (superConstructor != null)
                        return superConstructor;
                }
            }
        }
    }
    return referencedElement;
}
Also used : AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) EObject(org.eclipse.emf.ecore.EObject) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall)

Aggregations

AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)23 XExpression (org.eclipse.xtext.xbase.XExpression)13 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)12 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)10 Test (org.junit.Test)10 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)9 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)9 EObject (org.eclipse.emf.ecore.EObject)8 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)8 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)8 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)8 JvmType (org.eclipse.xtext.common.types.JvmType)7 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)6 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)5 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)4 JvmMember (org.eclipse.xtext.common.types.JvmMember)3 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)3 INode (org.eclipse.xtext.nodemodel.INode)3 IScope (org.eclipse.xtext.scoping.IScope)3 XConstructorCall (org.eclipse.xtext.xbase.XConstructorCall)3