Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Sep 29, 2024
1 parent eb0e094 commit 244cf7a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ static boolean checkInitCreation(IPyEdit edit, PySelection callPs, ItemPointer[]
TddRefactorCompletionInModule completion = new TddRefactorCompletionInModule("__init__",
imageCache.get(UIConstants.CREATE_METHOD_ICON), displayString, null, displayString,
IPyCompletionProposal.PRIORITY_CREATE, edit, definition.module.getFile(),
parametersAfterCall, pyCreateMethod, callPs);
completion.locationStrategy = AbstractPyCreateAction.LOCATION_STRATEGY_FIRST_METHOD;
parametersAfterCall, pyCreateMethod, callPs,
AbstractPyCreateAction.LOCATION_STRATEGY_FIRST_METHOD);
ret.add(completion);
return true;
}
Expand Down Expand Up @@ -186,8 +186,8 @@ public static boolean checkCreationBasedOnFoundPointers(IPyEdit edit, PySelectio
TddRefactorCompletionInModule completion = new TddRefactorCompletionInModule(methodToCreate,
imageCache.get(UIConstants.CREATE_METHOD_ICON), displayString,
null, displayString, IPyCompletionProposal.PRIORITY_CREATE, edit,
definition.module.getFile(), parametersAfterCall, pyCreateMethod, newSelection);
completion.locationStrategy = AbstractPyCreateAction.LOCATION_STRATEGY_END;
definition.module.getFile(), parametersAfterCall, pyCreateMethod, newSelection,
AbstractPyCreateAction.LOCATION_STRATEGY_END);
ret.add(completion);
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.python.pydev.shared_core.structure.Tuple;
import org.python.pydev.shared_ui.SharedUiPlugin;

import com.python.pydev.analysis.refactoring.tdd.AbstractPyCreateAction;
import com.python.pydev.analysis.refactoring.tdd.NullPyCreateAction;
import com.python.pydev.analysis.refactoring.tdd.PyCreateClass;
import com.python.pydev.analysis.refactoring.tdd.PyCreateMethodOrField;
Expand Down Expand Up @@ -349,7 +350,7 @@ private void addCreateClassmethodOption(PySelection ps, IPyEdit edit, List<IComp
" classmethod at class: " + className +
" in " + file,
IPyCompletionProposal.PRIORITY_CREATE, edit,
file, parametersAfterCall, pyCreateMethod, ps));
file, parametersAfterCall, pyCreateMethod, ps, AbstractPyCreateAction.LOCATION_STRATEGY_END));
}

private void addCreateMethodOption(PySelection ps, IPyEdit edit, List<ICompletionProposalHandle> props,
Expand All @@ -359,7 +360,7 @@ private void addCreateMethodOption(PySelection ps, IPyEdit edit, List<ICompletio
"Create " + markerContents +
" method at " + file,
IPyCompletionProposal.PRIORITY_CREATE, edit, file, parametersAfterCall, new PyCreateMethodOrField(),
ps));
ps, AbstractPyCreateAction.LOCATION_STRATEGY_END));
}

private void addCreateClassOption(PySelection ps, IPyEdit edit, List<ICompletionProposalHandle> props,
Expand All @@ -368,7 +369,8 @@ private void addCreateClassOption(PySelection ps, IPyEdit edit, List<ICompletion
" class at " + file.getName(), null,
"Create " + markerContents +
" class at " + file,
IPyCompletionProposal.PRIORITY_CREATE, edit, file, parametersAfterCall, new PyCreateClass(), ps));
IPyCompletionProposal.PRIORITY_CREATE, edit, file, parametersAfterCall, new PyCreateClass(), ps,
AbstractPyCreateAction.LOCATION_STRATEGY_END));
}

private void addCreateClassInNewModuleOption(PySelection ps, IPyEdit edit, List<ICompletionProposalHandle> props,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ public final class TddRefactorCompletionInModule extends AbstractTddRefactorComp

public TddRefactorCompletionInModule(String replacementString, IImageHandle image, String displayString,
IContextInformation contextInformation, String additionalProposalInfo, int priority, IPyEdit edit,
File module, List<String> parametersAfterCall, AbstractPyCreateAction pyCreateAction, PySelection ps) {
File module, List<String> parametersAfterCall, AbstractPyCreateAction pyCreateAction, PySelection ps,
int locationStrategy) {

super(edit, replacementString, 0, 0, 0, image, displayString, contextInformation, additionalProposalInfo,
priority);
this.module = module;
this.parametersAfterCall = parametersAfterCall;
this.pyCreateAction = pyCreateAction;
this.ps = ps;
this.locationStrategy = locationStrategy;
}

public List<String> getParametersAfterCall() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
*/
package com.python.pydev.refactoring.tdd;

import java.io.File;
import java.util.List;

import org.eclipse.jface.text.Document;
import org.python.pydev.ast.codecompletion.PyCodeCompletion;
import org.python.pydev.ast.codecompletion.revisited.CodeCompletionTestsBase;
import org.python.pydev.ast.codecompletion.revisited.PyEditStub;
import org.python.pydev.ast.codecompletion.revisited.PydevFileEditorInputStub;
import org.python.pydev.ast.codecompletion.revisited.modules.CompiledModule;
import org.python.pydev.ast.refactoring.AbstractPyRefactoring;
import org.python.pydev.core.IPyEdit;
Expand All @@ -24,6 +24,7 @@
import org.python.pydev.shared_core.callbacks.ICallback;
import org.python.pydev.shared_core.code_completion.ICompletionProposalHandle;
import org.python.pydev.shared_core.string.FastStringBuffer;
import org.python.pydev.shared_ui.editor_input.PydevFileEditorInput;

import com.python.pydev.analysis.refactoring.refactorer.Refactorer;
import com.python.pydev.analysis.refactoring.tdd.AbstractPyCreateClassOrMethodOrField;
Expand Down Expand Up @@ -158,8 +159,9 @@ def m1(self):
private void check(String s, String expected, String label) throws MisconfigurationException {
Document doc = new Document(s);

PydevFileEditorInputStub editorInputStub = new PydevFileEditorInputStub();
IPyEdit edit = new PyEditStub(doc, editorInputStub, nature);
File file = new File(TestDependent.TEST_PYSRC_TESTING_LOC + "extendable/check_analysis_and_tdd.py");
PydevFileEditorInput editorInputStub = new PydevFileEditorInput(file);
IPyEdit edit = new PyEditStub(doc, editorInputStub, nature, file);

List<ICompletionProposalHandle> props = TddCodeGenerationQuickFixWithoutMarkersParticipant.getTddProps(
new PySelection(doc, s.length() - 1), null, null, nature, edit, s.length() - 1, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.python.pydev.ast.analysis.messages.IMessage;
import org.python.pydev.ast.codecompletion.PyCodeCompletion;
import org.python.pydev.ast.codecompletion.revisited.PyEditStub;
import org.python.pydev.ast.codecompletion.revisited.PydevFileEditorInputStub;
import org.python.pydev.ast.codecompletion.revisited.modules.CompiledModule;
import org.python.pydev.ast.refactoring.AbstractPyRefactoring;
import org.python.pydev.core.IAnalysisPreferences;
Expand All @@ -34,6 +33,7 @@
import org.python.pydev.shared_core.code_completion.ICompletionProposalHandle;
import org.python.pydev.shared_core.markers.PyMarkerUtils.MarkerInfo;
import org.python.pydev.shared_core.string.StringUtils;
import org.python.pydev.shared_ui.editor_input.PydevFileEditorInput;

import com.python.pydev.analysis.AnalysisPreferences;
import com.python.pydev.analysis.AnalysisTestsBase;
Expand Down Expand Up @@ -155,10 +155,11 @@ public void testCreateModule() throws Exception {
String initial = """
import some_module
""";
// i.e.: New empty module
String expected = """
""";
String stringForRegion = "some_module";
String expectedLabel = "Create NewClass class";
String expectedLabel = "Create some_module module";
int markerType = IAnalysisPreferences.TYPE_UNRESOLVED_IMPORT;

check(initial, expected, stringForRegion, expectedLabel, markerType);
Expand Down Expand Up @@ -212,10 +213,9 @@ private void check(String initial, String expected, String stringForRegion, Stri
int offset = markerStart;
PySelection ps = new PySelection(doc, offset);
String line = ps.getLine();
PydevFileEditorInputStub editorInputStub = new PydevFileEditorInputStub();
IPyEdit edit = new PyEditStub(doc, editorInputStub, nature);

File file = new File(TestDependent.TEST_PYSRC_TESTING_LOC + "extendable/check_analysis_and_tdd.py");
PydevFileEditorInput editorInputStub = new PydevFileEditorInput(file);
IPyEdit edit = new PyEditStub(doc, editorInputStub, nature, file);

TddCodeGenerationQuickFixWithoutMarkersParticipant participant2 = new TddCodeGenerationQuickFixWithoutMarkersParticipant();
List<ICompletionProposalHandle> props = participant2.getProps(ps, null, file, nature, edit, offset);
Expand All @@ -224,11 +224,19 @@ private void check(String initial, String expected, String stringForRegion, Stri
participant.addProps(markerInfo, analysisPreferences, line, ps, offset, nature, edit, props);
}

TddRefactorCompletion completion = (TddRefactorCompletion) findCompletion(props, expectedLabel,
true);
TemplateInfo templateInfo = completion.getAsTemplateInfo();
templateInfo.apply(doc);
assertEquals(expected, doc.get());
ICompletionProposalExtension2 found = findCompletion(props, expectedLabel, true);
if (found instanceof TddRefactorCompletion) {
TddRefactorCompletion completion = (TddRefactorCompletion) found;
TemplateInfo templateInfo = completion.getAsTemplateInfo();
templateInfo.apply(doc);
assertEquals(expected, doc.get());
} else if (found instanceof TddRefactorCompletionInModule) {
TddRefactorCompletion completion = (TddRefactorCompletion) found;
TemplateInfo templateInfo = completion.getAsTemplateInfo();
Document d = new Document();
templateInfo.apply(d);
assertEquals(expected, d.get());
}

} finally {
GRAMMAR_TO_USE_FOR_PARSING = usedGrammar;
Expand Down Expand Up @@ -258,10 +266,9 @@ private void checkFromAnalysis(String initial, String expected, String expectedL
id, markerStart, markerLen);
IAnalysisPreferences analysisPreferences = new AnalysisPreferences(null);
String line = ps.getLine();
PydevFileEditorInputStub editorInputStub = new PydevFileEditorInputStub();
IPyEdit edit = new PyEditStub(doc, editorInputStub, nature);

File file = new File(TestDependent.TEST_PYSRC_TESTING_LOC + "extendable/check_analysis_and_tdd.py");
PydevFileEditorInput editorInputStub = new PydevFileEditorInput(file);
IPyEdit edit = new PyEditStub(doc, editorInputStub, nature, file);

TddCodeGenerationQuickFixWithoutMarkersParticipant participant2 = new TddCodeGenerationQuickFixWithoutMarkersParticipant();
List<ICompletionProposalHandle> props = participant2.getProps(ps, null, file, nature, edit, offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,20 @@ public class PyEditStub implements IPyEdit {
public IDocument doc;
public int parserChanged;
private Map<String, Object> cache = new HashMap<String, Object>();
private PydevFileEditorInputStub pydevFileEditorInputStub;
private IEditorInput pydevFileEditorInputStub;
private IPythonNature nature;
public IFile iFile;
public File file;

public PyEditStub(IDocument doc, PydevFileEditorInputStub pydevFileEditorInputStub) {
this(doc, pydevFileEditorInputStub, new PythonNatureStub());
public PyEditStub(IDocument doc, IEditorInput pydevFileEditorInputStub) {
this(doc, pydevFileEditorInputStub, new PythonNatureStub(), null);
}

public PyEditStub(IDocument doc, PydevFileEditorInputStub pydevFileEditorInputStub, IPythonNature nature) {
public PyEditStub(IDocument doc, IEditorInput pydevFileEditorInputStub, IPythonNature nature, File file) {
this.doc = doc;
this.pydevFileEditorInputStub = pydevFileEditorInputStub;
this.nature = nature;
this.file = file;
}

@Override
Expand Down

0 comments on commit 244cf7a

Please sign in to comment.