diff --git a/java_console/io/src/main/java/com/rusefi/ldmp/StateDictionary.java b/java_console/io/src/main/java/com/rusefi/ldmp/StateDictionary.java index e150a34dd1..a754614eb3 100644 --- a/java_console/io/src/main/java/com/rusefi/ldmp/StateDictionary.java +++ b/java_console/io/src/main/java/com/rusefi/ldmp/StateDictionary.java @@ -28,7 +28,7 @@ public enum StateDictionary { register(live_data_e.LDS_trigger_state, TriggerState.VALUES, "trigger_decoder.cpp"); // 11 register(live_data_e.LDS_ac_control, AcControl.VALUES, "ac_control.cpp"); // 12 register(live_data_e.LDS_fan_control, FuelPump.VALUES, "fan_control.cpp"); - register(live_data_e.LDS_injector_model, InjectorModel.VALUES, "injector_model"); + register(live_data_e.LDS_injector_model, InjectorModel.VALUES, "injector_model.cpp"); register(live_data_e.LDS_idle_state, IdleState.VALUES, "idle_thread.cpp"); register(live_data_e.LDS_fuel_pump, FuelPump.VALUES, "fuel_pump.cpp"); register(live_data_e.LDS_wall_fuel_state, WallFuelState.VALUES, "wall_fuel.cpp"); diff --git a/java_console/ui/src/main/java/com/rusefi/CodeWalkthrough.java b/java_console/ui/src/main/java/com/rusefi/CodeWalkthrough.java index 7939451141..ee9e37ae14 100644 --- a/java_console/ui/src/main/java/com/rusefi/CodeWalkthrough.java +++ b/java_console/ui/src/main/java/com/rusefi/CodeWalkthrough.java @@ -150,7 +150,11 @@ public class CodeWalkthrough { color = isAlive == BranchingState.TRUE ? ACTIVE_STATEMENT : PASSIVE_CODE; } } - Range range = new Range(ctx); + Range range = Range.create(ctx.start, ctx.stop); + if (range == null) { + // parsing error sorry we have to bail out + return; + } if (log.debugEnabled()) log.info(color + " for " + sourceCode.substring(range.getStart(), range.getStop())); painter.paintBackground(color, range); diff --git a/java_console/ui/src/main/java/com/rusefi/livedata/LiveDataParserPanel.java b/java_console/ui/src/main/java/com/rusefi/livedata/LiveDataParserPanel.java index d2f19223e3..0cf285c5cc 100644 --- a/java_console/ui/src/main/java/com/rusefi/livedata/LiveDataParserPanel.java +++ b/java_console/ui/src/main/java/com/rusefi/livedata/LiveDataParserPanel.java @@ -20,6 +20,7 @@ import com.rusefi.ui.livedocs.RefreshActions; import org.antlr.v4.runtime.*; import org.antlr.v4.runtime.tree.ParseTree; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.text.*; @@ -103,10 +104,19 @@ public class LiveDataParserPanel { } } + @NotNull public static String getContent(Class clazz, String fileName) throws IOException, URISyntaxException { + String contentOrNull = getContentOrNull(clazz, fileName); + if (contentOrNull == null) + return fileName + " getResourceAsStream not found"; + return contentOrNull; + } + + @Nullable + public static String getContentOrNull(Class clazz, String fileName) throws IOException { InputStream cpp = clazz.getResourceAsStream("/c_sources/" + fileName); if (cpp == null) - return fileName + " getResourceAsStream not found"; + return null; String line; StringBuilder result = new StringBuilder(); diff --git a/java_console/ui/src/main/java/com/rusefi/livedata/readme.md b/java_console/ui/src/main/java/com/rusefi/livedata/readme.md new file mode 100644 index 0000000000..3616a13243 --- /dev/null +++ b/java_console/ui/src/main/java/com/rusefi/livedata/readme.md @@ -0,0 +1 @@ +See https://github.com/antlr/grammars-v4/tree/master/cpp \ No newline at end of file diff --git a/java_console/ui/src/main/java/com/rusefi/ui/livedata/Range.java b/java_console/ui/src/main/java/com/rusefi/ui/livedata/Range.java index b548016adb..0f23c737e3 100644 --- a/java_console/ui/src/main/java/com/rusefi/ui/livedata/Range.java +++ b/java_console/ui/src/main/java/com/rusefi/ui/livedata/Range.java @@ -30,8 +30,11 @@ public class Range { public static Range create(Token startToken, Token stopToken) { int start = startToken.getStartIndex(); int stop = stopToken.getStopIndex() + 1; - if (stop < start) - throw new IllegalStateException("Order issue " + startToken + "/" + stopToken); + if (stop < start) { + // this happens in case of parsing error + // we are using CPP14 parser while we are using fancier version of C++ maybe that's a contributing factor? + return null; + } return new Range(startToken, stopToken); } diff --git a/java_console/ui/src/test/java/com/rusefi/ui/livedata/LiveDataColorTest.java b/java_console/ui/src/test/java/com/rusefi/ui/livedata/LiveDataColorTest.java new file mode 100644 index 0000000000..9f88817fca --- /dev/null +++ b/java_console/ui/src/test/java/com/rusefi/ui/livedata/LiveDataColorTest.java @@ -0,0 +1,54 @@ +package com.rusefi.ui.livedata; + +import com.rusefi.CodeWalkthrough; +import com.rusefi.enums.live_data_e; +import com.rusefi.ldmp.StateDictionary; +import com.rusefi.livedata.LiveDataParserPanel; +import org.antlr.v4.runtime.tree.ParseTree; +import org.junit.Test; + +import java.awt.*; +import java.io.IOException; +import java.net.URISyntaxException; + +import static com.rusefi.livedata.LiveDataParserPanel.getContentOrNull; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +public class LiveDataColorTest { + @Test + public void testAllFiles() throws IOException, URISyntaxException { + int counter = 0; + for (live_data_e view : live_data_e.values()) { + String fileName = StateDictionary.INSTANCE.getFileName(view); + + try { + testSpecificFile(fileName); + } catch (RuntimeException e) { + throw new IllegalStateException("During " + fileName, e); + } + + counter++; + } + + assertTrue(counter > 4); + + } + + private void testSpecificFile(String fileName) throws IOException { + String sourceCode = getContentOrNull(getClass(), fileName); + assertNotNull("sourceCode for " + fileName, sourceCode); + + ParseTree tree = LiveDataParserPanel.getParseTree(sourceCode); + + CodeWalkthrough.applyVariables(VariableValueSource.VOID, sourceCode, new SourceCodePainter() { + @Override + public void paintBackground(Color color, Range range) { + } + + @Override + public void paintForeground(Color color, Range range) { + } + }, tree); + } +} diff --git a/java_console/ui/src/test/java/com/rusefi/ui/livedata/LiveDataParserTest.java b/java_console/ui/src/test/java/com/rusefi/ui/livedata/LiveDataParserTest.java index b4ad70db3a..593a05ca76 100644 --- a/java_console/ui/src/test/java/com/rusefi/ui/livedata/LiveDataParserTest.java +++ b/java_console/ui/src/test/java/com/rusefi/ui/livedata/LiveDataParserTest.java @@ -28,6 +28,7 @@ public class LiveDataParserTest { "\tbool isEnabled = getAcState();\n" + "\n" + "\tm_acEnabled = isEnabled;\n" + + "auto [cltValid, clt] = Sensor::get(SensorType::Clt);\n" + "\n" + "\tenginePins.acRelay.setValue(isEnabled);\n" + "\n" + @@ -37,7 +38,7 @@ public class LiveDataParserTest { "}\n"; SourceCodePainter painter = run(name -> null, sourceCode); - verify(painter, times(4)).paintBackground(eq(CodeWalkthrough.ACTIVE_STATEMENT), any()); + verify(painter, times(7)).paintBackground(eq(CodeWalkthrough.ACTIVE_STATEMENT), any()); } @Test