Search in sources :

Example 1 with PsiMethod

use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.

the class GroovyGeneratePropertyMissingHandler method chooseOriginalMembers.

@Nullable
@Override
protected ClassMember[] chooseOriginalMembers(PsiClass aClass, Project project) {
    final PsiMethod[] missings = aClass.findMethodsByName("propertyMissing", true);
    PsiMethod getter = null;
    PsiMethod setter = null;
    for (PsiMethod missing : missings) {
        final PsiParameter[] parameters = missing.getParameterList().getParameters();
        if (parameters.length == 1) {
            if (isNameParam(parameters[0])) {
                getter = missing;
            }
        } else if (parameters.length == 2) {
            if (isNameParam(parameters[0])) {
                setter = missing;
            }
        }
    }
    if (setter != null && getter != null) {
        String text = GroovyCodeInsightBundle.message("generate.property.missing.already.defined.warning");
        if (Messages.showYesNoDialog(project, text, GroovyCodeInsightBundle.message("generate.property.missing.already.defined.title"), Messages.getQuestionIcon()) == Messages.YES) {
            final PsiMethod finalGetter = getter;
            final PsiMethod finalSetter = setter;
            if (!ApplicationManager.getApplication().runWriteAction(new Computable<Boolean>() {

                @Override
                public Boolean compute() {
                    try {
                        finalSetter.delete();
                        finalGetter.delete();
                        return Boolean.TRUE;
                    } catch (IncorrectOperationException e) {
                        LOG.error(e);
                        return Boolean.FALSE;
                    }
                }
            }).booleanValue()) {
                return null;
            }
        } else {
            return null;
        }
    }
    return new ClassMember[1];
}
Also used : PsiParameter(com.intellij.psi.PsiParameter) PsiMethod(com.intellij.psi.PsiMethod) IncorrectOperationException(com.intellij.util.IncorrectOperationException) ClassMember(com.intellij.codeInsight.generation.ClassMember) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with PsiMethod

use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.

the class ConfigurationsTest method testRenameMethod.

@Test
public void testRenameMethod() {
    final Project project = myProjectFixture.getProject();
    final PsiClass psiClass = findTestClass(project);
    final String className = psiClass.getName();
    final TestNGConfiguration configuration = createConfiguration(project);
    final PsiMethod method = findTestMethod(psiClass);
    configuration.beMethodConfiguration(new PsiLocation<>(project, method));
    final String newMethodName = "renamedTest";
    final RenameRefactoring renameMethod = RefactoringFactory.getInstance(project).createRename(method, newMethodName);
    renameMethod.setSearchInComments(false);
    renameMethod.setSearchInNonJavaFiles(false);
    new WriteCommandAction(project) {

        protected void run(@NotNull final Result result) throws Throwable {
            renameMethod.run();
        }
    }.execute();
    Assert.assertEquals(className, configuration.getPersistantData().getMainClassName());
    Assert.assertEquals(newMethodName, configuration.getPersistantData().getMethodName());
    final PsiMethod notATestMethod = findNotATestMethod(psiClass);
    final RenameRefactoring renameNotATestMethod1 = RefactoringFactory.getInstance(project).createRename(notATestMethod, "bbbbb");
    renameNotATestMethod1.setSearchInComments(false);
    renameNotATestMethod1.setSearchInNonJavaFiles(false);
    new WriteCommandAction(project) {

        protected void run(@NotNull final Result result) throws Throwable {
            renameNotATestMethod1.run();
        }
    }.execute();
    Assert.assertEquals(className, configuration.getPersistantData().getMainClassName());
    Assert.assertEquals(newMethodName, configuration.getPersistantData().getMethodName());
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) PsiMethod(com.intellij.psi.PsiMethod) RenameRefactoring(com.intellij.refactoring.RenameRefactoring) PsiClass(com.intellij.psi.PsiClass) Result(com.intellij.openapi.application.Result) Test(org.testng.annotations.Test)

Example 3 with PsiMethod

use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.

the class ConfigurationsTest method testClassRename.

@Test
public void testClassRename() {
    final Project project = myProjectFixture.getProject();
    final PsiClass psiClass = findTestClass(project);
    final TestNGConfiguration configuration = createConfiguration(project);
    configuration.beClassConfiguration(psiClass);
    final String newName = "Testt1";
    final RenameRefactoring renameClass = RefactoringFactory.getInstance(project).createRename(psiClass, newName);
    renameClass.setSearchInComments(false);
    renameClass.setSearchInNonJavaFiles(false);
    new WriteCommandAction(project) {

        protected void run(@NotNull final Result result) throws Throwable {
            renameClass.run();
        }
    }.execute();
    Assert.assertEquals(newName, configuration.getPersistantData().getMainClassName());
    final PsiMethod notATestMethod = findNotATestMethod(psiClass);
    final RenameRefactoring renameNotATestMethod = RefactoringFactory.getInstance(project).createRename(notATestMethod, "aaaa");
    renameNotATestMethod.setSearchInComments(false);
    renameNotATestMethod.setSearchInNonJavaFiles(false);
    new WriteCommandAction(project) {

        protected void run(@NotNull final Result result) throws Throwable {
            renameNotATestMethod.run();
        }
    }.execute();
    Assert.assertEquals(configuration.getPersistantData().getMainClassName(), newName);
    Assert.assertEquals(configuration.getPersistantData().getMethodName(), "");
    Assert.assertEquals(configuration.getPersistantData().TEST_OBJECT, TestType.CLASS.getType());
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) PsiMethod(com.intellij.psi.PsiMethod) RenameRefactoring(com.intellij.refactoring.RenameRefactoring) PsiClass(com.intellij.psi.PsiClass) Result(com.intellij.openapi.application.Result) Test(org.testng.annotations.Test)

Example 4 with PsiMethod

use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.

the class DetectClassesToRunTest method testRerunFailedTestWithDependency.

public void testRerunFailedTestWithDependency() throws Exception {
    final PsiClass aClass = myFixture.addClass("package a; public class ATest {" + "  @org.testng.annotations.Test()\n" + "  public void testTwo(){}\n " + "  @org.testng.annotations.Test(dependsOnMethods = \"testTwo\")\n" + //parameterized
    "  public void testOne(String s){}\n" + "}");
    final LinkedHashMap<PsiClass, Map<PsiMethod, List<String>>> classes = new LinkedHashMap<>();
    classes.put(aClass, new HashMap<>());
    final GlobalSearchScope projectScope = GlobalSearchScope.projectScope(getProject());
    final SMTestProxy testProxy = new SMTestProxy("testOne", false, "java:test://a.ATest.testOne[a]");
    testProxy.setLocator(new JavaTestLocator());
    RerunFailedTestsAction.includeFailedTestWithDependencies(classes, projectScope, getProject(), testProxy);
    assertEquals(1, classes.size());
    final Map<PsiMethod, List<String>> params = classes.get(aClass);
    assertContainsElements(params.keySet(), aClass.getMethods());
    final List<String> paramsToRerun = params.get(aClass.findMethodsByName("testOne", false)[0]);
    assertEquals(1, paramsToRerun.size());
    assertContainsElements(paramsToRerun, "a");
}
Also used : SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) LinkedHashMap(java.util.LinkedHashMap) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) List(java.util.List) JavaTestLocator(com.intellij.execution.testframework.JavaTestLocator) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 5 with PsiMethod

use of com.intellij.psi.PsiMethod in project intellij-community by JetBrains.

the class DetectClassesToRunTest method doTestMethodConfiguration.

private void doTestMethodConfiguration(PsiClass aClass, PsiClass secondaryClass, PsiMethod configMethod, PsiMethod... expectedMethods) throws CantRunException {
    final TestNGConfiguration configuration = new TestNGConfiguration("testOne", getProject(), TestNGConfigurationType.getInstance().getConfigurationFactories()[0]);
    final TestData data = configuration.getPersistantData();
    data.TEST_OBJECT = TestType.METHOD.getType();
    data.METHOD_NAME = "testOne";
    data.setScope(TestSearchScope.SINGLE_MODULE);
    configuration.setModule(data.setMainClass(aClass));
    final TestNGTestObject testObject = TestNGTestObject.fromConfig(configuration);
    assertNotNull(testObject);
    final LinkedHashMap<PsiClass, Map<PsiMethod, List<String>>> classes = new LinkedHashMap<>();
    testObject.fillTestObjects(classes);
    assertContainsElements(classes.keySet(), aClass);
    final Map<PsiMethod, List<String>> methods = classes.get(aClass);
    assertContainsElements(methods.keySet(), expectedMethods);
    if (secondaryClass != null) {
        final Map<PsiMethod, List<String>> configMethods = classes.get(secondaryClass);
        assertTrue(configMethods != null);
        assertTrue(configMethods.containsKey(configMethod));
    }
}
Also used : TestData(com.theoryinpractice.testng.model.TestData) PsiMethod(com.intellij.psi.PsiMethod) TestNGTestObject(com.theoryinpractice.testng.model.TestNGTestObject) PsiClass(com.intellij.psi.PsiClass) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

PsiMethod (com.intellij.psi.PsiMethod)298 PsiClass (com.intellij.psi.PsiClass)133 PsiElement (com.intellij.psi.PsiElement)92 NotNull (org.jetbrains.annotations.NotNull)36 ArrayList (java.util.ArrayList)30 Project (com.intellij.openapi.project.Project)25 Nullable (org.jetbrains.annotations.Nullable)24 Location (com.intellij.execution.Location)19 PsiFile (com.intellij.psi.PsiFile)19 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)17 List (java.util.List)16 Module (com.intellij.openapi.module.Module)14 PsiParameter (com.intellij.psi.PsiParameter)14 PsiReference (com.intellij.psi.PsiReference)14 Test (org.junit.Test)14 PsiAnnotation (com.intellij.psi.PsiAnnotation)13 PsiField (com.intellij.psi.PsiField)13 PsiModifierList (com.intellij.psi.PsiModifierList)11 PsiType (com.intellij.psi.PsiType)11 HashMap (java.util.HashMap)10