类org.eclipse.lsp4j.jsonrpc.ResponseErrorException源码实例Demo

下面列出了怎么用org.eclipse.lsp4j.jsonrpc.ResponseErrorException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: eclipse.jdt.ls   文件: RenameHandlerTest.java
@Test(expected = ResponseErrorException.class)
public void testRenameSystemLibrary() throws JavaModelException {
	IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);

	String[] codes = {
			"package test1;\n",
			"public class E {\n",
			"   public int bar() {\n",
			"		String str = new String();\n",
			"   	str.len|*gth();\n",
			"   }\n",
			"}\n"
	};
	StringBuilder builder = new StringBuilder();
	Position pos = mergeCode(builder, codes);
	ICompilationUnit cu = pack1.createCompilationUnit("E.java", builder.toString(), false, null);

	getRenameEdit(cu, pos, "newname");
}
 
源代码2 项目: eclipse.jdt.ls   文件: PrepareRenameHandlerTest.java
@Test(expected = ResponseErrorException.class)
public void testRenameImportDeclaration() throws JavaModelException, BadLocationException {
	when(clientPreferences.isResourceOperationSupported()).thenReturn(true);

	IPackageFragment pack1 = sourceFolder.createPackageFragment("ex.amples", false, null);

	{
	//@formatter:off
	String[] content = {
		"package ex.amples;\n",
		"import java.ne|*t.URI;\n",
		"public class A {}\n"
	};
	//@formatter:on
		StringBuilder builder = new StringBuilder();
		Position pos = mergeCode(builder, content);
		ICompilationUnit cu = pack1.createCompilationUnit("A.java", builder.toString(), false, null);

		prepareRename(cu, pos, "");
	}
}
 
源代码3 项目: lsp4intellij   文件: LanguageServerWrapper.java
public void logMessage(Message message) {
    if (message instanceof ResponseMessage) {
        ResponseMessage responseMessage = (ResponseMessage) message;
        if (responseMessage.getError() != null && (responseMessage.getId()
                .equals(Integer.toString(ResponseErrorCode.RequestCancelled.getValue())))) {
            LOG.error(new ResponseErrorException(responseMessage.getError()));
        }
    }
}
 
源代码4 项目: intellij-quarkus   文件: LanguageServerWrapper.java
private void logMessage(Message message) {
    if (message instanceof ResponseMessage && ((ResponseMessage) message).getError() != null
            && ((ResponseMessage) message).getId()
            .equals(Integer.toString(ResponseErrorCode.RequestCancelled.getValue()))) {
        ResponseMessage responseMessage = (ResponseMessage) message;
        LOGGER.warn("", new ResponseErrorException(responseMessage.getError()));
    } else if (LOGGER.isDebugEnabled()) {
        LOGGER.info(message.getClass().getSimpleName() + '\n' + message.toString());
    }
}
 
源代码5 项目: n4js   文件: XWorkspaceManager.java
/**
 * @return the workspace configuration
 * @throws ResponseErrorException
 *             if the workspace is not yet initialized
 */
public IWorkspaceConfig getWorkspaceConfig() throws ResponseErrorException {
	if (workspaceConfig == null) {
		ResponseError error = new ResponseError(ResponseErrorCode.serverNotInitialized,
				"Workspace has not been initialized yet.", null);
		throw new ResponseErrorException(error);
	}
	return workspaceConfig;
}
 
源代码6 项目: eclipse.jdt.ls   文件: PrepareRenameHandler.java
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));
	}
 
@Test
public void testExecuteCommandNonexistingCommand() {
	expectedEx.expect(ResponseErrorException.class);
	expectedEx.expectMessage("No delegateCommandHandler for testcommand.not.existing");

	WorkspaceExecuteCommandHandler handler = WorkspaceExecuteCommandHandler.getInstance();
	ExecuteCommandParams params = new ExecuteCommandParams();
	params.setCommand("testcommand.not.existing");
	params.setArguments(Arrays.asList("hello", "world"));
	Object result = handler.executeCommand(params, monitor);
}
 
@Test
public void testExecuteCommandThrowsExceptionCommand() {
	expectedEx.expect(ResponseErrorException.class);
	expectedEx.expectMessage("Unsupported");

	WorkspaceExecuteCommandHandler handler = WorkspaceExecuteCommandHandler.getInstance();
	ExecuteCommandParams params = new ExecuteCommandParams();
	params.setCommand("testcommand.throwexception");
	handler.executeCommand(params, monitor);
}
 
@Test
public void testExecuteCommandInvalidParameters() {
	expectedEx.expect(ResponseErrorException.class);
	expectedEx.expectMessage("The workspace/executeCommand has empty params or command");

	WorkspaceExecuteCommandHandler handler = WorkspaceExecuteCommandHandler.getInstance();
	ExecuteCommandParams params = null;
	handler.executeCommand(params, monitor);
}
 
源代码10 项目: eclipse.jdt.ls   文件: RenameHandlerTest.java
@Test(expected = ResponseErrorException.class)
public void testRenameTypeWithErrors() throws JavaModelException, BadLocationException {
	when(clientPreferences.isResourceOperationSupported()).thenReturn(true);

	IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);

	String[] codes = { "package test1;\n",
			           "public class Newname {\n",
			           "   }\n",
			           "}\n" };
	StringBuilder builder = new StringBuilder();
	mergeCode(builder, codes);
	ICompilationUnit cu = pack1.createCompilationUnit("Newname.java", builder.toString(), false, null);


	String[] codes1 = { "package test1;\n",
			           "public class E|* {\n",
			           "   public E() {\n",
			           "   }\n",
			           "   public int bar() {\n", "   }\n",
			           "   public int foo() {\n",
			           "		this.bar();\n",
			           "   }\n",
			           "}\n" };
	builder = new StringBuilder();
	Position pos = mergeCode(builder, codes1);
	cu = pack1.createCompilationUnit("E.java", builder.toString(), false, null);

	WorkspaceEdit edit = getRenameEdit(cu, pos, "Newname");
	assertNotNull(edit);
	List<Either<TextDocumentEdit, ResourceOperation>> resourceChanges = edit.getDocumentChanges();

	assertEquals(resourceChanges.size(), 3);
}
 
源代码11 项目: eclipse.jdt.ls   文件: PrepareRenameHandlerTest.java
@Test(expected = ResponseErrorException.class)
public void testRenamePackage() throws JavaModelException, BadLocationException {
	when(clientPreferences.isResourceOperationSupported()).thenReturn(true);

	IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
	IPackageFragment pack2 = sourceFolder.createPackageFragment("parent.test2", false, null);

	String[] codes1= {
			"package test1;\n",
			"import parent.test2.B;\n",
			"public class A {\n",
			"   public void foo(){\n",
			"		B b = new B();\n",
			"		b.foo();\n",
			"	}\n",
			"}\n"
	};

	String[] codes2 = {
			"package parent.test2|*;\n",
			"public class B {\n",
			"	public B() {}\n",
			"   public void foo() {}\n",
			"}\n"
	};
	StringBuilder builderA = new StringBuilder();
	mergeCode(builderA, codes1);
	pack1.createCompilationUnit("A.java", builderA.toString(), false, null);

	StringBuilder builderB = new StringBuilder();
	Position pos = mergeCode(builderB, codes2);
	ICompilationUnit cuB = pack2.createCompilationUnit("B.java", builderB.toString(), false, null);

	prepareRename(cuB, pos, "parent.newpackage");
}
 
源代码12 项目: eclipse.jdt.ls   文件: PrepareRenameHandlerTest.java
@Test(expected = ResponseErrorException.class)
public void testRenameMiddleOfPackage() throws JavaModelException, BadLocationException {
	when(clientPreferences.isResourceOperationSupported()).thenReturn(true);

	IPackageFragment pack1 = sourceFolder.createPackageFragment("ex.amples", false, null);

	//@formatter:off
	String[] content = {
		"package |*ex.amples;\n",
		"public class A {}\n"
	};
	//@formatter:on
	StringBuilder builder = new StringBuilder();
	Position pos = mergeCode(builder, content);
	ICompilationUnit cu = pack1.createCompilationUnit("A.java", builder.toString(), false, null);

	prepareRename(cu, pos, "ex.am.ple");

	//@formatter:off
	String[] content2 = {
		"package ex.|*amples;\n",
		"public class A {}\n"
	};
	//@formatter:on
	builder = new StringBuilder();
	pos = mergeCode(builder, content2);
	cu = pack1.createCompilationUnit("A.java", builder.toString(), false, null);

	prepareRename(cu, pos, "ex.am.ple");
}
 
源代码13 项目: xtext-core   文件: RenamePositionTest.java
protected void renameAndFail(final String model, final Position position, final String messageFragment) {
  final String modelFile = this.writeFile("MyType.testlang", model);
  this.initialize();
  try {
    final TextDocumentIdentifier identifier = new TextDocumentIdentifier(modelFile);
    PrepareRenameParams _prepareRenameParams = new PrepareRenameParams(identifier, position);
    final Either<Range, PrepareRenameResult> prepareRenameResult = this.languageServer.prepareRename(_prepareRenameParams).get();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("expected null result got ");
    _builder.append(prepareRenameResult);
    _builder.append(" instead");
    Assert.assertNull(_builder.toString(), prepareRenameResult);
    TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(modelFile);
    final RenameParams renameParams = new RenameParams(_textDocumentIdentifier, position, "Tescht");
    this.languageServer.rename(renameParams).get();
    Assert.fail("Rename should have failed");
  } catch (final Throwable _t) {
    if (_t instanceof Exception) {
      final Exception exc = (Exception)_t;
      final Throwable rootCause = Throwables.getRootCause(exc);
      Assert.assertTrue((rootCause instanceof ResponseErrorException));
      final ResponseError error = ((ResponseErrorException) rootCause).getResponseError();
      Assert.assertTrue(error.getData().toString().contains(messageFragment));
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
}
 
源代码14 项目: xtext-core   文件: WorkspaceManager.java
/**
 * @return the workspace configuration
 * @throws ResponseErrorException
 *             if the workspace is not yet initialized
 */
protected IWorkspaceConfig getWorkspaceConfig() throws ResponseErrorException {
	if (workspaceConfig == null) {
		ResponseError error = new ResponseError(ResponseErrorCode.serverNotInitialized,
				"Workspace has not been initialized yet.", null);
		throw new ResponseErrorException(error);
	}
	return workspaceConfig;
}
 
源代码15 项目: lsp4j   文件: GenericEndpoint.java
@Override
public CompletableFuture<?> request(String method, Object parameter) {
	// Check the registered method handlers
	Function<Object, CompletableFuture<Object>> handler = methodHandlers.get(method);
	if (handler != null) {
		return handler.apply(parameter);
	}
	
	// Ask the delegate objects whether they can handle the request generically
	List<CompletableFuture<?>> futures = new ArrayList<>(delegates.size());
	for (Object delegate : delegates) {
		if (delegate instanceof Endpoint) {
			futures.add(((Endpoint) delegate).request(method, parameter));
		}
	}
	if (!futures.isEmpty()) {
		return CompletableFuture.anyOf(futures.toArray(new CompletableFuture[futures.size()]));
	}
	
	// Create a log message about the unsupported method
	String message = "Unsupported request method: " + method;
	if (isOptionalMethod(method)) {
		LOG.log(Level.INFO, message);
		return CompletableFuture.completedFuture(null);
	}
	LOG.log(Level.WARNING, message);
	CompletableFuture<?> exceptionalResult = new CompletableFuture<Object>();
	ResponseError error = new ResponseError(ResponseErrorCode.MethodNotFound, message, null);
	exceptionalResult.completeExceptionally(new ResponseErrorException(error));
	return exceptionalResult;
}
 
源代码16 项目: eclipse.jdt.ls   文件: PrepareRenameHandlerTest.java
@Test(expected = ResponseErrorException.class)
public void testRenameClassFile() throws JavaModelException, BadLocationException {
	testRenameClassFile("Ex|*ception");
}
 
源代码17 项目: eclipse.jdt.ls   文件: PrepareRenameHandlerTest.java
@Test(expected = ResponseErrorException.class)
public void testRenameFQCNClassFile() throws JavaModelException, BadLocationException {
	testRenameClassFile("java.lang.Ex|*ception");
}
 
源代码18 项目: eclipse.jdt.ls   文件: PrepareRenameHandlerTest.java
@Test(expected = ResponseErrorException.class)
public void testRenameBinaryPackage() throws JavaModelException, BadLocationException {
	testRenameClassFile("java.net|*.URI");
}
 
源代码19 项目: xtext-core   文件: PrepareRenameTest.java
@Test
public void testRenameFqn_invalid_error() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("package foo.bar {");
  _builder.newLine();
  _builder.append("  ");
  _builder.append("type A {");
  _builder.newLine();
  _builder.append("    ");
  _builder.append("foo.bar.MyType bar");
  _builder.newLine();
  _builder.append("  ");
  _builder.append("}");
  _builder.newLine();
  _builder.append("  ");
  _builder.append("type MyType { }");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final String uri = this.writeFile("my-type-invalid.testlang", _builder);
  this.initialize();
  TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(uri);
  Position _position = new Position(2, 5);
  final RenameParams params = new RenameParams(_textDocumentIdentifier, _position, "Does not matter");
  try {
    final WorkspaceEdit workspaceEdit = this.languageServer.rename(params).get();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("Expected an expcetion when trying to rename document but got a valid workspace edit instead: ");
    _builder_1.append(workspaceEdit);
    Assert.fail(_builder_1.toString());
  } catch (final Throwable _t) {
    if (_t instanceof Exception) {
      final Exception e = (Exception)_t;
      final Throwable rootCause = Throwables.getRootCause(e);
      Assert.assertTrue((rootCause instanceof ResponseErrorException));
      final ResponseError error = ((ResponseErrorException) rootCause).getResponseError();
      Assert.assertTrue(error.getData().toString().contains("No element found at position"));
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
}
 
public void checkSeverity() {
	if (getMaximumSeverity().compareTo(Severity.WARNING) < 0) {
		throw new ResponseErrorException(toResponseError());
	}
}
 
 类所在包
 同包方法