Search in sources :

Example 71 with XtendMember

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

the class XtendCopyQualifiedNameServiceTest method testJvmOperation_2.

@Test
public void testJvmOperation_2() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def foo(java.util.Map<? extends String, ? extends String> map) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("map.get(null)");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("map.put(null, null)");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("bar(map)");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def <K, V> void bar(java.util.Map<K, V> map) {");
        _builder.newLine();
        _builder.append("\t\t");
        _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), "java.util.Map.get(Object)");
        this.assertCopyQualifiedName(expression.getExpressions().get(1), "java.util.Map.put(? extends String, ? extends String)");
        this.assertCopyQualifiedName(expression.getExpressions().get(2), "Foo.bar(Map<? extends String, ? extends 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 72 with XtendMember

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

the class XtendCopyQualifiedNameServiceTest method testXtendFunction_3.

@Test
public void testXtendFunction_3() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo extends java.util.ArrayList<String> {");
        _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(String 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(String)");
    } 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 73 with XtendMember

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

the class JdtFindReferencesTest method testFieldJavaElements.

@Test
public void testFieldJavaElements() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Xtend {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("int foo");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendMember field = IterableExtensions.<XtendMember>head(IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(this._workbenchTestHelper.xtendFile("Xtend.xtend", _builder.toString()).getXtendTypes(), XtendClass.class)).getMembers());
        IResourcesSetupUtil.waitForBuild();
        Iterable<IJavaElement> _javaElements = this._jvmModelFindReferenceHandler.getJavaElements(field);
        final Procedure1<Iterable<IJavaElement>> _function = (Iterable<IJavaElement> it) -> {
            Assert.assertEquals(1, IterableExtensions.size(it));
            final Function1<IJavaElement, Boolean> _function_1 = (IJavaElement it_1) -> {
                return Boolean.valueOf(((it_1 instanceof IField) && Objects.equal(((IField) it_1).getElementName(), "foo")));
            };
            Assert.assertTrue(IterableExtensions.<IJavaElement>exists(it, _function_1));
        };
        ObjectExtensions.<Iterable<IJavaElement>>operator_doubleArrow(_javaElements, _function);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) IField(org.eclipse.jdt.core.IField) Test(org.junit.Test)

Example 74 with XtendMember

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

the class JdtFindReferencesTest method testPropertyJavaElements.

@Test
public void testPropertyJavaElements() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Xtend {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("@Property int foo");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendMember field = IterableExtensions.<XtendMember>head(IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(this._workbenchTestHelper.xtendFile("Xtend.xtend", _builder.toString()).getXtendTypes(), XtendClass.class)).getMembers());
        IResourcesSetupUtil.waitForBuild();
        Iterable<IJavaElement> _javaElements = this._jvmModelFindReferenceHandler.getJavaElements(field);
        final Procedure1<Iterable<IJavaElement>> _function = (Iterable<IJavaElement> it) -> {
            Assert.assertEquals(3, IterableExtensions.size(it));
            final Function1<IJavaElement, Boolean> _function_1 = (IJavaElement it_1) -> {
                return Boolean.valueOf(((it_1 instanceof IMethod) && Objects.equal(((IMethod) it_1).getElementName(), "getFoo")));
            };
            Assert.assertTrue(IterableExtensions.<IJavaElement>exists(it, _function_1));
            final Function1<IJavaElement, Boolean> _function_2 = (IJavaElement it_1) -> {
                return Boolean.valueOf(((it_1 instanceof IMethod) && Objects.equal(((IMethod) it_1).getElementName(), "setFoo")));
            };
            Assert.assertTrue(IterableExtensions.<IJavaElement>exists(it, _function_2));
            final Function1<IJavaElement, Boolean> _function_3 = (IJavaElement it_1) -> {
                return Boolean.valueOf(((it_1 instanceof IField) && Objects.equal(((IField) it_1).getElementName(), "_foo")));
            };
            Assert.assertTrue(IterableExtensions.<IJavaElement>exists(it, _function_3));
        };
        ObjectExtensions.<Iterable<IJavaElement>>operator_doubleArrow(_javaElements, _function);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) IMethod(org.eclipse.jdt.core.IMethod) IField(org.eclipse.jdt.core.IField) Test(org.junit.Test)

Example 75 with XtendMember

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

the class JdtFindReferencesTest method testMethodJavaElements.

@Test
public void testMethodJavaElements() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Xtend {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def foo() {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendMember method = IterableExtensions.<XtendMember>head(IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(this._workbenchTestHelper.xtendFile("Xtend.xtend", _builder.toString()).getXtendTypes(), XtendClass.class)).getMembers());
        IResourcesSetupUtil.waitForBuild();
        Iterable<IJavaElement> _javaElements = this._jvmModelFindReferenceHandler.getJavaElements(method);
        final Procedure1<Iterable<IJavaElement>> _function = (Iterable<IJavaElement> it) -> {
            Assert.assertEquals(1, IterableExtensions.size(it));
            final Function1<IJavaElement, Boolean> _function_1 = (IJavaElement it_1) -> {
                return Boolean.valueOf(((it_1 instanceof IMethod) && Objects.equal(((IMethod) it_1).getElementName(), "foo")));
            };
            Assert.assertTrue(IterableExtensions.<IJavaElement>exists(it, _function_1));
        };
        ObjectExtensions.<Iterable<IJavaElement>>operator_doubleArrow(_javaElements, _function);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) IMethod(org.eclipse.jdt.core.IMethod) 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