Example usage for org.eclipse.jdt.internal.core CompilationUnit becomeWorkingCopy

List of usage examples for org.eclipse.jdt.internal.core CompilationUnit becomeWorkingCopy

Introduction

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

Prototype

@Override
    public void becomeWorkingCopy(IProblemRequestor problemRequestor, IProgressMonitor monitor)
            throws JavaModelException 

Source Link

Usage

From source file:org.eclipse.jdt.core.WorkingCopyOwner.java

License:Open Source License

/**
 * Returns a new working copy with the given name using this working copy owner to
 * create its buffer./*from   w  ww  .j a v  a  2  s  .  c  o  m*/
 * <p>
 * This working copy always belongs to the default package in a package
 * fragment root that corresponds to its Java project, and this Java project never exists.
 * However this Java project has the given classpath that is used when resolving names
 * in this working copy.
 * </p><p>
 * A DOM AST created using this working copy will have bindings resolved using the given
 * classpath, and problem are reported to the given problem requestor.
 * <p></p>
 * <code>JavaCore#getOptions()</code> is used to create the DOM AST as it is not
 * possible to set the options on the non-existing Java project.
 * </p><p>
 * When the working copy instance is created, an {@link IJavaElementDelta#ADDED added delta} is
 * reported on this working copy.
 * </p><p>
 * Once done with the working copy, users of this method must discard it using
 * {@link ICompilationUnit#discardWorkingCopy()}.
 * </p><p>
 * Note that when such working copy is committed, only its buffer is saved (see
 * {@link IBuffer#save(IProgressMonitor, boolean)}) but no resource is created.
 * </p><p>
 * This method is not intended to be overriden by clients.
 * </p>
 *
 * @param name the name of the working copy (e.g. "X.java")
 * @param classpath the classpath used to resolve names in this working copy
 * @param problemRequestor a requestor which will get notified of problems detected during
 *    reconciling as they are discovered. The requestor can be set to <code>null</code> indicating
 *    that the client is not interested in problems.
 * @param monitor a progress monitor used to report progress while opening the working copy
 *    or <code>null</code> if no progress should be reported
 * @throws JavaModelException if the contents of this working copy can
 *   not be determined.
 * @return a new working copy
 * @see ICompilationUnit#becomeWorkingCopy(IProblemRequestor, IProgressMonitor)
 * @since 3.2
 *
 * @deprecated Use {@link #newWorkingCopy(String, IClasspathEntry[], IProgressMonitor)} instead.
 *    Note that if this deprecated method is used, problems may be reported twice
 *    if the given requestor is not the same as the current working copy owner one.
 */
public final ICompilationUnit newWorkingCopy(String name, IClasspathEntry[] classpath,
        IProblemRequestor problemRequestor, IProgressMonitor monitor) throws JavaModelException {
    ExternalJavaProject project = new ExternalJavaProject(classpath);
    IPackageFragment parent = ((PackageFragmentRoot) project.getPackageFragmentRoot(project.getProject()))
            .getPackageFragment(CharOperation.NO_STRINGS);
    // GROOVY start
    /* old {
    CompilationUnit result = new CompilationUnit((PackageFragment) parent, name, this);
    } new */
    CompilationUnit result = LanguageSupportFactory.newCompilationUnit((PackageFragment) parent, name, this);
    // GROOVY end
    result.becomeWorkingCopy(problemRequestor, monitor);
    return result;
}

From source file:org.eclipse.jdt.core.WorkingCopyOwner.java

License:Open Source License

/**
 * Returns a new working copy with the given name using this working copy owner to
 * create its buffer./* w  ww.  j av a 2s.c  o m*/
 * <p>
 * This working copy always belongs to the default package in a package
 * fragment root that corresponds to its Java project, and this Java project never exists.
 * However this Java project has the given classpath that is used when resolving names
 * in this working copy.
 * </p><p>
 * If a DOM AST is created using this working copy, then given classpath will be used
 *  if bindings need to be resolved. Problems will be reported to the problem requestor
 * of the current working copy owner problem if it is not <code>null</code>.
 * <p></p>
 * Options used to create the DOM AST are got from {@link JavaCore#getOptions()}
 * as it is not possible to set the options on a non-existing Java project.
 * </p><p>
 * When the working copy instance is created, an {@link IJavaElementDelta#ADDED added delta} is
 * reported on this working copy.
 * </p><p>
 * Once done with the working copy, users of this method must discard it using
 * {@link ICompilationUnit#discardWorkingCopy()}.
 * </p><p>
 * Note that when such working copy is committed, only its buffer is saved (see
 * {@link IBuffer#save(IProgressMonitor, boolean)}) but no resource is created.
 * </p><p>
 * This method is not intended to be overriden by clients.
 * </p>
 *
 * @param name the name of the working copy (e.g. "X.java")
 * @param classpath the classpath used to resolve names in this working copy
 * @param monitor a progress monitor used to report progress while opening the working copy
 *    or <code>null</code> if no progress should be reported
 * @throws JavaModelException if the contents of this working copy can
 *   not be determined.
 * @return a new working copy
 * @see ICompilationUnit#becomeWorkingCopy(IProgressMonitor)
 *
 * @since 3.3
 */
public final ICompilationUnit newWorkingCopy(String name, IClasspathEntry[] classpath, IProgressMonitor monitor)
        throws JavaModelException {
    ExternalJavaProject project = new ExternalJavaProject(classpath);
    IPackageFragment parent = ((PackageFragmentRoot) project.getPackageFragmentRoot(project.getProject()))
            .getPackageFragment(CharOperation.NO_STRINGS);
    // GROOVY start
    /* old {
    CompilationUnit result = new CompilationUnit((PackageFragment) parent, name, this);
    } new */
    CompilationUnit result = LanguageSupportFactory.newCompilationUnit((PackageFragment) parent, name, this);
    // GROOVY end
    result.becomeWorkingCopy(getProblemRequestor(result), monitor);
    return result;
}