live data progress
This commit is contained in:
parent
eae9dea247
commit
e2a44063ec
|
@ -16,6 +16,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import static com.devexperts.logging.Logging.getLogging;
|
||||
|
@ -46,14 +47,24 @@ public class CodeWalkthrough {
|
|||
|
||||
java.util.List<TerminalNode> allTerminals = new java.util.ArrayList<>();
|
||||
|
||||
java.util.List<CPP14Parser.DeclaratorContext> functions = new ArrayList<>();
|
||||
List<CPP14Parser.UnqualifiedIdContext> functions = new ArrayList<>();
|
||||
|
||||
new ParseTreeWalker().walk(new CPP14ParserBaseListener() {
|
||||
@Override
|
||||
public void enterFunctionDefinition(CPP14Parser.FunctionDefinitionContext ctx) {
|
||||
// new method is starting new all over
|
||||
resetState(currentState);
|
||||
functions.add(ctx.declarator());
|
||||
CPP14Parser.DeclaratoridContext declaratorid = ctx.declarator().pointerDeclarator().noPointerDeclarator().noPointerDeclarator().declaratorid();
|
||||
CPP14Parser.IdExpressionContext idExpressionContext = declaratorid.idExpression();
|
||||
CPP14Parser.QualifiedIdContext qualifiedIdContext = idExpressionContext.qualifiedId();
|
||||
CPP14Parser.UnqualifiedIdContext unqualifiedIdContext;
|
||||
if (qualifiedIdContext != null) {
|
||||
unqualifiedIdContext = qualifiedIdContext.unqualifiedId();
|
||||
} else {
|
||||
unqualifiedIdContext = idExpressionContext.unqualifiedId();
|
||||
}
|
||||
System.out.println(declaratorid.getText());
|
||||
functions.add(unqualifiedIdContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -179,7 +190,7 @@ public class CodeWalkthrough {
|
|||
configTokens.add(token);
|
||||
}
|
||||
}
|
||||
return new ParseResult(configTokens, brokenConditions);
|
||||
return new ParseResult(configTokens, brokenConditions, functions);
|
||||
}
|
||||
|
||||
private static void resetState(Stack<BranchingState> currentState) {
|
||||
|
|
|
@ -1,19 +1,22 @@
|
|||
package com.rusefi.livedata;
|
||||
|
||||
import com.rusefi.livedata.generated.CPP14Parser;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ParseResult {
|
||||
static ParseResult VOID = new ParseResult(Collections.emptyList(), Collections.emptyList());
|
||||
static ParseResult VOID = new ParseResult(Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
|
||||
|
||||
private final List<Token> configTokens;
|
||||
private final List<String> brokenConditions;
|
||||
private final List<CPP14Parser.UnqualifiedIdContext> functions;
|
||||
|
||||
public ParseResult(List<Token> configTokens, java.util.List<String> brokenConditions) {
|
||||
public ParseResult(List<Token> configTokens, List<String> brokenConditions, List<CPP14Parser.UnqualifiedIdContext> functions) {
|
||||
this.configTokens = configTokens;
|
||||
this.brokenConditions = brokenConditions;
|
||||
this.functions = functions;
|
||||
}
|
||||
|
||||
public List<Token> getConfigTokens() {
|
||||
|
@ -23,4 +26,8 @@ public class ParseResult {
|
|||
public List<String> geBrokenConditions() {
|
||||
return brokenConditions;
|
||||
}
|
||||
|
||||
public List<CPP14Parser.UnqualifiedIdContext> getFunctions() {
|
||||
return functions;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,7 @@ import java.util.TreeMap;
|
|||
|
||||
import static com.rusefi.CodeWalkthrough.TRUE_CONDITION;
|
||||
import static com.rusefi.ui.LiveDataPane.CPP_SUFFIX;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
@ -43,6 +42,25 @@ public class LiveDataParserTest {
|
|||
verify(painter, times(7)).paintBackground(eq(CodeWalkthrough.ACTIVE_STATEMENT), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodNamesCode() {
|
||||
String sourceCode = "void AcController::onSlowCallback() {\n" +
|
||||
"}\n" +
|
||||
"void onSlowCallback2() {\n" +
|
||||
" }\n" +
|
||||
"int onSlowCallback3() {\n" +
|
||||
" }\n" +
|
||||
""
|
||||
;
|
||||
|
||||
SourceCodePainter painter = mock(SourceCodePainter.class);
|
||||
ParseTree tree = LiveDataParserPanel.getParseTree(sourceCode);
|
||||
|
||||
printTree(tree);
|
||||
ParseResult result = CodeWalkthrough.applyVariables(name -> null, sourceCode, painter, tree);
|
||||
assertEquals(3, result.getFunctions().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsing() {
|
||||
Map<String, Double> values = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
|
|
@ -624,8 +624,7 @@ public class PrintCPP14ParserListener implements CPP14ParserListener {
|
|||
|
||||
@Override
|
||||
public void enterCompoundStatement(CPP14Parser.CompoundStatementContext ctx) {
|
||||
printWithCounter("enterCompoundStatement " + ctx.statementSeq().getText());
|
||||
|
||||
printWithCounter("enterCompoundStatement " + (ctx.statementSeq() != null ? ctx.statementSeq().getText() : ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue