org.eclipse.lsp4j.jsonrpc.messages.Either#forRight ( )源码实例Demo

下面列出了org.eclipse.lsp4j.jsonrpc.messages.Either#forRight ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: eclipse.jdt.ls   文件: SnippetUtils.java
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);
	}
}
 
源代码2 项目: lsp4j   文件: HoverTypeAdapter.java
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));
      }
    }
  }
}
 
源代码3 项目: eclipse.jdt.ls   文件: NonProjectFixProcessor.java
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);
	}
}
 
源代码4 项目: lsp4j   文件: EitherTypeAdapter.java
@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);
}
 
源代码5 项目: lsp4j   文件: SignatureInformation.java
public void setDocumentation(final MarkupContent documentation) {
  if (documentation == null) {
    this.documentation = null;
    return;
  }
  this.documentation = Either.forRight(documentation);
}
 
源代码6 项目: lsp4j   文件: Hover.java
public void setContents(final MarkupContent contents) {
  if (contents == null) {
    Preconditions.checkNotNull(contents, "contents");
    this.contents = null;
    return;
  }
  this.contents = Either.forRight(contents);
}
 
源代码7 项目: lsp4j   文件: PublishDiagnosticsCapabilities.java
public void setTagSupport(final DiagnosticsTagSupport tagSupport) {
  if (tagSupport == null) {
    this.tagSupport = null;
    return;
  }
  this.tagSupport = Either.forRight(tagSupport);
}
 
源代码8 项目: lsp4j   文件: Diagnostic.java
public void setCode(final Number code) {
  if (code == null) {
    this.code = null;
    return;
  }
  this.code = Either.forRight(code);
}
 
源代码9 项目: lsp4j   文件: ServerCapabilities.java
public void setTextDocumentSync(final TextDocumentSyncOptions textDocumentSync) {
  if (textDocumentSync == null) {
    this.textDocumentSync = null;
    return;
  }
  this.textDocumentSync = Either.forRight(textDocumentSync);
}
 
源代码10 项目: lsp4j   文件: ParameterInformation.java
public void setDocumentation(final MarkupContent documentation) {
  if (documentation == null) {
    this.documentation = null;
    return;
  }
  this.documentation = Either.forRight(documentation);
}
 
源代码11 项目: lsp4j   文件: ServerCapabilities.java
public void setImplementationProvider(final StaticRegistrationOptions implementationProvider) {
  if (implementationProvider == null) {
    this.implementationProvider = null;
    return;
  }
  this.implementationProvider = Either.forRight(implementationProvider);
}
 
源代码12 项目: lsp4j   文件: ServerCapabilities.java
public void setCodeActionProvider(final CodeActionOptions codeActionProvider) {
  if (codeActionProvider == null) {
    this.codeActionProvider = null;
    return;
  }
  this.codeActionProvider = Either.forRight(codeActionProvider);
}
 
源代码13 项目: lsp4j   文件: ServerCapabilities.java
public void setRenameProvider(final RenameOptions renameProvider) {
  if (renameProvider == null) {
    this.renameProvider = null;
    return;
  }
  this.renameProvider = Either.forRight(renameProvider);
}
 
源代码14 项目: lsp4j   文件: EitherTest.java
@Test
public void testLeftEqualsNull() {
	Either<Object, String> either1 = Either.forRight("Testing");
	Either<Object, String> either2 = Either.forRight("Testing");

	assertTrue(either1.equals(either2));
}
 
源代码15 项目: lsp4j   文件: ServerCapabilities.java
public void setFoldingRangeProvider(final FoldingRangeProviderOptions foldingRangeProvider) {
  if (foldingRangeProvider == null) {
    this.foldingRangeProvider = null;
    return;
  }
  this.foldingRangeProvider = Either.forRight(foldingRangeProvider);
}
 
源代码16 项目: lsp4j   文件: ServerCapabilities.java
public void setTypeHierarchyProvider(final StaticRegistrationOptions typeHierarchyProvider) {
  if (typeHierarchyProvider == null) {
    this.typeHierarchyProvider = null;
    return;
  }
  this.typeHierarchyProvider = Either.forRight(typeHierarchyProvider);
}
 
源代码17 项目: lsp4j   文件: EitherTest.java
@Test
public void testParseEither() {
	MyObjectA object = new MyObjectA();
	object.myProperty = Either.forRight(7);
	assertParse(object, "{\"myProperty\":7}");
}
 
源代码18 项目: lsp4j   文件: MessageTypeAdapter.java
@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;
		}
	}
}
 
源代码19 项目: lsp4j   文件: DebugNotificationMessage.java
public void setId(int id) {
	this.id = Either.forRight(id);
}
 
源代码20 项目: lsp4j   文件: DebugResponseMessage.java
public void setResponseId(int id) {
	this.responseId = Either.forRight(id);
}