Search in sources :

Example 1 with ApplicationConfigurationProducer

use of com.intellij.execution.application.ApplicationConfigurationProducer in project intellij-community by JetBrains.

the class GroovyScriptRunConfigurationProducer method createConfigurationByElement.

@Override
protected RunnerAndConfigurationSettings createConfigurationByElement(final Location location, final ConfigurationContext context) {
    final PsiElement element = location.getPsiElement();
    final PsiFile file = element.getContainingFile();
    if (!(file instanceof GroovyFile)) {
        return null;
    }
    GroovyFile groovyFile = (GroovyFile) file;
    final PsiClass aClass = GroovyRunnerPsiUtil.getRunningClass(location.getPsiElement());
    if (aClass instanceof GroovyScriptClass || GroovyRunnerPsiUtil.isRunnable(aClass)) {
        final RunnerAndConfigurationSettings settings = createConfiguration(aClass);
        if (settings != null) {
            mySourceElement = element;
            final GroovyScriptRunConfiguration configuration = (GroovyScriptRunConfiguration) settings.getConfiguration();
            GroovyScriptUtil.getScriptType(groovyFile).tuneConfiguration(groovyFile, configuration, location);
            return settings;
        }
    }
    if (file.getText().contains("@Grab")) {
        ApplicationConfigurationProducer producer = new ApplicationConfigurationProducer();
        ConfigurationFromContext settings = producer.createConfigurationFromContext(context);
        if (settings != null) {
            PsiElement src = settings.getSourceElement();
            mySourceElement = src;
            return createConfiguration(src instanceof PsiMethod ? ((PsiMethod) src).getContainingClass() : (PsiClass) src);
        }
        return null;
    } else {
        return null;
    }
}
Also used : GroovyScriptClass(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass) ApplicationConfigurationProducer(com.intellij.execution.application.ApplicationConfigurationProducer) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile)

Aggregations

RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)1 ApplicationConfigurationProducer (com.intellij.execution.application.ApplicationConfigurationProducer)1 GroovyFile (org.jetbrains.plugins.groovy.lang.psi.GroovyFile)1 GroovyScriptClass (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass)1