Refactory: removed unnecessary local variables and imports.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / corext / util / JavaModelUtil.java
index bfa0f51..6359918 100644 (file)
@@ -24,7 +24,9 @@ import net.sourceforge.phpdt.core.IType;
 import net.sourceforge.phpdt.core.JavaModelException;
 import net.sourceforge.phpdt.core.Signature;
 import net.sourceforge.phpdt.core.compiler.CharOperation;
-import net.sourceforge.phpeclipse.phpeditor.EditorUtility;
+//import net.sourceforge.phpdt.ui.JavaUI;
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+//import net.sourceforge.phpeclipse.phpeditor.EditorUtility;
 
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
@@ -232,14 +234,14 @@ public class JavaModelUtil {
                return type.getTypeQualifiedName('.');
        }
 
-       private static void getTypeQualifiedName(IType type, StringBuffer buf) {
-               IType outerType = type.getDeclaringType();
-               if (outerType != null) {
-                       getTypeQualifiedName(outerType, buf);
-                       buf.append('.');
-               }
-               buf.append(type.getElementName());
-       }
+//     private static void getTypeQualifiedName(IType type, StringBuffer buf) {
+//             IType outerType = type.getDeclaringType();
+//             if (outerType != null) {
+//                     getTypeQualifiedName(outerType, buf);
+//                     buf.append('.');
+//             }
+//             buf.append(type.getElementName());
+//     }
 
        /**
         * Returns the fully qualified name of the given type using '.' as
@@ -571,7 +573,7 @@ public class JavaModelUtil {
                        if (semi == -1) {
                                throw new IllegalArgumentException();
                        }
-                       String name = refTypeSig.substring(arrayCount + 1, semi);
+                       //String name = refTypeSig.substring(arrayCount + 1, semi);
 
                        // String[][] resolvedNames= declaringType.resolveType(name);
                        // if (resolvedNames != null && resolvedNames.length > 0) {
@@ -672,7 +674,7 @@ public class JavaModelUtil {
        public static IMember toWorkingCopy(IMember member) {
                ICompilationUnit cu = member.getCompilationUnit();
                if (cu != null && !cu.isWorkingCopy()) {
-                       ICompilationUnit workingCopy = EditorUtility.getWorkingCopy(cu);
+                       ICompilationUnit workingCopy = /*EditorUtility.*/getWorkingCopy(cu);
                        if (workingCopy != null) {
                                IJavaElement[] members = workingCopy.findElements(member);
                                if (members != null && members.length > 0) {
@@ -689,7 +691,7 @@ public class JavaModelUtil {
         */
        public static ICompilationUnit toWorkingCopy(ICompilationUnit cu) {
                if (!cu.isWorkingCopy()) {
-                       ICompilationUnit workingCopy = EditorUtility.getWorkingCopy(cu);
+                       ICompilationUnit workingCopy = /*EditorUtility.*/getWorkingCopy(cu);
                        if (workingCopy != null) {
                                return workingCopy;
                        }
@@ -820,4 +822,46 @@ public class JavaModelUtil {
                System.arraycopy(args, 0, args = new String[count], 0, count);
                return args;
        }
+
+       //incastrix
+       /**
+        * Gets the working copy of an compilation unit opened in an editor
+        * 
+        * @param part
+        *            the editor part
+        * @param cu
+        *            the original compilation unit (or another working copy)
+        * @return the working copy of the compilation unit, or null if not found
+        */
+       public static ICompilationUnit getWorkingCopy(ICompilationUnit cu) {
+               if (cu == null)
+                       return null;
+               if (cu.isWorkingCopy())
+                       return cu;
+
+               return (ICompilationUnit) cu.findSharedWorkingCopy(PHPeclipsePlugin.getDefault()
+                               .getBufferFactory());
+       }
+
+       // incastrix
+       /**
+        * Gets the working copy of an member opened in an editor
+        * 
+        * @param member
+        *            the original member or a member in a working copy
+        * @return the corresponding member in the shared working copy or
+        *         <code>null</code> if not found
+        */
+       public static IMember getWorkingCopy(IMember member)
+                       throws JavaModelException {
+               ICompilationUnit cu = member.getCompilationUnit();
+               if (cu != null) {
+                       ICompilationUnit workingCopy = getWorkingCopy(cu);
+                       if (workingCopy != null) {
+                               return JavaModelUtil.findMemberInCompilationUnit(workingCopy,
+                                               member);
+                       }
+               }
+               return null;
+       }
 }