refactoring: traverseForward and traverseBackward
instead of boolean parameter 'directOrder'
This commit is contained in:
@@ -196,7 +196,7 @@ public class JetFlowInformationProvider {
|
||||
|
||||
final Map<Instruction, AbstractDiagnosticFactory> reportedDiagnosticMap = Maps.newHashMap();
|
||||
|
||||
PseudocodeTraverser.traverse(pseudocode, true, true, initializers, new InstructionDataAnalyzeStrategy<Map<VariableDescriptor, PseudocodeVariablesData.VariableInitState>>() {
|
||||
PseudocodeTraverser.traverseForward(pseudocode, true, initializers, new InstructionDataAnalyzeStrategy<Map<VariableDescriptor, PseudocodeVariablesData.VariableInitState>>() {
|
||||
@Override
|
||||
public void execute(@NotNull Instruction instruction,
|
||||
@Nullable Map<VariableDescriptor, VariableInitState> in,
|
||||
@@ -204,7 +204,6 @@ public class JetFlowInformationProvider {
|
||||
assert in != null && out != null;
|
||||
VariableInitContext ctxt = new VariableInitContext(instruction, reportedDiagnosticMap, in, out);
|
||||
if (ctxt.variableDescriptor == null) return;
|
||||
if (!(instruction instanceof ReadValueInstruction) && !(instruction instanceof WriteValueInstruction)) return;
|
||||
if (instruction instanceof ReadValueInstruction) {
|
||||
JetElement element = ((ReadValueInstruction) instruction).getElement();
|
||||
boolean error = checkBackingField(ctxt, element);
|
||||
@@ -213,6 +212,7 @@ public class JetFlowInformationProvider {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!(instruction instanceof WriteValueInstruction)) return;
|
||||
JetElement element = ((WriteValueInstruction) instruction).getlValue();
|
||||
boolean error = checkBackingField(ctxt, element);
|
||||
if (!(element instanceof JetExpression)) return;
|
||||
@@ -502,7 +502,7 @@ public class JetFlowInformationProvider {
|
||||
}
|
||||
}
|
||||
};
|
||||
PseudocodeTraverser.traverse(pseudocode, false, true, variableStatusData, variableStatusAnalyzeStrategy);
|
||||
PseudocodeTraverser.traverseBackward(pseudocode, true, variableStatusData, variableStatusAnalyzeStrategy);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -511,8 +511,8 @@ public class JetFlowInformationProvider {
|
||||
public void markUnusedLiteralsInBlock() {
|
||||
assert pseudocode != null;
|
||||
final Map<Instruction, AbstractDiagnosticFactory> reportedDiagnosticMap = Maps.newHashMap();
|
||||
PseudocodeTraverser.traverse(
|
||||
pseudocode, true, new InstructionAnalyzeStrategy() {
|
||||
PseudocodeTraverser.traverseForward(
|
||||
pseudocode, new InstructionAnalyzeStrategy() {
|
||||
@Override
|
||||
public void execute(@NotNull Instruction instruction) {
|
||||
if (!(instruction instanceof ReadValueInstruction)) return;
|
||||
|
||||
@@ -127,7 +127,19 @@ public class PseudocodeTraverser {
|
||||
}
|
||||
}
|
||||
|
||||
public static void traverse(
|
||||
public static void traverseForward(
|
||||
@NotNull Pseudocode pseudocode,
|
||||
@NotNull InstructionAnalyzeStrategy instructionAnalyzeStrategy) {
|
||||
traverse(pseudocode, true, instructionAnalyzeStrategy);
|
||||
}
|
||||
|
||||
public static void traverseBackward(
|
||||
@NotNull Pseudocode pseudocode,
|
||||
@NotNull InstructionAnalyzeStrategy instructionAnalyzeStrategy) {
|
||||
traverse(pseudocode, false, instructionAnalyzeStrategy);
|
||||
}
|
||||
|
||||
private static void traverse(
|
||||
@NotNull Pseudocode pseudocode, boolean directOrder,
|
||||
InstructionAnalyzeStrategy instructionAnalyzeStrategy) {
|
||||
|
||||
@@ -140,7 +152,21 @@ public class PseudocodeTraverser {
|
||||
}
|
||||
}
|
||||
|
||||
public static <D> void traverse(
|
||||
public static <D> void traverseForward(
|
||||
@NotNull Pseudocode pseudocode, boolean lookInside,
|
||||
@NotNull Map<Instruction, Edges<D>> edgesMap,
|
||||
@NotNull InstructionDataAnalyzeStrategy<D> instructionDataAnalyzeStrategy) {
|
||||
traverse(pseudocode, true, lookInside, edgesMap, instructionDataAnalyzeStrategy);
|
||||
}
|
||||
|
||||
public static <D> void traverseBackward(
|
||||
@NotNull Pseudocode pseudocode, boolean lookInside,
|
||||
@NotNull Map<Instruction, Edges<D>> edgesMap,
|
||||
@NotNull InstructionDataAnalyzeStrategy<D> instructionDataAnalyzeStrategy) {
|
||||
traverse(pseudocode, false, lookInside, edgesMap, instructionDataAnalyzeStrategy);
|
||||
}
|
||||
|
||||
private static <D> void traverse(
|
||||
@NotNull Pseudocode pseudocode, boolean directOrder, boolean lookInside,
|
||||
@NotNull Map<Instruction, Edges<D>> edgesMap,
|
||||
@NotNull InstructionDataAnalyzeStrategy<D> instructionDataAnalyzeStrategy) {
|
||||
|
||||
@@ -62,7 +62,7 @@ public class PseudocodeVariablesData {
|
||||
Set<VariableDescriptor> usedVariables = usedVariablesInEachDeclaration.get(pseudocode);
|
||||
if (usedVariables == null) {
|
||||
final Set<VariableDescriptor> result = Sets.newHashSet();
|
||||
PseudocodeTraverser.traverse(pseudocode, true, new InstructionAnalyzeStrategy() {
|
||||
PseudocodeTraverser.traverseForward(pseudocode, new InstructionAnalyzeStrategy() {
|
||||
@Override
|
||||
public void execute(@NotNull Instruction instruction) {
|
||||
VariableDescriptor variableDescriptor = PseudocodeUtil.extractVariableDescriptorIfAny(instruction, false,
|
||||
|
||||
Reference in New Issue
Block a user