Remove dump façade

This commit is contained in:
Clément Fournier
2019-04-27 15:47:08 +02:00
parent cb122590ba
commit 038ca21376
19 changed files with 0 additions and 1090 deletions

View File

@ -4,7 +4,6 @@
package net.sourceforge.pmd.lang.apex;
import java.io.Writer;
import java.util.Arrays;
import java.util.List;
@ -16,7 +15,6 @@ import net.sourceforge.pmd.lang.XPathHandler;
import net.sourceforge.pmd.lang.apex.ast.ASTMethod;
import net.sourceforge.pmd.lang.apex.ast.ASTUserClassOrInterface;
import net.sourceforge.pmd.lang.apex.ast.ApexNode;
import net.sourceforge.pmd.lang.apex.ast.DumpFacade;
import net.sourceforge.pmd.lang.apex.metrics.ApexMetricsComputer;
import net.sourceforge.pmd.lang.apex.metrics.api.ApexClassMetricKey;
import net.sourceforge.pmd.lang.apex.metrics.api.ApexOperationMetricKey;
@ -58,11 +56,6 @@ public class ApexHandler extends AbstractPmdLanguageVersionHandler {
return new ApexParser(parserOptions);
}
@Override
public VisitorStarter getDumpFacade(Writer writer, String prefix, boolean recurse) {
return rootNode -> new DumpFacade().initializeWith(writer, prefix, recurse, (ApexNode<?>) rootNode);
}
@Override
public LanguageMetricsProvider<ASTUserClassOrInterface<?>, ASTMethod> getLanguageMetricsProvider() {

View File

@ -1,85 +0,0 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.apex.ast;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.pmd.util.StringUtil;
public class DumpFacade {
private PrintWriter writer;
private boolean recurse;
public void initializeWith(Writer writer, String prefix, boolean recurse, ApexNode<?> node) {
this.writer = writer instanceof PrintWriter ? (PrintWriter) writer : new PrintWriter(writer);
this.recurse = recurse;
this.dump(node, prefix);
try {
writer.flush();
} catch (IOException e) {
throw new RuntimeException("Problem flushing PrintWriter.", e);
}
}
public Object visit(ApexNode<?> node, Object data) {
dump(node, (String) data);
if (recurse) {
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
visit((ApexNode<?>) node.jjtGetChild(i), data + " ");
}
return data;
} else {
return data;
}
}
private void dump(ApexNode<?> node, String prefix) {
//
// Dump format is generally composed of the following items...
//
// 1) Dump prefix
writer.print(prefix);
// 2) JJT Name of the Node
writer.print(node.getXPathNodeName());
//
// If there are any additional details, then:
// 1) A colon
// 2) The Node.getImage() if it is non-empty
// 3) Extras in parentheses
//
// Standard image handling
String image = node.getImage();
// Special image handling (e.g. Nodes with normally null images)
image = StringUtil.escapeWhitespace(image);
// Extras
List<String> extras = new ArrayList<>();
// Output image and extras
if (image != null || !extras.isEmpty()) {
writer.print(':');
if (image != null) {
writer.print(image);
}
for (String extra : extras) {
writer.print('(');
writer.print(extra);
writer.print(')');
}
}
writer.println();
}
}

View File

@ -22,11 +22,4 @@ public class ApexParserTestHelpers {
return parser.parse(reader);
}
public static void dumpNode(Node node) {
DumpFacade facade = new DumpFacade();
StringWriter writer = new StringWriter();
facade.initializeWith(writer, "", true, (ApexNode<?>) node);
facade.visit((ApexNode<?>) node, "");
System.out.println(writer.toString());
}
}

View File

@ -4,8 +4,6 @@
package net.sourceforge.pmd.lang;
import java.io.Writer;
import net.sourceforge.pmd.lang.dfa.DFAGraphRule;
import net.sourceforge.pmd.lang.metrics.LanguageMetricsProvider;
@ -52,11 +50,6 @@ public abstract class AbstractLanguageVersionHandler implements LanguageVersionH
return VisitorStarter.DUMMY;
}
@Override
public VisitorStarter getDumpFacade(final Writer writer, final String prefix, final boolean recurse) {
return VisitorStarter.DUMMY;
}
@Override
public VisitorStarter getMultifileFacade() {
return VisitorStarter.DUMMY;

View File

@ -4,7 +4,6 @@
package net.sourceforge.pmd.lang;
import java.io.Writer;
import java.util.List;
import net.sourceforge.pmd.annotation.Experimental;
@ -115,17 +114,6 @@ public interface LanguageVersionHandler {
@Deprecated
VisitorStarter getTypeResolutionFacade(ClassLoader classLoader);
/**
* Get the DumpFacade.
*
* @param writer
* The writer to dump to.
* @return VisitorStarter
* @deprecated The dump façade is not that useful and will be completely scrapped with PMD 7.0.0
*/
@Deprecated
VisitorStarter getDumpFacade(Writer writer, String prefix, boolean recurse);
/**
* Gets the visitor that performs multifile data gathering.

View File

@ -4,7 +4,6 @@
package net.sourceforge.pmd.lang.java;
import java.io.Writer;
import java.util.Arrays;
import java.util.List;
@ -18,8 +17,6 @@ import net.sourceforge.pmd.lang.ast.xpath.DefaultASTXPathHandler;
import net.sourceforge.pmd.lang.dfa.DFAGraphRule;
import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
import net.sourceforge.pmd.lang.java.ast.DumpFacade;
import net.sourceforge.pmd.lang.java.ast.JavaNode;
import net.sourceforge.pmd.lang.java.ast.MethodLikeNode;
import net.sourceforge.pmd.lang.java.dfa.DataFlowFacade;
import net.sourceforge.pmd.lang.java.dfa.JavaDFAGraphRule;
@ -128,16 +125,6 @@ public abstract class AbstractJavaHandler extends AbstractPmdLanguageVersionHand
};
}
@Override
public VisitorStarter getDumpFacade(final Writer writer, final String prefix, final boolean recurse) {
return new VisitorStarter() {
@Override
public void start(Node rootNode) {
new DumpFacade().initializeWith(writer, prefix, recurse, (JavaNode) rootNode);
}
};
}
@Override
public VisitorStarter getMultifileFacade() {
return new VisitorStarter() {

View File

@ -1,259 +0,0 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java.ast;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
public class DumpFacade extends JavaParserVisitorAdapter {
private PrintWriter writer;
private boolean recurse;
public void initializeWith(Writer writer, String prefix, boolean recurse, JavaNode node) {
this.writer = writer instanceof PrintWriter ? (PrintWriter) writer : new PrintWriter(writer);
this.recurse = recurse;
this.visit(node, prefix);
try {
writer.flush();
} catch (IOException e) {
throw new RuntimeException("Problem flushing PrintWriter.", e);
}
}
@Override
public Object visit(JavaNode node, Object data) {
dump(node, (String) data);
if (recurse) {
return super.visit(node, data + " ");
} else {
return data;
}
}
private void dump(JavaNode node, String prefix) {
//
// Dump format is generally composed of the following items...
//
// 1) Dump prefix
writer.print(prefix);
// 2) JJT Name of the Node
writer.print(node.getXPathNodeName());
//
// If there are any additional details, then:
// 1) A colon
// 2) The Node.getImage() if it is non-empty
// 3) Extras in parentheses
//
// Standard image handling
String image = node.getImage();
// Special image handling (e.g. Nodes with normally null images)
if (node instanceof ASTBooleanLiteral) {
image = String.valueOf(((ASTBooleanLiteral) node).isTrue());
} else if (node instanceof ASTPrimaryPrefix) {
ASTPrimaryPrefix primaryPrefix = (ASTPrimaryPrefix) node;
String result = null;
if (primaryPrefix.usesSuperModifier()) {
result = "super";
} else if (primaryPrefix.usesThisModifier()) {
result = "this";
}
if (image != null) {
result += "." + image;
}
image = result;
} else if (node instanceof ASTPrimarySuffix) {
ASTPrimarySuffix primarySuffix = (ASTPrimarySuffix) node;
if (primarySuffix.isArrayDereference()) {
if (image == null) {
image = "[";
} else {
image = "[" + image;
}
}
}
// Extras
List<String> extras = new ArrayList<>();
collectModifiers(node, extras);
// Standard Dimensionable extras
if (node instanceof Dimensionable) {
Dimensionable dimensionable = (Dimensionable) node;
if (dimensionable.isArray()) {
StringBuilder extra = new StringBuilder("array");
for (int i = 0; i < dimensionable.getArrayDepth(); i++) {
extra.append('[');
}
extras.add(extra.toString());
}
}
// Other extras
if (node instanceof ASTArguments) {
extras.add(String.valueOf(((ASTArguments) node).getArgumentCount()));
} else if (node instanceof ASTAssignmentOperator) {
extras.add(((ASTAssignmentOperator) node).isCompound() ? "compound" : "simple");
} else if (node instanceof ASTClassOrInterfaceBodyDeclaration) {
if (((ASTClassOrInterfaceBodyDeclaration) node).isAnonymousInnerClass()) {
extras.add("anonymous inner class");
}
if (((ASTClassOrInterfaceBodyDeclaration) node).isEnumChild()) {
extras.add("enum child");
}
} else if (node instanceof ASTBlock) {
if (((ASTBlock) node).containsComment()) {
extras.add("contains comment");
}
} else if (node instanceof ASTClassOrInterfaceDeclaration) {
extras.add(((ASTClassOrInterfaceDeclaration) node).isInterface() ? "interface" : "class");
if (((ASTClassOrInterfaceDeclaration) node).isNested()) {
extras.add("nested");
}
} else if (node instanceof ASTConditionalExpression) {
extras.add("ternary");
} else if (node instanceof ASTConstructorDeclaration) {
extras.add(String.valueOf(((ASTConstructorDeclaration) node).getParameterCount()));
if (((ASTConstructorDeclaration) node).containsComment()) {
extras.add("contains comment");
}
} else if (node instanceof ASTExplicitConstructorInvocation) {
extras.add(String.valueOf(((ASTExplicitConstructorInvocation) node).getArgumentCount()));
if (((ASTExplicitConstructorInvocation) node).isThis()) {
extras.add("this");
}
if (((ASTExplicitConstructorInvocation) node).isSuper()) {
extras.add("super");
}
} else if (node instanceof ASTFormalParameter) {
if (((ASTFormalParameter) node).isVarargs()) {
extras.add("varargs");
}
} else if (node instanceof ASTFormalParameters) {
extras.add(String.valueOf(((ASTFormalParameters) node).getParameterCount()));
} else if (node instanceof ASTIfStatement) {
if (((ASTIfStatement) node).hasElse()) {
extras.add("has else");
}
} else if (node instanceof ASTImportDeclaration) {
if (((ASTImportDeclaration) node).isImportOnDemand()) {
extras.add("on demand");
}
if (((ASTImportDeclaration) node).isStatic()) {
extras.add("static");
}
} else if (node instanceof ASTInitializer) {
extras.add(((ASTInitializer) node).isStatic() ? "static" : "nonstatic");
} else if (node instanceof ASTLiteral) {
ASTLiteral literal = (ASTLiteral) node;
if (literal.isCharLiteral()) {
extras.add("char style");
}
if (literal.isIntLiteral()) {
extras.add("int style");
}
if (literal.isFloatLiteral()) {
extras.add("float style");
}
if (literal.isStringLiteral()) {
extras.add("String style");
}
if (literal.isDoubleLiteral()) {
extras.add("double style");
}
if (literal.isLongLiteral()) {
extras.add("long style");
}
} else if (node instanceof ASTResultType) {
if (((ASTResultType) node).isVoid()) {
extras.add("void");
}
if (((ASTResultType) node).returnsArray()) {
extras.add("returns array");
}
} else if (node instanceof ASTSwitchLabel) {
if (((ASTSwitchLabel) node).isDefault()) {
extras.add("default");
}
} else if (node instanceof ASTTryStatement) {
if (((ASTTryStatement) node).hasFinally()) {
extras.add("has finally");
}
} else if (node instanceof ASTModuleDirective) {
ASTModuleDirective directive = (ASTModuleDirective) node;
extras.add(directive.getType());
if (directive.getRequiresModifier() != null) {
extras.add(directive.getRequiresModifier());
}
}
// Output image and extras
if (image != null || !extras.isEmpty()) {
writer.print(':');
if (image != null) {
writer.print(image);
}
for (String extra : extras) {
writer.print('(');
writer.print(extra);
writer.print(')');
}
}
writer.println();
}
private void collectModifiers(JavaNode node, List<String> extras) {
// Standard AccessNode extras
if (node instanceof AccessNode) {
AccessNode accessNode = (AccessNode) node;
if (accessNode.isPackagePrivate()) {
extras.add("package private");
}
if (accessNode.isPrivate()) {
extras.add("private");
}
if (accessNode.isPublic()) {
extras.add("public");
}
if (accessNode.isProtected()) {
extras.add("protected");
}
if (accessNode.isAbstract()) {
extras.add("abstract");
}
if (accessNode.isStatic()) {
extras.add("static");
}
if (accessNode.isFinal()) {
extras.add("final");
}
if (accessNode.isSynchronized()) {
extras.add("synchronized");
}
if (accessNode.isNative()) {
extras.add("native");
}
if (accessNode.isStrictfp()) {
extras.add("strict");
}
if (accessNode.isTransient()) {
extras.add("transient");
}
if (accessNode.isDefault()) {
extras.add("default");
}
}
}
}

View File

@ -4,17 +4,11 @@
package net.sourceforge.pmd.lang.ecmascript;
import java.io.Writer;
import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler;
import net.sourceforge.pmd.lang.Parser;
import net.sourceforge.pmd.lang.ParserOptions;
import net.sourceforge.pmd.lang.VisitorStarter;
import net.sourceforge.pmd.lang.XPathHandler;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.xpath.DefaultASTXPathHandler;
import net.sourceforge.pmd.lang.ecmascript.ast.DumpFacade;
import net.sourceforge.pmd.lang.ecmascript.ast.EcmascriptNode;
import net.sourceforge.pmd.lang.ecmascript.rule.EcmascriptRuleViolationFactory;
import net.sourceforge.pmd.lang.rule.RuleViolationFactory;
@ -43,13 +37,4 @@ public class Ecmascript3Handler extends AbstractPmdLanguageVersionHandler {
return new Ecmascript3Parser(parserOptions);
}
@Override
public VisitorStarter getDumpFacade(final Writer writer, final String prefix, final boolean recurse) {
return new VisitorStarter() {
@Override
public void start(Node rootNode) {
new DumpFacade().initializeWith(writer, prefix, recurse, (EcmascriptNode<?>) rootNode);
}
};
}
}

View File

@ -1,206 +0,0 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ecmascript.ast;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.pmd.util.StringUtil;
public class DumpFacade {
private PrintWriter writer;
private boolean recurse;
public void initializeWith(Writer writer, String prefix, boolean recurse, EcmascriptNode<?> node) {
this.writer = writer instanceof PrintWriter ? (PrintWriter) writer : new PrintWriter(writer);
this.recurse = recurse;
this.dump(node, prefix);
try {
writer.flush();
} catch (IOException e) {
throw new RuntimeException("Problem flushing PrintWriter.", e);
}
}
public Object visit(EcmascriptNode<?> node, Object data) {
dump(node, (String) data);
if (recurse) {
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
visit((EcmascriptNode<?>) node.jjtGetChild(i), data + " ");
}
return data;
} else {
return data;
}
}
private void dump(EcmascriptNode<?> node, String prefix) {
//
// Dump format is generally composed of the following items...
//
// 1) Dump prefix
writer.print(prefix);
// 2) JJT Name of the Node
writer.print(node.getXPathNodeName());
//
// If there are any additional details, then:
// 1) A colon
// 2) The Node.getImage() if it is non-empty
// 3) Extras in parentheses
//
// Standard image handling
String image = node.getImage();
// Special image handling (e.g. Nodes with normally null images)
image = StringUtil.escapeWhitespace(image);
// Extras
List<String> extras = new ArrayList<>();
// Standard DestructuringNode extras
if (node instanceof DestructuringNode) {
if (((DestructuringNode) node).isDestructuring()) {
extras.add("destructuring");
}
}
// Other extras
if (node instanceof ASTArrayComprehension) {
if (((ASTArrayComprehension) node).hasFilter()) {
extras.add("has filter");
}
} else if (node instanceof ASTBreakStatement) {
if (((ASTBreakStatement) node).hasLabel()) {
extras.add("has label");
}
} else if (node instanceof ASTCatchClause) {
if (((ASTCatchClause) node).isIf()) {
extras.add("if");
}
} else if (node instanceof ASTContinueStatement) {
if (((ASTContinueStatement) node).hasLabel()) {
extras.add("has label");
}
} else if (node instanceof ASTExpressionStatement) {
if (((ASTExpressionStatement) node).hasResult()) {
extras.add("has result");
}
} else if (node instanceof ASTForInLoop) {
if (((ASTForInLoop) node).isForEach()) {
extras.add("for each");
}
} else if (node instanceof ASTFunctionCall) {
if (((ASTFunctionCall) node).hasArguments()) {
extras.add("has arguments");
}
} else if (node instanceof ASTFunctionNode) {
if (((ASTFunctionNode) node).isClosure()) {
extras.add("closure");
}
if (((ASTFunctionNode) node).isGetter()) {
extras.add("getter");
}
if (((ASTFunctionNode) node).isSetter()) {
extras.add("setter");
}
} else if (node instanceof ASTIfStatement) {
if (((ASTIfStatement) node).hasElse()) {
extras.add("has else");
}
} else if (node instanceof ASTKeywordLiteral) {
if (((ASTKeywordLiteral) node).isBoolean()) {
extras.add("boolean");
}
} else if (node instanceof ASTLetNode) {
if (((ASTLetNode) node).hasBody()) {
extras.add("has body");
}
} else if (node instanceof ASTName) {
if (((ASTName) node).isLocalName()) {
extras.add("local");
}
if (((ASTName) node).isGlobalName()) {
extras.add("global");
}
} else if (node instanceof ASTNewExpression) {
if (((ASTNewExpression) node).hasArguments()) {
extras.add("has arguments");
}
if (((ASTNewExpression) node).hasInitializer()) {
extras.add("has initializer");
}
} else if (node instanceof ASTNumberLiteral) {
extras.add("Number=" + ((ASTNumberLiteral) node).getNumber());
extras.add("NormalizedImage=" + ((ASTNumberLiteral) node).getNormalizedImage());
} else if (node instanceof ASTObjectProperty) {
if (((ASTObjectProperty) node).isGetter()) {
extras.add("getter");
}
if (((ASTObjectProperty) node).isSetter()) {
extras.add("setter");
}
} else if (node instanceof ASTRegExpLiteral) {
extras.add("Flags=" + ((ASTRegExpLiteral) node).getFlags());
} else if (node instanceof ASTReturnStatement) {
if (((ASTReturnStatement) node).hasResult()) {
extras.add("has result");
}
} else if (node instanceof ASTStringLiteral) {
if (((ASTStringLiteral) node).isSingleQuoted()) {
extras.add("single quoted");
}
if (((ASTStringLiteral) node).isDoubleQuoted()) {
extras.add("double quoted");
}
} else if (node instanceof ASTSwitchCase) {
if (((ASTSwitchCase) node).isDefault()) {
extras.add("default");
}
} else if (node instanceof ASTTryStatement) {
if (((ASTTryStatement) node).hasCatch()) {
extras.add("catch");
}
if (((ASTTryStatement) node).hasFinally()) {
extras.add("finally");
}
} else if (node instanceof ASTUnaryExpression) {
if (((ASTUnaryExpression) node).isPrefix()) {
extras.add("prefix");
}
if (((ASTUnaryExpression) node).isPostfix()) {
extras.add("postfix");
}
}
// Standard EcmascriptNode extras
if (node.hasSideEffects()) {
extras.add("has side effects");
}
// Output image and extras
if (image != null || !extras.isEmpty()) {
writer.print(':');
if (image != null) {
writer.print(image);
}
for (String extra : extras) {
writer.print('(');
writer.print(extra);
writer.print(')');
}
}
writer.println();
}
}

View File

@ -25,11 +25,4 @@ public abstract class EcmascriptParserTestBase {
return (ASTAstRoot) parser.parse(sourceCode);
}
public String dump(EcmascriptNode<?> node) {
DumpFacade dumpFacade = new DumpFacade();
StringWriter writer = new StringWriter();
dumpFacade.initializeWith(writer, "", true, node);
dumpFacade.visit(node, "");
return writer.toString();
}
}

View File

@ -4,17 +4,11 @@
package net.sourceforge.pmd.lang.jsp;
import java.io.Writer;
import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler;
import net.sourceforge.pmd.lang.Parser;
import net.sourceforge.pmd.lang.ParserOptions;
import net.sourceforge.pmd.lang.VisitorStarter;
import net.sourceforge.pmd.lang.XPathHandler;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.xpath.DefaultASTXPathHandler;
import net.sourceforge.pmd.lang.jsp.ast.DumpFacade;
import net.sourceforge.pmd.lang.jsp.ast.JspNode;
import net.sourceforge.pmd.lang.jsp.rule.JspRuleViolationFactory;
import net.sourceforge.pmd.lang.rule.RuleViolationFactory;
@ -40,13 +34,4 @@ public class JspHandler extends AbstractPmdLanguageVersionHandler {
return new JspParser(parserOptions);
}
@Override
public VisitorStarter getDumpFacade(final Writer writer, final String prefix, final boolean recurse) {
return new VisitorStarter() {
@Override
public void start(Node rootNode) {
new DumpFacade().initializeWith(writer, prefix, recurse, (JspNode) rootNode);
}
};
}
}

View File

@ -1,104 +0,0 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.jsp.ast;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.pmd.lang.ast.Node;
public class DumpFacade extends JspParserVisitorAdapter {
private PrintWriter writer;
private boolean recurse;
public void initializeWith(Writer writer, String prefix, boolean recurse, JspNode node) {
this.writer = writer instanceof PrintWriter ? (PrintWriter) writer : new PrintWriter(writer);
this.recurse = recurse;
this.visit(node, prefix);
try {
writer.flush();
} catch (IOException e) {
throw new RuntimeException("Problem flushing PrintWriter.", e);
}
}
@Override
public Object visit(JspNode node, Object data) {
dump(node, (String) data);
if (recurse) {
return super.visit(node, data + " ");
} else {
return data;
}
}
private void dump(Node node, String prefix) {
//
// Dump format is generally composed of the following items...
//
// 1) Dump prefix
writer.print(prefix);
// 2) JJT Name of the Node
writer.print(node.getXPathNodeName());
//
// If there are any additional details, then:
// 1) A colon
// 2) The Node.getImage() if it is non-empty
// 3) Extras in parentheses
//
// Standard image handling
String image = node.getImage();
// Extras
List<String> extras = new ArrayList<>();
// Other extras
if (node instanceof ASTAttribute) {
extras.add("name=[" + ((ASTAttribute) node).getName() + "]");
} else if (node instanceof ASTDeclaration) {
extras.add("name=[" + ((ASTDeclaration) node).getName() + "]");
} else if (node instanceof ASTDoctypeDeclaration) {
extras.add("name=[" + ((ASTDoctypeDeclaration) node).getName() + "]");
} else if (node instanceof ASTDoctypeExternalId) {
extras.add("uri=[" + ((ASTDoctypeExternalId) node).getUri() + "]");
if (((ASTDoctypeExternalId) node).getPublicId().length() > 0) {
extras.add("publicId=[" + ((ASTDoctypeExternalId) node).getPublicId() + "]");
}
} else if (node instanceof ASTElement) {
extras.add("name=[" + ((ASTElement) node).getName() + "]");
if (((ASTElement) node).isEmpty()) {
extras.add("empty");
}
} else if (node instanceof ASTJspDirective) {
extras.add("name=[" + ((ASTJspDirective) node).getName() + "]");
} else if (node instanceof ASTJspDirectiveAttribute) {
extras.add("name=[" + ((ASTJspDirectiveAttribute) node).getName() + "]");
extras.add("value=[" + ((ASTJspDirectiveAttribute) node).getValue() + "]");
}
// Output image and extras
if (image != null || !extras.isEmpty()) {
writer.print(':');
if (image != null) {
writer.print(image);
}
for (String extra : extras) {
writer.print('(');
writer.print(extra);
writer.print(')');
}
}
writer.println();
}
}

View File

@ -4,8 +4,6 @@
package net.sourceforge.pmd.lang.plsql;
import java.io.Writer;
import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler;
import net.sourceforge.pmd.lang.DataFlowHandler;
import net.sourceforge.pmd.lang.Parser;
@ -16,8 +14,6 @@ import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.xpath.DefaultASTXPathHandler;
import net.sourceforge.pmd.lang.dfa.DFAGraphRule;
import net.sourceforge.pmd.lang.plsql.ast.ASTInput;
import net.sourceforge.pmd.lang.plsql.ast.DumpFacade;
import net.sourceforge.pmd.lang.plsql.ast.PLSQLNode;
import net.sourceforge.pmd.lang.plsql.dfa.DFAPLSQLGraphRule;
import net.sourceforge.pmd.lang.plsql.dfa.DataFlowFacade;
import net.sourceforge.pmd.lang.plsql.rule.PLSQLRuleViolationFactory;
@ -77,16 +73,6 @@ public class PLSQLHandler extends AbstractPmdLanguageVersionHandler {
};
}
@Override
public VisitorStarter getDumpFacade(final Writer writer, final String prefix, final boolean recurse) {
return new VisitorStarter() {
@Override
public void start(Node rootNode) {
new DumpFacade().initializeWith(writer, prefix, recurse, (PLSQLNode) rootNode);
}
};
}
/**
* Return minimal XPathHandler to cope with Jaxen XPath Rules.
*/

View File

@ -1,103 +0,0 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.plsql.ast;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
public class DumpFacade extends PLSQLParserVisitorAdapter {
private PrintWriter writer;
private boolean recurse;
public void initializeWith(Writer writer, String prefix, boolean recurse, PLSQLNode node) {
this.writer = writer instanceof PrintWriter ? (PrintWriter) writer : new PrintWriter(writer);
this.recurse = recurse;
this.visit(node, prefix);
try {
writer.flush();
} catch (IOException e) {
throw new RuntimeException("Problem flushing PrintWriter.", e);
}
}
@Override
public Object visit(PLSQLNode node, Object data) {
dump(node, (String) data);
if (recurse) {
return super.visit(node, data + " ");
} else {
return data;
}
}
private void dump(PLSQLNode node, String prefix) {
//
// Dump format is generally composed of the following items...
//
// 1) Dump prefix
writer.print(prefix);
// 2) JJT Name of the Node
writer.print(node.getXPathNodeName());
//
// If there are any additional details, then:
// 1) A colon
// 2) The Node.getImage() if it is non-empty
// 3) Extras in parentheses
//
// Standard image handling
String image = node.getImage();
// Special image handling (e.g. Nodes with normally null images)
if (node instanceof ASTBooleanLiteral) {
image = node.getImage();
} else if (node instanceof ASTPrimaryPrefix) {
String result = null;
/*
* if (primaryPrefix.usesSuperModifier()) { result = "super"; } else
* if (primaryPrefix.usesThisModifier()) { result = "this"; }
*/
if (image != null) {
result += "." + image;
}
image = result;
} else if (node instanceof ASTPrimarySuffix) {
ASTPrimarySuffix primarySuffix = (ASTPrimarySuffix) node;
if (primarySuffix.isArrayDereference()) {
if (image == null) {
image = "[";
} else {
image = "[" + image;
}
}
}
// Extras
List<String> extras = new ArrayList<>();
// Output image and extras
if (image != null || !extras.isEmpty()) {
writer.print(':');
if (image != null) {
writer.print(image);
}
for (String extra : extras) {
writer.print('(');
writer.print(extra);
writer.print(')');
}
}
writer.println();
}
}

View File

@ -4,18 +4,12 @@
package net.sourceforge.pmd.lang.vf;
import java.io.Writer;
import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler;
import net.sourceforge.pmd.lang.Parser;
import net.sourceforge.pmd.lang.ParserOptions;
import net.sourceforge.pmd.lang.VisitorStarter;
import net.sourceforge.pmd.lang.XPathHandler;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.xpath.DefaultASTXPathHandler;
import net.sourceforge.pmd.lang.rule.RuleViolationFactory;
import net.sourceforge.pmd.lang.vf.ast.DumpFacade;
import net.sourceforge.pmd.lang.vf.ast.VfNode;
import net.sourceforge.pmd.lang.vf.rule.VfRuleViolationFactory;
public class VfHandler extends AbstractPmdLanguageVersionHandler {
@ -35,13 +29,4 @@ public class VfHandler extends AbstractPmdLanguageVersionHandler {
return new VfParser(parserOptions);
}
@Override
public VisitorStarter getDumpFacade(final Writer writer, final String prefix, final boolean recurse) {
return new VisitorStarter() {
@Override
public void start(Node rootNode) {
new DumpFacade().initializeWith(writer, prefix, recurse, (VfNode) rootNode);
}
};
}
}

View File

@ -1,99 +0,0 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.vf.ast;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.pmd.lang.ast.Node;
public class DumpFacade extends VfParserVisitorAdapter {
private PrintWriter writer;
private boolean recurse;
public void initializeWith(Writer writer, String prefix, boolean recurse, VfNode node) {
this.writer = writer instanceof PrintWriter ? (PrintWriter) writer : new PrintWriter(writer);
this.recurse = recurse;
this.visit(node, prefix);
try {
writer.flush();
} catch (IOException e) {
throw new RuntimeException("Problem flushing PrintWriter.", e);
}
}
@Override
public Object visit(VfNode node, Object data) {
dump(node, (String) data);
if (recurse) {
return super.visit(node, data + " ");
} else {
return data;
}
}
private void dump(Node node, String prefix) {
//
// Dump format is generally composed of the following items...
//
// 1) Dump prefix
writer.print(prefix);
// 2) JJT Name of the Node
writer.print(node.getXPathNodeName());
//
// If there are any additional details, then:
// 1) A colon
// 2) The Node.getImage() if it is non-empty
// 3) Extras in parentheses
//
// Standard image handling
String image = node.getImage();
// Extras
List<String> extras = new ArrayList<>();
// Other extras
if (node instanceof ASTAttribute) {
extras.add("name=[" + ((ASTAttribute) node).getName() + "]");
} else if (node instanceof ASTDeclaration) {
extras.add("name=[" + ((ASTDeclaration) node).getName() + "]");
} else if (node instanceof ASTDoctypeDeclaration) {
extras.add("name=[" + ((ASTDoctypeDeclaration) node).getName() + "]");
} else if (node instanceof ASTDoctypeExternalId) {
extras.add("uri=[" + ((ASTDoctypeExternalId) node).getUri() + "]");
if (((ASTDoctypeExternalId) node).getPublicId().length() > 0) {
extras.add("publicId=[" + ((ASTDoctypeExternalId) node).getPublicId() + "]");
}
} else if (node instanceof ASTElement) {
extras.add("name=[" + ((ASTElement) node).getName() + "]");
if (((ASTElement) node).isEmpty()) {
extras.add("empty");
}
}
// Output image and extras
if (image != null || !extras.isEmpty()) {
writer.print(':');
if (image != null) {
writer.print(image);
}
for (String extra : extras) {
writer.print('(');
writer.print(extra);
writer.print(')');
}
}
writer.println();
}
}

View File

@ -4,17 +4,12 @@
package net.sourceforge.pmd.lang.vm;
import java.io.Writer;
import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler;
import net.sourceforge.pmd.lang.Parser;
import net.sourceforge.pmd.lang.ParserOptions;
import net.sourceforge.pmd.lang.VisitorStarter;
import net.sourceforge.pmd.lang.XPathHandler;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.xpath.DefaultASTXPathHandler;
import net.sourceforge.pmd.lang.rule.RuleViolationFactory;
import net.sourceforge.pmd.lang.vm.ast.AbstractVmNode;
import net.sourceforge.pmd.lang.vm.rule.VmRuleViolationFactory;
/**
@ -38,13 +33,4 @@ public class VmHandler extends AbstractPmdLanguageVersionHandler {
return new VmParser(parserOptions);
}
@Override
public VisitorStarter getDumpFacade(final Writer writer, final String prefix, final boolean recurse) {
return new VisitorStarter() {
@Override
public void start(final Node rootNode) {
((AbstractVmNode) rootNode).dump(prefix, recurse, writer);
}
};
}
}

View File

@ -4,18 +4,12 @@
package net.sourceforge.pmd.lang.xml;
import java.io.Writer;
import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler;
import net.sourceforge.pmd.lang.Parser;
import net.sourceforge.pmd.lang.ParserOptions;
import net.sourceforge.pmd.lang.VisitorStarter;
import net.sourceforge.pmd.lang.XPathHandler;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.xpath.DefaultASTXPathHandler;
import net.sourceforge.pmd.lang.rule.RuleViolationFactory;
import net.sourceforge.pmd.lang.xml.ast.DumpFacade;
import net.sourceforge.pmd.lang.xml.ast.XmlNode;
import net.sourceforge.pmd.lang.xml.rule.XmlRuleViolationFactory;
/**
@ -43,13 +37,4 @@ public class XmlHandler extends AbstractPmdLanguageVersionHandler {
return new XmlParser(parserOptions);
}
@Override
public VisitorStarter getDumpFacade(final Writer writer, final String prefix, final boolean recurse) {
return new VisitorStarter() {
@Override
public void start(Node rootNode) {
new DumpFacade().initializeWith(writer, prefix, recurse, (XmlNode) rootNode);
}
};
}
}

View File

@ -1,93 +0,0 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.xml.ast;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.sourceforge.pmd.lang.ast.xpath.Attribute;
import net.sourceforge.pmd.util.StringUtil;
public class DumpFacade {
private PrintWriter writer;
private boolean recurse;
public void initializeWith(Writer writer, String prefix, boolean recurse, XmlNode node) {
this.writer = writer instanceof PrintWriter ? (PrintWriter) writer : new PrintWriter(writer);
this.recurse = recurse;
this.dump(node, prefix);
try {
writer.flush();
} catch (IOException e) {
throw new RuntimeException("Problem flushing PrintWriter.", e);
}
}
public Object visit(XmlNode node, Object data) {
dump(node, (String) data);
if (recurse) {
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
visit((XmlNode) node.jjtGetChild(i), data + " ");
}
return data;
} else {
return data;
}
}
private void dump(XmlNode node, String prefix) {
//
// Dump format is generally composed of the following items...
//
// 1) Dump prefix
writer.print(prefix);
// 2) JJT Name of the Node
writer.print(node.getXPathNodeName());
//
// If there are any additional details, then:
// 1) A colon
// 2) The Node.getImage() if it is non-empty
// 3) Extras in parentheses
//
// Standard image handling
String image = node.getImage();
// Special image handling (e.g. Nodes with normally null images)
image = StringUtil.escapeWhitespace(image);
// Extras
List<String> extras = new ArrayList<>();
Iterator<Attribute> iterator = node.getAttributeIterator();
while (iterator.hasNext()) {
Attribute attribute = iterator.next();
extras.add(attribute.getName() + "=" + StringUtil.escapeWhitespace(attribute.getValue()));
}
// Output image and extras
if (image != null || !extras.isEmpty()) {
writer.print(':');
if (image != null) {
writer.print(image);
}
for (String extra : extras) {
writer.print('(');
writer.print(extra);
writer.print(')');
}
}
writer.println();
}
}