try { // Remember the file. // final IFile modelFile = getModelFile(); // Do the work within an operation. // WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { @Override protected void execute(IProgressMonitor progressMonitor) { try { // Create a resource set // ResourceSet resourceSet = new ResourceSetImpl(); // Get the URI of the model file. // URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true); // Create a resource for this file. // Resource resource = resourceSet.createResource(fileURI, Ecore2XMLPackage.eCONTENT_TYPE); // Add the initial model object to the contents. // EObject rootObject = createInitialModel(); if (rootObject != null) { resource.getContents().add(rootObject); } // Save the contents of the resource to the file system. // Map<Object, Object> options = new HashMap<Object, Object>(); options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding()); resource.save(options); } catch (Exception exception) { Ecore2XMLUIPlugin.INSTANCE.log(exception); } finally { progressMonitor.done(); } } }; getContainer().run(false, false, operation); // Select the new file resource in the current view. // IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); IWorkbenchPage page = workbenchWindow.getActivePage(); final IWorkbenchPart activePart = page.getActivePart(); if (activePart instanceof ISetSelectionTarget) { final ISelection targetSelection = new StructuredSelection(modelFile); getShell().getDisplay().asyncExec (new Runnable() { public void run() { ((ISetSelectionTarget)activePart).selectReveal(targetSelection); } }); } // Open an editor on the new file. // try { page.openEditor (new FileEditorInput(modelFile), workbench.getEditorRegistry().getDefaultEditor(modelFile.getFullPath().toString()).getId()); } catch (PartInitException exception) { MessageDialog.openError(workbenchWindow.getShell(), Ecore2XMLUIPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage()); //$NON-NLS-1$ return false; } return true; } catch (Exception exception) { Ecore2XMLUIPlugin.INSTANCE.log(exception); return false; }
try { // Remember the file. // final IFile modelFile = getModelFile(); // Do the work within an operation. // WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { @Override protected void execute(IProgressMonitor progressMonitor) { try { // Create a resource set // ResourceSet resourceSet = new ResourceSetImpl(); // Get the URI of the model file. // URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true); // Create a resource for this file. // Resource resource = resourceSet.createResource(fileURI, Ecore2EcorePackage.eCONTENT_TYPE); // Add the initial model object to the contents. // EObject rootObject = createInitialModel(); if (rootObject != null) { resource.getContents().add(rootObject); } // Save the contents of the resource to the file system. // Map<Object, Object> options = new HashMap<Object, Object>(); options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding()); resource.save(options); } catch (Exception exception) { Ecore2EcoreEditorPlugin.INSTANCE.log(exception); } finally { progressMonitor.done(); } } }; getContainer().run(false, false, operation); // Select the new file resource in the current view. // IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); IWorkbenchPage page = workbenchWindow.getActivePage(); final IWorkbenchPart activePart = page.getActivePart(); if (activePart instanceof ISetSelectionTarget) { final ISelection targetSelection = new StructuredSelection(modelFile); getShell().getDisplay().asyncExec (new Runnable() { public void run() { ((ISetSelectionTarget)activePart).selectReveal(targetSelection); } }); } // Open an editor on the new file. // try { page.openEditor (new FileEditorInput(modelFile), workbench.getEditorRegistry().getDefaultEditor(modelFile.getFullPath().toString()).getId()); } catch (PartInitException exception) { MessageDialog.openError(workbenchWindow.getShell(), Ecore2EcoreEditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage()); return false; } return true; } catch (Exception exception) { Ecore2EcoreEditorPlugin.INSTANCE.log(exception); return false; }
Clone fragments detected by clone detection tool
File path: /emf-2.4.1/src/org/eclipse/emf/mapping/ecore2xml/presentation/Ecore2XMLModelWizard.java File path: /emf-2.4.1/src/org/eclipse/emf/mapping/ecore2ecore/presentation/Ecore2EcoreModelWizard.java
Method name: boolean performFinish() Method name: boolean performFinish()
Number of AST nodes: 13 Number of AST nodes: 13
1
try
1
try
2
    {
2
    {
3
      // Remember the file.
3
      // Remember the file.
4
      //
4
      //
5
      final IFile modelFile = getModelFile();
5
      final IFile modelFile = getModelFile();
6
      // Do the work within an operation.
6
      // Do the work within an operation.
7
      //
7
      //
8
      WorkspaceModifyOperation operation =
8
      WorkspaceModifyOperation operation =
9
        new WorkspaceModifyOperation()
9
        new WorkspaceModifyOperation()
10
        {
10
        {
11
          @Override
11
          @Override
12
          protected void execute(IProgressMonitor progressMonitor)
12
          protected void execute(IProgressMonitor progressMonitor)
13
          {
13
          {
14
            try
14
            try
15
            {
15
            {
16
              // Create a resource set
16
              // Create a resource set
17
              //
17
              //
18
              ResourceSet resourceSet = new ResourceSetImpl();
18
              ResourceSet resourceSet = new ResourceSetImpl();
19
              // Get the URI of the model file.
19
              // Get the URI of the model file.
20
              //
20
              //
21
              URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true);
21
              URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true);
22
              // Create a resource for this file.
22
              // Create a resource for this file.
23
              //
23
              //
24
              Resource resource = resourceSet.createResource(fileURI, Ecore2XMLPackage.eCONTENT_TYPE);
24
              Resource resource = resourceSet.createResource(fileURI, Ecore2EcorePackage.eCONTENT_TYPE);
25
              // Add the initial model object to the contents.
25
              // Add the initial model object to the contents.
26
              //
26
              //
27
              EObject rootObject = createInitialModel();
27
              EObject rootObject = createInitialModel();
28
              if (rootObject != null)
28
              if (rootObject != null)
29
              {
29
              {
30
                resource.getContents().add(rootObject);
30
                resource.getContents().add(rootObject);
31
              }
31
              }
32
              // Save the contents of the resource to the file system.
32
              // Save the contents of the resource to the file system.
33
              //
33
              //
34
              Map<Object, Object> options = new HashMap<Object, Object>();
34
              Map<Object, Object> options = new HashMap<Object, Object>();
35
              options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding());
35
              options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding());
36
              resource.save(options);
36
              resource.save(options);
37
            }
37
            }
38
            catch (Exception exception)
38
            catch (Exception exception)
39
            {
39
            {
40
              Ecore2XMLUIPlugin.INSTANCE.log(exception);
40
              Ecore2EcoreEditorPlugin.INSTANCE.log(exception);
41
            }
41
            }
42
            finally
42
            finally
43
            {
43
            {
44
              progressMonitor.done();
44
              progressMonitor.done();
45
            }
45
            }
46
          }
46
          }
47
        };
47
        };
48
      getContainer().run(false, false, operation);
48
      getContainer().run(false, false, operation);
49
      // Select the new file resource in the current view.
49
      // Select the new file resource in the current view.
50
      //
50
      //
51
      IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
51
      IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
52
      IWorkbenchPage page = workbenchWindow.getActivePage();
52
      IWorkbenchPage page = workbenchWindow.getActivePage();
53
      final IWorkbenchPart activePart = page.getActivePart();
53
      final IWorkbenchPart activePart = page.getActivePart();
54
      if (activePart instanceof ISetSelectionTarget)
54
      if (activePart instanceof ISetSelectionTarget)
55
      {
55
      {
56
        final ISelection targetSelection = new StructuredSelection(modelFile);
56
        final ISelection targetSelection = new StructuredSelection(modelFile);
57
        getShell().getDisplay().asyncExec
57
        getShell().getDisplay().asyncExec
58
          (new Runnable()
58
          (new Runnable()
59
           {
59
           {
60
             public void run()
60
             public void run()
61
             {
61
             {
62
               ((ISetSelectionTarget)activePart).selectReveal(targetSelection);
62
               ((ISetSelectionTarget)activePart).selectReveal(targetSelection);
63
             }
63
             }
64
           });
64
           });
65
      }
65
      }
66
      // Open an editor on the new file.
66
      // Open an editor on the new file.
67
      //
67
      //
68
      try
68
      try
69
      {
69
      {
70
        page.openEditor
70
        page.openEditor
71
          (new FileEditorInput(modelFile),
71
          (new FileEditorInput(modelFile),
72
           workbench.getEditorRegistry().getDefaultEditor(modelFile.getFullPath().toString()).getId());
72
           workbench.getEditorRegistry().getDefaultEditor(modelFile.getFullPath().toString()).getId());
73
      }
73
      }
74
      catch (PartInitException exception)
74
      catch (PartInitException exception)
75
      {
75
      {
76
        MessageDialog.openError(workbenchWindow.getShell(), Ecore2XMLUIPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage()); //$NON-NLS-1$
76
        MessageDialog.openError(workbenchWindow.getShell(), Ecore2EcoreEditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage());
77
        return false;
77
        return false;
78
      }
78
      }
79
      return true;
79
      return true;
80
    }
80
    }
81
    catch (Exception exception)
81
    catch (Exception exception)
82
    {
82
    {
83
      Ecore2XMLUIPlugin.INSTANCE.log(exception);
83
      Ecore2EcoreEditorPlugin.INSTANCE.log(exception);
84
      return false;
84
      return false;
85
    }
85
    }
Summary
Number of common nesting structure subtrees1
Number of refactorable cases0
Number of non-refactorable cases1
Time elapsed for finding largest common nesting structure subtrees (ms)1.0
Clones locationClones are in different classes having the same super class
Number of node comparisons84
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements13
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)9.3
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    1
    try
    1
    try
    1
    try
    Differences
    Expression1Expression2Difference
    org.eclipse.emf.mapping.ecore2xml.ui.Ecore2XMLUIPluginorg.eclipse.emf.mapping.ecore2ecore.presentation.Ecore2EcoreEditorPluginSUBCLASS_TYPE_MISMATCH
    1
    try
    2
    final IFile modelFile = getModelFile();
    2
    final IFile modelFile = getModelFile();
    3
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {...};
    3
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {...};
    3
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {...};
    Differences
    Expression1Expression2Difference
    org.eclipse.emf.mapping.ecore2xml.Ecore2XMLPackageorg.eclipse.emf.mapping.ecore2ecore.Ecore2EcorePackageVARIABLE_TYPE_MISMATCH
    org.eclipse.emf.mapping.ecore2xml.presentation.Ecore2XMLModelWizard.Ecore2XMLModelWizardInitialObjectCreationPageorg.eclipse.emf.mapping.ecore2ecore.presentation.Ecore2EcoreModelWizard.Ecore2EcoreModelWizardInitialObjectCreationPageSUBCLASS_TYPE_MISMATCH
    org.eclipse.emf.mapping.ecore2xml.ui.Ecore2XMLUIPluginorg.eclipse.emf.mapping.ecore2ecore.presentation.Ecore2EcoreEditorPluginSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Type org.eclipse.emf.mapping.ecore2xml.Ecore2XMLPackage of variable Ecore2XMLPackage does not match with type org.eclipse.emf.mapping.ecore2ecore.Ecore2EcorePackage of variable Ecore2EcorePackage
    • Make classes org.eclipse.emf.mapping.ecore2xml.Ecore2XMLPackage and org.eclipse.emf.mapping.ecore2ecore.Ecore2EcorePackage extend a common superclass
    Expression initialObjectCreationPage cannot be unified with expression initialObjectCreationPage , because common superclass org.eclipse.jface.wizard.WizardPage does not declare member(s) public java.lang.String getEncoding()
    3
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {...};
    4
    getContainer().run(false, false, operation);
    4
    getContainer().run(false, false, operation);
    5
    IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
    5
    IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
    6
    IWorkbenchPage page = workbenchWindow.getActivePage();
    6
    IWorkbenchPage page = workbenchWindow.getActivePage();
    7
    final IWorkbenchPart activePart = page.getActivePart();
    7
    final IWorkbenchPart activePart = page.getActivePart();
    8
    if (activePart instanceof ISetSelectionTarget)
    8
    if (activePart instanceof ISetSelectionTarget)
    9
    final ISelection targetSelection = new StructuredSelection(modelFile);
    9
    final ISelection targetSelection = new StructuredSelection(modelFile);
    10
    getShell().getDisplay().asyncExec(new Runnable() {...});
    10
    getShell().getDisplay().asyncExec(new Runnable() {...});
    11
    try
    11
    try
    11
    try
    Differences
    Expression1Expression2Difference
    org.eclipse.emf.mapping.ecore2xml.ui.Ecore2XMLUIPluginorg.eclipse.emf.mapping.ecore2ecore.presentation.Ecore2EcoreEditorPluginSUBCLASS_TYPE_MISMATCH
    11
    try
    12
    page.openEditor(new FileEditorInput(modelFile), workbench.getEditorRegistry().getDefaultEditor(modelFile.getFullPath().toString()).getId());
    12
    page.openEditor(new FileEditorInput(modelFile), workbench.getEditorRegistry().getDefaultEditor(modelFile.getFullPath().toString()).getId());
    13
    return true;
    13
    return true;
    Precondition Violations (2)
    Row Violation
    1Type org.eclipse.emf.mapping.ecore2xml.Ecore2XMLPackage of variable Ecore2XMLPackage does not match with type org.eclipse.emf.mapping.ecore2ecore.Ecore2EcorePackage of variable Ecore2EcorePackage
    2Expression initialObjectCreationPage cannot be unified with expression initialObjectCreationPage , because common superclass org.eclipse.jface.wizard.WizardPage does not declare member(s) public java.lang.String getEncoding()