mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-01-10 20:30:11 +08:00
make testable inject method public
This commit is contained in:
parent
bd203dc409
commit
47aa73bd13
@ -5,6 +5,7 @@ import com.alibaba.testable.core.generator.TestSetupMethodGenerator;
|
|||||||
import com.alibaba.testable.core.generator.TestableRefFieldGenerator;
|
import com.alibaba.testable.core.generator.TestableRefFieldGenerator;
|
||||||
import com.alibaba.testable.core.model.TestableContext;
|
import com.alibaba.testable.core.model.TestableContext;
|
||||||
import com.alibaba.testable.core.constant.ConstPool;
|
import com.alibaba.testable.core.constant.ConstPool;
|
||||||
|
import com.alibaba.testable.core.util.TypeUtil;
|
||||||
import com.sun.tools.javac.tree.JCTree;
|
import com.sun.tools.javac.tree.JCTree;
|
||||||
import com.sun.tools.javac.tree.JCTree.*;
|
import com.sun.tools.javac.tree.JCTree.*;
|
||||||
import com.sun.tools.javac.util.ListBuffer;
|
import com.sun.tools.javac.util.ListBuffer;
|
||||||
@ -24,8 +25,8 @@ import java.util.Arrays;
|
|||||||
public class EnableTestableTranslator extends BaseTranslator {
|
public class EnableTestableTranslator extends BaseTranslator {
|
||||||
|
|
||||||
private final TestableContext cx;
|
private final TestableContext cx;
|
||||||
private String testClassName;
|
private final String testClassName;
|
||||||
private String sourceClassName;
|
private final String sourceClassName;
|
||||||
private final ListBuffer<Name> sourceClassIns = new ListBuffer<>();
|
private final ListBuffer<Name> sourceClassIns = new ListBuffer<>();
|
||||||
private final ListBuffer<String> privateOrFinalFields = new ListBuffer<>();
|
private final ListBuffer<String> privateOrFinalFields = new ListBuffer<>();
|
||||||
private final ListBuffer<String> privateMethods = new ListBuffer<>();
|
private final ListBuffer<String> privateMethods = new ListBuffer<>();
|
||||||
@ -85,12 +86,13 @@ public class EnableTestableTranslator extends BaseTranslator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search for TestableInject and TestSetup annotations
|
* Search for TestableInject 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) {
|
||||||
if (a.type != null && ConstPool.ANNOTATION_TESTABLE_INJECT.equals(a.type.tsym.toString())) {
|
if (a.type != null && ConstPool.ANNOTATION_TESTABLE_INJECT.equals(a.type.tsym.toString())) {
|
||||||
|
TypeUtil.toPublicFlags(jcMethodDecl.getModifiers());
|
||||||
ListBuffer<JCExpression> args = new ListBuffer<>();
|
ListBuffer<JCExpression> args = new ListBuffer<>();
|
||||||
for (JCVariableDecl p : jcMethodDecl.params) {
|
for (JCVariableDecl p : jcMethodDecl.params) {
|
||||||
args.add(cx.treeMaker.Select(p.vartype, cx.names.fromString(ConstPool.CLASS_OF_TYPE)));
|
args.add(cx.treeMaker.Select(p.vartype, cx.names.fromString(ConstPool.CLASS_OF_TYPE)));
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package com.alibaba.testable.core.util;
|
package com.alibaba.testable.core.util;
|
||||||
|
|
||||||
|
import com.sun.tools.javac.tree.JCTree;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -10,6 +13,15 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class TypeUtil {
|
public class TypeUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert modifier to public
|
||||||
|
*/
|
||||||
|
public static void toPublicFlags(JCTree.JCModifiers modifiers) {
|
||||||
|
modifiers.flags &= ~Modifier.PRIVATE;
|
||||||
|
modifiers.flags &= ~Modifier.PROTECTED;
|
||||||
|
modifiers.flags |= Modifier.PUBLIC;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Information of substitution method
|
* Information of substitution method
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user