Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Oct 1, 2024
1 parent 6202d9f commit 0864236
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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);
Expand Down Expand Up @@ -346,9 +344,12 @@ protected File getFileStructure(File file, String withoutLastPart) {
private void addCreateClassmethodOption(PySelection ps, IPyEdit edit, List<ICompletionProposalHandle> props,
String markerContents, List<String> 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,
Expand All @@ -358,8 +359,10 @@ private void addCreateClassmethodOption(PySelection ps, IPyEdit edit, List<IComp

private void addCreateMethodOption(PySelection ps, IPyEdit edit, List<ICompletionProposalHandle> props,
String markerContents, List<String> 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(),
Expand All @@ -368,8 +371,10 @@ IPyCompletionProposal.PRIORITY_CREATE, edit, file, parametersAfterCall, new PyCr

private void addCreateClassOption(PySelection ps, IPyEdit edit, List<ICompletionProposalHandle> props,
String markerContents, List<String> 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,
Expand All @@ -378,8 +383,10 @@ IPyCompletionProposal.PRIORITY_CREATE, edit, file, parametersAfterCall, new PyCr

private void addCreateClassInNewModuleOption(PySelection ps, IPyEdit edit, List<ICompletionProposalHandle> props,
String markerContents, String moduleName, List<String> 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,
Expand All @@ -389,8 +396,10 @@ private void addCreateClassInNewModuleOption(PySelection ps, IPyEdit edit, List<

private void addCreateMethodInNewModuleOption(PySelection ps, IPyEdit edit, List<ICompletionProposalHandle> props,
String markerContents, String moduleName, List<String> 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,
Expand All @@ -400,8 +409,10 @@ private void addCreateMethodInNewModuleOption(PySelection ps, IPyEdit edit, List

private void addCreateModuleOption(PySelection ps, IPyEdit edit, List<ICompletionProposalHandle> 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 +
")",
Expand All @@ -411,16 +422,20 @@ private void addCreateModuleOption(PySelection ps, IPyEdit edit, List<ICompletio

private void addCreateMethodOption(PySelection ps, IPyEdit edit, List<ICompletionProposalHandle> props,
String markerContents, List<String> 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<ICompletionProposalHandle> props,
String markerContents, List<String> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> parametersAfterCall, /*AbstractPyCreateAction*/ Object pyCreateAction,
PySelection ps);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<String> parametersAfterCall, Object pyCreateAction,
PySelection ps) {
return new TddRefactorCompletionInInexistentModule(replacementString, image, displayString,
(IContextInformation) contextInformation,
additionalProposalInfo, priority, edit, module, parametersAfterCall,
(AbstractPyCreateAction) pyCreateAction, ps);
}

}

0 comments on commit 0864236

Please sign in to comment.