Search in sources :

Example 46 with Function1

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

the class AbstractSingleEditorQueuedBuildTest method removeNestedTypesWithinDefaultPackage.

@Test
public void removeNestedTypesWithinDefaultPackage() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("public class Bar {");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("public class Foo { public class Foo3 {} }");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("public static class Foo2 {}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        this.testHelper.createFile("Bar.java", _builder.toString());
        final Procedure0 _function = () -> {
            final Function1<ITextEditor, ITextEditor> _function_1 = (ITextEditor it) -> {
                ITextEditor _xblockexpression = null;
                {
                    this._javaEditorExtension.changeContent(it, "public class Foo { public class Foo3 {} }", "");
                    _xblockexpression = this._javaEditorExtension.changeContent(it, "public static class Foo2 {}", "");
                }
                return _xblockexpression;
            };
            this.save("Bar.java", _function_1);
        };
        this.assertThereAreDeltas(_function, "Bar", "Bar$Foo", "Bar$Foo2", "Bar$Foo$Foo3");
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Procedure0(org.eclipse.xtext.xbase.lib.Procedures.Procedure0) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) AbstractQueuedBuildDataTest(org.eclipse.xtend.ide.tests.builder.AbstractQueuedBuildDataTest) Test(org.junit.Test)

Example 47 with Function1

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

the class DependentElementsCalculatorTests method testDependentElements.

@Test
public void testDependentElements() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def Foo foo() {");
        _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 file = this.testHelper.xtendFile("Foo", _builder.toString());
        XtendTypeDeclaration _get = file.getXtendTypes().get(0);
        final XtendClass fooClass = ((XtendClass) _get);
        NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
        final Iterable<URI> dependentElementURIs = this.dependentElementsCalculator.getDependentElementURIs(fooClass, _nullProgressMonitor);
        Assert.assertEquals(3, IterableExtensions.size(dependentElementURIs));
        XtendMember _get_1 = fooClass.getMembers().get(0);
        final XtendFunction fooFunction = ((XtendFunction) _get_1);
        final Consumer<EObject> _function = (EObject it) -> {
            final Function1<URI, Boolean> _function_1 = (URI element) -> {
                URI _uRI = EcoreUtil.getURI(it);
                return Boolean.valueOf(Objects.equal(element, _uRI));
            };
            Assert.assertTrue(it.toString(), IterableExtensions.<URI>exists(dependentElementURIs, _function_1));
        };
        CollectionLiterals.<EObject>newArrayList(fooFunction, this.associations.getInferredType(fooClass), this.associations.getInferredConstructor(fooClass)).forEach(_function);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) URI(org.eclipse.emf.common.util.URI) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) Test(org.junit.Test)

Example 48 with Function1

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

the class MemberFromSuperImplementor method appendConstructorFromSuper.

public void appendConstructorFromSuper(final XtendClass overrider, final IResolvedConstructor superConstructor, final ISourceAppender appendable) {
    final JvmGenericType inferredType = this.associations.getInferredType(overrider);
    final AbstractConstructorBuilder constructorBuilder = this.codeBuilderFactory.createConstructorBuilder(inferredType);
    this.initializeExecutableBuilder(constructorBuilder, inferredType, superConstructor);
    final Procedure1<ISourceAppender> _function = (ISourceAppender it) -> {
        boolean _isEmpty = superConstructor.getResolvedParameterTypes().isEmpty();
        boolean _not = (!_isEmpty);
        if (_not) {
            StringConcatenation _builder = new StringConcatenation();
            _builder.append("super(");
            final Function1<JvmFormalParameter, String> _function_1 = (JvmFormalParameter it_1) -> {
                return it_1.getSimpleName();
            };
            String _join = IterableExtensions.join(ListExtensions.<JvmFormalParameter, String>map(superConstructor.getDeclaration().getParameters(), _function_1), ", ");
            _builder.append(_join);
            _builder.append(")");
            it.append(_builder);
        }
    };
    constructorBuilder.setBodyGenerator(_function);
    boolean _isValid = constructorBuilder.isValid();
    if (_isValid) {
        constructorBuilder.build(appendable);
    }
}
Also used : AbstractConstructorBuilder(org.eclipse.xtend.ide.codebuilder.AbstractConstructorBuilder) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) ISourceAppender(org.eclipse.xtext.xbase.compiler.ISourceAppender)

Example 49 with Function1

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

the class JdtFindReferencesTest method testFindClassRef.

@Test
public void testFindClassRef() {
    try {
        Assert.assertTrue(this._workbenchTestHelper.createFile("Xtend.xtend", "class Xtend { }").exists());
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("public class JavaRef {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("private Xtend x;");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("public Xtend foo() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("return null;");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("public void bar() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("new Xtend();");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("\t");
        _builder.append("public void baz() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("Xtend y;");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        Assert.assertTrue(this._workbenchTestHelper.createFile("JavaRef.java", _builder.toString()).exists());
        IResourcesSetupUtil.waitForBuild();
        Assert.assertNotNull("Couldn\'t find \'src/Xtend.xtend\'.", this._workbenchTestHelper.getProject().findMember("/src/Xtend.xtend"));
        Assert.assertNotNull("Couldn\'t find \'src/JavaRef.java\'.", this._workbenchTestHelper.getProject().findMember("/src/JavaRef.java"));
        final IResource member = this._workbenchTestHelper.getProject().findMember("/xtend-gen/Xtend.java");
        if ((member == null)) {
            Assert.assertNotNull("Couldn\'t find \'xtend-gen/Xtend.java\'.", member);
        }
        IType type = JavaCore.create(this._workbenchTestHelper.getProject()).findType("Xtend");
        if ((type == null)) {
            Assert.assertNotNull("Couldn\'t find type \'Xtend\'.", type);
        }
        final IMethod constructor = type.getMethod("Xtend", ((String[]) Conversions.unwrapArray(CollectionLiterals.<String>newArrayList(), String.class)));
        ArrayList<Object> _findReferences = this.findReferences(type, constructor);
        final Procedure1<ArrayList<Object>> _function = (ArrayList<Object> it) -> {
            Assert.assertEquals(4, it.size());
            final Function1<IField, Boolean> _function_1 = (IField it_1) -> {
                String _elementName = it_1.getElementName();
                return Boolean.valueOf(Objects.equal(_elementName, "x"));
            };
            Assert.assertTrue(IterableExtensions.<IField>exists(Iterables.<IField>filter(it, IField.class), _function_1));
            final Function1<IMethod, Boolean> _function_2 = (IMethod it_1) -> {
                String _elementName = it_1.getElementName();
                return Boolean.valueOf(Objects.equal(_elementName, "foo"));
            };
            Assert.assertTrue(IterableExtensions.<IMethod>exists(Iterables.<IMethod>filter(it, IMethod.class), _function_2));
            final Function1<IMethod, Boolean> _function_3 = (IMethod it_1) -> {
                String _elementName = it_1.getElementName();
                return Boolean.valueOf(Objects.equal(_elementName, "bar"));
            };
            Assert.assertTrue(IterableExtensions.<IMethod>exists(Iterables.<IMethod>filter(it, IMethod.class), _function_3));
            final Function1<IMethod, Boolean> _function_4 = (IMethod it_1) -> {
                String _elementName = it_1.getElementName();
                return Boolean.valueOf(Objects.equal(_elementName, "baz"));
            };
            Assert.assertTrue(IterableExtensions.<IMethod>exists(Iterables.<IMethod>filter(it, IMethod.class), _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) IResource(org.eclipse.core.resources.IResource) IType(org.eclipse.jdt.core.IType) Test(org.junit.Test)

Example 50 with Function1

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

the class JdtFindReferencesTest method testBug387230.

@Test
public void testBug387230() {
    try {
        final XtendClass cls = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(this._workbenchTestHelper.xtendFile("Xtend.xtend", "@Data class Xtend { String field }").getXtendTypes(), XtendClass.class));
        IResourcesSetupUtil.waitForBuild();
        Iterable<IJavaElement> _javaElements = this._jvmModelFindReferenceHandler.getJavaElements(cls);
        final Procedure1<Iterable<IJavaElement>> _function = (Iterable<IJavaElement> it) -> {
            Assert.assertEquals(2, IterableExtensions.size(it));
            final Function1<IJavaElement, Boolean> _function_1 = (IJavaElement it_1) -> {
                return Boolean.valueOf(((it_1 instanceof IType) && Objects.equal(((IType) it_1).getElementName(), "Xtend")));
            };
            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(), "Xtend")));
            };
            Assert.assertTrue(IterableExtensions.<IJavaElement>exists(it, _function_2));
        };
        ObjectExtensions.<Iterable<IJavaElement>>operator_doubleArrow(_javaElements, _function);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) IMethod(org.eclipse.jdt.core.IMethod) IType(org.eclipse.jdt.core.IType) 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