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 info if the use count is 0)
19 * and signal its removal through a delta.
21 public class DiscardWorkingCopyOperation extends JavaModelOperation {
23 public DiscardWorkingCopyOperation(IJavaElement workingCopy) {
24 super(new IJavaElement[] {workingCopy});
26 protected void executeOperation() throws JavaModelException {
27 CompilationUnit workingCopy = getWorkingCopy();
29 int useCount = JavaModelManager.getJavaModelManager().discardPerWorkingCopyInfo(workingCopy);
31 if (!workingCopy.isPrimary()) {
32 // report removed java delta for a non-primary working copy
33 JavaElementDelta delta = new JavaElementDelta(this.getJavaModel());
34 delta.removed(workingCopy);
36 removeReconcileDelta(workingCopy);
38 if (workingCopy.getResource().isAccessible()) {
39 // report a F_PRIMARY_WORKING_COPY change delta for a primary working copy
40 JavaElementDelta delta = new JavaElementDelta(this.getJavaModel());
41 delta.changed(workingCopy, IJavaElementDelta.F_PRIMARY_WORKING_COPY);
44 // report a REMOVED delta
45 JavaElementDelta delta = new JavaElementDelta(this.getJavaModel());
46 delta.removed(workingCopy, IJavaElementDelta.F_PRIMARY_WORKING_COPY);
53 * Returns the working copy this operation is working on.
55 protected CompilationUnit getWorkingCopy() {
56 return (CompilationUnit)getElementToProcess();
59 * @see JavaModelOperation#isReadOnly
61 public boolean isReadOnly() {