use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.
the class GroovyRunnerUtil method getConfigurationName.
public static String getConfigurationName(PsiClass aClass, RunConfigurationModule module) {
String qualifiedName = aClass.getQualifiedName();
Project project = module.getProject();
if (qualifiedName == null) {
return module.getModuleName();
}
PsiClass psiClass = JavaPsiFacade.getInstance(project).findClass(qualifiedName.replace('$', '.'), GlobalSearchScope.projectScope(project));
if (psiClass != null) {
return psiClass.getName();
} else {
int lastDot = qualifiedName.lastIndexOf('.');
if (lastDot == -1 || lastDot == qualifiedName.length() - 1) {
return qualifiedName;
}
return qualifiedName.substring(lastDot + 1, qualifiedName.length());
}
}
use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.
the class GroovyScriptRunConfiguration method checkConfiguration.
@Override
public void checkConfiguration() throws RuntimeConfigurationException {
super.checkConfiguration();
final String scriptPath = getScriptPath();
final VirtualFile script = ScriptFileUtil.findScriptFileByPath(scriptPath);
if (script == null)
throw new RuntimeConfigurationException("Cannot find script " + scriptPath);
final GroovyScriptRunner scriptRunner = getScriptRunner();
if (scriptRunner == null)
throw new RuntimeConfigurationException("Unknown script type " + scriptPath);
scriptRunner.ensureRunnerConfigured(this);
final PsiFile file = PsiManager.getInstance(getProject()).findFile(script);
final PsiClass toRun = GroovyRunnerPsiUtil.getRunningClass(file);
if (toRun == null) {
throw new RuntimeConfigurationWarning(GroovyBundle.message("class.does.not.exist"));
}
if (toRun instanceof GrTypeDefinition) {
if (!GroovyRunnerPsiUtil.canBeRunByGroovy(toRun)) {
throw new RuntimeConfigurationWarning(GroovyBundle.message("class.cannot.be.executed"));
}
} else {
throw new RuntimeConfigurationWarning(GroovyBundle.message("script.file.is.not.groovy.file"));
}
JavaParametersUtil.checkAlternativeJRE(this);
}
use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.
the class GroovyScriptRunConfiguration method getRefactoringElementListener.
@Override
public RefactoringElementListener getRefactoringElementListener(PsiElement element) {
if (scriptPath == null || !scriptPath.equals(getPathByElement(element))) {
return null;
}
final PsiClass classToRun = GroovyRunnerPsiUtil.getRunningClass(element);
if (element instanceof GroovyFile) {
return new RefactoringElementAdapter() {
@Override
protected void elementRenamedOrMoved(@NotNull PsiElement newElement) {
if (newElement instanceof GroovyFile) {
GroovyFile file = (GroovyFile) newElement;
setScriptPath(ScriptFileUtil.getScriptFilePath(file.getVirtualFile()));
}
}
@Override
public void undoElementMovedOrRenamed(@NotNull PsiElement newElement, @NotNull String oldQualifiedName) {
elementRenamedOrMoved(newElement);
}
};
} else if (element instanceof PsiClass && element.getManager().areElementsEquivalent(element, classToRun)) {
return new RefactoringElementAdapter() {
@Override
protected void elementRenamedOrMoved(@NotNull PsiElement newElement) {
setName(((PsiClass) newElement).getName());
}
@Override
public void undoElementMovedOrRenamed(@NotNull PsiElement newElement, @NotNull String oldQualifiedName) {
elementRenamedOrMoved(newElement);
}
};
}
return null;
}
use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.
the class RenameGroovyScriptProcessor method findExistingNameConflicts.
@Override
public void findExistingNameConflicts(PsiElement element, String newName, MultiMap<PsiElement, String> conflicts) {
final String scriptName = FileUtil.getNameWithoutExtension(newName);
if (!StringUtil.isJavaIdentifier(scriptName)) {
final PsiClass script = ((GroovyFile) element).getScriptClass();
conflicts.putValue(script, GroovyRefactoringBundle.message("cannot.rename.script.class.to.0", script.getName(), scriptName));
}
}
use of com.intellij.psi.PsiClass in project intellij-community by JetBrains.
the class JUnit4IntegrationTest method ignoredTestMethod.
@Test
public void ignoredTestMethod() throws Throwable {
EdtTestUtil.runInEdtAndWait(() -> {
PsiClass psiClass = findClass(getModule1(), CLASS_NAME);
assertNotNull(psiClass);
PsiMethod testMethod = psiClass.findMethodsByName(METHOD_NAME, false)[0];
JUnitConfiguration configuration = createConfiguration(testMethod);
Executor executor = DefaultRunExecutor.getRunExecutorInstance();
RunnerAndConfigurationSettingsImpl settings = new RunnerAndConfigurationSettingsImpl(RunManagerImpl.getInstanceImpl(getProject()), configuration, false);
ExecutionEnvironment environment = new ExecutionEnvironment(executor, ProgramRunnerUtil.getRunner(DefaultRunExecutor.EXECUTOR_ID, settings), settings, getProject());
TestObject state = configuration.getState(executor, environment);
JavaParameters parameters = state.getJavaParameters();
parameters.setUseDynamicClasspath(getProject());
GeneralCommandLine commandLine = parameters.toCommandLine();
StringBuffer buf = new StringBuffer();
StringBuffer err = new StringBuffer();
OSProcessHandler process = new OSProcessHandler(commandLine);
process.addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
String text = event.getText();
try {
if (outputType == ProcessOutputTypes.STDOUT && !text.isEmpty() && ServiceMessage.parse(text.trim()) == null) {
buf.append(text);
}
if (outputType == ProcessOutputTypes.STDERR) {
err.append(text);
}
} catch (ParseException e) {
e.printStackTrace();
}
}
});
process.startNotify();
process.waitFor();
process.destroyProcess();
String testOutput = buf.toString();
assertEmpty(err.toString());
switch(myJUnitVersion) {
//shouldn't work for old versions
case "4.4":
//shouldn't work for old versions
case "4.5":
break;
default:
assertTrue(testOutput, testOutput.contains("Test1"));
}
});
}
Aggregations