Changed way to pass statementFilter from ElementResolver into ExpressionTypingServices

This commit is contained in:
Valentin Kipyatkov
2014-11-19 22:53:47 +03:00
parent a0c9c0e7b2
commit 00d9c94a8b
4 changed files with 39 additions and 30 deletions
@@ -75,11 +75,6 @@ public class BodyResolver {
this.expressionTypingServices = expressionTypingServices;
}
@NotNull
public ExpressionTypingServices getExpressionTypingServices() {
return expressionTypingServices;
}
@Inject
public void setCallResolver(@NotNull CallResolver callResolver) {
this.callResolver = callResolver;
@@ -18,9 +18,12 @@ package org.jetbrains.jet.lang.resolve;
import com.google.common.base.Predicate;
import com.intellij.psi.PsiFile;
import kotlin.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.context.GlobalContext;
import org.jetbrains.jet.context.LazinessToken;
import org.jetbrains.jet.lang.psi.JetElement;
import org.jetbrains.jet.storage.ExceptionTracker;
import org.jetbrains.jet.storage.StorageManager;
@@ -42,7 +45,7 @@ public class TopDownAnalysisParameters extends LazinessToken implements GlobalCo
boolean analyzingBootstrapLibrary,
boolean declaredLocally
) {
return new TopDownAnalysisParameters(storageManager, exceptionTracker, analyzeCompletely, analyzingBootstrapLibrary,
return new TopDownAnalysisParameters(storageManager, exceptionTracker, analyzeCompletely, null, analyzingBootstrapLibrary,
declaredLocally, LAZY);
}
@@ -54,7 +57,7 @@ public class TopDownAnalysisParameters extends LazinessToken implements GlobalCo
boolean analyzingBootstrapLibrary,
boolean declaredLocally
) {
return new TopDownAnalysisParameters(storageManager, exceptionTracker, analyzeCompletely, analyzingBootstrapLibrary,
return new TopDownAnalysisParameters(storageManager, exceptionTracker, analyzeCompletely, null, analyzingBootstrapLibrary,
declaredLocally, true);
}
@@ -64,15 +67,23 @@ public class TopDownAnalysisParameters extends LazinessToken implements GlobalCo
@NotNull ExceptionTracker exceptionTracker,
@NotNull Predicate<PsiFile> analyzeCompletely
) {
return new TopDownAnalysisParameters(storageManager, exceptionTracker, analyzeCompletely, false, true, false);
return createForLocalDeclarations(storageManager, exceptionTracker, analyzeCompletely, null);
}
@NotNull
private final StorageManager storageManager;
@NotNull
private final ExceptionTracker exceptionTracker;
@NotNull
private final Predicate<PsiFile> analyzeCompletely;
public static TopDownAnalysisParameters createForLocalDeclarations(
@NotNull StorageManager storageManager,
@NotNull ExceptionTracker exceptionTracker,
@NotNull Predicate<PsiFile> analyzeCompletely,
@Nullable Function1<JetElement, Boolean> statementFilter
) {
return new TopDownAnalysisParameters(storageManager, exceptionTracker, analyzeCompletely, statementFilter, false, true, false);
}
@NotNull private final StorageManager storageManager;
@NotNull private final ExceptionTracker exceptionTracker;
@NotNull private final Predicate<PsiFile> analyzeCompletely;
@Nullable private final Function1<JetElement, Boolean> statementFilter;
private final boolean analyzingBootstrapLibrary;
private final boolean declaredLocally;
private final boolean lazyTopDownAnalysis;
@@ -81,6 +92,7 @@ public class TopDownAnalysisParameters extends LazinessToken implements GlobalCo
@NotNull StorageManager storageManager,
@NotNull ExceptionTracker exceptionTracker,
@NotNull Predicate<PsiFile> analyzeCompletely,
@Nullable Function1<JetElement, Boolean> statementFilter,
boolean analyzingBootstrapLibrary,
boolean declaredLocally,
boolean lazyTopDownAnalysis
@@ -88,6 +100,7 @@ public class TopDownAnalysisParameters extends LazinessToken implements GlobalCo
this.storageManager = storageManager;
this.exceptionTracker = exceptionTracker;
this.analyzeCompletely = analyzeCompletely;
this.statementFilter = statementFilter;
this.analyzingBootstrapLibrary = analyzingBootstrapLibrary;
this.declaredLocally = declaredLocally;
this.lazyTopDownAnalysis = lazyTopDownAnalysis;
@@ -110,6 +123,11 @@ public class TopDownAnalysisParameters extends LazinessToken implements GlobalCo
return analyzeCompletely;
}
@Nullable
public Function1<JetElement, Boolean> getStatementFilter() {
return statementFilter;
}
public boolean isAnalyzingBootstrapLibrary() {
return analyzingBootstrapLibrary;
}
@@ -24,6 +24,7 @@ import kotlin.KotlinPackage;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.analyzer.AnalyzerPackage;
import org.jetbrains.jet.context.GlobalContext;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
@@ -75,8 +76,6 @@ public class ExpressionTypingServices {
private AnnotationResolver annotationResolver;
@NotNull
private CallResolverExtensionProvider extensionProvider;
@Nullable
private Function1<JetElement, Boolean> filter;
@NotNull
public Project getProject() {
@@ -144,12 +143,9 @@ public class ExpressionTypingServices {
}
@Nullable
public Function1<JetElement, Boolean> getFilter() {
return filter;
}
public void setFilter(@Nullable Function1<JetElement, Boolean> filter) {
this.filter = filter;
private Function1<JetElement, Boolean> getStatementFilter() {
GlobalContext context = expressionTypingComponents.globalContext;
return context instanceof TopDownAnalysisParameters ? ((TopDownAnalysisParameters) context).getStatementFilter() : null;
}
public ExpressionTypingServices(@NotNull ExpressionTypingComponents components) {
@@ -219,6 +215,7 @@ public class ExpressionTypingServices {
) {
List<JetElement> block = expression.getStatements();
Function1<JetElement, Boolean> filter = getStatementFilter();
if (filter != null && !(expression instanceof JetPsiUtil.JetExpressionWrapper)) {
block = KotlinPackage.filter(block, filter);
}