Search in sources :

Example 66 with XtendMember

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

the class XtendUIValidationTests method testForbiddenTypeUsageInnernClass.

@Test
public void testForbiddenTypeUsageInnernClass() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def bar(org.eclipse.xtend.core.tests.restricted.RestrictedClass$InnerRestrictedClass x) {}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.testHelper.xtendFile("Clazz.xtend", _builder.toString());
        XtendMember _head = IterableExtensions.<XtendMember>head(IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class)).getMembers());
        final XtendFunction function = ((XtendFunction) _head);
        this.helper.assertError(function.getParameters().get(0), TypesPackage.Literals.JVM_TYPE_REFERENCE, org.eclipse.xtext.xbase.validation.IssueCodes.FORBIDDEN_REFERENCE);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 67 with XtendMember

use of org.eclipse.xtend.core.xtend.XtendMember 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 68 with XtendMember

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

the class XtendCopyQualifiedNameServiceTest method testJvmOperation_7.

@Test
public void testJvmOperation_7() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def foo () {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("new Bar<String>.bar(null)");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("new Bar<String>.bar(<String>newArrayList)");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Bar<T> {");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def bar (java.util.List<T> list) {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        final XtendTypeDeclaration xtendType = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
        XtendMember _head = IterableExtensions.<XtendMember>head(xtendType.getMembers());
        XExpression _expression = ((XtendFunction) _head).getExpression();
        final XBlockExpression expression = ((XBlockExpression) _expression);
        this.assertCopyQualifiedName(expression.getExpressions().get(0), "Bar.bar(List<String>)");
        this.assertCopyQualifiedName(expression.getExpressions().get(1), "Bar.bar(ArrayList<String>)");
    } 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) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 69 with XtendMember

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

the class XtendCopyQualifiedNameServiceTest method testXtendFunction_4.

@Test
public void testXtendFunction_4() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo<T> extends java.util.ArrayList<T> {");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("override clear () {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("super.clear");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("override add(T value) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("super.add(value)");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        final XtendTypeDeclaration xtendType = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
        this.assertCopyQualifiedName(IterableExtensions.<XtendMember>head(xtendType.getMembers()), "Foo.clear()");
        this.assertCopyQualifiedName(IterableExtensions.<XtendMember>head(IterableExtensions.<XtendMember>tail(xtendType.getMembers())), "Foo.add(T)");
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) Test(org.junit.Test)

Example 70 with XtendMember

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

the class XtendCopyQualifiedNameServiceTest method testJvmOperation_6.

@Test
public void testJvmOperation_6() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo<T> extends java.util.ArrayList<T> {");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def bar() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("clear");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("add(null)");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("super.clear");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("super.add(null)");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("override clear () {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("super.clear");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("override add(T value) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("super.add(value)");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        final XtendTypeDeclaration xtendType = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
        XtendMember _head = IterableExtensions.<XtendMember>head(xtendType.getMembers());
        XExpression _expression = ((XtendFunction) _head).getExpression();
        final XBlockExpression expression = ((XBlockExpression) _expression);
        this.assertCopyQualifiedName(expression.getExpressions().get(0), "Foo.clear()");
        this.assertCopyQualifiedName(expression.getExpressions().get(1), "Foo.add(T)");
        this.assertCopyQualifiedName(expression.getExpressions().get(2), "java.util.ArrayList.clear()");
        this.assertCopyQualifiedName(expression.getExpressions().get(3), "java.util.ArrayList.add(T)");
    } 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) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Aggregations

XtendMember (org.eclipse.xtend.core.xtend.XtendMember)175 Test (org.junit.Test)140 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)131 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)119 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)101 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)91 XExpression (org.eclipse.xtext.xbase.XExpression)84 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)57 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)56 XtendField (org.eclipse.xtend.core.xtend.XtendField)33 EObject (org.eclipse.emf.ecore.EObject)17 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)15 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)14 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)12 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)12 XtendParameter (org.eclipse.xtend.core.xtend.XtendParameter)10 XtendConstructor (org.eclipse.xtend.core.xtend.XtendConstructor)9 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)9 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)8 JvmType (org.eclipse.xtext.common.types.JvmType)8