GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — [core] BaseAntlrTerminalNode should return type instead of index for getTokenKind() · Issue #6471 · pmd/pmd Closed DescriptionAffects PMD Version: 7.21.0 Description: Creating a custom Kotlin rule using Java we found that BaseAntlrInnerNode#getToken(s) would always return null. This filter fails: .filter(it -> it.getTokenKind() == kind) due to protected int getTokenKind() { return antlrNode.symbol.getTokenIndex(); } Fix is to change that to This can fail in antlr4 base Kotlin parser and perhaps also in the Swift parser. Code Sample demonstrating the issue: String code = "class Foo { fun foo() { var a = 42; a += 1 } }"; // Parse using KotlinParsingHelper KtKotlinFile root = KotlinParsingHelper.DEFAULT.parse(code); assertNotNull(root); // Traverse to the first function declaration in the file KtFunctionDeclaration fn = root.descendants(KtFunctionDeclaration.class).first(); assertNotNull(fn, "Expected a function declaration in the parsed Kotlin file"); // Find the first KtAssignmentAndOperator node within the function body KtAssignmentAndOperator idNode = fn.descendants(KtAssignmentAndOperator.class).first(); assertNotNull(idNode, "Expected a assignmentAndOperator within the function node"); // Call the generated accessor that returns the ADD_ASSIGNMENT terminal node. // This calls getToken/getTokens under the hood and will exercise // BaseAntlrInnerNode#getToken(s). TerminalNode tn = idNode.ADD_ASSIGNMENT(); assertNotNull(tn, "Expected an ADD_ASSIGNMENT terminal node"); assertEquals("+=", tn.getText()); assertEquals(ADD_ASSIGNMENT, tn.getSymbol().getType()); Steps to reproduce: Run the unit test above, will submit this in a PR. Running PMD through: [custom Kotlin Java rule] Activity
|
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |