-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
8324789: Add line number information to code models
Reviewed-by: mcimadamore
- Loading branch information
Paul Sandoz
committed
Apr 25, 2024
1 parent
628a931
commit 9f35792
Showing
14 changed files
with
487 additions
and
42 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/java.base/share/classes/java/lang/reflect/code/Location.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package java.lang.reflect.code; | ||
|
||
/** | ||
* Source location information. | ||
* | ||
* @param sourceRef the reference to the source | ||
* @param line the line in the source | ||
* @param column the column in the source | ||
*/ | ||
public record Location(String sourceRef, int line, int column) { | ||
|
||
/** | ||
* The location value, {@code null}, indicating no location information. | ||
*/ | ||
public static final Location NO_LOCATION = null; | ||
|
||
public Location(int line, int column) { | ||
this(null, line, column); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder s = new StringBuilder(); | ||
s.append(line).append(":").append(column); | ||
if (sourceRef != null) { | ||
s.append(":").append(sourceRef); | ||
} | ||
return s.toString(); | ||
} | ||
|
||
public static Location fromString(String s) { | ||
String[] split = s.split(":", 3); | ||
if (split.length < 2) { | ||
throw new IllegalArgumentException(); | ||
} | ||
|
||
int line = Integer.parseInt(split[0]); | ||
int column = Integer.parseInt(split[1]); | ||
String sourceRef; | ||
if (split.length == 3) { | ||
sourceRef = split[2]; | ||
} else { | ||
sourceRef = null; | ||
} | ||
return new Location(sourceRef, line, column); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.