Refactory: remove unused classes, imports, fields and methods.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / builder / IdentifierIndexManager.java
index 741ff32..8874d00 100644 (file)
@@ -24,7 +24,7 @@ import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
 import net.sourceforge.phpdt.internal.compiler.parser.SyntaxError;
 import net.sourceforge.phpdt.internal.compiler.util.Util;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
-import net.sourceforge.phpeclipse.obfuscator.PHPIdentifier;
+//import net.sourceforge.phpeclipse.obfuscator.PHPIdentifier;
 
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.runtime.CoreException;
@@ -128,6 +128,19 @@ public class IdentifierIndexManager {
                        return;
                }
 
+               private void skipComments()
+               {
+                       try {
+                               getNextToken();
+                               while (fToken == TokenNameCOMMENT_BLOCK  || fToken == TokenNameCOMMENT_PHPDOC) {
+                                               getNextToken();
+                               }
+                       } catch (InvalidInputException e1) {
+                               // TODO Auto-generated catch block
+                               e1.printStackTrace();
+                       }
+               }
+               
                private void parseDeclarations(char[] parent, StringBuffer buf,
                                boolean goBack) {
                        char[] ident;
@@ -159,7 +172,7 @@ public class IdentifierIndexManager {
                                                }
                                        }
                                        if (fToken == TokenNamefunction) {
-                                               getNextToken();
+                                               skipComments();
                                                if (fToken == TokenNameAND) {
                                                        getNextToken();
                                                }
@@ -181,40 +194,41 @@ public class IdentifierIndexManager {
                                                                                        phpdocOffset, phpdocLength);
                                                                }
                                                        }
-                                                       getNextToken();
+                                                       skipComments();
                                                        parseDeclarations(null, buf, true);
                                                }
                                        } else if (fToken == TokenNameclass
                                                        || fToken == TokenNameinterface) {
-                                               getNextToken();
+                                               skipComments();
                                                if (fToken == TokenNameIdentifier) {
                                                        ident = fScanner.getCurrentIdentifierSource();
                                                        addIdentifierInformation('c', ident, buf,
                                                                        phpdocOffset, phpdocLength);
-                                                       getNextToken();
+                                                       skipComments();
                                                        if (fToken == TokenNameextends) {
-                                                               getNextToken();
+                                                               skipComments();
                                                                while (fToken == TokenNameIdentifier) {
                                                                        ident = fScanner
                                                                                        .getCurrentIdentifierSource();
                                                                        // extends ident
                                                                        addIdentifierInformation('e', ident, buf);
-                                                                       getNextToken();
-                                                                       if (fToken == TokenNameCOMMA) {
-                                                                               getNextToken();
+                                                                       skipComments();
+                                                               if (fToken == TokenNameCOMMA) {
+                                                                       skipComments();
                                                                        }
                                                                }
                                                        }
                                                        if (fToken == TokenNameimplements) {
-                                                               getNextToken();
+                                                               skipComments();
                                                                while (fToken == TokenNameIdentifier) {
                                                                        ident = fScanner
                                                                                        .getCurrentIdentifierSource();
                                                                        // implements ident
                                                                        addIdentifierInformation('e', ident, buf);
-                                                                       getNextToken();
+                                                                       skipComments();
                                                                        if (fToken == TokenNameCOMMA) {
-                                                                               getNextToken();
+                                                                               skipComments();
+//                                                                             getNextToken();
                                                                        }
                                                                }
                                                        }
@@ -240,7 +254,7 @@ public class IdentifierIndexManager {
                                                                || fToken == TokenNamepublic
                                                                || fToken == TokenNameprotected
                                                                || fToken == TokenNameprivate) {
-                                                       getNextToken();
+                                                       skipComments();
                                                }
                                                while (fToken == TokenNameVariable) {
                                                        ident = fScanner.getCurrentIdentifierSource();
@@ -249,9 +263,9 @@ public class IdentifierIndexManager {
                                                                        ident.length - 1);
                                                        addClassVariableInformation('v', classVariable,
                                                                        buf, phpdocOffset, phpdocLength);
-                                                       getNextToken();
+                                                       skipComments();
                                                        if (fToken == TokenNameCOMMA) {
-                                                               getNextToken();
+                                                               skipComments();
                                                        }
                                                }
                                        } else if (!hasModifiers && fToken == TokenNameIdentifier) {
@@ -329,7 +343,8 @@ public class IdentifierIndexManager {
                                        // TokenNameERROR) {
                                        phpdocOffset = -1;
                                        hasModifiers = false;
-                                       if (fToken == TokenNameCOMMENT_PHPDOC) {
+                                       switch (fToken) {
+                                       case TokenNameCOMMENT_PHPDOC:
                                                phpdocOffset = fScanner.getCurrentTokenStartPosition();
                                                phpdocLength = fScanner.getCurrentTokenEndPosition()
                                                                - fScanner.getCurrentTokenStartPosition() + 1;
@@ -346,9 +361,10 @@ public class IdentifierIndexManager {
                                                if (fToken == TokenNameEOF || fToken == TokenNameERROR) {
                                                        break;
                                                }
-                                       }
-                                       if (fToken == TokenNamefunction) {
-                                               getNextToken();
+                                               break;
+                                               
+                                       case TokenNamefunction:
+                                               skipComments();
                                                if (fToken == TokenNameAND) {
                                                        getNextToken();
                                                }
@@ -356,40 +372,56 @@ public class IdentifierIndexManager {
                                                        ident = fScanner.getCurrentIdentifierSource();
                                                        addIdentifierInformation('f', ident, buf,
                                                                        phpdocOffset, phpdocLength);
-                                                       getNextToken();
+                                                       skipComments();
+                                                       if (fToken == TokenNameLPAREN) {
+                                                               skipComments();
+                                                               do {
+                                                                       if (fToken == TokenNameVariable) {
+                                                                               ident = fScanner.getCurrentIdentifierSource();
+                                                                               addIdentifierInformation('v', ident, buf,
+                                                                                               phpdocOffset, phpdocLength);
+                                                                               skipComments();
+                                                                               if (fToken == TokenNameCOMMA) {
+                                                                                       skipComments();
+                                                                               }
+                                                                       }       
+                                                               } while (fToken != TokenNameRPAREN );
+                                                       }
                                                        parseDeclarations(null, buf, true);
                                                }
-                                       } else if (fToken == TokenNameclass
-                                                       || fToken == TokenNameinterface) {
-                                               getNextToken();
+                                               break;
+                                               
+                                       case TokenNameclass:
+                                       case TokenNameinterface:
+                                               skipComments();
                                                if (fToken == TokenNameIdentifier) {
                                                        ident = fScanner.getCurrentIdentifierSource();
                                                        addIdentifierInformation('c', ident, buf,
                                                                        phpdocOffset, phpdocLength);
-                                                       getNextToken();
+                                                       skipComments();
                                                        if (fToken == TokenNameextends) {
-                                                               getNextToken();
+                                                               skipComments();
                                                                while (fToken == TokenNameIdentifier) {
                                                                        ident = fScanner
                                                                                        .getCurrentIdentifierSource();
                                                                        // extends ident
                                                                        addIdentifierInformation('e', ident, buf);
-                                                                       getNextToken();
+                                                                       skipComments();
                                                                        if (fToken == TokenNameCOMMA) {
-                                                                               getNextToken();
+                                                                               skipComments();
                                                                        }
                                                                }
                                                        }
                                                        if (fToken == TokenNameimplements) {
-                                                               getNextToken();
+                                                               skipComments();
                                                                while (fToken == TokenNameIdentifier) {
                                                                        ident = fScanner
                                                                                        .getCurrentIdentifierSource();
                                                                        // implements ident
                                                                        addIdentifierInformation('e', ident, buf);
-                                                                       getNextToken();
+                                                                       skipComments();
                                                                        if (fToken == TokenNameCOMMA) {
-                                                                               getNextToken();
+                                                                               skipComments();
                                                                        }
                                                                }
                                                        }
@@ -403,39 +435,20 @@ public class IdentifierIndexManager {
                                                        }
                                                        parseDeclarations(ident, buf, true);
                                                }
-                                       } else if (fToken == TokenNameVariable) {
+                                               break;
+
+                                       case TokenNameVariable:
                                                // global variable
                                                ident = fScanner.getCurrentIdentifierSource();
                                                addIdentifierInformation('g', ident, buf, phpdocOffset,
                                                                phpdocLength);
                                                getNextToken();
-                                       } else if (!hasModifiers && fToken == TokenNameIdentifier) {
-                                               ident = fScanner.getCurrentIdentifierSource();
-                                               getNextToken();
-                                               if (ident.length == 6 && ident[0] == 'd'
-                                                               && ident[1] == 'e' && ident[2] == 'f'
-                                                               && ident[3] == 'i' && ident[4] == 'n'
-                                                               && ident[5] == 'e') {
-                                                       if (fToken == TokenNameLPAREN) {
-                                                               getNextToken();
-                                                               if (fToken == TokenNameStringDoubleQuote) {
-                                                                       ident = fScanner
-                                                                                       .getCurrentStringLiteralSource();
-                                                                       addIdentifierInformation('d', ident, buf,
-                                                                                       phpdocOffset, phpdocLength);
-                                                                       getNextToken();
-                                                               } else if (fToken == TokenNameStringSingleQuote) {
-                                                                       ident = fScanner
-                                                                                       .getCurrentStringLiteralSource();
-                                                                       addIdentifierInformation('d', ident, buf,
-                                                                                       phpdocOffset, phpdocLength);
-                                                                       getNextToken();
-                                                               }
-                                                       }
-                                               }
-                                       } else {
+                                               break;
+
+                                       default:
                                                getNextToken();
                                        }
+                                       
                                }
                        } catch (InvalidInputException e) {
                                // ignore errors
@@ -445,7 +458,7 @@ public class IdentifierIndexManager {
                        }
                }
        }
-
+               
        class StringComparator implements Comparator {
                public int compare(Object o1, Object o2) {
                        String s1 = (String) o1;
@@ -563,7 +576,7 @@ public class IdentifierIndexManager {
                String line = (String) fFileMap.get(file.getProjectRelativePath()
                                .toString());
                if (line != null) {
-                       PHPIdentifierLocation ident;
+                       //PHPIdentifierLocation ident;
                        ArrayList allClassNames = new ArrayList();
                        addLine(treeMap, null, line, allClassNames);
                        int i = 0;
@@ -575,7 +588,7 @@ public class IdentifierIndexManager {
        }
 
        public void addIdentifiers(TreeMap treeMap, String startClazz) {
-               PHPIdentifierLocation ident;
+               //PHPIdentifierLocation ident;
                ArrayList allClassNames = new ArrayList();
                addClassName(treeMap, startClazz, allClassNames);
                int i = 0;