mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 04:51:24 +07:00
provide scope to detect location more precisely (IDEA-107895)
This commit is contained in:
@@ -25,6 +25,7 @@ import com.intellij.execution.testframework.JavaAwareFilter;
|
||||
import com.intellij.execution.testframework.actions.AbstractRerunFailedTestsAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.ComponentContainer;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class JavaRerunFailedTestsAction extends AbstractRerunFailedTestsAction {
|
||||
@@ -35,8 +36,8 @@ public class JavaRerunFailedTestsAction extends AbstractRerunFailedTestsAction {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Filter getFilter(Project project) {
|
||||
return Filter.FAILED_OR_INTERRUPTED.and(JavaAwareFilter.METHOD(project));
|
||||
protected Filter getFilter(Project project, GlobalSearchScope searchScope) {
|
||||
return Filter.FAILED_OR_INTERRUPTED.and(JavaAwareFilter.METHOD(project, searchScope));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,15 +25,16 @@ import com.intellij.execution.PsiLocation;
|
||||
import com.intellij.execution.junit2.info.MethodLocation;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
|
||||
public class JavaAwareFilter {
|
||||
private JavaAwareFilter() {
|
||||
}
|
||||
|
||||
public static Filter METHOD(final Project project) {
|
||||
public static Filter METHOD(final Project project, final GlobalSearchScope searchScope) {
|
||||
return new Filter() {
|
||||
public boolean shouldAccept(final AbstractTestProxy test) {
|
||||
final Location location = test.getLocation(project);
|
||||
final Location location = test.getLocation(project, searchScope);
|
||||
if (location instanceof MethodLocation) return true;
|
||||
if (location instanceof PsiLocation && location.getPsiElement() instanceof PsiMethod) return true;
|
||||
return false;
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.intellij.pom.Navigatable;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.testIntegration.TestLocationProvider;
|
||||
import com.intellij.util.containers.ContainerUtilRt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -207,7 +208,7 @@ public class SMTestProxy extends AbstractTestProxy {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Location getLocation(final Project project) {
|
||||
public Location getLocation(final Project project, GlobalSearchScope searchScope) {
|
||||
//determines location of test proxy
|
||||
|
||||
//TODO multiresolve support
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.execution.testframework.sm;
|
||||
|
||||
import com.intellij.execution.Location;
|
||||
import com.intellij.execution.testframework.sm.runner.SMTestProxy;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
|
||||
/**
|
||||
@@ -47,7 +48,7 @@ public class FileUrlLocationTest extends SMLightFixtureTestCase {
|
||||
new SMTestProxy("myTest", false, "file://" + filePath + ":" + lineNum);
|
||||
testProxy.setLocator(new CompositeTestLocationProvider(null));
|
||||
|
||||
final Location location = testProxy.getLocation(getProject());
|
||||
final Location location = testProxy.getLocation(getProject(), GlobalSearchScope.allScope(getProject()));
|
||||
assertNotNull(location);
|
||||
assertNotNull(location.getPsiElement());
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.execution.testframework.sm.runner;
|
||||
|
||||
import com.intellij.execution.testframework.Filter;
|
||||
import com.intellij.execution.testframework.sm.runner.ui.MockPrinter;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
|
||||
import static com.intellij.execution.testframework.sm.runner.states.TestStateInfo.Magnitude;
|
||||
|
||||
@@ -592,12 +593,12 @@ public class SMTestProxyTest extends BaseSMTRunnerTestCase {
|
||||
}
|
||||
|
||||
public void testLocation() {
|
||||
assertNull(mySuite.getLocation(getProject()));
|
||||
assertNull(mySuite.getLocation(getProject(), GlobalSearchScope.allScope(getProject())));
|
||||
|
||||
mySuite.addChild(mySimpleTest);
|
||||
|
||||
assertNull(mySuite.getLocation(getProject()));
|
||||
assertNull(mySimpleTest.getLocation(getProject()));
|
||||
assertNull(mySuite.getLocation(getProject(), GlobalSearchScope.allScope(getProject())));
|
||||
assertNull(mySimpleTest.getLocation(getProject(), GlobalSearchScope.allScope(getProject())));
|
||||
}
|
||||
|
||||
public void testNavigatable() {
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.intellij.openapi.actionSystem.DataKey;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.pom.Navigatable;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -53,7 +54,7 @@ public abstract class AbstractTestProxy extends CompositePrintable {
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
public abstract Location getLocation(final Project project);
|
||||
public abstract Location getLocation(final Project project, GlobalSearchScope searchScope);
|
||||
|
||||
public abstract Navigatable getDescriptor(final Location location, final TestConsoleProperties testConsoleProperties);
|
||||
|
||||
|
||||
@@ -49,7 +49,8 @@ public class TestsUIUtil {
|
||||
|
||||
@Nullable
|
||||
public static Object getData(final AbstractTestProxy testProxy, final String dataId, final TestFrameworkRunningModel model) {
|
||||
final Project project = model.getProperties().getProject();
|
||||
final TestConsoleProperties properties = model.getProperties();
|
||||
final Project project = properties.getProject();
|
||||
if (testProxy == null) return null;
|
||||
if (AbstractTestProxy.DATA_KEY.is(dataId)) return testProxy;
|
||||
if (PlatformDataKeys.NAVIGATABLE.is(dataId)) return getOpenFileDescriptor(testProxy, model);
|
||||
@@ -58,7 +59,7 @@ public class TestsUIUtil {
|
||||
return openFileDescriptor != null ? new Navigatable[]{openFileDescriptor} : null;
|
||||
}
|
||||
if (LangDataKeys.PSI_ELEMENT.is(dataId)) {
|
||||
final Location location = testProxy.getLocation(project);
|
||||
final Location location = testProxy.getLocation(project, properties.getScope());
|
||||
if (location != null) {
|
||||
final PsiElement element = location.getPsiElement();
|
||||
return element.isValid() ? element : null;
|
||||
@@ -67,8 +68,8 @@ public class TestsUIUtil {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (Location.DATA_KEY.is(dataId)) return testProxy.getLocation(project);
|
||||
if (RuntimeConfiguration.DATA_KEY.is(dataId)) return model.getProperties().getConfiguration();
|
||||
if (Location.DATA_KEY.is(dataId)) return testProxy.getLocation(project, properties.getScope());
|
||||
if (RuntimeConfiguration.DATA_KEY.is(dataId)) return properties.getConfiguration();
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -84,7 +85,7 @@ public class TestsUIUtil {
|
||||
final Project project = testConsoleProperties.getProject();
|
||||
|
||||
if (proxy != null) {
|
||||
final Location location = proxy.getLocation(project);
|
||||
final Location location = proxy.getLocation(project, testConsoleProperties.getScope());
|
||||
if (openFailureLine) {
|
||||
return proxy.getDescriptor(location, testConsoleProperties);
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ import com.intellij.openapi.options.SettingsEditor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.ComponentContainer;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -131,8 +132,9 @@ public class AbstractRerunFailedTestsAction extends AnAction implements AnAction
|
||||
TestFrameworkRunningModel model = getModel();
|
||||
if (model == null || model.getRoot() == null) return false;
|
||||
final List<? extends AbstractTestProxy> myAllTests = model.getRoot().getAllTests();
|
||||
final GlobalSearchScope searchScope = model.getProperties().getScope();
|
||||
for (Object test : myAllTests) {
|
||||
if (getFilter(project).shouldAccept((AbstractTestProxy)test)) return true;
|
||||
if (getFilter(project, searchScope).shouldAccept((AbstractTestProxy)test)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -143,11 +145,11 @@ public class AbstractRerunFailedTestsAction extends AnAction implements AnAction
|
||||
final List<? extends AbstractTestProxy> myAllTests = model != null
|
||||
? model.getRoot().getAllTests()
|
||||
: Collections.<AbstractTestProxy>emptyList();
|
||||
return getFilter(project).select(myAllTests);
|
||||
return getFilter(project, model != null ? model.getProperties().getScope() : GlobalSearchScope.allScope(project)).select(myAllTests);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Filter getFilter(Project project) {
|
||||
protected Filter getFilter(Project project, GlobalSearchScope searchScope) {
|
||||
return Filter.FAILED_OR_INTERRUPTED;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class ExcludeFromRunAction extends AnAction{
|
||||
@@ -42,10 +42,11 @@ public class ExcludeFromRunAction extends AnAction{
|
||||
LOG.assertTrue(project != null);
|
||||
final JUnitConfiguration configuration = (JUnitConfiguration)RuntimeConfiguration.DATA_KEY.getData(dataContext);
|
||||
LOG.assertTrue(configuration != null);
|
||||
final GlobalSearchScope searchScope = configuration.getConfigurationModule().getSearchScope();
|
||||
final Set<String> patterns = configuration.getPersistentData().getPatterns();
|
||||
final AbstractTestProxy testProxy = AbstractTestProxy.DATA_KEY.getData(dataContext);
|
||||
LOG.assertTrue(testProxy != null);
|
||||
patterns.remove(((PsiClass)testProxy.getLocation(project).getPsiElement()).getQualifiedName());
|
||||
patterns.remove(((PsiClass)testProxy.getLocation(project, searchScope).getPsiElement()).getQualifiedName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,7 +62,7 @@ public class ExcludeFromRunAction extends AnAction{
|
||||
if (data.TEST_OBJECT == JUnitConfiguration.TEST_PATTERN) {
|
||||
final AbstractTestProxy testProxy = AbstractTestProxy.DATA_KEY.getData(dataContext);
|
||||
if (testProxy != null) {
|
||||
final Location location = testProxy.getLocation(project);
|
||||
final Location location = testProxy.getLocation(project, ((JUnitConfiguration)configuration).getConfigurationModule().getSearchScope());
|
||||
if (location != null) {
|
||||
final PsiElement psiElement = location.getPsiElement();
|
||||
if (psiElement instanceof PsiClass && data.getPatterns().contains(((PsiClass)psiElement).getQualifiedName())) {
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.util.Function;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -68,8 +69,9 @@ public class TestMethods extends TestMethod {
|
||||
});
|
||||
if (exception[0] != null) throw exception[0];
|
||||
final LinkedHashSet<TestInfo> methods = new LinkedHashSet<TestInfo>();
|
||||
final GlobalSearchScope searchScope = myConfiguration.getConfigurationModule().getSearchScope();
|
||||
for (AbstractTestProxy failedTest : myFailedTests) {
|
||||
Location location = failedTest.getLocation(project);
|
||||
Location location = failedTest.getLocation(project, searchScope);
|
||||
if (!(location instanceof MethodLocation)) continue;
|
||||
PsiElement psiElement = location.getPsiElement();
|
||||
LOG.assertTrue(psiElement instanceof PsiMethod);
|
||||
@@ -79,7 +81,7 @@ public class TestMethods extends TestMethod {
|
||||
addClassesListToJavaParameters(methods, new Function<TestInfo, String>() {
|
||||
public String fun(TestInfo testInfo) {
|
||||
if (testInfo != null) {
|
||||
final MethodLocation location = (MethodLocation)testInfo.getLocation(project);
|
||||
final MethodLocation location = (MethodLocation)testInfo.getLocation(project, searchScope);
|
||||
LOG.assertTrue(location != null);
|
||||
return JavaExecutionUtil.getRuntimeQualifiedName(location.getContainingClass()) + "," + testInfo.getName();
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.intellij.execution.testframework.TestConsoleProperties;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.pom.Navigatable;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.rt.execution.junit.states.PoolOfTestStates;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -128,8 +129,8 @@ public class TestProxy extends AbstractTestProxy {
|
||||
return getState().getMagnitude();
|
||||
}
|
||||
|
||||
public Location getLocation(final Project project) {
|
||||
return getInfo().getLocation(project);
|
||||
public Location getLocation(final Project project, GlobalSearchScope searchScope) {
|
||||
return getInfo().getLocation(project, searchScope);
|
||||
}
|
||||
|
||||
public boolean isLeaf() {
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.execution.Location;
|
||||
import com.intellij.execution.junit.JUnitConfiguration;
|
||||
import com.intellij.execution.junit2.segments.ObjectReader;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
|
||||
class AllInPackageInfo extends TestInfo {
|
||||
private String myName;
|
||||
@@ -36,7 +37,7 @@ class AllInPackageInfo extends TestInfo {
|
||||
return myName.length() > 0 ? myName : JUnitConfiguration.DEFAULT_PACKAGE_NAME;
|
||||
}
|
||||
|
||||
public Location getLocation(final Project project) {
|
||||
public Location getLocation(final Project project, GlobalSearchScope searchScope) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.intellij.execution.junit2.info;
|
||||
import com.intellij.execution.Location;
|
||||
import com.intellij.execution.junit2.segments.ObjectReader;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class ClassBasedInfo extends TestInfo {
|
||||
@@ -40,8 +41,8 @@ public abstract class ClassBasedInfo extends TestInfo {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Location getLocation(final Project project) {
|
||||
return myClass.getLocation(project);
|
||||
public Location getLocation(final Project project, GlobalSearchScope searchScope) {
|
||||
return myClass.getLocation(project, searchScope);
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
|
||||
@@ -41,8 +41,8 @@ public class PsiClassLocator implements PsiLocator {
|
||||
return new PsiClassLocator(name.substring(lastDot + 1), name.substring(0, lastDot));
|
||||
}
|
||||
|
||||
public Location<PsiClass> getLocation(final Project project) {
|
||||
final PsiClass psiClass = JavaExecutionUtil.findMainClass(project, getQualifiedName(), GlobalSearchScope.allScope(project));
|
||||
public Location<PsiClass> getLocation(final Project project, GlobalSearchScope searchScope) {
|
||||
final PsiClass psiClass = JavaExecutionUtil.findMainClass(project, getQualifiedName(), searchScope);
|
||||
return psiClass != null ? new PsiLocation<PsiClass>(project, psiClass) : null;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,8 @@ package com.intellij.execution.junit2.info;
|
||||
|
||||
import com.intellij.execution.Location;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
|
||||
public interface PsiLocator {
|
||||
Location getLocation(Project project);
|
||||
Location getLocation(Project project, GlobalSearchScope searchScope);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.execution.Location;
|
||||
import com.intellij.execution.junit2.segments.ObjectReader;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.MethodSignatureUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -40,8 +41,8 @@ class TestCaseInfo extends ClassBasedInfo {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Location getLocation(final Project project) {
|
||||
final Location<PsiClass> classLocation = (Location<PsiClass>)super.getLocation(project);
|
||||
public Location getLocation(final Project project, GlobalSearchScope searchScope) {
|
||||
final Location<PsiClass> classLocation = (Location<PsiClass>)super.getLocation(project, searchScope);
|
||||
if (classLocation == null) return null;
|
||||
String strippedMethodName = myMethod; //navigation to for parametr. methods
|
||||
final int idx = myMethod.indexOf('[');
|
||||
|
||||
@@ -57,7 +57,7 @@ public class JUnitToolbarPanel extends ToolbarPanel {
|
||||
if (test == null) return;
|
||||
final Project project = jUnitModel.getProject();
|
||||
if (!ScrollToTestSourceAction.isScrollEnabled(model)) return;
|
||||
final Location location = test.getInfo().getLocation(project);
|
||||
final Location location = test.getInfo().getLocation(project, jUnitModel.getProperties().getScope());
|
||||
if (location != null) {
|
||||
final PsiClass aClass = PsiTreeUtil.getParentOfType(location.getPsiElement(), PsiClass.class, false);
|
||||
if (aClass != null && JUnitToolbarPanel.TEST_SUITE_CLASS_NAME.equals(aClass.getQualifiedName())) return;
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.intellij.execution.Location;
|
||||
import com.intellij.execution.junit2.info.TestInfo;
|
||||
import com.intellij.execution.junit2.segments.ObjectReader;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
@@ -47,7 +48,7 @@ public class RootTestInfo extends TestInfo {
|
||||
public void readFrom(ObjectReader reader) {
|
||||
}
|
||||
|
||||
public Location getLocation(final Project project) {
|
||||
public Location getLocation(final Project project, GlobalSearchScope searchScope) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.pom.Navigatable;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.testng.remote.strprotocol.MessageHelper;
|
||||
@@ -156,7 +157,7 @@ public class TestProxy extends AbstractTestProxy {
|
||||
return !isNotPassed();
|
||||
}
|
||||
|
||||
public Location getLocation(final Project project) {
|
||||
public Location getLocation(final Project project, GlobalSearchScope searchScope) {
|
||||
if (psiElement == null) return null;
|
||||
final PsiElement element = psiElement.getElement();
|
||||
if (element == null) return null;
|
||||
|
||||
@@ -51,7 +51,7 @@ public class RerunFailedTestsAction extends JavaRerunFailedTestsAction {
|
||||
@Override
|
||||
protected void fillTestObjects(final Map<PsiClass, Collection<PsiMethod>> classes) throws CantRunException {
|
||||
for (AbstractTestProxy proxy : failedTests) {
|
||||
final Location location = proxy.getLocation(config.getProject());
|
||||
final Location location = proxy.getLocation(config.getProject(), config.getConfigurationModule().getSearchScope());
|
||||
if (location != null) {
|
||||
final PsiElement element = location.getPsiElement();
|
||||
if (element instanceof PsiMethod && element.isValid()) {
|
||||
|
||||
Reference in New Issue
Block a user