我有以下代码来分析
a++;
return a++;
现在,我有以下方法实现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;
}
}
问题是,当使用第一个a++
调用此方法时,getParent()
方法应返回a++;
,但它会返回整个块。为什么呢?