diff --git a/java/compiler/impl/src/com/intellij/compiler/backwardRefs/CompilerReferenceServiceImpl.java b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/CompilerReferenceServiceImpl.java index 18c91aa357c5..f3c303244d82 100644 --- a/java/compiler/impl/src/com/intellij/compiler/backwardRefs/CompilerReferenceServiceImpl.java +++ b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/CompilerReferenceServiceImpl.java @@ -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(); + } + } } diff --git a/java/compiler/impl/src/com/intellij/compiler/backwardRefs/DirtyScopeHolder.java b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/DirtyScopeHolder.java index e2f71ea13964..47650e9b51f3 100644 --- a/java/compiler/impl/src/com/intellij/compiler/backwardRefs/DirtyScopeHolder.java +++ b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/DirtyScopeHolder.java @@ -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 unsavedChangedModuleList = new ArrayList<>(getAllDirtyModules()); + ContainerUtil.removeAll(unsavedChangedModuleList, vfsChangedModules); + final Module[] unsavedChangedModules = unsavedChangedModuleList.toArray(Module.EMPTY_ARRAY); + final List excludedFiles = myExcludedFilesScope instanceof Iterable ? ContainerUtil.newArrayList((Iterable)myExcludedFilesScope) : Collections.emptyList(); + return new DirtyScopeTestInfo(vfsChangedModules, unsavedChangedModules, excludedFiles.toArray(VirtualFile.EMPTY_ARRAY), getDirtyScope()); + } + } } diff --git a/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/CompilerReferenceFindUsagesTestInfo.java b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/CompilerReferenceFindUsagesTestInfo.java new file mode 100644 index 000000000000..4712bdcc1576 --- /dev/null +++ b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/CompilerReferenceFindUsagesTestInfo.java @@ -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; + } +} diff --git a/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/CompilerReferenceHierarchyTestInfo.java b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/CompilerReferenceHierarchyTestInfo.java new file mode 100644 index 000000000000..453bf8f2ab34 --- /dev/null +++ b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/CompilerReferenceHierarchyTestInfo.java @@ -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 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; + } +} diff --git a/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/DirtyScopeTestInfo.java b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/DirtyScopeTestInfo.java new file mode 100644 index 000000000000..69f1f8adb2cf --- /dev/null +++ b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/DirtyScopeTestInfo.java @@ -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; } +} diff --git a/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/InternalCompilerRefServiceView.java b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/InternalCompilerRefServiceView.java new file mode 100644 index 000000000000..3e9d72b91560 --- /dev/null +++ b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/InternalCompilerRefServiceView.java @@ -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; + } + +} diff --git a/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/TestCompilerReferenceServiceAction.java b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/TestCompilerReferenceServiceAction.java new file mode 100644 index 000000000000..8e96f505be90 --- /dev/null +++ b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/TestCompilerReferenceServiceAction.java @@ -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()); + } + } +} diff --git a/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/TestCompilerReferenceServiceFindUsagesAction.java b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/TestCompilerReferenceServiceFindUsagesAction.java new file mode 100644 index 000000000000..ecd6ce150b70 --- /dev/null +++ b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/TestCompilerReferenceServiceFindUsagesAction.java @@ -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); + } + } +} diff --git a/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/TestCompilerReferenceServiceFunctionalExpressionSearchAction.java b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/TestCompilerReferenceServiceFunctionalExpressionSearchAction.java new file mode 100644 index 000000000000..f77688df33c9 --- /dev/null +++ b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/TestCompilerReferenceServiceFunctionalExpressionSearchAction.java @@ -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); + } + } +} diff --git a/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/TestCompilerReferenceServiceInheritanceAction.java b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/TestCompilerReferenceServiceInheritanceAction.java new file mode 100644 index 000000000000..9eea7dc14101 --- /dev/null +++ b/java/compiler/impl/src/com/intellij/compiler/backwardRefs/view/TestCompilerReferenceServiceInheritanceAction.java @@ -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); + } + } +} diff --git a/resources/src/idea/JavaActions.xml b/resources/src/idea/JavaActions.xml index bf11bbc00f1e..eb892f604723 100644 --- a/resources/src/idea/JavaActions.xml +++ b/resources/src/idea/JavaActions.xml @@ -446,5 +446,7 @@ + +