handling another kind of statement
This commit is contained in:
parent
eb1aab5852
commit
99f7b7c2e3
|
@ -52,6 +52,12 @@ public class CodeWalkthrough {
|
|||
colorStatement(ctx, painter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterExpressionStatement(CPP14Parser.ExpressionStatementContext ctx) {
|
||||
super.enterExpressionStatement(ctx);
|
||||
colorStatement(ctx, painter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterJumpStatement(CPP14Parser.JumpStatementContext ctx) {
|
||||
super.enterJumpStatement(ctx);
|
||||
|
@ -126,7 +132,10 @@ public class CodeWalkthrough {
|
|||
boolean isAlive = getOverallState(currentState);
|
||||
color = isAlive ? ACTIVE_STATEMENT : INACTIVE_BRANCH;
|
||||
}
|
||||
painter.paintBackground(color, new Range(ctx));
|
||||
Range range = new Range(ctx);
|
||||
if (log.debugEnabled())
|
||||
log.info(color + " for " + sourceCode.substring(range.getStart(), range.getStop()));
|
||||
painter.paintBackground(color, range);
|
||||
}
|
||||
}, tree);
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ public class LiveDataParserSandbox {
|
|||
values.put("engineTooSlow", Boolean.TRUE);
|
||||
values.put("engineTooFast", Boolean.FALSE);
|
||||
|
||||
VariableValueSource valueSource = name -> values.get(name);
|
||||
VariableValueSource valueSource = values::get;
|
||||
|
||||
new FrameHelper(JDialog.EXIT_ON_CLOSE).showFrame(new LiveDataParserPanel(new UIContext(), valueSource, "ac_control.cpp").getContent());
|
||||
}
|
||||
|
|
|
@ -21,6 +21,24 @@ import static org.mockito.Matchers.eq;
|
|||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class LiveDataParserTest {
|
||||
@Test
|
||||
public void testGreenCode() {
|
||||
String sourceCode = "void AcController::onSlowCallback() {\n" +
|
||||
"\tbool isEnabled = getAcState();\n" +
|
||||
"\n" +
|
||||
"\tm_acEnabled = isEnabled;\n" +
|
||||
"\n" +
|
||||
"\tenginePins.acRelay.setValue(isEnabled);\n" +
|
||||
"\n" +
|
||||
"#if EFI_TUNER_STUDIO\n" +
|
||||
"\tengine->outputChannels.acState = isEnabled;\n" +
|
||||
"#endif // EFI_TUNER_STUDIO\n" +
|
||||
"}\n";
|
||||
|
||||
SourceCodePainter painter = run(name -> null, sourceCode);
|
||||
verify(painter, times(4)).paintBackground(eq(CodeWalkthrough.ACTIVE_STATEMENT), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsing() {
|
||||
Map<String, Object> values = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
@ -48,16 +66,8 @@ public class LiveDataParserTest {
|
|||
"return ff;\n" +
|
||||
"}\n";
|
||||
|
||||
SourceCodePainter painter = mock(SourceCodePainter.class);
|
||||
ParseTree tree = LiveDataParserPanel.getParseTree(sourceCode);
|
||||
SourceCodePainter painter = run(valueSource, sourceCode);
|
||||
|
||||
System.out.println("******************************************* Just print everything for educational purposes");
|
||||
new ParseTreeWalker().walk(new PrintCPP14ParserListener(), tree);
|
||||
|
||||
System.out.println("******************************************* Now running FOR REAL");
|
||||
|
||||
|
||||
CodeWalkthrough.applyVariables(valueSource, sourceCode, painter, tree);
|
||||
verify(painter, times(2)).paintForeground(eq(Color.blue), any());
|
||||
|
||||
verify(painter).paintBackground(eq(Color.red), any());
|
||||
|
@ -69,6 +79,17 @@ public class LiveDataParserTest {
|
|||
verify(painter, times(3)).paintBackground(eq(CodeWalkthrough.PASSIVE_CODE), any());
|
||||
}
|
||||
|
||||
private SourceCodePainter run(VariableValueSource valueSource, String sourceCode) {
|
||||
SourceCodePainter painter = mock(SourceCodePainter.class);
|
||||
ParseTree tree = LiveDataParserPanel.getParseTree(sourceCode);
|
||||
|
||||
System.out.println("******************************************* Just print everything for educational purposes");
|
||||
new ParseTreeWalker().walk(new PrintCPP14ParserListener(), tree);
|
||||
System.out.println("******************************************* Now running FOR REAL");
|
||||
CodeWalkthrough.applyVariables(valueSource, sourceCode, painter, tree);
|
||||
return painter;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigurationInRealSourceCode() throws IOException, URISyntaxException {
|
||||
String sourceCode = LiveDataParserPanel.getContent(LiveDataParserPanel.class, LiveDataView.BOOST_CONTROL.getFileName());
|
||||
|
|
|
@ -601,7 +601,7 @@ public class PrintCPP14ParserListener implements CPP14ParserListener {
|
|||
|
||||
@Override
|
||||
public void enterLabeledStatement(CPP14Parser.LabeledStatementContext ctx) {
|
||||
printWithCounter("enterLabeledStatement");
|
||||
printWithCounter("enterLabeledStatement " + ctx.getText());
|
||||
|
||||
}
|
||||
|
||||
|
@ -613,8 +613,7 @@ public class PrintCPP14ParserListener implements CPP14ParserListener {
|
|||
|
||||
@Override
|
||||
public void enterExpressionStatement(CPP14Parser.ExpressionStatementContext ctx) {
|
||||
printWithCounter("enterExpressionStatement");
|
||||
|
||||
printWithCounter("enterExpressionStatement " + ctx.getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -650,7 +649,6 @@ public class PrintCPP14ParserListener implements CPP14ParserListener {
|
|||
@Override
|
||||
public void enterSelectionStatement(CPP14Parser.SelectionStatementContext ctx) {
|
||||
printWithCounter("CONDITIONAL enterSelectionStatement " + ctx.getText() + " statements" + ctx.statement());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -672,26 +670,22 @@ public class PrintCPP14ParserListener implements CPP14ParserListener {
|
|||
|
||||
@Override
|
||||
public void enterIterationStatement(CPP14Parser.IterationStatementContext ctx) {
|
||||
printWithCounter("enterIterationStatement");
|
||||
|
||||
printWithCounter("enterIterationStatement " + ctx.getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exitIterationStatement(CPP14Parser.IterationStatementContext ctx) {
|
||||
printWithCounter("exitIterationStatement");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterForInitStatement(CPP14Parser.ForInitStatementContext ctx) {
|
||||
printWithCounter("enterForInitStatement");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exitForInitStatement(CPP14Parser.ForInitStatementContext ctx) {
|
||||
printWithCounter("exitForInitStatement");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -732,7 +726,7 @@ public class PrintCPP14ParserListener implements CPP14ParserListener {
|
|||
|
||||
@Override
|
||||
public void enterDeclarationStatement(CPP14Parser.DeclarationStatementContext ctx) {
|
||||
printWithCounter("enterDeclarationStatement");
|
||||
printWithCounter("enterDeclarationStatement " + ctx.getText());
|
||||
|
||||
}
|
||||
|
||||
|
@ -756,7 +750,7 @@ public class PrintCPP14ParserListener implements CPP14ParserListener {
|
|||
|
||||
@Override
|
||||
public void enterDeclaration(CPP14Parser.DeclarationContext ctx) {
|
||||
printWithCounter("enterDeclaration");
|
||||
printWithCounter("enterDeclaration " + ctx);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue