use of org.eclipse.xtext.xbase.lib.Functions.Function2 in project xtext-xtend by eclipse.
the class RichStringToLineModel method acceptSemanticText.
@Override
public void acceptSemanticText(final CharSequence text, final RichStringLiteral origin) {
super.acceptSemanticText(text, origin);
if ((!this.content)) {
if (((text.length() > 0) && (IterableExtensions.<Integer, Boolean>fold(new IntegerRange(0, (text.length() - 1)), Boolean.valueOf(false), ((Function2<Boolean, Integer, Boolean>) (Boolean v, Integer i) -> {
return Boolean.valueOf(((v).booleanValue() || (!Character.isWhitespace(text.charAt((i).intValue())))));
}))).booleanValue())) {
this.startContent();
}
}
int _length = text.length();
int _plus = (this.offset + _length);
this.offset = _plus;
}
use of org.eclipse.xtext.xbase.lib.Functions.Function2 in project xtext-core by eclipse.
the class ContentAssistFragment2 method generateGenJavaProposalProvider.
protected GeneratedJavaFileAccess generateGenJavaProposalProvider() {
GeneratedJavaFileAccess _xblockexpression = null;
{
final Set<String> excludedFqnFeatureNames = this.getFQFeatureNamesToExclude(this.getGrammar());
final HashSet<String> processedNames = CollectionLiterals.<String>newHashSet();
final Function2<ArrayList<Assignment>, Assignment, ArrayList<Assignment>> _function = (ArrayList<Assignment> candidates, Assignment assignment) -> {
ArrayList<Assignment> _xblockexpression_1 = null;
{
final String fqFeatureName = this.getFQFeatureName(assignment);
if (((!processedNames.contains(fqFeatureName)) && (!excludedFqnFeatureNames.contains(fqFeatureName)))) {
processedNames.add(fqFeatureName);
candidates.add(assignment);
}
_xblockexpression_1 = candidates;
}
return _xblockexpression_1;
};
final ArrayList<Assignment> assignments = IterableExtensions.<Assignment, ArrayList<Assignment>>fold(GrammarUtil.containedAssignments(this.getGrammar()), CollectionLiterals.<Assignment>newArrayList(), _function);
final Function2<ArrayList<AbstractRule>, AbstractRule, ArrayList<AbstractRule>> _function_1 = (ArrayList<AbstractRule> candidates, AbstractRule rule) -> {
ArrayList<AbstractRule> _xblockexpression_1 = null;
{
final String fqnFeatureName = this.getFQFeatureName(rule);
if (((!processedNames.contains(fqnFeatureName)) && (!excludedFqnFeatureNames.contains(fqnFeatureName)))) {
processedNames.add(fqnFeatureName);
candidates.add(rule);
}
_xblockexpression_1 = candidates;
}
return _xblockexpression_1;
};
final ArrayList<AbstractRule> remainingRules = IterableExtensions.<AbstractRule, ArrayList<AbstractRule>>fold(this.getGrammar().getRules(), CollectionLiterals.<AbstractRule>newArrayList(), _function_1);
TypeReference _xifexpression = null;
boolean _isGenerateStub = this.isGenerateStub();
if (_isGenerateStub) {
_xifexpression = this.getGenProposalProviderClass(this.getGrammar());
} else {
_xifexpression = this.getProposalProviderClass(this.getGrammar());
}
final TypeReference genClass = _xifexpression;
GeneratedJavaFileAccess _createGeneratedJavaFile = this.fileAccessFactory.createGeneratedJavaFile(genClass);
final Procedure1<GeneratedJavaFileAccess> _function_2 = (GeneratedJavaFileAccess it) -> {
final TypeReference superClass = this.getGenProposalProviderSuperClass(this.getGrammar());
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("/**");
_builder.newLine();
_builder.append(" ");
_builder.append("* Represents a generated, default implementation of superclass {@link ");
_builder.append(superClass, " ");
_builder.append("}.");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("* Methods are dynamically dispatched on the first parameter, i.e., you can override them ");
_builder.newLine();
_builder.append(" ");
_builder.append("* with a more concrete subtype. ");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
}
};
it.setTypeComment(_client);
StringConcatenationClient _client_1 = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public ");
{
boolean _isGenerateStub = ContentAssistFragment2.this.isGenerateStub();
if (_isGenerateStub) {
_builder.append("abstract ");
}
}
_builder.append("class ");
String _simpleName = genClass.getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
_builder.append(superClass);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
{
boolean _isEmpty = assignments.isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
{
for (final Assignment assignment : assignments) {
_builder.append("\t");
StringConcatenationClient _handleAssignment = ContentAssistFragment2.this.handleAssignment(assignment);
_builder.append(_handleAssignment, "\t");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
}
}
{
for (final AbstractRule rule : remainingRules) {
_builder.append("\t");
_builder.append("public void complete");
String _fQFeatureName = ContentAssistFragment2.this.getFQFeatureName(rule);
_builder.append(_fQFeatureName, "\t");
_builder.append("(");
_builder.append(EObject.class, "\t");
_builder.append(" model, ");
_builder.append(RuleCall.class, "\t");
_builder.append(" ruleCall, ");
TypeReference _contentAssistContextClass = ContentAssistFragment2.this.getContentAssistContextClass();
_builder.append(_contentAssistContextClass, "\t");
_builder.append(" context, ");
TypeReference _iCompletionProposalAcceptorClass = ContentAssistFragment2.this.getICompletionProposalAcceptorClass();
_builder.append(_iCompletionProposalAcceptorClass, "\t");
_builder.append(" acceptor) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("// subclasses may override");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
}
}
_builder.append("}");
_builder.newLine();
}
};
it.setContent(_client_1);
it.writeTo(this.getProjectConfig().getEclipsePlugin().getSrcGen());
};
_xblockexpression = ObjectExtensions.<GeneratedJavaFileAccess>operator_doubleArrow(_createGeneratedJavaFile, _function_2);
}
return _xblockexpression;
}
use of org.eclipse.xtext.xbase.lib.Functions.Function2 in project xtext-core by eclipse.
the class LanguageServerImpl method resolveCodeLens.
@Override
public CompletableFuture<CodeLens> resolveCodeLens(final CodeLens unresolved) {
final URI uri = this.uninstallURI(unresolved);
if ((uri == null)) {
return CompletableFuture.<CodeLens>completedFuture(unresolved);
}
final Function1<CancelIndicator, CodeLens> _function = (CancelIndicator cancelIndicator) -> {
final IResourceServiceProvider resourceServiceProvider = this.languagesRegistry.getResourceServiceProvider(uri);
ICodeLensResolver _get = null;
if (resourceServiceProvider != null) {
_get = resourceServiceProvider.<ICodeLensResolver>get(ICodeLensResolver.class);
}
final ICodeLensResolver resolver = _get;
if ((resolver == null)) {
return unresolved;
}
final Function2<Document, XtextResource, CodeLens> _function_1 = (Document document, XtextResource resource) -> {
final CodeLens result = resolver.resolveCodeLens(document, resource, unresolved, cancelIndicator);
return result;
};
return this.workspaceManager.<CodeLens>doRead(uri, _function_1);
};
return this.requestManager.<CodeLens>runRead(_function);
}
use of org.eclipse.xtext.xbase.lib.Functions.Function2 in project xtext-core by eclipse.
the class RenameService method rename.
@Override
public WorkspaceEdit rename(final WorkspaceManager workspaceManager, final RenameParams renameParams, final CancelIndicator cancelIndicator) {
WorkspaceEdit _xblockexpression = null;
{
final URI uri = this._uriExtensions.toUri(renameParams.getTextDocument().getUri());
final ServerRefactoringIssueAcceptor issueAcceptor = this.issueProvider.get();
final Function2<Document, XtextResource, WorkspaceEdit> _function = (Document document, XtextResource resource) -> {
final ProjectManager projectManager = workspaceManager.getProjectManager(uri);
final XtextResourceSet resourceSet = projectManager.createNewResourceSet(projectManager.getIndexState().getResourceDescriptions());
resourceSet.getLoadOptions().put(ResourceDescriptionsProvider.LIVE_SCOPE, Boolean.valueOf(true));
final int offset = document.getOffSet(renameParams.getPosition());
final WorkspaceEdit workspaceEdit = new WorkspaceEdit();
final Resource xtextResource = resourceSet.getResource(resource.getURI(), true);
if ((xtextResource instanceof XtextResource)) {
final EObject element = this._eObjectAtOffsetHelper.resolveElementAt(((XtextResource) xtextResource), offset);
if (((element == null) || element.eIsProxy())) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("No element found at position line:");
int _line = renameParams.getPosition().getLine();
_builder.append(_line);
_builder.append(" column:");
int _character = renameParams.getPosition().getCharacter();
_builder.append(_character);
issueAcceptor.add(RefactoringIssueAcceptor.Severity.FATAL, _builder.toString());
} else {
String _newName = renameParams.getNewName();
URI _uRI = EcoreUtil.getURI(element);
final RenameChange change = new RenameChange(_newName, _uRI);
final IChangeSerializer changeSerializer = this.changeSerializerProvider.get();
final RenameContext context = new RenameContext(Collections.<RenameChange>unmodifiableList(CollectionLiterals.<RenameChange>newArrayList(change)), resourceSet, changeSerializer, issueAcceptor);
this.renameStrategy.applyRename(context);
final ChangeConverter changeConverter = this.converterFactory.create(workspaceManager, workspaceEdit);
changeSerializer.applyModifications(changeConverter);
}
} else {
issueAcceptor.add(RefactoringIssueAcceptor.Severity.FATAL, "Loaded resource is not an XtextResource", resource.getURI());
}
return workspaceEdit;
};
_xblockexpression = workspaceManager.<WorkspaceEdit>doRead(uri, _function);
}
return _xblockexpression;
}
use of org.eclipse.xtext.xbase.lib.Functions.Function2 in project xtext-core by eclipse.
the class AbstractLanguageServerTest method getServerModule.
protected com.google.inject.Module getServerModule() {
ServerModule _serverModule = new ServerModule();
final com.google.inject.Module _function = (Binder it) -> {
AnnotatedBindingBuilder<RequestManager> _bind = it.<RequestManager>bind(RequestManager.class);
_bind.toInstance(new RequestManager() {
@Override
public <V extends Object> CompletableFuture<V> runRead(final Function1<? super CancelIndicator, ? extends V> request) {
final CompletableFuture<V> result = new CompletableFuture<V>();
try {
final CancelIndicator _function = () -> {
return false;
};
result.complete(request.apply(_function));
} catch (final Throwable _t) {
if (_t instanceof Throwable) {
final Throwable e = (Throwable) _t;
result.completeExceptionally(e);
} else {
throw Exceptions.sneakyThrow(_t);
}
}
return result;
}
@Override
public <U extends Object, V extends Object> CompletableFuture<V> runWrite(final Function0<? extends U> nonCancellable, final Function2<? super CancelIndicator, ? super U, ? extends V> request) {
final CompletableFuture<V> result = new CompletableFuture<V>();
try {
final CancelIndicator _function = () -> {
return false;
};
result.complete(request.apply(_function, nonCancellable.apply()));
} catch (final Throwable _t) {
if (_t instanceof Throwable) {
final Throwable e = (Throwable) _t;
result.completeExceptionally(e);
} else {
throw Exceptions.sneakyThrow(_t);
}
}
return result;
}
});
};
return Modules2.mixin(_serverModule, _function);
}
Aggregations