X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/IdentifierIndexManager.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/IdentifierIndexManager.java index fda5d2e..8e859cf 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/IdentifierIndexManager.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/IdentifierIndexManager.java @@ -11,6 +11,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; @@ -41,7 +42,25 @@ public class IdentifierIndexManager { private int fToken; public LineCreator() { - fScanner = new Scanner(true, false, false, false, true, null, null); + fScanner = new Scanner(true, false, false, false, true, null, null, true /* taskCaseSensitive */); + } + + /** + * Add the information of the current identifier to the line + * + * @param typeOfIdentifier + * the type of the identifier ('c'lass, 'd'efine, 'f'unction, 'm'ethod(class), 'v'ariable(class) 'g'lobal variable) + * @param identifier + * current identifier + * @param line + * Buffer for the current index line + */ + private void addIdentifierInformation(char typeOfIdentifier, char[] identifier, StringBuffer line) { + line.append('\t'); + line.append(typeOfIdentifier); + line.append(identifier); + // line.append("\to"); // Offset + // line.append(fScanner.getCurrentTokenStartPosition()); } /** @@ -161,6 +180,30 @@ public class IdentifierIndexManager { ident = fScanner.getCurrentIdentifierSource(); addIdentifierInformation('c', ident, buf, phpdocOffset, phpdocLength); getNextToken(); + if (fToken == TokenNameextends) { + getNextToken(); + while (fToken == TokenNameIdentifier) { + ident = fScanner.getCurrentIdentifierSource(); + // extends ident + addIdentifierInformation('e', ident, buf); + getNextToken(); + if (fToken == TokenNameCOMMA) { + getNextToken(); + } + } + } + if (fToken == TokenNameimplements) { + getNextToken(); + while (fToken == TokenNameIdentifier) { + ident = fScanner.getCurrentIdentifierSource(); + // implements ident + addIdentifierInformation('e', ident, buf); + getNextToken(); + if (fToken == TokenNameCOMMA) { + getNextToken(); + } + } + } //skip tokens for classname, extends and others until we have // the opening '{' while (fToken != TokenNameLBRACE && fToken != TokenNameEOF && fToken != TokenNameERROR) { @@ -174,12 +217,15 @@ public class IdentifierIndexManager { || fToken == TokenNameprotected || fToken == TokenNameprivate) { getNextToken(); } - if (fToken == TokenNameVariable) { + while (fToken == TokenNameVariable) { ident = fScanner.getCurrentIdentifierSource(); classVariable = new char[ident.length - 1]; System.arraycopy(ident, 1, classVariable, 0, ident.length - 1); addClassVariableInformation('v', classVariable, buf, phpdocOffset, phpdocLength); getNextToken(); + if (fToken == TokenNameCOMMA) { + getNextToken(); + } } } else if (!hasModifiers && fToken == TokenNameIdentifier) { ident = fScanner.getCurrentIdentifierSource(); @@ -192,6 +238,10 @@ public class IdentifierIndexManager { ident = fScanner.getCurrentStringLiteralSource(); addIdentifierInformation('d', ident, buf, phpdocOffset, phpdocLength); getNextToken(); + } else if (fToken == TokenNameStringSingleQuote) { + ident = fScanner.getCurrentStringLiteralSource(); + addIdentifierInformation('d', ident, buf, phpdocOffset, phpdocLength); + getNextToken(); } } } @@ -269,6 +319,30 @@ public class IdentifierIndexManager { ident = fScanner.getCurrentIdentifierSource(); addIdentifierInformation('c', ident, buf, phpdocOffset, phpdocLength); getNextToken(); + if (fToken == TokenNameextends) { + getNextToken(); + while (fToken == TokenNameIdentifier) { + ident = fScanner.getCurrentIdentifierSource(); + // extends ident + addIdentifierInformation('e', ident, buf); + getNextToken(); + if (fToken == TokenNameCOMMA) { + getNextToken(); + } + } + } + if (fToken == TokenNameimplements) { + getNextToken(); + while (fToken == TokenNameIdentifier) { + ident = fScanner.getCurrentIdentifierSource(); + // implements ident + addIdentifierInformation('e', ident, buf); + getNextToken(); + if (fToken == TokenNameCOMMA) { + getNextToken(); + } + } + } //skip fTokens for classname, extends and others until we have // the opening '{' while (fToken != TokenNameLBRACE && fToken != TokenNameEOF && fToken != TokenNameERROR) { @@ -292,6 +366,10 @@ public class IdentifierIndexManager { ident = fScanner.getCurrentStringLiteralSource(); addIdentifierInformation('d', ident, buf, phpdocOffset, phpdocLength); getNextToken(); + } else if (fToken == TokenNameStringSingleQuote) { + ident = fScanner.getCurrentStringLiteralSource(); + addIdentifierInformation('d', ident, buf, phpdocOffset, phpdocLength); + getNextToken(); } } } @@ -404,6 +482,75 @@ public class IdentifierIndexManager { * @param line */ private void addLine(String line) { + addLine(fIndentifierMap, fFileMap, line, null); + } + + public TreeMap getIdentifiers(IFile file) { + TreeMap treeMap = new TreeMap(new StringComparator()); + addIdentifiers(treeMap, file); + return treeMap; + } + public TreeMap getIdentifiers(String startClazz) { + TreeMap treeMap = new TreeMap(new StringComparator()); + addIdentifiers(treeMap, startClazz); + return treeMap; + } + + public void addIdentifiers(TreeMap treeMap, IFile file) { + String line = (String) fFileMap.get(file.getProjectRelativePath().toString()); + if (line != null) { + PHPIdentifierLocation ident; + ArrayList allClassNames = new ArrayList(); + addLine(treeMap, null, line, allClassNames); + int i=0; + while (i + // not in map + identifier = null; + phpIdentifier = null; + if (allClassNames != null) { + String extName = token.substring(1); + if (!allClassNames.contains(extName)) { + allClassNames.add(extName); + } + } + break; + case 'f': + // function name + identifier = token.substring(1); + phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.FUNCTION, phpFileName); + break; + case 'g': + // global variable + identifier = token.substring(1); + phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.GLOBAL_VARIABLE, phpFileName); + break; + case 'i': + // implements + // not in map + identifier = null; + phpIdentifier = null; + if (allClassNames != null) { + String implName = token.substring(1); + if (!allClassNames.contains(implName)) { + allClassNames.add(implName); } } - if (flag == false) { + break; + case 'k': + // constructor function name + identifier = token.substring(1); + phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.CONSTRUCTOR, phpFileName); + break; + case 'm': + //method inside a class + identifier = token.substring(1); + phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.METHOD, phpFileName, classname); + break; + case 'v': + // variable inside a class + identifier = token.substring(1); + phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.VARIABLE, phpFileName, classname); + break; + case 'o': + // offset information + identifier = null; + if (phpIdentifier != null) { + offset = token.substring(1); + phpIdentifier.setOffset(Integer.parseInt(offset)); + } + break; + case 'p': + // PHPdoc offset information + identifier = null; + if (phpIdentifier != null) { + offset = token.substring(1); + phpIdentifier.setPHPDocOffset(Integer.parseInt(offset)); + } + break; + case 'l': + // PHPdoc length information + identifier = null; + if (phpIdentifier != null) { + offset = token.substring(1); + phpIdentifier.setPHPDocLength(Integer.parseInt(offset)); + } + break; + default: + PHPeclipsePlugin.log(IStatus.ERROR, "Unknown token character in IdentifierIndexManager: " + token.charAt(0)); + identifier = null; + phpIdentifier = null; + classname = null; + } + if (identifier != null && phpIdentifier != null) { + tokenExists = true; + ArrayList list = (ArrayList) treeMap.get(identifier); + if (list == null) { + list = new ArrayList(); list.add(phpIdentifier); + treeMap.put(identifier, list); + } else { + boolean flag = false; + for (int i = 0; i < list.size(); i++) { + if (list.get(i).equals(phpIdentifier)) { + flag = true; + break; + } + } + if (flag == false) { + list.add(phpIdentifier); + } } } } + if (fileMap != null) { + fileMap.put(phpFileName, line); + } + } catch (Throwable e) { + // write to workspace/.metadata/.log file + PHPeclipsePlugin.log(e); } // if (tokenExists) { - fFileMap.put(phpFileName, line); + // } } @@ -618,6 +797,11 @@ public class IdentifierIndexManager { identifier = token.substring(1); phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.DEFINE, phpFileName); break; + case 'e': + // extends + identifier = null; + phpIdentifier = null; + break; case 'f': // function name identifier = token.substring(1); @@ -628,6 +812,11 @@ public class IdentifierIndexManager { identifier = token.substring(1); phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.GLOBAL_VARIABLE, phpFileName); break; + case 'i': + // implements + identifier = null; + phpIdentifier = null; + break; case 'k': // constructor function name identifier = token.substring(1);