diff --git a/TracerOnJavassist/src/tracer/Tracer.java b/TracerOnJavassist/src/tracer/Tracer.java index cf6d263..1d16290 100644 --- a/TracerOnJavassist/src/tracer/Tracer.java +++ b/TracerOnJavassist/src/tracer/Tracer.java @@ -138,7 +138,7 @@ public void edit(NewExpr n) throws CannotCompileException { try { CtConstructor m = n.getConstructor(); - if (m.isEmpty() || m.getDeclaringClass().getName().matches(CONCRETE_STANDARD_CLASSES)) { + if (m.getDeclaringClass().getName().matches(CONCRETE_STANDARD_CLASSES)) { Outputs out = generateOutputs(m.getDeclaringClass(), m, true); n.replace("{" + out.newOutput + out.methodOutput + out.classOutput + out.argsOutput + " $_ = $proceed($$); " + out.returnOutput + "}"); } @@ -146,27 +146,31 @@ e.printStackTrace(); } } - public void edit(ConstructorCall c) throws CannotCompileException { - try { - CtConstructor m = c.getConstructor(); - if ((m.isEmpty() && !m.getDeclaringClass().getName().equals("java.lang.Object")) - || m.getDeclaringClass().getName().matches(CONCRETE_STANDARD_CLASSES)) { - Outputs out = generateOutputs(m.getDeclaringClass(), m, true); - c.replace("{" + out.newOutput + out.methodOutput + out.classOutput + out.argsOutput + " $_ = $proceed($$); " + out.returnOutput + "}"); - } - } catch (NotFoundException e) { - e.printStackTrace(); - } - } +// public void edit(ConstructorCall c) throws CannotCompileException { +// try { +// CtConstructor m = c.getConstructor(); +// if (m.getDeclaringClass().getName().matches(CONCRETE_STANDARD_CLASSES)) { +// Outputs out = generateOutputs(m.getDeclaringClass(), m, true); +// c.replace("{" + out.newOutput + out.methodOutput + out.classOutput + out.argsOutput + " $_ = $proceed($$); " + out.returnOutput + "}"); +// } +// } catch (NotFoundException e) { +// e.printStackTrace(); +// } +// } }); // ���\�b�h�p�̏o�͕��𐶐����� + Outputs outputs = generateOutputs(cc, m, false); if (!m.isEmpty()) { - Outputs outputs = generateOutputs(cc, m, false); - // ���\�b�h�̎��s�O��ɏo�͕���}������ m.insertBefore("{" + outputs.newOutput + outputs.methodOutput + outputs.classOutput + outputs.argsOutput + "}"); m.insertAfter("{" + outputs.returnOutput + "}"); + } else { + // ���\�b�h�{�̂���̂Ƃ��̓R���X�g���N�^�̏ꍇ�̂�(=�f�t�H���g�R���X�g���N�^)�{�̂ɏo�͕���ݒ肷�� + if (m instanceof CtConstructor) { + m.setBody("{" + outputs.returnOutput + "}"); + m.insertBefore("{" + outputs.newOutput + outputs.methodOutput + outputs.classOutput + outputs.argsOutput + "}"); + } } // CodeConverter conv = new CodeConverter(); @@ -310,31 +314,40 @@ outputs.argsOutput += " + " + LINE_AND_THREAD + ");"; } - String accessor = ""; + String modifiers = ""; if ((m.getModifiers() & Modifier.PUBLIC) != 0) { - accessor = "public "; + modifiers = "public "; } else if ((m.getModifiers() & Modifier.PRIVATE) != 0) { - accessor = "private "; + modifiers = "private "; } else if ((m.getModifiers() & Modifier.PROTECTED) != 0) { - accessor = "protected "; + modifiers = "protected "; + } + if ((m.getModifiers() & Modifier.STATIC) != 0) { + modifiers += "static "; + } + if ((m.getModifiers() & Modifier.FINAL) != 0) { + modifiers += "final "; + } + if ((m.getModifiers() & Modifier.SYNCHRONIZED) != 0) { + modifiers += "synchronized "; } String longName = null; if ((m.getModifiers() & Modifier.STATIC) != 0) { // static���\�b�h�̏ꍇ - longName = accessor + "static " + m.getLongName().replace('$', '.'); // AspectJ�ł̓��\�b�h�V�O�j�`�����ł͖����N���X�̓h�b�g�ŋ�؂��� + longName = modifiers + m.getLongName().replace('$', '.'); // AspectJ�ł̓��\�b�h�V�O�j�`�����ł͖����N���X�̓h�b�g�ŋ�؂��� outputs.methodOutput = "tracer.MyPrintStream.println(\"Method " + declaredClassName + "," + longName + ":\" + 0 + " + LINE + " + System.nanoTime() + \":ThreadNo \" + Thread.currentThread().getId());"; outputs.classOutput = "tracer.MyPrintStream.println(\"Class " + declaredClassName + ":\" + 0 + " + LINE_AND_THREAD + ");"; } else if (m instanceof CtConstructor) { // �R���X�g���N�^�̏ꍇ - longName = accessor + m.getLongName().replace('$', '.'); // AspectJ�ł̓��\�b�h�V�O�j�`�����ł͖����N���X�̓h�b�g�ŋ�؂��� + longName = modifiers + m.getLongName().replace('$', '.'); // AspectJ�ł̓��\�b�h�V�O�j�`�����ł͖����N���X�̓h�b�g�ŋ�؂��� outputs.newOutput = "tracer.MyPrintStream.println(\"New " + declaredClassName + ":\" + 0 + " + LINE_AND_THREAD + ");"; outputs.methodOutput = "tracer.MyPrintStream.println(\"Method " + declaredClassName + "," + longName + ":\" + 0 + " + LINE + " + System.nanoTime() + \":ThreadNo \" + Thread.currentThread().getId());"; outputs.classOutput = "tracer.MyPrintStream.println(\"Class " + declaredClassName + ":\" + 0 + " + LINE_AND_THREAD + ");"; } else { // �ʏ�̃��\�b�h�̏ꍇ - longName = accessor + ((CtMethod)m).getReturnType().getName() + " " + m.getLongName().replace('$', '.'); // AspectJ�ł̓��\�b�h�V�O�j�`�����ł͖����N���X�̓h�b�g�ŋ�؂��� + longName = modifiers + ((CtMethod)m).getReturnType().getName() + " " + m.getLongName().replace('$', '.'); // AspectJ�ł̓��\�b�h�V�O�j�`�����ł͖����N���X�̓h�b�g�ŋ�؂��� if (!isCallerSideInstrumentation) { // �Ăяo����ɖ��ߍ��ޏꍇ(�ʏ�) outputs.methodOutput = "tracer.MyPrintStream.println(\"Method \" + this.getClass().getName() + \"," + longName