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 365620c..b72d55d 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/IdentifierIndexManager.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/IdentifierIndexManager.java @@ -34,13 +34,42 @@ public class IdentifierIndexManager { private int fToken; public LineCreator() { - fScanner = new Scanner(false, false); + fScanner = new Scanner(true, false); } + /** - * gets the next token from input + * 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, 'v'ariable) + * @param identifier current identifier + * @param line Buffer for the current index line + * @param phpdocOffset the offset of the PHPdoc comment if available + * @param phpdocLength the length of the PHPdoc comment if available */ - private void getNextToken() { + private void addIdentifierInformation( + char typeOfIdentifier, + char[] identifier, + StringBuffer line, + int phpdocOffset, + int phpdocLength) { + + line.append('\t'); + line.append(typeOfIdentifier); + line.append(identifier); + line.append("\to"); // Offset + line.append(fScanner.getCurrentTokenStartPosition()); + if (phpdocOffset >= 0) { + line.append("\tp"); // phpdoc offset + line.append(phpdocOffset); + line.append("\tl"); // phpdoc length + line.append(phpdocLength); + } + } + /** + * Get the next token from input + */ + private void getNextToken() { try { fToken = fScanner.getNextToken(); if (Scanner.DEBUG) { @@ -60,16 +89,25 @@ public class IdentifierIndexManager { private void parseDeclarations(StringBuffer buf, boolean goBack) { char[] ident; int counter = 0; + int phpdocOffset = -1; + int phpdocLength = -1; try { while (fToken != TokenNameEOF && fToken != TokenNameERROR) { + phpdocOffset = -1; + if (fToken == TokenNameCOMMENT_PHPDOC) { + phpdocOffset = fScanner.getCurrentTokenStartPosition(); + phpdocLength = fScanner.getCurrentTokenEndPosition() - fScanner.getCurrentTokenStartPosition() + 1; + getNextToken(); + if (fToken == TokenNameEOF || fToken == TokenNameERROR) { + break; + } + } if (fToken == TokenNamevar) { getNextToken(); if (fToken == TokenNameVariable) { ident = fScanner.getCurrentIdentifierSource(); - buf.append("\tv"); - buf.append(ident); - + addIdentifierInformation('v', ident, buf, phpdocOffset, phpdocLength); getNextToken(); } } else if (fToken == TokenNamefunction) { @@ -79,8 +117,7 @@ public class IdentifierIndexManager { } if (fToken == TokenNameIdentifier) { ident = fScanner.getCurrentIdentifierSource(); - buf.append("\tm"); - buf.append(ident); + addIdentifierInformation('m', ident, buf, phpdocOffset, phpdocLength); getNextToken(); parseDeclarations(buf, true); } @@ -88,8 +125,7 @@ public class IdentifierIndexManager { getNextToken(); if (fToken == TokenNameIdentifier) { ident = fScanner.getCurrentIdentifierSource(); - buf.append("\tc"); - buf.append(ident); + addIdentifierInformation('c', ident, buf, phpdocOffset, phpdocLength); getNextToken(); //skip tokens for classname, extends and others until we have the opening '{' @@ -104,8 +140,7 @@ public class IdentifierIndexManager { getNextToken(); if (fToken == TokenNameStringLiteral) { ident = fScanner.getCurrentStringLiteralSource(); - buf.append("\td"); - buf.append(ident); + addIdentifierInformation('d', ident, buf, phpdocOffset, phpdocLength); getNextToken(); } } @@ -132,6 +167,8 @@ public class IdentifierIndexManager { char[] ident; String identifier; int counter = 0; + int phpdocOffset = -1; + int phpdocLength = -1; fScanner.setSource(charArray); fScanner.setPHPMode(false); @@ -140,6 +177,15 @@ public class IdentifierIndexManager { try { while (fToken != TokenNameEOF && fToken != TokenNameERROR) { + phpdocOffset = -1; + if (fToken == TokenNameCOMMENT_PHPDOC) { + phpdocOffset = fScanner.getCurrentTokenStartPosition(); + phpdocLength = fScanner.getCurrentTokenEndPosition() - fScanner.getCurrentTokenStartPosition() + 1; + getNextToken(); + if (fToken == TokenNameEOF || fToken == TokenNameERROR) { + break; + } + } if (fToken == TokenNamefunction) { getNextToken(); if (fToken == TokenNameAND) { @@ -147,8 +193,7 @@ public class IdentifierIndexManager { } if (fToken == TokenNameIdentifier) { ident = fScanner.getCurrentIdentifierSource(); - buf.append("\tf"); - buf.append(ident); + addIdentifierInformation('f', ident, buf, phpdocOffset, phpdocLength); getNextToken(); parseDeclarations(buf, true); } @@ -156,8 +201,7 @@ public class IdentifierIndexManager { getNextToken(); if (fToken == TokenNameIdentifier) { ident = fScanner.getCurrentIdentifierSource(); - buf.append("\tc"); - buf.append(ident); + addIdentifierInformation('c', ident, buf, phpdocOffset, phpdocLength); getNextToken(); //skip fTokens for classname, extends and others until we have the opening '{' @@ -174,8 +218,7 @@ public class IdentifierIndexManager { getNextToken(); if (fToken == TokenNameStringLiteral) { ident = fScanner.getCurrentStringLiteralSource(); - buf.append("\td"); - buf.append(ident); + addIdentifierInformation('d', ident, buf, phpdocOffset, phpdocLength); getNextToken(); } } @@ -245,7 +288,8 @@ public class IdentifierIndexManager { String token; String identifier = null; String classname = null; - PHPIdentifier phpIdentifier = null; + String offset = null; + PHPIdentifierLocation phpIdentifier = null; boolean tokenExists = false; tokenizer = new StringTokenizer(line, "\t"); @@ -282,6 +326,27 @@ public class IdentifierIndexManager { 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 : identifier = null; phpIdentifier = null;