diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/GdslFileType.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/GdslFileType.kt new file mode 100644 index 000000000000..9b03171851d9 --- /dev/null +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/GdslFileType.kt @@ -0,0 +1,17 @@ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package org.jetbrains.plugins.groovy + +import com.intellij.openapi.fileTypes.LanguageFileType +import javax.swing.Icon + +object GdslFileType : LanguageFileType(GroovyLanguage, true) { + + init { + GroovyFileType.GROOVY_FILE_TYPES.add(this) + } + + override fun getIcon(): Icon? = GroovyFileType.GROOVY_FILE_TYPE.icon + override fun getName(): String = "gdsl" + override fun getDescription(): String = "IntelliJ Groovy DSL configuration" + override fun getDefaultExtension(): String = "gdsl" +} diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dsl/GdslUtil.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dsl/GdslUtil.java index 4ff349637f9f..84a70a657dd4 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dsl/GdslUtil.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dsl/GdslUtil.java @@ -1,30 +1,16 @@ -/* - * Copyright 2000-2014 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.plugins.groovy.dsl; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Key; -import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.plugins.groovy.GdslFileType; public class GdslUtil { public static final Key INITIAL_CONTEXT = Key.create("gdsl.initialContext"); - public static final Condition GDSL_FILTER = - file -> file != null && !file.isDirectory() && StringUtil.endsWith(file.getNameSequence(), ".gdsl"); + public static final Condition GDSL_FILTER = file -> file.getFileType() == GdslFileType.INSTANCE; + static volatile boolean ourGdslStopped = false; static void stopGdsl() { diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java index f542db993791..6ac5e5e37c75 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java @@ -20,6 +20,7 @@ import com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent; import com.intellij.openapi.vfs.newvfs.events.VFileEvent; import com.intellij.psi.*; import com.intellij.psi.impl.PsiManagerEx; +import com.intellij.psi.search.FileTypeIndex; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.util.CachedValue; import com.intellij.psi.util.CachedValueProvider; @@ -31,14 +32,10 @@ import com.intellij.util.concurrency.AppExecutorUtil; import com.intellij.util.containers.ConcurrentMultiMap; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.MultiMap; -import com.intellij.util.indexing.*; -import com.intellij.util.io.EnumeratorStringDescriptor; -import com.intellij.util.io.KeyDescriptor; import com.intellij.util.io.URLUtil; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.plugins.groovy.GroovyFileType; +import org.jetbrains.plugins.groovy.GdslFileType; import org.jetbrains.plugins.groovy.dsl.DslActivationStatus.Status; import org.jetbrains.plugins.groovy.dsl.holders.CustomMembersHolder; import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; @@ -56,53 +53,17 @@ import java.util.regex.Pattern; /** * @author peter */ -public final class GroovyDslFileIndex extends ScalarIndexExtension { +public class GroovyDslFileIndex { private static final Key> CACHED_EXECUTOR = Key.create("CachedGdslExecutor"); private static final Key>> SCRIPTS_CACHE = Key.create("GdslScriptCache"); private static final Logger LOG = Logger.getInstance(GroovyDslFileIndex.class); - private static final @NonNls String OUR_KEY = "ourKey"; - public static final @NonNls ID NAME = ID.create("GroovyDslFileIndex"); private static final MultiMap>> filesInProcessing = new ConcurrentMultiMap<>(); private static final ExecutorService ourPool = AppExecutorUtil.createBoundedApplicationPoolExecutor("GroovyDSLIndex Pool", 4); - private final MyDataIndexer myDataIndexer = new MyDataIndexer(); - - @Override - @NotNull - public ID getName() { - return NAME; - } - - @Override - @NotNull - public DataIndexer getIndexer() { - return myDataIndexer; - } - - @NotNull - @Override - public KeyDescriptor getKeyDescriptor() { - return EnumeratorStringDescriptor.INSTANCE; - } - - @NotNull - @Override - public FileBasedIndex.InputFilter getInputFilter() { - return new MyInputFilter(); - } - - @Override - public boolean dependsOnFileContent() { - return false; - } - - @Override - public int getVersion() { - return 0; - } + private GroovyDslFileIndex() {} @Nullable public static String getError(VirtualFile file) { @@ -288,14 +249,10 @@ public final class GroovyDslFileIndex extends ScalarIndexExtension { final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex(); final GlobalSearchScope scope = GlobalSearchScope.allScope(project); - for (VirtualFile vfile : FileBasedIndex.getInstance().getContainingFiles(NAME, OUR_KEY, scope)) { + for (VirtualFile vfile : FileTypeIndex.getFiles(GdslFileType.INSTANCE, scope)) { if (!vfile.isValid()) { continue; } - if (!GdslUtil.GDSL_FILTER.value(vfile)) { - LOG.error("Index returned non-gdsl file: " + vfile); - continue; - } if (fileIndex.isInLibrarySource(vfile)) { continue; } @@ -380,26 +337,6 @@ public final class GroovyDslFileIndex extends ScalarIndexExtension { }, false); } - private static class MyDataIndexer implements DataIndexer { - - @Override - @NotNull - public Map map(@NotNull final FileContent inputData) { - return Collections.singletonMap(OUR_KEY, null); - } - } - - private static class MyInputFilter extends DefaultFileTypeSpecificInputFilter { - MyInputFilter() { - super(GroovyFileType.GROOVY_FILE_TYPE); - } - - @Override - public boolean acceptInput(@NotNull final VirtualFile file) { - return GdslUtil.GDSL_FILTER.value(file); - } - } - private static void scheduleParsing(final LinkedBlockingQueue> queue, final Project project, final VirtualFile vfile, diff --git a/plugins/groovy/src/META-INF/plugin.xml b/plugins/groovy/src/META-INF/plugin.xml index f554717469e6..8adbf91eecdd 100644 --- a/plugins/groovy/src/META-INF/plugin.xml +++ b/plugins/groovy/src/META-INF/plugin.xml @@ -298,8 +298,10 @@ - + @@ -681,7 +683,6 @@ - diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/NewScriptAction.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/NewScriptAction.java index a6b6cb9d5a16..0777fc1bd15b 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/NewScriptAction.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/NewScriptAction.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.plugins.groovy.actions; @@ -28,6 +14,7 @@ import com.intellij.psi.PsiFile; import com.intellij.util.IncorrectOperationException; import icons.JetgroovyIcons; import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.groovy.GdslFileType; import org.jetbrains.plugins.groovy.GroovyBundle; import org.jetbrains.plugins.groovy.GroovyFileType; import org.jetbrains.plugins.groovy.lang.psi.GroovyFile; @@ -75,7 +62,7 @@ public class NewScriptAction extends JavaCreateTemplateInPackageAction