下面列出了org.eclipse.lsp4j.jsonrpc.messages.Either#forRight ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static Either<String, MarkupContent> beautifyDocument(String raw) {
// remove the placeholder for the plain cursor like: ${0}, ${1:variable}
String escapedString = raw.replaceAll("\\$\\{\\d:?(.*?)\\}", "$1");
// Replace the reserved variable with empty string.
// See: https://github.com/eclipse/eclipse.jdt.ls/issues/1220
escapedString = escapedString.replaceAll(TM_SELECTED_TEXT, "");
if (JavaLanguageServerPlugin.getPreferencesManager() != null && JavaLanguageServerPlugin.getPreferencesManager().getClientPreferences() != null
&& JavaLanguageServerPlugin.getPreferencesManager().getClientPreferences().isSupportsCompletionDocumentationMarkdown()) {
MarkupContent markupContent = new MarkupContent();
markupContent.setKind(MarkupKind.MARKDOWN);
markupContent.setValue(String.format("```%s\n%s\n```", MARKDOWN_LANGUAGE, escapedString));
return Either.forRight(markupContent);
} else {
return Either.forLeft(escapedString);
}
}
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));
}
}
}
}
private Either<Command, CodeAction> getDiagnosticsFixes(String message, String uri, String scope, boolean syntaxOnly) {
Command command = new Command(message, REFRESH_DIAGNOSTICS_COMMAND, Arrays.asList(uri, scope, syntaxOnly));
if (preferenceManager.getClientPreferences().isSupportedCodeActionKind(CodeActionKind.QuickFix)) {
CodeAction codeAction = new CodeAction(message);
codeAction.setKind(CodeActionKind.QuickFix);
codeAction.setCommand(command);
codeAction.setDiagnostics(Collections.EMPTY_LIST);
return Either.forRight(codeAction);
} else {
return Either.forLeft(command);
}
}
@SuppressWarnings("unchecked")
protected Either<L, R> createRight(R obj) throws IOException {
if (Either3.class.isAssignableFrom(typeToken.getRawType()))
return (Either<L, R>) Either3.forRight3((Either<?, ?>) obj);
else
return Either.forRight(obj);
}
public void setDocumentation(final MarkupContent documentation) {
if (documentation == null) {
this.documentation = null;
return;
}
this.documentation = Either.forRight(documentation);
}
public void setContents(final MarkupContent contents) {
if (contents == null) {
Preconditions.checkNotNull(contents, "contents");
this.contents = null;
return;
}
this.contents = Either.forRight(contents);
}
public void setTagSupport(final DiagnosticsTagSupport tagSupport) {
if (tagSupport == null) {
this.tagSupport = null;
return;
}
this.tagSupport = Either.forRight(tagSupport);
}
public void setCode(final Number code) {
if (code == null) {
this.code = null;
return;
}
this.code = Either.forRight(code);
}
public void setTextDocumentSync(final TextDocumentSyncOptions textDocumentSync) {
if (textDocumentSync == null) {
this.textDocumentSync = null;
return;
}
this.textDocumentSync = Either.forRight(textDocumentSync);
}
public void setDocumentation(final MarkupContent documentation) {
if (documentation == null) {
this.documentation = null;
return;
}
this.documentation = Either.forRight(documentation);
}
public void setImplementationProvider(final StaticRegistrationOptions implementationProvider) {
if (implementationProvider == null) {
this.implementationProvider = null;
return;
}
this.implementationProvider = Either.forRight(implementationProvider);
}
public void setCodeActionProvider(final CodeActionOptions codeActionProvider) {
if (codeActionProvider == null) {
this.codeActionProvider = null;
return;
}
this.codeActionProvider = Either.forRight(codeActionProvider);
}
public void setRenameProvider(final RenameOptions renameProvider) {
if (renameProvider == null) {
this.renameProvider = null;
return;
}
this.renameProvider = Either.forRight(renameProvider);
}
@Test
public void testLeftEqualsNull() {
Either<Object, String> either1 = Either.forRight("Testing");
Either<Object, String> either2 = Either.forRight("Testing");
assertTrue(either1.equals(either2));
}
public void setFoldingRangeProvider(final FoldingRangeProviderOptions foldingRangeProvider) {
if (foldingRangeProvider == null) {
this.foldingRangeProvider = null;
return;
}
this.foldingRangeProvider = Either.forRight(foldingRangeProvider);
}
public void setTypeHierarchyProvider(final StaticRegistrationOptions typeHierarchyProvider) {
if (typeHierarchyProvider == null) {
this.typeHierarchyProvider = null;
return;
}
this.typeHierarchyProvider = Either.forRight(typeHierarchyProvider);
}
@Test
public void testParseEither() {
MyObjectA object = new MyObjectA();
object.myProperty = Either.forRight(7);
assertParse(object, "{\"myProperty\":7}");
}
@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;
}
}
}
public void setId(int id) {
this.id = Either.forRight(id);
}
public void setResponseId(int id) {
this.responseId = Either.forRight(id);
}