diff --git a/TracerOnJavassist/src/tracer/Tracer.java b/TracerOnJavassist/src/tracer/Tracer.java index 1305c2c..b8858c6 100644 --- a/TracerOnJavassist/src/tracer/Tracer.java +++ b/TracerOnJavassist/src/tracer/Tracer.java @@ -40,13 +40,19 @@ private static CodeConverter conv = new CodeConverter(); public static void main(String[] args) { - outputStatementsGenerator = new OutputStatementsGenerator(new JSONTraceGenerator()); // �����ŏo�̓t�H�[�}�b�g���w�肷�� - String packageName = "worstCase"; // �w�肵���p�b�P�[�W�����̑S�N���X�ɃC���X�g�D�������e�[�V�������s�� - ClassLoader loader = Thread.currentThread().getContextClassLoader(); - URL resource = loader.getResource(packageName); - + initialize(new OutputStatementsGenerator(new JSONTraceGenerator())); // �����ŏo�̓t�H�[�}�b�g���w�肷�� + packageInstrumentation("worstCase"); // �w�肵���p�b�P�[�W�����̑S�N���X�ɃC���X�g�D�������e�[�V�������s�� + } + + /** + * �o�͕���������w�肵�ăC���X�g�D�������e�[�V�����̏��������s�� + * + * @param outputStatementsGenerator �o�͕�������(�o�̓t�H�[�}�b�g���w��ł���) + */ + public static void initialize(OutputStatementsGenerator outputStatementsGenerator) { // �z��ւ̃A�N�Z�X�̌��o - if (!(outputStatementsGenerator.getGenerator() instanceof PlainTextTraceGenerator)) { + Tracer.outputStatementsGenerator = outputStatementsGenerator; // �����ŏo�̓t�H�[�}�b�g���w�肷�� + if (!(Tracer.outputStatementsGenerator.getGenerator() instanceof PlainTextTraceGenerator)) { // ClassPool cp = ClassPool.getDefault(); CtClass cc; @@ -57,7 +63,24 @@ e1.printStackTrace(); } } - + } + + /** + * �������ς݂�? + * @return �������ς�: true, ����ȊO: false + */ + public static boolean isInitialized() { + return (outputStatementsGenerator != null); + } + + /** + * �w�肵���p�b�P�[�W���̃N���X�ɃC���X�g�D�������e�[�V�������s�� + * + * @param packageName �p�b�P�[�W�� + */ + public static void packageInstrumentation(String packageName) { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + URL resource = loader.getResource(packageName); File dir; try { dir = new File(URLDecoder.decode(resource.getPath(), "UTF-8")); @@ -73,31 +96,37 @@ } /** - * �w�肵���N���X�ɃC���X�g�D�������e�[�V�������s���i���j + * �w�肵���N���X�ɃC���X�g�D�������e�[�V�������s�� * - * @param className - * �N���X�� + * @param className �N���X�� */ - private static void classInstrumentation(String className) { + public static void classInstrumentation(String className) { ClassPool cp = ClassPool.getDefault(); CtClass cc; try { cc = cp.get(className); - for (final CtConstructor c : cc.getDeclaredConstructors()) { - methodInstrumentation(cc, c); - } - for (final CtMethod m : cc.getDeclaredMethods()) { - methodInstrumentation(cc, m); - } - cc.instrument(conv); - cc.writeFile("bin"); + classInstrumentation(cc); } catch (NotFoundException | BadBytecode | CannotCompileException | IOException e) { e.printStackTrace(); - // } catch (CannotCompileException | IOException e) { - // e.printStackTrace(); } } + /** + * �w�肵���N���X�ɃC���X�g�D�������e�[�V�������s�� + * + * @param cc Javassist�̃N���X�I�u�W�F�N�g + */ + public static void classInstrumentation(CtClass cc) throws BadBytecode, NotFoundException, CannotCompileException, IOException { + for (final CtConstructor c : cc.getDeclaredConstructors()) { + methodInstrumentation(cc, c); + } + for (final CtMethod m : cc.getDeclaredMethods()) { + methodInstrumentation(cc, m); + } + cc.instrument(conv); + cc.writeFile("bin"); + } + private static void methodInstrumentation(final CtClass cc, final CtBehavior m) throws BadBytecode, NotFoundException, CannotCompileException { // ���\�b�h�{�̓��̊e�u���b�N�̍ŏ��ɏo�͕���}������(�o�͕��̑}���Ńu���b�N�������Ă��܂��̂ŁA��ɑ}�����Ă���) Block[] blocks = null;