Search in sources :

Example 1 with ImplementationsDescriptorDTO

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

the class JavaTypeHierarchy method getImplementations.

/**
     * Get all implementations of selected Java Element.
     *
     * @param project
     *         opened project
     * @param fqn
     *         fully qualified name of the class file
     * @param offset
     *         cursor position
     * @return descriptor of the implementations
     * @throws JavaModelException
     *         when JavaModel has a failure
     */
public ImplementationsDescriptorDTO getImplementations(IJavaProject project, String fqn, int offset) throws JavaModelException {
    ImplementationsDescriptorDTO implementationDescriptor = DtoFactory.newDto(ImplementationsDescriptorDTO.class);
    IJavaElement element = getJavaElement(project, fqn, offset);
    if (element == null) {
        return implementationDescriptor.withImplementations(emptyList());
    }
    List<Type> implementations = new ArrayList<>();
    implementationDescriptor.setImplementations(implementations);
    switch(element.getElementType()) {
        case //type
        7:
            findSubTypes(element, implementations);
            implementationDescriptor.setMemberName(element.getElementName());
            break;
        case //method
        9:
            findTypesWithSubMethods(element, implementations);
            implementationDescriptor.setMemberName(element.getElementName());
            break;
        default:
            break;
    }
    return implementationDescriptor;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IType(org.eclipse.jdt.core.IType) Type(org.eclipse.che.ide.ext.java.shared.dto.model.Type) ImplementationsDescriptorDTO(org.eclipse.che.ide.ext.java.shared.dto.ImplementationsDescriptorDTO) ArrayList(java.util.ArrayList)

Example 2 with ImplementationsDescriptorDTO

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

the class OpenImplementationPresenter method show.

/**
     * Shows the implementations of the selected element.
     *
     * @param editorPartPresenter
     *         the active editor
     */
public void show(final EditorPartPresenter editorPartPresenter) {
    if (!(editorPartPresenter instanceof TextEditor)) {
        Log.error(getClass(), "Open Declaration support only TextEditor as editor");
        return;
    }
    activeEditor = ((TextEditor) editorPartPresenter);
    final VirtualFile file = activeEditor.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);
        service.getImplementations(project.get().getLocation(), fqn, activeEditor.getCursorOffset()).then(new Operation<ImplementationsDescriptorDTO>() {

            @Override
            public void apply(ImplementationsDescriptorDTO impls) throws OperationException {
                int overridingSize = impls.getImplementations().size();
                String title = locale.openImplementationWindowTitle(impls.getMemberName(), overridingSize);
                NoImplementationWidget noImplementationWidget = new NoImplementationWidget(popupResources, javaResources, locale, OpenImplementationPresenter.this, title);
                if (overridingSize == 1) {
                    actionPerformed(impls.getImplementations().get(0));
                } else if (overridingSize > 1) {
                    openOneImplementation(impls, noImplementationWidget, (TextEditor) editorPartPresenter);
                } else if (!isNullOrEmpty(impls.getMemberName()) && overridingSize == 0) {
                    showNoImplementations(noImplementationWidget, (TextEditor) editorPartPresenter);
                }
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Project(org.eclipse.che.ide.api.resources.Project) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) Resource(org.eclipse.che.ide.api.resources.Resource) ImplementationsDescriptorDTO(org.eclipse.che.ide.ext.java.shared.dto.ImplementationsDescriptorDTO) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

ImplementationsDescriptorDTO (org.eclipse.che.ide.ext.java.shared.dto.ImplementationsDescriptorDTO)2 ArrayList (java.util.ArrayList)1 OperationException (org.eclipse.che.api.promises.client.OperationException)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 Type (org.eclipse.che.ide.ext.java.shared.dto.model.Type)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 IType (org.eclipse.jdt.core.IType)1