Method[] methods = clazz.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { Method methodEntry = methods[i]; if (methodEntry.getName().equals(method)) { return true; } } return false;
Field[] fields = clazz.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { Field fieldEntry = fields[i]; if (fieldEntry.getName().equals(field)) { return true; } } return false;
Clone fragments detected by clone detection tool
File path: /apache-ant-1.7.0/src/org/apache/tools/ant/taskdefs/condition/HasMethod.java File path: /apache-ant-1.7.0/src/org/apache/tools/ant/taskdefs/condition/HasMethod.java
Method name: boolean isMethodFound(Class) Method name: boolean isFieldFound(Class)
Number of AST nodes: 6 Number of AST nodes: 6
1
Method[] methods = clazz.getDeclaredMethods();
1
Field[] fields = clazz.getDeclaredFields();
2
        for (int i = 0; i < methods.length; i++) {
2
        for (int i = 0; i < fields.length; i++) {
3
            Method methodEntry = methods[i];
3
            Field fieldEntry = fields[i];
4
            if (methodEntry.getName().equals(method)) {
4
            if (fieldEntry.getName().equals(field)) {
5
                return true;
5
                return true;
6
            }
6
            }
7
        }
7
        }
8
        return false;
8
        return false;
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.4
Clones locationClones are declared in the same class
Number of node comparisons12
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements5
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment1
    Time elapsed for statement mapping (ms)2.2
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
                                                                                            
    1
    Field[] fields = clazz.getDeclaredFields();
    Preondition Violations
    Unmatched statement Field[] fields=clazz.getDeclaredFields(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    1
    Field[] fields = clazz.getDeclaredFields();
    1
    Method[] methods = clazz.getDeclaredMethods();
    1
    Method[] methods = clazz.getDeclaredMethods();
    Preondition Violations
    Unmatched statement Method[] methods=clazz.getDeclaredMethods(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
                                                                                                  
    2
    for (int i = 0; i < methods.length; i++)
    2
    for (int i = 0; i < methods.length; i++)
    2
    for (int i = 0; i < fields.length; i++)
    Differences
    Expression1Expression2Difference
    methodsfieldsVARIABLE_NAME_MISMATCH
    java.lang.reflect.Method[]java.lang.reflect.Field[]VARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type int of variable methods.length does not match with type int of variable fields.length
    • Make classes java.lang.reflect.Method[] and java.lang.reflect.Field[] extend a common superclass
    2
    for (int i = 0; i < fields.length; i++)
    3
    Method methodEntry = methods[i];
    3
    Method methodEntry = methods[i];
    3
    Field fieldEntry = fields[i];
    Differences
    Expression1Expression2Difference
    java.lang.reflect.Methodjava.lang.reflect.FieldSUBCLASS_TYPE_MISMATCH
    methodEntryfieldEntryVARIABLE_NAME_MISMATCH
    java.lang.reflect.Methodjava.lang.reflect.FieldSUBCLASS_TYPE_MISMATCH
    methodsfieldsVARIABLE_NAME_MISMATCH
    java.lang.reflect.Method[]java.lang.reflect.Field[]VARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.lang.reflect.Method[] of variable methods does not match with type java.lang.reflect.Field[] of variable fields
    • Make classes java.lang.reflect.Method[] and java.lang.reflect.Field[] extend a common superclass
    3
    Field fieldEntry = fields[i];
    4
    if (methodEntry.getName().equals(method))
    4
    if (methodEntry.getName().equals(method))
    4
    if (fieldEntry.getName().equals(field))
    Differences
    Expression1Expression2Difference
    methodfieldVARIABLE_NAME_MISMATCH
    methodEntryfieldEntryVARIABLE_NAME_MISMATCH
    java.lang.reflect.Methodjava.lang.reflect.FieldSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression methodEntry cannot be unified with expression fieldEntry , because common superclass java.lang.reflect.AccessibleObject does not declare member(s) public java.lang.String getName()
    4
    if (fieldEntry.getName().equals(field))
    5
    return true;
    5
    return true;
    6
    return false;
    6
    return false;
    Precondition Violations (5)
    Row Violation
    1Unmatched statement Field[] fields=clazz.getDeclaredFields(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    2Unmatched statement Method[] methods=clazz.getDeclaredMethods(); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
    3Type int of variable methods.length does not match with type int of variable fields.length
    4Type java.lang.reflect.Method[] of variable methods does not match with type java.lang.reflect.Field[] of variable fields
    5Expression methodEntry cannot be unified with expression fieldEntry , because common superclass java.lang.reflect.AccessibleObject does not declare member(s) public java.lang.String getName()