From 08642360f5f336f56bcc2677bbebd039c3925ddc Mon Sep 17 00:00:00 2001 From: Fabio Zadrozny Date: Tue, 1 Oct 2024 09:07:47 -0300 Subject: [PATCH] wip --- .../TddQuickFixFromMarkersParticipant.java | 61 ++++++++++++------- ...erationQuickFixFromMarkersParticipant.java | 1 + ...ionQuickFixParticipantWithMarkersTest.java | 1 + .../proposals/ICompletionProposalFactory.java | 7 +++ .../DefaultCompletionProposalFactory.java | 12 ++++ 5 files changed, 59 insertions(+), 23 deletions(-) rename plugins/{com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd => com.python.pydev.analysis/src/com/python/pydev/analysis/marker_quick_fixes}/TddQuickFixFromMarkersParticipant.java (91%) diff --git a/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddQuickFixFromMarkersParticipant.java b/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/marker_quick_fixes/TddQuickFixFromMarkersParticipant.java similarity index 91% rename from plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddQuickFixFromMarkersParticipant.java rename to plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/marker_quick_fixes/TddQuickFixFromMarkersParticipant.java index 05aee364a2..8ccb58b2ef 100644 --- a/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddQuickFixFromMarkersParticipant.java +++ b/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/marker_quick_fixes/TddQuickFixFromMarkersParticipant.java @@ -4,7 +4,7 @@ * Please see the license.txt included with this distribution for details. * Any modifications to this file must keep this entire header intact. */ -package com.python.pydev.refactoring.tdd; +package com.python.pydev.analysis.marker_quick_fixes; import java.io.File; import java.util.ArrayList; @@ -38,10 +38,12 @@ import org.python.pydev.core.docutils.PySelection; import org.python.pydev.core.log.Log; import org.python.pydev.core.preferences.FileTypesPreferences; +import org.python.pydev.core.proposals.CompletionProposalFactory; import org.python.pydev.core.structure.CompletionRecursionException; import org.python.pydev.parser.jython.SimpleNode; import org.python.pydev.parser.jython.ast.ClassDef; import org.python.pydev.parser.visitors.NodeUtils; +import org.python.pydev.shared_core.SharedCorePlugin; import org.python.pydev.shared_core.code_completion.ICompletionProposalHandle; import org.python.pydev.shared_core.code_completion.IPyCompletionProposal; import org.python.pydev.shared_core.image.IImageCache; @@ -52,15 +54,11 @@ import org.python.pydev.shared_core.string.FullRepIterable; import org.python.pydev.shared_core.string.StringUtils; 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; -import com.python.pydev.refactoring.tdd.completions.TddRefactorCompletion; -import com.python.pydev.refactoring.tdd.completions.TddRefactorCompletionInInexistentModule; -import com.python.pydev.refactoring.tdd.completions.TddRefactorCompletionInModule; /** * This participant will add a suggestion to create class/methods/attributes when an undefined variable error is found. @@ -72,7 +70,7 @@ public class TddQuickFixFromMarkersParticipant implements IAnalysisMarkersPartic /*default*/IImageHandle imageModule; public TddQuickFixFromMarkersParticipant() { - IImageCache imageCache = SharedUiPlugin.getImageCache(); + IImageCache imageCache = SharedCorePlugin.getImageCache(); if (imageCache != null) { //making tests imageClass = imageCache.get(UIConstants.CREATE_CLASS_ICON); imageMethod = imageCache.get(UIConstants.CREATE_METHOD_ICON); @@ -346,9 +344,12 @@ protected File getFileStructure(File file, String withoutLastPart) { private void addCreateClassmethodOption(PySelection ps, IPyEdit edit, List props, String markerContents, List parametersAfterCall, PyCreateMethodOrField pyCreateMethod, File file, String className) { - props.add(new TddRefactorCompletionInModule(markerContents, imageMethod, "Create " + markerContents + - " classmethod at " + className + - " in " + file.getName(), null, + + props.add(CompletionProposalFactory.get().createTddRefactorCompletionInModule(markerContents, imageMethod, + "Create " + markerContents + + " classmethod at " + className + + " in " + file.getName(), + null, "Create " + markerContents + " classmethod at class: " + className + " in " + file, @@ -358,8 +359,10 @@ private void addCreateClassmethodOption(PySelection ps, IPyEdit edit, List props, String markerContents, List parametersAfterCall, File file) { - props.add(new TddRefactorCompletionInModule(markerContents, imageMethod, "Create " + markerContents + - " method at " + file.getName(), null, + props.add(CompletionProposalFactory.get().createTddRefactorCompletionInModule(markerContents, imageMethod, + "Create " + markerContents + + " method at " + file.getName(), + null, "Create " + markerContents + " method at " + file, IPyCompletionProposal.PRIORITY_CREATE, edit, file, parametersAfterCall, new PyCreateMethodOrField(), @@ -368,8 +371,10 @@ IPyCompletionProposal.PRIORITY_CREATE, edit, file, parametersAfterCall, new PyCr private void addCreateClassOption(PySelection ps, IPyEdit edit, List props, String markerContents, List parametersAfterCall, File file) { - props.add(new TddRefactorCompletionInModule(markerContents, imageClass, "Create " + markerContents + - " class at " + file.getName(), null, + props.add(CompletionProposalFactory.get().createTddRefactorCompletionInModule(markerContents, imageClass, + "Create " + markerContents + + " class at " + file.getName(), + null, "Create " + markerContents + " class at " + file, IPyCompletionProposal.PRIORITY_CREATE, edit, file, parametersAfterCall, new PyCreateClass(), ps, @@ -378,8 +383,10 @@ IPyCompletionProposal.PRIORITY_CREATE, edit, file, parametersAfterCall, new PyCr private void addCreateClassInNewModuleOption(PySelection ps, IPyEdit edit, List props, String markerContents, String moduleName, List parametersAfterCall, File file) { - props.add(new TddRefactorCompletionInInexistentModule(markerContents, imageClass, "Create " + markerContents + - " class at new module " + moduleName, null, + props.add(CompletionProposalFactory.get().createTddRefactorCompletionInInexistentModule(markerContents, + imageClass, "Create " + markerContents + + " class at new module " + moduleName, + null, "Create " + markerContents + " class at new module " + file, @@ -389,8 +396,10 @@ private void addCreateClassInNewModuleOption(PySelection ps, IPyEdit edit, List< private void addCreateMethodInNewModuleOption(PySelection ps, IPyEdit edit, List props, String markerContents, String moduleName, List parametersAfterCall, File file) { - props.add(new TddRefactorCompletionInInexistentModule(markerContents, imageMethod, "Create " + markerContents + - " method at new module " + moduleName, null, + props.add(CompletionProposalFactory.get().createTddRefactorCompletionInInexistentModule(markerContents, + imageMethod, "Create " + markerContents + + " method at new module " + moduleName, + null, "Create " + markerContents + " method at new module " + file, @@ -400,8 +409,10 @@ private void addCreateMethodInNewModuleOption(PySelection ps, IPyEdit edit, List private void addCreateModuleOption(PySelection ps, IPyEdit edit, List props, String markerContents, File file) { - props.add(new TddRefactorCompletionInInexistentModule(markerContents, imageModule, "Create " + markerContents + - " module", null, + props.add(CompletionProposalFactory.get().createTddRefactorCompletionInInexistentModule(markerContents, + imageModule, "Create " + markerContents + + " module", + null, "Create " + markerContents + " module (" + file + ")", @@ -411,16 +422,20 @@ private void addCreateModuleOption(PySelection ps, IPyEdit edit, List props, String markerContents, List parametersAfterCall) { - props.add(new TddRefactorCompletion(markerContents, imageMethod, "Create " + markerContents + - " method", null, + props.add(CompletionProposalFactory.get().createTddRefactorCompletion(markerContents, imageMethod, + "Create " + markerContents + + " method", + null, null, IPyCompletionProposal.PRIORITY_CREATE, edit, PyCreateClass.LOCATION_STRATEGY_BEFORE_CURRENT, parametersAfterCall, new PyCreateMethodOrField(), ps)); } private void addCreateClassOption(PySelection ps, IPyEdit edit, List props, String markerContents, List parametersAfterCall) { - props.add(new TddRefactorCompletion(markerContents, imageClass, "Create " + markerContents + - " class", null, + props.add(CompletionProposalFactory.get().createTddRefactorCompletion(markerContents, imageClass, + "Create " + markerContents + + " class", + null, null, IPyCompletionProposal.PRIORITY_CREATE, edit, PyCreateClass.LOCATION_STRATEGY_BEFORE_CURRENT, parametersAfterCall, new PyCreateClass(), ps)); } diff --git a/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddCodeGenerationQuickFixFromMarkersParticipant.java b/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddCodeGenerationQuickFixFromMarkersParticipant.java index 8f1c880662..f0b04c53cc 100644 --- a/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddCodeGenerationQuickFixFromMarkersParticipant.java +++ b/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddCodeGenerationQuickFixFromMarkersParticipant.java @@ -2,6 +2,7 @@ import com.python.pydev.analysis.additionalinfo.builders.AnalysisRunner; import com.python.pydev.analysis.ctrl_1.AbstractAnalysisMarkersParticipants; +import com.python.pydev.analysis.marker_quick_fixes.TddQuickFixFromMarkersParticipant; public class TddCodeGenerationQuickFixFromMarkersParticipant extends AbstractAnalysisMarkersParticipants { diff --git a/plugins/com.python.pydev.refactoring/tests/com/python/pydev/refactoring/tdd/TddCodeGenerationQuickFixParticipantWithMarkersTest.java b/plugins/com.python.pydev.refactoring/tests/com/python/pydev/refactoring/tdd/TddCodeGenerationQuickFixParticipantWithMarkersTest.java index 10a1e7f4a0..3381bc8782 100644 --- a/plugins/com.python.pydev.refactoring/tests/com/python/pydev/refactoring/tdd/TddCodeGenerationQuickFixParticipantWithMarkersTest.java +++ b/plugins/com.python.pydev.refactoring/tests/com/python/pydev/refactoring/tdd/TddCodeGenerationQuickFixParticipantWithMarkersTest.java @@ -38,6 +38,7 @@ import com.python.pydev.analysis.AnalysisPreferences; import com.python.pydev.analysis.AnalysisTestsBase; import com.python.pydev.analysis.additionalinfo.builders.AnalysisRunner; +import com.python.pydev.analysis.marker_quick_fixes.TddQuickFixFromMarkersParticipant; import com.python.pydev.analysis.refactoring.quick_fixes.DummyMarkerInfoForAnalysis; import com.python.pydev.analysis.refactoring.refactorer.Refactorer; import com.python.pydev.analysis.refactoring.tdd.TddCodeGenerationQuickFixWithoutMarkersParticipant; diff --git a/plugins/org.python.pydev.core/src/org/python/pydev/core/proposals/ICompletionProposalFactory.java b/plugins/org.python.pydev.core/src/org/python/pydev/core/proposals/ICompletionProposalFactory.java index 05793422d6..2fd21858ab 100644 --- a/plugins/org.python.pydev.core/src/org/python/pydev/core/proposals/ICompletionProposalFactory.java +++ b/plugins/org.python.pydev.core/src/org/python/pydev/core/proposals/ICompletionProposalFactory.java @@ -150,4 +150,11 @@ ICompletionProposalHandle createTddRefactorCompletionInModule(String replacement PySelection ps, int locationStrategy); + ICompletionProposalHandle createTddRefactorCompletionInInexistentModule(String replacementString, + IImageHandle image, String displayString, + /*IContextInformation*/ Object contextInformation, String additionalProposalInfo, int priority, + IPyEdit edit, + File module, List parametersAfterCall, /*AbstractPyCreateAction*/ Object pyCreateAction, + PySelection ps); + } \ No newline at end of file diff --git a/plugins/org.python.pydev/src/org/python/pydev/editor/codecompletion/proposals/DefaultCompletionProposalFactory.java b/plugins/org.python.pydev/src/org/python/pydev/editor/codecompletion/proposals/DefaultCompletionProposalFactory.java index 1eedb09aad..8e8333479f 100644 --- a/plugins/org.python.pydev/src/org/python/pydev/editor/codecompletion/proposals/DefaultCompletionProposalFactory.java +++ b/plugins/org.python.pydev/src/org/python/pydev/editor/codecompletion/proposals/DefaultCompletionProposalFactory.java @@ -38,6 +38,7 @@ import com.python.pydev.analysis.refactoring.tdd.AbstractPyCreateAction; import com.python.pydev.refactoring.tdd.completions.TddRefactorCompletion; +import com.python.pydev.refactoring.tdd.completions.TddRefactorCompletionInInexistentModule; import com.python.pydev.refactoring.tdd.completions.TddRefactorCompletionInModule; public class DefaultCompletionProposalFactory implements ICompletionProposalFactory { @@ -305,4 +306,15 @@ public ICompletionProposalHandle createTddRefactorCompletionInModule(String repl locationStrategy); } + @Override + public ICompletionProposalHandle createTddRefactorCompletionInInexistentModule(String replacementString, + IImageHandle image, String displayString, Object contextInformation, String additionalProposalInfo, + int priority, IPyEdit edit, File module, List parametersAfterCall, Object pyCreateAction, + PySelection ps) { + return new TddRefactorCompletionInInexistentModule(replacementString, image, displayString, + (IContextInformation) contextInformation, + additionalProposalInfo, priority, edit, module, parametersAfterCall, + (AbstractPyCreateAction) pyCreateAction, ps); + } + }