Use token document instead
This commit is contained in:
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -1551,7 +1551,7 @@ ASTCompilationUnit CompilationUnit() :
|
||||
<EOF>
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -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<Comment> comments;
|
||||
private Map<Integer, String> 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
|
||||
|
Reference in New Issue
Block a user