CFA classes rename: remove 'Kotlin' prefix

This commit is contained in:
Mikhail Glukhikh
2015-12-11 15:40:12 +03:00
parent 8db3fb03f9
commit d2fce9b16d
8 changed files with 51 additions and 50 deletions
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public interface KotlinControlFlowBuilder { public interface ControlFlowBuilder {
// Subroutines // Subroutines
void enterSubroutine(@NotNull KtElement subroutine); void enterSubroutine(@NotNull KtElement subroutine);
@@ -30,10 +30,10 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public abstract class KotlinControlFlowBuilderAdapter implements KotlinControlFlowBuilder { public abstract class ControlFlowBuilderAdapter implements ControlFlowBuilder {
@NotNull @NotNull
protected abstract KotlinControlFlowBuilder getDelegateBuilder(); protected abstract ControlFlowBuilder getDelegateBuilder();
@Override @Override
public void loadUnit(@NotNull KtExpression expression) { public void loadUnit(@NotNull KtExpression expression) {
@@ -73,14 +73,14 @@ import static org.jetbrains.kotlin.resolve.BindingContext.*;
import static org.jetbrains.kotlin.types.TypeUtils.NO_EXPECTED_TYPE; import static org.jetbrains.kotlin.types.TypeUtils.NO_EXPECTED_TYPE;
import static org.jetbrains.kotlin.types.TypeUtils.noExpectedType; import static org.jetbrains.kotlin.types.TypeUtils.noExpectedType;
public class KotlinFlowInformationProvider { public class ControlFlowInformationProvider {
private final KtElement subroutine; private final KtElement subroutine;
private final Pseudocode pseudocode; private final Pseudocode pseudocode;
private final BindingTrace trace; private final BindingTrace trace;
private PseudocodeVariablesData pseudocodeVariablesData; private PseudocodeVariablesData pseudocodeVariablesData;
private KotlinFlowInformationProvider( private ControlFlowInformationProvider(
@NotNull KtElement declaration, @NotNull KtElement declaration,
@NotNull BindingTrace trace, @NotNull BindingTrace trace,
@NotNull Pseudocode pseudocode @NotNull Pseudocode pseudocode
@@ -90,11 +90,11 @@ public class KotlinFlowInformationProvider {
this.pseudocode = pseudocode; this.pseudocode = pseudocode;
} }
public KotlinFlowInformationProvider( public ControlFlowInformationProvider(
@NotNull KtElement declaration, @NotNull KtElement declaration,
@NotNull BindingTrace trace @NotNull BindingTrace trace
) { ) {
this(declaration, trace, new KotlinControlFlowProcessor(trace).generatePseudocode(declaration)); this(declaration, trace, new ControlFlowProcessor(trace).generatePseudocode(declaration));
} }
public PseudocodeVariablesData getPseudocodeVariablesData() { public PseudocodeVariablesData getPseudocodeVariablesData() {
@@ -211,8 +211,8 @@ public class KotlinFlowInformationProvider {
(CallableDescriptor) trace.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, localDeclaration); (CallableDescriptor) trace.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, localDeclaration);
KotlinType expectedType = functionDescriptor != null ? functionDescriptor.getReturnType() : null; KotlinType expectedType = functionDescriptor != null ? functionDescriptor.getReturnType() : null;
KotlinFlowInformationProvider providerForLocalDeclaration = ControlFlowInformationProvider providerForLocalDeclaration =
new KotlinFlowInformationProvider(localDeclaration, trace, localDeclarationInstruction.getBody()); new ControlFlowInformationProvider(localDeclaration, trace, localDeclarationInstruction.getBody());
providerForLocalDeclaration.checkFunction(expectedType); providerForLocalDeclaration.checkFunction(expectedType);
} }
@@ -649,7 +649,7 @@ public class KotlinFlowInformationProvider {
public void markUnusedExpressions() { public void markUnusedExpressions() {
final Map<Instruction, DiagnosticFactory<?>> reportedDiagnosticMap = Maps.newHashMap(); final Map<Instruction, DiagnosticFactory<?>> reportedDiagnosticMap = Maps.newHashMap();
PseudocodeTraverserKt.traverse( PseudocodeTraverserKt.traverse(
pseudocode, TraversalOrder.FORWARD, new KotlinFlowInformationProvider.FunctionVoid1<Instruction>() { pseudocode, TraversalOrder.FORWARD, new ControlFlowInformationProvider.FunctionVoid1<Instruction>() {
@Override @Override
public void execute(@NotNull Instruction instruction) { public void execute(@NotNull Instruction instruction) {
if (!(instruction instanceof KtElementInstruction)) return; if (!(instruction instanceof KtElementInstruction)) return;
@@ -677,7 +677,7 @@ public class KotlinFlowInformationProvider {
public void markStatements() { public void markStatements() {
PseudocodeTraverserKt.traverse( PseudocodeTraverserKt.traverse(
pseudocode, TraversalOrder.FORWARD, new KotlinFlowInformationProvider.FunctionVoid1<Instruction>() { pseudocode, TraversalOrder.FORWARD, new ControlFlowInformationProvider.FunctionVoid1<Instruction>() {
@Override @Override
public void execute(@NotNull Instruction instruction) { public void execute(@NotNull Instruction instruction) {
PseudoValue value = instruction instanceof InstructionWithValue PseudoValue value = instruction instanceof InstructionWithValue
@@ -695,7 +695,7 @@ public class KotlinFlowInformationProvider {
public void markIfWithoutElse() { public void markIfWithoutElse() {
PseudocodeTraverserKt.traverse( PseudocodeTraverserKt.traverse(
pseudocode, TraversalOrder.FORWARD, new KotlinFlowInformationProvider.FunctionVoid1<Instruction>() { pseudocode, TraversalOrder.FORWARD, new ControlFlowInformationProvider.FunctionVoid1<Instruction>() {
@Override @Override
public void execute(@NotNull Instruction instruction) { public void execute(@NotNull Instruction instruction) {
PseudoValue value = instruction instanceof InstructionWithValue PseudoValue value = instruction instanceof InstructionWithValue
@@ -717,7 +717,7 @@ public class KotlinFlowInformationProvider {
public void markWhenWithoutElse() { public void markWhenWithoutElse() {
PseudocodeTraverserKt.traverse( PseudocodeTraverserKt.traverse(
pseudocode, TraversalOrder.FORWARD, new KotlinFlowInformationProvider.FunctionVoid1<Instruction>() { pseudocode, TraversalOrder.FORWARD, new ControlFlowInformationProvider.FunctionVoid1<Instruction>() {
@Override @Override
public void execute(@NotNull Instruction instruction) { public void execute(@NotNull Instruction instruction) {
PseudoValue value = instruction instanceof InstructionWithValue PseudoValue value = instruction instanceof InstructionWithValue
@@ -29,7 +29,7 @@ import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
import org.jetbrains.kotlin.cfg.pseudocode.KotlinControlFlowInstructionsGenerator; import org.jetbrains.kotlin.cfg.pseudocode.ControlFlowInstructionsGenerator;
import org.jetbrains.kotlin.cfg.pseudocode.PseudoValue; import org.jetbrains.kotlin.cfg.pseudocode.PseudoValue;
import org.jetbrains.kotlin.cfg.pseudocode.Pseudocode; import org.jetbrains.kotlin.cfg.pseudocode.Pseudocode;
import org.jetbrains.kotlin.cfg.pseudocode.PseudocodeImpl; import org.jetbrains.kotlin.cfg.pseudocode.PseudocodeImpl;
@@ -61,17 +61,17 @@ import org.jetbrains.kotlin.types.expressions.OperatorConventions;
import java.util.*; import java.util.*;
import static org.jetbrains.kotlin.cfg.KotlinControlFlowBuilder.PredefinedOperation.*; import static org.jetbrains.kotlin.cfg.ControlFlowBuilder.PredefinedOperation.*;
import static org.jetbrains.kotlin.diagnostics.Errors.*; import static org.jetbrains.kotlin.diagnostics.Errors.*;
import static org.jetbrains.kotlin.lexer.KtTokens.*; import static org.jetbrains.kotlin.lexer.KtTokens.*;
public class KotlinControlFlowProcessor { public class ControlFlowProcessor {
private final KotlinControlFlowBuilder builder; private final ControlFlowBuilder builder;
private final BindingTrace trace; private final BindingTrace trace;
public KotlinControlFlowProcessor(BindingTrace trace) { public ControlFlowProcessor(BindingTrace trace) {
this.builder = new KotlinControlFlowInstructionsGenerator(); this.builder = new ControlFlowInstructionsGenerator();
this.trace = trace; this.trace = trace;
} }
@@ -127,7 +127,7 @@ public class KotlinControlFlowProcessor {
} }
private class CFPVisitor extends KtVisitorVoid { private class CFPVisitor extends KtVisitorVoid {
private final KotlinControlFlowBuilder builder; private final ControlFlowBuilder builder;
private final KtVisitorVoid conditionVisitor = new KtVisitorVoid() { private final KtVisitorVoid conditionVisitor = new KtVisitorVoid() {
@@ -170,11 +170,11 @@ public class KotlinControlFlowProcessor {
@Override @Override
public void visitKtElement(@NotNull KtElement element) { public void visitKtElement(@NotNull KtElement element) {
throw new UnsupportedOperationException("[JetControlFlowProcessor] " + element.toString()); throw new UnsupportedOperationException("[ControlFlowProcessor] " + element.toString());
} }
}; };
private CFPVisitor(@NotNull KotlinControlFlowBuilder builder) { private CFPVisitor(@NotNull ControlFlowBuilder builder) {
this.builder = builder; this.builder = builder;
} }
@@ -411,7 +411,7 @@ public class KotlinControlFlowProcessor {
generateInstructions(right); generateInstructions(right);
} }
builder.bindLabel(resultLabel); builder.bindLabel(resultLabel);
KotlinControlFlowBuilder.PredefinedOperation operation = operationType == ANDAND ? AND : OR; ControlFlowBuilder.PredefinedOperation operation = operationType == ANDAND ? AND : OR;
builder.predefinedOperation(expression, operation, elementsToValues(Arrays.asList(left, right))); builder.predefinedOperation(expression, operation, elementsToValues(Arrays.asList(left, right)));
} }
@@ -35,32 +35,32 @@ import org.jetbrains.kotlin.types.KotlinType;
import java.util.*; import java.util.*;
public class KotlinControlFlowInstructionsGenerator extends KotlinControlFlowBuilderAdapter { public class ControlFlowInstructionsGenerator extends ControlFlowBuilderAdapter {
private KotlinControlFlowBuilder builder = null; private ControlFlowBuilder builder = null;
private final Stack<LoopInfo> loopInfo = new Stack<LoopInfo>(); private final Stack<LoopInfo> loopInfo = new Stack<LoopInfo>();
private final Stack<LexicalScope> lexicalScopes = new Stack<LexicalScope>(); private final Stack<LexicalScope> lexicalScopes = new Stack<LexicalScope>();
private final Map<KtElement, BreakableBlockInfo> elementToBlockInfo = new HashMap<KtElement, BreakableBlockInfo>(); private final Map<KtElement, BreakableBlockInfo> elementToBlockInfo = new HashMap<KtElement, BreakableBlockInfo>();
private int labelCount = 0; private int labelCount = 0;
private final Stack<KotlinControlFlowInstructionsGeneratorWorker> builders = new Stack<KotlinControlFlowInstructionsGeneratorWorker>(); private final Stack<ControlFlowInstructionsGeneratorWorker> builders = new Stack<ControlFlowInstructionsGeneratorWorker>();
private final Stack<BlockInfo> allBlocks = new Stack<BlockInfo>(); private final Stack<BlockInfo> allBlocks = new Stack<BlockInfo>();
@NotNull @NotNull
@Override @Override
protected KotlinControlFlowBuilder getDelegateBuilder() { protected ControlFlowBuilder getDelegateBuilder() {
return builder; return builder;
} }
private void pushBuilder(KtElement scopingElement, KtElement subroutine) { private void pushBuilder(KtElement scopingElement, KtElement subroutine) {
KotlinControlFlowInstructionsGeneratorWorker worker = new KotlinControlFlowInstructionsGeneratorWorker(scopingElement, subroutine); ControlFlowInstructionsGeneratorWorker worker = new ControlFlowInstructionsGeneratorWorker(scopingElement, subroutine);
builders.push(worker); builders.push(worker);
builder = worker; builder = worker;
} }
private KotlinControlFlowInstructionsGeneratorWorker popBuilder(@NotNull KtElement element) { private ControlFlowInstructionsGeneratorWorker popBuilder(@NotNull KtElement element) {
KotlinControlFlowInstructionsGeneratorWorker worker = builders.pop(); ControlFlowInstructionsGeneratorWorker worker = builders.pop();
if (!builders.isEmpty()) { if (!builders.isEmpty()) {
builder = builders.peek(); builder = builders.peek();
} }
@@ -88,15 +88,15 @@ public class KotlinControlFlowInstructionsGenerator extends KotlinControlFlowBui
public Pseudocode exitSubroutine(@NotNull KtElement subroutine) { public Pseudocode exitSubroutine(@NotNull KtElement subroutine) {
super.exitSubroutine(subroutine); super.exitSubroutine(subroutine);
builder.exitLexicalScope(subroutine); builder.exitLexicalScope(subroutine);
KotlinControlFlowInstructionsGeneratorWorker worker = popBuilder(subroutine); ControlFlowInstructionsGeneratorWorker worker = popBuilder(subroutine);
if (!builders.empty()) { if (!builders.empty()) {
KotlinControlFlowInstructionsGeneratorWorker builder = builders.peek(); ControlFlowInstructionsGeneratorWorker builder = builders.peek();
builder.declareFunction(subroutine, worker.getPseudocode()); builder.declareFunction(subroutine, worker.getPseudocode());
} }
return worker.getPseudocode(); return worker.getPseudocode();
} }
private class KotlinControlFlowInstructionsGeneratorWorker implements KotlinControlFlowBuilder { private class ControlFlowInstructionsGeneratorWorker implements ControlFlowBuilder {
private final PseudocodeImpl pseudocode; private final PseudocodeImpl pseudocode;
private final Label error; private final Label error;
@@ -115,7 +115,7 @@ public class KotlinControlFlowInstructionsGenerator extends KotlinControlFlowBui
} }
}; };
private KotlinControlFlowInstructionsGeneratorWorker(@NotNull KtElement scopingElement, @NotNull KtElement returnSubroutine) { private ControlFlowInstructionsGeneratorWorker(@NotNull KtElement scopingElement, @NotNull KtElement returnSubroutine) {
this.pseudocode = new PseudocodeImpl(scopingElement); this.pseudocode = new PseudocodeImpl(scopingElement);
this.error = pseudocode.createLabel("error", null); this.error = pseudocode.createLabel("error", null);
this.sink = pseudocode.createLabel("sink", null); this.sink = pseudocode.createLabel("sink", null);
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.cfg.pseudocode;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.cfg.KotlinControlFlowProcessor; import org.jetbrains.kotlin.cfg.ControlFlowProcessor;
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction; import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction;
import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.AccessTarget; import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.AccessTarget;
import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.AccessValueInstruction; import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.AccessValueInstruction;
@@ -84,7 +84,7 @@ public class PseudocodeUtil {
public void report(@NotNull Diagnostic diagnostic) { public void report(@NotNull Diagnostic diagnostic) {
} }
}; };
return new KotlinControlFlowProcessor(mockTrace).generatePseudocode(declaration); return new ControlFlowProcessor(mockTrace).generatePseudocode(declaration);
} }
@Nullable @Nullable
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.resolve;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
import org.jetbrains.kotlin.cfg.KotlinFlowInformationProvider; import org.jetbrains.kotlin.cfg.ControlFlowInformationProvider;
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor; import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor;
import org.jetbrains.kotlin.descriptors.PropertyDescriptor; import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor; import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor;
@@ -68,20 +68,21 @@ public class ControlFlowAnalyzer {
} }
private void checkSecondaryConstructor(@NotNull KtSecondaryConstructor constructor) { private void checkSecondaryConstructor(@NotNull KtSecondaryConstructor constructor) {
KotlinFlowInformationProvider flowInformationProvider = new KotlinFlowInformationProvider(constructor, trace); ControlFlowInformationProvider controlFlowInformationProvider = new ControlFlowInformationProvider(constructor, trace);
flowInformationProvider.checkDeclaration(); controlFlowInformationProvider.checkDeclaration();
flowInformationProvider.checkFunction(builtIns.getUnitType()); controlFlowInformationProvider.checkFunction(builtIns.getUnitType());
} }
private void checkDeclarationContainer(@NotNull BodiesResolveContext c, KtDeclarationContainer declarationContainer) { private void checkDeclarationContainer(@NotNull BodiesResolveContext c, KtDeclarationContainer declarationContainer) {
// A pseudocode of class/object initialization corresponds to a class/object // A pseudocode of class/object initialization corresponds to a class/object
// or initialization of properties corresponds to a package declared in a file // or initialization of properties corresponds to a package declared in a file
KotlinFlowInformationProvider flowInformationProvider = new KotlinFlowInformationProvider((KtElement) declarationContainer, trace); ControlFlowInformationProvider
controlFlowInformationProvider = new ControlFlowInformationProvider((KtElement) declarationContainer, trace);
if (c.getTopDownAnalysisMode().isLocalDeclarations()) { if (c.getTopDownAnalysisMode().isLocalDeclarations()) {
flowInformationProvider.checkForLocalClassOrObjectMode(); controlFlowInformationProvider.checkForLocalClassOrObjectMode();
return; return;
} }
flowInformationProvider.checkDeclaration(); controlFlowInformationProvider.checkDeclaration();
} }
private void checkProperty(@NotNull BodiesResolveContext c, KtProperty property, PropertyDescriptor propertyDescriptor) { private void checkProperty(@NotNull BodiesResolveContext c, KtProperty property, PropertyDescriptor propertyDescriptor) {
@@ -97,12 +98,12 @@ public class ControlFlowAnalyzer {
private void checkFunction(@NotNull BodiesResolveContext c, @NotNull KtDeclarationWithBody function, @Nullable KotlinType expectedReturnType) { private void checkFunction(@NotNull BodiesResolveContext c, @NotNull KtDeclarationWithBody function, @Nullable KotlinType expectedReturnType) {
if (!function.hasBody()) return; if (!function.hasBody()) return;
KotlinFlowInformationProvider flowInformationProvider = new KotlinFlowInformationProvider(function, trace); ControlFlowInformationProvider controlFlowInformationProvider = new ControlFlowInformationProvider(function, trace);
if (c.getTopDownAnalysisMode().isLocalDeclarations()) { if (c.getTopDownAnalysisMode().isLocalDeclarations()) {
flowInformationProvider.checkForLocalClassOrObjectMode(); controlFlowInformationProvider.checkForLocalClassOrObjectMode();
return; return;
} }
flowInformationProvider.checkDeclaration(); controlFlowInformationProvider.checkDeclaration();
flowInformationProvider.checkFunction(expectedReturnType); controlFlowInformationProvider.checkFunction(expectedReturnType);
} }
} }
@@ -23,7 +23,7 @@ import com.intellij.psi.util.CachedValuesManager
import com.intellij.psi.util.PsiModificationTracker import com.intellij.psi.util.PsiModificationTracker
import com.intellij.util.containers.ContainerUtil import com.intellij.util.containers.ContainerUtil
import org.jetbrains.kotlin.asJava.KotlinCodeBlockModificationListener import org.jetbrains.kotlin.asJava.KotlinCodeBlockModificationListener
import org.jetbrains.kotlin.cfg.KotlinFlowInformationProvider import org.jetbrains.kotlin.cfg.ControlFlowInformationProvider
import org.jetbrains.kotlin.container.get import org.jetbrains.kotlin.container.get
import org.jetbrains.kotlin.context.SimpleGlobalContext import org.jetbrains.kotlin.context.SimpleGlobalContext
import org.jetbrains.kotlin.context.withModule import org.jetbrains.kotlin.context.withModule
@@ -300,7 +300,7 @@ public class ResolveElementCache(
} }
val controlFlowTrace = DelegatingBindingTrace(trace.getBindingContext(), "Element control flow resolve", resolveElement) val controlFlowTrace = DelegatingBindingTrace(trace.getBindingContext(), "Element control flow resolve", resolveElement)
KotlinFlowInformationProvider(resolveElement, controlFlowTrace).checkDeclaration() ControlFlowInformationProvider(resolveElement, controlFlowTrace).checkDeclaration()
controlFlowTrace.addOwnDataTo(trace, null, false) controlFlowTrace.addOwnDataTo(trace, null, false)
return Pair(trace.getBindingContext(), statementFilterUsed) return Pair(trace.getBindingContext(), statementFilterUsed)
@@ -430,7 +430,7 @@ public class ResolveElementCache(
forceResolveAnnotationsInside(property) forceResolveAnnotationsInside(property)
for (accessor in property.getAccessors()) { for (accessor in property.getAccessors()) {
KotlinFlowInformationProvider(accessor, trace).checkDeclaration() ControlFlowInformationProvider(accessor, trace).checkDeclaration()
} }
return trace return trace