List of usage examples for org.eclipse.jdt.internal.core CreateCompilationUnitOperation CreateCompilationUnitOperation
public CreateCompilationUnitOperation(IPackageFragment parentElement, String name, String source, boolean force)
From source file:org.eclipse.jdt.internal.core.CompilationUnit.java
License:Open Source License
/** * @see ICompilationUnit#createType(String, IJavaElement, boolean, IProgressMonitor) *//*ww w .ja v a2 s . c o m*/ public IType createType(String content, IJavaElement sibling, boolean force, IProgressMonitor monitor) throws JavaModelException { if (!exists()) { //autogenerate this compilation unit IPackageFragment pkg = (IPackageFragment) getParent(); String source = ""; //$NON-NLS-1$ if (!pkg.isDefaultPackage()) { //not the default package...add the package declaration String lineSeparator = Util.getLineSeparator(null/*no existing source*/, getJavaProject()); source = "package " + pkg.getElementName() + ";" + lineSeparator + lineSeparator; //$NON-NLS-1$ //$NON-NLS-2$ } CreateCompilationUnitOperation op = new CreateCompilationUnitOperation(pkg, this.name, source, force); op.runOperation(monitor); } CreateTypeOperation op = new CreateTypeOperation(this, content, force); if (sibling != null) { op.createBefore(sibling); } op.runOperation(monitor); return (IType) op.getResultElements()[0]; }
From source file:org.eclipse.jdt.internal.core.PackageFragment.java
License:Open Source License
/** * @see IPackageFragment//from w w w . jav a 2s . c o m */ public ICompilationUnit createCompilationUnit(String cuName, String contents, boolean force, IProgressMonitor monitor) throws JavaModelException { CreateCompilationUnitOperation op = new CreateCompilationUnitOperation(this, cuName, contents, force); op.runOperation(monitor); // GROOVY start /* old { return new CompilationUnit(this, cuName, DefaultWorkingCopyOwner.PRIMARY); } new */ return LanguageSupportFactory.newCompilationUnit(this, cuName, DefaultWorkingCopyOwner.PRIMARY); // GROOVY end }