private List<NameOccurrence> determineUsages(ASTVariableDeclaratorId node) { Map<VariableNameDeclaration, List<NameOccurrence>> decls = node.getScope() .getDeclarations(VariableNameDeclaration.class); for (Map.Entry<VariableNameDeclaration, List<NameOccurrence>> entry : decls.entrySet()) { // find the first variable that matches if (node.hasImageEqualTo(entry.getKey().getName())) { return entry.getValue(); } } return Collections.emptyList(); }
/** * Tells if the type declaration has a field with varName. * * @param varName * the name of the field to search * @param typeDeclaration * the type declaration * @return <code>true</code> if there is a field in the type declaration * named varName, <code>false</code> in other case */ protected final boolean isField(String varName, ASTTypeDeclaration typeDeclaration) { final List<ASTFieldDeclaration> fds = typeDeclaration.findDescendantsOfType(ASTFieldDeclaration.class); if (fds != null) { for (ASTFieldDeclaration fd : fds) { final ASTVariableDeclaratorId vid = fd.getFirstDescendantOfType(ASTVariableDeclaratorId.class); if (vid != null && vid.hasImageEqualTo(varName)) { return true; } } } return false; }
/** * TODO modify usages to use symbol table Tells if the variable name is a * local variable declared in the method. * * @param vn * the variable name * @param node * the ASTMethodDeclaration where the local variable name will be * searched * @return <code>true</code> if the method declaration contains any local * variable named vn and <code>false</code> in other case */ protected boolean isLocalVariable(String vn, Node node) { final List<ASTLocalVariableDeclaration> lvars = node.findDescendantsOfType(ASTLocalVariableDeclaration.class); if (lvars != null) { for (ASTLocalVariableDeclaration lvd : lvars) { final ASTVariableDeclaratorId vid = lvd.getFirstDescendantOfType(ASTVariableDeclaratorId.class); if (vid != null && vid.hasImageEqualTo(vn)) { return true; } } } return false; }
private boolean isEmptyArray(String varName, ASTTypeDeclaration typeDeclaration) { final List<ASTFieldDeclaration> fds = typeDeclaration.findDescendantsOfType(ASTFieldDeclaration.class); if (fds != null) { for (ASTFieldDeclaration fd : fds) { final ASTVariableDeclaratorId vid = fd.getFirstDescendantOfType(ASTVariableDeclaratorId.class); if (vid != null && vid.hasImageEqualTo(varName)) { ASTVariableInitializer initializer = fd.getFirstDescendantOfType(ASTVariableInitializer.class); if (initializer != null && initializer.jjtGetNumChildren() == 1) { Node child = initializer.jjtGetChild(0); if (child instanceof ASTArrayInitializer && child.jjtGetNumChildren() == 0) { return true; } else if (child instanceof ASTExpression) { try { List<? extends Node> arrayAllocation = child.findChildNodesWithXPath( "./PrimaryExpression/PrimaryPrefix/AllocationExpression/ArrayDimsAndInits/Expression/PrimaryExpression/PrimaryPrefix/Literal[@IntLiteral=\"true\"][@Image=\"0\"]"); if (arrayAllocation != null && arrayAllocation.size() == 1) { return true; } } catch (JaxenException e) { return false; } } } } } } return false; } }
.getFirstChildOfType(ASTVariableDeclaratorId.class); if (variableDeclaratorId.hasImageEqualTo(baseName)) { boolean allocationFound = declarator .getFirstDescendantOfType(ASTAllocationExpression.class) != null;
for (ASTLocalVariableDeclaration l : locals) { ASTVariableDeclaratorId id = l.getFirstDescendantOfType(ASTVariableDeclaratorId.class); if (id != null && id.hasImageEqualTo(returnVariableName)) { initializer = l.getFirstDescendantOfType(ASTVariableInitializer.class); break;
private List<NameOccurrence> determineUsages(ASTVariableDeclaratorId node) { Map<VariableNameDeclaration, List<NameOccurrence>> decls = node.getScope() .getDeclarations(VariableNameDeclaration.class); for (Map.Entry<VariableNameDeclaration, List<NameOccurrence>> entry : decls.entrySet()) { // find the first variable that matches if (node.hasImageEqualTo(entry.getKey().getName())) { return entry.getValue(); } } return Collections.emptyList(); }
/** * TODO modify usages to use symbol table Tells if the variable name is a * local variable declared in the method. * * @param vn * the variable name * @param node * the ASTMethodDeclaration where the local variable name will be * searched * @return <code>true</code> if the method declaration contains any local * variable named vn and <code>false</code> in other case */ protected boolean isLocalVariable(String vn, Node node) { final List<ASTLocalVariableDeclaration> lvars = node.findDescendantsOfType(ASTLocalVariableDeclaration.class); if (lvars != null) { for (ASTLocalVariableDeclaration lvd : lvars) { final ASTVariableDeclaratorId vid = lvd.getFirstDescendantOfType(ASTVariableDeclaratorId.class); if (vid != null && vid.hasImageEqualTo(vn)) { return true; } } } return false; }
/** * Tells if the type declaration has a field with varName. * * @param varName * the name of the field to search * @param typeDeclaration * the type declaration * @return <code>true</code> if there is a field in the type declaration * named varName, <code>false</code> in other case */ protected final boolean isField(String varName, ASTTypeDeclaration typeDeclaration) { final List<ASTFieldDeclaration> fds = typeDeclaration.findDescendantsOfType(ASTFieldDeclaration.class); if (fds != null) { for (ASTFieldDeclaration fd : fds) { final ASTVariableDeclaratorId vid = fd.getFirstDescendantOfType(ASTVariableDeclaratorId.class); if (vid != null && vid.hasImageEqualTo(varName)) { return true; } } } return false; }
private boolean isEmptyArray(String varName, ASTTypeDeclaration typeDeclaration) { final List<ASTFieldDeclaration> fds = typeDeclaration.findDescendantsOfType(ASTFieldDeclaration.class); if (fds != null) { for (ASTFieldDeclaration fd : fds) { final ASTVariableDeclaratorId vid = fd.getFirstDescendantOfType(ASTVariableDeclaratorId.class); if (vid != null && vid.hasImageEqualTo(varName)) { ASTVariableInitializer initializer = fd.getFirstDescendantOfType(ASTVariableInitializer.class); if (initializer != null && initializer.jjtGetNumChildren() == 1) { Node child = initializer.jjtGetChild(0); if (child instanceof ASTArrayInitializer && child.jjtGetNumChildren() == 0) { return true; } else if (child instanceof ASTExpression) { try { List<? extends Node> arrayAllocation = child.findChildNodesWithXPath( "./PrimaryExpression/PrimaryPrefix/AllocationExpression/ArrayDimsAndInits/Expression/PrimaryExpression/PrimaryPrefix/Literal[@IntLiteral=\"true\"][@Image=\"0\"]"); if (arrayAllocation != null && arrayAllocation.size() == 1) { return true; } } catch (JaxenException e) { return false; } } } } } } return false; } }
.getFirstChildOfType(ASTVariableDeclaratorId.class); if (variableDeclaratorId.hasImageEqualTo(baseName)) { boolean allocationFound = declarator .getFirstDescendantOfType(ASTAllocationExpression.class) != null;
for (ASTLocalVariableDeclaration l : locals) { ASTVariableDeclaratorId id = l.getFirstDescendantOfType(ASTVariableDeclaratorId.class); if (id != null && id.hasImageEqualTo(returnVariableName)) { initializer = l.getFirstDescendantOfType(ASTVariableInitializer.class); break;