Search in sources :

Example 1 with OpenDeclarationDescriptor

use of org.eclipse.che.ide.ext.java.shared.OpenDeclarationDescriptor in project che by eclipse.

the class JavaNavigation method compilationUnitNavigation.

private OpenDeclarationDescriptor compilationUnitNavigation(ICompilationUnit unit, IJavaElement element) throws JavaModelException {
    OpenDeclarationDescriptor dto = DtoFactory.getInstance().createDto(OpenDeclarationDescriptor.class);
    String absolutePath = unit.getPath().toOSString();
    dto.setPath(absolutePath);
    dto.setBinary(false);
    if (element instanceof ISourceReference) {
        ISourceRange nameRange = ((ISourceReference) element).getNameRange();
        dto.setOffset(nameRange.getOffset());
        dto.setLength(nameRange.getLength());
    }
    return dto;
}
Also used : OpenDeclarationDescriptor(org.eclipse.che.ide.ext.java.shared.OpenDeclarationDescriptor) ISourceReference(org.eclipse.jdt.core.ISourceReference) ISourceRange(org.eclipse.jdt.core.ISourceRange)

Example 2 with OpenDeclarationDescriptor

use of org.eclipse.che.ide.ext.java.shared.OpenDeclarationDescriptor in project che by eclipse.

the class JavaNavigation method classFileNavigation.

private OpenDeclarationDescriptor classFileNavigation(IClassFile classFile, IJavaElement element) throws JavaModelException {
    OpenDeclarationDescriptor dto = DtoFactory.getInstance().createDto(OpenDeclarationDescriptor.class);
    dto.setPath(classFile.getType().getFullyQualifiedName());
    dto.setLibId(classFile.getAncestor(IPackageFragmentRoot.PACKAGE_FRAGMENT_ROOT).hashCode());
    dto.setBinary(true);
    if (classFile.getSourceRange() != null) {
        if (element instanceof ISourceReference) {
            ISourceRange nameRange = ((ISourceReference) element).getNameRange();
            dto.setOffset(nameRange.getOffset());
            dto.setLength(nameRange.getLength());
        }
    }
    return dto;
}
Also used : OpenDeclarationDescriptor(org.eclipse.che.ide.ext.java.shared.OpenDeclarationDescriptor) ISourceReference(org.eclipse.jdt.core.ISourceReference) ISourceRange(org.eclipse.jdt.core.ISourceRange)

Example 3 with OpenDeclarationDescriptor

use of org.eclipse.che.ide.ext.java.shared.OpenDeclarationDescriptor in project che by eclipse.

the class FindDeclarationTest method testFindClassIsNotNullOrEmpty.

@Test
public void testFindClassIsNotNullOrEmpty() throws Exception {
    OpenDeclarationDescriptor declaration = navigation.findDeclaration(project, "java.lang.String", 3669);
    assertThat(declaration).isNotNull();
}
Also used : OpenDeclarationDescriptor(org.eclipse.che.ide.ext.java.shared.OpenDeclarationDescriptor) Test(org.junit.Test)

Example 4 with OpenDeclarationDescriptor

use of org.eclipse.che.ide.ext.java.shared.OpenDeclarationDescriptor in project che by eclipse.

the class OpenDeclarationFinder method openDeclaration.

public void openDeclaration() {
    EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
    if (activeEditor == null) {
        return;
    }
    if (!(activeEditor instanceof TextEditor)) {
        Log.error(getClass(), "Open Declaration support only TextEditor as editor");
        return;
    }
    TextEditor editor = ((TextEditor) activeEditor);
    int offset = editor.getCursorOffset();
    final VirtualFile file = editor.getEditorInput().getFile();
    if (file instanceof Resource) {
        final Optional<Project> project = ((Resource) file).getRelatedProject();
        final Optional<Resource> srcFolder = ((Resource) file).getParentWithMarker(SourceFolderMarker.ID);
        if (!srcFolder.isPresent()) {
            return;
        }
        final String fqn = JavaUtil.resolveFQN((Container) srcFolder.get(), (Resource) file);
        navigationService.findDeclaration(project.get().getLocation(), fqn, offset).then(new Operation<OpenDeclarationDescriptor>() {

            @Override
            public void apply(OpenDeclarationDescriptor result) throws OperationException {
                if (result != null) {
                    handleDescriptor(project.get().getLocation(), result);
                }
            }
        });
    } else if (file instanceof JarFileNode) {
        navigationService.findDeclaration(((JarFileNode) file).getProjectLocation(), file.getLocation().toString().replace('/', '.'), offset).then(new Operation<OpenDeclarationDescriptor>() {

            @Override
            public void apply(OpenDeclarationDescriptor result) throws OperationException {
                if (result != null) {
                    handleDescriptor(((JarFileNode) file).getProject(), result);
                }
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) OpenDeclarationDescriptor(org.eclipse.che.ide.ext.java.shared.OpenDeclarationDescriptor) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) JarFileNode(org.eclipse.che.ide.ext.java.client.tree.library.JarFileNode) Project(org.eclipse.che.ide.api.resources.Project) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 5 with OpenDeclarationDescriptor

use of org.eclipse.che.ide.ext.java.shared.OpenDeclarationDescriptor in project che by eclipse.

the class FindDeclarationTest method testFindClassShouldReturnBinaryPath.

@Test
public void testFindClassShouldReturnBinaryPath() throws Exception {
    OpenDeclarationDescriptor declaration = navigation.findDeclaration(project, "org.eclipse.che.test.MyClass", 855);
    assertThat(declaration).isNotNull();
    assertThat(declaration.getOffset()).isNotNull();
    assertThat(declaration.getLength()).isNotNull();
    assertThat(declaration.isBinary()).isTrue();
    assertThat(declaration.getPath()).isEqualTo("java.lang.String");
}
Also used : OpenDeclarationDescriptor(org.eclipse.che.ide.ext.java.shared.OpenDeclarationDescriptor) Test(org.junit.Test)

Aggregations

OpenDeclarationDescriptor (org.eclipse.che.ide.ext.java.shared.OpenDeclarationDescriptor)7 Test (org.junit.Test)4 ISourceRange (org.eclipse.jdt.core.ISourceRange)2 ISourceReference (org.eclipse.jdt.core.ISourceReference)2 Operation (org.eclipse.che.api.promises.client.Operation)1 OperationException (org.eclipse.che.api.promises.client.OperationException)1 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)1 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)1 Project (org.eclipse.che.ide.api.resources.Project)1 Resource (org.eclipse.che.ide.api.resources.Resource)1 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)1 JarFileNode (org.eclipse.che.ide.ext.java.client.tree.library.JarFileNode)1