/** * Extracts the variable name by traversing PrimaryExpression -> PrimaryPrefix -> Name. * Also check if there is a PrimaryExpression -> PrimarySuffix which indicates a field or array access. * * @returns the Name or null if the PrimaryPrefix is "this" or "super" */ private ASTName singleVariableName(ASTPrimaryExpression primaryExpression) { final ASTPrimaryPrefix primaryPrefix = primaryExpression.getFirstChildOfType(ASTPrimaryPrefix.class); final ASTPrimarySuffix primarySuffix = primaryExpression.getFirstChildOfType(ASTPrimarySuffix.class); if (primarySuffix != null || primaryPrefix == null) { return null; } return primaryPrefix.getFirstChildOfType(ASTName.class); }
private ASTClassOrInterfaceType getTypeOfMethodCall(ASTPrimarySuffix node) { ASTClassOrInterfaceType type = null; ASTName methodName = node.jjtGetParent().getFirstChildOfType(ASTPrimaryPrefix.class) .getFirstChildOfType(ASTName.class); if (methodName != null) { ClassScope classScope = node.getScope().getEnclosingScope(ClassScope.class); Map<MethodNameDeclaration, List<NameOccurrence>> methods = classScope.getMethodDeclarations(); for (Map.Entry<MethodNameDeclaration, List<NameOccurrence>> e : methods.entrySet()) { if (e.getKey().getName().equals(methodName.getImage())) { type = e.getKey().getNode().getFirstParentOfType(ASTMethodDeclaration.class) .getFirstChildOfType(ASTResultType.class) .getFirstDescendantOfType(ASTClassOrInterfaceType.class); break; } } } return type; }
final String method = parentNode.getFirstChildOfType(ASTPrimaryPrefix.class).getFirstChildOfType(ASTName.class) .getImage().replace(nameDeclaration.getImage() + ".", "");
public void check(Object ctx, ASTArguments node) { if (node.getArgumentCount() == argumentsCount && node.getNthParent(2) instanceof ASTPrimaryExpression) { ASTPrimaryPrefix primaryPrefix = node.getNthParent(2).getFirstChildOfType(ASTPrimaryPrefix.class); if (primaryPrefix != null) { ASTName name = primaryPrefix.getFirstChildOfType(ASTName.class); if (name != null && name.hasImageEqualTo(this.assertionName)) { if (isException(node)) { return; } JUnitAssertionsShouldIncludeMessageRule.this.addViolation(ctx, name); } } } }
public boolean isStandAlonePrimitive() { if (jjtGetNumChildren() != 1) { return false; } ASTPrimaryExpression primaryExpression = getFirstChildOfType(ASTPrimaryExpression.class); if (primaryExpression == null || primaryExpression.jjtGetNumChildren() != 1) { return false; } ASTPrimaryPrefix primaryPrefix = primaryExpression.getFirstChildOfType(ASTPrimaryPrefix.class); if (primaryPrefix == null || primaryPrefix.jjtGetNumChildren() != 1) { return false; } ASTLiteral literal = primaryPrefix.getFirstChildOfType(ASTLiteral.class); // if it is not a string literal and not a null, then it is one of // byte, short, char, int, long, float, double, boolean return literal != null && !literal.isStringLiteral() && (literal.jjtGetNumChildren() == 0 || !(literal.jjtGetChild(0) instanceof ASTNullLiteral)); } }
.getFirstDescendantOfType(ASTPrimaryPrefix.class); if (primaryPrefix != null) { ASTName prefixName = primaryPrefix.getFirstChildOfType(ASTName.class); if (prefixName != null && prefixName.hasImageEqualTo(baseName)) {
if (prefix != null && suffix != null) { if (prefix.getImage() == null) { ASTName prefixName = prefix.getFirstChildOfType(ASTName.class); if (prefixName != null && closeTargets.contains(prefixName.getImage())) {
ASTPrimaryPrefix primaryPrefix = stmtExp.getFirstDescendantOfType(ASTPrimaryPrefix.class); if (primaryPrefix != null) { ASTName name = primaryPrefix.getFirstChildOfType(ASTName.class); if (name != null) { String image = name.getImage();
/** * Extracts the variable name by traversing PrimaryExpression -> PrimaryPrefix -> Name. * Also check if there is a PrimaryExpression -> PrimarySuffix which indicates a field or array access. * * @returns the Name or null if the PrimaryPrefix is "this" or "super" */ private ASTName singleVariableName(ASTPrimaryExpression primaryExpression) { final ASTPrimaryPrefix primaryPrefix = primaryExpression.getFirstChildOfType(ASTPrimaryPrefix.class); final ASTPrimarySuffix primarySuffix = primaryExpression.getFirstChildOfType(ASTPrimarySuffix.class); if (primarySuffix != null || primaryPrefix == null) { return null; } return primaryPrefix.getFirstChildOfType(ASTName.class); }
private void checkMathRandom(List<ASTMethodDeclaration> methodDeclarations, Object data) { for (ASTMethodDeclaration methodDeclaration : methodDeclarations) { List<ASTPrimaryPrefix> primaryPrefixes = methodDeclaration.findDescendantsOfType(ASTPrimaryPrefix.class); if (primaryPrefixes == null || primaryPrefixes.isEmpty()) { continue; } for (ASTPrimaryPrefix primaryPrefix : primaryPrefixes) { if (primaryPrefix.getType() != Math.class) { continue; } ASTName name = primaryPrefix.getFirstChildOfType(ASTName.class); if (name == null || name.getImage() == null || !name.getImage().endsWith(MATH_RANDOM_METHOD)) { continue; } addViolationWithMessage(data, primaryPrefix, MESSAGE_KEY_PREFIX + ".violation.msg.math.random"); } } }
private ASTClassOrInterfaceType getTypeOfMethodCall(ASTPrimarySuffix node) { ASTClassOrInterfaceType type = null; ASTName methodName = node.jjtGetParent().getFirstChildOfType(ASTPrimaryPrefix.class) .getFirstChildOfType(ASTName.class); if (methodName != null) { ClassScope classScope = node.getScope().getEnclosingScope(ClassScope.class); Map<MethodNameDeclaration, List<NameOccurrence>> methods = classScope.getMethodDeclarations(); for (Map.Entry<MethodNameDeclaration, List<NameOccurrence>> e : methods.entrySet()) { if (e.getKey().getName().equals(methodName.getImage())) { type = e.getKey().getNode().getFirstParentOfType(ASTMethodDeclaration.class) .getFirstChildOfType(ASTResultType.class) .getFirstDescendantOfType(ASTClassOrInterfaceType.class); break; } } } return type; }
final ASTName method = node.jjtGetParent() .getFirstChildOfType(ASTPrimaryPrefix.class) .getFirstChildOfType(ASTName.class); if (method != null) { final ClassScope scope = node.getScope()
final ASTName method = node.jjtGetParent() .getFirstChildOfType(ASTPrimaryPrefix.class) .getFirstChildOfType(ASTName.class); if (method != null) { final ClassScope scope = node.getScope()
final String method = parentNode.getFirstChildOfType(ASTPrimaryPrefix.class).getFirstChildOfType(ASTName.class) .getImage().replace(nameDeclaration.getImage() + ".", "");
if (right.getFirstChildOfType(ASTLiteral.class) != null) { ASTLiteral literal = right.getFirstChildOfType(ASTLiteral.class); if (literal.isStringLiteral()) { ASTName name = right.getFirstChildOfType(ASTName.class);
public void check(Object ctx, ASTArguments node) { if (node.getArgumentCount() == argumentsCount && node.getNthParent(2) instanceof ASTPrimaryExpression) { ASTPrimaryPrefix primaryPrefix = node.getNthParent(2).getFirstChildOfType(ASTPrimaryPrefix.class); if (primaryPrefix != null) { ASTName name = primaryPrefix.getFirstChildOfType(ASTName.class); if (name != null && name.hasImageEqualTo(this.assertionName)) { if (isException(node)) { return; } JUnitAssertionsShouldIncludeMessageRule.this.addViolation(ctx, name); } } } }
public boolean isStandAlonePrimitive() { if (jjtGetNumChildren() != 1) { return false; } ASTPrimaryExpression primaryExpression = getFirstChildOfType(ASTPrimaryExpression.class); if (primaryExpression == null || primaryExpression.jjtGetNumChildren() != 1) { return false; } ASTPrimaryPrefix primaryPrefix = primaryExpression.getFirstChildOfType(ASTPrimaryPrefix.class); if (primaryPrefix == null || primaryPrefix.jjtGetNumChildren() != 1) { return false; } ASTLiteral literal = primaryPrefix.getFirstChildOfType(ASTLiteral.class); // if it is not a string literal and not a null, then it is one of // byte, short, char, int, long, float, double, boolean return literal != null && !literal.isStringLiteral() && (literal.jjtGetNumChildren() == 0 || !(literal.jjtGetChild(0) instanceof ASTNullLiteral)); } }
.getFirstDescendantOfType(ASTPrimaryPrefix.class); if (primaryPrefix != null) { ASTName prefixName = primaryPrefix.getFirstChildOfType(ASTName.class); if (prefixName != null && prefixName.hasImageEqualTo(baseName)) {
if (prefix != null && suffix != null) { if (prefix.getImage() == null) { ASTName prefixName = prefix.getFirstChildOfType(ASTName.class); if (prefixName != null && closeTargets.contains(prefixName.getImage())) {
ASTPrimaryPrefix primaryPrefix = stmtExp.getFirstDescendantOfType(ASTPrimaryPrefix.class); if (primaryPrefix != null) { ASTName name = primaryPrefix.getFirstChildOfType(ASTName.class); if (name != null) { String image = name.getImage();