Search in sources :

Example 96 with Function1

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

the class AccessObjectProcessorTest method testWithPackage.

@Test
public void testWithPackage() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package my.pack");
    _builder.newLine();
    _builder.append("import org.eclipse.xtend.core.tests.macro.Accessors");
    _builder.newLine();
    _builder.newLine();
    _builder.append("@org.eclipse.xtend.core.tests.macro.AccessObjectAnn");
    _builder.newLine();
    _builder.append("class A {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("String field");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final IAcceptor<XtendCompilerTester.CompilationResult> _function = (XtendCompilerTester.CompilationResult it) -> {
        final TransformationContext ctx = it.getTransformationContext();
        final MutableClassDeclaration classA = ctx.findClass("my.pack.A");
        Assert.assertNotNull(classA.findDeclaredMethod("getField"));
        final MutableClassDeclaration classPA = ctx.findClass("my.pack.PA");
        final Function1<TypeReference, Boolean> _function_1 = (TypeReference it_1) -> {
            Type _type = it_1.getType();
            Type _type_1 = ctx.newTypeReference(Serializable.class).getType();
            return Boolean.valueOf(Objects.equal(_type, _type_1));
        };
        Assert.assertNotNull(IterableExtensions.findFirst(classPA.getImplementedInterfaces(), _function_1));
        final MutableClassDeclaration classGA = ctx.findClass("my.pack.GA");
        final Function1<TypeReference, Boolean> _function_2 = (TypeReference it_1) -> {
            Type _type = it_1.getType();
            Type _type_1 = ctx.newTypeReference(Serializable.class).getType();
            return Boolean.valueOf(Objects.equal(_type, _type_1));
        };
        Assert.assertNotNull(IterableExtensions.findFirst(classGA.getImplementedInterfaces(), _function_2));
    };
    this._xtendCompilerTester.compile(_builder, _function);
}
Also used : Type(org.eclipse.xtend.lib.macro.declaration.Type) Serializable(java.io.Serializable) XtendCompilerTester(org.eclipse.xtend.core.compiler.batch.XtendCompilerTester) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) TypeReference(org.eclipse.xtend.lib.macro.declaration.TypeReference) TransformationContext(org.eclipse.xtend.lib.macro.TransformationContext) MutableClassDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration) AbstractActiveAnnotationTest(org.eclipse.xtend.core.tests.macro.AbstractActiveAnnotationTest) Test(org.junit.Test)

Example 97 with Function1

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

the class Bug456264Test method testAddError.

@Test
public void testAddError() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("@org.eclipse.xtend.core.tests.macro.Bug456264 class C {}");
    _builder.newLine();
    final IAcceptor<XtendCompilerTester.CompilationResult> _function = (XtendCompilerTester.CompilationResult it) -> {
        final List<? extends Problem> problems = it.getAllProblems();
        final Function1<Problem, String> _function_1 = (Problem it_1) -> {
            return it_1.getMessage();
        };
        Assert.assertEquals(ListExtensions.map(problems, _function_1).toString(), 1, problems.size());
        Assert.assertEquals("My error message", IterableExtensions.head(problems).getMessage());
        final List<? extends Problem> specificProblems = it.getProblems(IterableExtensions.head(it.getCompilationUnit().getSourceTypeDeclarations()));
        Assert.assertEquals(specificProblems.toString(), 1, problems.size());
        Assert.assertEquals("My error message", IterableExtensions.head(specificProblems).getMessage());
    };
    this._xtendCompilerTester.compile(_builder, _function);
}
Also used : XtendCompilerTester(org.eclipse.xtend.core.compiler.batch.XtendCompilerTester) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) List(java.util.List) Problem(org.eclipse.xtend.lib.macro.services.Problem) AbstractActiveAnnotationTest(org.eclipse.xtend.core.tests.macro.AbstractActiveAnnotationTest) Test(org.junit.Test)

Example 98 with Function1

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

the class ActualTypeArgumentCollectorTest method operation.

protected JvmOperation operation(final String typeParameters, final String... alternatingTypeReferences) {
    try {
        JvmOperation _xblockexpression = null;
        {
            StringConcatenation _builder = new StringConcatenation();
            _builder.append("def ");
            {
                boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(typeParameters);
                boolean _not = (!_isNullOrEmpty);
                if (_not) {
                    _builder.append("<");
                    _builder.append(typeParameters);
                    _builder.append(">");
                }
            }
            _builder.append(" void method(");
            final Function1<String, CharSequence> _function = (String it) -> {
                return it;
            };
            String _join = IterableExtensions.<String>join(((Iterable<String>) Conversions.doWrapArray(alternatingTypeReferences)), null, " p, ", " p", _function);
            _builder.append(_join);
            _builder.append(") {}");
            final String signature = _builder.toString();
            final XtendFunction function = this.function(signature.toString());
            final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
            _xblockexpression = operation;
        }
        return _xblockexpression;
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1)

Example 99 with Function1

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

the class ErrorTest method testErrorModel_138.

@Test
public void testErrorModel_138() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package test");
    _builder.newLine();
    _builder.append("class Bar<T> extends test.Bar.Foo<T> {}");
    _builder.newLine();
    final XtendFile file = this.processWithoutException(_builder);
    EList<Resource.Diagnostic> _errors = file.eResource().getErrors();
    final Procedure1<EList<Resource.Diagnostic>> _function = (EList<Resource.Diagnostic> it) -> {
        final Function1<Resource.Diagnostic, Boolean> _function_1 = (Resource.Diagnostic it_1) -> {
            return Boolean.valueOf(it_1.getMessage().startsWith("Cyclic "));
        };
        Assert.assertFalse(it.toString(), IterableExtensions.<Resource.Diagnostic>exists(it, _function_1));
    };
    ObjectExtensions.<EList<Resource.Diagnostic>>operator_doubleArrow(_errors, _function);
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) EList(org.eclipse.emf.common.util.EList) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) Test(org.junit.Test)

Example 100 with Function1

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

the class ResolvedExecutableImpl method getResolvedParameters.

@Override
public Iterable<? extends ResolvedParameter> getResolvedParameters() {
    Iterable<? extends ResolvedParameter> _xblockexpression = null;
    {
        if ((this.resolvedParameters == null)) {
            int _size = this.getDelegate().getDeclaration().getParameters().size();
            final Function1<Integer, ResolvedParameterImpl> _function = (Integer i) -> {
                ParameterDeclaration _parameterDeclaration = this.getCompilationUnit().toParameterDeclaration(this.getDelegate().getDeclaration().getParameters().get((i).intValue()));
                TypeReference _typeReference = this.getCompilationUnit().toTypeReference(this.getDelegate().getResolvedParameterTypes().get((i).intValue()));
                return new ResolvedParameterImpl(_parameterDeclaration, _typeReference);
            };
            this.resolvedParameters = IterableExtensions.<Integer, ResolvedParameterImpl>map(new ExclusiveRange(0, _size, true), _function);
        }
        _xblockexpression = this.resolvedParameters;
    }
    return _xblockexpression;
}
Also used : Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) ResolvedParameterImpl(org.eclipse.xtend.core.macro.declaration.ResolvedParameterImpl) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) TypeReference(org.eclipse.xtend.lib.macro.declaration.TypeReference) ExclusiveRange(org.eclipse.xtext.xbase.lib.ExclusiveRange) ParameterDeclaration(org.eclipse.xtend.lib.macro.declaration.ParameterDeclaration)

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