Skip to content

Commit

Permalink
Add TokenBasedNode, AbstractJjtreeNode
Browse files Browse the repository at this point in the history
  • Loading branch information
oowekyala committed Dec 17, 2019
1 parent cf843a8 commit 98df6bd
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,10 @@ public void setUserData(final Object userData) {
this.userData = userData;
}

// TODO should we deprecate this too?
/**
* @deprecated Not all nodes have access to their tokens, use the interface {@link TokenBasedNode} instead
*/
@Deprecated
public GenericToken jjtGetFirstToken() {
return firstToken;
}
Expand All @@ -546,7 +549,10 @@ public void jjtSetFirstToken(final GenericToken token) {
this.firstToken = token;
}

// TODO should we deprecate this too?
/**
* @deprecated Not all nodes have access to their tokens, use the interface {@link TokenBasedNode} instead
*/
@Deprecated
public GenericToken jjtGetLastToken() {
return lastToken;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/

package net.sourceforge.pmd.lang.ast;

/**
* A {@link Node} that can provide access to the underlying
* {@linkplain GenericToken tokens} produced by the lexer.
*/
public interface TokenBasedNode<T extends GenericToken> {

/**
* Returns the first token producing this node.
* This is not a special token.
*/
T getFirstToken();


/**
* Returns the last token producing this node.
* This is not a special token.
*/
T getLastToken();


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/

package net.sourceforge.pmd.lang.java.ast.impl.javacc;

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.TokenBasedNode;

/**
* 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.
*/
public abstract class AbstractJjtreeNode<T extends GenericToken> extends AbstractNode implements TokenBasedNode<T> {

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 T getFirstToken() {
return (T) super.jjtGetFirstToken();
}

@Override
@SuppressWarnings("unchecked")
public T getLastToken() {
return (T) super.jjtGetLastToken();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.java.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<Token> implements JavaNode {

protected JavaParser parser;
private Scope scope;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@


import net.sourceforge.pmd.annotation.InternalApi;
import net.sourceforge.pmd.lang.ast.TokenBasedNode;
import net.sourceforge.pmd.lang.symboltable.Scope;
import net.sourceforge.pmd.lang.symboltable.ScopedNode;


/**
* Root interface for all Nodes of the Java AST.
*/
public interface JavaNode extends ScopedNode {
public interface JavaNode extends ScopedNode, TokenBasedNode<Token> {

/**
* Calls back the visitor's visit method corresponding to the runtime type of this Node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

package net.sourceforge.pmd.lang.jsp.ast;

import net.sourceforge.pmd.lang.ast.AbstractNode;
import net.sourceforge.pmd.lang.java.ast.impl.javacc.AbstractJjtreeNode;

public class AbstractJspNode extends AbstractNode implements JspNode {
public class AbstractJspNode extends AbstractJjtreeNode<Token> implements JspNode {

protected JspParser parser;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
package net.sourceforge.pmd.lang.jsp.ast;

import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.TokenBasedNode;

public interface JspNode extends Node {
public interface JspNode extends Node, TokenBasedNode<Token> {
/**
* Accept the visitor. *
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

package net.sourceforge.pmd.lang.plsql.ast;

import net.sourceforge.pmd.lang.java.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<Token> implements PLSQLNode {
protected Object value;
protected PLSQLParser parser;
protected Scope scope;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
package net.sourceforge.pmd.lang.plsql.ast;

import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.TokenBasedNode;
import net.sourceforge.pmd.lang.symboltable.Scope;
import net.sourceforge.pmd.lang.symboltable.ScopedNode;

public interface PLSQLNode extends Node, ScopedNode {
public interface PLSQLNode extends Node, ScopedNode, TokenBasedNode<Token> {

/** Accept the visitor. **/
Object jjtAccept(PLSQLParserVisitor visitor, Object data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

package net.sourceforge.pmd.lang.vf.ast;

import net.sourceforge.pmd.lang.ast.AbstractNode;
import net.sourceforge.pmd.lang.java.ast.impl.javacc.AbstractJjtreeNode;

public class AbstractVFNode extends AbstractNode implements VfNode {
public class AbstractVFNode extends AbstractJjtreeNode<Token> implements VfNode {

protected VfParser parser;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
package net.sourceforge.pmd.lang.vf.ast;

import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.TokenBasedNode;

public interface VfNode extends Node, TokenBasedNode<Token> {

public interface VfNode extends Node {
/**
* Accept the visitor. *
*/
Object jjtAccept(VfParserVisitor visitor, Object data);


/**
* Accept the visitor. *
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@

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.java.ast.impl.javacc.AbstractJjtreeNode;

/**
*
*/
public class AbstractVmNode extends AbstractNode implements VmNode {
public class AbstractVmNode extends AbstractJjtreeNode<Token> implements VmNode {

/** */
// TODO - It seems that this field is only valid when parsing, and should
Expand Down Expand Up @@ -93,17 +94,18 @@ public void jjtClose() {
endColumn = parser.token.endColumn;
}

/**
* @param t
*/
@InternalApi
@Deprecated
public void setFirstToken(final Token t) {
this.first = t;
}

@Override
public Token getFirstToken() {
return first;
}

@Override
public Token getLastToken() {
return last;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
package net.sourceforge.pmd.lang.vm.ast;

import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.TokenBasedNode;

public interface VmNode extends Node {
public interface VmNode extends Node, TokenBasedNode<Token> {
/**
* Accept the visitor. *
*/
Expand Down

0 comments on commit 98df6bd

Please sign in to comment.