Merge branch 'pr-2172'

[core] Deprecate jjtree methods from the Node interface
This commit is contained in:
Andreas Dangel
2020-01-17 08:18:50 +01:00
31 changed files with 903 additions and 92 deletions

View File

@ -92,6 +92,10 @@ You can identify them with the `@InternalApi` annotation. You'll also get a depr
##### For removal
* pmd-core
* Many methods on the {% jdoc core::lang.ast.Node %} interface
and {% jdoc core::lang.ast.AbstractNode %} base class. See their javadoc for details.
* pmd-java
* {% jdoc java::lang.java.AbstractJavaParser %}
* {% jdoc java::lang.java.AbstractJavaHandler %}
* [`ASTAnyTypeDeclaration.TypeKind`](https://javadoc.io/page/net.sourceforge.pmd/pmd-java/6.21.0/net/sourceforge/pmd/lang/java/ast/ASTAnyTypeDeclaration.TypeKind.html)
@ -119,6 +123,7 @@ You can identify them with the `@InternalApi` annotation. You'll also get a depr
* {% jdoc java::lang.java.ast.ASTYieldStatement %} will not implement {% jdoc java::lang.java.ast.TypeNode %}
anymore come 7.0.0. Test the type of the expression nested within it.
### External Contributions
* [#2041](https://github.com/pmd/pmd/pull/2041): \[modelica] Initial implementation for PMD - [Anatoly Trosinenko](https://github.com/atrosinenko)

View File

@ -17,7 +17,11 @@ public interface ApexNode<T extends AstNode> extends Node {
/**
* Accept the visitor. *
*
* @deprecated This method is not useful, the logic for combining
* children values should be present on the visitor, not the node
*/
@Deprecated
Object childrenAccept(ApexParserVisitor visitor, Object data);
/**

View File

@ -1,7 +1,6 @@
/**
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
/* Generated By:JJTree: Do not edit this line. Node.java */
package net.sourceforge.pmd.lang.ast;
@ -11,25 +10,55 @@ import java.util.List;
import org.jaxen.JaxenException;
import org.w3c.dom.Document;
import net.sourceforge.pmd.annotation.InternalApi;
import net.sourceforge.pmd.lang.ast.xpath.Attribute;
import net.sourceforge.pmd.lang.dfa.DataFlowNode;
/**
* All AST nodes must implement this interface. It provides basic
* machinery for constructing the parent and child relationships
* between nodes.
* Root interface for all AST nodes. This interface provides only the API
* shared by all AST implementations in PMD language modules. This includes for now:
* <ul>
* <li>Tree traversal methods, like {@link #getParent()} and {@link #getFirstChildOfType(Class)}
* <li>The API used to describe nodes in a form understandable by XPath expressions:
* {@link #getXPathNodeName()}, {@link #getXPathAttributesIterator()}
* <li>Location metadata: eg {@link #getBeginLine()}, {@link #getBeginColumn()}
* </ul>
*
* <p>Every language implementation must publish a sub-interface of Node
* which serves as a supertype for all nodes of that language (e.g.
* pmd-java provides JavaNode, pmd-apex provides ApexNode, etc.). It is
* assumed in many places that the {@link #getChild(int)} and {@link #getParent()}
* method return an instance of this sub-interface. For example,
* no JSP node should have a Java node as its child. Embedding nodes from
* different languages will not be done via these methods, and conforming
* implementations should ensure, that every node returned by these methods
* are indeed of the same type. Possibly, a type parameter will be added to
* the Node interface in 7.0.0 to enforce it at compile-time.
*
* <p>A number of methods are deprecated and will be removed in 7.0.0.
* Most of them are implementation details that clutter this API and
* make implementation more difficult. Some methods prefixed with {@code jjt}
* have a more conventional counterpart (e.g. {@link #jjtGetParent()} and
* {@link #getParent()}) that should be preferred.
*/
public interface Node {
/**
* This method is called after the node has been made the current node. It
* indicates that child nodes can now be added to it.
*
* @deprecated This is JJTree-specific and will be removed from this interface
*/
@Deprecated
void jjtOpen();
/**
* This method is called after all the child nodes have been added.
*
* @deprecated This is JJTree-specific and will be removed from this interface
*/
@Deprecated
void jjtClose();
@ -37,7 +66,10 @@ public interface Node {
* Sets the parent of this node.
*
* @param parent The parent
*
* @deprecated This is JJTree-specific and will be removed from this interface
*/
@Deprecated
void jjtSetParent(Node parent);
@ -45,7 +77,10 @@ public interface Node {
* Returns the parent of this node.
*
* @return The parent of the node
*
* @deprecated Use {@link #getParent()}
*/
@Deprecated
Node jjtGetParent();
@ -55,7 +90,10 @@ public interface Node {
*
* @param child The child to add
* @param index The index to which the child will be added
*
* @deprecated This is JJTree-specific and will be removed from this interface
*/
@Deprecated
void jjtAddChild(Node child, int index);
/**
@ -64,7 +102,10 @@ public interface Node {
*
* @param index
* the child index
*
* @deprecated This is JJTree-specific and will be removed from this interface
*/
@Deprecated
void jjtSetChildIndex(int index);
@ -72,9 +113,13 @@ public interface Node {
* Gets the index of this node in the children of its parent.
*
* @return The index of the node
*
* @deprecated Use {@link #getIndexInParent()}
*/
@Deprecated
int jjtGetChildIndex();
/**
* This method returns a child node. The children are numbered from zero,
* left to right.
@ -82,14 +127,26 @@ public interface Node {
* @param index
* the child index. Must be nonnegative and less than
* {@link #jjtGetNumChildren}.
*
* @deprecated Use {@link #getChild(int)}
*/
@Deprecated
Node jjtGetChild(int index);
/**
* Returns the number of children the node has.
*
* @deprecated Use {@link #getNumChildren()}
*/
@Deprecated
int jjtGetNumChildren();
/**
* @deprecated This is JJTree-specific and will be removed from this interface.
*/
@Deprecated
int jjtGetId();
@ -100,6 +157,12 @@ public interface Node {
*/
String getImage();
/**
* @deprecated This is internal API, the image should never be set by developers.
*/
@InternalApi
@Deprecated
void setImage(String image);
/**
@ -118,8 +181,18 @@ public interface Node {
// FIXME should not be inclusive
int getEndColumn();
/**
* @deprecated This is Java-specific and will be removed from this interface
*/
@Deprecated
DataFlowNode getDataFlowNode();
/**
* @deprecated This is Java-specific and will be removed from this interface
*/
@Deprecated
void setDataFlowNode(DataFlowNode dataFlowNode);
@ -260,7 +333,11 @@ public interface Node {
* the expression to check
* @return List of all matching nodes. Returns an empty list if none found.
* @throws JaxenException if the xpath is incorrect or fails altogether
*
* @deprecated This is very inefficient and should not be used in new code. PMD 7.0.0 will remove
* support for this method.
*/
@Deprecated
List<? extends Node> findChildNodesWithXPath(String xpathString) throws JaxenException;
/**
@ -269,7 +346,11 @@ public interface Node {
* @param xpathString
* the expression to check
* @return true if there is a match
*
* @deprecated This is very inefficient and should not be used in new code. PMD 7.0.0 will remove
* support for this method.
*/
@Deprecated
boolean hasDescendantMatchingXPath(String xpathString);
/**
@ -306,7 +387,11 @@ public interface Node {
/**
* Remove the current node from its parent.
*
* @deprecated This is internal API and will be removed from this interface with 7.0.0
*/
@Deprecated
@InternalApi
void remove();
/**
@ -315,10 +400,48 @@ public interface Node {
*
* @param childIndex
* The index of the child to be removed
*
* @deprecated This is internal API and will be removed from this interface with 7.0.0
*/
@Deprecated
@InternalApi
void removeChildAtIndex(int childIndex);
/**
* Returns the parent of this node, or null if this is the {@linkplain RootNode root}
* of the tree.
*
* <p>This method should be preferred to {@link #jjtGetParent()}.
*
* @return The parent of this node
*/
Node getParent();
/**
* Returns the child of this node at the given index.
*
* @throws IndexOutOfBoundsException if the index is negative or greater than {@link #getNumChildren()}.
*/
Node getChild(int index);
/**
* Returns the number of children of this node.
*/
int getNumChildren();
/**
* Returns the index of this node in its parent's children. If this
* node is a {@linkplain RootNode root node}, returns -1.
*
* <p>This method replaces {@link #jjtGetChildIndex()}, whose name was
* JJTree-specific.
*
* @return The index of this node in its parent's children
*/
int getIndexInParent();
/**
* Gets the name of the node that is used to match it with XPath queries.
*
@ -335,4 +458,21 @@ public interface Node {
*/
Iterator<Attribute> getXPathAttributesIterator();
/**
* Returns an iterable enumerating the children of this node.
* Use it with a foreach loop:
* <pre>{@code
* for (Node child : node.children()) {
* // process child
* }
* }</pre>
*
* <p>This method's return type will be changed to NodeStream
* in PMD 7, which is a more powerful kind of iterable. The
* change will be source compatible.
*
* @return A new iterable for the children of this node
*/
Iterable<? extends Node> children();
}

View File

@ -0,0 +1,49 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.ast.impl.javacc;
import net.sourceforge.pmd.annotation.Experimental;
import net.sourceforge.pmd.lang.ast.AbstractNode;
import net.sourceforge.pmd.lang.ast.Node;
/**
* Base class for node produced by JJTree. JJTree specific functionality
* present on the API of {@link Node} and {@link AbstractNode} will be
* moved here for 7.0.0.
*
* <p>This is experimental because it's expected to change for 7.0.0 in
* unforeseeable ways. Don't use it directly, use the node interfaces.
*/
@Experimental
public abstract class AbstractJjtreeNode<N extends Node> extends AbstractNode {
public AbstractJjtreeNode(int id) {
super(id);
}
public AbstractJjtreeNode(int id, int theBeginLine, int theEndLine, int theBeginColumn, int theEndColumn) {
super(id, theBeginLine, theEndLine, theBeginColumn, theEndColumn);
}
@Override
@SuppressWarnings("unchecked")
public N getChild(int index) {
return (N) super.getChild(index);
}
@Override
@SuppressWarnings("unchecked")
public N getParent() {
return (N) super.getParent();
}
@Override
@SuppressWarnings("unchecked")
public Iterable<N> children() {
return (Iterable<N>) super.children();
}
}

View File

@ -40,7 +40,7 @@ public class AttributeAxisIterator implements Iterator<Attribute> {
= new HashSet<>(Arrays.<Class<?>>asList(Integer.TYPE, Boolean.TYPE, Double.TYPE, String.class,
Long.TYPE, Character.TYPE, Float.TYPE));
private static final Set<String> FILTERED_OUT_NAMES
= new HashSet<>(Arrays.asList("toString", "getClass", "getXPathNodeName", "getTypeNameNode", "hashCode", "getImportedNameNode", "getScope"));
= new HashSet<>(Arrays.asList("toString", "getNumChildren", "getIndexInParent", "getParent", "getClass", "getXPathNodeName", "getTypeNameNode", "hashCode", "getImportedNameNode", "getScope"));
/* Iteration variables */
private Attribute currObj;

View File

@ -5,12 +5,12 @@
package net.sourceforge.pmd.lang.java.ast;
import net.sourceforge.pmd.annotation.InternalApi;
import net.sourceforge.pmd.lang.ast.AbstractNode;
import net.sourceforge.pmd.lang.ast.impl.javacc.AbstractJjtreeNode;
import net.sourceforge.pmd.lang.symboltable.Scope;
@Deprecated
@InternalApi
public abstract class AbstractJavaNode extends AbstractNode implements JavaNode {
public abstract class AbstractJavaNode extends AbstractJjtreeNode<JavaNode> implements JavaNode {
protected JavaParser parser;
private Scope scope;

View File

@ -34,10 +34,26 @@ public interface JavaNode extends ScopedNode {
*
* @param visitor Visitor to dispatch
* @param data Visit data
*
* @deprecated This method is not useful, the logic for combining
* children values should be present on the visitor, not the node
*/
@Deprecated
Object childrenAccept(JavaParserVisitor visitor, Object data);
@Override
JavaNode getChild(int index);
@Override
JavaNode getParent();
@Override
Iterable<JavaNode> children();
@InternalApi
@Deprecated
void setScope(Scope scope);

View File

@ -10,7 +10,129 @@ import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.java.JavaLanguageModule;
import net.sourceforge.pmd.lang.java.ast.*;
import net.sourceforge.pmd.lang.java.ast.ASTAdditiveExpression;
import net.sourceforge.pmd.lang.java.ast.ASTAllocationExpression;
import net.sourceforge.pmd.lang.java.ast.ASTAndExpression;
import net.sourceforge.pmd.lang.java.ast.ASTAnnotation;
import net.sourceforge.pmd.lang.java.ast.ASTAnnotationMethodDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTAnnotationTypeBody;
import net.sourceforge.pmd.lang.java.ast.ASTAnnotationTypeDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTAnnotationTypeMemberDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTArgumentList;
import net.sourceforge.pmd.lang.java.ast.ASTArguments;
import net.sourceforge.pmd.lang.java.ast.ASTArrayDimsAndInits;
import net.sourceforge.pmd.lang.java.ast.ASTArrayInitializer;
import net.sourceforge.pmd.lang.java.ast.ASTAssertStatement;
import net.sourceforge.pmd.lang.java.ast.ASTAssignmentOperator;
import net.sourceforge.pmd.lang.java.ast.ASTBlock;
import net.sourceforge.pmd.lang.java.ast.ASTBlockStatement;
import net.sourceforge.pmd.lang.java.ast.ASTBooleanLiteral;
import net.sourceforge.pmd.lang.java.ast.ASTBreakStatement;
import net.sourceforge.pmd.lang.java.ast.ASTCastExpression;
import net.sourceforge.pmd.lang.java.ast.ASTCatchStatement;
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBody;
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBodyDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType;
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
import net.sourceforge.pmd.lang.java.ast.ASTConditionalAndExpression;
import net.sourceforge.pmd.lang.java.ast.ASTConditionalExpression;
import net.sourceforge.pmd.lang.java.ast.ASTConditionalOrExpression;
import net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTContinueStatement;
import net.sourceforge.pmd.lang.java.ast.ASTDefaultValue;
import net.sourceforge.pmd.lang.java.ast.ASTDoStatement;
import net.sourceforge.pmd.lang.java.ast.ASTEmptyStatement;
import net.sourceforge.pmd.lang.java.ast.ASTEnumBody;
import net.sourceforge.pmd.lang.java.ast.ASTEnumConstant;
import net.sourceforge.pmd.lang.java.ast.ASTEnumDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTEqualityExpression;
import net.sourceforge.pmd.lang.java.ast.ASTExclusiveOrExpression;
import net.sourceforge.pmd.lang.java.ast.ASTExplicitConstructorInvocation;
import net.sourceforge.pmd.lang.java.ast.ASTExpression;
import net.sourceforge.pmd.lang.java.ast.ASTExtendsList;
import net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTFinallyStatement;
import net.sourceforge.pmd.lang.java.ast.ASTForInit;
import net.sourceforge.pmd.lang.java.ast.ASTForStatement;
import net.sourceforge.pmd.lang.java.ast.ASTForUpdate;
import net.sourceforge.pmd.lang.java.ast.ASTFormalParameter;
import net.sourceforge.pmd.lang.java.ast.ASTFormalParameters;
import net.sourceforge.pmd.lang.java.ast.ASTIfStatement;
import net.sourceforge.pmd.lang.java.ast.ASTImplementsList;
import net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTInclusiveOrExpression;
import net.sourceforge.pmd.lang.java.ast.ASTInitializer;
import net.sourceforge.pmd.lang.java.ast.ASTInstanceOfExpression;
import net.sourceforge.pmd.lang.java.ast.ASTLabeledStatement;
import net.sourceforge.pmd.lang.java.ast.ASTLambdaExpression;
import net.sourceforge.pmd.lang.java.ast.ASTLiteral;
import net.sourceforge.pmd.lang.java.ast.ASTLocalVariableDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTMarkerAnnotation;
import net.sourceforge.pmd.lang.java.ast.ASTMemberSelector;
import net.sourceforge.pmd.lang.java.ast.ASTMemberValue;
import net.sourceforge.pmd.lang.java.ast.ASTMemberValueArrayInitializer;
import net.sourceforge.pmd.lang.java.ast.ASTMemberValuePair;
import net.sourceforge.pmd.lang.java.ast.ASTMemberValuePairs;
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclarator;
import net.sourceforge.pmd.lang.java.ast.ASTMethodReference;
import net.sourceforge.pmd.lang.java.ast.ASTModuleDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTModuleDirective;
import net.sourceforge.pmd.lang.java.ast.ASTModuleName;
import net.sourceforge.pmd.lang.java.ast.ASTMultiplicativeExpression;
import net.sourceforge.pmd.lang.java.ast.ASTName;
import net.sourceforge.pmd.lang.java.ast.ASTNameList;
import net.sourceforge.pmd.lang.java.ast.ASTNormalAnnotation;
import net.sourceforge.pmd.lang.java.ast.ASTNullLiteral;
import net.sourceforge.pmd.lang.java.ast.ASTPackageDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTPostfixExpression;
import net.sourceforge.pmd.lang.java.ast.ASTPreDecrementExpression;
import net.sourceforge.pmd.lang.java.ast.ASTPreIncrementExpression;
import net.sourceforge.pmd.lang.java.ast.ASTPrimaryExpression;
import net.sourceforge.pmd.lang.java.ast.ASTPrimaryPrefix;
import net.sourceforge.pmd.lang.java.ast.ASTPrimarySuffix;
import net.sourceforge.pmd.lang.java.ast.ASTPrimitiveType;
import net.sourceforge.pmd.lang.java.ast.ASTRSIGNEDSHIFT;
import net.sourceforge.pmd.lang.java.ast.ASTRUNSIGNEDSHIFT;
import net.sourceforge.pmd.lang.java.ast.ASTReferenceType;
import net.sourceforge.pmd.lang.java.ast.ASTRelationalExpression;
import net.sourceforge.pmd.lang.java.ast.ASTResource;
import net.sourceforge.pmd.lang.java.ast.ASTResourceSpecification;
import net.sourceforge.pmd.lang.java.ast.ASTResources;
import net.sourceforge.pmd.lang.java.ast.ASTResultType;
import net.sourceforge.pmd.lang.java.ast.ASTReturnStatement;
import net.sourceforge.pmd.lang.java.ast.ASTShiftExpression;
import net.sourceforge.pmd.lang.java.ast.ASTSingleMemberAnnotation;
import net.sourceforge.pmd.lang.java.ast.ASTStatement;
import net.sourceforge.pmd.lang.java.ast.ASTStatementExpression;
import net.sourceforge.pmd.lang.java.ast.ASTStatementExpressionList;
import net.sourceforge.pmd.lang.java.ast.ASTSwitchExpression;
import net.sourceforge.pmd.lang.java.ast.ASTSwitchLabel;
import net.sourceforge.pmd.lang.java.ast.ASTSwitchLabeledBlock;
import net.sourceforge.pmd.lang.java.ast.ASTSwitchLabeledExpression;
import net.sourceforge.pmd.lang.java.ast.ASTSwitchLabeledThrowStatement;
import net.sourceforge.pmd.lang.java.ast.ASTSwitchStatement;
import net.sourceforge.pmd.lang.java.ast.ASTSynchronizedStatement;
import net.sourceforge.pmd.lang.java.ast.ASTThrowStatement;
import net.sourceforge.pmd.lang.java.ast.ASTTryStatement;
import net.sourceforge.pmd.lang.java.ast.ASTType;
import net.sourceforge.pmd.lang.java.ast.ASTTypeArgument;
import net.sourceforge.pmd.lang.java.ast.ASTTypeArguments;
import net.sourceforge.pmd.lang.java.ast.ASTTypeBound;
import net.sourceforge.pmd.lang.java.ast.ASTTypeDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTTypeParameter;
import net.sourceforge.pmd.lang.java.ast.ASTTypeParameters;
import net.sourceforge.pmd.lang.java.ast.ASTUnaryExpression;
import net.sourceforge.pmd.lang.java.ast.ASTUnaryExpressionNotPlusMinus;
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclarator;
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId;
import net.sourceforge.pmd.lang.java.ast.ASTVariableInitializer;
import net.sourceforge.pmd.lang.java.ast.ASTWhileStatement;
import net.sourceforge.pmd.lang.java.ast.ASTWildcardBounds;
import net.sourceforge.pmd.lang.java.ast.ASTYieldStatement;
import net.sourceforge.pmd.lang.java.ast.JavaNode;
import net.sourceforge.pmd.lang.java.ast.JavaParserVisitor;
import net.sourceforge.pmd.lang.rule.AbstractRule;
import net.sourceforge.pmd.lang.rule.ImmutableLanguage;
@ -92,7 +214,9 @@ public abstract class AbstractJavaRule extends AbstractRule implements JavaParse
//
@Override
public Object visit(JavaNode node, Object data) {
node.childrenAccept(this, data);
for (JavaNode child : node.children()) {
child.jjtAccept(this, data);
}
return null;
}

View File

@ -17,7 +17,11 @@ public interface EcmascriptNode<T extends AstNode> extends Node {
/**
* Accept the visitor. *
*
* @deprecated This method is not useful, the logic for combining
* children values should be present on the visitor, not the node
*/
@Deprecated
Object childrenAccept(EcmascriptParserVisitor visitor, Object data);
/**

View File

@ -4,9 +4,9 @@
package net.sourceforge.pmd.lang.jsp.ast;
import net.sourceforge.pmd.lang.ast.AbstractNode;
import net.sourceforge.pmd.lang.ast.impl.javacc.AbstractJjtreeNode;
public class AbstractJspNode extends AbstractNode implements JspNode {
public class AbstractJspNode extends AbstractJjtreeNode<JspNode> implements JspNode {
protected JspParser parser;

View File

@ -7,13 +7,30 @@ package net.sourceforge.pmd.lang.jsp.ast;
import net.sourceforge.pmd.lang.ast.Node;
public interface JspNode extends Node {
/**
* Accept the visitor. *
*/
Object jjtAccept(JspParserVisitor visitor, Object data);
/**
* Accept the visitor. *
* @deprecated This method is not useful, the logic for combining
* children values should be present on the visitor, not the node
*/
@Deprecated
Object childrenAccept(JspParserVisitor visitor, Object data);
@Override
JspNode getChild(int index);
@Override
JspNode getParent();
@Override
Iterable<JspNode> children();
}

View File

@ -68,7 +68,9 @@ public abstract class AbstractJspRule extends AbstractRule implements JspParserV
@Override
public Object visit(JspNode node, Object data) {
node.childrenAccept(this, data);
for (JspNode child : node.children()) {
child.jjtAccept(this, data);
}
return null;
}

View File

@ -55,8 +55,8 @@ abstract class AbstractModelicaClassSpecifierNode extends AbstractModelicaNode i
}
void pushExtendsAndImports(ModelicaClassType classTypeDeclaration, ASTComposition composition) {
for (int i = 0; i < composition.jjtGetNumChildren(); ++i) {
ModelicaNode maybeElementList = composition.jjtGetChild(i);
for (int i = 0; i < composition.getNumChildren(); ++i) {
ModelicaNode maybeElementList = composition.getChild(i);
if (maybeElementList instanceof ASTElementList) {
pushExtendsAndImportsFromList(classTypeDeclaration, (ASTElementList) maybeElementList);
}

View File

@ -4,9 +4,8 @@
package net.sourceforge.pmd.lang.modelica.ast;
import net.sourceforge.pmd.lang.ast.AbstractNode;
import net.sourceforge.pmd.lang.ast.GenericToken;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.impl.javacc.AbstractJjtreeNode;
import net.sourceforge.pmd.lang.modelica.resolver.ModelicaScope;
/**
@ -18,7 +17,7 @@ import net.sourceforge.pmd.lang.modelica.resolver.ModelicaScope;
*
* @see ModelicaNode for public API.
*/
abstract class AbstractModelicaNode extends AbstractNode implements Node, ModelicaNode {
abstract class AbstractModelicaNode extends AbstractJjtreeNode<ModelicaNode> implements ModelicaNode {
/**
* Kind for implicit tokens. Negative because JavaCC only picks
@ -46,16 +45,6 @@ abstract class AbstractModelicaNode extends AbstractNode implements Node, Modeli
return getClass().getSimpleName().substring(3);
}
@Override
public ModelicaNode jjtGetParent() {
return (ModelicaNode) super.jjtGetParent();
}
@Override
public ModelicaNode jjtGetChild(int index) {
return (ModelicaNode) super.jjtGetChild(index);
}
@Override
public int getBeginLine() {
return jjtGetFirstToken().getBeginLine();

View File

@ -11,6 +11,7 @@ import net.sourceforge.pmd.lang.modelica.resolver.ModelicaScope;
* Public interface for all Modelica AST nodes.
*/
public interface ModelicaNode extends Node {
/**
* Returns the lexical scope this node is contained in.
*/
@ -19,15 +20,20 @@ public interface ModelicaNode extends Node {
/**
* Returns the most specific lexical scope naturally associated with this node.
*
* @return the scope defined by this node itself or the same as {@link #getContainingScope} otherwise
* @return the scope defined by this node itself or the same as {@link #getContainingScope()} otherwise
*/
ModelicaScope getMostSpecificScope();
Object jjtAccept(ModelicaParserVisitor visitor, Object data);
@Override
ModelicaNode jjtGetParent();
ModelicaNode getParent();
@Override
ModelicaNode jjtGetChild(int index);
ModelicaNode getChild(int index);
@Override
Iterable<ModelicaNode> children();
}

View File

@ -8,8 +8,8 @@ public class ModelicaParserVisitorAdapter implements ModelicaParserVisitor {
@Override
public Object visit(ModelicaNode node, Object data) {
for (int i = 0; i < node.jjtGetNumChildren(); ++i) {
node.jjtGetChild(i).jjtAccept(this, data);
for (ModelicaNode child : node.children()) {
child.jjtAccept(this, data);
}
return data;
}

View File

@ -29,7 +29,7 @@ public class ScopeAndDeclarationFinder extends ModelicaParserVisitorAdapter {
}
private void createClassDeclaration(ASTClassDefinition node) {
ModelicaScope containingScope = ((ModelicaNode) node.jjtGetParent()).getMostSpecificScope();
ModelicaScope containingScope = node.getParent().getMostSpecificScope();
ModelicaClassDeclaration declaration = new ModelicaClassDeclaration(node);
((AbstractModelicaScope) containingScope).addDeclaration(declaration);

View File

@ -179,8 +179,8 @@ public abstract class AbstractModelicaRule extends AbstractRule implements Model
@Override
public Object visit(ModelicaNode node, Object data) {
for (int i = 0; i < node.jjtGetNumChildren(); ++i) {
node.jjtGetChild(i).jjtAccept(this, data);
for (ModelicaNode child : node.children()) {
child.jjtAccept(this, data);
}
return data;
}

View File

@ -7,9 +7,10 @@
package net.sourceforge.pmd.lang.plsql.ast;
import net.sourceforge.pmd.lang.ast.impl.javacc.AbstractJjtreeNode;
import net.sourceforge.pmd.lang.symboltable.Scope;
public abstract class AbstractPLSQLNode extends net.sourceforge.pmd.lang.ast.AbstractNode implements PLSQLNode {
public abstract class AbstractPLSQLNode extends AbstractJjtreeNode<PLSQLNode> implements PLSQLNode {
protected Object value;
protected PLSQLParser parser;
protected Scope scope;

View File

@ -13,7 +13,14 @@ public interface PLSQLNode extends Node, ScopedNode {
/** Accept the visitor. **/
Object jjtAccept(PLSQLParserVisitor visitor, Object data);
/** Accept the visitor. **/
/**
* Accept the visitor.
*
* @deprecated This method is not useful, the logic for combining
* children values should be present on the visitor, not the node
*/
@Deprecated
Object childrenAccept(PLSQLParserVisitor visitor, Object data);
@Override
@ -21,4 +28,13 @@ public interface PLSQLNode extends Node, ScopedNode {
void setScope(Scope scope);
@Override
PLSQLNode getChild(int index);
@Override
PLSQLNode getParent();
@Override
Iterable<PLSQLNode> children();
}

View File

@ -11,7 +11,231 @@ import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.plsql.PLSQLLanguageModule;
import net.sourceforge.pmd.lang.plsql.ast.*;
import net.sourceforge.pmd.lang.plsql.ast.ASTAccessibleByClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTAdditiveExpression;
import net.sourceforge.pmd.lang.plsql.ast.ASTAlterTrigger;
import net.sourceforge.pmd.lang.plsql.ast.ASTAlterTypeSpec;
import net.sourceforge.pmd.lang.plsql.ast.ASTAnalyticClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTArgument;
import net.sourceforge.pmd.lang.plsql.ast.ASTArgumentList;
import net.sourceforge.pmd.lang.plsql.ast.ASTArguments;
import net.sourceforge.pmd.lang.plsql.ast.ASTAssignment;
import net.sourceforge.pmd.lang.plsql.ast.ASTAttribute;
import net.sourceforge.pmd.lang.plsql.ast.ASTAttributeDeclaration;
import net.sourceforge.pmd.lang.plsql.ast.ASTBetweenCondition;
import net.sourceforge.pmd.lang.plsql.ast.ASTBlock;
import net.sourceforge.pmd.lang.plsql.ast.ASTBooleanLiteral;
import net.sourceforge.pmd.lang.plsql.ast.ASTBulkCollectIntoClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTCallSpecTail;
import net.sourceforge.pmd.lang.plsql.ast.ASTCaseExpression;
import net.sourceforge.pmd.lang.plsql.ast.ASTCaseStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTCaseWhenClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTCloseStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTCollectionDeclaration;
import net.sourceforge.pmd.lang.plsql.ast.ASTCollectionName;
import net.sourceforge.pmd.lang.plsql.ast.ASTCollectionTypeDefinition;
import net.sourceforge.pmd.lang.plsql.ast.ASTCollectionTypeName;
import net.sourceforge.pmd.lang.plsql.ast.ASTColumn;
import net.sourceforge.pmd.lang.plsql.ast.ASTColumnAlias;
import net.sourceforge.pmd.lang.plsql.ast.ASTComment;
import net.sourceforge.pmd.lang.plsql.ast.ASTComparisonCondition;
import net.sourceforge.pmd.lang.plsql.ast.ASTCompilationDataType;
import net.sourceforge.pmd.lang.plsql.ast.ASTCompilationDeclarationFragment;
import net.sourceforge.pmd.lang.plsql.ast.ASTCompilationExpression;
import net.sourceforge.pmd.lang.plsql.ast.ASTCompoundCondition;
import net.sourceforge.pmd.lang.plsql.ast.ASTCompoundTriggerBlock;
import net.sourceforge.pmd.lang.plsql.ast.ASTCondition;
import net.sourceforge.pmd.lang.plsql.ast.ASTConditionalAndExpression;
import net.sourceforge.pmd.lang.plsql.ast.ASTConditionalCompilationStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTConditionalInsertClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTConditionalOrExpression;
import net.sourceforge.pmd.lang.plsql.ast.ASTContinueStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTCrossOuterApplyClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTCursorBody;
import net.sourceforge.pmd.lang.plsql.ast.ASTCursorForLoopStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTCursorSpecification;
import net.sourceforge.pmd.lang.plsql.ast.ASTCursorUnit;
import net.sourceforge.pmd.lang.plsql.ast.ASTDDLCommand;
import net.sourceforge.pmd.lang.plsql.ast.ASTDDLEvent;
import net.sourceforge.pmd.lang.plsql.ast.ASTDMLTableExpressionClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTDatabaseEvent;
import net.sourceforge.pmd.lang.plsql.ast.ASTDatabaseLink;
import net.sourceforge.pmd.lang.plsql.ast.ASTDatatype;
import net.sourceforge.pmd.lang.plsql.ast.ASTDatatypeDeclaration;
import net.sourceforge.pmd.lang.plsql.ast.ASTDateTimeLiteral;
import net.sourceforge.pmd.lang.plsql.ast.ASTDeclarativeSection;
import net.sourceforge.pmd.lang.plsql.ast.ASTDeclarativeUnit;
import net.sourceforge.pmd.lang.plsql.ast.ASTDeleteStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTDirectory;
import net.sourceforge.pmd.lang.plsql.ast.ASTElseClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTElsifClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTEmbeddedSqlStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTEqualityExpression;
import net.sourceforge.pmd.lang.plsql.ast.ASTErrorLoggingClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTExceptionDeclaration;
import net.sourceforge.pmd.lang.plsql.ast.ASTExceptionHandler;
import net.sourceforge.pmd.lang.plsql.ast.ASTExistsCondition;
import net.sourceforge.pmd.lang.plsql.ast.ASTExitStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTExpression;
import net.sourceforge.pmd.lang.plsql.ast.ASTExpressionList;
import net.sourceforge.pmd.lang.plsql.ast.ASTExpressionListMultiple;
import net.sourceforge.pmd.lang.plsql.ast.ASTExpressionListSingle;
import net.sourceforge.pmd.lang.plsql.ast.ASTExtractExpression;
import net.sourceforge.pmd.lang.plsql.ast.ASTFetchStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTFieldDeclaration;
import net.sourceforge.pmd.lang.plsql.ast.ASTFloatingPointCondition;
import net.sourceforge.pmd.lang.plsql.ast.ASTForAllIndex;
import net.sourceforge.pmd.lang.plsql.ast.ASTForAllStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTForIndex;
import net.sourceforge.pmd.lang.plsql.ast.ASTForStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTForUpdateClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTFormalParameter;
import net.sourceforge.pmd.lang.plsql.ast.ASTFormalParameters;
import net.sourceforge.pmd.lang.plsql.ast.ASTFromClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTFunctionCall;
import net.sourceforge.pmd.lang.plsql.ast.ASTFunctionName;
import net.sourceforge.pmd.lang.plsql.ast.ASTGlobal;
import net.sourceforge.pmd.lang.plsql.ast.ASTGotoStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTGroupByClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTGroupingExpressionList;
import net.sourceforge.pmd.lang.plsql.ast.ASTGroupingSetsClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTHierarchicalQueryClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTHostArrayName;
import net.sourceforge.pmd.lang.plsql.ast.ASTID;
import net.sourceforge.pmd.lang.plsql.ast.ASTIfStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTInCondition;
import net.sourceforge.pmd.lang.plsql.ast.ASTInlineConstraint;
import net.sourceforge.pmd.lang.plsql.ast.ASTInlinePragma;
import net.sourceforge.pmd.lang.plsql.ast.ASTInnerCrossJoinClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTInput;
import net.sourceforge.pmd.lang.plsql.ast.ASTInsertIntoClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTInsertStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTIntoClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTIsASetCondition;
import net.sourceforge.pmd.lang.plsql.ast.ASTIsEmptyCondition;
import net.sourceforge.pmd.lang.plsql.ast.ASTIsNullCondition;
import net.sourceforge.pmd.lang.plsql.ast.ASTIsOfTypeCondition;
import net.sourceforge.pmd.lang.plsql.ast.ASTJavaInterfaceClass;
import net.sourceforge.pmd.lang.plsql.ast.ASTJoinClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTKEYWORD_UNRESERVED;
import net.sourceforge.pmd.lang.plsql.ast.ASTLabel;
import net.sourceforge.pmd.lang.plsql.ast.ASTLabelledStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTLikeCondition;
import net.sourceforge.pmd.lang.plsql.ast.ASTLikeExpression;
import net.sourceforge.pmd.lang.plsql.ast.ASTListaggOverflowClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTLiteral;
import net.sourceforge.pmd.lang.plsql.ast.ASTLoopStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTMemberCondition;
import net.sourceforge.pmd.lang.plsql.ast.ASTMethodDeclaration;
import net.sourceforge.pmd.lang.plsql.ast.ASTMethodDeclarator;
import net.sourceforge.pmd.lang.plsql.ast.ASTMultiSetCondition;
import net.sourceforge.pmd.lang.plsql.ast.ASTMultiTableInsert;
import net.sourceforge.pmd.lang.plsql.ast.ASTMultiplicativeExpression;
import net.sourceforge.pmd.lang.plsql.ast.ASTName;
import net.sourceforge.pmd.lang.plsql.ast.ASTNonDMLEvent;
import net.sourceforge.pmd.lang.plsql.ast.ASTNonDMLTrigger;
import net.sourceforge.pmd.lang.plsql.ast.ASTNullLiteral;
import net.sourceforge.pmd.lang.plsql.ast.ASTNumericLiteral;
import net.sourceforge.pmd.lang.plsql.ast.ASTObjectDeclaration;
import net.sourceforge.pmd.lang.plsql.ast.ASTObjectExpression;
import net.sourceforge.pmd.lang.plsql.ast.ASTObjectNameDeclaration;
import net.sourceforge.pmd.lang.plsql.ast.ASTOpenStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTOrderByClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTOutOfLineConstraint;
import net.sourceforge.pmd.lang.plsql.ast.ASTOuterJoinClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTOuterJoinExpression;
import net.sourceforge.pmd.lang.plsql.ast.ASTOuterJoinType;
import net.sourceforge.pmd.lang.plsql.ast.ASTPackageBody;
import net.sourceforge.pmd.lang.plsql.ast.ASTPackageSpecification;
import net.sourceforge.pmd.lang.plsql.ast.ASTParallelClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTPartitionExtensionClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTPipelineStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTPragma;
import net.sourceforge.pmd.lang.plsql.ast.ASTPragmaClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTPrimaryExpression;
import net.sourceforge.pmd.lang.plsql.ast.ASTPrimaryPrefix;
import net.sourceforge.pmd.lang.plsql.ast.ASTPrimarySuffix;
import net.sourceforge.pmd.lang.plsql.ast.ASTProgramUnit;
import net.sourceforge.pmd.lang.plsql.ast.ASTQualifiedID;
import net.sourceforge.pmd.lang.plsql.ast.ASTQualifiedName;
import net.sourceforge.pmd.lang.plsql.ast.ASTQueryBlock;
import net.sourceforge.pmd.lang.plsql.ast.ASTQueryPartitionClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTRaiseStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTRead2NextOccurrence;
import net.sourceforge.pmd.lang.plsql.ast.ASTReadPastNextOccurrence;
import net.sourceforge.pmd.lang.plsql.ast.ASTReferencesClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTRegexpLikeCondition;
import net.sourceforge.pmd.lang.plsql.ast.ASTRelationalExpression;
import net.sourceforge.pmd.lang.plsql.ast.ASTReturnStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTReturningClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTRollupCubeClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTRowLimitingClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTScalarDataTypeName;
import net.sourceforge.pmd.lang.plsql.ast.ASTSchemaName;
import net.sourceforge.pmd.lang.plsql.ast.ASTSelectIntoStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTSelectList;
import net.sourceforge.pmd.lang.plsql.ast.ASTSelectStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTSimpleExpression;
import net.sourceforge.pmd.lang.plsql.ast.ASTSingleTableInsert;
import net.sourceforge.pmd.lang.plsql.ast.ASTSkip2NextOccurrence;
import net.sourceforge.pmd.lang.plsql.ast.ASTSkip2NextTerminator;
import net.sourceforge.pmd.lang.plsql.ast.ASTSkip2NextTokenOccurrence;
import net.sourceforge.pmd.lang.plsql.ast.ASTSkipPastNextOccurrence;
import net.sourceforge.pmd.lang.plsql.ast.ASTSkipPastNextTokenOccurrence;
import net.sourceforge.pmd.lang.plsql.ast.ASTSqlExpression;
import net.sourceforge.pmd.lang.plsql.ast.ASTSqlPlusCommand;
import net.sourceforge.pmd.lang.plsql.ast.ASTSqlStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTStringExpression;
import net.sourceforge.pmd.lang.plsql.ast.ASTStringLiteral;
import net.sourceforge.pmd.lang.plsql.ast.ASTSubTypeDefinition;
import net.sourceforge.pmd.lang.plsql.ast.ASTSubmultisetCondition;
import net.sourceforge.pmd.lang.plsql.ast.ASTSubqueryOperation;
import net.sourceforge.pmd.lang.plsql.ast.ASTSubqueryRestrictionClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTSynonym;
import net.sourceforge.pmd.lang.plsql.ast.ASTTable;
import net.sourceforge.pmd.lang.plsql.ast.ASTTableAlias;
import net.sourceforge.pmd.lang.plsql.ast.ASTTableCollectionExpression;
import net.sourceforge.pmd.lang.plsql.ast.ASTTableColumn;
import net.sourceforge.pmd.lang.plsql.ast.ASTTableName;
import net.sourceforge.pmd.lang.plsql.ast.ASTTableReference;
import net.sourceforge.pmd.lang.plsql.ast.ASTTriggerTimingPointSection;
import net.sourceforge.pmd.lang.plsql.ast.ASTTriggerUnit;
import net.sourceforge.pmd.lang.plsql.ast.ASTTrimExpression;
import net.sourceforge.pmd.lang.plsql.ast.ASTTypeKeyword;
import net.sourceforge.pmd.lang.plsql.ast.ASTTypeMethod;
import net.sourceforge.pmd.lang.plsql.ast.ASTTypeSpecification;
import net.sourceforge.pmd.lang.plsql.ast.ASTUnaryExpression;
import net.sourceforge.pmd.lang.plsql.ast.ASTUnaryExpressionNotPlusMinus;
import net.sourceforge.pmd.lang.plsql.ast.ASTUnlabelledStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTUnqualifiedID;
import net.sourceforge.pmd.lang.plsql.ast.ASTUpdateSetClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTUpdateStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTValuesClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTVariableName;
import net.sourceforge.pmd.lang.plsql.ast.ASTVariableOrConstantDeclaration;
import net.sourceforge.pmd.lang.plsql.ast.ASTVariableOrConstantDeclarator;
import net.sourceforge.pmd.lang.plsql.ast.ASTVariableOrConstantDeclaratorId;
import net.sourceforge.pmd.lang.plsql.ast.ASTVariableOrConstantInitializer;
import net.sourceforge.pmd.lang.plsql.ast.ASTView;
import net.sourceforge.pmd.lang.plsql.ast.ASTViewColumn;
import net.sourceforge.pmd.lang.plsql.ast.ASTWhereClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTWhileStatement;
import net.sourceforge.pmd.lang.plsql.ast.ASTWindowingClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTWithClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTWithinClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTWrappedObject;
import net.sourceforge.pmd.lang.plsql.ast.ASTXMLAttributesClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTXMLElement;
import net.sourceforge.pmd.lang.plsql.ast.ASTXMLExists;
import net.sourceforge.pmd.lang.plsql.ast.ASTXMLNamespacesClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTXMLPassingClause;
import net.sourceforge.pmd.lang.plsql.ast.ASTXMLTable;
import net.sourceforge.pmd.lang.plsql.ast.ASTXMLTableColum;
import net.sourceforge.pmd.lang.plsql.ast.ASTXMLTableOptions;
import net.sourceforge.pmd.lang.plsql.ast.ExecutableCode;
import net.sourceforge.pmd.lang.plsql.ast.PLSQLNode;
import net.sourceforge.pmd.lang.plsql.ast.PLSQLParserVisitor;
import net.sourceforge.pmd.lang.rule.AbstractRule;
import net.sourceforge.pmd.lang.rule.ImmutableLanguage;
@ -94,7 +318,9 @@ public abstract class AbstractPLSQLRule extends AbstractRule implements PLSQLPar
*/
@Override
public Object visit(PLSQLNode node, Object data) {
node.childrenAccept(this, data);
for (PLSQLNode child : node.children()) {
child.jjtAccept(this, data);
}
return null;
}

View File

@ -32,6 +32,12 @@ abstract class AbstractScalaNode<T extends Tree> extends AbstractNode implements
pos = node.pos();
}
@Override
@SuppressWarnings("unchecked")
public Iterable<ScalaNode<?>> children() {
return (Iterable<ScalaNode<?>>) super.children();
}
@Override
public boolean isImplicit() {
return pos.end() - pos.start() == 0;
@ -86,12 +92,12 @@ abstract class AbstractScalaNode<T extends Tree> extends AbstractNode implements
}
@Override
public ScalaNode<?> jjtGetChild(int index) {
public ScalaNode<?> getChild(int index) {
return (ScalaNode<?>) super.jjtGetChild(index);
}
@Override
public ScalaNode<?> jjtGetParent() {
public ScalaNode<?> getParent() {
return (ScalaNode<?>) super.jjtGetParent();
}

View File

@ -54,9 +54,13 @@ public interface ScalaNode<T extends Tree> extends Node {
@Override
ScalaNode<?> jjtGetChild(int idx);
ScalaNode<?> getChild(int idx);
@Override
ScalaNode<?> jjtGetParent();
ScalaNode<?> getParent();
@Override
Iterable<ScalaNode<?>> children();
}

View File

@ -48,8 +48,8 @@ public class ScalaParserVisitorAdapter<D, R> implements ScalaParserVisitor<D, R>
@Override
public R visit(ScalaNode<?> node, D data) {
R returnValue = zero();
for (int i = 0; i < node.jjtGetNumChildren(); ++i) {
returnValue = combine(returnValue, node.jjtGetChild(i).accept(this, data));
for (int i = 0; i < node.getNumChildren(); ++i) {
returnValue = combine(returnValue, node.getChild(i).accept(this, data));
}
return returnValue;
}

View File

@ -186,8 +186,8 @@ public class ScalaRule extends AbstractRule implements ScalaParserVisitor<RuleCo
@Override
public RuleContext visit(ScalaNode<?> node, RuleContext data) {
for (int i = 0; i < node.jjtGetNumChildren(); ++i) {
node.jjtGetChild(i).accept(this, data);
for (ScalaNode<?> child : node.children()) {
child.accept(this, data);
}
return data;
}

View File

@ -4,9 +4,9 @@
package net.sourceforge.pmd.lang.vf.ast;
import net.sourceforge.pmd.lang.ast.AbstractNode;
import net.sourceforge.pmd.lang.ast.impl.javacc.AbstractJjtreeNode;
public class AbstractVFNode extends AbstractNode implements VfNode {
public class AbstractVFNode extends AbstractJjtreeNode<VfNode> implements VfNode {
protected VfParser parser;

View File

@ -7,13 +7,32 @@ package net.sourceforge.pmd.lang.vf.ast;
import net.sourceforge.pmd.lang.ast.Node;
public interface VfNode extends Node {
/**
* Accept the visitor. *
*/
Object jjtAccept(VfParserVisitor visitor, Object data);
/**
* Accept the visitor. *
*
* @deprecated This method is not useful, the logic for combining
* children values should be present on the visitor, not the node
*/
@Deprecated
Object childrenAccept(VfParserVisitor visitor, Object data);
@Override
VfNode getParent();
@Override
VfNode getChild(int i);
@Override
Iterable<VfNode> children();
}

View File

@ -25,12 +25,13 @@ import java.io.Writer;
import org.apache.commons.lang3.text.StrBuilder;
import net.sourceforge.pmd.lang.ast.AbstractNode;
import net.sourceforge.pmd.annotation.InternalApi;
import net.sourceforge.pmd.lang.ast.impl.javacc.AbstractJjtreeNode;
/**
*
*/
public class AbstractVmNode extends AbstractNode implements VmNode {
public class AbstractVmNode extends AbstractJjtreeNode<VmNode> implements VmNode {
/** */
// TODO - It seems that this field is only valid when parsing, and should
@ -93,9 +94,8 @@ public class AbstractVmNode extends AbstractNode implements VmNode {
endColumn = parser.token.endColumn;
}
/**
* @param t
*/
@InternalApi
@Deprecated
public void setFirstToken(final Token t) {
this.first = t;
}
@ -115,10 +115,8 @@ public class AbstractVmNode extends AbstractNode implements VmNode {
@Override
public Object childrenAccept(final VmParserVisitor visitor, final Object data) {
if (children != null) {
for (int i = 0; i < children.length; ++i) {
((VmNode) children[i]).jjtAccept(visitor, data);
}
for (VmNode c : children()) {
c.jjtAccept(visitor, data);
}
return data;
}

View File

@ -12,9 +12,26 @@ public interface VmNode extends Node {
*/
Object jjtAccept(VmParserVisitor visitor, Object data);
/**
* Accept the visitor. *
*
* @deprecated This method is not useful, the logic for combining
* children values should be present on the visitor, not the node
*/
@Deprecated
Object childrenAccept(VmParserVisitor visitor, Object data);
@Override
VmNode getChild(int index);
@Override
VmNode getParent();
@Override
Iterable<VmNode> children();
}

Some files were not shown because too many files have changed in this diff Show More