use of net.sourceforge.pmd.lang.java.ast.ASTPrimaryPrefix in project pmd by pmd.
the class AtfdBaseVisitor method getMethodOrAttributeName.
private String getMethodOrAttributeName(ASTPrimaryExpression node) {
ASTPrimaryPrefix prefix = node.getFirstDescendantOfType(ASTPrimaryPrefix.class);
ASTName name = prefix.getFirstDescendantOfType(ASTName.class);
String methodOrAttributeName = null;
if (name != null) {
int dotIndex = name.getImage().indexOf(".");
if (dotIndex > -1) {
methodOrAttributeName = name.getImage().substring(dotIndex + 1);
}
}
return methodOrAttributeName;
}
use of net.sourceforge.pmd.lang.java.ast.ASTPrimaryPrefix in project pmd by pmd.
the class AtfdBaseVisitor method getNameImage.
private String getNameImage(ASTPrimaryExpression node) {
ASTPrimaryPrefix prefix = node.getFirstDescendantOfType(ASTPrimaryPrefix.class);
ASTName name = prefix.getFirstDescendantOfType(ASTName.class);
String image = null;
if (name != null) {
image = name.getImage();
}
return image;
}
use of net.sourceforge.pmd.lang.java.ast.ASTPrimaryPrefix in project pmd by pmd.
the class UselessStringValueOfRule method isPrimitive.
private static boolean isPrimitive(Node parent) {
boolean result = false;
if (parent instanceof ASTPrimaryExpression && parent.jjtGetNumChildren() == 1) {
Node child = parent.jjtGetChild(0);
if (child instanceof ASTPrimaryPrefix && child.jjtGetNumChildren() == 1) {
Node gc = child.jjtGetChild(0);
if (gc instanceof ASTName) {
ASTName name = (ASTName) gc;
NameDeclaration nd = name.getNameDeclaration();
if (nd instanceof VariableNameDeclaration && ((VariableNameDeclaration) nd).isPrimitiveType()) {
result = true;
}
} else if (gc instanceof ASTLiteral) {
result = !((ASTLiteral) gc).isStringLiteral();
}
}
}
return result;
}
use of net.sourceforge.pmd.lang.java.ast.ASTPrimaryPrefix in project pmd by pmd.
the class JavaNameOccurrence method isSelfAssignment.
/**
* Assert it the occurrence is a self assignment such as:
* <code>i += 3;</code>
*
* @return true, if the occurrence is self-assignment, false, otherwise.
*/
@SuppressWarnings("PMD.AvoidBranchingStatementAsLastInLoop")
public boolean isSelfAssignment() {
Node l = location;
while (true) {
Node p = l.jjtGetParent();
Node gp = p.jjtGetParent();
Node node = gp.jjtGetParent();
if (node instanceof ASTPreDecrementExpression || node instanceof ASTPreIncrementExpression || node instanceof ASTPostfixExpression) {
return true;
}
if (hasAssignmentOperator(gp)) {
return isCompoundAssignment(gp);
}
if (hasAssignmentOperator(node)) {
return isCompoundAssignment(node);
}
// deal with extra parenthesis: "(i)++"
if (p instanceof ASTPrimaryPrefix && p.jjtGetNumChildren() == 1 && gp instanceof ASTPrimaryExpression && gp.jjtGetNumChildren() == 1 && node instanceof ASTExpression && node.jjtGetNumChildren() == 1 && node.jjtGetParent() instanceof ASTPrimaryPrefix && node.jjtGetParent().jjtGetNumChildren() == 1) {
l = node;
continue;
}
// catch this.i++ or ++this.i
return gp instanceof ASTPreDecrementExpression || gp instanceof ASTPreIncrementExpression || gp instanceof ASTPostfixExpression;
}
}
use of net.sourceforge.pmd.lang.java.ast.ASTPrimaryPrefix in project pmd by pmd.
the class JavaNameOccurrence method useThisOrSuper.
/**
* Simply return if the image start with keyword 'this' or 'super'.
*
* @return true, if keyword is used, false otherwise.
*/
public boolean useThisOrSuper() {
Node node = location.jjtGetParent();
if (node instanceof ASTPrimaryExpression) {
ASTPrimaryExpression primaryExpression = (ASTPrimaryExpression) node;
ASTPrimaryPrefix prefix = (ASTPrimaryPrefix) primaryExpression.jjtGetChild(0);
if (prefix != null) {
return prefix.usesSuperModifier() || prefix.usesThisModifier();
}
}
return image.startsWith(THIS_DOT) || image.startsWith(SUPER_DOT);
}
Aggregations