[platform] decompiler calls in hierarchy browser (IDEA-163673)

This commit is contained in:
Roman Shevchenko
2016-11-08 17:04:32 +01:00
parent 8e5f004aed
commit 3068fceeea
3 changed files with 80 additions and 10 deletions
@@ -31,12 +31,11 @@ import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.ex.ComboBoxAction;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.fileEditor.PsiElementNavigatable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.pom.Navigatable;
import com.intellij.psi.*;
import com.intellij.psi.search.scope.packageSet.NamedScope;
@@ -140,13 +139,14 @@ public abstract class HierarchyBrowserBaseEx extends HierarchyBrowserBase implem
@Override
@Nullable
protected Navigatable createDescriptorForNode(DefaultMutableTreeNode node) {
final HierarchyNodeDescriptor descriptor = getDescriptor(node);
if (descriptor == null) return null;
PsiElement psiElement = getOpenFileElementFromDescriptor(descriptor);
if (psiElement == null || !psiElement.isValid()) return null;
final VirtualFile virtualFile = psiElement.getContainingFile().getVirtualFile();
if (virtualFile == null) return null;
return new OpenFileDescriptor(psiElement.getProject(), virtualFile, psiElement.getTextOffset());
HierarchyNodeDescriptor descriptor = getDescriptor(node);
if (descriptor != null) {
PsiElement psiElement = getOpenFileElementFromDescriptor(descriptor);
if (psiElement != null && psiElement.isValid()) {
return new PsiElementNavigatable(psiElement);
}
}
return null;
}
@Override
@@ -0,0 +1,68 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.fileEditor;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.editor.EditorBundle;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.pom.Navigatable;
import com.intellij.psi.PsiElement;
import com.intellij.psi.SmartPointerManager;
import com.intellij.psi.SmartPsiElementPointer;
import org.jetbrains.annotations.NotNull;
public class PsiElementNavigatable implements Navigatable {
private final SmartPsiElementPointer<PsiElement> myPointer;
public PsiElementNavigatable(@NotNull PsiElement element) {
myPointer = SmartPointerManager.getInstance(element.getProject()).createSmartPsiElementPointer(element);
}
@Override
public final void navigate(boolean requestFocus) {
PsiElement element = myPointer.getElement();
if (element != null && element.isValid()) {
VirtualFile file = element.getContainingFile().getVirtualFile();
if (file != null) {
new Task.Backgroundable(element.getProject(), EditorBundle.message("editor.open.file.progress", file.getName())) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
if (element.isValid() && !myProject.isDisposed()) {
int offset = ReadAction.compute(() -> element.getTextOffset()); // may trigger decompilation
indicator.checkCanceled();
OpenFileDescriptor descriptor = new OpenFileDescriptor(myProject, file, offset);
ApplicationManager.getApplication().invokeLater(() -> descriptor.navigate(requestFocus), myProject.getDisposed());
}
}
}.queue();
}
}
}
@Override
public boolean canNavigate() {
PsiElement element = myPointer.getElement();
return element != null && element.isValid() && element.getContainingFile().getVirtualFile() != null;
}
@Override
public boolean canNavigateToSource() {
return canNavigate();
}
}
@@ -27,4 +27,6 @@ forced.soft.wrap.message=This document contains very long lines. Soft wraps were
forced.soft.wrap.hide.message=Hide notification
forced.soft.wrap.dont.show.again.message=Don't show again
editor.notification.default.action.name=Notification actions
editor.notification.settings.option.name=Settings...
editor.notification.settings.option.name=Settings...
editor.open.file.progress=Opening {0}