replaced a lot of deprecated code; if someone runs into a commit conflict afterwards...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / Openable.java
index 63b87b8..1364b4f 100644 (file)
@@ -1,10 +1,10 @@
 /*******************************************************************************
  * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials 
+ * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Common Public License v1.0
  * which accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/cpl-v10.html
- * 
+ *
  * Contributors:
  *     IBM Corporation - initial API and implementation
  *******************************************************************************/
@@ -60,8 +60,8 @@ protected Openable(JavaElement parent, String name) {
                } else {
                        JavaModelManager.getJavaModelManager().getElementsOutOfSynchWithBuffers().put(this, this);
                }
-       }       
-       
+       }
+
        /**
         * Builds this element's structure and properties in the given
         * info object, based on this element's current contents (reuse buffer
@@ -82,7 +82,7 @@ protected Openable(JavaElement parent, String name) {
 //protected void buildStructure(OpenableElementInfo info, IProgressMonitor monitor) throws JavaModelException {
 //
 //     if (monitor != null && monitor.isCanceled()) return;
-//     
+//
 //     // remove existing (old) infos
 //     removeInfo();
 //     HashMap newElements = new HashMap(11);
@@ -93,11 +93,11 @@ protected Openable(JavaElement parent, String name) {
 //             Object value = newElements.get(key);
 //             JavaModelManager.getJavaModelManager().putInfo(key, value);
 //     }
-//             
+//
 //     // add the info for this at the end, to ensure that a getInfo cannot reply null in case the LRU cache needs
 //     // to be flushed. Might lead to performance issues.
 //     // see PR 1G2K5S7: ITPJCORE:ALL - NPE when accessing source for a binary type
-//     JavaModelManager.getJavaModelManager().putInfo(this, info);     
+//     JavaModelManager.getJavaModelManager().putInfo(this, info);
 //}
 /*
  * Returns whether this element can be removed from the Java model cache to make space.
@@ -192,7 +192,7 @@ protected void closing(Object info) {
 //     // fix for 1FVGGKF
 //     JavaProject project = (JavaProject)getJavaProject();
 //     ISearchableNameEnvironment environment = project.getSearchableNameEnvironment();
-//     
+//
 //     // fix for 1FVXGDK
 //     SelectionEngine engine = new SelectionEngine(environment, requestor, project.getOptions(true));
 //     engine.select(cu, offset, offset + length - 1);
@@ -220,7 +220,7 @@ protected void generateInfos(Object info, HashMap newElements, IProgressMonitor
        if (JavaModelManager.VERBOSE){
                System.out.println("OPENING Element ("+ Thread.currentThread()+"): " + this.toStringWithAncestors()); //$NON-NLS-1$//$NON-NLS-2$
        }
-       
+
        // open the parent if necessary
        openParent(info, newElements, monitor);
        if (monitor != null && monitor.isCanceled()) return;
@@ -238,7 +238,7 @@ protected void generateInfos(Object info, HashMap newElements, IProgressMonitor
                newElements.remove(this);
                throw e;
        }
-       
+
        // remove out of sync buffer for this element
        JavaModelManager.getJavaModelManager().getElementsOutOfSynchWithBuffers().remove(this);
 
@@ -253,7 +253,7 @@ protected void generateInfos(Object info, HashMap newElements, IProgressMonitor
  * is the first time a request is being made for the buffer, an attempt is
  * made to create and fill this element's buffer. If the buffer has been
  * closed since it was first opened, the buffer is re-created.
- * 
+ *
  * @see IOpenable
  */
 public IBuffer getBuffer() throws JavaModelException {
@@ -299,7 +299,7 @@ public IResource getCorrespondingResource() throws JavaModelException {
  * @see IJavaElement
  */
 public IOpenable getOpenable() {
-       return this;    
+       return this;
 }
 
 
@@ -327,14 +327,14 @@ public IResource getUnderlyingResource() throws JavaModelException {
 }
 
 public boolean exists() {
-       
+
        IPackageFragmentRoot root = this.getPackageFragmentRoot();
        if (root == null || root == this || !root.isArchive()) {
                return parentExists() && resourceExists();
        } else {
                return super.exists();
        }
-}      
+}
 
 /**
  * Returns true if this element may have an associated source buffer,
@@ -344,7 +344,7 @@ protected boolean hasBuffer() {
        return false;
 }
 /**
- * @see IParent 
+ * @see IParent
  */
 public boolean hasChildren() throws JavaModelException {
        return getChildren().length > 0;
@@ -353,7 +353,7 @@ public boolean hasChildren() throws JavaModelException {
  * @see IOpenable
  */
 public boolean hasUnsavedChanges() throws JavaModelException{
-       
+
        if (isReadOnly() || !isOpen()) {
                return false;
        }
@@ -379,7 +379,7 @@ public boolean hasUnsavedChanges() throws JavaModelException{
                        }
                }
        }
-       
+
        return false;
 }
 /**
@@ -391,7 +391,7 @@ public boolean isConsistent() throws JavaModelException {
        return true;
 }
 /**
- * 
+ *
  * @see IOpenable
  */
 public boolean isOpen() {
@@ -417,10 +417,10 @@ protected boolean isSourceElement() {
 //}
 /**
  * @see IOpenable
- */ 
+ */
 public void makeConsistent(IProgressMonitor monitor) throws JavaModelException {
        if (isConsistent()) return;
-       
+
        // create a new info and make it the current info
        // (this will remove the info and its children just before storing the new infos)
        JavaModelManager manager = JavaModelManager.getJavaModelManager();
@@ -481,11 +481,11 @@ protected void openParent(Object childInfo, HashMap newElements, IProgressMonito
 // */
 //protected void openWhenClosed(IProgressMonitor pm) throws JavaModelException {
 //     try {
-//             
+//
 //             if (JavaModelManager.VERBOSE){
 //                     System.out.println("OPENING Element ("+ Thread.currentThread()+"): " + this.toStringWithAncestors()); //$NON-NLS-1$//$NON-NLS-2$
 //             }
-//             
+//
 //             // 1) Parent must be open - open the parent if necessary
 //             openParent(pm);
 //
@@ -493,14 +493,14 @@ protected void openParent(Object childInfo, HashMap newElements, IProgressMonito
 //             OpenableElementInfo info = createElementInfo();
 //             if (isSourceElement()) {
 //                     this.openBuffer(pm);
-//             } 
+//             }
 //
 //             // 3) build the structure of the openable
 //             buildStructure(info, pm);
 //
 //             // 4) anything special
 //             opening(info);
-//             
+//
 ////           if (JavaModelManager.VERBOSE) {
 ////                   System.out.println("-> Package cache size = " + JavaModelManager.getJavaModelManager().cache.pkgSize()); //$NON-NLS-1$
 ////                   System.out.println("-> Openable cache filling ratio = " + JavaModelManager.getJavaModelManager().cache.openableFillingRatio() + "%"); //$NON-NLS-1$//$NON-NLS-2$
@@ -517,10 +517,10 @@ protected void openParent(Object childInfo, HashMap newElements, IProgressMonito
 
 /**
  *  Answers true if the parent exists (null parent is answering true)
- * 
+ *
  */
 protected boolean parentExists(){
-       
+
        IJavaElement parent = this.getParent();
        if (parent == null) return true;
        return parent.exists();
@@ -532,9 +532,9 @@ protected boolean parentExists(){
 protected boolean resourceExists() {
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        if (workspace == null) return false; // workaround for http://bugs.eclipse.org/bugs/show_bug.cgi?id=34069
-       return 
+       return
                JavaModel.getTarget(
-                       workspace.getRoot(), 
+                       workspace.getRoot(),
                        this.getPath().makeRelative(), // ensure path is relative (see http://dev.eclipse.org/bugs/show_bug.cgi?id=22517)
                        true) != null;
 }
@@ -543,7 +543,7 @@ protected boolean resourceExists() {
  * @see IOpenable
  */
 public void save(IProgressMonitor pm, boolean force) throws JavaModelException {
-       if (isReadOnly() || this.getResource().isReadOnly()) {
+       if (isReadOnly() || this.getResource().getResourceAttributes().isReadOnly()) {
                throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.READ_ONLY, this));
        }
        IBuffer buf = getBuffer();