1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
13 import net.sourceforge.phpdt.core.IJavaElement;
14 import net.sourceforge.phpdt.core.IJavaElementDelta;
15 import net.sourceforge.phpdt.core.JavaModelException;
18 * Discards a working copy (decrement its use count and remove its working copy
19 * info if the use count is 0) and signal its removal through a delta.
21 public class DiscardWorkingCopyOperation extends JavaModelOperation {
23 public DiscardWorkingCopyOperation(IJavaElement workingCopy) {
24 super(new IJavaElement[] { workingCopy });
27 protected void executeOperation() throws JavaModelException {
28 CompilationUnit workingCopy = getWorkingCopy();
30 int useCount = JavaModelManager.getJavaModelManager()
31 .discardPerWorkingCopyInfo(workingCopy);
33 if (!workingCopy.isPrimary()) {
34 // report removed java delta for a non-primary working copy
35 JavaElementDelta delta = new JavaElementDelta(this
37 delta.removed(workingCopy);
39 removeReconcileDelta(workingCopy);
41 if (workingCopy.getResource().isAccessible()) {
42 // report a F_PRIMARY_WORKING_COPY change delta for a
43 // primary working copy
44 JavaElementDelta delta = new JavaElementDelta(this
46 delta.changed(workingCopy,
47 IJavaElementDelta.F_PRIMARY_WORKING_COPY);
50 // report a REMOVED delta
51 JavaElementDelta delta = new JavaElementDelta(this
53 delta.removed(workingCopy,
54 IJavaElementDelta.F_PRIMARY_WORKING_COPY);
62 * Returns the working copy this operation is working on.
64 protected CompilationUnit getWorkingCopy() {
65 return (CompilationUnit) getElementToProcess();
69 * @see JavaModelOperation#isReadOnly
71 public boolean isReadOnly() {