Use interface instead of deprecated abstract class
This commit is contained in:
1 parent
58cf6cbc96
commit
0ad1f47b29
8 files changed
+73
-35
No files matched your search
+6
-5
@@ -20,8 +20,9 @@ import net.sourceforge.pmd.lang.vf.ast.ASTElExpression;
|
||||
import net.sourceforge.pmd.lang.vf.ast.ASTElement;
|
||||
import net.sourceforge.pmd.lang.vf.ast.ASTExpression;
|
||||
import net.sourceforge.pmd.lang.vf.ast.ASTText;
|
||||
import net.sourceforge.pmd.lang.vf.ast.AbstractVFDataNode;
|
||||
import net.sourceforge.pmd.lang.vf.ast.VfAstInternals;
|
||||
import net.sourceforge.pmd.lang.vf.ast.VfParserVisitorAdapter;
|
||||
import net.sourceforge.pmd.lang.vf.ast.VfTypedNode;
|
||||
|
||||
/**
|
||||
* Visits {@link ASTExpression} nodes and stores type information for
|
||||
@@ -109,7 +110,7 @@ class VfExpressionTypeVisitor extends VfParserVisitorAdapter {
|
||||
*/
|
||||
@Override
|
||||
public Object visit(ASTElExpression node, Object data) {
|
||||
for (Map.Entry<AbstractVFDataNode, String> entry : getDataNodeNames(node).entrySet()) {
|
||||
for (Map.Entry<VfTypedNode, String> entry : getDataNodeNames(node).entrySet()) {
|
||||
String name = entry.getValue();
|
||||
DataType type = null;
|
||||
String[] parts = name.split("\\.");
|
||||
@@ -152,7 +153,7 @@ class VfExpressionTypeVisitor extends VfParserVisitorAdapter {
|
||||
}
|
||||
|
||||
if (type != null) {
|
||||
entry.getKey().setDataType(type);
|
||||
VfAstInternals.setDataType(entry.getKey(), type);
|
||||
} else {
|
||||
LOGGER.fine("Unable to determine type for: " + name);
|
||||
}
|
||||
@@ -164,8 +165,8 @@ class VfExpressionTypeVisitor extends VfParserVisitorAdapter {
|
||||
* Invoke {@link ASTExpression#getDataNodes()} for all {@link ASTExpression} children of {@code node} and return
|
||||
* the consolidated results.
|
||||
*/
|
||||
private IdentityHashMap<AbstractVFDataNode, String> getDataNodeNames(ASTElExpression node) {
|
||||
IdentityHashMap<AbstractVFDataNode, String> dataNodeToName = new IdentityHashMap<>();
|
||||
private IdentityHashMap<VfTypedNode, String> getDataNodeNames(ASTElExpression node) {
|
||||
IdentityHashMap<VfTypedNode, String> dataNodeToName = new IdentityHashMap<>();
|
||||
|
||||
for (ASTExpression expression : node.findChildrenOfType(ASTExpression.class)) {
|
||||
try {
|
||||
|
||||
@@ -102,13 +102,13 @@ public class ASTExpression extends AbstractVFNode {
|
||||
* @throws DataNodeStateException if the results of this method could have been incorrect. Callers should typically
|
||||
* not rethrow this exception, as it will happen often and doesn't represent a terminal exception.
|
||||
*/
|
||||
public Map<AbstractVFDataNode, String> getDataNodes() throws DataNodeStateException {
|
||||
Map<AbstractVFDataNode, String> result = new IdentityHashMap<>();
|
||||
public Map<VfTypedNode, String> getDataNodes() throws DataNodeStateException {
|
||||
Map<VfTypedNode, String> result = new IdentityHashMap<>();
|
||||
|
||||
int numChildren = getNumChildren();
|
||||
List<ASTIdentifier> identifiers = findChildrenOfType(ASTIdentifier.class);
|
||||
for (ASTIdentifier identifier : identifiers) {
|
||||
LinkedList<AbstractVFDataNode> identifierNodes = new LinkedList<>();
|
||||
LinkedList<VfTypedNode> identifierNodes = new LinkedList<>();
|
||||
|
||||
// The Identifier is the first item that makes up the string
|
||||
identifierNodes.add(identifier);
|
||||
@@ -126,7 +126,7 @@ public class ASTExpression extends AbstractVFNode {
|
||||
if (node.getNumChildren() == 1) {
|
||||
final Node expressionChild = node.getChild(0);
|
||||
if (expressionChild instanceof ASTIdentifier || expressionChild instanceof ASTLiteral) {
|
||||
identifierNodes.add((AbstractVFDataNode) expressionChild);
|
||||
identifierNodes.add((VfTypedNode) expressionChild);
|
||||
} else {
|
||||
// This should never happen
|
||||
logWarning("Node expected to be Identifier or Literal", node);
|
||||
|
||||
+4
-12
@@ -4,15 +4,13 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.vf.ast;
|
||||
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.lang.vf.DataType;
|
||||
|
||||
/**
|
||||
* Represents a node that displays a piece of data.
|
||||
*/
|
||||
@Deprecated
|
||||
@InternalApi
|
||||
public class AbstractVFDataNode extends AbstractVFNode {
|
||||
class AbstractVFDataNode extends AbstractVFNode implements VfTypedNode {
|
||||
|
||||
private DataType dataType;
|
||||
|
||||
public AbstractVFDataNode(int id) {
|
||||
@@ -24,18 +22,12 @@ public class AbstractVFDataNode extends AbstractVFNode {
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Example XPath 1.0 and 2.0: {@code //Identifier[@DataType='DateTime']}
|
||||
*
|
||||
* @return data type that this node refers to. A null value indicates that no matching Metadata was found for this
|
||||
* node. null differs from {@link DataType#Unknown} which indicates that Metadata was found but it wasn't mappable
|
||||
* to one of the enums.
|
||||
*/
|
||||
@Override
|
||||
public DataType getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
|
||||
public void setDataType(DataType dataType) {
|
||||
void setDataType(DataType dataType) {
|
||||
this.dataType = dataType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.vf.ast;
|
||||
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.lang.vf.DataType;
|
||||
|
||||
/**
|
||||
* This is internal API, and can be changed at any time.
|
||||
*/
|
||||
@InternalApi
|
||||
public final class VfAstInternals {
|
||||
|
||||
private VfAstInternals() {
|
||||
// utility class
|
||||
}
|
||||
|
||||
public static void setDataType(VfTypedNode node, DataType dataType) {
|
||||
((AbstractVFDataNode) node).setDataType(dataType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.vf.ast;
|
||||
|
||||
import net.sourceforge.pmd.lang.vf.DataType;
|
||||
|
||||
/**
|
||||
* Represents a node that displays a piece of data.
|
||||
*/
|
||||
public interface VfTypedNode extends VfNode {
|
||||
|
||||
/**
|
||||
* Returns the data type this node refers to. A null value indicates that no matching Metadata was found for this
|
||||
* node. null differs from {@link DataType#Unknown} which indicates that Metadata was found but it wasn't mappable
|
||||
* to one of the enums.
|
||||
*
|
||||
* <p>Example XPath 1.0 and 2.0: {@code //Identifier[@DataType='DateTime']}
|
||||
*/
|
||||
DataType getDataType();
|
||||
}
|
||||
+2
-2
@@ -25,8 +25,8 @@ import net.sourceforge.pmd.lang.vf.ast.ASTIdentifier;
|
||||
import net.sourceforge.pmd.lang.vf.ast.ASTLiteral;
|
||||
import net.sourceforge.pmd.lang.vf.ast.ASTNegationExpression;
|
||||
import net.sourceforge.pmd.lang.vf.ast.ASTText;
|
||||
import net.sourceforge.pmd.lang.vf.ast.AbstractVFDataNode;
|
||||
import net.sourceforge.pmd.lang.vf.ast.AbstractVFNode;
|
||||
import net.sourceforge.pmd.lang.vf.ast.VfTypedNode;
|
||||
import net.sourceforge.pmd.lang.vf.rule.AbstractVfRule;
|
||||
|
||||
/**
|
||||
@@ -451,7 +451,7 @@ public class VfUnescapeElRule extends AbstractVfRule {
|
||||
*/
|
||||
private boolean expressionContainsSafeDataNodes(ASTExpression expression) {
|
||||
try {
|
||||
for (AbstractVFDataNode node : expression.getDataNodes().keySet()) {
|
||||
for (VfTypedNode node : expression.getDataNodes().keySet()) {
|
||||
DataType dataType = node.getDataType();
|
||||
if (dataType == null || dataType.requiresEscaping) {
|
||||
return false;
|
||||
|
||||
+5
-5
@@ -26,7 +26,7 @@ import net.sourceforge.pmd.lang.ParserOptions;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.vf.ast.ASTIdentifier;
|
||||
import net.sourceforge.pmd.lang.vf.ast.ASTLiteral;
|
||||
import net.sourceforge.pmd.lang.vf.ast.AbstractVFDataNode;
|
||||
import net.sourceforge.pmd.lang.vf.ast.VfTypedNode;
|
||||
import net.sourceforge.pmd.util.treeexport.XmlTreeRenderer;
|
||||
|
||||
public class VfExpressionTypeVisitorTest {
|
||||
@@ -110,8 +110,8 @@ public class VfExpressionTypeVisitorTest {
|
||||
// Each string appears twice, it is set on a "value" attribute and inline
|
||||
assertEquals(2, nodes.size());
|
||||
for (Node node : nodes) {
|
||||
assertTrue(node.getClass().getSimpleName(), node instanceof AbstractVFDataNode);
|
||||
AbstractVFDataNode dataNode = (AbstractVFDataNode) node;
|
||||
assertTrue(node.getClass().getSimpleName(), node instanceof VfTypedNode);
|
||||
VfTypedNode dataNode = (VfTypedNode) node;
|
||||
assertNull(dataNode.getDataType());
|
||||
}
|
||||
}
|
||||
@@ -150,8 +150,8 @@ public class VfExpressionTypeVisitorTest {
|
||||
// Each string appears twice, it is set on a "value" attribute and inline
|
||||
assertEquals(2, nodes.size());
|
||||
for (Node node : nodes) {
|
||||
assertTrue(node.getClass().getSimpleName(), node instanceof AbstractVFDataNode);
|
||||
AbstractVFDataNode dataNode = (AbstractVFDataNode) node;
|
||||
assertTrue(node.getClass().getSimpleName(), node instanceof VfTypedNode);
|
||||
VfTypedNode dataNode = (VfTypedNode) node;
|
||||
assertNull(dataNode.getDataType());
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -39,7 +39,7 @@ public class ASTExpressionTest {
|
||||
assertEquals(template, 1, nodes.size());
|
||||
|
||||
ASTExpression expression = (ASTExpression) nodes.get(0);
|
||||
Map<AbstractVFDataNode, String> identifiers = expression.getDataNodes();
|
||||
Map<VfTypedNode, String> identifiers = expression.getDataNodes();
|
||||
assertEquals(template, 1, identifiers.size());
|
||||
|
||||
Map<String, Node> map = invertMap(identifiers);
|
||||
@@ -57,7 +57,7 @@ public class ASTExpressionTest {
|
||||
assertEquals(template, 1, nodes.size());
|
||||
|
||||
ASTExpression expression = (ASTExpression) nodes.get(0);
|
||||
Map<AbstractVFDataNode, String> identifiers = expression.getDataNodes();
|
||||
Map<VfTypedNode, String> identifiers = expression.getDataNodes();
|
||||
assertEquals(template, 1, identifiers.size());
|
||||
|
||||
Map<String, Node> map = invertMap(identifiers);
|
||||
@@ -75,7 +75,7 @@ public class ASTExpressionTest {
|
||||
assertEquals(template, 1, nodes.size());
|
||||
|
||||
ASTExpression expression = (ASTExpression) nodes.get(0);
|
||||
Map<AbstractVFDataNode, String> identifiers = expression.getDataNodes();
|
||||
Map<VfTypedNode, String> identifiers = expression.getDataNodes();
|
||||
assertEquals(template, 1, identifiers.size());
|
||||
|
||||
Map<String, Node> map = invertMap(identifiers);
|
||||
@@ -93,7 +93,7 @@ public class ASTExpressionTest {
|
||||
assertEquals(template, 1, nodes.size());
|
||||
|
||||
ASTExpression expression = (ASTExpression) nodes.get(0);
|
||||
Map<AbstractVFDataNode, String> identifiers = expression.getDataNodes();
|
||||
Map<VfTypedNode, String> identifiers = expression.getDataNodes();
|
||||
assertEquals(template, 2, identifiers.size());
|
||||
|
||||
Map<String, Node> map = invertMap(identifiers);
|
||||
@@ -114,7 +114,7 @@ public class ASTExpressionTest {
|
||||
assertEquals(template, 1, nodes.size());
|
||||
|
||||
ASTExpression expression = (ASTExpression) nodes.get(0);
|
||||
Map<AbstractVFDataNode, String> identifiers = expression.getDataNodes();
|
||||
Map<VfTypedNode, String> identifiers = expression.getDataNodes();
|
||||
assertEquals(template, 1, identifiers.size());
|
||||
|
||||
Map<String, Node> map = invertMap(identifiers);
|
||||
@@ -133,7 +133,7 @@ public class ASTExpressionTest {
|
||||
assertEquals(template, 1, nodes.size());
|
||||
|
||||
ASTExpression expression = (ASTExpression) nodes.get(0);
|
||||
Map<AbstractVFDataNode, String> identifiers = expression.getDataNodes();
|
||||
Map<VfTypedNode, String> identifiers = expression.getDataNodes();
|
||||
assertEquals(template, 2, identifiers.size());
|
||||
|
||||
Map<String, Node> map = invertMap(identifiers);
|
||||
@@ -206,7 +206,7 @@ public class ASTExpressionTest {
|
||||
/**
|
||||
* Invert the map to make it easier to unit test.
|
||||
*/
|
||||
private Map<String, Node> invertMap(Map<AbstractVFDataNode, String> map) {
|
||||
private Map<String, Node> invertMap(Map<VfTypedNode, String> map) {
|
||||
Map<String, Node> result = map.entrySet().stream()
|
||||
.collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey));
|
||||
// Ensure no values have been lost
|
||||
|
||||
Reference in new issue
Block a user