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];
}
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());
}
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());
}
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");
}
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));
}
}
Aggregations