diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/JavaCharStream.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/JavaCharStream.java index 619ee025d0..9de5a29fb3 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/JavaCharStream.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/JavaCharStream.java @@ -20,12 +20,14 @@ public class JavaCharStream extends JavaCharStreamBase { // full text with nothing escaped and all private final SharingCharSeq seq; + private final TokenDocument document; private int[] startOffsets; public JavaCharStream(String fulltext) { super(new StringReader(fulltext)); this.seq = new SharingCharSeq(fulltext); + this.document = new TokenDocument(seq); this.startOffsets = new int[bufsize]; maxNextCharInd = seq.length(); @@ -36,6 +38,7 @@ public class JavaCharStream extends JavaCharStreamBase { this(toString(toDump)); } + @Override protected void ExpandBuff(boolean wrapAround) { int[] newStartOffsets = new int[bufsize + 2048]; @@ -71,8 +74,8 @@ public class JavaCharStream extends JavaCharStreamBase { } } - public RichCharSequence getFullText() { - return seq; + public TokenDocument getTokenDocument() { + return document; } @Override diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/TokenDocument.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/TokenDocument.java new file mode 100644 index 0000000000..00c9070e48 --- /dev/null +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/TokenDocument.java @@ -0,0 +1,23 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.ast.impl; + +/** + * TODO double link tokens and stuff. + * + * @author Clément Fournier + */ +public class TokenDocument { + + private final RichCharSequence fullText; + + public TokenDocument(RichCharSequence fullText) { + this.fullText = fullText; + } + + public RichCharSequence getFullText() { + return fullText; + } +} diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index 3d260af38f..c6bc963dce 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -1551,7 +1551,7 @@ ASTCompilationUnit CompilationUnit() : { jjtThis.setComments(token_source.comments); - jjtThis.setFileText(((net.sourceforge.pmd.lang.ast.impl.JavaCharStream) token_source.input_stream).getFullText()); + jjtThis.setTokenDocument(((net.sourceforge.pmd.lang.ast.impl.JavaCharStream) token_source.input_stream).getTokenDocument()); return jjtThis; } } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCompilationUnit.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCompilationUnit.java index 5c33e8b9be..08c10759d6 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCompilationUnit.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCompilationUnit.java @@ -15,6 +15,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.RootNode; import net.sourceforge.pmd.lang.ast.impl.RichCharSequence; +import net.sourceforge.pmd.lang.ast.impl.TokenDocument; import net.sourceforge.pmd.lang.java.typeresolution.ClassTypeResolver; // FUTURE Change this class to extend from SimpleJavaNode, as TypeNode is not appropriate (unless I'm wrong) @@ -24,6 +25,7 @@ public final class ASTCompilationUnit extends AbstractJavaTypeNode implements Ro private List comments; private Map noPmdComments = Collections.emptyMap(); private RichCharSequence fileText; + private TokenDocument tokenDocument; ASTCompilationUnit(int id) { super(id); @@ -43,12 +45,12 @@ public final class ASTCompilationUnit extends AbstractJavaTypeNode implements Ro @Override public RichCharSequence getText() { - return fileText; + return tokenDocument.getFullText(); } - void setFileText(RichCharSequence fileText) { - this.fileText = fileText; + void setTokenDocument(TokenDocument document) { + this.tokenDocument = document; } @Override