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.obfuscator.PHPIdentifier;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
/**
private Scanner fScanner;
private int fToken;
public LineCreator() {
- fScanner = new Scanner(true, false);
+ fScanner = new Scanner(true, false, false, false, true, null, null);
}
/**
* Add the information of the current identifier to the line
return;
} catch (InvalidInputException e) {
// ignore errors
+// e.printStackTrace();
}
fToken = TokenNameERROR;
}
e.printStackTrace();
}
}
- public void parseIdentifiers(char[] charArray, StringBuffer buf) {
+ synchronized public void parseIdentifiers(char[] charArray, StringBuffer buf) {
char[] ident;
String identifier;
int counter = 0;
fToken = TokenNameEOF;
getNextToken();
try {
- while (fToken != TokenNameEOF && fToken != TokenNameERROR) {
+ while (fToken != TokenNameEOF) { // && fToken != TokenNameERROR) {
phpdocOffset = -1;
if (fToken == TokenNameCOMMENT_PHPDOC) {
phpdocOffset = fScanner.getCurrentTokenStartPosition();
}
return true;
}
+ public LineCreator createLineCreator() {
+ return new LineCreator();
+ }
/**
* Add the information for a given IFile resource
*
*/
public void addFile(IFile fileToParse) {
// InputStream iStream;
- LineCreator lineCreator = new LineCreator();
+ 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;
- // }
- InputStream stream = null;
+ addInputStream(new BufferedInputStream(fileToParse.getContents()), fileToParse.getFullPath().toString(), lineCreator);
+ } catch (CoreException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ }
+ /**
+ * @param fileToParse
+ * @param lineCreator
+ * @throws CoreException
+ */
+ public void addInputStream(InputStream stream, String filePath, LineCreator lineCreator) throws CoreException {
+ try {
+ StringBuffer lineBuffer = new StringBuffer();
+ lineBuffer.append(filePath);
+ int lineLength = lineBuffer.length();
+ lineCreator.parseIdentifiers(Util.getInputStreamAsCharArray(stream, -1,
+ null), lineBuffer);
+// if (lineLength != lineBuffer.length()) {
+ // always add the file for Open Include Action
+ addLine(lineBuffer.toString());
+// }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
try {
- stream = new BufferedInputStream(fileToParse.getContents());
- StringBuffer lineBuffer = new StringBuffer();
- lineBuffer.append(fileToParse.getFullPath().toString());
- 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());
+ if (stream != null) {
+ stream.close();
}
} catch (IOException e) {
- return;
- } finally {
- try {
- if (stream != null) {
- stream.close();
- }
- } catch (IOException e) {
- }
}
- } catch (CoreException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
}
}
/**
}
}
}
- if (tokenExists) {
+// if (tokenExists) {
fFileMap.put(phpFileName, line);
- }
+// }
}
/**
* Change the information for a given IFile resource
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