ConstPool cp = classfile.getConstPool(); int this_class_index = cp.getThisClassInfo(); MethodInfo minfo = new MethodInfo(cp, SETFIELDHANDLER_METHOD_NAME, SETFIELDHANDLER_METHOD_DESCRIPTOR); /* local variables | this | callback | */ Bytecode code = new Bytecode(cp, 3, 3); // aload_0 // load this code.addAload(0); // aload_1 // load callback code.addAload(1); // putfield // put field "$JAVASSIST_CALLBACK" defined already code.addOpcode(Opcode.PUTFIELD); int field_index = cp.addFieldrefInfo(this_class_index, HANDLER_FIELD_NAME, HANDLER_FIELD_DESCRIPTOR); code.addIndex(field_index); // return code.addOpcode(Opcode.RETURN); minfo.setCodeAttribute(code.toCodeAttribute()); minfo.setAccessFlags(AccessFlag.PUBLIC); classfile.addMethod(minfo);
ConstPool cp = classfile.getConstPool(); int this_class_index = cp.getThisClassInfo(); MethodInfo minfo = new MethodInfo(cp, GETFIELDHANDLER_METHOD_NAME, GETFIELDHANDLER_METHOD_DESCRIPTOR); /* local variable | this | */ Bytecode code = new Bytecode(cp, 2, 1); // aload_0 // load this code.addAload(0); // getfield // get field "$JAVASSIST_CALLBACK" defined already code.addOpcode(Opcode.GETFIELD); int field_index = cp.addFieldrefInfo(this_class_index, HANDLER_FIELD_NAME, HANDLER_FIELD_DESCRIPTOR); code.addIndex(field_index); // areturn // return the value of the field code.addOpcode(Opcode.ARETURN); minfo.setCodeAttribute(code.toCodeAttribute()); minfo.setAccessFlags(AccessFlag.PUBLIC); classfile.addMethod(minfo);
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/core/src/main/java/org/hibernate/bytecode/javassist/FieldTransformer.java File path: /hibernate-distribution-3.3.2.GA/project/core/src/main/java/org/hibernate/bytecode/javassist/FieldTransformer.java
Method name: void addSetFieldHandlerMethod(ClassFile) Method name: void addGetFieldHandlerMethod(ClassFile)
Number of AST nodes: 13 Number of AST nodes: 12
1
ConstPool cp = classfile.getConstPool();
1
ConstPool cp = classfile.getConstPool();
2
		int this_class_index = cp.getThisClassInfo();
2
		int this_class_index = cp.getThisClassInfo();
3
		MethodInfo minfo = new MethodInfo(cp, SETFIELDHANDLER_METHOD_NAME,
3
		MethodInfo minfo = new MethodInfo(cp, GETFIELDHANDLER_METHOD_NAME,
4
		                                  SETFIELDHANDLER_METHOD_DESCRIPTOR);
4
		                                  GETFIELDHANDLER_METHOD_DESCRIPTOR);
5
		/* local variables | this | callback | */
5
		/* local variable | this | */
6
		Bytecode code = new Bytecode(cp, 3, 3);
6
		Bytecode code = new Bytecode(cp, 2, 1);
7
		// aload_0 // load this
7
		// aload_0 // load this
8
		code.addAload(0);
8
		code.addAload(0);
9
		// aload_1 // load callback
9
		// 
10
		code.addAload(1);
11
		// putfield // put field "$JAVASSIST_CALLBACK" defined already
10
getfield // get field "$JAVASSIST_CALLBACK" defined already
12
		code.addOpcode(Opcode.PUTFIELD);
11
		code.addOpcode(Opcode.GETFIELD);
13
		int field_index = cp.addFieldrefInfo(this_class_index,
12
		int field_index = cp.addFieldrefInfo(this_class_index,
14
		                                     HANDLER_FIELD_NAME, HANDLER_FIELD_DESCRIPTOR);
13
		                                     HANDLER_FIELD_NAME, HANDLER_FIELD_DESCRIPTOR);
15
		code.addIndex(field_index);
14
		code.addIndex(field_index);
16
		// return
15
		// areturn // return the value of the field
17
		code.addOpcode(Opcode.RETURN);
16
		code.addOpcode(Opcode.ARETURN);
18
		minfo.setCodeAttribute(code.toCodeAttribute());
17
		minfo.setCodeAttribute(code.toCodeAttribute());
19
		minfo.setAccessFlags(AccessFlag.PUBLIC);
18
		minfo.setAccessFlags(AccessFlag.PUBLIC);
20
		classfile.addMethod(minfo);
19
		classfile.addMethod(minfo);
Summary
Number of common nesting structure subtrees1
Number of refactorable cases0
Number of non-refactorable cases1
Time elapsed for finding largest common nesting structure subtrees (ms)0.0
Clones locationClones are declared in the same class
Number of node comparisons113
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements12
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    1
    ConstPool cp = classfile.getConstPool();
    1
    ConstPool cp = classfile.getConstPool();
    2
    int this_class_index = cp.getThisClassInfo();
    2
    int this_class_index = cp.getThisClassInfo();
    3
    MethodInfo minfo = new MethodInfo(cp, SETFIELDHANDLER_METHOD_NAME, SETFIELDHANDLER_METHOD_DESCRIPTOR);
    3
    MethodInfo minfo = new MethodInfo(cp, SETFIELDHANDLER_METHOD_NAME, SETFIELDHANDLER_METHOD_DESCRIPTOR);
    3
    MethodInfo minfo = new MethodInfo(cp, GETFIELDHANDLER_METHOD_NAME, GETFIELDHANDLER_METHOD_DESCRIPTOR);
    Differences
    Expression1Expression2Difference
    SETFIELDHANDLER_METHOD_NAMEGETFIELDHANDLER_METHOD_NAMEVARIABLE_NAME_MISMATCH
    SETFIELDHANDLER_METHOD_DESCRIPTORGETFIELDHANDLER_METHOD_DESCRIPTORVARIABLE_NAME_MISMATCH
    3
    MethodInfo minfo = new MethodInfo(cp, GETFIELDHANDLER_METHOD_NAME, GETFIELDHANDLER_METHOD_DESCRIPTOR);
    4
    Bytecode code = new Bytecode(cp, 3, 3);
    4
    Bytecode code = new Bytecode(cp, 3, 3);
    4
    Bytecode code = new Bytecode(cp, 2, 1);
    Differences
    Expression1Expression2Difference
    32LITERAL_VALUE_MISMATCH
    31LITERAL_VALUE_MISMATCH
    4
    Bytecode code = new Bytecode(cp, 2, 1);
    5
    code.addAload(0);
    5
    code.addAload(0);
    6
    code.addAload(1);
                                            
    7
    code.addOpcode(Opcode.PUTFIELD);
    7
    code.addOpcode(Opcode.PUTFIELD);
    6
    code.addOpcode(Opcode.GETFIELD);
    Differences
    Expression1Expression2Difference
    PUTFIELDGETFIELDVARIABLE_NAME_MISMATCH
    6
    code.addOpcode(Opcode.GETFIELD);
    8
    int field_index = cp.addFieldrefInfo(this_class_index, HANDLER_FIELD_NAME, HANDLER_FIELD_DESCRIPTOR);
    7
    int field_index = cp.addFieldrefInfo(this_class_index, HANDLER_FIELD_NAME, HANDLER_FIELD_DESCRIPTOR);
    9
    code.addIndex(field_index);
    8
    code.addIndex(field_index);
    10
    code.addOpcode(Opcode.RETURN);
    10
    code.addOpcode(Opcode.RETURN);
    9
    code.addOpcode(Opcode.ARETURN);
    Differences
    Expression1Expression2Difference
    RETURNARETURNVARIABLE_NAME_MISMATCH
    9
    code.addOpcode(Opcode.ARETURN);
    11
    minfo.setCodeAttribute(code.toCodeAttribute());
    10
    minfo.setCodeAttribute(code.toCodeAttribute());
    12
    minfo.setAccessFlags(AccessFlag.PUBLIC);
    11
    minfo.setAccessFlags(AccessFlag.PUBLIC);
    13
    classfile.addMethod(minfo);
    12
    classfile.addMethod(minfo);
    Precondition Violations (1)
    Row Violation
    1Clone fragment #1 returns variables code , while Clone fragment #2 returns variables