use of org.python.pydev.core.MisconfigurationException in project Pydev by fabioz.
the class AdditionalSystemInterpreterInfo method getPythonPathFolders.
@Override
protected Set<String> getPythonPathFolders() {
Set<String> ret = new HashSet<>();
try {
IInterpreterInfo interpreterInfo = this.manager.getInterpreterInfo(additionalInfoInterpreter, new NullProgressMonitor());
ret.addAll(interpreterInfo.getPythonPath());
} catch (MisconfigurationException e) {
Log.log(e);
}
return ret;
}
use of org.python.pydev.core.MisconfigurationException in project Pydev by fabioz.
the class PyGoToDefinition method findDefinitionsAndOpen.
public ItemPointer[] findDefinitionsAndOpen(boolean doOpenDefinition) {
request = null;
ps = PySelectionFromEditor.createPySelectionFromEditor(getTextEditor());
final PyEdit pyEdit = getPyEdit();
RefactoringRequest refactoringRequest;
try {
refactoringRequest = getRefactoringRequest();
} catch (MisconfigurationException e1) {
Log.log(e1);
return new ItemPointer[0];
}
final Shell shell = EditorUtils.getShell();
try {
if (areRefactorPreconditionsOK(refactoringRequest)) {
boolean acceptTypeshed = false;
boolean findInAdditionalInfo = false;
ItemPointer[] defs = findDefinition(pyEdit, acceptTypeshed, findInAdditionalInfo);
boolean retry = defs == null || defs.length == 0;
if (!retry) {
if (defs.length == 1) {
if (defs[0].definition == null) {
retry = true;
} else if (defs[0].definition.module == null) {
retry = true;
} else if (defs[0].definition.module.getFile() == null) {
retry = true;
}
}
}
if (retry) {
acceptTypeshed = true;
findInAdditionalInfo = true;
defs = findDefinition(pyEdit, acceptTypeshed, findInAdditionalInfo);
}
if (doOpenDefinition) {
openDefinition(defs, pyEdit, shell);
}
return defs;
}
} catch (Exception e) {
Log.log(e);
String msg = e.getMessage();
if (msg == null) {
msg = "Unable to get error msg (null)";
}
ErrorDialog.openError(shell, "Error", "Unable to do requested action", new Status(Status.ERROR, PydevPlugin.getPluginID(), 0, msg, e));
}
return null;
}
use of org.python.pydev.core.MisconfigurationException in project Pydev by fabioz.
the class PyRenameInFileAction method fillWithOccurrences.
/**
* Puts the found positions referente to the occurrences in the group
*
* @param document the document that will contain this positions
* @param group the group that will contain this positions
* @param ps the selection used
* @return
*
* @throws BadLocationException
* @throws OperationCanceledException
* @throws CoreException
* @throws MisconfigurationException
*/
private boolean fillWithOccurrences(IDocument document, LinkedPositionGroup group, IProgressMonitor monitor, PySelection ps) throws BadLocationException, OperationCanceledException, CoreException, MisconfigurationException {
RefactoringRequest req = MarkOccurrencesJob.getRefactoringRequest(pyEdit, MarkOccurrencesJob.getRefactorAction(pyEdit), ps);
if (monitor.isCanceled()) {
return false;
}
PyRenameEntryPoint processor = new PyRenameEntryPoint(req);
// process it to get what we need
processor.checkInitialConditions(monitor);
processor.checkFinalConditions(monitor, null);
HashSet<ASTEntry> occurrences = processor.getOccurrences();
if (monitor.isCanceled()) {
return false;
}
// used so that we don't add duplicates
Set<Tuple<Integer, Integer>> found = new HashSet<Tuple<Integer, Integer>>();
List<ProposalPosition> groupPositions = new ArrayList<ProposalPosition>();
if (occurrences != null) {
// first, just sort by position (line, col)
ArrayList<ASTEntry> sortedOccurrences = new ArrayList<ASTEntry>(occurrences);
Collections.sort(sortedOccurrences, new Comparator<ASTEntry>() {
@Override
public int compare(ASTEntry o1, ASTEntry o2) {
int thisVal = o1.node.beginLine;
int anotherVal = o2.node.beginLine;
int ret;
if (thisVal == anotherVal) {
// if it's in the same line, let's sort by column
thisVal = o1.node.beginColumn;
anotherVal = o2.node.beginColumn;
ret = (thisVal < anotherVal ? -1 : (thisVal == anotherVal ? 0 : 1));
} else {
ret = (thisVal < anotherVal ? -1 : 1);
}
return ret;
}
});
// now, gather positions to add to the group
int i = 0;
int firstPosition = -1;
int absoluteCursorOffset = ps.getAbsoluteCursorOffset();
for (ASTEntry entry : sortedOccurrences) {
try {
IRegion lineInformation = document.getLineInformation(entry.node.beginLine - 1);
int colDef = NodeUtils.getClassOrFuncColDefinition(entry.node) - 1;
int offset = lineInformation.getOffset() + colDef;
int len = req.qualifier.length();
Tuple<Integer, Integer> foundAt = new Tuple<Integer, Integer>(offset, len);
if (!found.contains(foundAt)) {
i++;
ProposalPosition proposalPosition = new ProposalPosition(document, offset, len, i, new ICompletionProposal[0]);
found.add(foundAt);
groupPositions.add(proposalPosition);
if (offset <= absoluteCursorOffset && absoluteCursorOffset < offset + len) {
firstPosition = i;
}
}
} catch (Exception e) {
Log.log(e);
return false;
}
}
if (firstPosition != -1) {
ArrayList<ProposalPosition> newGroupPositions = new ArrayList<ProposalPosition>();
// add from current to end
for (i = firstPosition - 1; i < groupPositions.size(); i++) {
newGroupPositions.add(groupPositions.get(i));
}
// and now from the start up to the current
for (i = 0; i < firstPosition - 1; i++) {
newGroupPositions.add(groupPositions.get(i));
}
groupPositions = newGroupPositions;
}
for (ProposalPosition proposalPosition : groupPositions) {
group.addPosition(proposalPosition);
}
}
return groupPositions.size() > 0;
}
use of org.python.pydev.core.MisconfigurationException in project Pydev by fabioz.
the class AbstractInterpreterManager method getBuiltinMod.
@Override
public IModule getBuiltinMod(String projectInterpreterName, IModuleRequestState moduleRequest) {
// Cache with the internal name.
projectInterpreterName = getInternalName(projectInterpreterName);
if (projectInterpreterName == null) {
return null;
}
String cacheName = projectInterpreterName + "_" + moduleRequest.getAcceptTypeshed();
IModule mod = builtinMod.get(cacheName);
if (mod != null) {
return mod;
}
try {
InterpreterInfo interpreterInfo = this.getInterpreterInfo(projectInterpreterName, null);
ISystemModulesManager modulesManager = interpreterInfo.getModulesManager();
mod = modulesManager.getBuiltinModule("__builtin__", false, moduleRequest);
if (mod == null) {
// Python 3.0 has builtins and not __builtin__
mod = modulesManager.getBuiltinModule("builtins", false, moduleRequest);
}
if (mod != null) {
builtinMod.put(cacheName, mod);
}
} catch (MisconfigurationException e) {
Log.log(e);
}
return builtinMod.get(cacheName);
}
use of org.python.pydev.core.MisconfigurationException in project Pydev by fabioz.
the class PythonNature method getVersionAndError.
@Override
public Tuple<String, String> getVersionAndError(boolean translateIfInterpreter) throws CoreException {
if (project != null) {
if (versionPropertyCache == null) {
String storeVersion = getStore().getPropertyFromXml(getPythonProjectVersionQualifiedName());
if (storeVersion == null) {
// there is no such property set (let's set it to the default)
// will set the versionPropertyCache too
setVersion(getDefaultVersion(false), null);
} else {
// now, before returning and setting in the cache, let's make sure it's a valid version.
if (!IPythonNature.Versions.ALL_VERSIONS_ANY_FLAVOR.contains(storeVersion)) {
Log.log("The stored version is invalid (" + storeVersion + "). Setting default.");
// will set the versionPropertyCache too
setVersion(getDefaultVersion(false), null);
} else {
// Ok, it's correct.
versionPropertyCache = storeVersion;
}
}
}
} else {
String msg = "Trying to get version without project set. Returning default.";
Log.log(msg);
return new Tuple<String, String>(getDefaultVersion(translateIfInterpreter), msg);
}
if (versionPropertyCache == null) {
String msg = "The cached version is null. Returning default.";
Log.log(msg);
return new Tuple<String, String>(getDefaultVersion(translateIfInterpreter), msg);
} else if (!IPythonNature.Versions.ALL_VERSIONS_ANY_FLAVOR.contains(versionPropertyCache)) {
String msg = "The cached version (" + versionPropertyCache + ") is invalid. Returning default.";
Log.log(msg);
return new Tuple<String, String>(getDefaultVersion(translateIfInterpreter), msg);
}
if (translateIfInterpreter && versionPropertyCache.endsWith(IPythonNature.Versions.INTERPRETER_VERSION)) {
Tuple<String, String> split = StringUtils.splitOnFirst(versionPropertyCache, ' ');
String errorMessage;
try {
IInterpreterInfo info = this.getProjectInterpreter();
String version = info.getVersion();
if (version != null) {
return new Tuple<String, String>(IPythonNature.Versions.convertToInternalVersion(new FastStringBuffer(split.o1, 6).append(' '), version), null);
} else {
errorMessage = "Unable to get version from interpreter info: " + info.getNameForUI() + " - " + info.getExecutableOrJar();
Log.log(errorMessage);
}
} catch (MisconfigurationException | PythonNatureWithoutProjectException e) {
Log.log(e);
errorMessage = e.getMessage();
}
return new Tuple<String, String>(split.o1 + " " + "2.7", errorMessage + " (in project: " + getProject() + ")");
}
return new Tuple<String, String>(versionPropertyCache, null);
}
Aggregations