Skip to content

Commit 9ff8d1c

Browse files
committed
Fix Token generation
1 parent df52a12 commit 9ff8d1c

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

languages/java-cpg/src/main/java/de/jplag/java_cpg/token/CpgTokenConsumer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public abstract class CpgTokenConsumer implements TokenConsumer {
2727
* length of any sensible line of code.
2828
*/
2929
private static final int MULTILINE_TOKEN_LENGTH = 1024;
30-
private File currentFile;
3130

3231
private static int calculateLength(Region region) {
3332
if (region.getEndLine() == region.startLine) {
@@ -49,11 +48,10 @@ public void addToken(TokenType type, Node node, boolean isEndToken) {
4948
File file;
5049
Region region;
5150
if (Objects.isNull(location)) {
52-
file = currentFile;
53-
region = new Region();
51+
// implicit node, e.g., declaration of API classes - we do not want tokens for those.
52+
return;
5453
} else {
5554
file = new File(location.getArtifactLocation().getUri());
56-
currentFile = file;
5755
region = location.getRegion();
5856
}
5957

@@ -62,6 +60,8 @@ public void addToken(TokenType type, Node node, boolean isEndToken) {
6260
int line = isEndToken ? region.getEndLine() : region.startLine;
6361
int column = isEndToken ? region.getEndColumn() - 1 : region.startColumn;
6462
newRegion = new Region(line, column, line, column + 1);
63+
} else if (node.getAstChildren().isEmpty()) {
64+
newRegion = region;
6565
} else {
6666

6767
List<Region> childRegions = node.getAstChildren().stream().map(Node::getLocation).filter(Objects::nonNull)

0 commit comments

Comments
 (0)