From 0f5de48157d5a4f928e3bdb590420a14f4c8b25b Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Tue, 24 Jun 2014 20:09:52 +0400 Subject: [PATCH] Drop JetFilesProvider service --- .../cli/jvm/compiler/CliJetFilesProvider.java | 50 ------------- .../cli/jvm/compiler/JetCoreEnvironment.java | 2 - .../lang/resolve/java/JetFilesProvider.java | 36 --------- idea/src/META-INF/plugin.xml | 3 - .../project/PluginJetFilesProvider.java | 75 +------------------ 5 files changed, 2 insertions(+), 164 deletions(-) delete mode 100644 compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CliJetFilesProvider.java delete mode 100644 compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JetFilesProvider.java diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CliJetFilesProvider.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CliJetFilesProvider.java deleted file mode 100644 index ea7aa5911c5..00000000000 --- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CliJetFilesProvider.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2010-2013 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. - */ - -package org.jetbrains.jet.cli.jvm.compiler; - -import com.intellij.psi.search.GlobalSearchScope; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.psi.JetFile; -import org.jetbrains.jet.lang.resolve.java.JetFilesProvider; - -import java.util.ArrayList; -import java.util.List; - -public class CliJetFilesProvider extends JetFilesProvider { - private final JetCoreEnvironment environment; - - public CliJetFilesProvider(JetCoreEnvironment environment) { - this.environment = environment; - } - - @NotNull - @Override - public List allInScope(@NotNull GlobalSearchScope scope) { - List answer = new ArrayList(); - for (JetFile file : environment.getSourceFiles()) { - if (scope.contains(file.getVirtualFile())) { - answer.add(file); - } - } - return answer; - } - - @Override - public boolean isFileInScope(@NotNull JetFile file, @NotNull GlobalSearchScope scope) { - return scope.contains(file.getVirtualFile()) && environment.getSourceFiles().contains(file); - } -} diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/JetCoreEnvironment.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/JetCoreEnvironment.java index ee1a4dad786..3ea8a8f90b2 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/JetCoreEnvironment.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/JetCoreEnvironment.java @@ -55,7 +55,6 @@ import org.jetbrains.jet.config.CompilerConfiguration; import org.jetbrains.jet.lang.parsing.JetParserDefinition; import org.jetbrains.jet.lang.parsing.JetScriptDefinitionProvider; import org.jetbrains.jet.lang.psi.JetFile; -import org.jetbrains.jet.lang.resolve.java.JetFilesProvider; import org.jetbrains.jet.lang.resolve.kotlin.KotlinBinaryClassCache; import org.jetbrains.jet.lang.resolve.kotlin.VirtualFileFinder; import org.jetbrains.jet.lang.resolve.lazy.declarations.CliDeclarationProviderFactoryService; @@ -176,7 +175,6 @@ public class JetCoreEnvironment { MockProject project = projectEnvironment.getProject(); project.registerService(JetScriptDefinitionProvider.class, new JetScriptDefinitionProvider()); - project.registerService(JetFilesProvider.class, new CliJetFilesProvider(this)); project.registerService(CoreJavaFileManager.class, (CoreJavaFileManager) ServiceManager.getService(project, JavaFileManager.class)); CliLightClassGenerationSupport cliLightClassGenerationSupport = new CliLightClassGenerationSupport(); diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JetFilesProvider.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JetFilesProvider.java deleted file mode 100644 index 2b2b2c1deaa..00000000000 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JetFilesProvider.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2010-2013 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. - */ - -package org.jetbrains.jet.lang.resolve.java; - -import com.intellij.openapi.components.ServiceManager; -import com.intellij.openapi.project.Project; -import com.intellij.psi.search.GlobalSearchScope; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.psi.JetFile; - -import java.util.Collection; - -public abstract class JetFilesProvider { - @NotNull - public static JetFilesProvider getInstance(Project project) { - return ServiceManager.getService(project, JetFilesProvider.class); - } - - @NotNull - public abstract Collection allInScope(@NotNull GlobalSearchScope scope); - public abstract boolean isFileInScope(@NotNull JetFile file, @NotNull GlobalSearchScope scope); -} diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 7a17c7e23b3..8d90433b36f 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -119,9 +119,6 @@ - - diff --git a/idea/src/org/jetbrains/jet/plugin/project/PluginJetFilesProvider.java b/idea/src/org/jetbrains/jet/plugin/project/PluginJetFilesProvider.java index 0462b92a728..5a7b1bb4d20 100644 --- a/idea/src/org/jetbrains/jet/plugin/project/PluginJetFilesProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/project/PluginJetFilesProvider.java @@ -16,8 +16,6 @@ package org.jetbrains.jet.plugin.project; -import com.google.common.base.Predicates; -import com.google.common.collect.Collections2; import com.google.common.collect.Sets; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.FileTypeManager; @@ -27,48 +25,19 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ContentIterator; import com.intellij.openapi.roots.ModuleFileIndex; import com.intellij.openapi.roots.ModuleRootManager; -import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; -import com.intellij.psi.search.FileTypeIndex; -import com.intellij.psi.search.GlobalSearchScope; -import com.intellij.psi.util.*; -import com.intellij.util.Function; -import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.psi.JetFile; -import org.jetbrains.jet.lang.resolve.java.JetFilesProvider; import org.jetbrains.jet.plugin.JetFileType; import org.jetbrains.jet.plugin.JetPluginUtil; import java.util.Collection; -import java.util.Collections; import java.util.HashSet; import java.util.Set; -public class PluginJetFilesProvider extends JetFilesProvider { - private final Project project; - - private final ParameterizedCachedValue, GlobalSearchScope> cache; - - public PluginJetFilesProvider(Project project) { - this.project = project; - this.cache = CachedValuesManager.getManager(project).createParameterizedCachedValue( - new ParameterizedCachedValueProvider, GlobalSearchScope>() { - @Nullable - @Override - public CachedValueProvider.Result> compute(GlobalSearchScope param) { - return new CachedValueProvider.Result>( - computeAllInScope(param), - PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT - ); - } - }, - false - ); - } +public class PluginJetFilesProvider { public static Collection allFilesInProject(@NotNull final JetFile rootFile) { final Project project = rootFile.getProject(); @@ -106,46 +75,6 @@ public class PluginJetFilesProvider extends JetFilesProvider { return files; } - private boolean isKotlinSourceVirtualFile(@NotNull VirtualFile virtualFile) { - return ProjectFileIndex.SERVICE.getInstance(project).isInSourceContent(virtualFile) && - !JetPluginUtil.isKtFileInGradleProjectInWrongFolder(virtualFile, project); - } - - @NotNull - @Override - public Collection allInScope(@NotNull GlobalSearchScope scope) { - return cache.getValue(scope); - } - - private Collection computeAllInScope(GlobalSearchScope scope) { - final PsiManager manager = PsiManager.getInstance(project); - - Collection jetFiles = ContainerUtil.map( - FileTypeIndex.getFiles(JetFileType.INSTANCE, scope), - new Function() { - @Override - public JetFile fun(@Nullable VirtualFile file) { - if (file == null || !isKotlinSourceVirtualFile(file)) { - return null; - } - - PsiFile psiFile = manager.findFile(file); - if (!(psiFile instanceof JetFile)) { - return null; - } - - return ((JetFile) psiFile); - } - }); - - return Collections.unmodifiableCollection( - Sets.newHashSet(Collections2.filter(jetFiles, Predicates.notNull())) - ); - } - - @Override - public boolean isFileInScope(@NotNull JetFile file, @NotNull GlobalSearchScope scope) { - VirtualFile virtualFile = file.getVirtualFile(); - return virtualFile != null && scope.contains(virtualFile) && isKotlinSourceVirtualFile(virtualFile); + private PluginJetFilesProvider() { } }