try { Class scriptClass = scriptObject.getClass(); final Method blockMethod = scriptClass.getMethod(method, scriptClass, ThreadContext.class, IRubyObject.class, IRubyObject.class); return new CompiledBlockCallback() { public IRubyObject call(ThreadContext context, IRubyObject self, IRubyObject args) { try { return (IRubyObject)blockMethod.invoke(null, scriptObject, context, self, args); } catch (IllegalAccessException ex) { throw new RuntimeException(ex); } catch (IllegalArgumentException ex) { throw new RuntimeException(ex); } catch (InvocationTargetException ex) { Throwable cause = ex.getCause(); if (cause instanceof RuntimeException) { throw (RuntimeException) cause; } else if (cause instanceof Error) { throw (Error) cause; } else { throw new RuntimeException(ex); } } } }; } catch (NoSuchMethodException nsme) { throw new RuntimeException(nsme); }
try { final Method blockMethod = scriptObject.getClass().getMethod(method, new Class[]{ThreadContext.class, IRubyObject.class, IRubyObject.class}); return new CompiledBlockCallback() { public IRubyObject call(ThreadContext context, IRubyObject self, IRubyObject args) { try { return (IRubyObject)blockMethod.invoke(scriptObject, new Object[]{context, self, args}); } catch (IllegalAccessException ex) { throw new RuntimeException(ex); } catch (IllegalArgumentException ex) { throw new RuntimeException(ex); } catch (InvocationTargetException ex) { Throwable cause = ex.getCause(); if (cause instanceof RuntimeException) { throw (RuntimeException) cause; } else if (cause instanceof Error) { throw (Error) cause; } else { throw new RuntimeException(ex); } } } }; } catch (NoSuchMethodException nsme) { throw new RuntimeException(nsme); }
Clone fragments detected by clone detection tool
File path: /jruby-1.4.0/src/org/jruby/internal/runtime/methods/ReflectionMethodFactory.java File path: /jruby-1.4.0/src/org/jruby/runtime/callback/ReflectionCallbackFactory.java
Method name: CompiledBlockCallback getBlockCallback(String, Object) Method name: CompiledBlockCallback getBlockCallback(String, Object)
Number of AST nodes: 4 Number of AST nodes: 3
1
try {
1
try {
2
            Class scriptClass = scriptObject.getClass();
3
            final Method blockMethod = scriptClass.getMethod(method, scriptClass, ThreadContext.class, IRubyObject.class, IRubyObject.class);
2
            final Method blockMethod = scriptObject.getClass().getMethod(method, new Class[]{ThreadContext.class, IRubyObject.class, IRubyObject.class});
4
            return new CompiledBlockCallback() {
3
            return new CompiledBlockCallback() {
5
                public IRubyObject call(ThreadContext context, IRubyObject self, IRubyObject args) {
4
                public IRubyObject call(ThreadContext context, IRubyObject self, IRubyObject args) {
6
                    try {
5
                    try {
7
                        return (IRubyObject)blockMethod.invoke(null, scriptObject, context, self, args);
6
                        return (IRubyObject)blockMethod.invoke(scriptObject, new Object[]{context, self, args});
8
                    } catch (IllegalAccessException ex) {
7
                    } catch (IllegalAccessException ex) {
9
                        throw new RuntimeException(ex);
8
                        throw new RuntimeException(ex);
10
                    } catch (IllegalArgumentException ex) {
9
                    } catch (IllegalArgumentException ex) {
11
                        throw new RuntimeException(ex);
10
                        throw new RuntimeException(ex);
12
                    } catch (InvocationTargetException ex) {
11
                    } catch (InvocationTargetException ex) {
13
                        Throwable cause = ex.getCause();
12
                        Throwable cause = ex.getCause();
14
                        if (cause instanceof RuntimeException) {
13
                        if (cause instanceof RuntimeException) {
15
                            throw (RuntimeException) cause;
14
                            throw (RuntimeException) cause;
16
                        } else if (cause instanceof Error) {
15
                        } else if (cause instanceof Error) {
17
                            throw (Error) cause;
16
                            throw (Error) cause;
18
                        } else {
17
                        } else {
19
                            throw new RuntimeException(ex);
18
                            throw new RuntimeException(ex);
20
                        }
19
                        }
21
                    }
20
                    }
22
                }
21
                }
23
            };
22
            };
24
        } catch (NoSuchMethodException nsme) {
23
        } catch (NoSuchMethodException nsme) {
25
            throw new RuntimeException(nsme);
24
            throw new RuntimeException(nsme);
26
        }
25
        }
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.9
Clones locationClones are in different classes
Number of node comparisons12
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements2
    Number of unmapped statements in the first code fragment2
    Number of unmapped statements in the second code fragment1
    Time elapsed for statement mapping (ms)13.2
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    1
    try
    1
    try
                                                                                                                                                                                                                                                                                          
    2
    final Method blockMethod = scriptObject.getClass().getMethod(method, new Class[] {ThreadContext.class, IRubyObject.class, IRubyObject.class});
    2
    Class scriptClass = scriptObject.getClass();
                                                                                              
    3
    final Method blockMethod = scriptClass.getMethod(method, scriptClass, ThreadContext.class, IRubyObject.class, IRubyObject.class);
    3
    final Method blockMethod = scriptClass.getMethod(method, scriptClass, ThreadContext.class, IRubyObject.class, IRubyObject.class);
    Preondition Violations
    Unmatched statement final Method blockMethod=scriptClass.getMethod(method,scriptClass,ThreadContext.class,IRubyObject.class,IRubyObject.class); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
                                                                                                                                                                                                                                                                
    4
    return new CompiledBlockCallback() {...};
    4
    return new CompiledBlockCallback() {...};
    3
    return new CompiledBlockCallback() {...};
    Differences
    Expression1Expression2Difference
    blockMethod.invoke(null,scriptObject,context,self,args)blockMethod.invoke(scriptObject,new Object[]{context,self,args})ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression blockMethod.invoke(null,scriptObject,context,self,args) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression blockMethod.invoke(scriptObject,new Object[]{context,self,args}) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3
    return new CompiledBlockCallback() {...};
    Precondition Violations (3)
    Row Violation
    1Unmatched statement final Method blockMethod=scriptClass.getMethod(method,scriptClass,ThreadContext.class,IRubyObject.class,IRubyObject.class); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    2Expression blockMethod.invoke(null,scriptObject,context,self,args) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Expression blockMethod.invoke(scriptObject,new Object[]{context,self,args}) cannot be parameterized, because it has dependencies to/from statements that will be extracted