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();
}
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();
}
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;
}
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;
}
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;
}
Aggregations