Search in sources :

Example 1 with Function2

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;
}
Also used : IntegerRange(org.eclipse.xtext.xbase.lib.IntegerRange) Function2(org.eclipse.xtext.xbase.lib.Functions.Function2)

Example 2 with Function2

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;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) ArrayList(java.util.ArrayList) Function2(org.eclipse.xtext.xbase.lib.Functions.Function2) RuleCall(org.eclipse.xtext.RuleCall) Assignment(org.eclipse.xtext.Assignment) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) EObject(org.eclipse.emf.ecore.EObject) GeneratedJavaFileAccess(org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess) TypeReference(org.eclipse.xtext.xtext.generator.model.TypeReference) AbstractRule(org.eclipse.xtext.AbstractRule) HashSet(java.util.HashSet)

Example 3 with Function2

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);
}
Also used : ICodeLensResolver(org.eclipse.xtext.ide.server.codelens.ICodeLensResolver) CodeLens(org.eclipse.lsp4j.CodeLens) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) XtextResource(org.eclipse.xtext.resource.XtextResource) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) Function2(org.eclipse.xtext.xbase.lib.Functions.Function2) Document(org.eclipse.xtext.ide.server.Document) URI(org.eclipse.emf.common.util.URI)

Example 4 with Function2

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;
}
Also used : RenameChange(org.eclipse.xtext.ide.refactoring.RenameChange) RenameContext(org.eclipse.xtext.ide.refactoring.RenameContext) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) ChangeConverter(org.eclipse.xtext.ide.server.rename.ChangeConverter) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) XtextResource(org.eclipse.xtext.resource.XtextResource) Function2(org.eclipse.xtext.xbase.lib.Functions.Function2) Document(org.eclipse.xtext.ide.server.Document) URI(org.eclipse.emf.common.util.URI) ServerRefactoringIssueAcceptor(org.eclipse.xtext.ide.server.rename.ServerRefactoringIssueAcceptor) ProjectManager(org.eclipse.xtext.ide.server.ProjectManager) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Example 5 with Function2

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);
}
Also used : Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) Function0(org.eclipse.xtext.xbase.lib.Functions.Function0) Function2(org.eclipse.xtext.xbase.lib.Functions.Function2) ServerModule(org.eclipse.xtext.ide.server.ServerModule) Binder(com.google.inject.Binder) AnnotatedBindingBuilder(com.google.inject.binder.AnnotatedBindingBuilder) CompletableFuture(java.util.concurrent.CompletableFuture) RequestManager(org.eclipse.xtext.ide.server.concurrent.RequestManager) CancelIndicator(org.eclipse.xtext.util.CancelIndicator)

Aggregations

Function2 (org.eclipse.xtext.xbase.lib.Functions.Function2)9 EClass (org.eclipse.emf.ecore.EClass)4 INode (org.eclipse.xtext.nodemodel.INode)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 URI (org.eclipse.emf.common.util.URI)2 EObject (org.eclipse.emf.ecore.EObject)2 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)2 ValueConverterException (org.eclipse.xtext.conversion.ValueConverterException)2 Document (org.eclipse.xtext.ide.server.Document)2 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)2 LeafNode (org.eclipse.xtext.nodemodel.impl.LeafNode)2 XtextResource (org.eclipse.xtext.resource.XtextResource)2 CancelIndicator (org.eclipse.xtext.util.CancelIndicator)2 Binder (com.google.inject.Binder)1 AnnotatedBindingBuilder (com.google.inject.binder.AnnotatedBindingBuilder)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Resource (org.eclipse.emf.ecore.resource.Resource)1