/** * Finds all Json RPC methods on a given class. * * @return the supported JsonRpcMethods */ public static Map<String, JsonRpcMethod> getSupportedMethods(Class<?> type) { Set<Class<?>> visitedTypes = new HashSet<>(); return getSupportedMethods(type, visitedTypes); }
/** * Finds all Json RPC methods on a given class. * * @return the supported JsonRpcMethods */ public static Map<String, JsonRpcMethod> getSupportedMethods(Class<?> type) { Set<Class<?>> visitedTypes = new HashSet<>(); return getSupportedMethods(type, visitedTypes); }
/** * Gather all JSON-RPC methods from the local and remote services. */ protected Map<String, JsonRpcMethod> getSupportedMethods() { Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>(); // Gather the supported methods of remote interfaces for (Class<?> interface_ : remoteInterfaces) { supportedMethods.putAll(ServiceEndpoints.getSupportedMethods(interface_)); } // Gather the supported methods of local services for (Object localService : localServices) { if (localService instanceof JsonRpcMethodProvider) { JsonRpcMethodProvider rpcMethodProvider = (JsonRpcMethodProvider) localService; supportedMethods.putAll(rpcMethodProvider.supportedMethods()); } else { supportedMethods.putAll(ServiceEndpoints.getSupportedMethods(localService.getClass())); } } return supportedMethods; }
/** * Gather all JSON-RPC methods from the local and remote services. */ protected Map<String, JsonRpcMethod> getSupportedMethods() { Map<String, JsonRpcMethod> supportedMethods = new LinkedHashMap<>(); // Gather the supported methods of remote interfaces for (Class<?> interface_ : remoteInterfaces) { supportedMethods.putAll(ServiceEndpoints.getSupportedMethods(interface_)); } // Gather the supported methods of local services for (Object localService : localServices) { if (localService instanceof JsonRpcMethodProvider) { JsonRpcMethodProvider rpcMethodProvider = (JsonRpcMethodProvider) localService; supportedMethods.putAll(rpcMethodProvider.supportedMethods()); } else { supportedMethods.putAll(ServiceEndpoints.getSupportedMethods(localService.getClass())); } } return supportedMethods; }
@Before public void setup() { final Map<String, JsonRpcMethod> methods = ServiceEndpoints.getSupportedMethods(LanguageServer.class); final Map<String, JsonRpcMethod> clientMethods = ServiceEndpoints.getSupportedMethods(LanguageClient.class); final HashMap<String, JsonRpcMethod> all = new HashMap<String, JsonRpcMethod>(); all.putAll(methods); all.putAll(clientMethods); MessageJsonHandler _messageJsonHandler = new MessageJsonHandler(all); this.jsonHandler = _messageJsonHandler; }
supportedMethods.putAll(ServiceEndpoints.getSupportedMethods(this.getClass())); final LinkedHashMap<String, JsonRpcMethod> extensions = CollectionLiterals.<String, JsonRpcMethod>newLinkedHashMap(); Iterable<IResourceServiceProvider> _filter = Iterables.<IResourceServiceProvider>filter(IterableExtensions.<Object>toSet(this.languagesRegistry.getExtensionToFactoryMap().values()), IResourceServiceProvider.class); _xifexpression = ((JsonRpcMethodProvider)ext).supportedMethods(); } else { _xifexpression = ServiceEndpoints.getSupportedMethods(ext.getClass());
Map<String, JsonRpcMethod> supportedDelegateMethods = getSupportedMethods(method.getReturnType(), visitedTypes); for (JsonRpcMethod meth : supportedDelegateMethods.values()) { if (result.put(meth.getMethodName(), meth) != null) {
Map<String, JsonRpcMethod> supportedDelegateMethods = getSupportedMethods(method.getReturnType(), visitedTypes); for (JsonRpcMethod meth : supportedDelegateMethods.values()) { if (result.put(meth.getMethodName(), meth) != null) {
@Test public void testDocumentSymbol() { Map<String, JsonRpcMethod> methods = ServiceEndpoints.getSupportedMethods(TextDocumentService.class); JsonRpcMethod jsonRpcMethod = methods.get("textDocument/documentSymbol"); Assert.assertNotNull(jsonRpcMethod); }
@Before public void setup() { final Map<String, JsonRpcMethod> methods = ServiceEndpoints.getSupportedMethods(LanguageServer.class); final Consumer<GsonBuilder> _function = (GsonBuilder it) -> { it.setPrettyPrinting(); }; MessageJsonHandler _messageJsonHandler = new MessageJsonHandler(methods, _function); this.jsonHandler = _messageJsonHandler; }
@Test public void testCodelensResolve() { Map<String, JsonRpcMethod> methods = ServiceEndpoints.getSupportedMethods(TextDocumentService.class); Assert.assertNotNull(methods.get("codeLens/resolve")); Assert.assertNotNull(methods.get("completionItem/resolve")); } }
@Test public void testRpcMethods_01() { Map<String, JsonRpcMethod> methods = ServiceEndpoints.getSupportedMethods(Foo.class); assertEquals("foo/doStuff", methods.get("foo/doStuff").getMethodName()); assertEquals(String.class, methods.get("foo/doStuff").getParameterTypes()[0]); assertFalse(methods.get("foo/doStuff").isNotification()); assertEquals("foo/myNotification", methods.get("foo/myNotification").getMethodName()); assertEquals(String.class, methods.get("foo/myNotification").getParameterTypes()[0]); assertTrue(methods.get("foo/myNotification").isNotification()); assertEquals("hubba", methods.get("hubba").getMethodName()); assertEquals(String.class, methods.get("hubba").getParameterTypes()[0]); assertTrue(methods.get("hubba").isNotification()); }
@Test public void testIssue107() { Map<String, JsonRpcMethod> methods = ServiceEndpoints.getSupportedMethods(StringConsumer.class); final JsonRpcMethod method = methods.get("consumer/accept"); assertEquals("consumer/accept", method.getMethodName()); assertEquals(1, method.getParameterTypes().length); assertEquals(String.class, method.getParameterTypes()[0]); assertTrue(method.isNotification()); }
@Test public void testNullResponse() throws InterruptedException, ExecutionException { LogMessageAccumulator logMessages = new LogMessageAccumulator(); try { logMessages.registerTo(GenericEndpoint.class); Endpoint endpoint = ServiceEndpoints.toEndpoint(this); Map<String, JsonRpcMethod> methods = ServiceEndpoints.getSupportedMethods(LanguageServer.class); MessageJsonHandler handler = new MessageJsonHandler(methods); List<Message> msgs = new ArrayList<>(); MessageConsumer consumer = (message) -> { msgs.add(message); }; RemoteEndpoint re = new RemoteEndpoint(consumer, endpoint); RequestMessage request = new RequestMessage(); request.setId("1"); request.setMethod("shutdown"); re.consume(request); Assert.assertEquals("{\"jsonrpc\":\"2.0\",\"id\":\"1\",\"result\":null}", handler.serialize(msgs.get(0))); msgs.clear(); shutdownReturn = new Object(); re.consume(request); Assert.assertEquals("{\"jsonrpc\":\"2.0\",\"id\":\"1\",\"result\":{}}", handler.serialize(msgs.get(0))); } finally { logMessages.unregister(); } }
@Test public void testRpcMethods_02() { Map<String, JsonRpcMethod> methods = ServiceEndpoints.getSupportedMethods(Bar.class); final JsonRpcMethod requestMethod = methods.get("bar/doStuff2"); assertEquals("bar/doStuff2", requestMethod.getMethodName()); assertEquals(2, requestMethod.getParameterTypes().length); assertEquals(String.class, requestMethod.getParameterTypes()[0]); assertEquals(Integer.class, requestMethod.getParameterTypes()[1]); assertFalse(requestMethod.isNotification()); final JsonRpcMethod notificationMethod = methods.get("bar/myNotification2"); assertEquals("bar/myNotification2", notificationMethod.getMethodName()); assertEquals(2, notificationMethod.getParameterTypes().length); assertEquals(String.class, notificationMethod.getParameterTypes()[0]); assertEquals(Integer.class, notificationMethod.getParameterTypes()[1]); assertTrue(notificationMethod.isNotification()); final JsonRpcMethod delegateMethod = methods.get("hubba"); assertEquals("hubba", delegateMethod.getMethodName()); assertEquals(2, delegateMethod.getParameterTypes().length); assertEquals(String.class, delegateMethod.getParameterTypes()[0]); assertEquals(Integer.class, delegateMethod.getParameterTypes()[1]); assertTrue(delegateMethod.isNotification()); }