public static Object getTagDefinition(String tdName) { // look for it in all the models Collection models = getModels(); for (Object model : models) { Collection tagDefinitions = getModelManagementHelper(). getAllModelElementsOfKindWithModel(model, Model.getMetaTypes().getTagDefinition()); for (Object td : tagDefinitions) { if (tdName.equals(getFacade().getName(td))) { return td; } } } // create it in an editable model if one is found Collection editableModels = getEditableModels(); Iterator it = editableModels.iterator(); if (it.hasNext()) { return getExtensionMechanismsFactory().buildTagDefinition(tdName, null, it.next()); } throw new IllegalStateException("Unable to find an editable model."); }
/** * Helper method that gets a stereotype for the given model * element with the given name. * * TODO: this might be a performance bottleneck. If so, caching of * stereotypes for model elements by their stereotypes names could fix it. * * @param modelElement The model element for which to look for the * stereotype with the given name * @param stereotypeName The name of the stereotype. * @return the stereotype model element or null if not found. */ private Object getStereotype(Object modelElement, String stereotypeName) { Object stereotype = null; Collection stereotypes = StereotypeUtility.getAvailableStereotypes( modelElement); for (Iterator it = stereotypes.iterator(); it.hasNext();) { Object candidateStereotype = it.next(); if (getFacade().getName(candidateStereotype).equals( stereotypeName)) { stereotype = candidateStereotype; break; } } return stereotype; }
Clone fragments detected by clone detection tool
File path: /ArgoUML-0.34-src/argouml-cpp/src/org/argouml/language/cpp/profile/BaseProfile.java File path: /ArgoUML-0.34-src/argouml-cpp/src/org/argouml/language/cpp/reveng/XtorModeler.java
Method name: Object getTagDefinition(String) Method name: Object getStereotype(Object, String)
Number of AST nodes: 3 Number of AST nodes: 5
1
public static Object getTagDefinition(String tdName) {
1
/**
2
        // look for it in all the models
2
     * Helper method that gets a stereotype for the given model
3
        Collection models = getModels();
3
     * element with the given name.
4
        for (Object model : models) {
4
     *
5
            Collection tagDefinitions = getModelManagementHelper().
5
     * TODO: this might be a performance bottleneck. If so, caching of
6
                getAllModelElementsOfKindWithModel(model, 
6
     * stereotypes for model elements by their stereotypes names could fix it.
7
                    Model.getMetaTypes().getTagDefinition());
7
     *
8
            for (Object td : tagDefinitions) {
8
     * @param modelElement The model element for which to look for the
9
                if (tdName.equals(getFacade().getName(td))) {
9
     *            stereotype with the given name
10
                    return td;
10
     * @param stereotypeName The name of the stereotype.
11
                }
11
     * @return the stereotype model element or null if not found.
12
            }
12
     */
13
        }
13
    private Object getStereotype(Object modelElement, String stereotypeName) {
14
        // create it in an editable model if one is found
14
        Object stereotype = null;
15
        Collection editableModels = getEditableModels();
15
        Collection stereotypes = StereotypeUtility.getAvailableStereotypes(
16
        Iterator it = editableModels.iterator();
16
                modelElement);
17
        if (it.hasNext()) {
17
        for (Iterator it = stereotypes.iterator(); it.hasNext();) {
18
            return getExtensionMechanismsFactory().buildTagDefinition(tdName, 
18
            Object candidateStereotype = it.next();
19
                null, it.next());
19
            if (getFacade().getName(candidateStereotype).equals(
20
        }
20
                stereotypeName)) {
21
        throw new IllegalStateException("Unable to find an editable model.");
21
                stereotype = candidateStereotype;
22
    }
22
                break;
23
            }
24
        }
25
        return stereotype;
26
    }
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements3
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment2
    Time elapsed for statement mapping (ms)0.0
    Similarity Score1.000
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    4
    for (Object td : tagDefinitions)
    4
    for (Object td : tagDefinitions)
    3
    for (Iterator it = stereotypes.iterator(); it.hasNext(); )
    Differences
    Expression1Expression2Difference
    tdcandidateStereotypeVARIABLE_NAME_MISMATCH
    3
    for (Iterator it = stereotypes.iterator(); it.hasNext(); )
                                                                                    
    4
    Object candidateStereotype = it.next();
    Differences
    Expression1Expression2Difference
    tdcandidateStereotypeVARIABLE_NAME_MISMATCH
    4
    Object candidateStereotype = it.next();
    5
    if (tdName.equals(getFacade().getName(td)))
    5
    if (tdName.equals(getFacade().getName(td)))
    5
    if (getFacade().getName(candidateStereotype).equals(stereotypeName))
    Differences
    Expression1Expression2Difference
    getFacade().getName(td)stereotypeNameTYPE_COMPATIBLE_REPLACEMENT
    tdNamegetFacade().getName(candidateStereotype)TYPE_COMPATIBLE_REPLACEMENT
    5
    if (getFacade().getName(candidateStereotype).equals(stereotypeName))
                                                                        
    6
    stereotype = candidateStereotype;
    Preondition Violations
    Unmatched statement stereotype=candidateStereotype; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6
    stereotype = candidateStereotype;
    6
    return td;
    6
    return td;
    Preondition Violations
    Unmatched statement return td; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    Unmatched return td;
                              
                      
    7
    break;
    Preondition Violations
    Unmatched break;
    7
    break;
    Precondition Violations (4)
    Row Violation
    1Unmatched statement stereotype=candidateStereotype; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Unmatched statement return td; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Unmatched return td;
    4Unmatched break;