List of usage examples for org.eclipse.jdt.internal.core CreateTypeOperation CreateTypeOperation
public CreateTypeOperation(IJavaElement parentElement, 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) *//*from w w w .java 2 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]; }