Drop JetFilesProvider service
This commit is contained in:
@@ -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<JetFile> allInScope(@NotNull GlobalSearchScope scope) {
|
||||
List<JetFile> answer = new ArrayList<JetFile>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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<JetFile> allInScope(@NotNull GlobalSearchScope scope);
|
||||
public abstract boolean isFileInScope(@NotNull JetFile file, @NotNull GlobalSearchScope scope);
|
||||
}
|
||||
@@ -119,9 +119,6 @@
|
||||
<applicationService serviceInterface="org.jetbrains.jet.lang.resolve.kotlin.KotlinBinaryClassCache"
|
||||
serviceImplementation="org.jetbrains.jet.lang.resolve.kotlin.KotlinBinaryClassCache"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.jet.lang.resolve.java.JetFilesProvider"
|
||||
serviceImplementation="org.jetbrains.jet.plugin.project.PluginJetFilesProvider"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.jet.plugin.caches.resolve.KotlinCacheService"
|
||||
serviceImplementation="org.jetbrains.jet.plugin.caches.resolve.KotlinCacheService"/>
|
||||
|
||||
|
||||
@@ -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<Collection<JetFile>, GlobalSearchScope> cache;
|
||||
|
||||
public PluginJetFilesProvider(Project project) {
|
||||
this.project = project;
|
||||
this.cache = CachedValuesManager.getManager(project).createParameterizedCachedValue(
|
||||
new ParameterizedCachedValueProvider<Collection<JetFile>, GlobalSearchScope>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public CachedValueProvider.Result<Collection<JetFile>> compute(GlobalSearchScope param) {
|
||||
return new CachedValueProvider.Result<Collection<JetFile>>(
|
||||
computeAllInScope(param),
|
||||
PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT
|
||||
);
|
||||
}
|
||||
},
|
||||
false
|
||||
);
|
||||
}
|
||||
public class PluginJetFilesProvider {
|
||||
|
||||
public static Collection<JetFile> 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<JetFile> allInScope(@NotNull GlobalSearchScope scope) {
|
||||
return cache.getValue(scope);
|
||||
}
|
||||
|
||||
private Collection<JetFile> computeAllInScope(GlobalSearchScope scope) {
|
||||
final PsiManager manager = PsiManager.getInstance(project);
|
||||
|
||||
Collection<JetFile> jetFiles = ContainerUtil.map(
|
||||
FileTypeIndex.getFiles(JetFileType.INSTANCE, scope),
|
||||
new Function<VirtualFile, JetFile>() {
|
||||
@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.<JetFile>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() {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user