From 95bac5eb950c8859a1805eefc2673d2adf021add Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sat, 18 Apr 2020 12:50:34 +0200 Subject: [PATCH] Convert CharStream to class --- .../pmd/cpd/internal/JavaCCTokenizer.java | 5 +- .../pmd/lang/ast/impl/io/NewCharStream.java | 84 ------------------- .../ast/{ => impl/javacc}/CharStream.java | 84 +++++++++++++------ .../{io => javacc}/EscapeAwareReader.java | 6 +- .../impl/{io => javacc}/EscapeTracker.java | 21 +++-- .../impl/{io => javacc}/JavaInputReader.java | 6 +- .../pmd/lang/ast/impl/javacc/JavaccToken.java | 1 - .../ast/impl/javacc/JavaccTokenDocument.java | 2 - .../ast/impl/javacc/JjtreeParserAdapter.java | 4 +- .../lang/ast/impl/io/JavaInputReaderTest.java | 1 + .../ast/impl/javacc/CharStreamImplTest.java | 8 +- .../net/sourceforge/pmd/cpd/CPPTokenizer.java | 4 +- .../pmd/lang/cpp/ast/CppEscapeReader.java | 2 +- .../pmd/cpd/CppCharStreamTest.java | 5 +- pmd-java/etc/grammar/Java.jjt | 2 +- .../sourceforge/pmd/cpd/JavaTokenizer.java | 2 +- .../pmd/lang/java/ast/JavaParser.java | 2 +- .../pmd/lang/java/ast/JavaTokenDocument.java | 6 +- .../pmd/cpd/EcmascriptTokenizer.java | 2 +- pmd-jsp/etc/grammar/Jsp.jjt | 2 +- .../net/sourceforge/pmd/cpd/JSPTokenizer.java | 6 +- .../pmd/lang/jsp/ast/JspParser.java | 2 +- .../sourceforge/pmd/cpd/MatlabTokenizer.java | 2 +- .../pmd/cpd/ModelicaTokenizer.java | 2 +- .../pmd/lang/modelica/ast/ModelicaParser.java | 2 +- .../pmd/cpd/ObjectiveCTokenizer.java | 2 +- pmd-plsql/etc/grammar/PLSQL.jjt | 2 +- .../sourceforge/pmd/cpd/PLSQLTokenizer.java | 2 +- .../pmd/lang/plsql/ast/PLSQLParser.java | 2 +- .../sourceforge/pmd/cpd/PythonTokenizer.java | 2 +- pmd-visualforce/etc/grammar/Vf.jjt | 2 +- .../net/sourceforge/pmd/cpd/VfTokenizer.java | 6 +- .../sourceforge/pmd/lang/vf/ast/VfParser.java | 2 +- pmd-vm/etc/grammar/Vm.jjt | 2 +- .../sourceforge/pmd/lang/vm/ast/VmParser.java | 2 +- 35 files changed, 118 insertions(+), 169 deletions(-) delete mode 100644 pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/io/NewCharStream.java rename pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/{ => impl/javacc}/CharStream.java (60%) rename pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/{io => javacc}/EscapeAwareReader.java (97%) rename pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/{io => javacc}/EscapeTracker.java (95%) rename pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/{io => javacc}/JavaInputReader.java (96%) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/internal/JavaCCTokenizer.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/internal/JavaCCTokenizer.java index 5e3c06a735..7f6b906172 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/internal/JavaCCTokenizer.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/internal/JavaCCTokenizer.java @@ -13,9 +13,8 @@ import net.sourceforge.pmd.cpd.Tokens; import net.sourceforge.pmd.cpd.token.JavaCCTokenFilter; import net.sourceforge.pmd.cpd.token.TokenFilter; import net.sourceforge.pmd.lang.TokenManager; -import net.sourceforge.pmd.lang.ast.CharStream; import net.sourceforge.pmd.lang.ast.TokenMgrError; -import net.sourceforge.pmd.lang.ast.impl.io.NewCharStream; +import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument; import net.sourceforge.pmd.util.document.TextDocument; @@ -27,7 +26,7 @@ public abstract class JavaCCTokenizer implements Tokenizer { protected TokenManager getLexerForSource(SourceCode sourceCode) throws IOException { TextDocument textDocument = TextDocument.create(TextFile.cpdCompat(sourceCode)); JavaccTokenDocument tokenDoc = newTokenDoc(textDocument); - return makeLexerImpl(NewCharStream.open(tokenDoc)); + return makeLexerImpl(CharStream.create(tokenDoc)); } protected JavaccTokenDocument newTokenDoc(TextDocument textDoc) { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/io/NewCharStream.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/io/NewCharStream.java deleted file mode 100644 index dd8ded5daf..0000000000 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/io/NewCharStream.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.lang.ast.impl.io; - -import java.io.EOFException; -import java.io.IOException; - -import net.sourceforge.pmd.lang.ast.CharStream; -import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument; -import net.sourceforge.pmd.util.document.FileLocation; -import net.sourceforge.pmd.util.document.TextDocument; - -public class NewCharStream implements CharStream { - - private final JavaccTokenDocument document; - private final EscapeTracker.Cursor cursor; - - private NewCharStream(JavaccTokenDocument document, EscapeTracker.Cursor cursor) { - this.document = document; - this.cursor = cursor; - } - - public static CharStream open(JavaccTokenDocument doc) throws IOException { - try (EscapeAwareReader reader = doc.newReader(doc.getTextDocument().getText())) { - reader.translate(); - return new NewCharStream(doc, reader.escapes.new Cursor(reader.input)); - } - } - - @Override - public JavaccTokenDocument getTokenDocument() { - return document; - } - - @Override - public char readChar() throws EOFException { - return cursor.next(); - } - - @Override - public char BeginToken() throws EOFException { - cursor.mark(); - return cursor.next(); - } - - @Override - public String GetImage() { - StringBuilder sb = new StringBuilder(); - cursor.markToString(sb); - return sb.toString(); - } - - @Override - public void backup(int amount) { - cursor.backup(amount); - } - - @Override - public int getEndColumn() { - return endLocation().getEndColumn(); - } - - @Override - public int getEndLine() { - return endLocation().getEndLine(); - } - - private FileLocation endLocation() { - TextDocument textDoc = document.getTextDocument(); - return textDoc.toLocation(textDoc.createRegion(getEndOffset(), 0)); - } - - @Override - public int getStartOffset() { - return cursor.markOutOffset(); - } - - @Override - public int getEndOffset() { - return cursor.curOutOffset(); - } -} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/CharStream.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/CharStream.java similarity index 60% rename from pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/CharStream.java rename to pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/CharStream.java index 4565dafc42..a81d2af44a 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/CharStream.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/CharStream.java @@ -2,13 +2,14 @@ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ -package net.sourceforge.pmd.lang.ast; +package net.sourceforge.pmd.lang.ast.impl.javacc; import java.io.EOFException; import java.io.IOException; -import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument; +import net.sourceforge.pmd.util.document.FileLocation; +import net.sourceforge.pmd.util.document.TextDocument; /** * PMD flavour of character streams used by JavaCC parsers. @@ -17,7 +18,25 @@ import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument; * * rename methods to match decent naming conventions * * move to impl.javacc package */ -public interface CharStream { +public final class CharStream { + + private final JavaccTokenDocument tokenDoc; + private final EscapeTracker.Cursor cursor; + + private CharStream(JavaccTokenDocument tokenDoc, EscapeTracker.Cursor cursor) { + this.tokenDoc = tokenDoc; + this.cursor = cursor; + } + + /** + * Create a new char stream for the given document. + */ + public static CharStream create(JavaccTokenDocument doc) throws IOException { + try (EscapeAwareReader reader = doc.newReader(doc.getTextDocument().getText())) { + reader.translate(); + return new CharStream(doc, reader.escapes.new Cursor(reader.input)); + } + } /** * Returns the next character from the input. After a {@link #backup(int)}, @@ -26,9 +45,10 @@ public interface CharStream { * @return The next character * * @throws EOFException Upon EOF - * @throws IOException If the underlying char stream throws EOF */ - char readChar() throws IOException; + public char readChar() throws EOFException { + return cursor.next(); + } /** @@ -37,14 +57,21 @@ public interface CharStream { * the buffer between two successive calls to this method to implement * backup correctly. */ - char BeginToken() throws IOException; + public char BeginToken() throws EOFException { + cursor.mark(); + return cursor.next(); + } /** * Returns a string made up of characters from the token mark up to * to the current buffer position. */ - String GetImage(); + public String GetImage() { + StringBuilder sb = new StringBuilder(); + cursor.markToString(sb); + return sb.toString(); + } /** @@ -65,13 +92,13 @@ public interface CharStream { * @throws IndexOutOfBoundsException If len is greater than the length of the * current token */ - default char[] GetSuffix(int len) { + public char[] GetSuffix(int len) { String t = GetImage(); return t.substring(t.length() - len).toCharArray(); } - default void appendSuffix(StringBuilder sb, int len) { + public void appendSuffix(StringBuilder sb, int len) { String t = GetImage(); sb.append(t, t.length() - len, t.length()); } @@ -89,41 +116,46 @@ public interface CharStream { * @throws AssertionError If the requested amount is greater than the * number of read chars */ - void backup(int amount); - + public void backup(int amount) { + cursor.backup(amount); + } /** Returns the column number of the last character for the current token. */ - int getEndColumn(); - - - /** Returns the line number of the last character for current token. */ - int getEndLine(); - - - default int getBeginColumn() { - return -1; + public int getEndColumn() { + return endLocation().getEndColumn(); } - default int getBeginLine() { - return -1; + /** Returns the line number of the last character for current token. */ + public int getEndLine() { + return endLocation().getEndLine(); + } + + + private FileLocation endLocation() { + TextDocument textDoc = tokenDoc.getTextDocument(); + return textDoc.toLocation(textDoc.createRegion(getEndOffset(), 0)); } /** Returns the start offset of the current token (in the original source), inclusive. */ - int getStartOffset(); + public int getStartOffset() { + return cursor.markOutOffset(); + } /** Returns the end offset of the current token (in the original source), exclusive. */ - int getEndOffset(); + public int getEndOffset() { + return cursor.curOutOffset(); + } /** * Returns the token document for the tokens being built. Having it * here is the most convenient place for the time being. */ - default JavaccTokenDocument getTokenDocument() { - return null; // for VelocityCharStream + public JavaccTokenDocument getTokenDocument() { + return tokenDoc; } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/io/EscapeAwareReader.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/EscapeAwareReader.java similarity index 97% rename from pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/io/EscapeAwareReader.java rename to pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/EscapeAwareReader.java index fa8412e920..8b0f8eb0e1 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/io/EscapeAwareReader.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/EscapeAwareReader.java @@ -2,7 +2,11 @@ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ -package net.sourceforge.pmd.lang.ast.impl.io; +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.ast.impl.javacc; import static java.lang.Integer.min; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/io/EscapeTracker.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/EscapeTracker.java similarity index 95% rename from pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/io/EscapeTracker.java rename to pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/EscapeTracker.java index 5c9bd03921..9745741c6c 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/io/EscapeTracker.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/EscapeTracker.java @@ -2,7 +2,11 @@ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ -package net.sourceforge.pmd.lang.ast.impl.io; +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.ast.impl.javacc; import static java.lang.Integer.max; @@ -122,7 +126,6 @@ class EscapeTracker { /** Backend for a CharStream. */ class Cursor { - /** * This is the index in buf of the next char to read, it always * holds that buf[pos] is a valid character. @@ -158,7 +161,7 @@ class EscapeTracker { this.buf = buf; } - char next() throws EOFException { + public char next() throws EOFException { if (pos == buf.length()) { throw new EOFException(); } @@ -178,7 +181,7 @@ class EscapeTracker { } - void backup(int numChars) { + public void backup(int numChars) { ensureMarked(); if (numChars > markLength()) { throw new IllegalArgumentException( @@ -217,13 +220,13 @@ class EscapeTracker { } } - void mark() { + public void mark() { this.mark = pos; this.markEscape = nextEscape; this.markOutOffset = outOffset; } - void markToString(StringBuilder sb) { + public void markToString(StringBuilder sb) { ensureMarked(); int prevLength = sb.length(); @@ -256,15 +259,15 @@ class EscapeTracker { assert markEscape <= escapeRecords.length : "Wrong escape mark"; } - int curOutOffset() { + public int curOutOffset() { return outOffset; } - int markOutOffset() { + public int markOutOffset() { return markOutOffset; } - int markLength() { + public int markLength() { return outOffset - markOutOffset; } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/io/JavaInputReader.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/JavaInputReader.java similarity index 96% rename from pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/io/JavaInputReader.java rename to pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/JavaInputReader.java index 7e3eb6f087..68f1970809 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/io/JavaInputReader.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/JavaInputReader.java @@ -2,7 +2,11 @@ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ -package net.sourceforge.pmd.lang.ast.impl.io; +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.ast.impl.javacc; import static java.lang.Integer.min; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/JavaccToken.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/JavaccToken.java index b57889ff55..d2e0c02045 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/JavaccToken.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/JavaccToken.java @@ -4,7 +4,6 @@ package net.sourceforge.pmd.lang.ast.impl.javacc; -import net.sourceforge.pmd.lang.ast.CharStream; import net.sourceforge.pmd.lang.ast.GenericToken; import net.sourceforge.pmd.util.document.FileLocation; import net.sourceforge.pmd.util.document.TextRegion; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/JavaccTokenDocument.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/JavaccTokenDocument.java index 8c0e82ce4a..896193d356 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/JavaccTokenDocument.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/JavaccTokenDocument.java @@ -7,9 +7,7 @@ package net.sourceforge.pmd.lang.ast.impl.javacc; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -import net.sourceforge.pmd.lang.ast.CharStream; import net.sourceforge.pmd.lang.ast.impl.TokenDocument; -import net.sourceforge.pmd.lang.ast.impl.io.EscapeAwareReader; import net.sourceforge.pmd.util.document.Chars; import net.sourceforge.pmd.util.document.TextDocument; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/JjtreeParserAdapter.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/JjtreeParserAdapter.java index e7625b446b..c37da63d78 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/JjtreeParserAdapter.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/JjtreeParserAdapter.java @@ -7,11 +7,9 @@ package net.sourceforge.pmd.lang.ast.impl.javacc; import java.io.IOException; import net.sourceforge.pmd.lang.Parser; -import net.sourceforge.pmd.lang.ast.CharStream; import net.sourceforge.pmd.lang.ast.ParseException; import net.sourceforge.pmd.lang.ast.RootNode; import net.sourceforge.pmd.lang.ast.TokenMgrError; -import net.sourceforge.pmd.lang.ast.impl.io.NewCharStream; import net.sourceforge.pmd.util.document.TextDocument; /** @@ -34,7 +32,7 @@ public abstract class JjtreeParserAdapter implements Parser JavaccTokenDocument doc = newDocumentImpl(task.getTextDocument()); try { - CharStream charStream = NewCharStream.open(doc); + CharStream charStream = CharStream.create(doc); return parseImpl(charStream, task); } catch (IOException e) { throw new TokenMgrError(-1, -1, task.getFileDisplayName(), "IO error", e); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/impl/io/JavaInputReaderTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/impl/io/JavaInputReaderTest.java index 3169ed9bde..61c2de1725 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/impl/io/JavaInputReaderTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/impl/io/JavaInputReaderTest.java @@ -10,6 +10,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.junit.Assert; import org.junit.Test; +import net.sourceforge.pmd.lang.ast.impl.javacc.JavaInputReader; import net.sourceforge.pmd.util.document.Chars; diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/impl/javacc/CharStreamImplTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/impl/javacc/CharStreamImplTest.java index 5e88930067..816d184e42 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/impl/javacc/CharStreamImplTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/impl/javacc/CharStreamImplTest.java @@ -14,10 +14,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import net.sourceforge.pmd.lang.ast.CharStream; -import net.sourceforge.pmd.lang.ast.impl.io.EscapeAwareReader; -import net.sourceforge.pmd.lang.ast.impl.io.JavaInputReader; -import net.sourceforge.pmd.lang.ast.impl.io.NewCharStream; import net.sourceforge.pmd.util.document.Chars; import net.sourceforge.pmd.util.document.TextDocument; @@ -139,11 +135,11 @@ public class CharStreamImplTest { } public static CharStream simpleCharStream(String abcd) throws IOException { - return NewCharStream.open(new JavaccTokenDocument(TextDocument.readOnlyString(abcd))); + return CharStream.create(new JavaccTokenDocument(TextDocument.readOnlyString(abcd))); } public static CharStream javaCharStream(String abcd) throws IOException { - return NewCharStream.open(new JavaccTokenDocument(TextDocument.readOnlyString(abcd)) { + return CharStream.create(new JavaccTokenDocument(TextDocument.readOnlyString(abcd)) { @Override public EscapeAwareReader newReader(Chars text) { return new JavaInputReader(text); diff --git a/pmd-cpp/src/main/java/net/sourceforge/pmd/cpd/CPPTokenizer.java b/pmd-cpp/src/main/java/net/sourceforge/pmd/cpd/CPPTokenizer.java index 6aa98771b6..9d0bcb4a93 100644 --- a/pmd-cpp/src/main/java/net/sourceforge/pmd/cpd/CPPTokenizer.java +++ b/pmd-cpp/src/main/java/net/sourceforge/pmd/cpd/CPPTokenizer.java @@ -13,8 +13,8 @@ import org.checkerframework.checker.nullness.qual.Nullable; import net.sourceforge.pmd.PMD; import net.sourceforge.pmd.cpd.internal.JavaCCTokenizer; import net.sourceforge.pmd.lang.TokenManager; -import net.sourceforge.pmd.lang.ast.CharStream; -import net.sourceforge.pmd.lang.ast.impl.io.EscapeAwareReader; +import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; +import net.sourceforge.pmd.lang.ast.impl.javacc.EscapeAwareReader; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument; import net.sourceforge.pmd.lang.cpp.ast.CppEscapeReader; diff --git a/pmd-cpp/src/main/java/net/sourceforge/pmd/lang/cpp/ast/CppEscapeReader.java b/pmd-cpp/src/main/java/net/sourceforge/pmd/lang/cpp/ast/CppEscapeReader.java index 4b3f3417b7..99f4581f5e 100644 --- a/pmd-cpp/src/main/java/net/sourceforge/pmd/lang/cpp/ast/CppEscapeReader.java +++ b/pmd-cpp/src/main/java/net/sourceforge/pmd/lang/cpp/ast/CppEscapeReader.java @@ -8,7 +8,7 @@ import static java.lang.Integer.min; import java.io.IOException; -import net.sourceforge.pmd.lang.ast.impl.io.EscapeAwareReader; +import net.sourceforge.pmd.lang.ast.impl.javacc.EscapeAwareReader; import net.sourceforge.pmd.util.document.Chars; public class CppEscapeReader extends EscapeAwareReader { diff --git a/pmd-cpp/src/test/java/net/sourceforge/pmd/cpd/CppCharStreamTest.java b/pmd-cpp/src/test/java/net/sourceforge/pmd/cpd/CppCharStreamTest.java index a8823f011f..fab00aab81 100644 --- a/pmd-cpp/src/test/java/net/sourceforge/pmd/cpd/CppCharStreamTest.java +++ b/pmd-cpp/src/test/java/net/sourceforge/pmd/cpd/CppCharStreamTest.java @@ -11,15 +11,14 @@ import java.io.IOException; import org.checkerframework.checker.nullness.qual.NonNull; import org.junit.Test; -import net.sourceforge.pmd.lang.ast.CharStream; -import net.sourceforge.pmd.lang.ast.impl.io.NewCharStream; +import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; import net.sourceforge.pmd.util.document.TextDocument; public class CppCharStreamTest { @NonNull public CharStream charStreamFor(String source) throws IOException { - return NewCharStream.open(new CPPTokenizer().newTokenDoc(TextDocument.readOnlyString(source))); + return CharStream.create(new CPPTokenizer().newTokenDoc(TextDocument.readOnlyString(source))); } @Test diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index 5fcf6d995d..b2eb1fbba4 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -240,7 +240,7 @@ import java.util.EnumSet; import java.util.List; import java.util.Set; import java.util.Map; -import net.sourceforge.pmd.lang.ast.CharStream; +import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; import net.sourceforge.pmd.lang.ast.GenericToken; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken; import net.sourceforge.pmd.lang.ast.Node; diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/cpd/JavaTokenizer.java b/pmd-java/src/main/java/net/sourceforge/pmd/cpd/JavaTokenizer.java index 83c69ae100..aa304b6ab2 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/cpd/JavaTokenizer.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/cpd/JavaTokenizer.java @@ -13,7 +13,7 @@ import net.sourceforge.pmd.cpd.internal.JavaCCTokenizer; import net.sourceforge.pmd.cpd.token.JavaCCTokenFilter; import net.sourceforge.pmd.cpd.token.TokenFilter; import net.sourceforge.pmd.lang.TokenManager; -import net.sourceforge.pmd.lang.ast.CharStream; +import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument; import net.sourceforge.pmd.lang.java.ast.InternalApiBridge; diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaParser.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaParser.java index a3bf759260..ea8a1b2b1b 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaParser.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaParser.java @@ -4,7 +4,7 @@ package net.sourceforge.pmd.lang.java.ast; -import net.sourceforge.pmd.lang.ast.CharStream; +import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; import net.sourceforge.pmd.lang.ast.ParseException; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument; import net.sourceforge.pmd.lang.ast.impl.javacc.JjtreeParserAdapter; diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaTokenDocument.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaTokenDocument.java index a3a67d2fb0..a1d74fe154 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaTokenDocument.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaTokenDocument.java @@ -14,9 +14,9 @@ import static net.sourceforge.pmd.lang.java.ast.JavaTokenKinds.WHITESPACE; import org.checkerframework.checker.nullness.qual.Nullable; -import net.sourceforge.pmd.lang.ast.CharStream; -import net.sourceforge.pmd.lang.ast.impl.io.EscapeAwareReader; -import net.sourceforge.pmd.lang.ast.impl.io.JavaInputReader; +import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; +import net.sourceforge.pmd.lang.ast.impl.javacc.EscapeAwareReader; +import net.sourceforge.pmd.lang.ast.impl.javacc.JavaInputReader; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument; import net.sourceforge.pmd.util.document.Chars; diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/cpd/EcmascriptTokenizer.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/cpd/EcmascriptTokenizer.java index 1294536009..d66d74949f 100644 --- a/pmd-javascript/src/main/java/net/sourceforge/pmd/cpd/EcmascriptTokenizer.java +++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/cpd/EcmascriptTokenizer.java @@ -6,7 +6,7 @@ package net.sourceforge.pmd.cpd; import net.sourceforge.pmd.cpd.internal.JavaCCTokenizer; import net.sourceforge.pmd.lang.TokenManager; -import net.sourceforge.pmd.lang.ast.CharStream; +import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken; import net.sourceforge.pmd.lang.ecmascript5.ast.Ecmascript5TokenKinds; diff --git a/pmd-jsp/etc/grammar/Jsp.jjt b/pmd-jsp/etc/grammar/Jsp.jjt index c5400e8b6c..9e4483a441 100644 --- a/pmd-jsp/etc/grammar/Jsp.jjt +++ b/pmd-jsp/etc/grammar/Jsp.jjt @@ -30,7 +30,7 @@ options { PARSER_BEGIN(JspParserImpl) package net.sourceforge.pmd.lang.jsp.ast; -import net.sourceforge.pmd.lang.ast.CharStream; +import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; import net.sourceforge.pmd.lang.ast.TokenMgrError; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken; diff --git a/pmd-jsp/src/main/java/net/sourceforge/pmd/cpd/JSPTokenizer.java b/pmd-jsp/src/main/java/net/sourceforge/pmd/cpd/JSPTokenizer.java index fcb65f40f2..48a62f5131 100644 --- a/pmd-jsp/src/main/java/net/sourceforge/pmd/cpd/JSPTokenizer.java +++ b/pmd-jsp/src/main/java/net/sourceforge/pmd/cpd/JSPTokenizer.java @@ -6,9 +6,9 @@ package net.sourceforge.pmd.cpd; import net.sourceforge.pmd.cpd.internal.JavaCCTokenizer; import net.sourceforge.pmd.lang.TokenManager; -import net.sourceforge.pmd.lang.ast.CharStream; -import net.sourceforge.pmd.lang.ast.impl.io.EscapeAwareReader; -import net.sourceforge.pmd.lang.ast.impl.io.JavaInputReader; +import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; +import net.sourceforge.pmd.lang.ast.impl.javacc.EscapeAwareReader; +import net.sourceforge.pmd.lang.ast.impl.javacc.JavaInputReader; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument; import net.sourceforge.pmd.lang.jsp.ast.JspTokenKinds; diff --git a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/JspParser.java b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/JspParser.java index da368c871b..6d8cf7f3a0 100644 --- a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/JspParser.java +++ b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/JspParser.java @@ -6,7 +6,7 @@ package net.sourceforge.pmd.lang.jsp.ast; import org.checkerframework.checker.nullness.qual.Nullable; -import net.sourceforge.pmd.lang.ast.CharStream; +import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; import net.sourceforge.pmd.lang.ast.ParseException; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument; import net.sourceforge.pmd.lang.ast.impl.javacc.JjtreeParserAdapter; diff --git a/pmd-matlab/src/main/java/net/sourceforge/pmd/cpd/MatlabTokenizer.java b/pmd-matlab/src/main/java/net/sourceforge/pmd/cpd/MatlabTokenizer.java index 3273203072..9459c44696 100644 --- a/pmd-matlab/src/main/java/net/sourceforge/pmd/cpd/MatlabTokenizer.java +++ b/pmd-matlab/src/main/java/net/sourceforge/pmd/cpd/MatlabTokenizer.java @@ -6,7 +6,7 @@ package net.sourceforge.pmd.cpd; import net.sourceforge.pmd.cpd.internal.JavaCCTokenizer; import net.sourceforge.pmd.lang.TokenManager; -import net.sourceforge.pmd.lang.ast.CharStream; +import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken; import net.sourceforge.pmd.lang.matlab.ast.MatlabTokenKinds; diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/cpd/ModelicaTokenizer.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/cpd/ModelicaTokenizer.java index 71f1bb930f..3258a3cda7 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/cpd/ModelicaTokenizer.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/cpd/ModelicaTokenizer.java @@ -7,7 +7,7 @@ package net.sourceforge.pmd.cpd; import net.sourceforge.pmd.cpd.internal.JavaCCTokenizer; import net.sourceforge.pmd.cpd.token.JavaCCTokenFilter; import net.sourceforge.pmd.lang.TokenManager; -import net.sourceforge.pmd.lang.ast.CharStream; +import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken; import net.sourceforge.pmd.lang.modelica.ast.ModelicaTokenKinds; diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ModelicaParser.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ModelicaParser.java index cda61a0ba1..058941d176 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ModelicaParser.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ModelicaParser.java @@ -4,7 +4,7 @@ package net.sourceforge.pmd.lang.modelica.ast; -import net.sourceforge.pmd.lang.ast.CharStream; +import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; import net.sourceforge.pmd.lang.ast.ParseException; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument; import net.sourceforge.pmd.lang.ast.impl.javacc.JjtreeParserAdapter; diff --git a/pmd-objectivec/src/main/java/net/sourceforge/pmd/cpd/ObjectiveCTokenizer.java b/pmd-objectivec/src/main/java/net/sourceforge/pmd/cpd/ObjectiveCTokenizer.java index e101af905d..acccfcd24a 100644 --- a/pmd-objectivec/src/main/java/net/sourceforge/pmd/cpd/ObjectiveCTokenizer.java +++ b/pmd-objectivec/src/main/java/net/sourceforge/pmd/cpd/ObjectiveCTokenizer.java @@ -6,7 +6,7 @@ package net.sourceforge.pmd.cpd; import net.sourceforge.pmd.cpd.internal.JavaCCTokenizer; import net.sourceforge.pmd.lang.TokenManager; -import net.sourceforge.pmd.lang.ast.CharStream; +import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken; import net.sourceforge.pmd.lang.objectivec.ast.ObjectiveCTokenKinds; diff --git a/pmd-plsql/etc/grammar/PLSQL.jjt b/pmd-plsql/etc/grammar/PLSQL.jjt index 097b6391ff..090f90e235 100644 --- a/pmd-plsql/etc/grammar/PLSQL.jjt +++ b/pmd-plsql/etc/grammar/PLSQL.jjt @@ -154,7 +154,7 @@ package net.sourceforge.pmd.lang.plsql.ast; import java.io.*; import net.sourceforge.pmd.lang.ast.Node; -import net.sourceforge.pmd.lang.ast.CharStream; +import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; import net.sourceforge.pmd.lang.ast.TokenMgrError; public class PLSQLParserImpl { diff --git a/pmd-plsql/src/main/java/net/sourceforge/pmd/cpd/PLSQLTokenizer.java b/pmd-plsql/src/main/java/net/sourceforge/pmd/cpd/PLSQLTokenizer.java index f302bc540e..77abbf8794 100644 --- a/pmd-plsql/src/main/java/net/sourceforge/pmd/cpd/PLSQLTokenizer.java +++ b/pmd-plsql/src/main/java/net/sourceforge/pmd/cpd/PLSQLTokenizer.java @@ -8,7 +8,7 @@ import java.util.Properties; import net.sourceforge.pmd.cpd.internal.JavaCCTokenizer; import net.sourceforge.pmd.lang.TokenManager; -import net.sourceforge.pmd.lang.ast.CharStream; +import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken; import net.sourceforge.pmd.lang.plsql.ast.PLSQLTokenKinds; diff --git a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/PLSQLParser.java b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/PLSQLParser.java index ed2cb3e08d..5cf6fa5ef7 100644 --- a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/PLSQLParser.java +++ b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/PLSQLParser.java @@ -6,7 +6,7 @@ package net.sourceforge.pmd.lang.plsql.ast; import org.checkerframework.checker.nullness.qual.Nullable; -import net.sourceforge.pmd.lang.ast.CharStream; +import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; import net.sourceforge.pmd.lang.ast.ParseException; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument; import net.sourceforge.pmd.lang.ast.impl.javacc.JjtreeParserAdapter; diff --git a/pmd-python/src/main/java/net/sourceforge/pmd/cpd/PythonTokenizer.java b/pmd-python/src/main/java/net/sourceforge/pmd/cpd/PythonTokenizer.java index 9e61ea2067..70755980ea 100644 --- a/pmd-python/src/main/java/net/sourceforge/pmd/cpd/PythonTokenizer.java +++ b/pmd-python/src/main/java/net/sourceforge/pmd/cpd/PythonTokenizer.java @@ -10,7 +10,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import net.sourceforge.pmd.cpd.internal.JavaCCTokenizer; import net.sourceforge.pmd.lang.TokenManager; -import net.sourceforge.pmd.lang.ast.CharStream; +import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument; import net.sourceforge.pmd.lang.python.ast.PythonTokenKinds; diff --git a/pmd-visualforce/etc/grammar/Vf.jjt b/pmd-visualforce/etc/grammar/Vf.jjt index 8edfcc2612..2af403e0cb 100644 --- a/pmd-visualforce/etc/grammar/Vf.jjt +++ b/pmd-visualforce/etc/grammar/Vf.jjt @@ -13,7 +13,7 @@ options { PARSER_BEGIN(VfParserImpl) package net.sourceforge.pmd.lang.vf.ast; -import net.sourceforge.pmd.lang.ast.CharStream; +import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; import net.sourceforge.pmd.lang.ast.TokenMgrError; public class VfParserImpl { diff --git a/pmd-visualforce/src/main/java/net/sourceforge/pmd/cpd/VfTokenizer.java b/pmd-visualforce/src/main/java/net/sourceforge/pmd/cpd/VfTokenizer.java index 8fa9212144..ba239ef3cf 100644 --- a/pmd-visualforce/src/main/java/net/sourceforge/pmd/cpd/VfTokenizer.java +++ b/pmd-visualforce/src/main/java/net/sourceforge/pmd/cpd/VfTokenizer.java @@ -6,9 +6,9 @@ package net.sourceforge.pmd.cpd; import net.sourceforge.pmd.cpd.internal.JavaCCTokenizer; import net.sourceforge.pmd.lang.TokenManager; -import net.sourceforge.pmd.lang.ast.CharStream; -import net.sourceforge.pmd.lang.ast.impl.io.EscapeAwareReader; -import net.sourceforge.pmd.lang.ast.impl.io.JavaInputReader; +import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; +import net.sourceforge.pmd.lang.ast.impl.javacc.EscapeAwareReader; +import net.sourceforge.pmd.lang.ast.impl.javacc.JavaInputReader; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument; import net.sourceforge.pmd.lang.vf.ast.VfTokenKinds; diff --git a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/VfParser.java b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/VfParser.java index 5b5ff1fa69..b740cc8c63 100644 --- a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/VfParser.java +++ b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/VfParser.java @@ -6,7 +6,7 @@ package net.sourceforge.pmd.lang.vf.ast; import org.checkerframework.checker.nullness.qual.Nullable; -import net.sourceforge.pmd.lang.ast.CharStream; +import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; import net.sourceforge.pmd.lang.ast.ParseException; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument; import net.sourceforge.pmd.lang.ast.impl.javacc.JjtreeParserAdapter; diff --git a/pmd-vm/etc/grammar/Vm.jjt b/pmd-vm/etc/grammar/Vm.jjt index 0106fcd6d8..678ed8de31 100644 --- a/pmd-vm/etc/grammar/Vm.jjt +++ b/pmd-vm/etc/grammar/Vm.jjt @@ -45,8 +45,8 @@ import java.util.Map; import org.apache.commons.lang3.StringUtils; -import net.sourceforge.pmd.lang.ast.CharStream; import net.sourceforge.pmd.lang.ast.TokenMgrError; +import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken; diff --git a/pmd-vm/src/main/java/net/sourceforge/pmd/lang/vm/ast/VmParser.java b/pmd-vm/src/main/java/net/sourceforge/pmd/lang/vm/ast/VmParser.java index 236abc5886..a2995685d2 100644 --- a/pmd-vm/src/main/java/net/sourceforge/pmd/lang/vm/ast/VmParser.java +++ b/pmd-vm/src/main/java/net/sourceforge/pmd/lang/vm/ast/VmParser.java @@ -6,7 +6,7 @@ package net.sourceforge.pmd.lang.vm.ast; import org.checkerframework.checker.nullness.qual.Nullable; -import net.sourceforge.pmd.lang.ast.CharStream; +import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; import net.sourceforge.pmd.lang.ast.ParseException; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument;