Java Code Examples for org.eclipse.lsp4j.jsonrpc.messages.Either#forLeft()
The following examples show how to use
org.eclipse.lsp4j.jsonrpc.messages.Either#forLeft() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HoverTypeAdapter.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
protected Either<List<Either<String, MarkedString>>, MarkupContent> readContents(final JsonReader in) throws IOException { final JsonToken nextToken = in.peek(); boolean _equals = Objects.equal(nextToken, JsonToken.STRING); if (_equals) { final List<Either<String, MarkedString>> value = CollectionLiterals.<Either<String, MarkedString>>newArrayList(Either.<String, MarkedString>forLeft(in.nextString())); return Either.<List<Either<String, MarkedString>>, MarkupContent>forLeft(value); } else { boolean _equals_1 = Objects.equal(nextToken, JsonToken.BEGIN_ARRAY); if (_equals_1) { final List<Either<String, MarkedString>> value_1 = this.gson.<List<Either<String, MarkedString>>>fromJson(in, HoverTypeAdapter.LIST_STRING_MARKEDSTRING.getType()); return Either.<List<Either<String, MarkedString>>, MarkupContent>forLeft(value_1); } else { JsonElement _parse = new JsonParser().parse(in); final JsonObject object = ((JsonObject) _parse); boolean _has = object.has("language"); if (_has) { final List<Either<String, MarkedString>> value_2 = CollectionLiterals.<Either<String, MarkedString>>newArrayList(Either.<String, MarkedString>forRight(this.gson.<MarkedString>fromJson(object, MarkedString.class))); return Either.<List<Either<String, MarkedString>>, MarkupContent>forLeft(value_2); } else { return Either.<List<Either<String, MarkedString>>, MarkupContent>forRight(this.gson.<MarkupContent>fromJson(object, MarkupContent.class)); } } } }
Example 2
Source File: Diagnostic.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
public void setCode(final String code) { if (code == null) { this.code = null; return; } this.code = Either.forLeft(code); }
Example 3
Source File: ServerCapabilities.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
public void setTypeHierarchyProvider(final Boolean typeHierarchyProvider) { if (typeHierarchyProvider == null) { this.typeHierarchyProvider = null; return; } this.typeHierarchyProvider = Either.forLeft(typeHierarchyProvider); }
Example 4
Source File: ServerCapabilities.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
public void setCallHierarchyProvider(final Boolean callHierarchyProvider) { if (callHierarchyProvider == null) { this.callHierarchyProvider = null; return; } this.callHierarchyProvider = Either.forLeft(callHierarchyProvider); }
Example 5
Source File: ServerCapabilities.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
public void setFoldingRangeProvider(final Boolean foldingRangeProvider) { if (foldingRangeProvider == null) { this.foldingRangeProvider = null; return; } this.foldingRangeProvider = Either.forLeft(foldingRangeProvider); }
Example 6
Source File: CompletionItem.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
public void setDocumentation(final String documentation) { if (documentation == null) { this.documentation = null; return; } this.documentation = Either.forLeft(documentation); }
Example 7
Source File: EitherTest.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
@Test public void testEqualsForNull() { Either<Object, Object> either1 = Either.forLeft(null); Either<Object, Object> either2 = Either.forLeft(null); assertTrue(either1.equals(either2)); }
Example 8
Source File: EitherTest.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
@Test public void testEqualsFalseWithNonNull() { Either<Object, String> either1 = Either.forLeft("Testing"); Either<Object, String> either2 = Either.forRight("Testing"); assertFalse(either1.equals(either2)); }
Example 9
Source File: ServerCapabilities.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
public void setImplementationProvider(final Boolean implementationProvider) { if (implementationProvider == null) { this.implementationProvider = null; return; } this.implementationProvider = Either.forLeft(implementationProvider); }
Example 10
Source File: PublishDiagnosticsCapabilities.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
public void setTagSupport(final Boolean tagSupport) { if (tagSupport == null) { this.tagSupport = null; return; } this.tagSupport = Either.forLeft(tagSupport); }
Example 11
Source File: ServerCapabilities.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
public void setSelectionRangeProvider(final Boolean selectionRangeProvider) { if (selectionRangeProvider == null) { this.selectionRangeProvider = null; return; } this.selectionRangeProvider = Either.forLeft(selectionRangeProvider); }
Example 12
Source File: SignatureInformation.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
public void setDocumentation(final String documentation) { if (documentation == null) { this.documentation = null; return; } this.documentation = Either.forLeft(documentation); }
Example 13
Source File: WorkspaceFoldersOptions.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
public void setChangeNotifications(final String changeNotifications) { if (changeNotifications == null) { this.changeNotifications = null; return; } this.changeNotifications = Either.forLeft(changeNotifications); }
Example 14
Source File: StackFrame.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
public void setModuleId(final Integer moduleId) { if (moduleId == null) { this.moduleId = null; return; } this.moduleId = Either.forLeft(moduleId); }
Example 15
Source File: PrepareRenameHandler.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public Either<Range, PrepareRenameResult> prepareRename(TextDocumentPositionParams params, IProgressMonitor monitor) { final ICompilationUnit unit = JDTUtils.resolveCompilationUnit(params.getTextDocument().getUri()); if (unit != null) { try { OccurrencesFinder finder = new OccurrencesFinder(); CompilationUnit ast = CoreASTProvider.getInstance().getAST(unit, CoreASTProvider.WAIT_YES, monitor); if (ast != null) { int offset = JsonRpcHelpers.toOffset(unit.getBuffer(), params.getPosition().getLine(), params.getPosition().getCharacter()); String error = finder.initialize(ast, offset, 0); if (error == null) { OccurrenceLocation[] occurrences = finder.getOccurrences(); if (occurrences != null) { for (OccurrenceLocation loc : occurrences) { if (monitor.isCanceled()) { return Either.forLeft(new Range()); } if (loc.getOffset() <= offset && loc.getOffset() + loc.getLength() >= offset) { InnovationContext context = new InnovationContext(unit, loc.getOffset(), loc.getLength()); context.setASTRoot(ast); ASTNode node = context.getCoveredNode(); // Rename package is not fully supported yet. if (!isBinaryOrPackage(node)) { return Either.forLeft(JDTUtils.toRange(unit, loc.getOffset(), loc.getLength())); } } } } } } } catch (CoreException e) { JavaLanguageServerPlugin.logException("Problem computing occurrences for" + unit.getElementName() + " in prepareRename", e); } } throw new ResponseErrorException(new ResponseError(ResponseErrorCode.InvalidRequest, "Renaming this element is not supported.", null)); }
Example 16
Source File: ParameterInformation.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
public void setLabel(final String label) { if (label == null) { Preconditions.checkNotNull(label, "label"); this.label = null; return; } this.label = Either.forLeft(label); }
Example 17
Source File: EitherTest.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
@Test public void testRightEqualsNull() { Either<Object, String> either1 = Either.forLeft("Testing"); Either<Object, String> either2 = Either.forLeft("Testing"); assertTrue(either1.equals(either2)); }
Example 18
Source File: XMLAssert.java From lemminx with Eclipse Public License 2.0 | 4 votes |
public static Either<TextDocumentEdit, ResourceOperation> teOp(String uri, int startLine, int startChar, int endLine, int endChar, String newText) { return Either.forLeft(new TextDocumentEdit(new VersionedTextDocumentIdentifier(uri, 0), Collections.singletonList(te(startLine, startChar, endLine, endChar, newText)))); }
Example 19
Source File: DebugNotificationMessage.java From lsp4j with Eclipse Public License 2.0 | 4 votes |
public void setId(String id) { this.id = Either.forLeft(id); }
Example 20
Source File: MessageTypeAdapter.java From lsp4j with Eclipse Public License 2.0 | 4 votes |
@Override public Message read(JsonReader in) throws IOException, JsonIOException, JsonSyntaxException { if (in.peek() == JsonToken.NULL) { in.nextNull(); return null; } in.beginObject(); String jsonrpc = null, method = null; Either<String, Number> id = null; Object rawParams = null; Object rawResult = null; ResponseError responseError = null; try { while (in.hasNext()) { String name = in.nextName(); switch (name) { case "jsonrpc": { jsonrpc = in.nextString(); break; } case "id": { if (in.peek() == JsonToken.NUMBER) id = Either.forRight(in.nextInt()); else id = Either.forLeft(in.nextString()); break; } case "method": { method = in.nextString(); break; } case "params": { rawParams = parseParams(in, method); break; } case "result": { rawResult = parseResult(in, id != null ? id.get().toString() : null); break; } case "error": { responseError = gson.fromJson(in, ResponseError.class); break; } default: in.skipValue(); } } Object params = parseParams(rawParams, method); Object result = parseResult(rawResult, id != null ? id.get().toString() : null); in.endObject(); return createMessage(jsonrpc, id, method, params, result, responseError); } catch (JsonSyntaxException | MalformedJsonException | EOFException exception) { if (id != null || method != null) { // Create a message and bundle it to an exception with an issue that wraps the original exception Message message = createMessage(jsonrpc, id, method, rawParams, rawResult, responseError); MessageIssue issue = new MessageIssue("Message could not be parsed.", ResponseErrorCode.ParseError.getValue(), exception); throw new MessageIssueException(message, issue); } else { throw exception; } } }