use of org.python.pydev.core.MisconfigurationException in project Pydev by fabioz.
the class PySetNextTarget method setNextToLine.
@Override
public boolean setNextToLine(IWorkbenchPart part, ISelection selection, ISuspendResume target) throws CoreException {
// System.out.println("Run to line:"+target);
PyStackFrame stack = null;
if (target instanceof PyStackFrame) {
stack = (PyStackFrame) target;
target = stack.getThread();
}
if (!(part instanceof PyEdit)) {
return false;
}
PyEdit pyEdit = (PyEdit) part;
SimpleNode ast = pyEdit.getAST();
if (ast == null) {
IDocument doc = pyEdit.getDocument();
SourceModule sourceModule;
IPythonNature nature = null;
try {
nature = pyEdit.getPythonNature();
} catch (MisconfigurationException e) {
// Let's try to find a suitable nature
File editorFile = pyEdit.getEditorFile();
if (editorFile == null || !editorFile.exists()) {
Log.log(e);
return false;
}
nature = InterpreterManagersAPI.getInfoForFile(editorFile).o1;
}
if (nature == null) {
Log.log("Unable to determine nature!");
return false;
}
try {
sourceModule = AbstractModule.createModuleFromDoc("", pyEdit.getEditorFile(), doc, nature, true);
} catch (MisconfigurationException e) {
Log.log(e);
return false;
}
ast = sourceModule.getAst();
}
if (ast == null) {
Log.log("Cannot determine context to run to.");
return false;
}
if (target instanceof PyThread && selection instanceof ITextSelection) {
ITextSelection textSelection = (ITextSelection) selection;
PyThread pyThread = (PyThread) target;
if (!pyThread.isPydevThread()) {
int sourceLine = stack.getLineNumber();
int targetLine = textSelection.getStartLine();
if (!NodeUtils.isValidContextForSetNext(ast, sourceLine, targetLine)) {
return false;
}
String functionName = NodeUtils.getContextName(targetLine, ast);
if (functionName == null) {
// global context
functionName = "";
} else {
functionName = FullRepIterable.getLastPart(functionName).trim();
}
pyThread.setNextStatement(targetLine + 1, functionName);
return true;
}
}
return true;
}
use of org.python.pydev.core.MisconfigurationException in project Pydev by fabioz.
the class PyParser method reparseDocument.
/**
* Parses the document, generates error annotations
*
* @param argsToReparse: will be passed to fireParserError / fireParserChanged so that the IParserObserver2
* can check it. This is useful when the reparse was done with some specific thing in mind, so that its requestor
* can pass some specific thing to the parser observers
*
* @return a tuple with the SimpleNode root(if parsed) and the error (if any).
* if we are able to recover from a reparse, we have both, the root and the error.
*/
@Override
public ParseOutput reparseDocument(Object... argsToReparse) {
// get the document ast and error in object
int version;
AdditionalGrammarVersionsToCheck additionalGrammarsToCheck = null;
try {
version = grammarVersionProvider.getGrammarVersion();
additionalGrammarsToCheck = grammarVersionProvider.getAdditionalGrammarVersions();
} catch (MisconfigurationException e1) {
// Ok, we cannot get it... let's put on the default
version = IGrammarVersionProvider.LATEST_GRAMMAR_PY3_VERSION;
}
long documentTime = System.currentTimeMillis();
ParseOutput obj = reparseDocument(new ParserInfo(document, version, true, additionalGrammarsToCheck));
IFile original = null;
IAdaptable adaptable = null;
if (input == null) {
return obj;
}
original = (input instanceof IAdaptable) ? ((IAdaptable) input).getAdapter(IFile.class) : null;
if (original != null) {
adaptable = original;
} else {
// probably an external file, may have some location provider mechanism
// it may be org.eclipse.ui.internal.editors.text.JavaFileEditorInput
adaptable = (IAdaptable) input;
}
// delete the markers
if (original != null) {
try {
deleteErrorMarkers(original);
} catch (ResourceException e) {
// so, there is no need to log this failure
if (original.exists()) {
Log.log(e);
}
} catch (CoreException e) {
Log.log(e);
}
} else if (adaptable == null) {
// ok, we have nothing... maybe we are in tests...
if (!PyParser.ACCEPT_NULL_INPUT_EDITOR) {
throw new RuntimeException("Null input editor received in parser!");
}
}
if (disposed) {
// if it was disposed in this time, don't fire any notification nor return anything valid.
return new ParseOutput();
}
ErrorParserInfoForObservers errorInfo = null;
if (obj.error instanceof ParseException || obj.error instanceof TokenMgrError) {
errorInfo = new ErrorParserInfoForObservers(obj.error, adaptable, document, argsToReparse);
}
if (obj.ast != null) {
// Ok, reparse successful, lets erase the markers that are in the editor we just parsed
// Note: we may get the ast even if errors happen (and we'll notify in that case too).
ChangedParserInfoForObservers info = new ChangedParserInfoForObservers(obj.ast, obj.modificationStamp, adaptable, document, documentTime, errorInfo, argsToReparse);
fireParserChanged(info);
}
if (errorInfo != null) {
fireParserError(errorInfo);
}
if (postParserListeners.size() > 0) {
ArrayList<IPostParserListener> tempList = new ArrayList<>(postParserListeners);
for (IPostParserListener iParserObserver : tempList) {
iParserObserver.participantsNotified(argsToReparse);
}
}
return obj;
}
use of org.python.pydev.core.MisconfigurationException in project Pydev by fabioz.
the class DjangoNewProjectPage method getNextPage.
@Override
public IWizardPage getNextPage() {
String projectType = this.getProjectType();
IInterpreterManager interpreterManager;
if (IPythonNature.Versions.ALL_JYTHON_VERSIONS.contains(projectType)) {
interpreterManager = InterpreterManagersAPI.getJythonInterpreterManager();
} else if (IPythonNature.Versions.ALL_IRONPYTHON_VERSIONS.contains(projectType)) {
interpreterManager = InterpreterManagersAPI.getIronpythonInterpreterManager();
} else {
// if others fail, consider it python
interpreterManager = InterpreterManagersAPI.getPythonInterpreterManager();
}
try {
String projectInterpreter = this.getProjectInterpreter();
IInterpreterInfo interpreterInfo;
if (projectInterpreter.toLowerCase().equals("default")) {
interpreterInfo = interpreterManager.getDefaultInterpreterInfo(false);
} else {
interpreterInfo = interpreterManager.getInterpreterInfo(projectInterpreter, new NullProgressMonitor());
}
IModule module = interpreterInfo.getModulesManager().getModuleWithoutBuiltins("django.core.__init__", null, false, new BaseModuleRequest(false));
if (module == null) {
DjangoNotAvailableWizardPage page = new DjangoNotAvailableWizardPage("Django not available", interpreterInfo);
page.setWizard(this.getWizard());
return page;
}
} catch (MisconfigurationException e) {
ErrorWizardPage page = new ErrorWizardPage("Unexpected error.", "An unexpected error happened:\n" + e.getMessage());
page.setWizard(this.getWizard());
return page;
}
return super.getNextPage();
}
use of org.python.pydev.core.MisconfigurationException in project Pydev by fabioz.
the class PrettyPrinterV2 method createDefaultPrefs.
public static PrettyPrinterPrefsV2 createDefaultPrefs(IGrammarVersionProvider versionProvider, IIndentPrefs indentPrefs, String endLineDelim) {
if (versionProvider == null) {
versionProvider = new IGrammarVersionProvider() {
@Override
public int getGrammarVersion() throws MisconfigurationException {
return IGrammarVersionProvider.LATEST_GRAMMAR_PY3_VERSION;
}
@Override
public AdditionalGrammarVersionsToCheck getAdditionalGrammarVersions() throws MisconfigurationException {
return null;
}
};
}
PrettyPrinterPrefsV2 prettyPrinterPrefs = new PrettyPrinterPrefsV2(endLineDelim, indentPrefs.getIndentationString(), versionProvider);
prettyPrinterPrefs.setSpacesAfterComma(1);
prettyPrinterPrefs.setSpacesBeforeComment(1);
prettyPrinterPrefs.setLinesAfterMethod(1);
prettyPrinterPrefs.setLinesAfterClass(2);
prettyPrinterPrefs.setLinesAfterSuite(1);
return prettyPrinterPrefs;
}
use of org.python.pydev.core.MisconfigurationException in project Pydev by fabioz.
the class ModuleAdapter method resolveClass.
/**
* Get a class adapter for a given class contained in this module.
*
* @param name the name of the class we want to resolve.
*
* @return an adapter to the class.
*/
public IClassDefAdapter resolveClass(String name) {
CompletionCache completionCache = new CompletionCache();
HashSet<String> toResolve = new HashSet<String>();
toResolve.add(name);
Set<IClassDefAdapter> resolved;
try {
resolved = resolveImportedClass(toResolve, completionCache);
} catch (MisconfigurationException e) {
throw new RuntimeException(e);
}
if (toResolve.size() == 1) {
return resolved.iterator().next();
}
return null;
}
Aggregations