+48
-7
lines changedFilter options
+48
-7
lines changed Original file line number Diff line number Diff line change
@@ -2540,7 +2540,7 @@ void PrimaryExpression() #void :
2540
2540
Expressions that may be present at the start of a primary expression.
2541
2541
*/
2542
2542
void PrimaryPrefix() #void :
2543
-
{Token t;}
2543
+
{Token savedStart;}
2544
2544
{
2545
2545
Literal()
2546
2546
| "this" #ThisExpression
@@ -2560,7 +2560,14 @@ void PrimaryPrefix() #void :
2560
2560
2561
2561
| LOOKAHEAD(LambdaLahead()) LambdaExpression()
2562
2562
2563
-
| "(" Expression() ")" { AstImplUtil.bumpParenDepth((ASTExpression) jjtree.peekNode()); }
2563
+
// Parenthesized expr, we need to adjust start/end tokens
2564
+
| "(" {savedStart = getToken(0);} Expression() ")"
2565
+
{
2566
+
AstImplUtil.bumpParenDepth((ASTExpression) jjtree.peekNode());
2567
+
AbstractJavaNode top = (AbstractJavaNode) jjtree.peekNode();
2568
+
top.jjtSetFirstToken(savedStart);
2569
+
top.jjtSetLastToken(getToken(0));
2570
+
}
2564
2571
// If it is an ambiguous name, then we may go on
2565
2572
// into the next step, which is less restricted
2566
2573
// than PrimarySuffix
Original file line number Diff line number Diff line change
@@ -76,6 +76,7 @@ object CustomTreePrinter : KotlintestBeanTreePrinter<Node>(NodeTreeLikeAdapter)
76
76
77
77
}
78
78
79
+
// invariants that should be preserved always
79
80
private val javaImplicitAssertions: Assertions<Node> = {
80
81
DefaultMatchingConfig.implicitAssertions(it)
81
82
@@ -86,6 +87,11 @@ private val javaImplicitAssertions: Assertions<Node> = {
86
87
it::isBooleanLiteral shouldBe (it is ASTBooleanLiteral)
87
88
it::isNullLiteral shouldBe (it is ASTNullLiteral)
88
89
}
90
+
91
+
if (it is ASTExpression) run {
92
+
it::isParenthesized shouldBe (it.parenthesisDepth > 0)
93
+
}
94
+
89
95
}
90
96
91
97
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
4
4
5
5
package net.sourceforge.pmd.lang.java.ast
6
6
7
+
import io.kotlintest.shouldBe
7
8
import net.sourceforge.pmd.lang.ast.test.shouldBe
8
9
import net.sourceforge.pmd.lang.java.ast.ASTPrimitiveType.PrimitiveType.INT
9
10
import net.sourceforge.pmd.lang.java.ast.ParserTestCtx.Companion.StatementParsingCtx
@@ -46,6 +47,8 @@ class ParenthesesTest : ParserTestSpec({
46
47
it::getInitializer shouldBe int(3) {
47
48
it::getParenthesisDepth shouldBe 2
48
49
it::isParenthesized shouldBe true
50
+
51
+
it.tokenList().map { it.image } shouldBe listOf("(", "(", "3", ")", ")")
49
52
}
50
53
}
51
54
}
@@ -60,6 +63,8 @@ class ParenthesesTest : ParserTestSpec({
60
63
it::getLhsExpression shouldBe variableRef("a") {
61
64
it::getParenthesisDepth shouldBe 2
62
65
it::isParenthesized shouldBe true
66
+
67
+
it.tokenList().map { it.image } shouldBe listOf("(", "(", "a", ")", ")")
63
68
}
64
69
}
65
70
}
@@ -71,9 +76,13 @@ class ParenthesesTest : ParserTestSpec({
71
76
it::getParenthesisDepth shouldBe 1
72
77
it::isParenthesized shouldBe true
73
78
79
+
it.tokenList().map { it.image } shouldBe listOf("(", "(", "a", ")", ".", "f", ")")
80
+
74
81
it::getLhsExpression shouldBe variableRef("a") {
75
82
it::getParenthesisDepth shouldBe 1
76
83
it::isParenthesized shouldBe true
84
+
85
+
it.tokenList().map { it.image } shouldBe listOf("(", "a", ")")
77
86
}
78
87
}
79
88
}
@@ -87,15 +96,25 @@ class ParenthesesTest : ParserTestSpec({
87
96
it::getParenthesisDepth shouldBe 1
88
97
it::isParenthesized shouldBe true
89
98
99
+
it.tokenList().map { it.image } shouldBe
100
+
listOf("(", "(", "1", "+", "2", ")", "+", "f", ")")
101
+
90
102
additiveExpr(BinaryOp.ADD) {
91
103
it::getParenthesisDepth shouldBe 1
92
104
it::isParenthesized shouldBe true
93
105
106
+
107
+
it.tokenList().map { it.image } shouldBe
108
+
listOf("(", "1", "+", "2", ")")
109
+
94
110
int(1)
95
111
int(2)
96
112
}
97
113
98
-
variableRef("f")
114
+
variableRef("f") {
115
+
it::isParenthesized shouldBe false
116
+
it::getParenthesisDepth shouldBe 0
117
+
}
99
118
}
100
119
}
101
120
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
1
1
package net.sourceforge.pmd.lang.java.ast
2
2
3
3
import com.github.oowekyala.treeutils.matchers.TreeNodeWrapper
4
+
import net.sourceforge.pmd.lang.ast.GenericToken
4
5
import net.sourceforge.pmd.lang.ast.Node
5
-
import net.sourceforge.pmd.lang.ast.test.NodeSpec
6
-
import net.sourceforge.pmd.lang.ast.test.ValuedNodeSpec
7
-
import net.sourceforge.pmd.lang.ast.test.shouldBe
8
-
import net.sourceforge.pmd.lang.ast.test.shouldMatch
6
+
import net.sourceforge.pmd.lang.ast.test.*
9
7
import net.sourceforge.pmd.lang.java.ast.ASTPrimitiveType.PrimitiveType.*
10
8
import java.util.*
11
9
import kotlin.reflect.KCallable
@@ -28,6 +26,17 @@ infix fun <T, U : T> KCallable<Optional<T>>.shouldBePresent(any: U) = this shoul
28
26
::get shouldBe any
29
27
}
30
28
29
+
fun JavaNode.tokenList(): List<GenericToken> {
30
+
val lst = mutableListOf<GenericToken>()
31
+
var t = firstToken
32
+
lst += t
33
+
while (t != lastToken) {
34
+
t = t.next
35
+
lst += t
36
+
}
37
+
return lst
38
+
}
39
+
31
40
fun String.addArticle() = when (this[0].toLowerCase()) {
32
41
'a', 'e', 'i', 'o', 'u' -> "an $this"
33
42
else -> "a $this"
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4