Search in sources :

Example 1 with Function1

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

the class AntlrGrammarGenerator method compileParserImports.

@Override
protected String compileParserImports(final Grammar it, final AntlrOptions options) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.newLine();
    _builder.append("import org.eclipse.xtext.*;");
    _builder.newLine();
    _builder.append("import org.eclipse.xtext.parser.*;");
    _builder.newLine();
    _builder.append("import org.eclipse.xtext.parser.impl.*;");
    _builder.newLine();
    _builder.append("import org.eclipse.emf.ecore.util.EcoreUtil;");
    _builder.newLine();
    _builder.append("import org.eclipse.emf.ecore.EObject;");
    _builder.newLine();
    {
        boolean _isEmpty = GrammarUtil.allEnumRules(it).isEmpty();
        boolean _not = (!_isEmpty);
        if (_not) {
            _builder.append("import org.eclipse.emf.common.util.Enumerator;");
            _builder.newLine();
        }
    }
    _builder.append("import org.eclipse.xtext.parser.antlr.AbstractInternalAntlrParser;");
    _builder.newLine();
    _builder.append("import org.eclipse.xtext.parser.antlr.XtextTokenStream;");
    _builder.newLine();
    _builder.append("import org.eclipse.xtext.parser.antlr.XtextTokenStream.HiddenTokens;");
    _builder.newLine();
    {
        if (((!IterableExtensions.isEmpty(Iterables.<UnorderedGroup>filter(Iterables.<EObject>concat(ListExtensions.<ParserRule, List<EObject>>map(GrammarUtil.allParserRules(it), ((Function1<ParserRule, List<EObject>>) (ParserRule it_1) -> {
            return EcoreUtil2.eAllContentsAsList(it_1);
        }))), UnorderedGroup.class))) && options.isBacktrack())) {
            _builder.append("import org.eclipse.xtext.parser.antlr.IUnorderedGroupHelper.UnorderedGroupState;");
            _builder.newLine();
        }
    }
    _builder.append("import org.eclipse.xtext.parser.antlr.AntlrDatatypeRuleToken;");
    _builder.newLine();
    _builder.append("import ");
    String _gaFQName = this._grammarAccess.gaFQName(it);
    _builder.append(_gaFQName);
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    return _builder.toString();
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) UnorderedGroup(org.eclipse.xtext.UnorderedGroup) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) List(java.util.List)

Example 2 with Function1

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

the class PsiAntlrGrammarGenerator method compileParserImports.

@Override
protected String compileParserImports(final Grammar it, final AntlrOptions options) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.newLine();
    _builder.append("import org.eclipse.xtext.idea.parser.AbstractPsiAntlrParser;");
    _builder.newLine();
    _builder.append("import ");
    String _elementTypeProviderName = this._ideaPluginClassNames.getElementTypeProviderName(GrammarUtil.getGrammar(it));
    _builder.append(_elementTypeProviderName);
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    _builder.append("import org.eclipse.xtext.idea.parser.TokenTypeProvider;");
    _builder.newLine();
    _builder.append("import org.eclipse.xtext.parser.antlr.XtextTokenStream;");
    _builder.newLine();
    _builder.append("import org.eclipse.xtext.parser.antlr.XtextTokenStream.HiddenTokens;");
    _builder.newLine();
    {
        if (((!IterableExtensions.isEmpty(Iterables.<UnorderedGroup>filter(Iterables.<EObject>concat(ListExtensions.<ParserRule, List<EObject>>map(GrammarUtil.allParserRules(it), ((Function1<ParserRule, List<EObject>>) (ParserRule it_1) -> {
            return EcoreUtil2.eAllContentsAsList(it_1);
        }))), UnorderedGroup.class))) && options.isBacktrack())) {
            _builder.append("import org.eclipse.xtext.parser.antlr.IUnorderedGroupHelper.UnorderedGroupState;");
            _builder.newLine();
        }
    }
    _builder.append("import ");
    String _gaFQName = this._grammarAccess.gaFQName(it);
    _builder.append(_gaFQName);
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("import com.intellij.lang.PsiBuilder;");
    _builder.newLine();
    return _builder.toString();
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) UnorderedGroup(org.eclipse.xtext.UnorderedGroup) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) List(java.util.List)

Example 3 with Function1

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

the class InMemoryJavaCompiler method compile.

public InMemoryJavaCompiler.Result compile(final JavaSource... sources) {
    final InMemoryJavaCompiler.Result result = new InMemoryJavaCompiler.Result(this.parentClassLoader);
    IErrorHandlingPolicy _proceedWithAllProblems = DefaultErrorHandlingPolicies.proceedWithAllProblems();
    final ICompilerRequestor _function = (CompilationResult it) -> {
        ClassFile[] _classFiles = it.getClassFiles();
        for (final ClassFile cf : _classFiles) {
            final Function1<char[], String> _function_1 = (char[] it_1) -> {
                return String.valueOf(it_1);
            };
            result.classMap.put(IterableExtensions.join(ListExtensions.<char[], String>map(((List<char[]>) Conversions.doWrapArray(cf.getCompoundName())), _function_1), "."), cf.getBytes());
        }
    };
    org.eclipse.jdt.internal.compiler.Compiler compiler = new org.eclipse.jdt.internal.compiler.Compiler(this.nameEnv, _proceedWithAllProblems, this.compilerOptions, _function, new DefaultProblemFactory() {

        @Override
        public CategorizedProblem createProblem(final char[] originatingFileName, final int problemId, final String[] problemArguments, final int elaborationId, final String[] messageArguments, final int severity, final int startPosition, final int endPosition, final int lineNumber, final int columnNumber) {
            final CategorizedProblem problem = super.createProblem(originatingFileName, problemId, problemArguments, elaborationId, messageArguments, severity, startPosition, endPosition, lineNumber, columnNumber);
            result.compilationProblems.add(problem);
            return problem;
        }

        @Override
        public CategorizedProblem createProblem(final char[] originatingFileName, final int problemId, final String[] problemArguments, final String[] messageArguments, final int severity, final int startPosition, final int endPosition, final int lineNumber, final int columnNumber) {
            final CategorizedProblem problem = super.createProblem(originatingFileName, problemId, problemArguments, messageArguments, severity, startPosition, endPosition, lineNumber, columnNumber);
            result.compilationProblems.add(problem);
            return problem;
        }
    });
    final Function1<JavaSource, CompilationUnit> _function_1 = (JavaSource it) -> {
        char[] _charArray = it.getCode().toCharArray();
        String _fileName = it.getFileName();
        return new CompilationUnit(_charArray, _fileName, null);
    };
    ICompilationUnit[] units = ((ICompilationUnit[]) Conversions.unwrapArray(ListExtensions.<JavaSource, CompilationUnit>map(((List<JavaSource>) Conversions.doWrapArray(sources)), _function_1), ICompilationUnit.class));
    compiler.compile(units);
    return result;
}
Also used : IErrorHandlingPolicy(org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy) CompilationResult(org.eclipse.jdt.internal.compiler.CompilationResult) JavaSource(org.eclipse.xtext.xbase.compiler.JavaSource) DefaultProblemFactory(org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory) CompilationUnit(org.eclipse.jdt.internal.compiler.batch.CompilationUnit) ICompilationUnit(org.eclipse.jdt.internal.compiler.env.ICompilationUnit) ICompilationUnit(org.eclipse.jdt.internal.compiler.env.ICompilationUnit) ClassFile(org.eclipse.jdt.internal.compiler.ClassFile) ICompilerRequestor(org.eclipse.jdt.internal.compiler.ICompilerRequestor) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) CategorizedProblem(org.eclipse.jdt.core.compiler.CategorizedProblem) CompilationResult(org.eclipse.jdt.internal.compiler.CompilationResult)

Example 4 with Function1

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

the class FormatterTester method applyDebugEdits.

protected String applyDebugEdits(final String oldDocument, final Collection<TextReplacement> edits) {
    String _xblockexpression = null;
    {
        int lastOffset = 0;
        final StringBuilder debugTrace = new StringBuilder();
        final Function1<TextReplacement, Integer> _function = (TextReplacement it) -> {
            return Integer.valueOf(it.getOffset());
        };
        List<TextReplacement> _sortBy = IterableExtensions.<TextReplacement, Integer>sortBy(edits, _function);
        for (final TextReplacement edit : _sortBy) {
            {
                debugTrace.append(oldDocument.substring(lastOffset, edit.getOffset()));
                StringConcatenation _builder = new StringConcatenation();
                _builder.append("[");
                int _offset = edit.getOffset();
                int _length = edit.getLength();
                int _plus = (_offset + _length);
                String _substring = oldDocument.substring(edit.getOffset(), _plus);
                _builder.append(_substring);
                _builder.append("|");
                String _text = edit.getText();
                _builder.append(_text);
                _builder.append("]");
                debugTrace.append(_builder);
                int _offset_1 = edit.getOffset();
                int _length_1 = edit.getLength();
                int _plus_1 = (_offset_1 + _length_1);
                lastOffset = _plus_1;
            }
        }
        debugTrace.append(oldDocument.substring(lastOffset, oldDocument.length()));
        _xblockexpression = debugTrace.toString();
    }
    return _xblockexpression;
}
Also used : TextReplacement(org.eclipse.xtext.xbase.formatting.TextReplacement) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with Function1

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

the class Xbase10_Switch method myMethod.

public List<String> myMethod() throws Throwable {
    List<String> _xblockexpression = null;
    {
        final ArrayList<String> list = CollectionLiterals.<String>newArrayList("foo", "bar", "baz");
        String _head = IterableExtensions.<String>head(list);
        if (_head != null) {
            switch(_head) {
                case "foo":
                    /* "it\'s foo" */
                    break;
                case "bar":
                    /* "a bar" */
                    break;
                default:
                    /* "don\'t know" */
                    break;
            }
        } else {
        /* "don\'t know" */
        }
        Rectangle _rectangle = new Rectangle(5, 5);
        Circle _circle = new Circle(4);
        Rectangle _rectangle_1 = new Rectangle(6, 8);
        final ArrayList<Shape> list2 = CollectionLiterals.<Shape>newArrayList(_rectangle, _circle, _rectangle_1);
        final Function1<Shape, String> _function = (Shape shape) -> {
            String _switchResult_1 = null;
            boolean _matched = false;
            if (shape instanceof Circle) {
                _matched = true;
                _switchResult_1 = ("a circle : diameter=" + Integer.valueOf(((Circle) shape).diameter));
            }
            if (!_matched) {
                if (shape instanceof Rectangle) {
                    if ((((Rectangle) shape).height == ((Rectangle) shape).width)) {
                        _matched = true;
                        _switchResult_1 = ("a square : size=" + Integer.valueOf(((Rectangle) shape).width));
                    }
                }
            }
            if (!_matched) {
                if (shape instanceof Rectangle) {
                    _matched = true;
                    _switchResult_1 = ((("a rectangle : width=" + Integer.valueOf(((Rectangle) shape).width)) + ", height=") + Integer.valueOf(((Rectangle) shape).height));
                }
            }
            return _switchResult_1;
        };
        _xblockexpression = ListExtensions.<Shape, String>map(list2, _function);
    }
    return _xblockexpression;
}
Also used : Circle(helper.Circle) Shape(helper.Shape) ArrayList(java.util.ArrayList) Rectangle(helper.Rectangle) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1)

Aggregations

Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)172 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)92 Test (org.junit.Test)55 List (java.util.List)29 ArrayList (java.util.ArrayList)22 EObject (org.eclipse.emf.ecore.EObject)20 EList (org.eclipse.emf.common.util.EList)17 AbstractXtendCompilerTest (org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest)17 CompilationTestHelper (org.eclipse.xtext.xbase.testing.CompilationTestHelper)17 ColumnSource (com.robotoworks.mechanoid.db.sqliteModel.ColumnSource)13 Method (java.lang.reflect.Method)12 Set (java.util.Set)12 URI (org.eclipse.emf.common.util.URI)11 Resource (org.eclipse.emf.ecore.resource.Resource)9 CompilationUnitImpl (org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl)9 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)9 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)9 ScreenListItemCell (org.applause.lang.applauseDsl.ScreenListItemCell)8 IMethod (org.eclipse.jdt.core.IMethod)8 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)8