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;
}
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);
}
}
});
}
}
Aggregations