protected Iterable<IGeneratorNode> leafsBackwards(final IGeneratorNode it) { Iterable<IGeneratorNode> _switchResult = null; boolean _matched = false; if (it instanceof CompositeGeneratorNode) { _matched=true; final Function1<IGeneratorNode, Iterable<IGeneratorNode>> _function = (IGeneratorNode it_1) -> { return this.leafsBackwards(it_1); }; final Function2<Iterable<IGeneratorNode>, Iterable<IGeneratorNode>, Iterable<IGeneratorNode>> _function_1 = (Iterable<IGeneratorNode> p1, Iterable<IGeneratorNode> p2) -> { return Iterables.<IGeneratorNode>concat(p1, p2); }; _switchResult = IterableExtensions.<Iterable<IGeneratorNode>>reduce(ListExtensions.<IGeneratorNode, Iterable<IGeneratorNode>>map(ListExtensions.<IGeneratorNode>reverseView(((CompositeGeneratorNode)it).getChildren()), _function), _function_1); } if (!_matched) { _switchResult = Collections.<IGeneratorNode>unmodifiableList(CollectionLiterals.<IGeneratorNode>newArrayList(it)); } return _switchResult; }
@Test(timeout = 1000) public void testRunReadAfterWrite() { try { final Function0<Object> _function = () -> { return null; }; final Function2<CancelIndicator, Object, Integer> _function_1 = (CancelIndicator $0, Object $1) -> { return Integer.valueOf(this.sharedState.incrementAndGet()); }; this.requestManager.<Object, Integer>runWrite(_function, _function_1); final Function1<CancelIndicator, Integer> _function_2 = (CancelIndicator it) -> { return Integer.valueOf(this.sharedState.get()); }; final CompletableFuture<Integer> future = this.requestManager.<Integer>runRead(_function_2); Assert.assertEquals(1, (future.get()).intValue()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Test(timeout = 1000) public void testRunWriteAfterRead() { final Function1<CancelIndicator, Integer> _function = (CancelIndicator it) -> { return Integer.valueOf(this.sharedState.incrementAndGet()); }; final CompletableFuture<Integer> previsousRead = this.requestManager.<Integer>runRead(_function); final Function0<Object> _function_1 = () -> { return null; }; final Function2<CancelIndicator, Object, Integer> _function_2 = (CancelIndicator $0, Object $1) -> { int _xblockexpression = (int) 0; { while (((this.sharedState.get() == 0) && (!previsousRead.isCancelled()))) { } _xblockexpression = this.sharedState.incrementAndGet(); } return Integer.valueOf(_xblockexpression); }; this.requestManager.<Object, Integer>runWrite(_function_1, _function_2).join(); Assert.assertEquals(2, this.sharedState.get()); }
@Test public void testConvertNullInput() throws Exception { EClass eClass = EcoreFactory.eINSTANCE.createEClass(); Function2<String, INode, Object> toValueImpl = new Function2<String, INode, Object>() { @Override public Object apply(String lexerRule, INode node) { if ("foo".equals(lexerRule) ) { return "FOO"; } return null; } }; DefaultEcoreElementFactory factory = new DefaultEcoreElementFactory(); factory.setConverterService(new MockedConverterService(toValueImpl)); factory.set(eClass, "name", null, "foo", null); assertEquals("FOO", eClass.getName()); }
protected Either<List<CompletionItem>, CompletionList> completion(final CancelIndicator origialCancelIndicator, final TextDocumentPositionParams params) { final LanguageServerImpl.BufferedCancelIndicator cancelIndicator = new LanguageServerImpl.BufferedCancelIndicator(origialCancelIndicator); final URI uri = this._uriExtensions.toUri(params.getTextDocument().getUri()); final IResourceServiceProvider resourceServiceProvider = this.languagesRegistry.getResourceServiceProvider(uri); ContentAssistService _get = null; if (resourceServiceProvider!=null) { _get=resourceServiceProvider.<ContentAssistService>get(ContentAssistService.class); } final ContentAssistService contentAssistService = _get; if ((contentAssistService == null)) { CompletionList _completionList = new CompletionList(); return Either.<List<CompletionItem>, CompletionList>forRight(_completionList); } final Function2<Document, XtextResource, CompletionList> _function = (Document document, XtextResource resource) -> { return contentAssistService.createCompletionList(document, resource, params, cancelIndicator); }; final CompletionList completionList = this.workspaceManager.<CompletionList>doRead(uri, _function); return Either.<List<CompletionItem>, CompletionList>forRight(completionList); }
protected List<? extends Location> definition(final CancelIndicator cancelIndicator, final TextDocumentPositionParams params) { final URI uri = this._uriExtensions.toUri(params.getTextDocument().getUri()); final IResourceServiceProvider resourceServiceProvider = this.languagesRegistry.getResourceServiceProvider(uri); DocumentSymbolService _get = null; if (resourceServiceProvider!=null) { _get=resourceServiceProvider.<DocumentSymbolService>get(DocumentSymbolService.class); } final DocumentSymbolService documentSymbolService = _get; if ((documentSymbolService == null)) { return CollectionLiterals.<Location>emptyList(); } final Function2<Document, XtextResource, List<? extends Location>> _function = (Document document, XtextResource resource) -> { return documentSymbolService.getDefinitions(document, resource, params, this.resourceAccess, cancelIndicator); }; return this.workspaceManager.<List<? extends Location>>doRead(uri, _function); }
@Override public CompletableFuture<List<? extends Location>> references(final ReferenceParams params) { final Function1<CancelIndicator, List<? extends Location>> _function = (CancelIndicator cancelIndicator) -> { final URI uri = this._uriExtensions.toUri(params.getTextDocument().getUri()); final IResourceServiceProvider resourceServiceProvider = this.languagesRegistry.getResourceServiceProvider(uri); DocumentSymbolService _get = null; if (resourceServiceProvider!=null) { _get=resourceServiceProvider.<DocumentSymbolService>get(DocumentSymbolService.class); } final DocumentSymbolService documentSymbolService = _get; if ((documentSymbolService == null)) { return CollectionLiterals.<Location>emptyList(); } final Function2<Document, XtextResource, List<? extends Location>> _function_1 = (Document document, XtextResource resource) -> { return documentSymbolService.getReferences(document, resource, params, this.resourceAccess, this.workspaceManager.getIndex(), cancelIndicator); }; return this.workspaceManager.<List<? extends Location>>doRead(uri, _function_1); }; return this.requestManager.<List<? extends Location>>runRead(_function); }
@Override public CompletableFuture<List<? extends SymbolInformation>> documentSymbol(final DocumentSymbolParams params) { final Function1<CancelIndicator, List<? extends SymbolInformation>> _function = (CancelIndicator cancelIndicator) -> { final URI uri = this._uriExtensions.toUri(params.getTextDocument().getUri()); final IResourceServiceProvider resourceServiceProvider = this.languagesRegistry.getResourceServiceProvider(uri); DocumentSymbolService _get = null; if (resourceServiceProvider!=null) { _get=resourceServiceProvider.<DocumentSymbolService>get(DocumentSymbolService.class); } final DocumentSymbolService documentSymbolService = _get; if ((documentSymbolService == null)) { return CollectionLiterals.<SymbolInformation>emptyList(); } final Function2<Document, XtextResource, List<? extends SymbolInformation>> _function_1 = (Document document, XtextResource resource) -> { return documentSymbolService.getSymbols(document, resource, params, cancelIndicator); }; return this.workspaceManager.<List<? extends SymbolInformation>>doRead(uri, _function_1); }; return this.requestManager.<List<? extends SymbolInformation>>runRead(_function); }
@Override public CompletableFuture<Hover> hover(final TextDocumentPositionParams params) { final Function1<CancelIndicator, Hover> _function = (CancelIndicator cancelIndicator) -> { final URI uri = this._uriExtensions.toUri(params.getTextDocument().getUri()); final IResourceServiceProvider resourceServiceProvider = this.languagesRegistry.getResourceServiceProvider(uri); IHoverService _get = null; if (resourceServiceProvider!=null) { _get=resourceServiceProvider.<IHoverService>get(IHoverService.class); } final IHoverService hoverService = _get; if ((hoverService == null)) { return IHoverService.EMPTY_HOVER; } final Function2<Document, XtextResource, Hover> _function_1 = (Document document, XtextResource resource) -> { return hoverService.hover(document, resource, params, cancelIndicator); }; return this.workspaceManager.<Hover>doRead(uri, _function_1); }; return this.requestManager.<Hover>runRead(_function); }
@Override public CompletableFuture<SignatureHelp> signatureHelp(final TextDocumentPositionParams params) { final Function1<CancelIndicator, SignatureHelp> _function = (CancelIndicator cancelIndicator) -> { final URI uri = this._uriExtensions.toUri(params.getTextDocument().getUri()); final IResourceServiceProvider serviceProvider = this.languagesRegistry.getResourceServiceProvider(uri); ISignatureHelpService _get = null; if (serviceProvider!=null) { _get=serviceProvider.<ISignatureHelpService>get(ISignatureHelpService.class); } final ISignatureHelpService helper = _get; if ((helper == null)) { return ISignatureHelpService.EMPTY; } final Function2<Document, XtextResource, SignatureHelp> _function_1 = (Document doc, XtextResource resource) -> { return helper.getSignatureHelp(doc, resource, params, cancelIndicator); }; return this.workspaceManager.<SignatureHelp>doRead(uri, _function_1); }; return this.requestManager.<SignatureHelp>runRead(_function); }
@Override public CompletableFuture<List<? extends DocumentHighlight>> documentHighlight(final TextDocumentPositionParams params) { final Function1<CancelIndicator, List<? extends DocumentHighlight>> _function = (CancelIndicator cancelIndicator) -> { final URI uri = this._uriExtensions.toUri(params.getTextDocument().getUri()); final IResourceServiceProvider serviceProvider = this.languagesRegistry.getResourceServiceProvider(uri); IDocumentHighlightService _get = null; if (serviceProvider!=null) { _get=serviceProvider.<IDocumentHighlightService>get(IDocumentHighlightService.class); } final IDocumentHighlightService service = _get; if ((service == null)) { return CollectionLiterals.<DocumentHighlight>emptyList(); } final Function2<Document, XtextResource, List<? extends DocumentHighlight>> _function_1 = (Document doc, XtextResource resource) -> { return service.getDocumentHighlights(doc, resource, params, cancelIndicator); }; return this.workspaceManager.<List<? extends DocumentHighlight>>doRead(uri, _function_1); }; return this.requestManager.<List<? extends DocumentHighlight>>runRead(_function); }
@Override public CompletableFuture<List<? extends Command>> codeAction(final CodeActionParams params) { final Function1<CancelIndicator, List<? extends Command>> _function = (CancelIndicator cancelIndicator) -> { final URI uri = this._uriExtensions.toUri(params.getTextDocument().getUri()); final IResourceServiceProvider serviceProvider = this.languagesRegistry.getResourceServiceProvider(uri); ICodeActionService _get = null; if (serviceProvider!=null) { _get=serviceProvider.<ICodeActionService>get(ICodeActionService.class); } final ICodeActionService service = _get; if ((service == null)) { return CollectionLiterals.<Command>emptyList(); } final Function2<Document, XtextResource, List<? extends Command>> _function_1 = (Document doc, XtextResource resource) -> { return service.getCodeActions(doc, resource, params, cancelIndicator); }; return this.workspaceManager.<List<? extends Command>>doRead(uri, _function_1); }; return this.requestManager.<List<? extends Command>>runRead(_function); }
@Override public CompletableFuture<List<? extends CodeLens>> codeLens(final CodeLensParams params) { final Function1<CancelIndicator, List<? extends CodeLens>> _function = (CancelIndicator cancelIndicator) -> { final URI uri = this._uriExtensions.toUri(params.getTextDocument().getUri()); final IResourceServiceProvider resourceServiceProvider = this.languagesRegistry.getResourceServiceProvider(uri); ICodeLensService _get = null; if (resourceServiceProvider!=null) { _get=resourceServiceProvider.<ICodeLensService>get(ICodeLensService.class); } final ICodeLensService codeLensService = _get; if ((codeLensService == null)) { return CollectionLiterals.<CodeLens>emptyList(); } final Function2<Document, XtextResource, List<? extends CodeLens>> _function_1 = (Document document, XtextResource resource) -> { final List<? extends CodeLens> result = codeLensService.computeCodeLenses(document, resource, params, cancelIndicator); this.installURI(result, uri.toString()); return result; }; return this.workspaceManager.<List<? extends CodeLens>>doRead(uri, _function_1); }; return this.requestManager.<List<? extends CodeLens>>runRead(_function); }
@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); }
@Override public CompletableFuture<List<? extends TextEdit>> formatting(final DocumentFormattingParams params) { final Function1<CancelIndicator, List<? extends TextEdit>> _function = (CancelIndicator cancelIndicator) -> { final URI uri = this._uriExtensions.toUri(params.getTextDocument().getUri()); final IResourceServiceProvider resourceServiceProvider = this.languagesRegistry.getResourceServiceProvider(uri); FormattingService _get = null; if (resourceServiceProvider!=null) { _get=resourceServiceProvider.<FormattingService>get(FormattingService.class); } final FormattingService formatterService = _get; if ((formatterService == null)) { return CollectionLiterals.<TextEdit>emptyList(); } final Function2<Document, XtextResource, List<? extends TextEdit>> _function_1 = (Document document, XtextResource resource) -> { return formatterService.format(document, resource, params, cancelIndicator); }; return this.workspaceManager.<List<? extends TextEdit>>doRead(uri, _function_1); }; return this.requestManager.<List<? extends TextEdit>>runRead(_function); }
@Override public CompletableFuture<List<? extends TextEdit>> rangeFormatting(final DocumentRangeFormattingParams params) { final Function1<CancelIndicator, List<? extends TextEdit>> _function = (CancelIndicator cancelIndicator) -> { final URI uri = this._uriExtensions.toUri(params.getTextDocument().getUri()); final IResourceServiceProvider resourceServiceProvider = this.languagesRegistry.getResourceServiceProvider(uri); FormattingService _get = null; if (resourceServiceProvider!=null) { _get=resourceServiceProvider.<FormattingService>get(FormattingService.class); } final FormattingService formatterService = _get; if ((formatterService == null)) { return CollectionLiterals.<TextEdit>emptyList(); } final Function2<Document, XtextResource, List<? extends TextEdit>> _function_1 = (Document document, XtextResource resource) -> { return formatterService.format(document, resource, params, cancelIndicator); }; return this.workspaceManager.<List<? extends TextEdit>>doRead(uri, _function_1); }; return this.requestManager.<List<? extends TextEdit>>runRead(_function); }
public static void fillBoard(final ServerBoardImpl board, final IntPoint size, final CheckModelElement checker, final Function2<Integer, Integer, Integer> heightFunction) { final Procedure2<Integer, Integer> _function = new Procedure2<Integer, Integer>() { @Override public void apply(final Integer x, final Integer y) { final int id = IDGenerator.generateId(); final IntPoint boardCoordinate = IntPoint.from((x).intValue(), (y).intValue()); final int height = (heightFunction.apply(x, y)).intValue(); final CellTypes cellType = CellTypes.PLAIN; final ServerCellImpl cell = new ServerCellImpl(id, boardCoordinate, height, cellType, checker); cell.setBattle(false); cell.setStrength(0); cell.<Player>setOwner(null); board.setCellAt(cell); } }; FieldLoop.visitAllFields(size.x, size.y, _function); }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public String getValueAsString() { final StringBuilder result = new StringBuilder("`"); final Function1<Expression, StringBuilder> _function = new Function1<Expression, StringBuilder>() { public StringBuilder apply(final Expression expr) { StringBuilder _switchResult = null; boolean _matched = false; if (expr instanceof Literal) { _matched=true; _switchResult = result.append(TemplateLiteralImpl.this.getValueAsString()); } if (!_matched) { _switchResult = result.append("<<").append(TemplateLiteralImpl.this.eClass().getName()).append(">>"); } return _switchResult; } }; final Function1<Expression, StringBuilder> appender = _function; final Function2<Boolean, Expression, Boolean> _function_1 = new Function2<Boolean, Expression, Boolean>() { public Boolean apply(final Boolean isRaw, final Expression expression) { if ((!(isRaw).booleanValue())) { result.append("${"); appender.apply(expression); result.append("}"); } else { appender.apply(expression); } return Boolean.valueOf((!(isRaw).booleanValue())); } }; IterableExtensions.<Expression, Boolean>fold(this.getSegments(), Boolean.valueOf(true), _function_1); result.append("`"); return result.toString(); }
public int getLenght() { final Function2<Integer, LeafInfo, Integer> _function = (Integer x, LeafInfo i) -> { ILeafNode _node = i.getNode(); int _length = 0; if (_node!=null) { _length=_node.getLength(); } return Integer.valueOf(((x).intValue() + _length)); }; return (int) IterableExtensions.<LeafInfo, Integer>fold(this.leafs, Integer.valueOf(0), _function); }
public int getNewLines() { final Function2<Integer, LeafInfo, Integer> _function = (Integer x, LeafInfo i) -> { int _newLines = i.getNewLines(); return Integer.valueOf(((x).intValue() + _newLines)); }; return (int) IterableExtensions.<LeafInfo, Integer>fold(this.leafs, Integer.valueOf(0), _function); }
public int getNewLinesInComments() { final Function2<Integer, CommentInfo, Integer> _function = (Integer x, CommentInfo i) -> { int _newLines = i.getNewLines(); return Integer.valueOf(((x).intValue() + _newLines)); }; return (int) IterableExtensions.<CommentInfo, Integer>fold(Iterables.<CommentInfo>filter(this.leafs, CommentInfo.class), Integer.valueOf(0), _function); }
/** * Curries a function that takes two arguments. * * @param function * the original function. May not be <code>null</code>. * @param argument * the fixed first argument of {@code function}. * @return a function that takes one argument. Never <code>null</code>. */ @Pure public static <P1, P2, RESULT> Function1<P2, RESULT> curry(final Function2<? super P1, ? super P2, ? extends RESULT> function, final P1 argument) { if (function == null) throw new NullPointerException("function"); return new Function1<P2, RESULT>() { @Override public RESULT apply(P2 p) { return function.apply(argument, p); } }; }
/** * Curries a function that takes three arguments. * * @param function * the original function. May not be <code>null</code>. * @param argument * the fixed first argument of {@code function}. * @return a function that takes two arguments. Never <code>null</code>. */ @Pure public static <P1, P2, P3, RESULT> Function2<P2, P3, RESULT> curry(final Function3<? super P1, ? super P2, ? super P3, ? extends RESULT> function, final P1 argument) { if (function == null) throw new NullPointerException("function"); return new Function2<P2, P3, RESULT>() { @Override public RESULT apply(P2 p2, P3 p3) { return function.apply(argument, p2, p3); } }; }
public TypeReference replace(final TypeReference target, final Map<? extends TypeReference, ? extends TypeReference> mappings) { final Function2<TypeReference, Map.Entry<? extends TypeReference, ? extends TypeReference>, TypeReference> _function = new Function2<TypeReference, Map.Entry<? extends TypeReference, ? extends TypeReference>, TypeReference>() { @Override public TypeReference apply(final TypeReference result, final Map.Entry<? extends TypeReference, ? extends TypeReference> mapping) { return Util.this.replace(result, mapping.getKey(), mapping.getValue()); } }; return IterableExtensions.fold(mappings.entrySet(), target, _function); }
/** * Finds an EObject for the given context EObject and fragment. * * @param from the EObject from which the path should be resolved * @param toFragment the fragment * * @return the resolved EObject based. If the given fragment is <code>null</null>, the given EObject itself will be returned. */ public EObject getEObject(final EObject from, final String toFragment) { if ((toFragment == null)) { return from; } final Iterable<String> splitted = Splitter.on("/").split(toFragment); final Function2<EObject, String, EObject> _function = (EObject $0, String $1) -> { return ((InternalEObject) $0).eObjectForURIFragmentSegment($1); }; return IterableExtensions.<String, EObject>fold(splitted, from, _function); }
@Test(timeout = 1000) public void testRunWrite() { final Function0<Object> _function = () -> { return null; }; final Function2<CancelIndicator, Object, Integer> _function_1 = (CancelIndicator $0, Object $1) -> { return Integer.valueOf(this.sharedState.incrementAndGet()); }; this.requestManager.<Object, Integer>runWrite(_function, _function_1).join(); Assert.assertEquals(1, this.sharedState.get()); }
@Test public void testDoRead() { StringConcatenation _builder = new StringConcatenation(); _builder.append("type Test {"); _builder.newLine(); _builder.append(" "); _builder.append("string foo"); _builder.newLine(); _builder.append("}"); _builder.newLine(); final URI path = this.operator_mappedTo("MyType1.testlang", _builder); this.workspaceManger.doBuild(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(path)), CollectionLiterals.<URI>emptyList(), null); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("type Test {"); _builder_1.newLine(); _builder_1.append(" "); _builder_1.append("Test foo"); _builder_1.newLine(); _builder_1.append("}"); _builder_1.newLine(); final String inMemContents = _builder_1.toString(); this.workspaceManger.didOpen(path, 1, inMemContents).build(null); final Function2<Document, XtextResource, String> _function = (Document $0, XtextResource $1) -> { return $0.getContents(); }; Assert.assertEquals(inMemContents, this.workspaceManger.<String>doRead(path, _function)); }
@Test public void testNullInput() throws Exception { EClass eClass = EcoreFactory.eINSTANCE.createEClass(); final ILeafNode node = new LeafNode(); Function2<String, INode, Object> toValueImpl = new Function2<String, INode, Object>() { @Override public Object apply(String lexerRule, INode nodeParam) { if ("foo".equals(lexerRule) && nodeParam.equals(node)) { return null; } fail(); return null; } }; DefaultEcoreElementFactory factory = new DefaultEcoreElementFactory(); factory.setConverterService(new MockedConverterService(toValueImpl)); try { factory.set(eClass, "abstract", null, "foo", node); fail("Expected ValueConverterException"); } catch (ValueConverterException ex) { assertNull(ex.getCause()); assertTrue(ex.getMessage().indexOf("ValueConverter returned null for") >= 0); assertSame(node, ex.getNode()); } }
@Test public void testValueConverterException() throws Exception { EClass eClass = EcoreFactory.eINSTANCE.createEClass(); final ILeafNode node = new LeafNode(); final ValueConverterException expected = new ValueConverterException("Foo", node, null); Function2<String, INode, Object> toValueImpl = new Function2<String, INode, Object>() { @Override public Object apply(String lexerRule, INode nodeParam) { if ("foo".equals(lexerRule) && node.equals(nodeParam)) { throw expected; } fail(); return null; } }; DefaultEcoreElementFactory factory = new DefaultEcoreElementFactory(); factory.setConverterService(new MockedConverterService(toValueImpl)); try { factory.set(eClass, "abstract", null, "foo", node); fail("Expected ValueConverterException"); } catch (ValueConverterException ex) { assertSame(expected, ex); } }
@Override public <R extends Object> R readOnly(final URI targetURI, final IUnitOfWork<R, ResourceSet> work) { final Function2<Document, XtextResource, R> _function = (Document document, XtextResource resource) -> { try { if ((resource == null)) { return null; } return work.exec(resource.getResourceSet()); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }; return this.workspaceManager.<R>doRead(targetURI, _function); }
protected void _handleReplacements(final IEmfResourceChange change) { try { final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { final URI uri = change.getResource().getURI(); change.getResource().save(outputStream, null); byte[] _byteArray = outputStream.toByteArray(); String _charset = this.getCharset(change.getResource()); final String newContent = new String(_byteArray, _charset); final Function2<Document, XtextResource, List<TextEdit>> _function = (Document document, XtextResource resource) -> { List<TextEdit> _xblockexpression = null; { Position _position = document.getPosition(0); Position _position_1 = document.getPosition(document.getContents().length()); final Range range = new Range(_position, _position_1); final TextEdit textEdit = new TextEdit(range, newContent); _xblockexpression = this.addTextEdit(uri, textEdit); } return _xblockexpression; }; this.workspaceManager.<List<TextEdit>>doRead(uri, _function); } finally { outputStream.close(); } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@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; }
@Override public void didOpen(final DidOpenTextDocumentParams params) { final Function0<BuildManager.Buildable> _function = () -> { return this.workspaceManager.didOpen(this._uriExtensions.toUri(params.getTextDocument().getUri()), params.getTextDocument().getVersion(), params.getTextDocument().getText()); }; final Function2<CancelIndicator, BuildManager.Buildable, List<IResourceDescription.Delta>> _function_1 = (CancelIndicator cancelIndicator, BuildManager.Buildable buildable) -> { return buildable.build(cancelIndicator); }; this.requestManager.<BuildManager.Buildable, List<IResourceDescription.Delta>>runWrite(_function, _function_1); }
@Override public void didClose(final DidCloseTextDocumentParams params) { final Function0<BuildManager.Buildable> _function = () -> { return this.workspaceManager.didClose(this._uriExtensions.toUri(params.getTextDocument().getUri())); }; final Function2<CancelIndicator, BuildManager.Buildable, List<IResourceDescription.Delta>> _function_1 = (CancelIndicator cancelIndicator, BuildManager.Buildable buildable) -> { return buildable.build(cancelIndicator); }; this.requestManager.<BuildManager.Buildable, List<IResourceDescription.Delta>>runWrite(_function, _function_1); }
@Override public void didChangeWatchedFiles(final DidChangeWatchedFilesParams params) { final Function0<BuildManager.Buildable> _function = () -> { BuildManager.Buildable _xblockexpression = null; { final ArrayList<URI> dirtyFiles = CollectionLiterals.<URI>newArrayList(); final ArrayList<URI> deletedFiles = CollectionLiterals.<URI>newArrayList(); List<FileEvent> _changes = params.getChanges(); for (final FileEvent fileEvent : _changes) { FileChangeType _type = fileEvent.getType(); boolean _tripleEquals = (_type == FileChangeType.Deleted); if (_tripleEquals) { URI _uri = this._uriExtensions.toUri(fileEvent.getUri()); deletedFiles.add(_uri); } else { URI _uri_1 = this._uriExtensions.toUri(fileEvent.getUri()); dirtyFiles.add(_uri_1); } } _xblockexpression = this.workspaceManager.didChangeFiles(dirtyFiles, deletedFiles); } return _xblockexpression; }; final Function2<CancelIndicator, BuildManager.Buildable, List<IResourceDescription.Delta>> _function_1 = (CancelIndicator cancelIndicator, BuildManager.Buildable buildable) -> { return buildable.build(cancelIndicator); }; this.requestManager.<BuildManager.Buildable, List<IResourceDescription.Delta>>runWrite(_function, _function_1); }
@Override public void didChangeConfiguration(final DidChangeConfigurationParams params) { final Function0<Object> _function = () -> { this.workspaceManager.refreshWorkspaceConfig(CancelIndicator.NullImpl); return null; }; final Function2<CancelIndicator, Object, Object> _function_1 = (CancelIndicator $0, Object $1) -> { return null; }; this.requestManager.<Object, Object>runWrite(_function, _function_1); }
@Override public <T extends Object> CompletableFuture<T> doRead(final String uri, final Function<ILanguageServerAccess.Context, T> function) { final Function1<CancelIndicator, T> _function = (CancelIndicator cancelIndicator) -> { final Function2<Document, XtextResource, T> _function_1 = (Document document, XtextResource resource) -> { boolean _isDocumentOpen = LanguageServerImpl.this.workspaceManager.isDocumentOpen(resource.getURI()); final ILanguageServerAccess.Context ctx = new ILanguageServerAccess.Context(resource, document, _isDocumentOpen, cancelIndicator); return function.apply(ctx); }; return LanguageServerImpl.this.workspaceManager.<T>doRead(LanguageServerImpl.this._uriExtensions.toUri(uri), _function_1); }; return LanguageServerImpl.this.requestManager.<T>runRead(_function); }
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>(); final CompletableFuture<Void> localWritePending = new CompletableFuture<Void>(); this.writePending = localWritePending; final Callable<Boolean> _function = () -> { boolean _xblockexpression = false; { final RequestCancelIndicator cancelIndicator = new RequestCancelIndicator(result); boolean _xtrycatchfinallyexpression = false; try { boolean _xblockexpression_1 = false; { this.cancel(); this.w.lock(); localWritePending.complete(null); final U intermediateResult = nonCancellable.apply(); this.toCancel.add(cancelIndicator); cancelIndicator.checkCanceled(); _xblockexpression_1 = result.complete(request.apply(cancelIndicator, intermediateResult)); } _xtrycatchfinallyexpression = _xblockexpression_1; } catch (final Throwable _t) { if (_t instanceof Throwable) { final Throwable e = (Throwable)_t; _xtrycatchfinallyexpression = result.completeExceptionally(e); } else { throw Exceptions.sneakyThrow(_t); } } finally { this.toCancel.remove(cancelIndicator); this.w.unlock(); } _xblockexpression = _xtrycatchfinallyexpression; } return Boolean.valueOf(_xblockexpression); }; this.parallel.<Boolean>submit(_function); return result; }
public <T extends Object> T doRead(final URI uri, final Function2<? super Document, ? super XtextResource, ? extends T> work) { final URI resourceURI = uri.trimFragment(); final ProjectManager projectMnr = this.getProjectManager(resourceURI); Resource _resource = null; if (projectMnr!=null) { _resource=projectMnr.getResource(resourceURI); } final XtextResource resource = ((XtextResource) _resource); if ((resource == null)) { return work.apply(null, null); } Document doc = this.getDocument(resource); Resource _resource_1 = projectMnr.getResource(resourceURI); return work.apply(doc, ((XtextResource) _resource_1)); }
public Integer getMaxJRows(final ConnectiveTreeBuilder ctb) { List<Pair<String, List<JointMovement>>> _states = ctb.getStates(); int _size = _states.size(); ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _size, true); final Function2<Integer, Integer, Integer> _function = new Function2<Integer, Integer, Integer>() { @Override public Integer apply(final Integer acc, final Integer idx) { int _rowNumForState = RigidBodiesGenerator.this.getRowNumForState(ctb, (idx).intValue()); return Integer.valueOf(Math.max((acc).intValue(), _rowNumForState)); } }; return IterableExtensions.<Integer, Integer>fold(_doubleDotLessThan, Integer.valueOf(1), _function); }