/** * Returns true if this node declares a field. */ public boolean isField() { return getNthParent(2) instanceof ASTFieldDeclaration; }
/** * Returns true if this node declares a local variable. */ public boolean isLocalVariable() { return getNthParent(2) instanceof ASTLocalVariableDeclaration; }
private boolean isLocalVariableTypeInferred() { if (isResourceDeclaration()) { // covers "var" in try-with-resources return jjtGetParent().getFirstChildOfType(ASTType.class) == null; } else if (getNthParent(2) instanceof ASTLocalVariableDeclaration) { // covers "var" as local variables and in for statements return getNthParent(2).getFirstChildOfType(ASTType.class) == null; } return false; }
/** * Returns true if this node declares a formal parameter for * a lambda expression. In that case, the type of this parameter * is not necessarily inferred, see {@link #isTypeInferred()}. */ public boolean isLambdaParameter() { return isLambdaParamWithNoType() || jjtGetParent() instanceof ASTFormalParameter && getNthParent(3) instanceof ASTLambdaExpression; }
private boolean isLambdaTypeInferred() { return getNthParent(3) instanceof ASTLambdaExpression && jjtGetParent().getFirstChildOfType(ASTType.class) == null; }
@Override String kindDisplayName(ASTVariableDeclaratorId node, PropertyDescriptor<Pattern> descriptor) { ASTFieldDeclaration field = (ASTFieldDeclaration) node.getNthParent(2); if (field.isFinal() && field.isStatic()) { return field.isPublic() ? "public constant" : "constant"; } else if (field.isFinal()) { return "final field"; } else if (field.isStatic()) { return "static field"; } else { return "field"; } }
/** * Returns true if the variable declared by this node is declared final. * Doesn't account for the "effectively-final" nuance. Resource * declarations are implicitly final. */ public boolean isFinal() { if (isResourceDeclaration()) { // this is implicit even if "final" is not explicitly declared. return true; } else if (isLambdaParamWithNoType()) { return false; } if (jjtGetParent() instanceof ASTFormalParameter) { // This accounts for exception parameters too for now return ((ASTFormalParameter) jjtGetParent()).isFinal(); } Node grandpa = getNthParent(2); if (grandpa instanceof ASTLocalVariableDeclaration) { return ((ASTLocalVariableDeclaration) grandpa).isFinal(); } else if (grandpa instanceof ASTFieldDeclaration) { return ((ASTFieldDeclaration) grandpa).isFinal(); } throw new IllegalStateException("All cases should be handled"); }
/** * Returns true if this node declares a local variable. */ public boolean isLocalVariable() { return getNthParent(2) instanceof ASTLocalVariableDeclaration; }
/** * Returns true if this node declares a field. */ public boolean isField() { return getNthParent(2) instanceof ASTFieldDeclaration; }
/** * Returns true if this node declares a formal parameter for * a lambda expression. In that case, the type of this parameter * is not necessarily inferred, see {@link #isTypeInferred()}. */ public boolean isLambdaParameter() { return isLambdaParamWithNoType() || jjtGetParent() instanceof ASTFormalParameter && getNthParent(3) instanceof ASTLambdaExpression; }
private boolean isLocalVariableTypeInferred() { if (isResourceDeclaration()) { // covers "var" in try-with-resources return jjtGetParent().getFirstChildOfType(ASTType.class) == null; } else if (getNthParent(2) instanceof ASTLocalVariableDeclaration) { // covers "var" as local variables and in for statements return getNthParent(2).getFirstChildOfType(ASTType.class) == null; } return false; }
private boolean isLambdaTypeInferred() { return getNthParent(3) instanceof ASTLambdaExpression && jjtGetParent().getFirstChildOfType(ASTType.class) == null; }
@Override String kindDisplayName(ASTVariableDeclaratorId node, PropertyDescriptor<Pattern> descriptor) { ASTFieldDeclaration field = (ASTFieldDeclaration) node.getNthParent(2); if (field.isFinal() && field.isStatic()) { return field.isPublic() ? "public constant" : "constant"; } else if (field.isFinal()) { return "final field"; } else if (field.isStatic()) { return "static field"; } else { return "field"; } }
/** * Returns true if the variable declared by this node is declared final. * Doesn't account for the "effectively-final" nuance. Resource * declarations are implicitly final. */ public boolean isFinal() { if (isResourceDeclaration()) { // this is implicit even if "final" is not explicitly declared. return true; } else if (isLambdaParamWithNoType()) { return false; } if (jjtGetParent() instanceof ASTFormalParameter) { // This accounts for exception parameters too for now return ((ASTFormalParameter) jjtGetParent()).isFinal(); } Node grandpa = getNthParent(2); if (grandpa instanceof ASTLocalVariableDeclaration) { return ((ASTLocalVariableDeclaration) grandpa).isFinal(); } else if (grandpa instanceof ASTFieldDeclaration) { return ((ASTFieldDeclaration) grandpa).isFinal(); } throw new IllegalStateException("All cases should be handled"); }