private String generateClassifierAttributes(Object modelElement) { if (!Model.getFacade().isAClassifier(modelElement)) { throw new ClassCastException(modelElement.getClass() + " has wrong object type, Classifier required"); } String sClsAttr = ""; if (Model.getFacade().isAClass(modelElement)) { sClsAttr += INDENT + "// --- ATTRIBUTES ---\n"; Collection colAttributes = Model.getFacade().getAttributes(modelElement); if (colAttributes != null) { Iterator itAttributes = colAttributes.iterator(); while (itAttributes.hasNext()) { Object attr = itAttributes.next(); sClsAttr += "\n"; PHPDocumentor objPHPDoc = null; try { objPHPDoc = new PHPDocumentor(attr); } catch (Exception exp) { LOG.error("Generating attribute DocBlock FAILED: " + exp.getMessage()); } finally { if (objPHPDoc != null) { sClsAttr += objPHPDoc.toString(INDENT); } } sClsAttr += INDENT + generateAttribute(attr, false) + "\n"; } } sClsAttr += "\n"; } return sClsAttr; }
private String generateClassifierOperations(Object modelElement) { if (!Model.getFacade().isAClassifier(modelElement)) { throw new ClassCastException(modelElement.getClass() + " has wrong object type, Classifier required"); } String sClsOp = ""; sClsOp += INDENT + "// --- OPERATIONS ---\n"; /* generate constructor */ Object objTaggedValue = Model.getFacade().getTaggedValue(modelElement, "constructor"); if (objTaggedValue != null) { String sTaggedValueConstructor = Model.getFacade().getValueOfTag(objTaggedValue); if (sTaggedValueConstructor != null && sTaggedValueConstructor.equals("true")) { if (findConstructor(modelElement) == null) { String sConstructor = null; if (iLanguageMajorVersion < 5) { sConstructor = "function " + NameGenerator.generate( modelElement, iLanguageMajorVersion); } else { sConstructor = "public function __construct"; } sClsOp += "\n"; sClsOp += INDENT + "/**\n"; sClsOp += INDENT + " * Class constructor\n"; sClsOp += INDENT + " *\n"; sClsOp += INDENT + " * @access public\n"; sClsOp += INDENT + " *\n"; sClsOp += INDENT + " * @return void\n"; sClsOp += INDENT + " *\n"; sClsOp += INDENT + " * @author ArgoUML PHP Module" + " (revised $Date: 2010-01-12 20:15:17 +0100 (Tue, 12 Jan 2010) $)\n"; sClsOp += INDENT + " */\n"; sClsOp += INDENT + sConstructor + "()\n"; sClsOp += INDENT + "{\n"; sClsOp += generateSection(modelElement, INDENT, sConstructor.substring(sConstructor.lastIndexOf(" "))); sClsOp += INDENT + "}\n"; } } } if (Model.getFacade().isAClass(modelElement)) { for (Object spec : Model.getFacade() .getSpecifications(modelElement)) { for (Object operation : Model.getFacade().getOperations(spec)) { sClsOp += "\n"; PHPDocumentor objPHPDoc = null; try { objPHPDoc = new PHPDocumentor(operation); } catch (Exception exp) { LOG.error("Generating operation DocBlock " + "FAILED: " + exp.getMessage()); } finally { if (objPHPDoc != null) { sClsOp += objPHPDoc.toString(INDENT); } } sClsOp += INDENT + generateOperation(operation, false); sClsOp += generateMethodBody(operation, true); } } } for (Object operation : Model.getFacade().getOperations(modelElement)) { sClsOp += "\n"; PHPDocumentor objPHPDoc = null; try { objPHPDoc = new PHPDocumentor(operation); } catch (Exception exp) { LOG.error("Generating operation DocBlock FAILED: " + exp.getMessage()); } finally { if (objPHPDoc != null) { sClsOp += objPHPDoc.toString(INDENT); } } sClsOp += INDENT + generateOperation(operation, false); if (Model.getFacade().isAClass(modelElement)) { sClsOp += generateMethodBody(operation, false); } else { if (iLanguageMajorVersion < 5) { sClsOp += "\n" + INDENT + "{\n"; sClsOp += INDENT + INDENT + "die('abstract method called');\n"; sClsOp += INDENT + "}\n"; } else { sClsOp += ";\n"; } } } return sClsOp; }
Clone fragments detected by clone detection tool
File path: /ArgoUML-0.34-src/argouml-php/src/org/argouml/language/php/generator/GeneratorPHP4.java File path: /ArgoUML-0.34-src/argouml-php/src/org/argouml/language/php/generator/GeneratorPHP4.java
Method name: String generateClassifierAttributes(Object) Method name: String generateClassifierOperations(Object)
Number of AST nodes: 6 Number of AST nodes: 6
1
private String generateClassifierAttributes(Object modelElement) {
1
private String generateClassifierOperations(Object modelElement) {
2
        if (!Model.getFacade().isAClassifier(modelElement)) {
2
        if (!Model.getFacade().isAClassifier(modelElement)) {
3
            throw new ClassCastException(modelElement.getClass()
3
            throw new ClassCastException(modelElement.getClass()
4
                    + " has wrong object type, Classifier required");
4
                    + " has wrong object type, Classifier required");
5
        }
5
        }
6
6
7
        String sClsAttr = "";
7
        String sClsOp = "";
8
8
9
        if (Model.getFacade().isAClass(modelElement)) {
9
        sClsOp += INDENT + "// --- OPERATIONS ---\n";
10
            sClsAttr += INDENT + "// --- ATTRIBUTES ---\n";
10
11
11
        /* generate constructor */
12
            Collection colAttributes =
12
        Object objTaggedValue =
13
                Model.getFacade().getAttributes(modelElement);
13
            Model.getFacade().getTaggedValue(modelElement, "constructor");
14
14
        if (objTaggedValue != null) {
15
            if (colAttributes != null) {
15
            String sTaggedValueConstructor =
16
                Iterator itAttributes = colAttributes.iterator();
16
                Model.getFacade().getValueOfTag(objTaggedValue);
17
                while (itAttributes.hasNext()) {
17
18
                    Object attr = itAttributes.next();
18
            if (sTaggedValueConstructor != null
19
19
                    && sTaggedValueConstructor.equals("true")) {
20
                    sClsAttr += "\n";
20
                if (findConstructor(modelElement) == null) {
21
21
                    String sConstructor = null;
22
                    PHPDocumentor objPHPDoc = null;
22
23
                    try {
23
                    if (iLanguageMajorVersion < 5) {
24
                        objPHPDoc = new PHPDocumentor(attr);
24
                        sConstructor = "function " + NameGenerator.generate(
25
                    } catch (Exception exp) {
25
                                modelElement, iLanguageMajorVersion);
26
                        LOG.error("Generating attribute DocBlock FAILED: "
26
                    } else {
27
                                + exp.getMessage());
27
                        sConstructor = "public function __construct";
28
                    } finally {
28
                    }
29
                        if (objPHPDoc != null) {
29
30
                            sClsAttr += objPHPDoc.toString(INDENT);
30
                    sClsOp += "\n";
31
                        }
31
                    sClsOp += INDENT + "/**\n";
32
                    }
32
                    sClsOp += INDENT + " * Class constructor\n";
33
33
                    sClsOp += INDENT + " *\n";
34
                    sClsAttr += INDENT + generateAttribute(attr, false) + "\n";
34
                    sClsOp += INDENT + " * @access public\n";
35
                }
35
                    sClsOp += INDENT + " *\n";
36
            }
36
                    sClsOp += INDENT + " * @return void\n";
37
37
                    sClsOp += INDENT + " *\n";
38
            sClsAttr += "\n";
38
                    sClsOp += INDENT + " * @author ArgoUML PHP Module"
39
        }
39
                                    + " (revised $Date: 2010-01-12 20:15:17 +0100 (Tue, 12 Jan 2010) $)\n";
40
40
                    sClsOp += INDENT + " */\n";
41
        return sClsAttr;
41
42
    }
42
                    sClsOp += INDENT + sConstructor + "()\n";
43
                    sClsOp += INDENT + "{\n";
44
                    sClsOp += generateSection(modelElement, INDENT,
45
                        sConstructor.substring(sConstructor.lastIndexOf(" ")));
46
                    sClsOp += INDENT + "}\n";
47
                }
48
            }
49
        }
50
51
        if (Model.getFacade().isAClass(modelElement)) {
52
            for (Object spec : Model.getFacade()
53
                    .getSpecifications(modelElement)) {
54
                for (Object operation : Model.getFacade().getOperations(spec)) {
55
                    sClsOp += "\n";
56
57
                    PHPDocumentor objPHPDoc = null;
58
                    try {
59
                        objPHPDoc = new PHPDocumentor(operation);
60
                    } catch (Exception exp) {
61
                        LOG.error("Generating operation DocBlock " + "FAILED: "
62
                                + exp.getMessage());
63
                    } finally {
64
                        if (objPHPDoc != null) {
65
                            sClsOp += objPHPDoc.toString(INDENT);
66
                        }
67
                    }
68
69
                    sClsOp += INDENT + generateOperation(operation, false);
70
                    sClsOp += generateMethodBody(operation, true);
71
                }
72
            }
73
        }
74
75
        for (Object operation : Model.getFacade().getOperations(modelElement)) {
76
77
            sClsOp += "\n";
78
            PHPDocumentor objPHPDoc = null;
79
            try {
80
                objPHPDoc = new PHPDocumentor(operation);
81
            } catch (Exception exp) {
82
                LOG.error("Generating operation DocBlock FAILED: "
83
                        + exp.getMessage());
84
            } finally {
85
                if (objPHPDoc != null) {
86
                    sClsOp += objPHPDoc.toString(INDENT);
87
                }
88
            }
89
90
            sClsOp += INDENT + generateOperation(operation, false);
91
92
            if (Model.getFacade().isAClass(modelElement)) {
93
                sClsOp += generateMethodBody(operation, false);
94
            } else {
95
                if (iLanguageMajorVersion < 5) {
96
                    sClsOp += "\n" + INDENT + "{\n";
97
                    sClsOp += INDENT + INDENT
98
                    + "die('abstract method called');\n";
99
                    sClsOp += INDENT + "}\n";
100
                } else {
101
                    sClsOp += ";\n";
102
                }
103
            }
104
        }
105
        
106
        return sClsOp;
107
    }
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements8
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment1
    Time elapsed for statement mapping (ms)0.0
    Similarity Score0.625
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    9
    while (itAttributes.hasNext())
    9
    while (itAttributes.hasNext())
    30
    for (Object operation : Model.getFacade().getOperations(spec))
    Differences
    Expression1Expression2Difference
    attroperationVARIABLE_NAME_MISMATCH
    java.util.Collectionjava.util.ListVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.util.Collection of variable colAttributes does not match with type java.util.List of variable Model.getFacade().getOperations(spec)
    • Make classes java.util.Collection and java.util.List extend a common superclass
    30
    for (Object operation : Model.getFacade().getOperations(spec))
    10
    Object attr = itAttributes.next();
    10
    Object attr = itAttributes.next();
    Differences
    Expression1Expression2Difference
    attroperationVARIABLE_NAME_MISMATCH
                                                                            
    11
    sClsAttr += "\n";
    11
    sClsAttr += "\n";
    31
    sClsOp += "\n";
    Differences
    Expression1Expression2Difference
    sClsAttrsClsOpVARIABLE_NAME_MISMATCH
    31
    sClsOp += "\n";
    12
    PHPDocumentor objPHPDoc = null;
    32
    PHPDocumentor objPHPDoc = null;
    13
    try
    13
    try
    33
    try
    Differences
    Expression1Expression2Difference
    "Generating attribute DocBlock FAILED: ""Generating operation DocBlock "LITERAL_VALUE_MISMATCH
    exp.getMessage()"FAILED: "TYPE_COMPATIBLE_REPLACEMENT
    "Generating attribute DocBlock FAILED: " + exp.getMessage()"Generating operation DocBlock " + "FAILED: " + exp.getMessage()INFIX_EXTENDED_OPERAND_NUMBER_MISMATCH
    sClsAttrsClsOpVARIABLE_NAME_MISMATCH
    33
    try
    14
    objPHPDoc = new PHPDocumentor(attr);
    14
    objPHPDoc = new PHPDocumentor(attr);
    34
    objPHPDoc = new PHPDocumentor(operation);
    Differences
    Expression1Expression2Difference
    attroperationVARIABLE_NAME_MISMATCH
    34
    objPHPDoc = new PHPDocumentor(operation);
                                                                                                                    
    35
    sClsOp += INDENT + generateOperation(operation, false);
    Preondition Violations
    Unmatched statement sClsOp+=INDENT + generateOperation(operation,false); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    35
    sClsOp += INDENT + generateOperation(operation, false);
    15
    sClsAttr += INDENT + generateAttribute(attr, false) + "\n";
    15
    sClsAttr += INDENT + generateAttribute(attr, false) + "\n";
    36
    sClsOp += generateMethodBody(operation, true);
    Differences
    Expression1Expression2Difference
    sClsAttrsClsOpVARIABLE_NAME_MISMATCH
    INDENT + generateAttribute(attr,false) + "\n"generateMethodBody(operation,true)TYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    Expression generateMethodBody(operation,true) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    • Inline private method generateMethodBody
    36
    sClsOp += generateMethodBody(operation, true);
    Precondition Violations (4)
    Row Violation
    1Type java.util.Collection of variable colAttributes does not match with type java.util.List of variable Model.getFacade().getOperations(spec)
    2Unmatched statement sClsOp+=INDENT + generateOperation(operation,false); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Expression generateMethodBody(operation,true) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4Clone fragment #1 returns variables sClsAttr , while Clone fragment #2 returns variables operation, sClsOp