Exemplo n.º 1
0
 /*
  * @see IClassFile
  */
 public ICompilationUnit getWorkingCopy(WorkingCopyOwner owner, IProgressMonitor monitor)
     throws JavaModelException {
   CompilationUnit workingCopy =
       new ClassFileWorkingCopy(this, owner == null ? DefaultWorkingCopyOwner.PRIMARY : owner);
   JavaModelManager manager = JavaModelManager.getJavaModelManager();
   JavaModelManager.PerWorkingCopyInfo perWorkingCopyInfo =
       manager.getPerWorkingCopyInfo(
           workingCopy,
           false /*don't create*/,
           true /*record usage*/,
           null /*not used since don't create*/);
   if (perWorkingCopyInfo != null) {
     return perWorkingCopyInfo
         .getWorkingCopy(); // return existing handle instead of the one created above
   }
   BecomeWorkingCopyOperation op = new BecomeWorkingCopyOperation(workingCopy, null);
   op.runOperation(monitor);
   return workingCopy;
 }
Exemplo n.º 2
0
  /*
   * @see IClassFile#becomeWorkingCopy(IProblemRequestor, WorkingCopyOwner, IProgressMonitor)
   */
  public ICompilationUnit becomeWorkingCopy(
      IProblemRequestor problemRequestor, WorkingCopyOwner owner, IProgressMonitor monitor)
      throws JavaModelException {
    JavaModelManager manager = JavaModelManager.getJavaModelManager();
    CompilationUnit workingCopy =
        new ClassFileWorkingCopy(this, owner == null ? DefaultWorkingCopyOwner.PRIMARY : owner);
    JavaModelManager.PerWorkingCopyInfo perWorkingCopyInfo =
        manager.getPerWorkingCopyInfo(
            workingCopy,
            false /*don't create*/,
            true /*record usage*/,
            null /*no problem requestor needed*/);
    if (perWorkingCopyInfo == null) {
      // close cu and its children
      close();

      BecomeWorkingCopyOperation operation =
          new BecomeWorkingCopyOperation(workingCopy, problemRequestor);
      operation.runOperation(monitor);

      return workingCopy;
    }
    return perWorkingCopyInfo.workingCopy;
  }