public Object findClassifierByName(Object ofs, String s) { if (!(ofs instanceof ObjectFlowState)) { throw new IllegalArgumentException(); } CompositeState cs = ((ObjectFlowState) ofs).getContainer(); StateMachine sm = cs.getStateMachine(); ModelElement ns = sm.getContext(); if (ns == null) { return null; } if (!(ns instanceof Namespace)) { ns = ns.getNamespace(); } if (ns != null) { Collection c = Model.getModelManagementHelper().getAllModelElementsOfKind( ns, Model.getMetaTypes().getClassifier()); Iterator i = c.iterator(); while (i.hasNext()) { ModelElement classifier = (ModelElement) i.next(); String cn = classifier.getName(); if (cn != null && cn.equals(s)) { return classifier; } } } else { throw new IllegalArgumentException(); } return null; }
/** * Finds a type in a model by name * * @param s the type name * @param model the model * @return the type or <code>null</code> if the type has not been found. */ public static Object findTypeInModel(String s, Object model) { if (!Model.getFacade().isANamespace(model)) { throw new IllegalArgumentException( "Looking for the classifier " + s + " in a non-namespace object of " + model + ". A namespace was expected."); } Collection allClassifiers = Model.getModelManagementHelper() .getAllModelElementsOfKind(model, Model.getMetaTypes().getClassifier()); for (Object classifier : allClassifiers) { if (Model.getFacade().getName(classifier) != null && Model.getFacade().getName(classifier).equals(s)) { return classifier; } } return null; }
Clone fragments detected by clone detection tool
File path: /ArgoUML-0.34-src/argouml/src/argouml-core-model-mdr/src/org/argouml/model/mdr/ActivityGraphsHelperMDRImpl.java File path: /ArgoUML-0.34-src/argouml/src/argouml-app/src/org/argouml/profile/internal/ModelUtils.java
Method name: Object findClassifierByName(Object, String) Method name: Object findTypeInModel(String, Object)
Number of AST nodes: 5 Number of AST nodes: 3
1
public Object findClassifierByName(Object ofs, String s) {
1
/**
2
        if (!(ofs instanceof ObjectFlowState)) {
2
     * Finds a type in a model by name
3
            throw new IllegalArgumentException();
3
     * 
4
        }
4
     * @param s the type name
5
5
     * @param model the model
6
        CompositeState cs = ((ObjectFlowState) ofs).getContainer();
6
     * @return the type or <code>null</code> if the type has not been found.
7
        StateMachine sm = cs.getStateMachine();
7
     */
8
        ModelElement ns = sm.getContext();
8
    public static Object findTypeInModel(String s, Object model) {
9
        if (ns == null) {
9
10
            return null;
10
        if (!Model.getFacade().isANamespace(model)) {
11
        }
11
            throw new IllegalArgumentException(
12
        if (!(ns instanceof Namespace)) {
12
                    "Looking for the classifier " + s
13
            ns = ns.getNamespace();
13
                    + " in a non-namespace object of " + model
14
        }
14
                    + ". A namespace was expected.");
15
        if (ns != null) {
15
        }
16
            Collection c =
16
17
                Model.getModelManagementHelper().getAllModelElementsOfKind(
17
        Collection allClassifiers =
18
                    ns, Model.getMetaTypes().getClassifier());
18
            Model.getModelManagementHelper()
19
            Iterator i = c.iterator();
19
                .getAllModelElementsOfKind(model,
20
            while (i.hasNext()) {
20
                        Model.getMetaTypes().getClassifier());
21
                ModelElement classifier = (ModelElement) i.next();
21
22
                String cn = classifier.getName();
22
        for (Object classifier : allClassifiers) {
23
                if (cn != null && cn.equals(s)) {
23
            if (Model.getFacade().getName(classifier) != null
24
                    return classifier;
24
                        && Model.getFacade().getName(classifier).equals(s)) {
25
                }
25
                return classifier;
26
            }
26
            }
27
        } else {
27
        }
28
            throw new IllegalArgumentException();
28
29
        }
29
        return null;
30
        return null;
30
    }
31
    }
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements4
    Number of unmapped statements in the first code fragment2
    Number of unmapped statements in the second code fragment1
    Time elapsed for statement mapping (ms)0.0
    Similarity Score0.333
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    13
    while (i.hasNext())
    4
    for (Object classifier : allClassifiers)
    14
    ModelElement classifier = (ModelElement)i.next();
                                                                                                          
    15
    String cn = classifier.getName();
    15
    String cn = classifier.getName();
    Preondition Violations
    Unmatched statement String cn=classifier.getName(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                          
    16
    if (cn != null && cn.equals(s))
    16
    if (cn != null && cn.equals(s))
    5
    if (Model.getFacade().getName(classifier) != null && Model.getFacade().getName(classifier).equals(s))
    Differences
    Expression1Expression2Difference
    cnModel.getFacade().getName(classifier)TYPE_COMPATIBLE_REPLACEMENT
    cnModel.getFacade().getName(classifier)TYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    Expression Model.getFacade().getName(classifier) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression Model.getFacade().getName(classifier) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    5
    if (Model.getFacade().getName(classifier) != null && Model.getFacade().getName(classifier).equals(s))
                                              
    6
    return classifier;
    Preondition Violations
    Unmatched statement return classifier; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    Unmatched return classifier;
    6
    return classifier;
    17
    return classifier;
    17
    return classifier;
    Preondition Violations
    Unmatched statement return classifier; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    Unmatched return classifier;
                                                
    Precondition Violations (8)
    Row Violation
    1Unmatched statement String cn=classifier.getName(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Expression Model.getFacade().getName(classifier) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Expression Model.getFacade().getName(classifier) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4Unmatched statement return classifier; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5Unmatched return classifier;
    6Unmatched statement return classifier; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    7Unmatched return classifier;
    8Clone fragment #1 returns variable classifier with type org.omg.uml.foundation.core.ModelElement , while Clone fragment #2 returns variable classifier with type java.lang.Object