Function object replaced by a normal function

+ unneededly public member made protected
This commit is contained in:
Andrey Breslav
2014-04-08 18:30:18 +04:00
parent ebd44816d0
commit e4e60bc377
6 changed files with 37 additions and 50 deletions
@@ -17,7 +17,6 @@
package org.jetbrains.jet.cli.jvm.compiler; package org.jetbrains.jet.cli.jvm.compiler;
import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.Function;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.java.JetFilesProvider; import org.jetbrains.jet.lang.resolve.java.JetFilesProvider;
@@ -28,21 +27,14 @@ import java.util.List;
public class CliJetFilesProvider extends JetFilesProvider { public class CliJetFilesProvider extends JetFilesProvider {
private final JetCoreEnvironment environment; private final JetCoreEnvironment environment;
private final Function<JetFile,Collection<JetFile>> allFiles = new Function<JetFile, Collection<JetFile>>() {
@Override
public Collection<JetFile> fun(JetFile file) {
return environment.getSourceFiles();
}
};
public CliJetFilesProvider(JetCoreEnvironment environment) { public CliJetFilesProvider(JetCoreEnvironment environment) {
this.environment = environment; this.environment = environment;
} }
@Override @Override
public Function<JetFile, Collection<JetFile>> sampleToAllFilesInModule() { protected Collection<JetFile> sampleToAllFilesInModule(@NotNull JetFile file) {
return allFiles; return environment.getSourceFiles();
} }
@NotNull @NotNull
@@ -22,7 +22,6 @@ import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFile;
import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.Function;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.name.FqName;
@@ -36,7 +35,7 @@ public abstract class JetFilesProvider {
public final Collection<JetFile> allPackageFiles(@NotNull JetFile file) { public final Collection<JetFile> allPackageFiles(@NotNull JetFile file) {
final FqName name = file.getPackageFqName(); final FqName name = file.getPackageFqName();
return Collections2.filter(sampleToAllFilesInModule().fun(file), new Predicate<PsiFile>() { return Collections2.filter(sampleToAllFilesInModule(file), new Predicate<PsiFile>() {
@Override @Override
public boolean apply(PsiFile psiFile) { public boolean apply(PsiFile psiFile) {
return ((JetFile) psiFile).getPackageFqName().equals(name); return ((JetFile) psiFile).getPackageFqName().equals(name);
@@ -44,7 +43,7 @@ public abstract class JetFilesProvider {
}); });
} }
public abstract Function<JetFile, Collection<JetFile>> sampleToAllFilesInModule(); protected abstract Collection<JetFile> sampleToAllFilesInModule(@NotNull JetFile file);
@NotNull @NotNull
public abstract Collection<JetFile> allInScope(@NotNull GlobalSearchScope scope); public abstract Collection<JetFile> allInScope(@NotNull GlobalSearchScope scope);
public abstract boolean isFileInScope(@NotNull JetFile file, @NotNull GlobalSearchScope scope); public abstract boolean isFileInScope(@NotNull JetFile file, @NotNull GlobalSearchScope scope);
@@ -67,10 +67,7 @@ public class PluginJetFilesProvider extends JetFilesProvider {
); );
} }
public static final Function<JetFile, Collection<JetFile>> WHOLE_PROJECT_DECLARATION_PROVIDER = new Function<JetFile, Collection<JetFile>>() { public static Collection<JetFile> allFilesInProject(@NotNull final JetFile rootFile) {
@Override
public Collection<JetFile> fun(final JetFile rootFile) {
final Project project = rootFile.getProject(); final Project project = rootFile.getProject();
final Set<JetFile> files = Sets.newLinkedHashSet(); final Set<JetFile> files = Sets.newLinkedHashSet();
@@ -105,11 +102,10 @@ public class PluginJetFilesProvider extends JetFilesProvider {
files.add(rootFile); files.add(rootFile);
return files; return files;
} }
};
@Override @Override
public Function<JetFile, Collection<JetFile>> sampleToAllFilesInModule() { protected Collection<JetFile> sampleToAllFilesInModule(@NotNull JetFile file) {
return WHOLE_PROJECT_DECLARATION_PROVIDER; return allFilesInProject(file);
} }
private boolean isKotlinSourceVirtualFile(@NotNull VirtualFile virtualFile) { private boolean isKotlinSourceVirtualFile(@NotNull VirtualFile virtualFile) {
@@ -84,7 +84,7 @@ public class AddOverrideToEqualsHashCodeToStringFix extends JetIntentionAction<P
@Override @Override
protected void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException { protected void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
Collection<JetFile> files = PluginJetFilesProvider.WHOLE_PROJECT_DECLARATION_PROVIDER.fun(file); Collection<JetFile> files = PluginJetFilesProvider.allFilesInProject(file);
AnalyzeExhaust analyzeExhaust = MigrateSureInProjectFix.analyzeFiles(file, files); AnalyzeExhaust analyzeExhaust = MigrateSureInProjectFix.analyzeFiles(file, files);
@@ -90,7 +90,7 @@ public class MigrateSureInProjectFix extends JetIntentionAction<PsiElement> {
@Override @Override
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException { public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
Collection<JetFile> files = PluginJetFilesProvider.WHOLE_PROJECT_DECLARATION_PROVIDER.fun(file); Collection<JetFile> files = PluginJetFilesProvider.allFilesInProject(file);
AnalyzeExhaust analyzeExhaust = analyzeFiles(file, files); AnalyzeExhaust analyzeExhaust = analyzeFiles(file, files);
@@ -53,7 +53,7 @@ public class RemoveValVarFromParametersFix implements IntentionAction {
// TODO after M6, this quick fix should remove val/var only for current parameter // TODO after M6, this quick fix should remove val/var only for current parameter
JetFile initialFile = (JetFile) file; JetFile initialFile = (JetFile) file;
Collection<JetFile> files = PluginJetFilesProvider.WHOLE_PROJECT_DECLARATION_PROVIDER.fun(initialFile); Collection<JetFile> files = PluginJetFilesProvider.allFilesInProject(initialFile);
for (JetFile jetFile : files) { for (JetFile jetFile : files) {
jetFile.acceptChildren(new JetVisitorVoid() { jetFile.acceptChildren(new JetVisitorVoid() {
@Override @Override