Source:
private static IFolder getOutputFolder( EObject eobj ) { String projectName = ProjectUtils.getProjectName( eobj ); projectName = projectName + "_CDTProject"; IWorkspaceRoot workspace = ResourcesPlugin.getWorkspace().getRoot(); String rootPath = workspace.getLocation().toOSString(); IProject project = workspace.getProject( projectName ); if (project.exists()) { if (regenerate) { try { project.delete( true, true, null ); } catch (CoreException e) { } } } if (!project.exists()) { boolean result = new CppProjectGenerator().generate( rootPath, projectName ); if (!result) { CodeGenPlugin.error( "Failed to create output project" ); return null; } try { IProjectDescription description = ResourcesPlugin .getWorkspace() .loadProjectDescription( new org.eclipse.core.runtime.Path( rootPath + "/" + projectName + "/.project" ) ); project = ResourcesPlugin.getWorkspace().getRoot() .getProject( description.getName() ); project.create( description, null ); } catch (CoreException e1) { CodeGenPlugin.error( "Failed to create output project" ); } } if (!project.isOpen()) { try { project.open( new NullProgressMonitor() ); } catch (CoreException e) { CodeGenPlugin.error( "Failed to open project" ); } } IFolder folder = project.getFolder( "src" ); try { folder.refreshLocal( IResource.DEPTH_ZERO, null ); } catch (CoreException e) { CodeGenPlugin.error( "could not refresh output folder", e ); } if (!folder.exists()) try { folder.create( true, true, null ); } catch (CoreException e) { CodeGenPlugin.error( "could not create output folder", e ); } return folder; }

Target:
private static IFolder getOutputFolder( EObject eobj ) { String projectName = ProjectUtils.getProjectName( eobj ); projectName = projectName + "_CDTProject"; IWorkspaceRoot workspace = ResourcesPlugin.getWorkspace().getRoot(); String rootPath = workspace.getLocation().toOSString(); IProject project = workspace.getProject( projectName ); if (project.exists()) { if (regenerate) { try { project.delete( true, true, null ); } catch (CoreException e) { CodeGenPlugin.error( "Failed to delete the previously generated project" ); } } } if (!project.exists()) { boolean result = new CppProjectGenerator().generate( rootPath, projectName ); if (!result) { CodeGenPlugin.error( "Failed to create output project" ); return null; } try { IProjectDescription description = ResourcesPlugin .getWorkspace() .loadProjectDescription( new org.eclipse.core.runtime.Path( rootPath + "/" + projectName + "/.project" ) ); project = ResourcesPlugin.getWorkspace().getRoot() .getProject( description.getName() ); project.create( description, null ); } catch (CoreException e1) { CodeGenPlugin.error( "Failed to create output project" ); } } if (!project.isOpen()) { try { project.open( new NullProgressMonitor() ); } catch (CoreException e) { CodeGenPlugin.error( "Failed to open project" ); } } IFolder folder = project.getFolder( "src" ); try { folder.refreshLocal( IResource.DEPTH_ZERO, null ); } catch (CoreException e) { CodeGenPlugin.error( "could not refresh output folder", e ); } if (!folder.exists()) try { folder.create( true, true, null ); } catch (CoreException e) { CodeGenPlugin.error( "could not create output folder", e ); } return folder; }