Refactor ExpressionTypingVisitorDispatcher
Inject in in ExpressionTypingServices
This commit is contained in:
+8
-4
@@ -55,10 +55,14 @@ public class ExpressionTypingServices {
|
|||||||
|
|
||||||
@NotNull private final StatementFilter statementFilter;
|
@NotNull private final StatementFilter statementFilter;
|
||||||
|
|
||||||
public ExpressionTypingServices(@NotNull ExpressionTypingComponents components, @NotNull StatementFilter statementFilter) {
|
public ExpressionTypingServices(
|
||||||
|
@NotNull ExpressionTypingComponents components,
|
||||||
|
@NotNull StatementFilter statementFilter,
|
||||||
|
@NotNull ExpressionTypingVisitorDispatcher.ForDeclarations facade
|
||||||
|
) {
|
||||||
this.expressionTypingComponents = components;
|
this.expressionTypingComponents = components;
|
||||||
this.statementFilter = statementFilter;
|
this.statementFilter = statementFilter;
|
||||||
this.expressionTypingFacade = ExpressionTypingVisitorDispatcher.create(components);
|
this.expressionTypingFacade = facade;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull public StatementFilter getStatementFilter() {
|
@NotNull public StatementFilter getStatementFilter() {
|
||||||
@@ -226,7 +230,7 @@ public class ExpressionTypingServices {
|
|||||||
return TypeInfoFactoryPackage.createTypeInfo(expressionTypingComponents.builtIns.getUnitType(), context);
|
return TypeInfoFactoryPackage.createTypeInfo(expressionTypingComponents.builtIns.getUnitType(), context);
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpressionTypingInternals blockLevelVisitor = ExpressionTypingVisitorDispatcher.createForBlock(expressionTypingComponents, scope);
|
ExpressionTypingInternals blockLevelVisitor = new ExpressionTypingVisitorDispatcher.ForBlock(expressionTypingComponents, scope);
|
||||||
ExpressionTypingContext newContext = context.replaceScope(scope).replaceExpectedType(NO_EXPECTED_TYPE);
|
ExpressionTypingContext newContext = context.replaceScope(scope).replaceExpectedType(NO_EXPECTED_TYPE);
|
||||||
|
|
||||||
JetTypeInfo result = TypeInfoFactoryPackage.noTypeInfo(context);
|
JetTypeInfo result = TypeInfoFactoryPackage.noTypeInfo(context);
|
||||||
@@ -259,7 +263,7 @@ public class ExpressionTypingServices {
|
|||||||
newContext = newContext.replaceDataFlowInfo(newDataFlowInfo);
|
newContext = newContext.replaceDataFlowInfo(newDataFlowInfo);
|
||||||
// We take current data flow info if jump there is not possible
|
// We take current data flow info if jump there is not possible
|
||||||
}
|
}
|
||||||
blockLevelVisitor = ExpressionTypingVisitorDispatcher.createForBlock(expressionTypingComponents, scope);
|
blockLevelVisitor = new ExpressionTypingVisitorDispatcher.ForBlock(expressionTypingComponents, scope);
|
||||||
}
|
}
|
||||||
return result.replaceJumpOutPossible(jumpOutPossible).replaceJumpFlowInfo(beforeJumpInfo);
|
return result.replaceJumpOutPossible(jumpOutPossible).replaceJumpFlowInfo(beforeJumpInfo);
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-46
@@ -39,67 +39,50 @@ import org.jetbrains.kotlin.utils.KotlinFrontEndException;
|
|||||||
import static org.jetbrains.kotlin.diagnostics.Errors.TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM;
|
import static org.jetbrains.kotlin.diagnostics.Errors.TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM;
|
||||||
import static org.jetbrains.kotlin.resolve.bindingContextUtil.BindingContextUtilPackage.recordScopeAndDataFlowInfo;
|
import static org.jetbrains.kotlin.resolve.bindingContextUtil.BindingContextUtilPackage.recordScopeAndDataFlowInfo;
|
||||||
|
|
||||||
public class ExpressionTypingVisitorDispatcher extends JetVisitor<JetTypeInfo, ExpressionTypingContext> implements ExpressionTypingInternals {
|
public abstract class ExpressionTypingVisitorDispatcher extends JetVisitor<JetTypeInfo, ExpressionTypingContext> implements ExpressionTypingInternals {
|
||||||
|
|
||||||
public static final PerformanceCounter typeInfoPerfCounter = PerformanceCounter.Companion.create("Type info", true);
|
public static final PerformanceCounter typeInfoPerfCounter = PerformanceCounter.Companion.create("Type info", true);
|
||||||
|
|
||||||
public interface StatementVisitorProvider {
|
private static final Logger LOG = Logger.getInstance(ExpressionTypingVisitor.class);
|
||||||
ExpressionTypingVisitorForStatements get(@NotNull ExpressionTypingContext context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class StatementVisitorProviderForBlock implements StatementVisitorProvider {
|
public static class ForDeclarations extends ExpressionTypingVisitorDispatcher {
|
||||||
private final ExpressionTypingVisitorForStatements visitorForBlock;
|
public ForDeclarations(@NotNull ExpressionTypingComponents components) {
|
||||||
|
super(components);
|
||||||
|
|
||||||
public StatementVisitorProviderForBlock(@NotNull WritableScope scope) {
|
|
||||||
visitorForBlock = new ExpressionTypingVisitorForStatements(
|
|
||||||
ExpressionTypingVisitorDispatcher.this, scope, basic, controlStructures, patterns, functions
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ExpressionTypingVisitorForStatements get(@NotNull ExpressionTypingContext context) {
|
protected ExpressionTypingVisitorForStatements getStatementVisitor(@NotNull ExpressionTypingContext context) {
|
||||||
return visitorForBlock;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class StatementVisitorProviderForDeclarations implements StatementVisitorProvider {
|
|
||||||
@Override
|
|
||||||
public ExpressionTypingVisitorForStatements get(@NotNull ExpressionTypingContext context) {
|
|
||||||
return createStatementVisitor(context);
|
return createStatementVisitor(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Logger LOG = Logger.getInstance(ExpressionTypingVisitor.class);
|
protected abstract ExpressionTypingVisitorForStatements getStatementVisitor(@NotNull ExpressionTypingContext context);
|
||||||
|
|
||||||
@NotNull
|
public static class ForBlock extends ExpressionTypingVisitorDispatcher {
|
||||||
public static ExpressionTypingFacade create(@NotNull ExpressionTypingComponents components) {
|
|
||||||
ExpressionTypingVisitorDispatcher typingVisitorDispatcher = new ExpressionTypingVisitorDispatcher(components);
|
|
||||||
typingVisitorDispatcher.setProviderForStatements(typingVisitorDispatcher.new StatementVisitorProviderForDeclarations());
|
|
||||||
return typingVisitorDispatcher;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
private final ExpressionTypingVisitorForStatements visitorForBlock;
|
||||||
public static ExpressionTypingInternals createForBlock(
|
|
||||||
@NotNull ExpressionTypingComponents components,
|
|
||||||
@NotNull WritableScope writableScope
|
|
||||||
) {
|
|
||||||
ExpressionTypingVisitorDispatcher typingVisitorDispatcher = new ExpressionTypingVisitorDispatcher(components);
|
|
||||||
typingVisitorDispatcher.setProviderForStatements(typingVisitorDispatcher.new StatementVisitorProviderForBlock(writableScope));
|
|
||||||
return typingVisitorDispatcher;
|
|
||||||
|
|
||||||
|
public ForBlock(
|
||||||
|
@NotNull ExpressionTypingComponents components,
|
||||||
|
@NotNull WritableScope writableScope
|
||||||
|
) {
|
||||||
|
super(components);
|
||||||
|
this.visitorForBlock = new ExpressionTypingVisitorForStatements(
|
||||||
|
this, writableScope, basic, controlStructures, patterns, functions
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ExpressionTypingVisitorForStatements getStatementVisitor(@NotNull ExpressionTypingContext context) {
|
||||||
|
return visitorForBlock;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ExpressionTypingComponents components;
|
private final ExpressionTypingComponents components;
|
||||||
private final BasicExpressionTypingVisitor basic;
|
protected final BasicExpressionTypingVisitor basic;
|
||||||
private StatementVisitorProvider providerForStatements;
|
protected final FunctionsTypingVisitor functions;
|
||||||
private final FunctionsTypingVisitor functions;
|
protected final ControlStructureTypingVisitor controlStructures;
|
||||||
private final ControlStructureTypingVisitor controlStructures;
|
protected final PatternMatchingTypingVisitor patterns;
|
||||||
private final PatternMatchingTypingVisitor patterns;
|
|
||||||
|
|
||||||
public void setProviderForStatements(StatementVisitorProvider providerForStatements) {
|
|
||||||
this.providerForStatements = providerForStatements;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ExpressionTypingVisitorDispatcher(
|
private ExpressionTypingVisitorDispatcher(
|
||||||
@NotNull ExpressionTypingComponents components
|
@NotNull ExpressionTypingComponents components
|
||||||
@@ -153,10 +136,10 @@ public class ExpressionTypingVisitorDispatcher extends JetVisitor<JetTypeInfo, E
|
|||||||
@NotNull
|
@NotNull
|
||||||
public final JetTypeInfo getTypeInfo(@NotNull JetExpression expression, ExpressionTypingContext context, boolean isStatement) {
|
public final JetTypeInfo getTypeInfo(@NotNull JetExpression expression, ExpressionTypingContext context, boolean isStatement) {
|
||||||
if (!isStatement) return getTypeInfo(expression, context);
|
if (!isStatement) return getTypeInfo(expression, context);
|
||||||
return getTypeInfo(expression, context, providerForStatements.get(context));
|
return getTypeInfo(expression, context, getStatementVisitor(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
private ExpressionTypingVisitorForStatements createStatementVisitor(ExpressionTypingContext context) {
|
protected ExpressionTypingVisitorForStatements createStatementVisitor(ExpressionTypingContext context) {
|
||||||
return new ExpressionTypingVisitorForStatements(this,
|
return new ExpressionTypingVisitorForStatements(this,
|
||||||
ExpressionTypingUtils.newWritableScopeImpl(context, "statement scope"),
|
ExpressionTypingUtils.newWritableScopeImpl(context, "statement scope"),
|
||||||
basic, controlStructures, patterns, functions);
|
basic, controlStructures, patterns, functions);
|
||||||
|
|||||||
Reference in New Issue
Block a user