Example usage for org.eclipse.jdt.internal.core CreateTypeOperation CreateTypeOperation

List of usage examples for org.eclipse.jdt.internal.core CreateTypeOperation CreateTypeOperation

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core CreateTypeOperation CreateTypeOperation.

Prototype

public CreateTypeOperation(IJavaElement parentElement, String source, boolean force) 

Source Link

Document

When executed, this operation will create a type unit in the given parent element (a compilation unit, type)

Usage

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];
}