mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-01-11 04:40:12 +08:00
fix crash when meet primary parameter type
This commit is contained in:
parent
fecaafca88
commit
eeb3117e7b
@ -55,15 +55,22 @@ public class TestableClassTestRoleTranslator extends TreeTranslator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Demo d = new Demo() -> DemoTestable d = new Demo()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void visitVarDef(JCVariableDecl jcVariableDecl) {
|
public void visitVarDef(JCVariableDecl jcVariableDecl) {
|
||||||
super.visitVarDef(jcVariableDecl);
|
super.visitVarDef(jcVariableDecl);
|
||||||
if (((JCIdent)jcVariableDecl.vartype).name.toString().equals(sourceClassName)) {
|
if (jcVariableDecl.vartype.getClass().equals(JCIdent.class) &&
|
||||||
|
((JCIdent)jcVariableDecl.vartype).name.toString().equals(sourceClassName)) {
|
||||||
jcVariableDecl.vartype = getTestableClassIdent(jcVariableDecl.vartype);
|
jcVariableDecl.vartype = getTestableClassIdent(jcVariableDecl.vartype);
|
||||||
sourceClassIns.add(jcVariableDecl.name);
|
sourceClassIns.add(jcVariableDecl.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Demo d = new Demo() -> Demo d = new DemoTestable()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void visitNewClass(JCNewClass jcNewClass) {
|
public void visitNewClass(JCNewClass jcNewClass) {
|
||||||
super.visitNewClass(jcNewClass);
|
super.visitNewClass(jcNewClass);
|
||||||
@ -72,16 +79,9 @@ public class TestableClassTestRoleTranslator extends TreeTranslator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getSimpleClassName(JCNewClass jcNewClass) {
|
/**
|
||||||
if (jcNewClass.clazz.getClass().equals(JCIdent.class)) {
|
* d.privateField = val -> d.privateFieldTestableSet(val)
|
||||||
return ((JCIdent)jcNewClass.clazz).name.toString();
|
*/
|
||||||
} else if (jcNewClass.clazz.getClass().equals(JCFieldAccess.class)) {
|
|
||||||
return ((JCFieldAccess)jcNewClass.clazz).name.toString();
|
|
||||||
} else {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitExec(JCExpressionStatement jcExpressionStatement) {
|
public void visitExec(JCExpressionStatement jcExpressionStatement) {
|
||||||
if (jcExpressionStatement.expr.getClass().equals(JCAssign.class) &&
|
if (jcExpressionStatement.expr.getClass().equals(JCAssign.class) &&
|
||||||
@ -95,6 +95,9 @@ public class TestableClassTestRoleTranslator extends TreeTranslator {
|
|||||||
super.visitExec(jcExpressionStatement);
|
super.visitExec(jcExpressionStatement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search for TestableInject and TestSetup annotations
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void visitMethodDef(JCMethodDecl jcMethodDecl) {
|
public void visitMethodDef(JCMethodDecl jcMethodDecl) {
|
||||||
for (JCAnnotation a : jcMethodDecl.mods.annotations) {
|
for (JCAnnotation a : jcMethodDecl.mods.annotations) {
|
||||||
@ -122,6 +125,9 @@ public class TestableClassTestRoleTranslator extends TreeTranslator {
|
|||||||
super.visitMethodDef(jcMethodDecl);
|
super.visitMethodDef(jcMethodDecl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate test setup method to initialize n.e.pool
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void visitClassDef(JCClassDecl jcClassDecl) {
|
public void visitClassDef(JCClassDecl jcClassDecl) {
|
||||||
super.visitClassDef(jcClassDecl);
|
super.visitClassDef(jcClassDecl);
|
||||||
@ -135,7 +141,7 @@ public class TestableClassTestRoleTranslator extends TreeTranslator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For break point
|
* For setter break point
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void visitAssign(JCAssign jcAssign) {
|
public void visitAssign(JCAssign jcAssign) {
|
||||||
@ -143,13 +149,23 @@ public class TestableClassTestRoleTranslator extends TreeTranslator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For break point
|
* For getter break point
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void visitSelect(JCFieldAccess jcFieldAccess) {
|
public void visitSelect(JCFieldAccess jcFieldAccess) {
|
||||||
super.visitSelect(jcFieldAccess);
|
super.visitSelect(jcFieldAccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getSimpleClassName(JCNewClass jcNewClass) {
|
||||||
|
if (jcNewClass.clazz.getClass().equals(JCIdent.class)) {
|
||||||
|
return ((JCIdent)jcNewClass.clazz).name.toString();
|
||||||
|
} else if (jcNewClass.clazz.getClass().equals(JCFieldAccess.class)) {
|
||||||
|
return ((JCFieldAccess)jcNewClass.clazz).name.toString();
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private List<JCAnnotation> makeAnnotations(String fullAnnotationName) {
|
private List<JCAnnotation> makeAnnotations(String fullAnnotationName) {
|
||||||
JCExpression setupAnnotation = nameToExpression(fullAnnotationName);
|
JCExpression setupAnnotation = nameToExpression(fullAnnotationName);
|
||||||
return List.of(cx.treeMaker.Annotation(setupAnnotation, List.<JCExpression>nil()));
|
return List.of(cx.treeMaker.Annotation(setupAnnotation, List.<JCExpression>nil()));
|
||||||
|
Loading…
Reference in New Issue
Block a user