getParent() returning unexpected node

43 Views Asked by At

I have the following code to analyze

a++;
return a++;

Now, I have the following implementation of method isToBeProcessed

public boolean isToBeProcessed(CtUnaryOperator<? extends CtElement> candidate) {
    if (!super.validMutationSpot(candidate)) {
        LOGGER.log(Level.FINER, "{0} is not a valid mutation spot", new Object[]{candidate});
        return false;
    }
    if (    candidate.getKind().compareTo(UnaryOperatorKind.POSTDEC) == 0
            ||
            candidate.getKind().compareTo(UnaryOperatorKind.POSTINC) == 0
            ||
            candidate.getKind().compareTo(UnaryOperatorKind.PREDEC) == 0
            ||
            candidate.getKind().compareTo(UnaryOperatorKind.PREINC) == 0) {
        //check that is not a statement
        if (candidate.getParent() instanceof CtStatement) {
            LOGGER.log(Level.FINER, "{0} is a statement {1}", new Object[]{candidate, candidate.getParent()});
            return false;
        } else {
            return true;
        }
    } else {
        LOGGER.log(Level.FINER, "{0} operator is not a pre/post inc or dec", new Object[]{candidate});
        return false;
    }
}

The problem is that when this method is called with the first a++ the getParent() method should return a++; but it's returning the whole block. Why?

0

There are 0 best solutions below