Skip to content

Commit 169c786

Browse files
committed
More
1 parent 8159c1f commit 169c786

28 files changed

Lines changed: 783 additions & 618 deletions

.claude/settings.local.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
"Bash(../gradlew test:*)",
3939
"Bash(./gradlew :rewrite-scala:test --tests \"org.openrewrite.scala.tree.MethodInvocationTest.methodCallOnFieldAccess\" -i)",
4040
"Bash(touch:*)",
41-
"Bash(sed:*)"
41+
"Bash(sed:*)",
42+
"Bash(../gradlew :rewrite-scala:compileTestJava)"
4243
],
4344
"deny": []
4445
}

DebugAssignment.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object Test {
2+
var (a, b) = (1, 2)
3+
println(s"a = $a, b = $b")
4+
5+
// This is the problematic line
6+
(a, b) = (3, 4)
7+
println(s"After assignment: a = $a, b = $b")
8+
}

DebugSpans.class

1.57 KB
Binary file not shown.

DebugSpans.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class DebugSpans {
2+
public static void main(String[] args) {
3+
String code = "object Test {\n var (a, b) = (1, 2)\n (a, b) = (3, 4)\n}";
4+
System.out.println("Source code:");
5+
System.out.println(code);
6+
System.out.println("\nLine 3: '(a, b) = (3, 4)'");
7+
8+
// Find the position of the second tuple
9+
int lineStart = code.indexOf(" (a, b)");
10+
System.out.println("Start of line 3: position " + lineStart);
11+
12+
for (int i = lineStart; i < lineStart + 20 && i < code.length(); i++) {
13+
char c = code.charAt(i);
14+
System.out.printf(" pos %2d: '%s'\n", i, c == '\n' ? "\\n" : String.valueOf(c));
15+
}
16+
}
17+
}

DebugTupleSpans.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import org.openrewrite.scala.ScalaParser;
2+
import org.openrewrite.scala.tree.S;
3+
import org.openrewrite.java.tree.J;
4+
5+
public class DebugTupleSpans {
6+
public static void main(String[] args) {
7+
String code = "object Test {\n var (a, b) = (1, 2)\n (a, b) = (3, 4)\n}";
8+
System.out.println("Source code:");
9+
System.out.println(code);
10+
System.out.println("\nCharacter positions:");
11+
for (int i = 0; i < code.length(); i++) {
12+
char c = code.charAt(i);
13+
System.out.printf("%2d: '%s'\n", i, c == '\n' ? "\\n" : String.valueOf(c));
14+
}
15+
}
16+
}

PartialTest.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class Test { def add(x: Int, y: Int): Int = x + y; val addFive = add(5, _) }

TestDebugTuple.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Test {
2+
var (a, b) = (1, 2)
3+
(a, b) = (3, 4)
4+
}

TestSpanDebug.scala

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import dotty.tools.dotc.ast.untpd
2+
import dotty.tools.dotc.core.Contexts.*
3+
import dotty.tools.dotc.parsing.Parsers.Parser
4+
import dotty.tools.dotc.util.SourceFile
5+
import dotty.tools.dotc.CompilationUnit
6+
import dotty.tools.dotc.core.Contexts.Context
7+
import dotty.tools.dotc.Driver
8+
import dotty.tools.dotc.config.Settings
9+
10+
object TestSpanDebug {
11+
def main(args: Array[String]): Unit = {
12+
val code = """object Test {
13+
var (a, b) = (1, 2)
14+
(a, b) = (3, 4)
15+
}"""
16+
17+
// Setup compiler context
18+
val driver = new Driver
19+
given Context = driver.initCtx.fresh
20+
21+
val source = SourceFile.virtual("test.scala", code)
22+
val unit = CompilationUnit(source)
23+
val parser = Parser(source)
24+
val tree = parser.parse()
25+
26+
def showTree(t: untpd.Tree, indent: Int = 0): Unit = {
27+
val prefix = " " * indent
28+
val span = t.span
29+
val spanStr = if (span.exists) {
30+
val start = span.start
31+
val end = span.end
32+
val content = if (start >= 0 && end <= code.length) {
33+
code.substring(start, end).replace("\n", "\\n")
34+
} else "???"
35+
s"[${start}-${end}] '$content'"
36+
} else "[no span]"
37+
38+
println(s"${prefix}${t.getClass.getSimpleName}: $spanStr")
39+
40+
t match {
41+
case pkg: untpd.PackageDef =>
42+
pkg.stats.foreach(showTree(_, indent + 1))
43+
case mod: untpd.ModuleDef =>
44+
mod.impl.body.foreach(showTree(_, indent + 1))
45+
case vd: untpd.ValDef =>
46+
println(s"${prefix} name: ${vd.name}")
47+
if (vd.tpt != null) showTree(vd.tpt, indent + 1)
48+
if (vd.rhs != null) showTree(vd.rhs, indent + 1)
49+
case asg: untpd.Assign =>
50+
println(s"${prefix} LHS:")
51+
showTree(asg.lhs, indent + 2)
52+
println(s"${prefix} RHS:")
53+
showTree(asg.rhs, indent + 2)
54+
case tuple: untpd.Tuple =>
55+
println(s"${prefix} Elements:")
56+
tuple.trees.foreach(showTree(_, indent + 2))
57+
case _ =>
58+
// Show children
59+
t.productIterator.foreach {
60+
case child: untpd.Tree => showTree(child, indent + 1)
61+
case list: List[_] => list.foreach {
62+
case tree: untpd.Tree => showTree(tree, indent + 1)
63+
case _ =>
64+
}
65+
case _ =>
66+
}
67+
}
68+
}
69+
70+
showTree(tree)
71+
}
72+
}

TupleTest.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Test {
2+
var (a, b) = (1, 2)
3+
(a, b) = (3, 4)
4+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Test {
2+
println("Testing tuple pattern")
3+
val (a, b) = (1, 2)
4+
println(s"a=$a, b=$b")
5+
}

0 commit comments

Comments
 (0)