public void bePatternConfiguration(List<PsiClass> classes, PsiMethod method) { data.TEST_OBJECT = TestType.PATTERN.getType(); final String suffix; if (method != null) { data.METHOD_NAME = method.getName(); suffix = "," + data.METHOD_NAME; } else { suffix = ""; } LinkedHashSet<String> patterns = new LinkedHashSet<String>(); for (PsiClass pattern : classes) { patterns.add(JavaExecutionUtil.getRuntimeQualifiedName(pattern) + suffix); } data.setPatterns(patterns); final Module module = RunConfigurationProducer.getInstance(TestNGPatternConfigurationProducer.class) .findModule(this, getConfigurationModule().getModule(), patterns); if (module == null) { data.setScope(TestSearchScope.WHOLE_PROJECT); setModule(null); } else { setModule(module); } setGeneratedName(); }
@Nullable public PsiPackage getPsiElement() { final String qualifiedName = data.getPackageName(); return qualifiedName != null ? JavaPsiFacade.getInstance(getProject()).findPackage(qualifiedName) : null; }
@Nullable public PsiClass getPsiElement() { final String qualifiedName = data.getMainClassName(); return qualifiedName != null ? JavaPsiFacade.getInstance(getProject()) .findClass(qualifiedName, GlobalSearchScope.allScope(project)) : null; }
@Override protected ModuleBasedConfiguration createInstance() { try { return new TestNGConfiguration( getName(), getProject(), (TestData) data.clone(), TestNGConfigurationType.getInstance().getConfigurationFactories()[0]); } catch (CloneNotSupportedException e) { // can't happen right? e.printStackTrace(); } return null; }
@Nullable public RefactoringElementListener getRefactoringElementListener(final PsiElement element) { if (data.TEST_OBJECT.equals(TestType.PACKAGE.getType())) { if (!(element instanceof PsiPackage)) return null; final RefactoringElementListener listener = RefactoringListeners.getListener((PsiPackage) element, myPackage); return RunConfigurationExtension.wrapRefactoringElementListener(element, this, listener); } else if (data.TEST_OBJECT.equals(TestType.CLASS.getType())) { if (!(element instanceof PsiClass) && !(element instanceof PsiPackage)) return null; final RefactoringElementListener listener = RefactoringListeners.getClassOrPackageListener(element, myClass); return RunConfigurationExtension.wrapRefactoringElementListener(element, this, listener); } else if (data.TEST_OBJECT.equals(TestType.METHOD.getType())) { if (!(element instanceof PsiMethod)) { final RefactoringElementListener listener = RefactoringListeners.getClassOrPackageListener(element, myClass); return RunConfigurationExtension.wrapRefactoringElementListener(element, this, listener); } final PsiMethod method = (PsiMethod) element; if (!method.getName().equals(data.getMethodName())) return null; if (!method.getContainingClass().equals(myClass.getPsiElement())) return null; class Listener extends RefactoringElementAdapter implements UndoRefactoringElementListener { public void elementRenamedOrMoved(@NotNull final PsiElement newElement) { data.setTestMethod(PsiLocation.fromPsiElement((PsiMethod) newElement)); } @Override public void undoElementMovedOrRenamed( @NotNull PsiElement newElement, @NotNull String oldQualifiedName) { final int methodIdx = oldQualifiedName.indexOf("#") + 1; if (methodIdx <= 0 || methodIdx >= oldQualifiedName.length()) return; data.METHOD_NAME = oldQualifiedName.substring(methodIdx); } } return RunConfigurationExtension.wrapRefactoringElementListener( element, this, new Listener()); } return null; }
public void setEnvs(@NotNull Map<String, String> envs) { data.setEnvs(envs); }
public void setMethodConfiguration(Location<PsiMethod> location) { setModule(data.setTestMethod(location)); setGeneratedName(); }
@Override public Collection<Module> getValidModules() { // TODO add handling for package return JavaRunConfigurationModule.getModulesForClass(getProject(), data.getMainClassName()); }
public void setClassConfiguration(PsiClass psiclass) { setModule(data.setMainClass(psiclass)); data.TEST_OBJECT = TestType.CLASS.getType(); setGeneratedName(); }
public void setPackageConfiguration(Module module, PsiPackage pkg) { data.setPackage(pkg); setModule(module); data.TEST_OBJECT = TestType.PACKAGE.getType(); setGeneratedName(); }
public String getRunClass() { return !data.TEST_OBJECT.equals(TestType.CLASS.getType()) && !data.TEST_OBJECT.equals(TestType.METHOD.getType()) ? null : data.getMainClassName(); }
public String getPackage() { return !data.TEST_OBJECT.equals(TestType.PACKAGE.getType()) ? null : data.getPackageName(); }
public void setVMParameters(String value) { data.setVMParameters(value); }
public void setPassParentEnvs(boolean passParentEnvs) { data.PASS_PARENT_ENVS = passParentEnvs; }
public String getVMParameters() { return data.getVMParameters(); }
public String getWorkingDirectory() { return data.getWorkingDirectory(project); }
public void setWorkingDirectory(String value) { data.setWorkingDirectory(value); }
public String getProgramParameters() { return data.getProgramParameters(); }
public void setProgramParameters(String value) { data.setProgramParameters(value); }
public void setName(final String qualifiedName) { final boolean generatedName = isGeneratedName(); data.MAIN_CLASS_NAME = qualifiedName; if (generatedName) setGeneratedName(); }
@NotNull public Map<String, String> getEnvs() { return data.getEnvs(); }