Exemplo n.º 1
0
  public void openDeclaration() {
    EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
    if (activeEditor == null) {
      return;
    }

    if (!(activeEditor instanceof EmbeddedTextEditorPresenter)) {
      Log.error(getClass(), "Open Declaration support only EmbeddedTextEditorPresenter as editor");
      return;
    }
    EmbeddedTextEditorPresenter editor = ((EmbeddedTextEditorPresenter) activeEditor);
    int offset = editor.getCursorOffset();
    final VirtualFile file = editor.getEditorInput().getFile();
    Unmarshallable<OpenDeclarationDescriptor> unmarshaller =
        factory.newUnmarshaller(OpenDeclarationDescriptor.class);
    navigationService.findDeclaration(
        file.getProject().getProjectConfig().getPath(),
        JavaSourceFolderUtil.getFQNForFile(file),
        offset,
        new AsyncRequestCallback<OpenDeclarationDescriptor>(unmarshaller) {
          @Override
          protected void onSuccess(OpenDeclarationDescriptor result) {
            if (result != null) {
              handleDescriptor(result);
            }
          }

          @Override
          protected void onFailure(Throwable exception) {
            Log.error(OpenDeclarationFinder.class, exception);
          }
        });
  }
  private void setupProposals(
      final CodeAssistCallback callback,
      final TextEditor textEditor,
      final int offset,
      final List<Problem> annotations) {
    final VirtualFile file = textEditor.getEditorInput().getFile();
    final String projectPath = file.getProject().getProjectConfig().getPath();
    String fqn = JavaSourceFolderUtil.getFQNForFile(file);
    Unmarshallable<Proposals> unmarshaller = unmarshallerFactory.newUnmarshaller(Proposals.class);
    client.computeAssistProposals(
        projectPath,
        fqn,
        offset,
        annotations,
        new AsyncRequestCallback<Proposals>(unmarshaller) {
          @Override
          protected void onSuccess(Proposals proposals) {
            showProposals(callback, proposals, textEditor);
          }

          @Override
          protected void onFailure(Throwable throwable) {
            Log.error(JavaCodeAssistProcessor.class, throwable);
          }
        });
  }