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
*
*
* @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
ident[5]=='e') {
if (fToken == TokenNameLPAREN) {
getNextToken();
- if (fToken == TokenNameStringLiteral) {
+ if (fToken == TokenNameStringDoubleQuote) {
ident = fScanner.getCurrentStringLiteralSource();
addIdentifierInformation('d', ident, buf, phpdocOffset,
phpdocLength);
}
}
}
+ } 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++;
e.printStackTrace();
}
}
- public void parseIdentifiers(char[] charArray, StringBuffer buf) {
+ synchronized public void parseIdentifiers(char[] charArray, StringBuffer buf) {
char[] ident;
String identifier;
int counter = 0;
}
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();
ident[5]=='e') {
if (fToken == TokenNameLPAREN) {
getNextToken();
- if (fToken == TokenNameStringLiteral) {
+ if (fToken == TokenNameStringDoubleQuote) {
ident = fScanner.getCurrentStringLiteralSource();
addIdentifierInformation('d', ident, buf, phpdocOffset,
phpdocLength);
// 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);
+ addInputStream(new BufferedInputStream(fileToParse.getContents()), fileToParse.getProjectRelativePath().toString(), lineCreator);
} catch (CoreException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
* @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) {
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);
}
break;
default :
+ PHPeclipsePlugin.log(IStatus.ERROR, "Unknown token character in IdentifierIndexManager: "+token.charAt(0));
identifier = null;
phpIdentifier = null;
classname = null;
}
}
}
- if (tokenExists) {
+// if (tokenExists) {
fFileMap.put(phpFileName, line);
- }
+// }
}
/**
* Change the information for a given IFile resource
//System.out.println(token);
} else {
return;
- }
+ }
+ int offset = -1;
// all the other tokens are identifiers:
while (tokenizer.hasMoreTokens()) {
token = tokenizer.nextToken();
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);
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);
PHPIdentifier.VARIABLE, phpFileName, classname);
break;
default :
+ PHPeclipsePlugin.log(IStatus.ERROR, "Unknown token character in IdentifierIndexManager: "+token.charAt(0));
identifier = null;
phpIdentifier = null;
classname = null;
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