Search in sources :

Example 1 with MapDataContext

use of com.intellij.testFramework.MapDataContext in project intellij-community by JetBrains.

the class ConfigurationsTest method testCreateFromContext.

@Test
public void testCreateFromContext() {
    final Project project = myProjectFixture.getProject();
    final PsiClass psiClass = findTestClass(project);
    final TestNGInClassConfigurationProducer producer = new TestNGInClassConfigurationProducer();
    final MapDataContext dataContext = new MapDataContext();
    dataContext.put(CommonDataKeys.PROJECT, project);
    dataContext.put(LangDataKeys.MODULE, ModuleUtil.findModuleForPsiElement(psiClass));
    dataContext.put(Location.DATA_KEY, PsiLocation.fromPsiElement(psiClass));
    final ConfigurationFromContext fromContext = producer.createConfigurationFromContext(ConfigurationContext.getFromContext(dataContext));
    assert fromContext != null;
    final RunnerAndConfigurationSettings config = fromContext.getConfigurationSettings();
    final RunConfiguration runConfiguration = config.getConfiguration();
    Assert.assertTrue(runConfiguration instanceof TestNGConfiguration);
    TestNGConfigurationType t = (TestNGConfigurationType) runConfiguration.getType();
    Assert.assertTrue(t.isConfigurationByLocation(runConfiguration, new PsiLocation(project, psiClass)));
}
Also used : Project(com.intellij.openapi.project.Project) MapDataContext(com.intellij.testFramework.MapDataContext) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiClass(com.intellij.psi.PsiClass) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) PsiLocation(com.intellij.execution.PsiLocation) Test(org.testng.annotations.Test)

Example 2 with MapDataContext

use of com.intellij.testFramework.MapDataContext in project intellij-community by JetBrains.

the class MavenDomTestCase method createDataContext.

private MapDataContext createDataContext(VirtualFile f) throws IOException {
    MapDataContext context = new MapDataContext();
    context.put(CommonDataKeys.EDITOR, getEditor(f));
    context.put(CommonDataKeys.PSI_FILE, getTestPsiFile(f));
    context.put(CommonDataKeys.PSI_ELEMENT, TargetElementUtil.findTargetElement(getEditor(f), TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED | TargetElementUtil.ELEMENT_NAME_ACCEPTED));
    return context;
}
Also used : MapDataContext(com.intellij.testFramework.MapDataContext)

Example 3 with MapDataContext

use of com.intellij.testFramework.MapDataContext in project intellij-community by JetBrains.

the class MavenDomTestCase method assertCannotRename.

protected void assertCannotRename() throws Exception {
    MapDataContext context = createRenameDataContext(myProjectPom, "new name");
    RenameHandler handler = RenameHandlerRegistry.getInstance().getRenameHandler(context);
    if (handler == null)
        return;
    try {
        invokeRename(context, handler);
    } catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
        if (!e.getMessage().startsWith("Cannot perform refactoring.")) {
            throw e;
        }
    }
}
Also used : MapDataContext(com.intellij.testFramework.MapDataContext) CommonRefactoringUtil(com.intellij.refactoring.util.CommonRefactoringUtil) RenameHandler(com.intellij.refactoring.rename.RenameHandler) PsiElementRenameHandler(com.intellij.refactoring.rename.PsiElementRenameHandler)

Example 4 with MapDataContext

use of com.intellij.testFramework.MapDataContext in project intellij-community by JetBrains.

the class MavenDomTestCase method search.

protected List<PsiElement> search(VirtualFile file) throws IOException {
    final MapDataContext context = createDataContext(file);
    UsageTarget[] targets = UsageTargetUtil.findUsageTargets(new DataProvider() {

        @Override
        public Object getData(@NonNls String dataId) {
            return context.getData(dataId);
        }
    });
    PsiElement target = ((PsiElement2UsageTargetAdapter) targets[0]).getElement();
    List<PsiReference> result = new ArrayList<>(ReferencesSearch.search(target).findAll());
    return ContainerUtil.map(result, psiReference -> psiReference.getElement());
}
Also used : DataProvider(com.intellij.openapi.actionSystem.DataProvider) MapDataContext(com.intellij.testFramework.MapDataContext) ArrayList(java.util.ArrayList) PsiElement2UsageTargetAdapter(com.intellij.find.findUsages.PsiElement2UsageTargetAdapter) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) UsageTarget(com.intellij.usages.UsageTarget)

Example 5 with MapDataContext

use of com.intellij.testFramework.MapDataContext in project intellij-community by JetBrains.

the class MavenDomTestCase method createRenameDataContext.

private MapDataContext createRenameDataContext(VirtualFile f, String value) throws IOException {
    MapDataContext context = createDataContext(f);
    context.put(PsiElementRenameHandler.DEFAULT_NAME, value);
    return context;
}
Also used : MapDataContext(com.intellij.testFramework.MapDataContext)

Aggregations

MapDataContext (com.intellij.testFramework.MapDataContext)25 PsiClass (com.intellij.psi.PsiClass)8 Module (com.intellij.openapi.module.Module)6 RenameHandler (com.intellij.refactoring.rename.RenameHandler)4 PsiPackage (com.intellij.psi.PsiPackage)3 PsiElementRenameHandler (com.intellij.refactoring.rename.PsiElementRenameHandler)3 NotNull (org.jetbrains.annotations.NotNull)3 JavaFxPropertyRenameHandler (org.jetbrains.plugins.javaFX.refactoring.JavaFxPropertyRenameHandler)3 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)2 ApplicationConfiguration (com.intellij.execution.application.ApplicationConfiguration)2 TestActionEvent (com.intellij.testFramework.TestActionEvent)2 JavaOverrideMethodsHandler (com.intellij.codeInsight.generation.JavaOverrideMethodsHandler)1 PsiLocation (com.intellij.execution.PsiLocation)1 ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)1 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)1 JUnitConfiguration (com.intellij.execution.junit.JUnitConfiguration)1 PsiElement2UsageTargetAdapter (com.intellij.find.findUsages.PsiElement2UsageTargetAdapter)1 DataProvider (com.intellij.openapi.actionSystem.DataProvider)1 Editor (com.intellij.openapi.editor.Editor)1 Project (com.intellij.openapi.project.Project)1