public void actionPerformed(ActionEvent e) { super.actionPerformed(e); Object t = TargetManager.getInstance().getModelTarget(); Object owner = null; Object namespace = null; if (Model.getFacade().isAStereotype(t)) { owner = t; } else if (Model.getFacade().isAPackage(t)) { namespace = t; } else { namespace = Model.getFacade().getInnerContainingModel(t); } Object newTagDefinition = null; if (Model.getFacade().getUmlVersion().charAt(0) == '1') { newTagDefinition = Model.getExtensionMechanismsFactory() .buildTagDefinition((String) null, owner, namespace); } else { Object type = null; for (Object aType : Model.getExtensionMechanismsHelper() .getCommonTaggedValueTypes()) { if ("String".equals(Model.getFacade().getName(aType))) { type = aType; break; } } newTagDefinition = Model.getCoreFactory().buildAttribute2(t, type); } TargetManager.getInstance().setTarget(newTagDefinition); super.actionPerformed(e); }
/** * 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/src/argouml-app/src/org/argouml/uml/ui/foundation/extension_mechanisms/ActionNewTagDefinition.java File path: /ArgoUML-0.34-src/argouml-cpp/src/org/argouml/language/cpp/reveng/XtorModeler.java
Method name: void actionPerformed(ActionEvent) Method name: Object getStereotype(Object, String)
Number of AST nodes: 4 Number of AST nodes: 5
1
public void actionPerformed(ActionEvent e) {
1
/**
2
        super.actionPerformed(e);
2
     * Helper method that gets a stereotype for the given model
3
        Object t = TargetManager.getInstance().getModelTarget();
3
     * element with the given name.
4
        Object owner = null;
4
     *
5
        Object namespace = null;
5
     * TODO: this might be a performance bottleneck. If so, caching of
6
        if (Model.getFacade().isAStereotype(t)) {
6
     * stereotypes for model elements by their stereotypes names could fix it.
7
            owner = t;
7
     *
8
        } else if (Model.getFacade().isAPackage(t)) {
8
     * @param modelElement The model element for which to look for the
9
            namespace = t;
9
     *            stereotype with the given name
10
        } else {
10
     * @param stereotypeName The name of the stereotype.
11
            namespace = Model.getFacade().getInnerContainingModel(t);
11
     * @return the stereotype model element or null if not found.
12
        }
12
     */
13
        Object newTagDefinition = null;
13
    private Object getStereotype(Object modelElement, String stereotypeName) {
14
        if (Model.getFacade().getUmlVersion().charAt(0) == '1') {
14
        Object stereotype = null;
15
            newTagDefinition = Model.getExtensionMechanismsFactory()
15
        Collection stereotypes = StereotypeUtility.getAvailableStereotypes(
16
                .buildTagDefinition((String) null, owner, namespace);
16
                modelElement);
17
        } else {
17
        for (Iterator it = stereotypes.iterator(); it.hasNext();) {
18
            Object type = null;
18
            Object candidateStereotype = it.next();
19
            for (Object aType : Model.getExtensionMechanismsHelper()
19
            if (getFacade().getName(candidateStereotype).equals(
20
                    .getCommonTaggedValueTypes()) {
20
                stereotypeName)) {
21
                if ("String".equals(Model.getFacade().getName(aType))) {
21
                stereotype = candidateStereotype;
22
                    type = aType;
22
                break;
23
                    break;
23
            }
24
                }
24
        }
25
            }
25
        return stereotype;
26
            newTagDefinition = Model.getCoreFactory().buildAttribute2(t, type);
26
    }
27
        }
28
        TargetManager.getInstance().setTarget(newTagDefinition);
29
        super.actionPerformed(e);
30
    }
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements5
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)0.0
    Similarity Score0.833
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    14
    for (Object aType : Model.getExtensionMechanismsHelper().getCommonTaggedValueTypes())
    14
    for (Object aType : Model.getExtensionMechanismsHelper().getCommonTaggedValueTypes())
    3
    for (Iterator it = stereotypes.iterator(); it.hasNext(); )
    Differences
    Expression1Expression2Difference
    aTypecandidateStereotypeVARIABLE_NAME_MISMATCH
    Model.getExtensionMechanismsHelper().getCommonTaggedValueTypes()stereotypesTYPE_COMPATIBLE_REPLACEMENT
    3
    for (Iterator it = stereotypes.iterator(); it.hasNext(); )
                                                                                    
    4
    Object candidateStereotype = it.next();
    Differences
    Expression1Expression2Difference
    aTypecandidateStereotypeVARIABLE_NAME_MISMATCH
    4
    Object candidateStereotype = it.next();
    15
    if ("String".equals(Model.getFacade().getName(aType)))
    15
    if ("String".equals(Model.getFacade().getName(aType)))
    5
    if (getFacade().getName(candidateStereotype).equals(stereotypeName))
    Differences
    Expression1Expression2Difference
    Model.getFacade().getName(aType)stereotypeNameTYPE_COMPATIBLE_REPLACEMENT
    "String"getFacade().getName(candidateStereotype)TYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    Expression Model.getFacade().getName(aType) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    5
    if (getFacade().getName(candidateStereotype).equals(stereotypeName))
    16
    type = aType;
    16
    type = aType;
    6
    stereotype = candidateStereotype;
    Differences
    Expression1Expression2Difference
    typestereotypeVARIABLE_NAME_MISMATCH
    aTypecandidateStereotypeVARIABLE_NAME_MISMATCH
    6
    stereotype = candidateStereotype;
    17
    break;
    7
    break;
    Precondition Violations (1)
    Row Violation
    1Expression Model.getFacade().getName(aType) cannot be parameterized, because it has dependencies to/from statements that will be extracted