Cleanup FormalParameter

This commit is contained in:
Clément Fournier
2019-07-20 13:13:45 +02:00
parent db1344d5aa
commit bba0367b10
3 changed files with 10 additions and 14 deletions

View File

@ -1794,7 +1794,7 @@ void FormalParameter() :
}
{
( "final" {jjtThis.setFinal(true);} | Annotation() )*
Type() ("|" Type())*
Type()
// TODO there may be annotations before the "..." of the varargs
// the ... is treated analogously to a pair of brackets
// the sensible way to parse it would probably be to push an ArrayType with ArrayTypeDim for the "..."
@ -2999,7 +2999,7 @@ void UnionType() #UnionType(isUnion):
// Annotations of the first class type belong to the
// catch parameter (the variable) because of syntactic ambiguity
// This is similar to how a local var type works.
ClassOrInterfaceType() ( "|" {isUnion=true; checkForBadMultipleExceptionsCatching();} AnnotatedClassOrInterfaceType() )*
ClassOrInterfaceType() ( "|" {isUnion=true;} AnnotatedClassOrInterfaceType() )*
}
void FinallyClause() :

View File

@ -11,16 +11,14 @@ import net.sourceforge.pmd.lang.java.typeresolution.typedefinition.JavaTypeDefin
/**
* Formal parameter node. Used in the {@link ASTFormalParameters}
* production of {@link ASTMethodDeclarator} to represent a
* method's formal parameter. Also used in the {@link ASTCatchClause}
* production to represent the declared exception variable.
* Also used in LambdaExpressions for the LambdaParameters.
* method's formal parameter.
*
* <pre class="grammar">
*
* FormalParameter ::= ( "final" | {@link ASTAnnotation Annotation} )* {@link ASTType Type} ( "|" {@link ASTType Type} )* [ "..." ] {@link ASTVariableDeclaratorId VariableDeclaratorId}
* FormalParameter ::= ( "final" | {@link ASTAnnotation Annotation} )* {@link ASTType Type} [ "..." ] {@link ASTVariableDeclaratorId VariableDeclaratorId}
* </pre>
*/
public class ASTFormalParameter extends AbstractJavaAccessTypeNode implements Dimensionable {
public class ASTFormalParameter extends AbstractJavaAccessTypeNode implements Dimensionable, Annotatable {
private boolean isVarargs;
@ -50,12 +48,12 @@ public class ASTFormalParameter extends AbstractJavaAccessTypeNode implements Di
/**
* If true, this formal parameter represents one without explit types.
* This can appear as part of a lambda expression with java11 using "var".
*
* @see ASTVariableDeclaratorId#isTypeInferred()
* @deprecated Returns false always, since lambda expressions use {@link ASTLambdaParameter}.
*/
@Deprecated
public boolean isTypeInferred() {
return getTypeNode() == null;
return false;
}
@Override

View File

@ -120,10 +120,8 @@ public class MethodNameDeclaration extends AbstractNameDeclaration {
int hash = declaration.getName().hashCode() * 31 + declaration.getArity();
for (ASTFormalParameter myParam : declaration.getFormalParameters()) {
if (!myParam.isTypeInferred()) {
String myTypeImg = myParam.getTypeNode().getTypeImage();
hash = hash * 31 + myTypeImg.hashCode();
}
String myTypeImg = myParam.getTypeNode().getTypeImage();
hash = hash * 31 + myTypeImg.hashCode();
}
return hash;