use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-xtend by eclipse.
the class AbstractReusableActiveAnnotationTests method testMarkReadAndInitialized2.
@Test
public void testMarkReadAndInitialized2() {
Pair<String, String> _mappedTo = Pair.<String, String>of("myannotation/InitAnnotation.xtend", "\n\t\t\t\tpackage myannotation\n\t\t\t\t\n\t\t\t\timport java.util.List\n\t\t\t\timport org.eclipse.xtend.lib.macro.Active\n\t\t\t\timport org.eclipse.xtend.lib.macro.TransformationContext\n\t\t\t\timport org.eclipse.xtend.lib.macro.TransformationParticipant\n\t\t\t\timport org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration\n\t\t\t\timport org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration\n\n\t\t\t\t@Active(InitProcessor)\n\t\t\t\tannotation Init { }\n\t\t\t\tclass InitProcessor implements TransformationParticipant<MutableFieldDeclaration> {\n\t\t\t\t\t\n\t\t\t\t\toverride doTransform(List<? extends MutableFieldDeclaration> annotatedTargetFields, extension TransformationContext context) {\n\t\t\t\t\t\tval ctor = annotatedTargetFields.head.declaringType.addConstructor [\n\t\t\t\t\t\t\tprimarySourceElement = declaringType\n\t\t\t\t\t\t\tbody = [\'\'\'\n\t\t\t\t\t\t\t\t�FOR f : annotatedTargetFields�\n\t\t\t\t\t\t\t\t\tthis.�f.simpleName� = \"foo\";\n\t\t\t\t\t\t\t\t�ENDFOR�\n\t\t\t\t\t\t\t\'\'\']\n\t\t\t\t\t\t]\n\t\t\t\t\t\tannotatedTargetFields.forEach [ field |\n\t\t\t\t\t\t\tfield.setFinal(true)\n\t\t\t\t\t\t]\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t");
StringConcatenation _builder = new StringConcatenation();
_builder.append("package myusercode");
_builder.newLine();
_builder.newLine();
_builder.append("class MyClass {");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("@myannotation.Init String myField");
_builder.newLine();
_builder.append("}");
_builder.newLine();
Pair<String, String> _mappedTo_1 = Pair.<String, String>of("myusercode/UserCode.xtend", _builder.toString());
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
final Function1<Resource.Diagnostic, Boolean> _function_1 = (Resource.Diagnostic it_1) -> {
return Boolean.valueOf(it_1.getMessage().contains("myField may not have been initialized"));
};
IterableExtensions.<Resource.Diagnostic>exists(it.getXtendFile().eResource().getErrors(), _function_1);
};
this.assertProcessing(_mappedTo, _mappedTo_1, _function);
}
use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-xtend by eclipse.
the class AbstractReusableActiveAnnotationTests method testNoMutationInValidationPhase.
@Test
public void testNoMutationInValidationPhase() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package myannotation");
_builder.newLine();
_builder.newLine();
_builder.append("import java.util.List");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.Active");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.TransformationParticipant");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.ValidationParticipant");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.ValidationContext");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration");
_builder.newLine();
_builder.append("import org.eclipse.xtend.lib.macro.TransformationContext");
_builder.newLine();
_builder.newLine();
_builder.append("@Active(EvilProcessor)");
_builder.newLine();
_builder.append("annotation EvilAnnotation {");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("class EvilProcessor implements TransformationParticipant<MutableClassDeclaration>, ValidationParticipant<MutableClassDeclaration> {");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("override doTransform(List<? extends MutableClassDeclaration> classes, extension TransformationContext context) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("classes.forEach[");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("final = false");
_builder.newLine();
_builder.append("\t\t");
_builder.append("]");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("override doValidate(List<? extends MutableClassDeclaration> classes, extension ValidationContext context) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("classes.forEach[");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("final = true");
_builder.newLine();
_builder.append("\t\t");
_builder.append("]");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
Pair<String, String> _mappedTo = Pair.<String, String>of("myannotation/EvilAnnotation.xtend", _builder.toString());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("package myusercode");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("import myannotation.*");
_builder_1.newLine();
_builder_1.newLine();
_builder_1.append("@EvilAnnotation");
_builder_1.newLine();
_builder_1.append("class Foo {");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
Pair<String, String> _mappedTo_1 = Pair.<String, String>of("myusercode/UserCode.xtend", _builder_1.toString());
final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
final Function1<Resource.Diagnostic, Boolean> _function_1 = (Resource.Diagnostic it_1) -> {
return Boolean.valueOf(it_1.getMessage().contains("cannot be modified"));
};
IterableExtensions.<Resource.Diagnostic>exists(it.getXtendFile().eResource().getErrors(), _function_1);
};
this.assertProcessing(_mappedTo, _mappedTo_1, _function);
}
use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-core by eclipse.
the class BuildManager method internalBuild.
protected List<IResourceDescription.Delta> internalBuild(final CancelIndicator cancelIndicator) {
final ArrayList<URI> allDirty = new ArrayList<URI>(this.dirtyFiles);
final HashMultimap<ProjectDescription, URI> project2dirty = HashMultimap.<ProjectDescription, URI>create();
for (final URI dirty : allDirty) {
{
final ProjectDescription projectManager = this.workspaceManager.getProjectManager(dirty).getProjectDescription();
project2dirty.put(projectManager, dirty);
}
}
final HashMultimap<ProjectDescription, URI> project2deleted = HashMultimap.<ProjectDescription, URI>create();
for (final URI deleted : this.deletedFiles) {
{
final ProjectDescription projectManager = this.workspaceManager.getProjectManager(deleted).getProjectDescription();
project2deleted.put(projectManager, deleted);
}
}
Set<ProjectDescription> _keySet = project2dirty.keySet();
Set<ProjectDescription> _keySet_1 = project2deleted.keySet();
Iterable<ProjectDescription> _plus = Iterables.<ProjectDescription>concat(_keySet, _keySet_1);
final List<ProjectDescription> sortedDescriptions = this.sortByDependencies(_plus);
final ArrayList<IResourceDescription.Delta> result = CollectionLiterals.<IResourceDescription.Delta>newArrayList();
for (final ProjectDescription it : sortedDescriptions) {
{
final ProjectManager projectManager = this.workspaceManager.getProjectManager(it.getName());
final List<URI> projectDirty = IterableExtensions.<URI>toList(project2dirty.get(it));
final List<URI> projectDeleted = IterableExtensions.<URI>toList(project2deleted.get(it));
final IncrementalBuilder.Result partialResult = projectManager.doBuild(projectDirty, projectDeleted, result, cancelIndicator);
final Function1<IResourceDescription.Delta, URI> _function = (IResourceDescription.Delta it_1) -> {
return it_1.getUri();
};
allDirty.addAll(ListExtensions.<IResourceDescription.Delta, URI>map(partialResult.getAffectedResources(), _function));
Iterables.removeAll(this.dirtyFiles, projectDirty);
Iterables.removeAll(this.deletedFiles, projectDeleted);
result.addAll(partialResult.getAffectedResources());
}
}
return result;
}
use of org.eclipse.xtext.xbase.lib.Functions.Function1 in project xtext-core 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 ");
String _name = this.getGrammarNaming().getInternalParserSuperClass(it).getName();
_builder.append(_name);
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("import ");
TypeReference _elementTypeProvider = this._ideaPluginClassNames.getElementTypeProvider(GrammarUtil.getGrammar(it));
_builder.append(_elementTypeProvider);
_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 _name_1 = this._grammarAccessExtensions.getGrammarAccess(it).getName();
_builder.append(_name_1);
_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-core by eclipse.
the class AbstractAntlrGrammarWithActionsGenerator method _ebnf2.
@Override
protected String _ebnf2(final UnorderedGroup it, final AntlrOptions options, final boolean supportActions) {
String _xifexpression = null;
if (supportActions) {
String _xblockexpression = null;
{
final Function1<AbstractElement, Boolean> _function = (AbstractElement it_1) -> {
boolean _isOptionalCardinality = GrammarUtil.isOptionalCardinality(it_1);
return Boolean.valueOf((!_isOptionalCardinality));
};
final int mandatoryContent = IterableExtensions.size(IterableExtensions.<AbstractElement>filter(it.getElements(), _function));
StringConcatenation _builder = new StringConcatenation();
_builder.append("(");
_builder.newLine();
_builder.append("\t");
_builder.append("{ ");
_builder.newLine();
_builder.append("\t ");
_builder.append("getUnorderedGroupHelper().enter(grammarAccess.");
UnorderedGroup _originalElement = AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it);
String _gaRuleElementAccessor = this._grammarAccessExtensions.gaRuleElementAccessor(((AbstractElement) _originalElement));
_builder.append(_gaRuleElementAccessor, "\t ");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("(");
_builder.newLine();
_builder.append("\t\t");
_builder.append("(");
_builder.newLine();
{
Iterable<Pair<Integer, AbstractElement>> _indexed = IterableExtensions.<AbstractElement>indexed(it.getElements());
boolean _hasElements = false;
for (final Pair<Integer, AbstractElement> element : _indexed) {
if (!_hasElements) {
_hasElements = true;
} else {
_builder.appendImmediate("|", "");
}
_builder.append("(");
_builder.newLine();
_builder.append("\t");
_builder.append("{getUnorderedGroupHelper().canSelect(grammarAccess.");
UnorderedGroup _originalElement_1 = AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it);
String _gaRuleElementAccessor_1 = this._grammarAccessExtensions.gaRuleElementAccessor(((AbstractElement) _originalElement_1));
_builder.append(_gaRuleElementAccessor_1, "\t");
_builder.append(", ");
Integer _key = element.getKey();
_builder.append(_key, "\t");
_builder.append(")}?=>(");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("{");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("getUnorderedGroupHelper().select(grammarAccess.");
UnorderedGroup _originalElement_2 = AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it);
String _gaRuleElementAccessor_2 = this._grammarAccessExtensions.gaRuleElementAccessor(((AbstractElement) _originalElement_2));
_builder.append(_gaRuleElementAccessor_2, "\t\t\t");
_builder.append(", ");
Integer _key_1 = element.getKey();
_builder.append(_key_1, "\t\t\t");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t\t\t\t");
_builder.append("({true}?=>(");
String _ebnf2 = this.ebnf2(element.getValue(), options, supportActions);
_builder.append(_ebnf2, "\t\t\t\t\t");
_builder.append("))");
{
boolean _isMultipleCardinality = GrammarUtil.isMultipleCardinality(element.getValue());
if (_isMultipleCardinality) {
_builder.append("+");
}
}
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("{ ");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("getUnorderedGroupHelper().returnFromSelection(grammarAccess.");
UnorderedGroup _originalElement_3 = AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it);
String _gaRuleElementAccessor_3 = this._grammarAccessExtensions.gaRuleElementAccessor(((AbstractElement) _originalElement_3));
_builder.append(_gaRuleElementAccessor_3, "\t\t\t");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append(")");
_builder.newLine();
_builder.append(")");
_builder.newLine();
}
}
_builder.append("\t\t");
_builder.append(")");
{
if ((mandatoryContent != 0)) {
_builder.append("+");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("{getUnorderedGroupHelper().canLeave(grammarAccess.");
UnorderedGroup _originalElement_4 = AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it);
String _gaRuleElementAccessor_4 = this._grammarAccessExtensions.gaRuleElementAccessor(((AbstractElement) _originalElement_4));
_builder.append(_gaRuleElementAccessor_4, "\t\t");
_builder.append(")}?");
} else {
_builder.append("*");
}
}
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append(")");
_builder.newLine();
_builder.append(")");
_builder.newLine();
_builder.append("\t");
_builder.append("{ ");
_builder.newLine();
_builder.append("\t ");
_builder.append("getUnorderedGroupHelper().leave(grammarAccess.");
UnorderedGroup _originalElement_5 = AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it);
String _gaRuleElementAccessor_5 = this._grammarAccessExtensions.gaRuleElementAccessor(((AbstractElement) _originalElement_5));
_builder.append(_gaRuleElementAccessor_5, "\t ");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_xblockexpression = _builder.toString();
}
_xifexpression = _xblockexpression;
} else {
_xifexpression = super._ebnf2(it, options, supportActions);
}
return _xifexpression;
}
Aggregations