下面列出了org.eclipse.lsp4j.jsonrpc.messages.Either#isRight ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private boolean shouldPrepareRename(ILanguageServerAccess access) {
Either<Boolean, RenameOptions> provider = null;
if (access != null) {
InitializeResult initializeResult = access.getInitializeResult();
if (initializeResult != null) {
ServerCapabilities capabilities = initializeResult.getCapabilities();
if (capabilities != null) {
provider = capabilities.getRenameProvider();
}
}
}
if (provider != null && provider.isRight()) {
return Boolean.TRUE.equals(provider.getRight().getPrepareProvider());
} else {
return false;
}
}
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 "";
}
}
public void documentSaved(long timestamp) {
this.modificationStamp = timestamp;
ServerCapabilities serverCapabilities = languageServerWrapper.getServerCapabilities();
if(serverCapabilities != null ) {
Either<TextDocumentSyncKind, TextDocumentSyncOptions> textDocumentSync = serverCapabilities.getTextDocumentSync();
if(textDocumentSync.isRight() && textDocumentSync.getRight().getSave() == null) {
return;
}
}
TextDocumentIdentifier identifier = new TextDocumentIdentifier(fileUri.toString());
DidSaveTextDocumentParams params = new DidSaveTextDocumentParams(identifier, document.getText());
languageServerWrapper.getInitializedServer().thenAcceptAsync(ls -> ls.getTextDocumentService().didSave(params));
}
/**
* Checks if the action has the same title as this. If it has, then assert that
* that action is equivalent to this in kind and content.
*/
public void assertEquivalent(Either<Command, CodeAction> action) throws Exception {
String title = getTitle(action);
assertEquals("Unexpected command :", name, title);
if (!ALL_KINDS.equals(kind) && action.isRight()) {
assertEquals(title + " has the wrong kind ", kind, action.getRight().getKind());
}
String actionContent = evaluateCodeActionCommand(action);
assertEquals(title + " has the wrong content ", content, actionContent);
}
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());
}
protected void writeId(JsonWriter out, Either<String, Number> id) throws IOException {
if (id == null)
writeNullValue(out);
else if (id.isLeft())
out.value(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 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));
}
/**
* Validate all fields of the given object.
*/
protected void validate(Object object, List<MessageIssue> issues, Deque<Object> objectStack, Deque<Object> accessorStack) throws Exception {
if (object == null
|| object instanceof Enum<?>
|| object instanceof String
|| object instanceof Number
|| object instanceof Boolean
|| object instanceof JsonElement
|| object instanceof Throwable) {
return;
}
if (objectStack.contains(object)) {
issues.add(new MessageIssue("An element of the message has a direct or indirect reference to itself."
+ " Path: " + createPathString(accessorStack),
ResponseErrorCode.InvalidParams.getValue()));
return;
}
objectStack.push(object);
if (object instanceof List<?>) {
ListIterator<?> iter = ((List<?>) object).listIterator();
while (iter.hasNext()) {
accessorStack.push(iter.nextIndex());
Object element = iter.next();
if (element == null) {
issues.add(new MessageIssue("Lists must not contain null references."
+ " Path: " + createPathString(accessorStack),
ResponseErrorCode.InvalidParams.getValue()));
}
validate(element, issues, objectStack, accessorStack);
accessorStack.pop();
}
} else if (object instanceof Either<?, ?>) {
Either<?, ?> either = (Either<?, ?>) object;
if (either.isLeft()) {
validate(either.getLeft(), issues, objectStack, accessorStack);
} else if (either.isRight()) {
validate(either.getRight(), issues, objectStack, accessorStack);
} else {
issues.add(new MessageIssue("An Either instance must not be empty."
+ " Path: " + createPathString(accessorStack),
ResponseErrorCode.InvalidParams.getValue()));
}
} else {
for (Method method : object.getClass().getMethods()) {
if (isGetter(method)) {
accessorStack.push(method);
Object value = method.invoke(object);
if (value == null && method.getAnnotation(NonNull.class) != null) {
issues.add(new MessageIssue("The accessor '" + method.getDeclaringClass().getSimpleName()
+ "." + method.getName() + "()' must return a non-null value."
+ " Path: " + createPathString(accessorStack),
ResponseErrorCode.InvalidParams.getValue()));
}
validate(value, issues, objectStack, accessorStack);
accessorStack.pop();
}
}
}
objectStack.pop();
}