do not suggest org.jruby.util.ShellLauncher.ChannelPumper when find usages of "Thread.start"

This commit is contained in:
Alexey Kudravtsev
2015-10-28 14:55:39 +03:00
parent 91d5d75923
commit f9547c2ece
3 changed files with 82 additions and 9 deletions
@@ -19,9 +19,11 @@ import com.intellij.codeInspection.InspectionsBundle;
import com.intellij.lang.findUsages.DescriptiveNameUtil;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethod;
@@ -30,6 +32,7 @@ import com.intellij.psi.impl.FindSuperElementsHelper;
import com.intellij.psi.presentation.java.SymbolPresentationUtil;
import com.intellij.psi.search.PsiElementProcessor;
import com.intellij.psi.search.searches.DeepestSuperMethodsSearch;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.ui.components.JBList;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
@@ -52,15 +55,7 @@ public class SuperMethodWarningUtil {
PsiClass aClass = method.getContainingClass();
if (aClass == null) return new PsiMethod[]{method};
final Collection<PsiMethod> superMethods = DeepestSuperMethodsSearch.search(method).findAll();
superMethods.removeAll(ignore);
if (superMethods.isEmpty()) {
PsiMethod siblingSuperMethod = FindSuperElementsHelper.getSiblingInheritedViaSubClass(method);
if (siblingSuperMethod != null) {
superMethods.add(siblingSuperMethod);
}
}
final Collection<PsiMethod> superMethods = getSuperMethods(method, aClass, ignore);
if (superMethods.isEmpty()) return new PsiMethod[]{method};
@@ -90,6 +85,23 @@ public class SuperMethodWarningUtil {
return PsiMethod.EMPTY_ARRAY;
}
@NotNull
static Collection<PsiMethod> getSuperMethods(@NotNull PsiMethod method, PsiClass aClass, @NotNull Collection<PsiElement> ignore) {
final Collection<PsiMethod> superMethods = DeepestSuperMethodsSearch.search(method).findAll();
superMethods.removeAll(ignore);
if (superMethods.isEmpty()) {
VirtualFile virtualFile = PsiUtilCore.getVirtualFile(aClass);
if (virtualFile != null && ProjectRootManager.getInstance(aClass.getProject()).getFileIndex().isInSourceContent(virtualFile)) {
PsiMethod siblingSuperMethod = FindSuperElementsHelper.getSiblingInheritedViaSubClass(method);
if (siblingSuperMethod != null) {
superMethods.add(siblingSuperMethod);
}
}
}
return superMethods;
}
public static PsiMethod checkSuperMethod(@NotNull PsiMethod method, @NotNull String actionString) {
PsiClass aClass = method.getContainingClass();
@@ -0,0 +1,9 @@
interface Pumper extends Runnable {
void start();
}
class MyThread extends Thread implements Pumper {
}
@@ -0,0 +1,52 @@
/*
* Copyright 2000-2015 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.ide.util;
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiJavaFile;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.impl.FindSuperElementsHelper;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.Collections;
public class JavaSuperMethodTest extends LightDaemonAnalyzerTestCase {
@NotNull
@Override
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();
}
private static String getBasePath() {
return "/codeInsight/gotosuper/";
}
public void testDoNotGoToSiblingInheritanceIfInLibrary() throws Throwable {
configureByFile(getBasePath() + "OverridingLibrary.java");
PsiJavaFile file = (PsiJavaFile)getFile();
PsiClass aThread = getJavaFacade().findClass("java.lang.Thread");
PsiMethod startMethod = aThread.findMethodsByName("start", false)[0];
PsiMethod sibling = FindSuperElementsHelper.getSiblingInheritedViaSubClass(startMethod);
assertNotNull(sibling);
Collection<PsiMethod> superMethods = SuperMethodWarningUtil.getSuperMethods(startMethod, aThread, Collections.emptyList());
assertEmpty(superMethods);
}
}