use of org.python.pydev.editor.PyEdit in project Pydev by fabioz.
the class TddTestWorkbench method checkCreateNewModule2.
private void checkCreateNewModule2() throws CoreException, BadLocationException, MisconfigurationException {
String mod1Contents;
TddCodeGenerationQuickFixParticipant quickFix;
PySelection ps;
List<ICompletionProposalHandle> props;
IFile mod2 = initFile.getParent().getFile(new Path("pack2a/module_new.py"));
final List<PyEdit> pyEditCreated = new ArrayList<PyEdit>();
ICallbackListener<PyEdit> listener = new ICallbackListener<PyEdit>() {
@Override
public Object call(PyEdit obj) {
pyEditCreated.add(obj);
return null;
}
};
PyEdit.onPyEditCreated.registerListener(listener);
try {
// give it a bit more time...
goToManual(AnalysisRequestsTestWorkbench.TIME_FOR_ANALYSIS);
mod1Contents = "" + "import pack1.pack2.pack2a.module_new";
setContentsAndWaitReparseAndError(mod1Contents);
quickFix = new TddCodeGenerationQuickFixParticipant();
int offset = mod1Contents.length();
ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
props = waitForQuickFixProps(quickFix, ps, offset);
assertTrue(!mod2.exists());
findCompletion(props, "Create pack1.pack2.pack2a.module_new module").apply(editor.getISourceViewer(), '\n', 0, offset);
assertTrue(mod2.exists());
assertEquals(1, pyEditCreated.size());
} finally {
for (PyEdit edit : pyEditCreated) {
edit.close(false);
}
PyEdit.onPyEditCreated.unregisterListener(listener);
mod2.delete(true, null);
}
}
use of org.python.pydev.editor.PyEdit in project Pydev by fabioz.
the class TddTestWorkbench method checkCreateMethodAtOtherModule2.
private void checkCreateMethodAtOtherModule2() throws CoreException, BadLocationException, MisconfigurationException {
String mod1Contents;
TddCodeGenerationQuickFixParticipant quickFix;
PySelection ps;
IFile mod2 = initFile.getParent().getFile(new Path("other_module3.py"));
String str = "" + "class Bar(object):\n" + " pass\n" + "";
mod2.create(new ByteArrayInputStream(str.getBytes()), true, null);
PyEdit editor2 = (PyEdit) PyOpenEditor.doOpenEditor(mod2);
try {
// give it a bit more time...
goToManual(AnalysisRequestsTestWorkbench.TIME_FOR_ANALYSIS);
mod1Contents = "" + "import other_module3\n" + "other_module3.Bar.Foo(10, 20)";
setContentsAndWaitReparseAndError(mod1Contents);
quickFix = new TddCodeGenerationQuickFixParticipant();
int offset = mod1Contents.length() - "o(a, b)".length();
ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
waitForQuickFixProps(quickFix, ps, offset, "Create Foo classmethod at Bar in other_module3.py").apply(editor.getISourceViewer(), '\n', 0, offset);
assertContentsEqual("" + "class Bar(object):\n" + " \n" + " \n" + " @classmethod\n" + " def Foo(cls, param1, param2):\n" + " pass\n" + " \n" + " \n" + "\n" + "", editor2.getDocument().get());
} finally {
editor2.close(false);
mod2.delete(true, null);
}
}
use of org.python.pydev.editor.PyEdit in project Pydev by fabioz.
the class TddTestWorkbench method checkCreateNewModuleWithClass.
private void checkCreateNewModuleWithClass() throws CoreException, BadLocationException, MisconfigurationException {
String mod1Contents;
TddCodeGenerationQuickFixParticipant quickFix;
PySelection ps;
List<ICompletionProposalHandle> props;
IFile mod2 = initFile.getParent().getFolder(new Path("pack3")).getFile(new Path("module_new2.py"));
final List<PyEdit> pyEditCreated = new ArrayList<PyEdit>();
ICallbackListener<PyEdit> listener = new ICallbackListener<PyEdit>() {
@Override
public Object call(PyEdit obj) {
pyEditCreated.add(obj);
return null;
}
};
PyEdit.onPyEditCreated.registerListener(listener);
try {
// give it a bit more time...
goToManual(AnalysisRequestsTestWorkbench.TIME_FOR_ANALYSIS);
mod1Contents = "" + "from pack1.pack2.pack3.module_new2 import Foo";
setContentsAndWaitReparseAndError(mod1Contents);
quickFix = new TddCodeGenerationQuickFixParticipant();
int offset = mod1Contents.length();
ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
props = waitForQuickFixProps(quickFix, ps, offset);
assertTrue(!mod2.exists());
findCompletion(props, "Create Foo class at new module pack1.pack2.pack3.module_new2").apply(editor.getISourceViewer(), '\n', 0, offset);
assertTrue(mod2.exists());
assertEquals(1, pyEditCreated.size());
assertContentsEqual("" + "class Foo(object):\n" + " pass\n" + "\n" + "\n" + "", pyEditCreated.get(0).getDocument().get());
} finally {
for (PyEdit edit : pyEditCreated) {
edit.close(false);
}
PyEdit.onPyEditCreated.unregisterListener(listener);
mod2.delete(true, null);
}
}
use of org.python.pydev.editor.PyEdit in project Pydev by fabioz.
the class AbstractTddRefactorCompletion method forceReparseInBaseEditorAnd.
protected void forceReparseInBaseEditorAnd(PyEdit... others) {
if (edit != null) {
PyParser parser = edit.getParser();
parser.forceReparse(new Tuple<String, Boolean>(IMiscConstants.ANALYSIS_PARSER_OBSERVER_FORCE, true));
}
for (PyEdit e : others) {
PyParser parser = e.getParser();
parser.forceReparse(new Tuple<String, Boolean>(IMiscConstants.ANALYSIS_PARSER_OBSERVER_FORCE, true));
}
}
Aggregations