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