private boolean isAdditive(Node n) { ASTAdditiveExpression add = n.getFirstDescendantOfType(ASTAdditiveExpression.class); // if the first descendant additive expression is deeper than 4 levels, // it belongs to a nested method call and not anymore to the append // argument. return add != null && add.getNthParent(4) == n; }
private int processAdditive(Object data, int concurrentCount, Node sn, Node rootNode) { ASTAdditiveExpression additive = sn.getFirstDescendantOfType(ASTAdditiveExpression.class); if (additive == null || additive.getType() != null && !TypeHelper.isA(additive, String.class)) { return 0; List<ASTLiteral> literals = additive.findDescendantsOfType(ASTLiteral.class); boolean stringLiteralFound = false; for (ASTLiteral l : literals) { for (int ix = 0; ix < additive.jjtGetNumChildren(); ix++) { Node childNode = additive.jjtGetChild(ix); if (childNode.jjtGetNumChildren() != 1 || childNode.hasDescendantOfType(ASTName.class)) { if (!found) {
private boolean isAllocatedStringBuffer(ASTAdditiveExpression node) { ASTAllocationExpression ao = node.getFirstParentOfType(ASTAllocationExpression.class); if (ao == null) { return false; } // note that the child can be an ArrayDimsAndInits, for example, from // java.lang.FloatingDecimal: t = new int[ nWords+wordcount+1 ]; ASTClassOrInterfaceType an = ao.getFirstChildOfType(ASTClassOrInterfaceType.class); return an != null && TypeHelper.isEither(an, StringBuffer.class, StringBuilder.class); } }
private int processAdditive(Node sn) { ASTAdditiveExpression additive = sn.getFirstDescendantOfType(ASTAdditiveExpression.class); if (additive == null) { return 0; } int anticipatedLength = 0; for (int ix = 0; ix < additive.jjtGetNumChildren(); ix++) { Node childNode = additive.jjtGetChild(ix); ASTLiteral literal = childNode.getFirstDescendantOfType(ASTLiteral.class); if (literal != null && literal.getImage() != null) { anticipatedLength += literal.getImage().length() - 2; } } return anticipatedLength; }
final public void AdditiveExpression() throws ParseException { ASTAdditiveExpression jjtn000 = new ASTAdditiveExpression(this, JJTADDITIVEEXPRESSION); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { MultiplicativeExpression(); case PLUS: jj_consume_token(PLUS); jjtn000.setImage("+"); break; case MINUS: jj_consume_token(MINUS); jjtn000.setImage("-"); break; default: if (jjtc000) { jjtree.closeNodeScope(jjtn000, jjtree.nodeArity() > 1); jjtn000.jjtSetLastToken(getToken(0));
@Override public Object visit(ASTAdditiveExpression node, Object data) { ASTBlockStatement bs = node.getFirstParentOfType(ASTBlockStatement.class); if (bs == null) { return data; List<ASTLiteral> nodes = node.findDescendantsOfType(ASTLiteral.class); for (ASTLiteral literal : nodes) { if (literal.getNthParent(3) instanceof ASTAdditiveExpression) { List<ASTName> nameNodes = node.findDescendantsOfType(ASTName.class); for (ASTName name : nameNodes) { if (name.getNameDeclaration() != null && name.getNameDeclaration() instanceof VariableNameDeclaration) {
/** * Returns the image of the operator, i.e. "+" or "-". */ public String getOperator() { return getImage(); } }
/** * Checks to see if there is string concatenation in the node. * * This method checks if it's additive with respect to the append method * only. * * @param n * Node to check * @return true if the node has an additive expression (i.e. "Hello " + * Const.WORLD) */ private boolean isAdditive(Node n) { List<ASTAdditiveExpression> lstAdditive = n.findDescendantsOfType(ASTAdditiveExpression.class); if (lstAdditive.isEmpty()) { return false; } // if there are more than 1 set of arguments above us we're not in the // append // but a sub-method call for (int ix = 0; ix < lstAdditive.size(); ix++) { ASTAdditiveExpression expr = lstAdditive.get(ix); if (expr.getParentsOfType(ASTArgumentList.class).size() != 1) { return false; } } return true; }
final public void AdditiveExpression() throws ParseException { ASTAdditiveExpression jjtn000 = new ASTAdditiveExpression(this, JJTADDITIVEEXPRESSION); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { MultiplicativeExpression(); case PLUS: jj_consume_token(PLUS); jjtn000.setImage("+"); break; case MINUS: jj_consume_token(MINUS); jjtn000.setImage("-"); break; default: if (jjtc000) { jjtree.closeNodeScope(jjtn000, jjtree.nodeArity() > 1); jjtn000.jjtSetLastToken(getToken(0));
private int processAdditive(Node sn) { ASTAdditiveExpression additive = sn.getFirstDescendantOfType(ASTAdditiveExpression.class); if (additive == null) { return 0; } int anticipatedLength = 0; for (int ix = 0; ix < additive.jjtGetNumChildren(); ix++) { Node childNode = additive.jjtGetChild(ix); ASTLiteral literal = childNode.getFirstDescendantOfType(ASTLiteral.class); if (literal != null && literal.getImage() != null) { anticipatedLength += literal.getImage().length() - 2; } } return anticipatedLength; }
@Override public Object visit(ASTAdditiveExpression node, Object data) { ASTBlockStatement bs = node.getFirstParentOfType(ASTBlockStatement.class); if (bs == null) { return data; List<ASTLiteral> nodes = node.findDescendantsOfType(ASTLiteral.class); for (ASTLiteral literal : nodes) { if (literal.getNthParent(3) instanceof ASTAdditiveExpression) { List<ASTName> nameNodes = node.findDescendantsOfType(ASTName.class); for (ASTName name : nameNodes) { if (name.getNameDeclaration() != null && name.getNameDeclaration() instanceof VariableNameDeclaration) {
/** * Returns the image of the operator, i.e. "+" or "-". */ public String getOperator() { return getImage(); } }
/** * Checks to see if there is string concatenation in the node. * * This method checks if it's additive with respect to the append method * only. * * @param n * Node to check * @return true if the node has an additive expression (i.e. "Hello " + * Const.WORLD) */ private boolean isAdditive(Node n) { List<ASTAdditiveExpression> lstAdditive = n.findDescendantsOfType(ASTAdditiveExpression.class); if (lstAdditive.isEmpty()) { return false; } // if there are more than 1 set of arguments above us we're not in the // append // but a sub-method call for (int ix = 0; ix < lstAdditive.size(); ix++) { ASTAdditiveExpression expr = lstAdditive.get(ix); if (expr.getParentsOfType(ASTArgumentList.class).size() != 1) { return false; } } return true; }
private int processAdditive(Object data, int concurrentCount, Node sn, Node rootNode) { ASTAdditiveExpression additive = sn.getFirstDescendantOfType(ASTAdditiveExpression.class); if (additive == null || additive.getType() != null && !TypeHelper.isA(additive, String.class)) { return 0; List<ASTLiteral> literals = additive.findDescendantsOfType(ASTLiteral.class); boolean stringLiteralFound = false; for (ASTLiteral l : literals) { for (int ix = 0; ix < additive.jjtGetNumChildren(); ix++) { Node childNode = additive.jjtGetChild(ix); if (childNode.jjtGetNumChildren() != 1 || childNode.hasDescendantOfType(ASTName.class)) { if (!found) {
private boolean isAdditive(Node n) { ASTAdditiveExpression add = n.getFirstDescendantOfType(ASTAdditiveExpression.class); // if the first descendant additive expression is deeper than 4 levels, // it belongs to a nested method call and not anymore to the append // argument. return add != null && add.getNthParent(4) == n; }
private boolean isAllocatedStringBuffer(ASTAdditiveExpression node) { ASTAllocationExpression ao = node.getFirstParentOfType(ASTAllocationExpression.class); if (ao == null) { return false; } // note that the child can be an ArrayDimsAndInits, for example, from // java.lang.FloatingDecimal: t = new int[ nWords+wordcount+1 ]; ASTClassOrInterfaceType an = ao.getFirstChildOfType(ASTClassOrInterfaceType.class); return an != null && TypeHelper.isEither(an, StringBuffer.class, StringBuilder.class); } }
for (Node additiveNode : additiveNodes) { ASTAdditiveExpression additiveExpression = (ASTAdditiveExpression)additiveNode; Node assignmentStatement = additiveExpression.getNthParent(2); if (!(assignmentStatement instanceof ASTStatementExpression)) { continue;