Merge branch 'pmd/7.0.x' into pr-4049

This commit is contained in:
Andreas Dangel
2022-09-10 20:08:30 +02:00
183 changed files with 4157 additions and 2179 deletions

View File

@@ -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;

View File

@@ -6,21 +6,40 @@ 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.ParseException;
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.ast.impl.javacc.JavaccTokenDocument.TokenDocumentBehavior;
import net.sourceforge.pmd.lang.ast.impl.javacc.JjtreeParserAdapter;
import net.sourceforge.pmd.lang.document.TextDocument;
/**
* Adapter for the VmParser.
*/
public class VmParser extends JjtreeParserAdapter<ASTTemplate> {
private static final TokenDocumentBehavior TOKEN_BEHAVIOR = new TokenDocumentBehavior(VmTokenKinds.TOKEN_NAMES) {
@Override
public JavaccToken createToken(JavaccTokenDocument self, int kind, CharStream cs, @Nullable String image) {
String realImage = image == null ? cs.getTokenImage() : image;
if (kind == VmTokenKinds.ESCAPE_DIRECTIVE) {
realImage = escapedDirective(realImage);
}
return super.createToken(self, kind, cs, realImage);
}
private String escapedDirective(String strImage) {
int iLast = strImage.lastIndexOf("\\");
String strDirective = strImage.substring(iLast + 1);
return strImage.substring(0, iLast / 2) + strDirective;
}
};
@Override
protected JavaccTokenDocument newDocumentImpl(TextDocument fullText) {
return new VmTokenDocument(fullText);
protected TokenDocumentBehavior tokenBehavior() {
return TOKEN_BEHAVIOR;
}
@Override
@@ -29,33 +48,4 @@ public class VmParser extends JjtreeParserAdapter<ASTTemplate> {
}
private static class VmTokenDocument extends JavaccTokenDocument {
VmTokenDocument(TextDocument fullText) {
super(fullText);
}
@Override
protected @Nullable String describeKindImpl(int kind) {
return VmTokenKinds.describe(kind);
}
@Override
public JavaccToken createToken(int kind, CharStream cs, @Nullable String image) {
String realImage = image == null ? cs.GetImage() : image;
if (kind == VmTokenKinds.ESCAPE_DIRECTIVE) {
realImage = escapedDirective(realImage);
}
return super.createToken(kind, cs, realImage);
}
private String escapedDirective(String strImage) {
int iLast = strImage.lastIndexOf("\\");
String strDirective = strImage.substring(iLast + 1);
return strImage.substring(0, iLast / 2) + strDirective;
}
}
}