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