Search in sources :

Example 51 with Function1

use of org.eclipse.xtext.xbase.lib.Functions.Function1 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 52 with Function1

use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-xtend by eclipse.

the class JdtFindReferencesTest method testFindFieldRef.

@Test
public void testFindFieldRef() {
    try {
        this._workbenchTestHelper.createFile("Xtend.xtend", "class Xtend { public int foo = 0 }");
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("public class JavaRef extends Xtend {");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("private int bar = foo;");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("public int baz() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("return foo;");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("public void fooBar_0() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("return new Xtend().foo;");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("public void fooBar_1() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("return new JavaRef().foo;");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        this._workbenchTestHelper.createFile("JavaRef.java", _builder.toString());
        IResourcesSetupUtil.waitForBuild();
        final IType type = JavaCore.create(this._workbenchTestHelper.getProject()).findType("Xtend");
        final IField field = type.getField("foo");
        ArrayList<Object> _findReferences = this.findReferences(field);
        final Procedure1<ArrayList<Object>> _function = (ArrayList<Object> it) -> {
            Assert.assertEquals(4, it.size());
            final Function1<Object, Boolean> _function_1 = (Object it_1) -> {
                return Boolean.valueOf(((it_1 instanceof IField) && Objects.equal(((IField) it_1).getElementName(), "bar")));
            };
            Assert.assertTrue(IterableExtensions.<Object>exists(it, _function_1));
            final Function1<Object, Boolean> _function_2 = (Object it_1) -> {
                return Boolean.valueOf(((it_1 instanceof IMethod) && Objects.equal(((IMethod) it_1).getElementName(), "baz")));
            };
            Assert.assertTrue(IterableExtensions.<Object>exists(it, _function_2));
            final Function1<Object, Boolean> _function_3 = (Object it_1) -> {
                return Boolean.valueOf(((it_1 instanceof IMethod) && Objects.equal(((IMethod) it_1).getElementName(), "fooBar_0")));
            };
            Assert.assertTrue(IterableExtensions.<Object>exists(it, _function_3));
            final Function1<Object, Boolean> _function_4 = (Object it_1) -> {
                return Boolean.valueOf(((it_1 instanceof IMethod) && Objects.equal(((IMethod) it_1).getElementName(), "fooBar_1")));
            };
            Assert.assertTrue(IterableExtensions.<Object>exists(it, _function_4));
        };
        ObjectExtensions.<ArrayList<Object>>operator_doubleArrow(_findReferences, _function);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ArrayList(java.util.ArrayList) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) IMethod(org.eclipse.jdt.core.IMethod) IField(org.eclipse.jdt.core.IField) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Example 53 with Function1

use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-xtend by eclipse.

the class JdtFindReferencesTest method testFindMethodRef.

@Test
public void testFindMethodRef() {
    try {
        this._workbenchTestHelper.createFile("Xtend.xtend", "class Xtend { def foo() { 0 }}");
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("public class JavaRef {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("private Xtend x = new Xtend();");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("private int y = x.foo();");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("public int bar() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("return x.foo();");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        this._workbenchTestHelper.createFile("JavaRef.java", _builder.toString());
        IResourcesSetupUtil.waitForBuild();
        final IType type = JavaCore.create(this._workbenchTestHelper.getProject()).findType("Xtend");
        final IMethod method = type.getMethod("foo", ((String[]) Conversions.unwrapArray(CollectionLiterals.<String>newArrayList(), String.class)));
        ArrayList<Object> _findReferences = this.findReferences(method);
        final Procedure1<ArrayList<Object>> _function = (ArrayList<Object> it) -> {
            Assert.assertEquals(2, it.size());
            final Function1<Object, Boolean> _function_1 = (Object it_1) -> {
                return Boolean.valueOf(((it_1 instanceof IField) && Objects.equal(((IField) it_1).getElementName(), "y")));
            };
            Assert.assertTrue(IterableExtensions.<Object>exists(it, _function_1));
            final Function1<Object, Boolean> _function_2 = (Object it_1) -> {
                return Boolean.valueOf(((it_1 instanceof IMethod) && Objects.equal(((IMethod) it_1).getElementName(), "bar")));
            };
            Assert.assertTrue(IterableExtensions.<Object>exists(it, _function_2));
        };
        ObjectExtensions.<ArrayList<Object>>operator_doubleArrow(_findReferences, _function);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ArrayList(java.util.ArrayList) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) IMethod(org.eclipse.jdt.core.IMethod) IField(org.eclipse.jdt.core.IField) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Example 54 with Function1

use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-xtend by eclipse.

the class JdtFindReferencesTest method testJavaClassRef.

@Test
public void testJavaClassRef() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Xtend { ");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("Java foo");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def Java bar() { ");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("null");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def void baz() { ");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("new Java()");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        this._workbenchTestHelper.createFile("Xtend.xtend", _builder.toString());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("public class Java {");
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        this._workbenchTestHelper.createFile("Java.java", _builder_1.toString());
        IResourcesSetupUtil.waitForBuild();
        final IType javaType = JavaCore.create(this._workbenchTestHelper.getProject()).findType("Java");
        ArrayList<Object> _findReferences = this.findReferences(javaType);
        final Procedure1<ArrayList<Object>> _function = (ArrayList<Object> it) -> {
            Assert.assertEquals(3, it.size());
            final Function1<Object, Boolean> _function_1 = (Object it_1) -> {
                return Boolean.valueOf(((it_1 instanceof IField) && Objects.equal(((IField) it_1).getElementName(), "foo")));
            };
            Assert.assertTrue(IterableExtensions.<Object>exists(it, _function_1));
            final Function1<Object, Boolean> _function_2 = (Object it_1) -> {
                return Boolean.valueOf(((it_1 instanceof IMethod) && Objects.equal(((IMethod) it_1).getElementName(), "bar")));
            };
            Assert.assertTrue(IterableExtensions.<Object>exists(it, _function_2));
            final Function1<Object, Boolean> _function_3 = (Object it_1) -> {
                return Boolean.valueOf(((it_1 instanceof IMethod) && Objects.equal(((IMethod) it_1).getElementName(), "baz")));
            };
            Assert.assertTrue(IterableExtensions.<Object>exists(it, _function_3));
        };
        ObjectExtensions.<ArrayList<Object>>operator_doubleArrow(_findReferences, _function);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ArrayList(java.util.ArrayList) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) IMethod(org.eclipse.jdt.core.IMethod) IField(org.eclipse.jdt.core.IField) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Example 55 with Function1

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

Aggregations

Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)131 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)80 Test (org.junit.Test)54 List (java.util.List)20 ArrayList (java.util.ArrayList)19 AbstractXtendCompilerTest (org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest)17 CompilationTestHelper (org.eclipse.xtext.xbase.testing.CompilationTestHelper)17 EList (org.eclipse.emf.common.util.EList)14 EObject (org.eclipse.emf.ecore.EObject)14 ColumnSource (com.robotoworks.mechanoid.db.sqliteModel.ColumnSource)13 Method (java.lang.reflect.Method)12 Set (java.util.Set)10 IMethod (org.eclipse.jdt.core.IMethod)10 CompilationUnitImpl (org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl)9 ScreenListItemCell (org.applause.lang.applauseDsl.ScreenListItemCell)8 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)8 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)8 ColumnType (com.robotoworks.mechanoid.db.sqliteModel.ColumnType)7 URI (org.eclipse.emf.common.util.URI)7 Resource (org.eclipse.emf.ecore.resource.Resource)7