some annotation type can be null, e.g. java.lang.Override

This commit is contained in:
金戟 2020-07-26 20:42:27 +08:00
parent a814e51f66
commit 9e1c1b8c3b

View File

@ -86,7 +86,7 @@ public class EnableTestableTranslator extends BaseTranslator {
@Override
public void visitMethodDef(JCMethodDecl jcMethodDecl) {
for (JCAnnotation a : jcMethodDecl.mods.annotations) {
if (ConstPool.ANNOTATION_TESTABLE_INJECT.equals(a.type.tsym.toString())) {
if (a.type != null && ConstPool.ANNOTATION_TESTABLE_INJECT.equals(a.type.tsym.toString())) {
ListBuffer<JCExpression> args = new ListBuffer<>();
for (JCVariableDecl p : jcMethodDecl.params) {
args.add(cx.treeMaker.Select(p.vartype, cx.names.fromString(ConstPool.CLASS_OF_TYPE)));
@ -145,16 +145,6 @@ public class EnableTestableTranslator extends BaseTranslator {
return expr;
}
private List<JCAnnotation> removeAnnotation(List<JCAnnotation> annotations, String target) {
ListBuffer<JCAnnotation> nb = new ListBuffer<>();
for (JCAnnotation i : annotations) {
if (!i.type.tsym.toString().equals(target)) {
nb.add(i);
}
}
return nb.toList();
}
private boolean isPrivateField(JCAssign expr) {
return expr.lhs.getClass().equals(JCFieldAccess.class) &&
((JCFieldAccess)(expr).lhs).selected.getClass().equals(JCIdent.class) &&