mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
javac ast indices: test ui; unfinished
This commit is contained in:
+39
@@ -17,6 +17,9 @@ package com.intellij.compiler.backwardRefs;
|
||||
|
||||
import com.intellij.compiler.CompilerDirectHierarchyInfo;
|
||||
import com.intellij.compiler.CompilerReferenceService;
|
||||
import com.intellij.compiler.backwardRefs.view.CompilerReferenceFindUsagesTestInfo;
|
||||
import com.intellij.compiler.backwardRefs.view.CompilerReferenceHierarchyTestInfo;
|
||||
import com.intellij.compiler.backwardRefs.view.DirtyScopeTestInfo;
|
||||
import com.intellij.compiler.server.BuildManager;
|
||||
import com.intellij.compiler.server.BuildManagerListener;
|
||||
import com.intellij.lang.injection.InjectedLanguageManager;
|
||||
@@ -504,4 +507,40 @@ public class CompilerReferenceServiceImpl extends CompilerReferenceService imple
|
||||
public DirtyScopeHolder getDirtyScopeHolder() {
|
||||
return myDirtyScopeHolder;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CompilerReferenceFindUsagesTestInfo getTestFindUsages(@NotNull PsiElement element) {
|
||||
myReadDataLock.lock();
|
||||
try {
|
||||
final TIntHashSet referentFileIds = getReferentFileIds(element);
|
||||
final DirtyScopeTestInfo dirtyScopeInfo = myDirtyScopeHolder.getState();
|
||||
return new CompilerReferenceFindUsagesTestInfo(referentFileIds, dirtyScopeInfo, myProject);
|
||||
} finally {
|
||||
myReadDataLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CompilerReferenceHierarchyTestInfo getTestHierarchy(@NotNull PsiNamedElement element, @NotNull GlobalSearchScope scope, @NotNull FileType fileType) {
|
||||
myReadDataLock.lock();
|
||||
try {
|
||||
final CompilerHierarchyInfoImpl hierarchyInfo = getHierarchyInfo(element, scope, scope, fileType, CompilerHierarchySearchType.DIRECT_INHERITOR);
|
||||
final DirtyScopeTestInfo dirtyScopeInfo = myDirtyScopeHolder.getState();
|
||||
return new CompilerReferenceHierarchyTestInfo(hierarchyInfo, dirtyScopeInfo);
|
||||
} finally {
|
||||
myReadDataLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CompilerReferenceHierarchyTestInfo getTestFunExpressions(@NotNull PsiNamedElement element, @NotNull GlobalSearchScope scope, @NotNull FileType fileType) {
|
||||
myReadDataLock.lock();
|
||||
try {
|
||||
final CompilerHierarchyInfoImpl hierarchyInfo = getHierarchyInfo(element, scope, scope, fileType, CompilerHierarchySearchType.FUNCTIONAL_EXPRESSION);
|
||||
final DirtyScopeTestInfo dirtyScopeInfo = myDirtyScopeHolder.getState();
|
||||
return new CompilerReferenceHierarchyTestInfo(hierarchyInfo, dirtyScopeInfo);
|
||||
} finally {
|
||||
myReadDataLock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.compiler.backwardRefs;
|
||||
|
||||
import com.intellij.compiler.CompilerConfiguration;
|
||||
import com.intellij.compiler.backwardRefs.view.DirtyScopeTestInfo;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
import com.intellij.openapi.compiler.options.ExcludeEntryDescription;
|
||||
import com.intellij.openapi.compiler.options.ExcludedEntriesListener;
|
||||
@@ -38,6 +39,7 @@ import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -209,4 +211,17 @@ public class DirtyScopeHolder extends UserDataHolderBase {
|
||||
return getAllDirtyModules();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@NotNull
|
||||
DirtyScopeTestInfo getState() {
|
||||
synchronized (myLock) {
|
||||
final Module[] vfsChangedModules = myVFSChangedModules.toArray(Module.EMPTY_ARRAY);
|
||||
final List<Module> unsavedChangedModuleList = new ArrayList<>(getAllDirtyModules());
|
||||
ContainerUtil.removeAll(unsavedChangedModuleList, vfsChangedModules);
|
||||
final Module[] unsavedChangedModules = unsavedChangedModuleList.toArray(Module.EMPTY_ARRAY);
|
||||
final List<VirtualFile> excludedFiles = myExcludedFilesScope instanceof Iterable ? ContainerUtil.newArrayList((Iterable<VirtualFile>)myExcludedFilesScope) : Collections.emptyList();
|
||||
return new DirtyScopeTestInfo(vfsChangedModules, unsavedChangedModules, excludedFiles.toArray(VirtualFile.EMPTY_ARRAY), getDirtyScope());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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.compiler.backwardRefs.view;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.indexing.FileBasedIndex;
|
||||
import gnu.trove.TIntHashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class CompilerReferenceFindUsagesTestInfo {
|
||||
@Nullable private final TIntHashSet myFileIds;
|
||||
@NotNull private final DirtyScopeTestInfo myDirtyScopeInfo;
|
||||
@NotNull private final Project myProject;
|
||||
|
||||
public CompilerReferenceFindUsagesTestInfo(@Nullable TIntHashSet occurrencesIds,
|
||||
@NotNull DirtyScopeTestInfo dirtyScopeTestInfo,
|
||||
@NotNull Project project) {
|
||||
myFileIds = occurrencesIds;
|
||||
myDirtyScopeInfo = dirtyScopeTestInfo;
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
VirtualFile[] getFilesWithKnownOccurrences() {
|
||||
if (myFileIds == null) throw new IllegalStateException();
|
||||
final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
|
||||
return IntStream.of(myFileIds.toArray())
|
||||
.mapToObj(id -> fileBasedIndex.findFileById(myProject, id))
|
||||
.filter(f -> !myDirtyScopeInfo.getDirtyScope().contains(f))
|
||||
.toArray(VirtualFile[]::new);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
Module[] getDirtyModules() {
|
||||
return myDirtyScopeInfo.getDirtyModules();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
Module[] getDirtyUnsavedModules() {
|
||||
return myDirtyScopeInfo.getDirtyUnsavedModules();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
VirtualFile[] getExcludedFiles() {
|
||||
return myDirtyScopeInfo.getExcludedFiles();
|
||||
}
|
||||
|
||||
boolean isEnabled() {
|
||||
return myFileIds != null;
|
||||
}
|
||||
|
||||
DefaultMutableTreeNode asTree() {
|
||||
DefaultMutableTreeNode node = new DefaultMutableTreeNode();
|
||||
if (isEnabled()) {
|
||||
final DefaultMutableTreeNode knownOccurrences = new DefaultMutableTreeNode("Known occurrence files");
|
||||
node.add(knownOccurrences);
|
||||
for (VirtualFile file : getFilesWithKnownOccurrences()) {
|
||||
knownOccurrences.add(new DefaultMutableTreeNode(file));
|
||||
}
|
||||
|
||||
final DefaultMutableTreeNode dirtyModules = new DefaultMutableTreeNode("Dirty modules");
|
||||
node.add(dirtyModules);
|
||||
for (Module module : getDirtyModules()) {
|
||||
dirtyModules.add(new DefaultMutableTreeNode(module));
|
||||
}
|
||||
|
||||
final DefaultMutableTreeNode unsavedDirtyModules = new DefaultMutableTreeNode("Unsaved dirty modules");
|
||||
node.add(unsavedDirtyModules);
|
||||
for (Module module : getDirtyUnsavedModules()) {
|
||||
unsavedDirtyModules.add(new DefaultMutableTreeNode(module));
|
||||
}
|
||||
|
||||
final DefaultMutableTreeNode excludedFiles = new DefaultMutableTreeNode("Current excluded files");
|
||||
node.add(excludedFiles);
|
||||
for (VirtualFile excludedFile : getExcludedFiles()) {
|
||||
excludedFiles.add(new DefaultMutableTreeNode(excludedFile));
|
||||
}
|
||||
}
|
||||
else {
|
||||
node.add(new DefaultMutableTreeNode("Service is not available"));
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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.compiler.backwardRefs.view;
|
||||
|
||||
import com.intellij.compiler.CompilerDirectHierarchyInfo;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class CompilerReferenceHierarchyTestInfo {
|
||||
@Nullable private final CompilerDirectHierarchyInfo myHierarchyInfo;
|
||||
@NotNull private final DirtyScopeTestInfo myDirtyScopeInfo;
|
||||
|
||||
public CompilerReferenceHierarchyTestInfo(@Nullable CompilerDirectHierarchyInfo hierarchyInfo,
|
||||
@NotNull DirtyScopeTestInfo dirtyScopeTestInfo) {
|
||||
myHierarchyInfo = hierarchyInfo;
|
||||
myDirtyScopeInfo = dirtyScopeTestInfo;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Stream<PsiElement> getHierarchyChildren() {
|
||||
if (myHierarchyInfo == null) throw new IllegalArgumentException();
|
||||
return myHierarchyInfo.getHierarchyChildren();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
Module[] getDirtyModules() {
|
||||
return myDirtyScopeInfo.getDirtyModules();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
Module[] getDirtyUnsavedModules() {
|
||||
return myDirtyScopeInfo.getDirtyUnsavedModules();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
VirtualFile[] getExcludedFiles() {
|
||||
return myDirtyScopeInfo.getExcludedFiles();
|
||||
}
|
||||
|
||||
boolean isEnabled() {
|
||||
return myHierarchyInfo != null;
|
||||
}
|
||||
|
||||
DefaultMutableTreeNode asTree() {
|
||||
DefaultMutableTreeNode node = new DefaultMutableTreeNode();
|
||||
if (isEnabled()) {
|
||||
final DefaultMutableTreeNode knownOccurrences = new DefaultMutableTreeNode("Known hierarchy direct children");
|
||||
node.add(knownOccurrences);
|
||||
getHierarchyChildren().forEach(e -> {
|
||||
knownOccurrences.add(new DefaultMutableTreeNode(e));
|
||||
});
|
||||
|
||||
final DefaultMutableTreeNode dirtyModules = new DefaultMutableTreeNode("Dirty modules");
|
||||
node.add(dirtyModules);
|
||||
for (Module module : getDirtyModules()) {
|
||||
dirtyModules.add(new DefaultMutableTreeNode(module));
|
||||
}
|
||||
|
||||
final DefaultMutableTreeNode unsavedDirtyModules = new DefaultMutableTreeNode("Unsaved dirty modules");
|
||||
node.add(unsavedDirtyModules);
|
||||
for (Module module : getDirtyUnsavedModules()) {
|
||||
unsavedDirtyModules.add(new DefaultMutableTreeNode(module));
|
||||
}
|
||||
|
||||
final DefaultMutableTreeNode excludedFiles = new DefaultMutableTreeNode("Current excluded files");
|
||||
node.add(excludedFiles);
|
||||
for (VirtualFile excludedFile : getExcludedFiles()) {
|
||||
excludedFiles.add(new DefaultMutableTreeNode(excludedFile));
|
||||
}
|
||||
}
|
||||
else {
|
||||
node.add(new DefaultMutableTreeNode("Service is not available"));
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.compiler.backwardRefs.view;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
|
||||
public class DirtyScopeTestInfo {
|
||||
private final Module[] myDirtyModules;
|
||||
private final Module[] myDirtyUnsavedModules;
|
||||
private final VirtualFile[] myExcludedFiles;
|
||||
private final GlobalSearchScope myDirtyScope;
|
||||
|
||||
public DirtyScopeTestInfo(Module[] dirtyModules,
|
||||
Module[] dirtyUnsavedModules,
|
||||
VirtualFile[] files,
|
||||
GlobalSearchScope dirtyScope) {
|
||||
|
||||
myDirtyModules = dirtyModules;
|
||||
myDirtyUnsavedModules = dirtyUnsavedModules;
|
||||
myExcludedFiles = files;
|
||||
myDirtyScope = dirtyScope;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
Module[] getDirtyModules() {
|
||||
return myDirtyModules;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
Module[] getDirtyUnsavedModules() {
|
||||
return myDirtyUnsavedModules;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
VirtualFile[] getExcludedFiles() {
|
||||
return myExcludedFiles;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
GlobalSearchScope getDirtyScope() { return myDirtyScope; }
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* 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.compiler.backwardRefs.view;
|
||||
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.DataProvider;
|
||||
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.wm.ToolWindow;
|
||||
import com.intellij.openapi.wm.ToolWindowAnchor;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.presentation.java.SymbolPresentationUtil;
|
||||
import com.intellij.ui.ColoredTreeCellRenderer;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
import com.intellij.ui.ToolbarDecorator;
|
||||
import com.intellij.ui.content.impl.ContentImpl;
|
||||
import com.intellij.ui.treeStructure.Tree;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.TreePath;
|
||||
import java.awt.*;
|
||||
|
||||
public class InternalCompilerRefServiceView extends JPanel implements DataProvider {
|
||||
private static final String TOOL_WINDOW_ID = "Compiler Reference View";
|
||||
private final Tree myTree;
|
||||
private final Project myProject;
|
||||
|
||||
public InternalCompilerRefServiceView(Project project) {
|
||||
myProject = project;
|
||||
myTree = new Tree(new DefaultTreeModel(new DefaultMutableTreeNode()));
|
||||
myTree.setRootVisible(false);
|
||||
myTree.setCellRenderer(new ColoredTreeCellRenderer() {
|
||||
@Override
|
||||
public void customizeCellRenderer(@NotNull JTree tree,
|
||||
Object value,
|
||||
boolean selected,
|
||||
boolean expanded,
|
||||
boolean leaf,
|
||||
int row,
|
||||
boolean hasFocus) {
|
||||
final DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
|
||||
final Object userObject = node.getUserObject();
|
||||
if (userObject instanceof String) {
|
||||
append((String)userObject, SimpleTextAttributes.GRAY_ATTRIBUTES);
|
||||
}
|
||||
else if (userObject instanceof VirtualFile) {
|
||||
append(((VirtualFile)userObject).getName());
|
||||
append(" in ");
|
||||
append(((VirtualFile)userObject).getParent().getPath(), SimpleTextAttributes.GRAY_ATTRIBUTES);
|
||||
} else {
|
||||
append(userObject.toString());
|
||||
}
|
||||
}
|
||||
});
|
||||
setLayout(new BorderLayout());
|
||||
add(ToolbarDecorator.createDecorator(myTree).createPanel());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object getData(String dataId) {
|
||||
if (CommonDataKeys.NAVIGATABLE.is(dataId)) {
|
||||
final TreePath path = myTree.getSelectionPath();
|
||||
if (path != null) {
|
||||
final Object usrObject = ((DefaultMutableTreeNode)path.getLastPathComponent()).getUserObject();
|
||||
if (usrObject instanceof VirtualFile) {
|
||||
return new OpenFileDescriptor(myProject, (VirtualFile)usrObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void showFindUsages(CompilerReferenceFindUsagesTestInfo info, PsiElement element) {
|
||||
final InternalCompilerRefServiceView view = getView(element);
|
||||
final DefaultMutableTreeNode node = info.asTree();
|
||||
node.setUserObject(element);
|
||||
((DefaultTreeModel)view.myTree.getModel()).setRoot(node);
|
||||
}
|
||||
|
||||
public static InternalCompilerRefServiceView getView(PsiElement element) {
|
||||
Project project = element.getProject();
|
||||
final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
|
||||
ToolWindow toolWindow = toolWindowManager.getToolWindow(TOOL_WINDOW_ID);
|
||||
if (toolWindow == null) {
|
||||
toolWindow = toolWindowManager.registerToolWindow(TOOL_WINDOW_ID,
|
||||
true,
|
||||
ToolWindowAnchor.TOP);
|
||||
}
|
||||
final InternalCompilerRefServiceView view = new InternalCompilerRefServiceView(project);
|
||||
ToolWindow finalToolWindow = toolWindow;
|
||||
toolWindow.activate(() -> {
|
||||
final String text = SymbolPresentationUtil.getSymbolPresentableText(element);
|
||||
final ContentImpl content = new ContentImpl(view, text, true);
|
||||
finalToolWindow.getContentManager().addContent(content);
|
||||
finalToolWindow.getContentManager().setSelectedContent(content, true);
|
||||
});
|
||||
return view;
|
||||
}
|
||||
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.compiler.backwardRefs.view;
|
||||
|
||||
import com.intellij.codeInsight.TargetElementUtil;
|
||||
import com.intellij.compiler.CompilerReferenceService;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.application.ex.ApplicationManagerEx;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class TestCompilerReferenceServiceAction extends AnAction {
|
||||
public TestCompilerReferenceServiceAction(String text) {
|
||||
super(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
|
||||
if (editor != null) {
|
||||
final PsiElement element = TargetElementUtil.getInstance()
|
||||
.findTargetElement(editor, TargetElementUtil.ELEMENT_NAME_ACCEPTED, editor.getCaretModel().getOffset());
|
||||
if (element != null) {
|
||||
startActionFor(element);
|
||||
}
|
||||
System.out.println(element);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void startActionFor(@NotNull PsiElement element);
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
super.update(e);
|
||||
final Presentation presentation = e.getPresentation();
|
||||
if (presentation.isEnabled()) {
|
||||
presentation.setEnabledAndVisible(CompilerReferenceService.isEnabled() && ApplicationManagerEx.getApplicationEx().isInternal());
|
||||
}
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.compiler.backwardRefs.view;
|
||||
|
||||
import com.intellij.compiler.CompilerReferenceService;
|
||||
import com.intellij.compiler.backwardRefs.CompilerReferenceServiceImpl;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TestCompilerReferenceServiceFindUsagesAction extends TestCompilerReferenceServiceAction {
|
||||
public TestCompilerReferenceServiceFindUsagesAction() {
|
||||
super("Compiler Reference Find Usages");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startActionFor(@NotNull PsiElement element) {
|
||||
if (element instanceof PsiMethod || element instanceof PsiField || element instanceof PsiClass) {
|
||||
final CompilerReferenceServiceImpl compilerReferenceService =
|
||||
(CompilerReferenceServiceImpl)CompilerReferenceService.getInstance(element.getProject());
|
||||
final CompilerReferenceFindUsagesTestInfo compilerReferenceTestInfo = compilerReferenceService.getTestFindUsages(element);
|
||||
InternalCompilerRefServiceView.showFindUsages(compilerReferenceTestInfo, element);
|
||||
}
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.compiler.backwardRefs.view;
|
||||
|
||||
import com.intellij.compiler.CompilerReferenceService;
|
||||
import com.intellij.compiler.backwardRefs.CompilerReferenceServiceImpl;
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.LambdaUtil;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiNamedElement;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.GlobalSearchScopeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TestCompilerReferenceServiceFunctionalExpressionSearchAction extends TestCompilerReferenceServiceAction {
|
||||
|
||||
public TestCompilerReferenceServiceFunctionalExpressionSearchAction(String text) {
|
||||
super(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startActionFor(@NotNull PsiElement element) {
|
||||
if (element instanceof PsiClass && LambdaUtil.isFunctionalClass((PsiClass)element)) {
|
||||
final Project project = element.getProject();
|
||||
final CompilerReferenceServiceImpl compilerReferenceService = (CompilerReferenceServiceImpl)CompilerReferenceService.getInstance(
|
||||
project);
|
||||
final GlobalSearchScope scope = GlobalSearchScopeUtil.toGlobalSearchScope(element.getUseScope(), project);
|
||||
compilerReferenceService.getTestFunExpressions((PsiNamedElement)element, scope, StdFileTypes.JAVA);
|
||||
}
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.compiler.backwardRefs.view;
|
||||
|
||||
import com.intellij.compiler.CompilerReferenceService;
|
||||
import com.intellij.compiler.backwardRefs.CompilerReferenceServiceImpl;
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiNamedElement;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.GlobalSearchScopeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TestCompilerReferenceServiceInheritanceAction extends TestCompilerReferenceServiceAction {
|
||||
public TestCompilerReferenceServiceInheritanceAction(String text) {
|
||||
super(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startActionFor(@NotNull PsiElement element) {
|
||||
if (element instanceof PsiClass) {
|
||||
final Project project = element.getProject();
|
||||
final CompilerReferenceServiceImpl compilerReferenceService = (CompilerReferenceServiceImpl)CompilerReferenceService.getInstance(project);
|
||||
final GlobalSearchScope scope = GlobalSearchScopeUtil.toGlobalSearchScope(element.getUseScope(), project);
|
||||
final CompilerReferenceHierarchyTestInfo hierarchyInfo = compilerReferenceService.getTestHierarchy(
|
||||
(PsiNamedElement)element,
|
||||
scope,
|
||||
StdFileTypes.JAVA);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -446,5 +446,7 @@
|
||||
<action id="FileChooser.GotoJDK" class="com.intellij.openapi.projectRoots.JdkPopupAction" >
|
||||
<add-to-group group-id="FileChooserToolbar" anchor="last"/>
|
||||
</action>
|
||||
|
||||
<action class="com.intellij.compiler.backwardRefs.view.TestCompilerReferenceServiceFindUsagesAction" id="TestCompilerReferenceServiceFindUsages"/>
|
||||
</actions>
|
||||
</idea-plugin>
|
||||
|
||||
Reference in New Issue
Block a user