Search in sources :

Example 76 with GroovyFile

use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.

the class GroovyScriptRunConfigurationProducer method findExistingByElement.

@Override
protected RunnerAndConfigurationSettings findExistingByElement(Location location, @NotNull List<RunnerAndConfigurationSettings> existingConfigurations, ConfigurationContext context) {
    for (RunnerAndConfigurationSettings existingConfiguration : existingConfigurations) {
        final RunConfiguration configuration = existingConfiguration.getConfiguration();
        final GroovyScriptRunConfiguration existing = (GroovyScriptRunConfiguration) configuration;
        final String path = existing.getScriptPath();
        if (path != null) {
            final PsiFile file = location.getPsiElement().getContainingFile();
            if (file instanceof GroovyFile) {
                final VirtualFile vfile = file.getVirtualFile();
                if (vfile != null && FileUtil.toSystemIndependentName(path).equals(ScriptFileUtil.getScriptFilePath(vfile))) {
                    if (!((GroovyFile) file).isScript() || GroovyScriptUtil.getScriptType((GroovyFile) file).isConfigurationByLocation(existing, location)) {
                        return existingConfiguration;
                    }
                }
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile)

Example 77 with GroovyFile

use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.

the class GroovyMoveClassToInnerHandler method removeRedundantImports.

@Override
public void removeRedundantImports(PsiFile targetClassFile) {
    if (targetClassFile instanceof GroovyFile) {
        GroovyFile file = (GroovyFile) targetClassFile;
        final Set<GrImportStatement> usedImports = GroovyImportUtil.findUsedImports(file);
        final List<GrImportStatement> validImports = org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.getValidImportStatements(file);
        for (GrImportStatement importStatement : validImports) {
            if (!usedImports.contains(importStatement)) {
                file.removeImport(importStatement);
            }
        }
    }
}
Also used : GrImportStatement(org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile)

Example 78 with GroovyFile

use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.

the class GroovyScriptRunConfiguration method getScriptRunner.

@Nullable
private GroovyScriptRunner getScriptRunner() {
    final VirtualFile scriptFile = ScriptFileUtil.findScriptFileByPath(getScriptPath());
    if (scriptFile == null)
        return null;
    final PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(scriptFile);
    if (!(psiFile instanceof GroovyFile))
        return null;
    final GroovyFile groovyFile = (GroovyFile) psiFile;
    if (groovyFile.isScript()) {
        return GroovyScriptUtil.getScriptType(groovyFile).getRunner();
    } else {
        return new DefaultGroovyScriptRunner();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) Nullable(org.jetbrains.annotations.Nullable)

Example 79 with GroovyFile

use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.

the class GroovyDslAnnotator method annotate.

@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder holder) {
    if (!(psiElement instanceof GroovyFile))
        return;
    final GroovyFile groovyFile = (GroovyFile) psiElement;
    if (!GrFileIndexUtil.isGroovySourceFile(groovyFile))
        return;
    final VirtualFile vfile = groovyFile.getVirtualFile();
    if (!GdslUtil.GDSL_FILTER.value(vfile))
        return;
    final DslActivationStatus.Status status = GroovyDslFileIndex.getStatus(vfile);
    if (status == ACTIVE)
        return;
    final String message = status == MODIFIED ? "DSL descriptor file has been changed and isn't currently executed." : "DSL descriptor file has been disabled due to a processing error.";
    final Annotation annotation = holder.createWarningAnnotation(psiElement, message);
    annotation.setFileLevelAnnotation(true);
    if (status == ERROR) {
        final String error = GroovyDslFileIndex.getError(vfile);
        if (error != null) {
            annotation.registerFix(GroovyQuickFixFactory.getInstance().createInvestigateFix(error));
        }
    }
    annotation.registerFix(new ActivateFix(vfile));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Status(org.jetbrains.plugins.groovy.dsl.DslActivationStatus.Status) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) Annotation(com.intellij.lang.annotation.Annotation)

Example 80 with GroovyFile

use of org.jetbrains.plugins.groovy.lang.psi.GroovyFile in project intellij-community by JetBrains.

the class GroovyImportHelper method getImplicitlyImportedPackages.

public static LinkedHashSet<String> getImplicitlyImportedPackages(@NotNull GroovyFile file) {
    final LinkedHashSet<String> result = new LinkedHashSet<>();
    ContainerUtil.addAll(result, GroovyFileBase.IMPLICITLY_IMPORTED_PACKAGES);
    for (GrImportContributor contributor : GrImportContributor.EP_NAME.getExtensions()) {
        result.addAll(ContainerUtil.mapNotNull(contributor.getImports(file), i -> i.getType() == ImportType.STAR ? i.getName() : null));
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PsiScopeProcessor(com.intellij.psi.scope.PsiScopeProcessor) GrImportStatement(org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement) ResolveState(com.intellij.psi.ResolveState) ContainerUtil(com.intellij.util.containers.ContainerUtil) GroovyFileBase(org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase) GrImportContributor(org.jetbrains.plugins.groovy.lang.resolve.GrImportContributor) Nullable(org.jetbrains.annotations.Nullable) PsiClass(com.intellij.psi.PsiClass) PsiElement(com.intellij.psi.PsiElement) ImportType(org.jetbrains.plugins.groovy.lang.resolve.ImportType) NotNull(org.jetbrains.annotations.NotNull) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) LinkedHashSet(java.util.LinkedHashSet) GrImportContributor(org.jetbrains.plugins.groovy.lang.resolve.GrImportContributor)

Aggregations

GroovyFile (org.jetbrains.plugins.groovy.lang.psi.GroovyFile)91 PsiFile (com.intellij.psi.PsiFile)26 PsiElement (com.intellij.psi.PsiElement)21 NotNull (org.jetbrains.annotations.NotNull)17 GrImportStatement (org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement)17 VirtualFile (com.intellij.openapi.vfs.VirtualFile)13 Project (com.intellij.openapi.project.Project)10 GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)10 PsiClass (com.intellij.psi.PsiClass)9 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)9 Nullable (org.jetbrains.annotations.Nullable)8 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)8 GroovyScriptClass (org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass)8 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)7 Module (com.intellij.openapi.module.Module)6 IncorrectOperationException (com.intellij.util.IncorrectOperationException)6 GrReferenceElement (org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement)6 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)6 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)6 ASTNode (com.intellij.lang.ASTNode)5