private StringBuffer generateIncludes(StringBuffer sb) { for (Iterator it = systemInc.iterator(); it.hasNext(); ) { String inc = (String) it.next(); sb.append("#include <"); sb.append(inc).append('>').append(LINE_SEPARATOR); } // separate system from external headers if (systemInc.size() > 0) sb.append(LINE_SEPARATOR); for (Iterator it = extInc.iterator(); it.hasNext(); ) { String inc = (String) it.next(); sb.append("#include <"); sb.append(inc).append('>').append(LINE_SEPARATOR); } // separate external from local headers if (extInc.size() > 0) sb.append(LINE_SEPARATOR); for (Iterator it = localInc.iterator(); it.hasNext(); ) { String inc = (String) it.next(); sb.append("#include \"").append(inc).append("\"" + LINE_SEPARATOR); } return sb; }
/** 2002-12-12 Achim Spangler * generate global typedefs */ private StringBuffer generateGlobalTypedefs(Object cls) { StringBuffer sb = new StringBuffer(); if (getFacade().isAClass(cls) || getFacade().isAInstance(cls)) { // add typedefs if (generatorPass == HEADER_PASS) { Collection globalTypedefStatements = findTagValues(cls, "typedef_global_header"); if (!globalTypedefStatements.isEmpty()) { sb.append("// global type definitions for header defined " + "by Tag entries in ArgoUML"); sb.append(LINE_SEPARATOR); sb.append("// Result: typedef <typedef_global_header> " + "<tag_value>;"); sb.append(LINE_SEPARATOR); Iterator typedefEnum = globalTypedefStatements.iterator(); while (typedefEnum.hasNext()) { sb.append("typedef ").append(typedefEnum.next()); sb.append(";").append(LINE_SEPARATOR); } } } else { Collection globalTypedefStatements = findTagValues(cls, "typedef_global_source"); if (!globalTypedefStatements.isEmpty()) { sb.append("// global type definitions for class " + "implementation in source file defined by Tag " + "entries in ArgoUML"); sb.append(LINE_SEPARATOR); sb.append("// Result: typedef <typedef_global_source> " + "<tag_value>;"); sb.append(LINE_SEPARATOR); Iterator typedefEnum = globalTypedefStatements.iterator(); while (typedefEnum.hasNext()) { sb.append("typedef ").append(typedefEnum.next()); sb.append(";").append(LINE_SEPARATOR); } } } } return sb; }
Clone fragments detected by clone detection tool
File path: /ArgoUML-0.34-src/argouml-cpp/src/org/argouml/language/cpp/generator/GeneratorCpp.java File path: /ArgoUML-0.34-src/argouml-cpp/src/org/argouml/language/cpp/generator/GeneratorCpp.java
Method name: StringBuffer generateIncludes(StringBuffer) Method name: StringBuffer generateGlobalTypedefs(Object)
Number of AST nodes: 4 Number of AST nodes: 3
1
private StringBuffer generateIncludes(StringBuffer sb) {
1
/** 2002-12-12 Achim Spangler
2
        for (Iterator it = systemInc.iterator(); it.hasNext(); ) {
2
     * generate global typedefs
3
            String inc = (String) it.next();
3
     */
4
            sb.append("#include <");
4
    private StringBuffer generateGlobalTypedefs(Object cls) {
5
            sb.append(inc).append('>').append(LINE_SEPARATOR);
5
        StringBuffer sb = new StringBuffer();
6
        }
6
        if (getFacade().isAClass(cls) || getFacade().isAInstance(cls)) {
7
        // separate system from external headers
7
            // add typedefs
8
        if (systemInc.size() > 0) sb.append(LINE_SEPARATOR);
8
            if (generatorPass == HEADER_PASS) {
9
        for (Iterator it = extInc.iterator(); it.hasNext(); ) {
9
                Collection globalTypedefStatements =
10
            String inc = (String) it.next();
10
                    findTagValues(cls, "typedef_global_header");
11
            sb.append("#include <");
11
                if (!globalTypedefStatements.isEmpty()) {
12
            sb.append(inc).append('>').append(LINE_SEPARATOR);
12
                    sb.append("// global type definitions for header defined "
13
        }
13
                              + "by Tag entries in ArgoUML");
14
        // separate external from local headers
14
                    sb.append(LINE_SEPARATOR);
15
        if (extInc.size() > 0) sb.append(LINE_SEPARATOR);
15
                    sb.append("// Result: typedef <typedef_global_header> "
16
        for (Iterator it = localInc.iterator(); it.hasNext(); ) {
16
                              + "<tag_value>;");
17
            String inc = (String) it.next();
17
                    sb.append(LINE_SEPARATOR);
18
            sb.append("#include \"").append(inc).append("\"" + LINE_SEPARATOR);
18
                    Iterator typedefEnum =
19
        }
19
                        globalTypedefStatements.iterator();
20
        return sb;
20
                    while (typedefEnum.hasNext()) {
21
    }
21
                        sb.append("typedef ").append(typedefEnum.next());
22
                        sb.append(";").append(LINE_SEPARATOR);
23
                    }
24
                }
25
            }
26
            else {
27
                Collection globalTypedefStatements =
28
                    findTagValues(cls, "typedef_global_source");
29
                if (!globalTypedefStatements.isEmpty()) {
30
                    sb.append("// global type definitions for class "
31
                            + "implementation in source file defined by Tag "
32
                            + "entries in ArgoUML");
33
                    sb.append(LINE_SEPARATOR);
34
                    sb.append("// Result: typedef <typedef_global_source> "
35
                            + "<tag_value>;");
36
                    sb.append(LINE_SEPARATOR);
37
                    Iterator typedefEnum = globalTypedefStatements.iterator();
38
                    while (typedefEnum.hasNext()) {
39
                        sb.append("typedef ").append(typedefEnum.next());
40
                        sb.append(";").append(LINE_SEPARATOR);
41
                    }
42
                }
43
            }
44
        }
45
        return sb;
46
    }
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements4
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment1
    Time elapsed for statement mapping (ms)0.0
    Similarity Score0.500
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    1
    for (Iterator it = systemInc.iterator(); it.hasNext(); )
    1
    for (Iterator it = systemInc.iterator(); it.hasNext(); )
    11
    while (typedefEnum.hasNext())
    Differences
    Expression1Expression2Difference
    ittypedefEnumVARIABLE_NAME_MISMATCH
    java.util.Setjava.util.CollectionVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.util.Set of variable systemInc does not match with type java.util.Collection of variable globalTypedefStatements
    • Make classes java.util.Set and java.util.Collection extend a common superclass
    11
    while (typedefEnum.hasNext())
    2
    String inc = (String)it.next();
                                                                    
                                                                                                              
    12
    sb.append("typedef ").append(typedefEnum.next());
    3
    sb.append("#include <");
    3
    sb.append("#include <");
    13
    sb.append(";").append(LINE_SEPARATOR);
    Differences
    Expression1Expression2Difference
    "#include <"LINE_SEPARATORTYPE_COMPATIBLE_REPLACEMENT
    sbsb.append(";")TYPE_COMPATIBLE_REPLACEMENT
    13
    sb.append(";").append(LINE_SEPARATOR);
    4
    sb.append(inc).append('>').append(LINE_SEPARATOR);
    4
    sb.append(inc).append('>').append(LINE_SEPARATOR);
    Preondition Violations
    Unmatched statement sb.append(inc).append('>').append(LINE_SEPARATOR); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                              
    Precondition Violations (3)
    Row Violation
    1Type java.util.Set of variable systemInc does not match with type java.util.Collection of variable globalTypedefStatements
    2Unmatched statement sb.append(inc).append('>').append(LINE_SEPARATOR); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Clone fragment #1 returns variables inc , while Clone fragment #2 returns variables