1 11 package org.eclipse.jdt.internal.core; 12 13 import org.eclipse.jdt.core.IJavaElement; 14 import org.eclipse.jdt.core.IJavaElementDelta; 15 import org.eclipse.jdt.core.IJavaProject; 16 import org.eclipse.jdt.core.JavaModelException; 17 18 22 public class DiscardWorkingCopyOperation extends JavaModelOperation { 23 24 public DiscardWorkingCopyOperation(IJavaElement workingCopy) { 25 super(new IJavaElement[] {workingCopy}); 26 } 27 protected void executeOperation() throws JavaModelException { 28 CompilationUnit workingCopy = getWorkingCopy(); 29 30 JavaModelManager manager = JavaModelManager.getJavaModelManager(); 31 int useCount = manager.discardPerWorkingCopyInfo(workingCopy); 32 if (useCount == 0) { 33 IJavaProject javaProject = workingCopy.getJavaProject(); 34 if (ExternalJavaProject.EXTERNAL_PROJECT_NAME.equals(javaProject.getElementName())) { 35 manager.removePerProjectInfo((JavaProject) javaProject); 36 manager.containerRemove(javaProject); 37 } 38 if (!workingCopy.isPrimary()) { 39 JavaElementDelta delta = new JavaElementDelta(getJavaModel()); 41 delta.removed(workingCopy); 42 addDelta(delta); 43 removeReconcileDelta(workingCopy); 44 } else { 45 if (workingCopy.getResource().isAccessible()) { 46 JavaElementDelta delta = new JavaElementDelta(getJavaModel()); 48 delta.changed(workingCopy, IJavaElementDelta.F_PRIMARY_WORKING_COPY); 49 addDelta(delta); 50 } else { 51 JavaElementDelta delta = new JavaElementDelta(getJavaModel()); 53 delta.removed(workingCopy, IJavaElementDelta.F_PRIMARY_WORKING_COPY); 54 addDelta(delta); 55 } 56 } 57 } 58 } 59 62 protected CompilationUnit getWorkingCopy() { 63 return (CompilationUnit)getElementToProcess(); 64 } 65 68 public boolean isReadOnly() { 69 return true; 70 } 71 } 72 | Popular Tags |