Simplify qualified this & super

This commit is contained in:
Clément Fournier
2019-05-25 02:05:42 +02:00
parent 066ec0f022
commit c18b3803d4
5 changed files with 15 additions and 49 deletions

View File

@@ -2509,11 +2509,17 @@ void PrimaryPrefix() #void :
)
| ("(" Expression() ")") #ParenthesizedExpression
// If it is an ambiguous name, then we may go on
// into the next step, which is less restricted
// than PrimarySuffix
| AmbiguousName() [ LOOKAHEAD(Step2Lahead()) PrimaryStep2() ]
}
// this describes the cases where the PrimaryPrefix may fall
// into PrimaryStep2
// This describes the cases where the PrimaryPrefix may fall
// into PrimaryStep2. Notice that type arguments is still possible,
// as well as annotations ("@")
// If we are in an explicit constructor invocation, then super or
// this is disallowed.
private void Step2Lahead() #void:
{}
{
@@ -2544,11 +2550,13 @@ void PrimaryStep2() #void:
| ArgumentList() #MethodCall(2)
| "." (
{forceTypeContext();} "class" #ClassLiteral(1)
| "this" #ThisExpression(1)
// qualified this or super
| {forceTypeContext();} "this" #ThisExpression(1)
| {forceTypeContext();} "super" #SuperExpression(1)
// here we force the super to be followed by something,
// "super" alone is not a valid expression
("." MemberSelector() | MethodReference())
| MemberSelector()
// we need to lookahead for the dot after "super", because in qualified
// super constructor invocation the "super" might be followed by a "("
| "super" #SuperExpression(1) ("." MemberSelector() | MethodReference())
)
| LOOKAHEAD("@" | "[" "]") {forceTypeContext();} Dims() #ArrayType(2) (MethodReference() | "." "class" #ClassLiteral(1))
| "[" Expression() "]" #ArrayAccess(2)

View File

@@ -66,10 +66,6 @@ public final class ASTClassOrInterfaceType extends AbstractJavaTypeNode implemen
* Gets the owner type of this type if it's not ambiguous. This is a
* type we know for sure that this type is a member of.
*
* TODO for now, all lhs are classified as ambiguous because they may be
* a package name. This must be taken care of by a disambiguation phase
* that takes the symbol table into account.
*
* @return A type, or null if this is a base type
*/
@Nullable

View File

@@ -16,7 +16,7 @@ import net.sourceforge.pmd.lang.ast.Node;
* <pre class="grammar">
*
* SuperExpression ::= "super"
* * | {@link ASTClassOrInterfaceType TypeName} "." "super"
* | {@link ASTClassOrInterfaceType TypeName} "." "super"
*
* </pre>
*/
@@ -30,27 +30,11 @@ public final class ASTSuperExpression extends AbstractJavaTypeNode implements AS
super(p, id);
}
@Override
public void jjtClose() {
super.jjtClose();
if (jjtGetNumChildren() > 0) {
// There's a qualifier
Node child = jjtGetChild(0);
if (child instanceof ASTAmbiguousName) {
this.replaceChildAt(0, ((ASTAmbiguousName) child).forceTypeContext());
}
}
}
@Nullable
public ASTClassOrInterfaceType getQualifier() {
return jjtGetNumChildren() > 0 ? (ASTClassOrInterfaceType) jjtGetChild(0) : null;
}
/**
* Accept the visitor. *
*/
@Override
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
return visitor.visit(this, data);

View File

@@ -30,28 +30,12 @@ public final class ASTThisExpression extends AbstractJavaTypeNode implements AST
super(p, id);
}
@Override
public void jjtClose() {
super.jjtClose();
if (jjtGetNumChildren() > 0) {
// There's a qualifier
Node child = jjtGetChild(0);
if (child instanceof ASTAmbiguousName) {
this.replaceChildAt(0, ((ASTAmbiguousName) child).forceTypeContext());
}
}
}
@Nullable
public ASTClassOrInterfaceType getQualifier() {
return jjtGetNumChildren() > 0 ? (ASTClassOrInterfaceType) jjtGetChild(0) : null;
}
/**
* Accept the visitor. *
*/
@Override
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
return visitor.visit(this, data);

View File

@@ -57,9 +57,6 @@ public abstract class AbstractJavaNode extends AbstractNode implements JavaNode
}
/**
* Accept the visitor. *
*/
@Override
public Object jjtAccept(JavaParserVisitor visitor, Object data) {
return visitor.visit(this, data);
@@ -72,9 +69,6 @@ public abstract class AbstractJavaNode extends AbstractNode implements JavaNode
}
/**
* Accept the visitor. *
*/
@Override
public Object childrenAccept(JavaParserVisitor visitor, Object data) {
for (Node child : children) {