当前位置: 首页>>代码示例>>Java>>正文


Java CompletableFutures类代码示例

本文整理汇总了Java中org.eclipse.lsp4j.jsonrpc.CompletableFutures的典型用法代码示例。如果您正苦于以下问题:Java CompletableFutures类的具体用法?Java CompletableFutures怎么用?Java CompletableFutures使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CompletableFutures类属于org.eclipse.lsp4j.jsonrpc包,在下文中一共展示了CompletableFutures类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDocumentResolve

import org.eclipse.lsp4j.jsonrpc.CompletableFutures; //导入依赖的package包/类
@Test public void testDocumentResolve() throws Exception, ExecutionException {
	LanguageServer languageServer = wrap(LanguageServer.class, new MockLanguageServer() {
		@Override
		public CompletableFuture<DocumentLink> documentLinkResolve(DocumentLink params) {
			return CompletableFutures.computeAsync(canceler -> {
				params.setTarget("resolved");
				return params;
			});
		}
	});
	
	CompletableFuture<DocumentLink> future = languageServer.getTextDocumentService().documentLinkResolve(
			new DocumentLink(new Range(new Position(0, 0), new Position(0, 0)), "unresolved")
	);
	DocumentLink resolved = future.get(TIMEOUT, TimeUnit.MILLISECONDS);
	
	Assert.assertEquals("resolved", resolved.getTarget());
}
 
开发者ID:eclipse,项目名称:lsp4j,代码行数:19,代码来源:ProtocolTest.java

示例2: resolveCompletionItem

import org.eclipse.lsp4j.jsonrpc.CompletableFutures; //导入依赖的package包/类
@Override
public CompletableFuture<CompletionItem> resolveCompletionItem(CompletionItem unresolved) {
    return CompletableFutures.computeAsync(
            cancel -> {
                server.configured().docs.resolveCompletionItem(unresolved);

                return unresolved;
            });
}
 
开发者ID:georgewfraser,项目名称:vscode-javac,代码行数:10,代码来源:JavaTextDocumentService.java

示例3: testDocumentLink_01

import org.eclipse.lsp4j.jsonrpc.CompletableFutures; //导入依赖的package包/类
@Test public void testDocumentLink_01() throws Exception, ExecutionException {
	LanguageServer languageServer = wrap(LanguageServer.class, new MockLanguageServer() {
		@Override
		public CompletableFuture<List<DocumentLink>> documentLink(DocumentLinkParams params) {
			return CompletableFutures.computeAsync(canceler -> {
				return new ArrayList<>();
			});
		}
	});
	
	CompletableFuture<List<DocumentLink>> future = languageServer.getTextDocumentService().documentLink(new DocumentLinkParams(new TextDocumentIdentifier("test")));
	List<DocumentLink> list = future.get(TIMEOUT, TimeUnit.MILLISECONDS);
	
	Assert.assertTrue(list.isEmpty());
}
 
开发者ID:eclipse,项目名称:lsp4j,代码行数:16,代码来源:ProtocolTest.java

示例4: testDocumentLink_02

import org.eclipse.lsp4j.jsonrpc.CompletableFutures; //导入依赖的package包/类
@Test public void testDocumentLink_02() throws Exception, ExecutionException {
	LanguageServer languageServer = wrap(LanguageServer.class, new MockLanguageServer() {
		@Override
		public CompletableFuture<List<DocumentLink>> documentLink(DocumentLinkParams params) {
			return CompletableFutures.computeAsync(canceler -> {
				return null;
			});
		}
	});
	
	CompletableFuture<List<DocumentLink>> future = languageServer.getTextDocumentService().documentLink(new DocumentLinkParams(new TextDocumentIdentifier("test")));
	List<DocumentLink> list = future.get(TIMEOUT, TimeUnit.MILLISECONDS);
	
	Assert.assertNull(list);
}
 
开发者ID:eclipse,项目名称:lsp4j,代码行数:16,代码来源:ProtocolTest.java

示例5: testCancellationResponse

import org.eclipse.lsp4j.jsonrpc.CompletableFutures; //导入依赖的package包/类
@Test
public void testCancellationResponse() throws Exception {
	// create client messages
	String requestMessage = "{\"type\":\"request\","
			+ "\"seq\":1,\n"
			+ "\"command\":\"askServer\",\n"
			+ "\"arguments\": { value: \"bar\" }\n"
			+ "}";
	String cancellationMessage = "{\"type\":\"event\","
			+ "\"command\":\"$/cancelRequest\",\n"
			+ "\"body\": { id: 1 }\n"
			+ "}";
	String clientMessages = getHeader(requestMessage.getBytes().length) + requestMessage
			+ getHeader(cancellationMessage.getBytes().length) + cancellationMessage;

	// create server side
	ByteArrayInputStream in = new ByteArrayInputStream(clientMessages.getBytes());
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	MyServer server = new MyServer() {
		@Override
		public CompletableFuture<MyParam> askServer(MyParam param) {
			return CompletableFutures.computeAsync(cancelToken -> {
				try {
					long startTime = System.currentTimeMillis();
					do {
						cancelToken.checkCanceled();
						Thread.sleep(50);
					} while (System.currentTimeMillis() - startTime < TIMEOUT);
				} catch (InterruptedException e) {
					Assert.fail("Thread was interrupted unexpectedly.");
				}
				return param;
			});
		}
	};
	DebugLauncher<MyClient> serverSideLauncher = DebugLauncher.createLauncher(server, MyClient.class, in, out);
	serverSideLauncher.startListening().get(TIMEOUT, TimeUnit.MILLISECONDS);

	Assert.assertEquals("Content-Length: 133\r\n\r\n" +
			"{\"type\":\"response\",\"request_seq\":1,\"success\":false,\"message\":\"The request (id: 1, method: \\u0027askServer\\u0027) has been cancelled\"}",
			out.toString());
}
 
开发者ID:tracymiranda,项目名称:dsp4e,代码行数:43,代码来源:DebugIntegrationTest.java

示例6: testCancellationResponse

import org.eclipse.lsp4j.jsonrpc.CompletableFutures; //导入依赖的package包/类
@Test
public void testCancellationResponse() throws Exception {
	// create client messages
	String requestMessage = "{\"type\":\"request\","
			+ "\"seq\":1,\n"
			+ "\"command\":\"askServer\",\n"
			+ "\"arguments\": { value: \"bar\" }\n"
			+ "}";
	String cancellationMessage = "{\"type\":\"event\","
			+ "\"command\":\"$/cancelRequest\",\n"
			+ "\"body\": { id: 1 }\n"
			+ "}";
	String clientMessages = getHeader(requestMessage.getBytes().length) + requestMessage
			+ getHeader(cancellationMessage.getBytes().length) + cancellationMessage;

	// create server side
	ByteArrayInputStream in = new ByteArrayInputStream(clientMessages.getBytes());
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	MyServer server = new MyServer() {
		@Override
		public CompletableFuture<MyParam> askServer(MyParam param) {
			return CompletableFutures.computeAsync(cancelToken -> {
				try {
					long startTime = System.currentTimeMillis();
					do {
						cancelToken.checkCanceled();
						Thread.sleep(50);
					} while (System.currentTimeMillis() - startTime < TIMEOUT);
				} catch (InterruptedException e) {
					Assert.fail("Thread was interrupted unexpectedly.");
				}
				return param;
			});
		}
	};
	DebugLauncher<MyClient> serverSideLauncher = DebugLauncher.createLauncher(server, MyClient.class, in, out);
	serverSideLauncher.startListening().get(TIMEOUT, TimeUnit.MILLISECONDS);

	Assert.assertEquals("Content-Length: 163\r\n\r\n" +
			"{\"type\":\"response\",\"seq\":1,\"request_seq\":1,\"command\":\"askServer\",\"success\":false,\"message\":\"The request (id: 1, method: \\u0027askServer\\u0027) has been cancelled\"}",
			out.toString());
}
 
开发者ID:eclipse,项目名称:lsp4j,代码行数:43,代码来源:DebugIntegrationTest.java

示例7: testCancellationResponse

import org.eclipse.lsp4j.jsonrpc.CompletableFutures; //导入依赖的package包/类
@Test
public void testCancellationResponse() throws Exception {
	// create client messages
	String requestMessage = "{\"jsonrpc\":\"2.0\","
			+ "\"id\":\"1\",\n" 
			+ "\"method\":\"askServer\",\n" 
			+ "\"params\": { value: \"bar\" }\n"
			+ "}";
	String cancellationMessage = "{\"jsonrpc\":\"2.0\","
			+ "\"method\":\"$/cancelRequest\",\n" 
			+ "\"params\": { id: 1 }\n"
			+ "}";
	String clientMessages = getHeader(requestMessage.getBytes().length) + requestMessage
			+ getHeader(cancellationMessage.getBytes().length) + cancellationMessage;
	
	// create server side
	ByteArrayInputStream in = new ByteArrayInputStream(clientMessages.getBytes());
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	MyServer server = new MyServer() {
		@Override
		public CompletableFuture<MyParam> askServer(MyParam param) {
			return CompletableFutures.computeAsync(cancelToken -> {
				try {
					long startTime = System.currentTimeMillis();
					do {
						cancelToken.checkCanceled();
						Thread.sleep(50);
					} while (System.currentTimeMillis() - startTime < TIMEOUT);
				} catch (InterruptedException e) {
					Assert.fail("Thread was interrupted unexpectedly.");
				}
				return param;
			});
		}
	};
	Launcher<MyClient> serverSideLauncher = Launcher.createLauncher(server, MyClient.class, in, out);
	serverSideLauncher.startListening().get(TIMEOUT, TimeUnit.MILLISECONDS);
	
	Assert.assertEquals("Content-Length: 132" + CRLF + CRLF
			+ "{\"jsonrpc\":\"2.0\",\"id\":\"1\",\"error\":{\"code\":-32800,\"message\":\"The request (id: 1, method: \\u0027askServer\\u0027) has been cancelled\"}}",
			out.toString());
}
 
开发者ID:eclipse,项目名称:lsp4j,代码行数:43,代码来源:IntegrationTest.java


注:本文中的org.eclipse.lsp4j.jsonrpc.CompletableFutures类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。