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); }
/** * Search the attribute named <code>attributeName</code> in the given * relation. If there exist more than one attribute the first one is * returned. * * @param relation * The relation in which to search the attribute. * @param attributeName * The name of the attribute to search. * @return The attribute if found, <code>null</code> else. */ public static Object getAttributeForName(Object relation, String attributeName) { Object attribute = null; Collection attributes = Model.getFacade().getAttributes(relation); for (Iterator it = attributes.iterator(); it.hasNext();) { Object attr = it.next(); if (Model.getFacade().getName(attr).equals(attributeName)) { attribute = attr; break; } } return attribute; }
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-sql/src/org/argouml/language/sql/Utils.java
Method name: void actionPerformed(ActionEvent) Method name: Object getAttributeForName(Object, String)
Number of AST nodes: 4 Number of AST nodes: 5
1
public void actionPerformed(ActionEvent e) {
1
/**
2
        super.actionPerformed(e);
2
     * Search the attribute named <code>attributeName</code> in the given
3
        Object t = TargetManager.getInstance().getModelTarget();
3
     * relation. If there exist more than one attribute the first one is
4
        Object owner = null;
4
     * returned.
5
        Object namespace = null;
5
     * 
6
        if (Model.getFacade().isAStereotype(t)) {
6
     * @param relation
7
            owner = t;
7
     *            The relation in which to search the attribute.
8
        } else if (Model.getFacade().isAPackage(t)) {
8
     * @param attributeName
9
            namespace = t;
9
     *            The name of the attribute to search.
10
        } else {
10
     * @return The attribute if found, <code>null</code> else.
11
            namespace = Model.getFacade().getInnerContainingModel(t);
11
     */
12
        }
12
    public static Object getAttributeForName(Object relation,
13
        Object newTagDefinition = null;
13
            String attributeName) {
14
        if (Model.getFacade().getUmlVersion().charAt(0) == '1') {
14
        Object attribute = null;
15
            newTagDefinition = Model.getExtensionMechanismsFactory()
15
16
                .buildTagDefinition((String) null, owner, namespace);
16
        Collection attributes = Model.getFacade().getAttributes(relation);
17
        } else {
17
        for (Iterator it = attributes.iterator(); it.hasNext();) {
18
            Object type = null;
18
            Object attr = it.next();
19
            for (Object aType : Model.getExtensionMechanismsHelper()
19
            if (Model.getFacade().getName(attr).equals(attributeName)) {
20
                    .getCommonTaggedValueTypes()) {
20
                attribute = attr;
21
                if ("String".equals(Model.getFacade().getName(aType))) {
21
                break;
22
                    type = aType;
22
            }
23
                    break;
23
        }
24
                }
24
25
            }
25
        return attribute;
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 Score1.000
    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 = attributes.iterator(); it.hasNext(); )
    Differences
    Expression1Expression2Difference
    aTypeattrVARIABLE_NAME_MISMATCH
    Model.getExtensionMechanismsHelper().getCommonTaggedValueTypes()attributesTYPE_COMPATIBLE_REPLACEMENT
    3
    for (Iterator it = attributes.iterator(); it.hasNext(); )
                                                      
    4
    Object attr = it.next();
    Differences
    Expression1Expression2Difference
    aTypeattrVARIABLE_NAME_MISMATCH
    4
    Object attr = it.next();
    15
    if ("String".equals(Model.getFacade().getName(aType)))
    15
    if ("String".equals(Model.getFacade().getName(aType)))
    5
    if (Model.getFacade().getName(attr).equals(attributeName))
    Differences
    Expression1Expression2Difference
    Model.getFacade().getName(aType)attributeNameTYPE_COMPATIBLE_REPLACEMENT
    "String"Model.getFacade().getName(attr)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 (Model.getFacade().getName(attr).equals(attributeName))
    16
    type = aType;
    16
    type = aType;
    6
    attribute = attr;
    Differences
    Expression1Expression2Difference
    typeattributeVARIABLE_NAME_MISMATCH
    aTypeattrVARIABLE_NAME_MISMATCH
    6
    attribute = attr;
    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