From 90071c69b850a0f3c79d7a67b3b51f51af61bb80 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Sun, 28 Sep 2014 12:11:35 -0500 Subject: [PATCH] Fix getSourceName returning null (fixes #667) --- runtime/Java/src/org/antlr/v4/runtime/ANTLRInputStream.java | 4 ++++ .../Java/src/org/antlr/v4/runtime/UnbufferedCharStream.java | 4 ++++ tool/test/org/antlr/v4/test/BaseTest.java | 2 +- tool/test/org/antlr/v4/test/TestCommonTokenStream.java | 5 +++-- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/runtime/Java/src/org/antlr/v4/runtime/ANTLRInputStream.java b/runtime/Java/src/org/antlr/v4/runtime/ANTLRInputStream.java index d120b1c96..62c562e3f 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/ANTLRInputStream.java +++ b/runtime/Java/src/org/antlr/v4/runtime/ANTLRInputStream.java @@ -238,6 +238,10 @@ public class ANTLRInputStream implements CharStream { @Override public String getSourceName() { + if (name == null || name.isEmpty()) { + return UNKNOWN_SOURCE_NAME; + } + return name; } diff --git a/runtime/Java/src/org/antlr/v4/runtime/UnbufferedCharStream.java b/runtime/Java/src/org/antlr/v4/runtime/UnbufferedCharStream.java index d07e0ec21..eb23ae714 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/UnbufferedCharStream.java +++ b/runtime/Java/src/org/antlr/v4/runtime/UnbufferedCharStream.java @@ -297,6 +297,10 @@ public class UnbufferedCharStream implements CharStream { @Override public String getSourceName() { + if (name == null || name.isEmpty()) { + return UNKNOWN_SOURCE_NAME; + } + return name; } diff --git a/tool/test/org/antlr/v4/test/BaseTest.java b/tool/test/org/antlr/v4/test/BaseTest.java index ee48dcf3b..0fafb0c72 100644 --- a/tool/test/org/antlr/v4/test/BaseTest.java +++ b/tool/test/org/antlr/v4/test/BaseTest.java @@ -1269,7 +1269,7 @@ public abstract class BaseTest { @Override public String getSourceName() { - return null; + return UNKNOWN_SOURCE_NAME; } @Override diff --git a/tool/test/org/antlr/v4/test/TestCommonTokenStream.java b/tool/test/org/antlr/v4/test/TestCommonTokenStream.java index a58451568..2578d093b 100644 --- a/tool/test/org/antlr/v4/test/TestCommonTokenStream.java +++ b/tool/test/org/antlr/v4/test/TestCommonTokenStream.java @@ -33,6 +33,7 @@ package org.antlr.v4.test; import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.CommonToken; import org.antlr.v4.runtime.CommonTokenStream; +import org.antlr.v4.runtime.IntStream; import org.antlr.v4.runtime.Lexer; import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.TokenFactory; @@ -235,7 +236,7 @@ public class TestCommonTokenStream extends TestBufferedTokenStream { @Override public String getSourceName() { - return null; + return IntStream.UNKNOWN_SOURCE_NAME; } @Override @@ -283,7 +284,7 @@ public class TestCommonTokenStream extends TestBufferedTokenStream { @Override public String getSourceName() { - return null; + return IntStream.UNKNOWN_SOURCE_NAME; } @Override