Fix merge
This commit is contained in:
@ -94,6 +94,11 @@ public abstract class AbstractNode<B extends AbstractNode<B, N>, N extends Gener
|
||||
children = newChildren;
|
||||
}
|
||||
|
||||
setChild(child, index);
|
||||
}
|
||||
|
||||
protected void setChild(final B child, final int index) {
|
||||
assert index >= 0 && index < children.length : "Invalid index " + index + " for length " + children.length;
|
||||
children[index] = child;
|
||||
child.setChildIndex(index);
|
||||
child.setParent(asSelf(this));
|
||||
|
@ -356,7 +356,7 @@ class JavaParserImpl {
|
||||
token_source.setSuppressMarker(marker);
|
||||
}
|
||||
|
||||
private void setLastTokenImage(JavaNode node) {
|
||||
private void setLastTokenImage(AbstractJavaNode node) {
|
||||
node.setImage(getToken(0).getImage());
|
||||
}
|
||||
|
||||
@ -377,8 +377,8 @@ class JavaParserImpl {
|
||||
emptyMods.setDeclaredModifiers(Collections.emptySet());
|
||||
|
||||
JavaccToken tok = JavaccToken.implicitBefore(getToken(1));
|
||||
emptyMods.jjtSetFirstToken(tok);
|
||||
emptyMods.jjtSetLastToken(tok);
|
||||
emptyMods.setFirstToken(tok);
|
||||
emptyMods.setLastToken(tok);
|
||||
|
||||
jjtree.pushNode(emptyMods);
|
||||
}
|
||||
@ -400,8 +400,8 @@ class JavaParserImpl {
|
||||
private void injectTop() {
|
||||
AbstractJavaNode top = (AbstractJavaNode) jjtree.popNode();
|
||||
AbstractJavaNode prev = (AbstractJavaNode) jjtree.peekNode();
|
||||
prev.jjtAddChild(top, prev.getNumChildren());
|
||||
prev.jjtSetLastToken(top.jjtGetLastToken());
|
||||
prev.addChild(top, prev.getNumChildren());
|
||||
prev.setLastToken(top.getLastToken());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1753,8 +1753,8 @@ void PrimaryPrefix() #void :
|
||||
{
|
||||
AstImplUtil.bumpParenDepth((ASTExpression) jjtree.peekNode());
|
||||
AbstractJavaNode top = (AbstractJavaNode) jjtree.peekNode();
|
||||
top.jjtSetFirstToken(savedStart);
|
||||
top.jjtSetLastToken(getToken(0));
|
||||
top.setFirstToken(savedStart);
|
||||
top.setLastToken(getToken(0));
|
||||
}
|
||||
// If it is an ambiguous name, then we may go on
|
||||
// into the next step, which is less restricted
|
||||
@ -2078,7 +2078,7 @@ void BlockStatement() #void:
|
||||
LocalVariableDeclaration() ";" {
|
||||
// make it so that the LocalVariableDeclaration's last token is the semicolon
|
||||
AbstractJavaNode top = (AbstractJavaNode) jjtree.peekNode();
|
||||
top.jjtSetLastToken(getToken(0));
|
||||
top.setLastToken(getToken(0));
|
||||
} {}
|
||||
|
|
||||
// we need to lookahead until the "class" token,
|
||||
@ -2238,13 +2238,13 @@ void ForStatement() #void:
|
||||
t="for" "("
|
||||
(
|
||||
LOOKAHEAD(LocalVariableDeclaration() ":")
|
||||
(LocalVariableDeclaration() ":" Expression() ")" Statement() { jjtThis.jjtSetFirstToken(t); }) #ForeachStatement
|
||||
(LocalVariableDeclaration() ":" Expression() ")" Statement() { jjtThis.setFirstToken(t); }) #ForeachStatement
|
||||
| (
|
||||
[ ForInit() ] ";"
|
||||
[ Expression() ] ";"
|
||||
[ ForUpdate() ]
|
||||
")" Statement()
|
||||
{ jjtThis.jjtSetFirstToken(t); }
|
||||
{ jjtThis.setFirstToken(t); }
|
||||
) #ForStatement
|
||||
)
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public final class ASTBlock extends AbstractStatement implements Iterable<ASTSta
|
||||
|
||||
|
||||
public boolean containsComment() {
|
||||
JavaccToken t = jjtGetLastToken().getPreviousComment();
|
||||
JavaccToken t = getLastToken().getPreviousComment();
|
||||
while (t != null) {
|
||||
if (JavaTokenDocument.isComment(t)) {
|
||||
return true;
|
||||
|
@ -28,17 +28,17 @@ public final class ASTFieldAccess extends AbstractJavaExpr implements ASTAssigna
|
||||
*/
|
||||
ASTFieldAccess(ASTAmbiguousName lhs, String fieldName) {
|
||||
super(JavaParserImplTreeConstants.JJTFIELDACCESS);
|
||||
this.jjtAddChild(lhs, 0);
|
||||
this.addChild(lhs, 0);
|
||||
this.setImage(fieldName);
|
||||
}
|
||||
|
||||
ASTFieldAccess(ASTExpression lhs, JavaccToken identifier) {
|
||||
super(JavaParserImplTreeConstants.JJTFIELDACCESS);
|
||||
TokenUtils.expectKind(identifier, JavaTokenKinds.IDENTIFIER);
|
||||
this.jjtAddChild(lhs, 0);
|
||||
this.addChild((AbstractJavaNode) lhs, 0);
|
||||
this.setImage(identifier.getImage());
|
||||
this.jjtSetFirstToken(lhs.jjtGetFirstToken());
|
||||
this.jjtSetLastToken(identifier);
|
||||
this.setFirstToken(lhs.getFirstToken());
|
||||
this.setLastToken(identifier);
|
||||
}
|
||||
|
||||
|
||||
|
@ -6,7 +6,6 @@ package net.sourceforge.pmd.lang.java.ast;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.lang.java.ast.InternalInterfaces.VariableIdOwner;
|
||||
import net.sourceforge.pmd.lang.java.typeresolution.typedefinition.JavaTypeDefinition;
|
||||
|
||||
@ -44,7 +43,7 @@ public final class ASTFormalParameter extends AbstractJavaNode
|
||||
* Returns the list of formal parameters containing this param.
|
||||
*/
|
||||
public ASTFormalParameters getOwnerList() {
|
||||
return (ASTFormalParameters) jjtGetParent();
|
||||
return (ASTFormalParameters) getParent();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,10 +38,10 @@ public final class ASTMethodReference extends AbstractJavaExpr implements ASTPri
|
||||
// if constructor ref, then the LHS is unambiguously a type.
|
||||
if (lhs instanceof ASTAmbiguousName) {
|
||||
if (isConstructorReference()) {
|
||||
replaceChildAt(0, new ASTTypeExpression(((ASTAmbiguousName) lhs).forceTypeContext()));
|
||||
setChild(new ASTTypeExpression(((ASTAmbiguousName) lhs).forceTypeContext()), 0);
|
||||
}
|
||||
} else if (lhs instanceof ASTType) {
|
||||
replaceChildAt(0, new ASTTypeExpression((ASTType) lhs));
|
||||
setChild(new ASTTypeExpression((ASTType) lhs), 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,9 +18,10 @@ public class ASTName extends AbstractJavaTypeNode {
|
||||
*/
|
||||
@InternalApi
|
||||
@Deprecated
|
||||
public ASTName(String image) {
|
||||
public ASTName(String image, AbstractJavaNode parent) {
|
||||
super(JavaParserImplTreeConstants.JJTNAME);
|
||||
setImage(image);
|
||||
setParent(parent);
|
||||
}
|
||||
|
||||
ASTName(int id) {
|
||||
|
@ -30,7 +30,7 @@ public final class ASTPatternExpression extends AbstractJavaNode implements ASTP
|
||||
|
||||
ASTPatternExpression(ASTPattern wrapped) {
|
||||
this(JavaParserImplTreeConstants.JJTPATTERNEXPRESSION);
|
||||
this.jjtAddChild(wrapped, 0);
|
||||
this.addChild((AbstractJavaNode) wrapped, 0);
|
||||
copyTextCoordinates((AbstractJavaNode) wrapped);
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ public final class ASTTypeExpression extends AbstractJavaNode implements ASTPrim
|
||||
|
||||
ASTTypeExpression(ASTType wrapped) {
|
||||
this(JavaParserImplTreeConstants.JJTTYPEEXPRESSION);
|
||||
this.jjtAddChild(wrapped, 0);
|
||||
this.addChild((AbstractJavaNode) wrapped, 0);
|
||||
copyTextCoordinates((AbstractJavaNode) wrapped);
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ public final class ASTTypeParameter extends AbstractTypedSymbolDeclarator<JTypeP
|
||||
* Returns the node to which this type parameter belongs.
|
||||
*/
|
||||
public TypeParamOwnerNode getOwner() {
|
||||
return (TypeParamOwnerNode) jjtGetParent().jjtGetParent();
|
||||
return (TypeParamOwnerNode) getParent().getParent();
|
||||
}
|
||||
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.java.ast;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@ -54,9 +53,8 @@ public final class ASTUnionType extends AbstractJavaTypeNode
|
||||
/**
|
||||
* Returns the list of component types.
|
||||
*/
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public List<ASTClassOrInterfaceType> getComponents() {
|
||||
return (List<ASTClassOrInterfaceType>) (List) Arrays.asList(children);
|
||||
return children(ASTClassOrInterfaceType.class).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -33,8 +33,8 @@ public final class ASTVariableAccess extends AbstractJavaExpr implements ASTAssi
|
||||
TokenUtils.expectKind(identifier, JavaTokenKinds.IDENTIFIER);
|
||||
|
||||
setImage(identifier.getImage());
|
||||
jjtSetFirstToken(identifier);
|
||||
jjtSetLastToken(identifier);
|
||||
setFirstToken(identifier);
|
||||
setLastToken(identifier);
|
||||
}
|
||||
|
||||
|
||||
|
@ -248,8 +248,8 @@ public final class ASTVariableDeclaratorId extends AbstractTypedSymbolDeclarator
|
||||
*/
|
||||
@Nullable
|
||||
public ASTExpression getInitializer() {
|
||||
if (parent instanceof ASTVariableDeclarator) {
|
||||
return ((ASTVariableDeclarator) parent).getInitializer();
|
||||
if (getParent() instanceof ASTVariableDeclarator) {
|
||||
return ((ASTVariableDeclarator) getParent()).getInitializer();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -47,6 +47,22 @@ abstract class AbstractJavaNode extends AbstractJjtreeNode<AbstractJavaNode, Jav
|
||||
super.setImage(image);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void setFirstToken(JavaccToken token) {
|
||||
super.setFirstToken(token);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setLastToken(JavaccToken token) {
|
||||
super.setLastToken(token);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setChild(AbstractJavaNode child, int index) {
|
||||
super.setChild(child, index);
|
||||
}
|
||||
|
||||
void setSymbolTable(JSymbolTable table) {
|
||||
this.symbolTable = table;
|
||||
}
|
||||
@ -126,16 +142,6 @@ abstract class AbstractJavaNode extends AbstractJjtreeNode<AbstractJavaNode, Jav
|
||||
}
|
||||
|
||||
|
||||
// assumes that the child has the same text bounds
|
||||
// as the old one. Used to replace an ambiguous name
|
||||
// with an unambiguous representation
|
||||
void replaceChildAt(int idx, AbstractJavaNode newChild) {
|
||||
// parent of the old child must not be reset to null
|
||||
// as chances are we're reusing it as a child of the
|
||||
// new child
|
||||
super.addChild(newChild, idx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getXPathNodeName() {
|
||||
return JavaParserImplTreeConstants.jjtNodeName[id];
|
||||
|
@ -176,7 +176,7 @@ final class AstDisambiguationPass {
|
||||
}
|
||||
|
||||
if (resolved != name) { // NOPMD - intentional check for reference equality
|
||||
((AbstractJavaNode) name.getParent()).replaceChildAt(name.getIndexInParent(), resolved);
|
||||
((AbstractJavaNode) name.getParent()).setChild((AbstractJavaNode) resolved, name.getIndexInParent());
|
||||
}
|
||||
}
|
||||
|
||||
@ -327,7 +327,7 @@ final class AstDisambiguationPass {
|
||||
|
||||
TokenUtils.expectKind(identifier, JavaTokenKinds.IDENTIFIER);
|
||||
|
||||
final ASTClassOrInterfaceType type = new ASTClassOrInterfaceType(qualifier, image, ambig.jjtGetFirstToken(), identifier);
|
||||
final ASTClassOrInterfaceType type = new ASTClassOrInterfaceType(qualifier, image, ambig.getFirstToken(), identifier);
|
||||
type.setSymbol(sym);
|
||||
|
||||
if (!remaining.hasNext()) { // done
|
||||
|
@ -4,9 +4,6 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.java.ast;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
@ -21,7 +18,6 @@ import net.sourceforge.pmd.lang.java.symbols.JMethodSymbol;
|
||||
import net.sourceforge.pmd.lang.java.symbols.JTypeParameterSymbol;
|
||||
import net.sourceforge.pmd.lang.java.symbols.JVariableSymbol;
|
||||
import net.sourceforge.pmd.lang.java.symbols.table.JSymbolTable;
|
||||
import net.sourceforge.pmd.lang.java.symboltable.MethodNameDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.typeresolution.typedefinition.JavaTypeDefinition;
|
||||
import net.sourceforge.pmd.lang.symboltable.Scope;
|
||||
|
||||
@ -43,6 +39,14 @@ public final class InternalApiBridge {
|
||||
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static ASTVariableDeclaratorId newVarId(String image) {
|
||||
ASTVariableDeclaratorId varid = new ASTVariableDeclaratorId(JavaParserImplTreeConstants.JJTVARIABLEDECLARATORID);
|
||||
varid.setImage(image);
|
||||
return varid;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a fake method name declaration for built-in methods from Java
|
||||
* like the Enum Method "valueOf".
|
||||
@ -75,7 +79,7 @@ public final class InternalApiBridge {
|
||||
|
||||
PrimitiveType primitive = PrimitiveType.fromToken(parameterTypes[i]);
|
||||
// TODO : this could actually be a primitive array...
|
||||
ASTType type = primitive != null
|
||||
AbstractJavaNode type = primitive != null
|
||||
? new ASTPrimitiveType(primitive)
|
||||
: new ASTClassOrInterfaceType(parameterTypes[i]);
|
||||
|
||||
|
@ -113,6 +113,6 @@ final class TokenUtils {
|
||||
}
|
||||
|
||||
public static Iterator<JavaccToken> tokenRange(JavaNode node) {
|
||||
return GenericToken.range(node.jjtGetFirstToken(), node.jjtGetLastToken());
|
||||
return GenericToken.range(node.getFirstToken(), node.getLastToken());
|
||||
}
|
||||
}
|
||||
|
@ -65,6 +65,6 @@ abstract class AbstractAstTParamOwner<T extends TypeParamOwnerNode & AccessNode>
|
||||
return tparams.size();
|
||||
}
|
||||
ASTTypeParameters ps = node.getTypeParameters();
|
||||
return ps == null ? 0 : ps.jjtGetNumChildren();
|
||||
return ps == null ? 0 : ps.getNumChildren();
|
||||
}
|
||||
}
|
||||
|
@ -1181,8 +1181,7 @@ public class ClassTypeResolver extends JavaParserVisitorAdapter implements Nulla
|
||||
super.visit(node, data);
|
||||
// FIXME this is a hack because visit(ASTName) is too powerful,
|
||||
// Annotations don't have a Name node anymore so we imitate this
|
||||
ASTName name = new ASTName(node.getImage());
|
||||
name.setParent(node);
|
||||
ASTName name = new ASTName(node.getImage(), node);
|
||||
visit(name, data);
|
||||
if (name.getTypeDefinition() != null) {
|
||||
setTypeDefinition(node, name.getTypeDefinition());
|
||||
|
@ -6,6 +6,7 @@ import io.kotlintest.Result
|
||||
import io.kotlintest.matchers.collections.shouldBeEmpty
|
||||
import io.kotlintest.matchers.types.shouldBeInstanceOf
|
||||
import io.kotlintest.shouldNotBe
|
||||
import net.sourceforge.pmd.internal.util.IteratorUtil
|
||||
import net.sourceforge.pmd.lang.ast.GenericToken
|
||||
import net.sourceforge.pmd.lang.ast.Node
|
||||
import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken
|
||||
@ -42,16 +43,8 @@ fun haveVisibility(vis: AccessNode.Visibility): Matcher<AccessNode> = object : M
|
||||
Result(value.visibility == vis, "Expected $value to have visibility $vis", "Expected $value to not have visibility $vis")
|
||||
}
|
||||
|
||||
fun JavaNode.tokenList(): List<JavaccToken> {
|
||||
val lst = mutableListOf<JavaccToken>()
|
||||
var t = jjtGetFirstToken()
|
||||
lst += t
|
||||
while (t != jjtGetLastToken()) {
|
||||
t = t.next
|
||||
lst += t
|
||||
}
|
||||
return lst
|
||||
}
|
||||
fun JavaNode.tokenList(): List<JavaccToken> =
|
||||
IteratorUtil.toList(TokenUtils.tokenRange(this))
|
||||
|
||||
fun String.addArticle() = when (this[0].toLowerCase()) {
|
||||
'a', 'e', 'i', 'o', 'u' -> "an $this"
|
||||
|
@ -25,7 +25,7 @@ class TokenUtilsTest : FunSpec({
|
||||
ParserTestCtx(JavaVersion.J11)
|
||||
)
|
||||
|
||||
val fileTokens = generateSequence(decl.root.jjtGetFirstToken()) { it.next }.toList()
|
||||
val fileTokens = generateSequence(decl.root.firstToken) { it.next }.toList()
|
||||
|
||||
fileTokens.map { it.image } shouldBe listOf(
|
||||
// for some reason there's 2 EOF tokens but that's not the point of this test
|
||||
|
Reference in New Issue
Block a user