* @param edit this is the editor to which a parser should be attached.
*/
public synchronized void attachParserTo(IPyEdit edit) {
synchronized (lock) {
//remove previous...
IPyParser existingParser = getParser(edit);
if (existingParser != null) {
//it was already bounded to a parser, so, we have to remove that one before
//attaching a new one
notifyEditorDisposed(edit);
}
for (Map.Entry<IPyParser, List<IPyEdit>> entry : parsers.entrySet()) {
for (IPyEdit curr : entry.getValue()) {
if (curr.hasSameInput(edit)) {
//do nothing, as it is already binded to a similar document (just force a reparse
//and add it to the list of edits for that parser)
IPyParser p = getParser(curr);
makeParserAssociations(edit, p);
p.forceReparse();
return;
}
}
}
if (DEBUG) {
System.out.println("Creating new parser.");
}
IPyParser pyParser = new PyParser(edit);
boolean useAnalysisOnlyOnDocSave = useAnalysisOnlyOnDocSave();
pyParser.resetTimeoutPreferences(useAnalysisOnlyOnDocSave);
makeParserAssociations(edit, pyParser);
IDocument doc = edit.getDocument();
pyParser.setDocument(doc, edit.getEditorInput());
if (DEBUG) {
System.out.println("Available parsers:" + this.parsers.size());
}
}