1) Moved net.sourceforge.phpeclipse.ui\src\net\sourceforge\phpdt back to net.sourcefo...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / corext / phpdoc / PHPDocUtil.java
index 5bf73a7..7043892 100644 (file)
@@ -55,19 +55,19 @@ public class PHPDocUtil {
                }
        }
 
-       static String getEncoding(String filename) {
-               String encoding = null;
-               IFile file = PHPeclipsePlugin.getWorkspace().getRoot()
-                               .getFileForLocation(new Path(filename));
-               if (file != null) {
-                       try {
-                               encoding = file.getCharset();
-                       } catch (CoreException e) {
-                               // TODO: should log the fact that we could not get the encoding?
-                       }
-               }
-               return encoding;
-       }
+//     static String getEncoding(String filename) {
+//             String encoding = null;
+//             IFile file = PHPeclipsePlugin.getWorkspace().getRoot()
+//                             .getFileForLocation(new Path(filename));
+//             if (file != null) {
+//                     try {
+//                             encoding = file.getCharset();
+//                     } catch (CoreException e) {
+//                             // TODO: should log the fact that we could not get the encoding?
+//                     }
+//             }
+//             return encoding;
+//     }
 
        public static String getUsage(String filename,
                        PHPIdentifierLocation location) {
@@ -93,15 +93,21 @@ public class PHPDocUtil {
                                if (length == -1) {
                                        length = 256;
                                }
-                               for (int i = 0; i < length; i++) {
-                                       if (functionDeclarationCharArray[i] == ')') {
-                                               length = i + 1;
-                                               break;
-                                       }
-                                       if (functionDeclarationCharArray[i] == '{'
-                                                       || functionDeclarationCharArray[i] == '}') {
-                                               length = i;
-                                               break;
+                               if (location.isDefine()) {
+                                       length = getClosingParenthesis(functionDeclarationCharArray);
+                                       if (length < 0)
+                                               return "";
+                               } else {
+                                       for (int i = 0; i < length; i++) {
+                                               if (functionDeclarationCharArray[i] == ')') {
+                                                       length = i + 1;
+                                                       break;
+                                               }
+                                               if (functionDeclarationCharArray[i] == '{'
+                                                               || functionDeclarationCharArray[i] == '}') {
+                                                       length = i;
+                                                       break;
+                                               }
                                        }
                                }
                                usage = new String(functionDeclarationCharArray, 0, length);
@@ -134,4 +140,42 @@ public class PHPDocUtil {
                return null;
        }
 
+       private static int getClosingParenthesis(char[] buffer) {
+               int p = 0;
+               boolean dq = false;
+               boolean sq = false;
+
+               for (int i = 0; i < buffer.length; i++) {
+                       if (buffer[i] == '\\') {
+                               i++;
+                               continue;
+                       }
+                       if (dq) {
+                               dq = (buffer[i] != '"');
+                               continue;
+                       }
+                       if (sq) {
+                               sq = (buffer[i] != '\'');
+                               continue;
+                       }
+                       switch (buffer[i]) {
+                       case '(':
+                               p++;
+                               break;
+                       case ')':
+                               p--;
+                               if (p < 0)
+                                       return i;
+                               break;
+                       case '"':
+                               dq = true;
+                               break;
+                       case '\'':
+                               sq = true;
+                               break;
+                       }
+               }
+               return -1;
+       }
+
 }