X-Git-Url: http://secure.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 532a301..03810ee 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/IdentifierIndexManager.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/IdentifierIndexManager.java @@ -12,17 +12,22 @@ import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Set; import java.util.SortedMap; import java.util.StringTokenizer; import java.util.TreeMap; + import net.sourceforge.phpdt.core.compiler.ITerminalSymbols; import net.sourceforge.phpdt.core.compiler.InvalidInputException; 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 org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; /** * Manages the identifer index information for a specific project * @@ -39,7 +44,7 @@ public class IdentifierIndexManager { * * @param typeOfIdentifier * the type of the identifier ('c'lass, 'd'efine, 'f'unction, - * 'm'ethod, 'v'ariable) + * 'm'ethod(class), 'v'ariable(class) 'g'lobal variable) * @param identifier * current identifier * @param line @@ -79,7 +84,7 @@ public class IdentifierIndexManager { return; } catch (InvalidInputException e) { // ignore errors - e.printStackTrace(); +// e.printStackTrace(); } fToken = TokenNameERROR; } @@ -165,7 +170,7 @@ public class IdentifierIndexManager { ident[5]=='e') { if (fToken == TokenNameLPAREN) { getNextToken(); - if (fToken == TokenNameStringLiteral) { + if (fToken == TokenNameStringDoubleQuote) { ident = fScanner.getCurrentStringLiteralSource(); addIdentifierInformation('d', ident, buf, phpdocOffset, phpdocLength); @@ -173,6 +178,19 @@ public class IdentifierIndexManager { } } } + } else if (fToken == TokenNameglobal) { + // global variable + while (fToken != TokenNameEOF && fToken != TokenNameERROR && + fToken != TokenNameSEMICOLON && + fToken != TokenNameLBRACE && + fToken != TokenNameRBRACE ) { + getNextToken(); + if (fToken == TokenNameVariable) { + ident = fScanner.getCurrentIdentifierSource(); + addIdentifierInformation('g', ident, buf, phpdocOffset, + phpdocLength); + } + } } else if (fToken == TokenNameLBRACE) { getNextToken(); counter++; @@ -191,7 +209,7 @@ public class IdentifierIndexManager { e.printStackTrace(); } } - public void parseIdentifiers(char[] charArray, StringBuffer buf) { + synchronized public void parseIdentifiers(char[] charArray, StringBuffer buf) { char[] ident; String identifier; int counter = 0; @@ -240,6 +258,12 @@ public class IdentifierIndexManager { } parseDeclarations(ident, buf, true); } + } else if (fToken == TokenNameVariable) { + // global variable + ident = fScanner.getCurrentIdentifierSource(); + addIdentifierInformation('g', ident, buf, phpdocOffset, + phpdocLength); + getNextToken(); } else if (fToken == TokenNameIdentifier) { ident = fScanner.getCurrentIdentifierSource(); getNextToken(); @@ -252,7 +276,7 @@ public class IdentifierIndexManager { ident[5]=='e') { if (fToken == TokenNameLPAREN) { getNextToken(); - if (fToken == TokenNameStringLiteral) { + if (fToken == TokenNameStringDoubleQuote) { ident = fScanner.getCurrentStringLiteralSource(); addIdentifierInformation('d', ident, buf, phpdocOffset, phpdocLength); @@ -319,18 +343,6 @@ public class IdentifierIndexManager { // InputStream iStream; LineCreator lineCreator = createLineCreator(); try { - // iStream = fileToParse.getContents(); - // - // StringBuffer buf = new StringBuffer(); - // int c0; - // try { - // while ((c0 = iStream.read()) != (-1)) { - // buf.append((char) c0); - // } - // } catch (IOException e) { - // return; - // } - addInputStream(new BufferedInputStream(fileToParse.getContents()), fileToParse.getFullPath().toString(), lineCreator); } catch (CoreException e1) { // TODO Auto-generated catch block @@ -343,21 +355,18 @@ public class IdentifierIndexManager { * @throws CoreException */ public void addInputStream(InputStream stream, String filePath, LineCreator lineCreator) throws CoreException { -// InputStream stream; try { - // stream = new BufferedInputStream(fileToParse.getContents()); StringBuffer lineBuffer = new StringBuffer(); lineBuffer.append(filePath); int lineLength = lineBuffer.length(); - // lineCreator.parseIdentifiers(buf.toString().toCharArray(), - // lineBuffer); lineCreator.parseIdentifiers(Util.getInputStreamAsCharArray(stream, -1, null), lineBuffer); - if (lineLength != lineBuffer.length()) { - addLine(lineBuffer.toString()); - } - } catch (IOException e) { - e.printStackTrace(); +// if (lineLength != lineBuffer.length()) { + // always add the file for Open Include Action + addLine(lineBuffer.toString()); +// } + } catch (IOException e) { + e.printStackTrace(); } finally { try { if (stream != null) { @@ -414,6 +423,12 @@ public class IdentifierIndexManager { 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 'k' : // constructor function name identifier = token.substring(1); @@ -457,6 +472,7 @@ public class IdentifierIndexManager { } break; default : + PHPeclipsePlugin.log(IStatus.ERROR, "Unknown token character in IdentifierIndexManager: "+token.charAt(0)); identifier = null; phpIdentifier = null; classname = null; @@ -482,9 +498,9 @@ public class IdentifierIndexManager { } } } - if (tokenExists) { +// if (tokenExists) { fFileMap.put(phpFileName, line); - } +// } } /** * Change the information for a given IFile resource @@ -566,7 +582,8 @@ public class IdentifierIndexManager { //System.out.println(token); } else { return; - } + } + int offset = -1; // all the other tokens are identifiers: while (tokenizer.hasMoreTokens()) { token = tokenizer.nextToken(); @@ -591,6 +608,12 @@ public class IdentifierIndexManager { 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 'k' : // constructor function name identifier = token.substring(1); @@ -603,6 +626,18 @@ public class IdentifierIndexManager { phpIdentifier = new PHPIdentifierLocation(identifier, PHPIdentifier.METHOD, phpFileName, classname); break; + case 'o' : + // offset information + identifier = null; + break; + case 'p' : + // PHPdoc offset information + identifier = null; + break; + case 'l' : + // PHPdoc length information + identifier = null; + break; case 'v' : // variable inside a class identifier = token.substring(1); @@ -610,6 +645,7 @@ public class IdentifierIndexManager { PHPIdentifier.VARIABLE, phpFileName, classname); break; default : + PHPeclipsePlugin.log(IStatus.ERROR, "Unknown token character in IdentifierIndexManager: "+token.charAt(0)); identifier = null; phpIdentifier = null; classname = null; @@ -663,4 +699,22 @@ public class IdentifierIndexManager { public SortedMap getIdentifierMap() { return fIndentifierMap; } + + synchronized public List getFileList(String filePattern) { + Set set = fFileMap.keySet(); + if (set.isEmpty()) { + return null; + } + Iterator iter = set.iterator(); + ArrayList list = new ArrayList(); + String fileName; + int index; + while(iter.hasNext()) { + fileName = (String) iter.next(); + if ((index=fileName.indexOf(filePattern))!=-1 && fileName.length()==(index+filePattern.length())) { + list.add(fileName); + } + } + return list; + } } \ No newline at end of file