List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot createPackageFragment
IPackageFragment createPackageFragment(String name, boolean force, IProgressMonitor monitor) throws JavaModelException;
From source file:rabbit.tracking.internal.trackers.LaunchTrackerTest.java
License:Apache License
@BeforeClass public static void beforeClass() throws Exception { new OpenJavaPerspectiveAction().run(); // Create a new Java project: IProject proj = ResourcesPlugin.getWorkspace().getRoot().getProject("P"); JavaCapabilityConfigurationPage.createProject(proj, (URI) null, null); IJavaProject javaProj = JavaCore.create(proj); JavaCapabilityConfigurationPage page = new JavaCapabilityConfigurationPage(); page.init(javaProj, null, null, true); page.configureJavaProject(null);/* ww w . jav a 2s. co m*/ // Create a package: IPackageFragmentRoot src = javaProj.getPackageFragmentRoots()[0]; pkg = src.createPackageFragment("pkg", true, null); }
From source file:x10dt.ui.wizards.NewX10ClassPage.java
License:Open Source License
/** * The worker method. It will find the container, create the file if missing or just replace its contents, and open the * editor on the newly created file./*from ww w.j av a 2s . c om*/ */ private void doCreateType(String typeName, IPackageFragment pkgFrag, String superClass, List<String> superIntfs, IProgressMonitor monitor) throws CoreException { monitor.beginTask("Creating " + typeName, 2); if (!pkgFrag.exists()) { String pkgName = pkgFrag.getElementName(); IPackageFragmentRoot root = this.getPackageFragmentRoot(); if (!root.exists()) { IJavaProject javaProject = getJavaProject(); IClasspathEntry newEntry = JavaCore .newSourceEntry(new Path(getPackageFragmentRootText()).makeAbsolute()); IClasspathEntry[] entries = javaProject.getRawClasspath(); IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1]; System.arraycopy(entries, 0, newEntries, 0, entries.length); newEntries[entries.length] = newEntry; javaProject.setRawClasspath(newEntries, new NullProgressMonitor()); root = (IPackageFragmentRoot) JavaCore .create(javaProject.getProject().getWorkspace().getRoot().getFolder(newEntry.getPath())); } pkgFrag = root.createPackageFragment(pkgName, true, null); } IResource resource = pkgFrag.getCorrespondingResource(); IContainer container = (IContainer) resource; final IFile file = container.getFile(new Path(typeName + ".x10")); try { boolean doComments = isAddComments(); InputStream stream = createContentStream(file, typeName, pkgFrag, superClass, superIntfs, isCreateMain(), isCreateConstructors(), doComments); if (file.exists()) { file.setContents(stream, true, true, monitor); } else { file.create(stream, IResource.FORCE | IResource.KEEP_HISTORY, monitor); } stream.close(); } catch (IOException e) { } monitor.worked(1); }
From source file:x10dt.ui.wizards.NewX10InterfacePage.java
License:Open Source License
/** * The worker method. It will find the container, create the file if missing or just replace its contents, and open the * editor on the newly created file./* ww w . ja va 2 s .c om*/ */ private void doCreateType(String typeName, IPackageFragment pkgFrag, String superClass, List<String> superIntfs, IProgressMonitor monitor) throws CoreException { monitor.beginTask("Creating " + typeName, 2); if (!pkgFrag.exists()) { String pkgName = pkgFrag.getElementName(); IPackageFragmentRoot root = this.getPackageFragmentRoot(); pkgFrag = root.createPackageFragment(pkgName, true, null); } IResource resource = pkgFrag.getCorrespondingResource(); IContainer container = (IContainer) resource; final IFile file = container.getFile(new Path(typeName + ".x10")); try { InputStream stream = createContentStream(file, typeName, pkgFrag, superClass, superIntfs); if (file.exists()) { file.setContents(stream, true, true, monitor); } else { file.create(stream, IResource.FORCE | IResource.KEEP_HISTORY, monitor); } stream.close(); } catch (IOException e) { } monitor.worked(1); }
From source file:x10dt.ui.wizards.NewX10PackageWizardPage.java
License:Open Source License
/** * Creates the new package using the entered field values. * /* w ww. j a va 2 s .c o m*/ * @param monitor * a progress monitor to report progress. The progress monitor must not be <code>null</code> * @throws CoreException * Thrown if creating the package failed. * @throws InterruptedException * Thrown when the operation has been canceled. * @since 2.1 */ public void createPackage(IProgressMonitor monitor) throws CoreException, InterruptedException { if (monitor == null) { monitor = new NullProgressMonitor(); } IPackageFragmentRoot root = getPackageFragmentRoot(); String packName = getPackageText(); fCreatedPackageFragment = root.createPackageFragment(packName, true, monitor); if (monitor.isCanceled()) { throw new InterruptedException(); } }