.getFirstDescendantOfType(ASTArgumentList.class).findChildrenOfType(ASTExpression.class);
/** * Determines the log level, that is used. It is either the called method name * itself or - in case java util logging is used, then it is the first argument of * the method call (if it exists). * * @param node the method call * @param methodCallName the called method name previously determined * @return the log level or <code>null</code> if it could not be determined */ private String getLogLevelName(Node node, String methodCallName) { if (!JAVA_UTIL_LOG_METHOD.equals(methodCallName) && !JAVA_UTIL_LOG_GUARD_METHOD.equals(methodCallName)) { return methodCallName; } String logLevel = null; ASTPrimarySuffix suffix = node.getFirstDescendantOfType(ASTPrimarySuffix.class); if (suffix != null) { ASTArgumentList argumentList = suffix.getFirstDescendantOfType(ASTArgumentList.class); if (argumentList != null && argumentList.jjtGetNumChildren() > 0) { // at least one argument - the log level. If the method call is "log", then a message might follow ASTName name = GuardLogStatementRule.<ASTName>getFirstChild(argumentList.jjtGetChild(0), ASTPrimaryExpression.class, ASTPrimaryPrefix.class, ASTName.class); String lastPart = getLastPartOfName(name); lastPart = lastPart.toLowerCase(Locale.ROOT); if (!lastPart.isEmpty()) { logLevel = lastPart; } } } return logLevel; }
final public void ArgumentList() throws ParseException { ASTArgumentList jjtn000 = new ASTArgumentList(this, JJTARGUMENTLIST); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { Expression(); if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0));
public static List<Constraint> produceInitialConstraints(Method method, ASTArgumentList argList, List<Variable> variables) { List<Constraint> result = new ArrayList<>(); Type[] methodParameters = method.getGenericParameterTypes(); TypeVariable<Method>[] methodTypeParameters = method.getTypeParameters(); // TODO: add support for variable arity methods for (int i = 0; i < methodParameters.length; i++) { int typeParamIndex = -1; if (methodParameters[i] instanceof TypeVariable) { typeParamIndex = JavaTypeDefinition .getGenericTypeIndex(methodTypeParameters, ((TypeVariable<?>) methodParameters[i]).getName()); } if (typeParamIndex != -1) { // TODO: we are cheating here, it should be a contraint of the form 'var -> expression' not 'var->type' result.add(new Constraint(((TypeNode) argList.jjtGetChild(i)).getTypeDefinition(), variables.get(typeParamIndex), LOOSE_INVOCATION)); } } return result; }
private int getArgumentListArity(ASTArgumentList argList) { if (argList != null) { return argList.jjtGetNumChildren(); } return 0; }
/** * Determine if the constructor contains (or ends with) a String Literal * * @param node * @return 1 if the constructor contains string argument, else 0 */ private int checkConstructor(ASTVariableDeclaratorId node, Object data) { Node parent = node.jjtGetParent(); if (parent.jjtGetNumChildren() >= 2) { ASTAllocationExpression allocationExpression = parent.jjtGetChild(1) .getFirstDescendantOfType(ASTAllocationExpression.class); ASTArgumentList list = null; if (allocationExpression != null) { list = allocationExpression.getFirstDescendantOfType(ASTArgumentList.class); } if (list != null) { ASTLiteral literal = list.getFirstDescendantOfType(ASTLiteral.class); if (!isAdditive(list) && literal != null && literal.isStringLiteral()) { return 1; } return processAdditive(data, 0, list, node); } } return 0; }
private boolean isEqualsViolation(Node parent) { // 3. child: equals if (parent.jjtGetChild(2).hasImageEqualTo("equals")) { // 4. child: the arguments of equals, there must be exactly one and // it must be "" List<ASTArgumentList> argList = parent.jjtGetChild(3).findDescendantsOfType(ASTArgumentList.class); if (argList.size() == 1) { List<ASTLiteral> literals = argList.get(0).findDescendantsOfType(ASTLiteral.class); return literals.size() == 1 && literals.get(0).hasImageEqualTo("\"\""); } } return false; }
if (argList != null && argList.getFirstParentOfType(ASTStatementExpression.class) == statement) {
Node parent = args.jjtGetParent().jjtGetParent(); if (parent instanceof ASTAllocationExpression) {
@Override public Object visit(ASTAllocationExpression node, Object data) { ASTClassOrInterfaceType declClassName = node.getFirstChildOfType(ASTClassOrInterfaceType.class); if (declClassName != null && TypeHelper.isA(declClassName, javax.crypto.spec.IvParameterSpec.class)) { Node firstArgument = null; ASTArguments arguments = node.getFirstChildOfType(ASTArguments.class); if (arguments.getArgumentCount() > 0) { firstArgument = arguments.getFirstChildOfType(ASTArgumentList.class).jjtGetChild(0); } if (firstArgument != null) { ASTPrimaryPrefix prefix = firstArgument.getFirstDescendantOfType(ASTPrimaryPrefix.class); validateProperIv(data, prefix); } } return data; }
protected static boolean isInStringBufferOperation(Node node, int length, String methodName) { if (!(node.getNthParent(length) instanceof ASTStatementExpression)) { return false; } ASTStatementExpression s = node.getFirstParentOfType(ASTStatementExpression.class); if (s == null) { return false; } ASTName n = s.getFirstDescendantOfType(ASTName.class); if (n == null || n.getImage().indexOf(methodName) == -1 || !(n.getNameDeclaration() instanceof TypedNameDeclaration)) { return false; } // TODO having to hand-code this kind of dredging around is ridiculous // we need something to support this in the framework // but, "for now" (tm): // if more than one arg to append(), skip it ASTArgumentList argList = s.getFirstDescendantOfType(ASTArgumentList.class); if (argList == null || argList.jjtGetNumChildren() > 1) { return false; } return TypeHelper.isExactlyAny((TypedNameDeclaration) n.getNameDeclaration(), StringBuffer.class, StringBuilder.class); }
ASTName arg = args.getFirstDescendantOfType(ASTName.class); if (arg != null) { NameDeclaration declaration = arg.getNameDeclaration();
private boolean isEqualsViolation(Node parent) { // 3. child: equals if (parent.jjtGetChild(2).hasImageEqualTo("equals")) { // 4. child: the arguments of equals, there must be exactly one and // it must be "" List<ASTArgumentList> argList = parent.jjtGetChild(3).findDescendantsOfType(ASTArgumentList.class); if (argList.size() == 1) { List<ASTLiteral> literals = argList.get(0).findDescendantsOfType(ASTLiteral.class); return literals.size() == 1 && literals.get(0).hasImageEqualTo("\"\""); } } return false; }
if (argList != null && argList.getFirstParentOfType(ASTStatementExpression.class) == statement) {
Node parent = args.jjtGetParent().jjtGetParent(); if (parent instanceof ASTAllocationExpression) {
final int argCount = argList == null ? 0 : argList.jjtGetNumChildren(); (ASTExpression) argList.jjtGetChild(argIndex))) { methodIsApplicable = false; break;
@Override public Object visit(ASTAllocationExpression node, Object data) { ASTClassOrInterfaceType declClassName = node.getFirstChildOfType(ASTClassOrInterfaceType.class); if (declClassName != null && TypeHelper.isA(declClassName, SECRET_KEY_SPEC)) { Node firstArgument = null; ASTArguments arguments = node.getFirstChildOfType(ASTArguments.class); if (arguments.getArgumentCount() > 0) { firstArgument = arguments.getFirstChildOfType(ASTArgumentList.class).jjtGetChild(0); } if (firstArgument != null) { ASTPrimaryPrefix prefix = firstArgument.getFirstDescendantOfType(ASTPrimaryPrefix.class); validateProperKeyArgument(data, prefix); } } return data; }
final public void ArgumentList() throws ParseException { ASTArgumentList jjtn000 = new ASTArgumentList(this, JJTARGUMENTLIST); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { Expression(); if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0));
private int getArgumentListArity(ASTArgumentList argList) { if (argList != null) { return argList.jjtGetNumChildren(); } return 0; }
@Override public Object visit(final ASTArgumentList rtn, final Object data) { final List<ASTVariableDeclarator> names = rtn.findChildrenOfType(ASTVariableDeclarator.class); for (final ASTVariableDeclarator name : names) { this.usages(rtn, data, name); } return data; }