Java 类org.eclipse.lsp4j.jsonrpc.Endpoint 实例源码

项目:SOMns-vscode    文件:GenericEndpoint.java   
@Override
public CompletableFuture<?> request(String method, Object parameter) {
    Function<Object, CompletableFuture<Object>> handler = methodHandlers.get(method);
    if (handler != null) {
        return handler.apply(parameter);
    }
    if (delegate instanceof Endpoint) {
        return ((Endpoint) delegate).request(method, parameter);
    }
    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;
}
项目:SOMns-vscode    文件:GenericEndpoint.java   
@Override
public void notify(String method, Object parameter) {
    Function<Object, CompletableFuture<Object>> handler = methodHandlers.get(method);
    if (handler != null) {
        handler.apply(parameter);
        return;
    }
    if (delegate instanceof Endpoint) {
        ((Endpoint) delegate).notify(method, parameter);
        return;
    }
    String message = "Unsupported notification method: " + method;
    if (isOptionalMethod(method)) {
        LOG.log(Level.INFO, message);
    } else {
        LOG.log(Level.WARNING, message);
    }
}
项目:xtext-core    文件:LanguageServerImpl.java   
@Override
public void notify(final String method, final Object parameter) {
  Collection<Endpoint> _get = this.extensionProviders.get(method);
  for (final Endpoint endpoint : _get) {
    try {
      endpoint.notify(method, parameter);
    } catch (final Throwable _t) {
      if (_t instanceof UnsupportedOperationException) {
        final UnsupportedOperationException e = (UnsupportedOperationException)_t;
        if ((e != ILanguageServerExtension.NOT_HANDLED_EXCEPTION)) {
          throw e;
        }
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
  }
}
项目:xtext-core    文件:LanguageServerImpl.java   
@Override
public CompletableFuture<?> request(final String method, final Object parameter) {
  boolean _containsKey = this.extensionProviders.containsKey(method);
  boolean _not = (!_containsKey);
  if (_not) {
    throw new UnsupportedOperationException((("The json request \'" + method) + "\' is unknown."));
  }
  Collection<Endpoint> _get = this.extensionProviders.get(method);
  for (final Endpoint endpoint : _get) {
    try {
      return endpoint.request(method, parameter);
    } catch (final Throwable _t) {
      if (_t instanceof UnsupportedOperationException) {
        final UnsupportedOperationException e = (UnsupportedOperationException)_t;
        if ((e != ILanguageServerExtension.NOT_HANDLED_EXCEPTION)) {
          throw e;
        }
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
  }
  return null;
}
项目:lsp4j    文件:NullResponseTest.java   
@Test public void testNullResponse() throws InterruptedException, ExecutionException {
    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)));
}
项目:lsp4j    文件:GenericEndpoint.java   
@Override
public CompletableFuture<?> request(String method, Object parameter) {
    Function<Object, CompletableFuture<Object>> handler = methodHandlers.get(method);
    if (handler != null) {
        return handler.apply(parameter);
    }
    if (delegate instanceof Endpoint) {
        return ((Endpoint) delegate).request(method, parameter);
    }
    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;
}
项目:lsp4j    文件:GenericEndpoint.java   
@Override
public void notify(String method, Object parameter) {
    Function<Object, CompletableFuture<Object>> handler = methodHandlers.get(method);
    if (handler != null) {
        handler.apply(parameter);
        return;
    }
    if (delegate instanceof Endpoint) {
        ((Endpoint) delegate).notify(method, parameter);
        return;
    }
    String message = "Unsupported notification method: " + method;
    if (isOptionalMethod(method)) {
        LOG.log(Level.INFO, message);
    } else {
        LOG.log(Level.WARNING, message);
    }
}
项目:che    文件:YamlLanguageServerLauncher.java   
@Override
public void onServerInitialized(
    LanguageServerLauncher launcher,
    LanguageServer server,
    ServerCapabilities capabilities,
    String projectPath) {

  try {
    Map<String, String> preferences =
        requestFactory.fromUrl(apiUrl + "/preferences").useGetMethod().request().asProperties();

    Endpoint endpoint = ServiceEndpoints.toEndpoint(server);
    YamlSchemaAssociations serviceObject =
        ServiceEndpoints.toServiceObject(endpoint, YamlSchemaAssociations.class);
    Map<String, String[]> associations =
        jsonToSchemaAssociations(preferences.get("yaml.preferences"));
    serviceObject.yamlSchemaAssociation(associations);

  } catch (ApiException | IOException e) {
    LOG.error(e.getLocalizedMessage(), e);
  }
}
项目:che    文件:YamlService.java   
/**
 * Route for getting getting schemas from client side and injecting them into yaml language server
 *
 * @param yamlDto A yamlDTO containing the list of schemas you would like to add
 */
@POST
@Path("schemas")
@Consumes(MediaType.APPLICATION_JSON)
public void putSchemas(YamlDTO yamlDto) throws ApiException {

  LanguageServer yamlLS = YamlLanguageServerLauncher.getYamlLanguageServer();

  if (yamlDto != null && yamlLS != null) {

    Endpoint endpoint = ServiceEndpoints.toEndpoint(yamlLS);
    YamlSchemaAssociations serviceObject =
        ServiceEndpoints.toServiceObject(endpoint, YamlSchemaAssociations.class);

    Map<String, String[]> schemaAssociations = new HashMap<>();
    Map<String, String> yamlDtoSchemas = yamlDto.getSchemas();

    for (Map.Entry<String, String> schema : yamlDtoSchemas.entrySet()) {
      schemaAssociations.put(
          schema.getKey(), new Gson().fromJson(schema.getValue(), String[].class));
    }

    serviceObject.yamlSchemaAssociation(schemaAssociations);
  }
}
项目:che    文件:JsonLanguageServerLauncher.java   
@Override
public void onServerInitialized(
    LanguageServerLauncher launcher,
    LanguageServer server,
    ServerCapabilities capabilities,
    String projectPath) {
  Endpoint endpoint = ServiceEndpoints.toEndpoint(server);
  JsonExtension serviceObject = ServiceEndpoints.toServiceObject(endpoint, JsonExtension.class);
  Map<String, String[]> associations = new HashMap<>();
  associations.put("/*.schema.json", new String[] {"http://json-schema.org/draft-04/schema#"});
  associations.put("/bower.json", new String[] {"http://json.schemastore.org/bower"});
  associations.put("/.bower.json", new String[] {"http://json.schemastore.org/bower"});
  associations.put("/.bowerrc", new String[] {"http://json.schemastore.org/bowerrc"});
  associations.put("/composer.json", new String[] {"https://getcomposer.org/schema.json"});
  associations.put("/package.json", new String[] {"http://json.schemastore.org/package"});
  associations.put("/jsconfig.json", new String[] {"http://json.schemastore.org/jsconfig"});
  associations.put("/tsconfig.json", new String[] {"http://json.schemastore.org/tsconfig"});
  serviceObject.jsonSchemaAssociation(associations);
}
项目:SOMns-vscode    文件:EndpointProxy.java   
public EndpointProxy(Endpoint delegate, Class<?> interf) {
    if (delegate == null)
        throw new NullPointerException("delegate");
    if (interf == null)
        throw new NullPointerException("interf");
    this.delegate = delegate;
    try {
        object_equals = Object.class.getDeclaredMethod("equals", Object.class);
        object_hashCode = Object.class.getDeclaredMethod("hashCode");
        object_toString = Object.class.getDeclaredMethod("toString");
    } catch (NoSuchMethodException | SecurityException exception) {
        throw new RuntimeException(exception);
    }
    methodInfos = new LinkedHashMap<>();
    AnnotationUtil.findRpcMethods(interf, new HashSet<Class<?>>(), (methodInfo) -> {
        if (methodInfos.put(methodInfo.method.getName(), methodInfo) != null) {
            throw new IllegalStateException("Method overload not allowed : " + methodInfo.method);
        }
    });
    delegatedSegments = new LinkedHashMap<>();
    AnnotationUtil.findDelegateSegments(interf, new HashSet<Class<?>>(), (method) -> {
        Object delegateProxy = ServiceEndpoints.toServiceObject(delegate, method.getReturnType());
        DelegateInfo info = new DelegateInfo();
        info.delegate = delegateProxy;
        info.method = method;
        if (delegatedSegments.put(method.getName(), info) != null) {
            throw new IllegalStateException("Method overload not allowed : " + method);
        }
    });
}
项目:xtext-core    文件:TestLangLSPExtension.java   
@Override
public void initialize(final ILanguageServerAccess access) {
  this.access = access;
  this.access.addBuildListener(this);
  LanguageClient _languageClient = access.getLanguageClient();
  this.client = ServiceEndpoints.<TestLangLSPExtension.CustomClient>toServiceObject(((Endpoint) _languageClient), TestLangLSPExtension.CustomClient.class);
}
项目:lsp4j    文件:EndpointProxy.java   
public EndpointProxy(Endpoint delegate, Class<?> interf) {
    if (delegate == null)
        throw new NullPointerException("delegate");
    if (interf == null)
        throw new NullPointerException("interf");
    this.delegate = delegate;
    try {
        object_equals = Object.class.getDeclaredMethod("equals", Object.class);
        object_hashCode = Object.class.getDeclaredMethod("hashCode");
        object_toString = Object.class.getDeclaredMethod("toString");
    } catch (NoSuchMethodException | SecurityException exception) {
        throw new RuntimeException(exception);
    }
    methodInfos = new LinkedHashMap<>();
    AnnotationUtil.findRpcMethods(interf, new HashSet<Class<?>>(), (methodInfo) -> {
        if (methodInfos.put(methodInfo.method.getName(), methodInfo) != null) {
            throw new IllegalStateException("Method overload not allowed : " + methodInfo.method);
        }
    });
    delegatedSegments = new LinkedHashMap<>();
    AnnotationUtil.findDelegateSegments(interf, new HashSet<Class<?>>(), (method) -> {
        Object delegateProxy = ServiceEndpoints.toServiceObject(delegate, method.getReturnType());
        DelegateInfo info = new DelegateInfo();
        info.delegate = delegateProxy;
        info.method = method;
        if (delegatedSegments.put(method.getName(), info) != null) {
            throw new IllegalStateException("Method overload not allowed : " + method);
        }
    });
}
项目:lsp4j    文件:DebugRemoteEndpoint.java   
public DebugRemoteEndpoint(MessageConsumer out, Endpoint localEndpoint) {
    super(out, localEndpoint);
}
项目:lsp4j    文件:DebugRemoteEndpoint.java   
public DebugRemoteEndpoint(MessageConsumer out, Endpoint localEndpoint,
        Function<Throwable, ResponseError> exceptionHandler) {
    super(out, localEndpoint, exceptionHandler);
}
项目:SOMns-vscode    文件:ServiceEndpoints.java   
/**
 * Wraps a given {@link Endpoint} in the given service interface.
 * @param endpoint
 * @param interface_
 * @return
 */
@SuppressWarnings("unchecked")
public static <T> T toServiceObject(Endpoint endpoint, Class<T> interface_) {
    Object newProxyInstance = Proxy.newProxyInstance(interface_.getClassLoader(), new Class[]{interface_, Endpoint.class}, new EndpointProxy(endpoint, interface_));
    return (T) newProxyInstance;
}
项目:SOMns-vscode    文件:ServiceEndpoints.java   
/**
 * Wraps a given object with service annotations behind an {@link Endpoint} interface.
 * 
 * @param serviceObject
 * @return
 */
public static Endpoint toEndpoint(Object serviceObject) {
    return new GenericEndpoint(serviceObject);
}
项目:lsp4j    文件:ServiceEndpoints.java   
/**
 * Wraps a given {@link Endpoint} in the given service interface.
 * @param endpoint
 * @param interface_
 * @return the wrapped service object
 */
@SuppressWarnings("unchecked")
public static <T> T toServiceObject(Endpoint endpoint, Class<T> interface_) {
    Object newProxyInstance = Proxy.newProxyInstance(interface_.getClassLoader(), new Class[]{interface_, Endpoint.class}, new EndpointProxy(endpoint, interface_));
    return (T) newProxyInstance;
}
项目:lsp4j    文件:ServiceEndpoints.java   
/**
 * Wraps a given object with service annotations behind an {@link Endpoint} interface.
 * 
 * @param serviceObject
 * @return the wrapped service endpoint
 */
public static Endpoint toEndpoint(Object serviceObject) {
    return new GenericEndpoint(serviceObject);
}