use of com.python.pydev.analysis.pep8.Pep8Visitor in project Pydev by fabioz.
the class OccurrencesAnalyzer method analyzeDocument.
public IMessage[] analyzeDocument(IPythonNature nature, final SourceModule module, final IAnalysisPreferences prefs, final IDocument document, final IProgressMonitor monitor, IIndentPrefs indentPrefs) {
// Do pep8 in a thread.
final List<IMessage> pep8Messages = new ArrayList<>();
Thread t = new Thread() {
@Override
public void run() {
pep8Messages.addAll(new Pep8Visitor().getMessages(module, document, monitor, prefs));
}
};
t.start();
OccurrencesVisitor visitor = new OccurrencesVisitor(nature, module.getName(), module, prefs, document, monitor);
try {
SimpleNode ast = module.getAst();
if (ast != null) {
if (nature.startRequests()) {
try {
ast.accept(visitor);
} finally {
nature.endRequests();
}
}
}
} catch (OperationCanceledException e) {
throw e;
} catch (Exception e) {
Log.log(IStatus.ERROR, ("Error while visiting " + module.getName() + " (" + module.getFile() + ")"), e);
}
List<IMessage> messages = new ArrayList<IMessage>();
if (!monitor.isCanceled()) {
messages.addAll(visitor.getMessages());
try {
FileUtils.getPythonFileEncoding(document, module.getName());
} catch (PyUnsupportedEncodingException e) {
Message m = new Message(IAnalysisPreferences.TYPE_INVALID_ENCODING, e.getMessage(), e.getLine(), e.getLine(), e.getColumn(), e.getColumn() + e.getMessage().length(), prefs);
messages.add(m);
}
try {
messages.addAll(TabNanny.analyzeDoc(document, prefs, module.getName(), indentPrefs, monitor));
} catch (Exception e) {
// just to be safe... (could happen if the document changes during the process).
Log.log(e);
}
}
if (!monitor.isCanceled()) {
try {
t.join();
messages.addAll(pep8Messages);
} catch (InterruptedException e) {
// If interrupted keep on going as it is.
}
}
return messages.toArray(new IMessage[messages.size()]);
}
Aggregations