use of org.python.pydev.core.IPyEdit in project Pydev by fabioz.
the class AdditionalInfoIntegrityChecker method onCreateActions.
@Override
public void onCreateActions(ListResourceBundle resources, final BaseEditor baseEditor, IProgressMonitor monitor) {
IPyEdit edit = (IPyEdit) baseEditor;
edit.addOfflineActionListener("--internal-test-modules", new Action() {
@Override
public void run() {
List<IPythonNature> allPythonNatures = PythonNature.getAllPythonNatures();
StringBuffer buf = new StringBuffer();
try {
for (IPythonNature nature : allPythonNatures) {
buf.append(checkIntegrity(nature, new NullProgressMonitor(), true));
}
} catch (MisconfigurationException e) {
buf.append(e.getMessage());
}
PyDialogHelpers.showString(buf.toString());
}
}, "Used just for testing (do not use).", true);
}
use of org.python.pydev.core.IPyEdit in project Pydev by fabioz.
the class AbstractAnalysisMarkersParticipants method getProps.
@Override
public List<ICompletionProposalHandle> getProps(PySelection ps, IImageCache imageCache, File f, IPythonNature nature, IPyEdit edit, int offset) throws BadLocationException {
fillParticipants();
PySourceViewer s = ((PyEdit) edit).getPySourceViewer();
int line = ps.getLineOfOffset(offset);
OrderedSet<MarkerAnnotationAndPosition> markersAtLine = new OrderedSet<MarkerAnnotationAndPosition>();
// Add it to a set to make sure that the entries are unique.
// -- i.e.: the code analysis seems to be creating 2 markers in the following case (when sys is undefined):
// sys.call1().call2()
// So, we add it to a set to make sure we'll only analyze unique markers.
// Note that it'll check equality by the marker type and text (not by position), so, if a given error
// appears twice in the same line being correct, we'll only show the options once here (which is what
// we want).
List<MarkerAnnotationAndPosition> markersAtLine2 = s.getMarkersAtLine(line, getMarkerType());
markersAtLine.addAll(markersAtLine2);
ArrayList<ICompletionProposalHandle> props = new ArrayList<ICompletionProposalHandle>();
if (markersAtLine != null) {
IAnalysisPreferences analysisPreferences = new AnalysisPreferences(edit);
String currLine = ps.getLine();
for (MarkerAnnotationAndPosition marker : markersAtLine) {
for (IAnalysisMarkersParticipant participant : participants) {
try {
participant.addProps(marker, analysisPreferences, currLine, ps, offset, nature, (PyEdit) edit, props);
} catch (Exception e) {
Log.log("Error when getting proposals.", e);
}
}
}
}
return props;
}
use of org.python.pydev.core.IPyEdit in project Pydev by fabioz.
the class OverrideMethodCompletionProposal method applyOnDocument.
public int applyOnDocument(ITextViewer viewer, IDocument document, char trigger, int stateMask, int offset) {
IGrammarVersionProvider versionProvider = null;
IPyEdit edit = null;
if (viewer instanceof IPySourceViewer) {
IPySourceViewer pySourceViewer = (IPySourceViewer) viewer;
versionProvider = edit = pySourceViewer.getEdit();
} else {
versionProvider = new IGrammarVersionProvider() {
@Override
public int getGrammarVersion() throws MisconfigurationException {
return IGrammarVersionProvider.LATEST_GRAMMAR_PY3_VERSION;
}
@Override
public AdditionalGrammarVersionsToCheck getAdditionalGrammarVersions() throws MisconfigurationException {
return null;
}
};
}
String delimiter = PySelection.getDelimiter(document);
PyAstFactory factory = new PyAstFactory(new AdapterPrefs(delimiter, versionProvider));
// Note that the copy won't have a parent.
stmtType overrideBody = factory.createOverrideBody(this.functionDef, parentClassName, currentClassName);
FunctionDef functionDef = this.functionDef.createCopy(false);
functionDef.body = new stmtType[] { overrideBody != null ? overrideBody : new Pass() };
try {
MakeAstValidForPrettyPrintingVisitor.makeValid(functionDef);
} catch (Exception e) {
Log.log(e);
}
IIndentPrefs indentPrefs;
if (edit != null) {
indentPrefs = edit.getIndentPrefs();
} else {
indentPrefs = DefaultIndentPrefs.get(null);
}
String printed = NodeUtils.printAst(indentPrefs, edit, functionDef, delimiter);
PySelection ps = new PySelection(document, offset);
try {
String lineContentsToCursor = ps.getLineContentsToCursor();
int defIndex = lineContentsToCursor.indexOf("def");
int defOffset = ps.getLineOffset() + defIndex;
printed = StringUtils.indentTo(printed, lineContentsToCursor.substring(0, defIndex), false);
printed = StringUtils.rightTrim(printed);
this.fLen += offset - defOffset;
document.replace(defOffset, this.fLen, printed);
return defOffset + printed.length();
} catch (BadLocationException x) {
// ignore
}
return -1;
}
use of org.python.pydev.core.IPyEdit in project Pydev by fabioz.
the class AssistImportToLocal method getProps.
@Override
public List<ICompletionProposalHandle> getProps(PySelection ps, IImageCache imageCache, File f, IPythonNature nature, IPyEdit edit, int offset) throws BadLocationException, MisconfigurationException {
boolean addOnlyGlobalImports = true;
boolean allowBadInput = false;
Tuple<String, Integer> currToken = ps.getCurrToken();
List<ICompletionProposalHandle> ret = new ArrayList<ICompletionProposalHandle>();
if (currToken.o1 != null && currToken.o1.length() > 0) {
int startOfImportLine = ps.getStartOfImportLine();
if (startOfImportLine == -1) {
return ret;
}
int startOffset = ps.getLineOffset(startOfImportLine);
PyImportsIterator pyImportsIterator = new PyImportsIterator(ps.getDoc(), addOnlyGlobalImports, allowBadInput, startOffset);
OUT: while (pyImportsIterator.hasNext()) {
ImportHandle handle = pyImportsIterator.next();
List<ImportHandleInfo> importInfo = handle.getImportInfo();
for (ImportHandleInfo importHandleInfo : importInfo) {
List<String> importedStr = importHandleInfo.getImportedStr();
int startLine = importHandleInfo.getStartLine();
int endLine = importHandleInfo.getEndLine();
if (ps.getLineOfOffset() < startLine) {
continue;
}
if (ps.getLineOfOffset() > endLine) {
// Stop iterating.
break OUT;
}
for (String s : importedStr) {
if (s.equals(currToken.o1)) {
// Found!
IProgressMonitor monitor = new NullProgressMonitor();
final RefactoringRequest req = PyRefactorAction.createRefactoringRequest(monitor, (PyEdit) edit, ps);
req.setAdditionalInfo(RefactoringRequest.FIND_DEFINITION_IN_ADDITIONAL_INFO, false);
req.setAdditionalInfo(RefactoringRequest.FIND_REFERENCES_ONLY_IN_LOCAL_SCOPE, true);
req.fillActivationTokenAndQualifier();
ret.add(CompletionProposalFactory.get().createMoveImportsToLocalCompletionProposal(req, s, importHandleInfo, imageCache.get(UIConstants.ASSIST_MOVE_IMPORT), "Move import to local scope(s)"));
}
}
}
}
}
return ret;
}
use of org.python.pydev.core.IPyEdit in project Pydev by fabioz.
the class AnalyzeOnRequestSetter method onCreateActions.
@Override
public void onCreateActions(ListResourceBundle resources, BaseEditor baseEditor, IProgressMonitor monitor) {
IPyEdit edit = (IPyEdit) baseEditor;
AnalyzeOnRequestAction action = new AnalyzeOnRequestAction(edit);
edit.addOfflineActionListener("c", action, "Code-analysis on request", true);
}
Aggregations