下面列出了org.eclipse.lsp4j.jsonrpc.messages.Either#isLeft ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected String _toExpectation(final Either<?, ?> either) {
StringConcatenation _builder = new StringConcatenation();
{
boolean _isLeft = either.isLeft();
if (_isLeft) {
String _expectation = this.toExpectation(either.getLeft());
_builder.append(_expectation);
_builder.newLineIfNotEmpty();
} else {
String _expectation_1 = this.toExpectation(either.getRight());
_builder.append(_expectation_1);
_builder.newLineIfNotEmpty();
}
}
return _builder.toString();
}
public static void applyCodeAction(LSPBindings server, Either<Command, CodeAction> cmd) {
try {
Command command;
if (cmd.isLeft()) {
command = cmd.getLeft();
} else {
Utils.applyWorkspaceEdit(cmd.getRight().getEdit());
command = cmd.getRight().getCommand();
}
if (command != null) {
server.getWorkspaceService().executeCommand(new ExecuteCommandParams(command.getCommand(), command.getArguments())).get();
}
} catch (InterruptedException | ExecutionException ex) {
Exceptions.printStackTrace(ex);
}
}
private String extractLabel(SignatureInformation signatureInformation, Either<String, Tuple.Two<Integer, Integer>> label) {
if (label.isLeft()) {
return label.getLeft();
} else if (label.isRight()) {
return signatureInformation.getLabel().substring(label.getRight().getFirst(), label.getRight().getSecond());
} else {
return "";
}
}
private TextEdit getTextEdit(Either<Command, CodeAction> codeAction) {
Command c = codeAction.isLeft() ? codeAction.getLeft() : codeAction.getRight().getCommand();
Assert.assertEquals(CodeActionHandler.COMMAND_ID_APPLY_EDIT, c.getCommand());
Assert.assertNotNull(c.getArguments());
Assert.assertTrue(c.getArguments().get(0) instanceof WorkspaceEdit);
WorkspaceEdit we = (WorkspaceEdit) c.getArguments().get(0);
Iterator<Entry<String, List<TextEdit>>> editEntries = we.getChanges().entrySet().iterator();
Entry<String, List<TextEdit>> entry = editEntries.next();
TextEdit edit = entry.getValue().get(0);
return edit;
}
/** @return string for given element */
public String toString2(Either<String, MarkedString> ms) {
if (ms == null) {
return "";
}
if (ms.isLeft()) {
return ms.getLeft();
} else {
return toString(ms.getRight());
}
}
@Override
public void write(JsonWriter out, Either<L, R> value) throws IOException {
if (value == null) {
out.nullValue();
} else if (value.isLeft()) {
left.write(out, value.getLeft());
} else {
right.write(out, value.getRight());
}
}
private WorkspaceEdit getWorkspaceEdit(Either<Command, CodeAction> codeAction) {
Command c = codeAction.isLeft() ? codeAction.getLeft() : codeAction.getRight().getCommand();
assertEquals(CodeActionHandler.COMMAND_ID_APPLY_EDIT, c.getCommand());
assertNotNull(c.getArguments());
assertTrue(c.getArguments().get(0) instanceof WorkspaceEdit);
return (WorkspaceEdit) c.getArguments().get(0);
}
/** @return string for given element */
public String toString6(Either<TextDocumentEdit, ResourceOperation> documentChanges) {
if (documentChanges == null) {
return "";
}
if (documentChanges.isLeft()) {
return toString(documentChanges.getLeft());
} else {
return toString(documentChanges.getRight());
}
}
/** @return string for given element */
public String toString7(Either<String, MarkupContent> documentation) {
if (documentation == null) {
return "";
}
if (documentation.isLeft()) {
return documentation.getLeft();
} else {
return toString(documentation.getRight());
}
}
/** @return string for given element */
public String toString8(Either<String, Two<Integer, Integer>> documentation) {
if (documentation == null) {
return "";
}
if (documentation.isLeft()) {
return documentation.getLeft();
} else {
Two<Integer, Integer> right = documentation.getRight();
return "(" + right.getFirst() + "," + right.getSecond() + ")";
}
}
private void writeIntId(JsonWriter out, Either<String, Number> id) throws IOException {
if (id == null)
writeNullValue(out);
else if (id.isLeft())
out.value(Integer.parseInt(id.getLeft()));
else if (id.isRight())
out.value(id.getRight());
}
private boolean checkCodeActionProvider(Either<Boolean, CodeActionOptions> provider) {
return provider != null && ((provider.isLeft() && provider.getLeft()) || (provider.isRight()
&& provider.getRight() != null));
}
private Collection<? extends LookupElement> toProposals(Project project, Editor editor, Document document, int offset, Either<List<CompletionItem>, CompletionList> completion, LanguageServer languageServer) {
List<CompletionItem> items = completion.isLeft()?completion.getLeft():completion.getRight().getItems();
return items.stream().map(item -> createLookupItem(project, editor, offset, item, languageServer)).collect(Collectors.toList());
//return Collections.singletonList(LookupElementBuilder.create("quarkus.application.name=").withPresentableText("quarkus.application.name="));
}
public Command getCommand(Either<Command, CodeAction> codeAction) {
return codeAction.isLeft() ? codeAction.getLeft() : codeAction.getRight().getCommand();
}
public static Command getCommand(Either<Command, CodeAction> codeAction) {
return codeAction.isLeft() ? codeAction.getLeft() : codeAction.getRight().getCommand();
}
private boolean isTagSupported(Either<Boolean, DiagnosticsTagSupport> tagSupport) {
return tagSupport.isLeft() ? tagSupport.getLeft() : tagSupport.getRight().getValueSet() != null;
}
private static Children createChildren(String currentFileUri, Either<SymbolInformation, DocumentSymbol> sym) {
if (sym.isLeft()) {
return LEAF;
}
return createChildren(currentFileUri, sym.getRight());
}
public void setBindings(LSPBindings bindings) {
this.bindings = bindings;
ServerCapabilities serverCapabilities = bindings.getInitResult().getCapabilities();
Either<Boolean, CodeActionOptions> codeActions = serverCapabilities.getCodeActionProvider();
allowCodeActions = codeActions != null && (!codeActions.isLeft() || codeActions.getLeft());
}
private boolean checkProvider(Either<Boolean, StaticRegistrationOptions> provider) {
return provider != null && ((provider.isLeft() && provider.getLeft()) || (provider.isRight()
&& provider.getRight() != null));
}
private boolean checkCodeActionProvider(Either<Boolean, CodeActionOptions> provider) {
return provider != null && ((provider.isLeft() && provider.getLeft()) || (provider.isRight()
&& provider.getRight() != null));
}