diff --git a/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/AbstractPyCreateAction.java b/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/AbstractPyCreateAction.java index 6a32332ce5..6f4ff18a88 100644 --- a/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/AbstractPyCreateAction.java +++ b/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/AbstractPyCreateAction.java @@ -32,6 +32,10 @@ public abstract class AbstractPyCreateAction extends Action implements IEditorAc protected IPyEdit targetEditor; + public void setActiveEditor(IAction action, IPyEdit edit) { + this.targetEditor = edit; + } + @Override public void setActiveEditor(IAction action, IEditorPart targetEditor) { if (targetEditor instanceof ITextEditor) { diff --git a/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/AbstractTddRefactorCompletion.java b/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/AbstractTddRefactorCompletion.java index 8567cf1768..6b15436f5e 100644 --- a/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/AbstractTddRefactorCompletion.java +++ b/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/AbstractTddRefactorCompletion.java @@ -9,6 +9,7 @@ import org.eclipse.jface.text.contentassist.ICompletionProposalExtension2; import org.eclipse.jface.text.contentassist.IContextInformation; import org.python.pydev.ast.codecompletion.ProposalsComparator; +import org.python.pydev.core.IPyEdit; import org.python.pydev.editor.PyEdit; import org.python.pydev.editor.codecompletion.proposals.PyCompletionProposal; import org.python.pydev.parser.PyParser; @@ -24,22 +25,22 @@ public abstract class AbstractTddRefactorCompletion extends PyCompletionProposal implements ICompletionProposalExtension2 { - protected PyEdit edit; + protected IPyEdit edit; - public AbstractTddRefactorCompletion(PyEdit edit, String replacementString, int replacementOffset, + public AbstractTddRefactorCompletion(IPyEdit edit, String replacementString, int replacementOffset, int replacementLength, int cursorPosition, int priority) { this(edit, replacementString, replacementOffset, replacementLength, cursorPosition, null, null, null, null, priority); } - public AbstractTddRefactorCompletion(PyEdit edit, String replacementString, int replacementOffset, + public AbstractTddRefactorCompletion(IPyEdit edit, String replacementString, int replacementOffset, int replacementLength, int cursorPosition, IImageHandle image, String displayString, IContextInformation contextInformation, String additionalProposalInfo, int priority) { this(edit, replacementString, replacementOffset, replacementLength, cursorPosition, image, displayString, contextInformation, additionalProposalInfo, priority, IPyCompletionProposal.ON_APPLY_DEFAULT, ""); } - public AbstractTddRefactorCompletion(PyEdit edit, String replacementString, int replacementOffset, + public AbstractTddRefactorCompletion(IPyEdit edit, String replacementString, int replacementOffset, int replacementLength, int cursorPosition, IImageHandle image, String displayString, IContextInformation contextInformation, String additionalProposalInfo, int priority, int onApplyAction, String args) { @@ -50,13 +51,13 @@ public AbstractTddRefactorCompletion(PyEdit edit, String replacementString, int protected void forceReparseInBaseEditorAnd(PyEdit... others) { if (edit != null) { - PyParser parser = edit.getParser(); + PyParser parser = (PyParser) edit.getParser(); parser.forceReparse( new Tuple(IMiscConstants.ANALYSIS_PARSER_OBSERVER_FORCE, true)); } - for (PyEdit e : others) { - PyParser parser = e.getParser(); + for (IPyEdit e : others) { + PyParser parser = (PyParser) e.getParser(); parser.forceReparse( new Tuple(IMiscConstants.ANALYSIS_PARSER_OBSERVER_FORCE, true)); } diff --git a/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddCodeGenerationQuickFixParticipant.java b/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddCodeGenerationQuickFixParticipant.java index 29b07e5ec0..436eaf00eb 100644 --- a/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddCodeGenerationQuickFixParticipant.java +++ b/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddCodeGenerationQuickFixParticipant.java @@ -35,7 +35,6 @@ import org.python.pydev.core.docutils.PySelection.TddPossibleMatches; import org.python.pydev.core.log.Log; import org.python.pydev.core.structure.CompletionRecursionException; -import org.python.pydev.editor.PyEdit; import org.python.pydev.parser.jython.ast.ClassDef; import org.python.pydev.parser.jython.ast.FunctionDef; import org.python.pydev.parser.jython.ast.Return; @@ -47,6 +46,7 @@ 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; +import org.python.pydev.shared_core.image.UIConstants; import org.python.pydev.shared_core.string.FullRepIterable; import org.python.pydev.shared_core.string.StringUtils; @@ -73,13 +73,13 @@ public List getProps(PySelection ps, IImageCache imag IPythonNature nature, IPyEdit edit, int offset) throws BadLocationException { List ret = super.getProps(ps, imageCache, f, nature, edit, offset); - this.getTddProps(ps, imageCache, f, nature, (PyEdit) edit, offset, ret); + TddCodeGenerationQuickFixParticipant.getTddProps(ps, imageCache, f, nature, edit, offset, ret); return ret; } - public List getTddProps(PySelection ps, IImageCache imageCache, File f, + public static List getTddProps(PySelection ps, IImageCache imageCache, File f, IPythonNature nature, - PyEdit edit, int offset, List ret) { + IPyEdit edit, int offset, List ret) { if (ret == null) { ret = new ArrayList(); } @@ -158,7 +158,7 @@ public List getTddProps(PySelection ps, IImageCache i PySelection newSelection = new PySelection(callPs.getDoc(), absoluteCursorOffset); checkCreationBasedOnFoundPointers(edit, callPs, ret, possibleMatch, pointers, methodToCreate, - newSelection, nature); + newSelection, nature, imageCache); continue CONTINUE_FOR; } @@ -166,7 +166,7 @@ public List getTddProps(PySelection ps, IImageCache i //Ok, we found whatever was there, so, we don't need to create anything (except maybe do //the __init__ or something at the class level). - if (!checkInitCreation(edit, callPs, pointers, ret)) { + if (!checkInitCreation(edit, callPs, pointers, ret, imageCache)) { //This was called only when isCall == false //Ok, if it's not a call and we found a field, it's still possible that we may want to create //a field if it wasn't found in the __init__ @@ -188,13 +188,13 @@ public List getTddProps(PySelection ps, IImageCache i } if (!foundInInit) { checkMethodCreationAtClass(edit, pyRefactoring, callWithoutParens, callPs, ret, - lineContents, possibleMatch, f, nature); + lineContents, possibleMatch, f, nature, imageCache); } } } else if (pointers.length == 0) { checkMethodCreationAtClass(edit, pyRefactoring, callWithoutParens, callPs, ret, lineContents, - possibleMatch, f, nature); + possibleMatch, f, nature, imageCache); } } catch (Exception e) { @@ -211,10 +211,11 @@ public List getTddProps(PySelection ps, IImageCache i public static ICallback onGetTddPropsError; - private boolean checkMethodCreationAtClass(PyEdit edit, IPyRefactoring pyRefactoring, String callWithoutParens, + private static boolean checkMethodCreationAtClass(IPyEdit edit, IPyRefactoring pyRefactoring, + String callWithoutParens, PySelection callPs, List ret, String lineContents, TddPossibleMatches possibleMatch, - File f, IPythonNature nature) throws MisconfigurationException, Exception { + File f, IPythonNature nature, IImageCache imageCache) throws MisconfigurationException, Exception { RefactoringRequest request; ItemPointer[] pointers; //Ok, no definition found for the full string, so, check if we have a dot there and check @@ -242,7 +243,7 @@ private boolean checkMethodCreationAtClass(PyEdit edit, IPyRefactoring pyRefacto pyCreateMethod.setCreateInClass(classNameInLine); addCreateMethodOption(callPs, edit, ret, methodToCreate, parametersAfterCall, - pyCreateMethod, classNameInLine); + pyCreateMethod, classNameInLine, imageCache); } } } @@ -259,7 +260,7 @@ private boolean checkMethodCreationAtClass(PyEdit edit, IPyRefactoring pyRefacto pointers = pyRefactoring.findDefinition(request); if (pointers.length == 1) { if (checkCreationBasedOnFoundPointers(edit, callPs, ret, possibleMatch, pointers, methodToCreate, - newSelection, nature)) { + newSelection, nature, imageCache)) { return true; } } @@ -267,7 +268,7 @@ private boolean checkMethodCreationAtClass(PyEdit edit, IPyRefactoring pyRefacto return false; } - public Definition rebaseAssignDefinition(AssignDefinition assignDef, IPythonNature nature, + public static Definition rebaseAssignDefinition(AssignDefinition assignDef, IPythonNature nature, ICompletionCache completionCache) throws Exception { IDefinition[] definitions2; if ("None".equals(assignDef.type)) { @@ -297,7 +298,8 @@ public Definition rebaseAssignDefinition(AssignDefinition assignDef, IPythonNatu return assignDef; } - public Definition rebaseFunctionDef(Definition definition, IPythonNature nature, ICompletionCache completionCache) + public static Definition rebaseFunctionDef(Definition definition, IPythonNature nature, + ICompletionCache completionCache) throws Exception { ITypeInfo type = NodeUtils.getReturnTypeFromFuncDefAST(definition.ast); if (type != null) { @@ -328,7 +330,7 @@ public Definition rebaseFunctionDef(Definition definition, IPythonNature nature, return definition; } - private Definition rebaseToClassDefDefinition(IPythonNature nature, CompletionCache completionCache, + private static Definition rebaseToClassDefDefinition(IPythonNature nature, CompletionCache completionCache, Definition definition, CompletionState completionState) throws CompletionRecursionException, Exception { if (completionState == null) { @@ -355,10 +357,10 @@ private Definition rebaseToClassDefDefinition(IPythonNature nature, CompletionCa return definition; } - public boolean checkCreationBasedOnFoundPointers(PyEdit edit, PySelection callPs, + public static boolean checkCreationBasedOnFoundPointers(IPyEdit edit, PySelection callPs, List ret, TddPossibleMatches possibleMatch, ItemPointer[] pointers, String methodToCreate, PySelection newSelection, - IPythonNature nature) throws MisconfigurationException, Exception { + IPythonNature nature, IImageCache imageCache) throws MisconfigurationException, Exception { CompletionCache completionCache = new CompletionCache(); for (ItemPointer pointer : pointers) { Definition definition = pointer.definition; @@ -392,7 +394,7 @@ public boolean checkCreationBasedOnFoundPointers(PyEdit edit, PySelection callPs pyCreateMethod.getCreationStr(), className, definition.module.getName()); TddRefactorCompletionInModule completion = new TddRefactorCompletionInModule(methodToCreate, - tddQuickFixParticipant != null ? tddQuickFixParticipant.imageMethod : null, displayString, + 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; @@ -404,7 +406,7 @@ public boolean checkCreationBasedOnFoundPointers(PyEdit edit, PySelection callPs return false; } - private List configCreateAsAndReturnParametersAfterCall(PySelection callPs, boolean isCall, + private static List configCreateAsAndReturnParametersAfterCall(PySelection callPs, boolean isCall, PyCreateMethodOrField pyCreateMethod, List parametersAfterCall, String methodToCreate) { if (isCall) { pyCreateMethod.setCreateAs(PyCreateMethodOrField.BOUND_METHOD); @@ -420,20 +422,21 @@ private List configCreateAsAndReturnParametersAfterCall(PySelection call return parametersAfterCall; } - private void addCreateMethodOption(PySelection ps, PyEdit edit, List props, + private static void addCreateMethodOption(PySelection ps, IPyEdit edit, List props, String markerContents, List parametersAfterCall, PyCreateMethodOrField pyCreateMethod, - String classNameInLine) { + String classNameInLine, IImageCache imageCache) { String displayString = StringUtils.format("Create %s %s at %s", markerContents, pyCreateMethod.getCreationStr(), classNameInLine); TddRefactorCompletion tddRefactorCompletion = new TddRefactorCompletion(markerContents, - tddQuickFixParticipant.imageMethod, displayString, null, null, IPyCompletionProposal.PRIORITY_CREATE, + imageCache.get(UIConstants.CREATE_METHOD_ICON), displayString, null, null, + IPyCompletionProposal.PRIORITY_CREATE, edit, PyCreateClass.LOCATION_STRATEGY_BEFORE_CURRENT, parametersAfterCall, pyCreateMethod, ps); props.add(tddRefactorCompletion); } - private boolean checkInitCreation(PyEdit edit, PySelection callPs, ItemPointer[] pointers, - List ret) { + private static boolean checkInitCreation(IPyEdit edit, PySelection callPs, ItemPointer[] pointers, + List ret, IImageCache imageCache) { for (ItemPointer pointer : pointers) { Definition definition = pointer.definition; if (definition != null && definition.ast instanceof ClassDef) { @@ -452,7 +455,7 @@ private boolean checkInitCreation(PyEdit edit, PySelection callPs, ItemPointer[] "Create %s __init__ (%s)", className, definition.module.getName()); TddRefactorCompletionInModule completion = new TddRefactorCompletionInModule("__init__", - tddQuickFixParticipant.imageMethod, displayString, null, displayString, + 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; diff --git a/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddRefactorCompletion.java b/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddRefactorCompletion.java index 0e55a13172..04450d5a67 100644 --- a/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddRefactorCompletion.java +++ b/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddRefactorCompletion.java @@ -14,10 +14,11 @@ import org.eclipse.jface.text.contentassist.IContextInformation; import org.eclipse.jface.text.templates.TemplateProposal; import org.eclipse.swt.graphics.Point; +import org.python.pydev.core.IPyEdit; import org.python.pydev.core.MisconfigurationException; import org.python.pydev.core.docutils.PySelection; import org.python.pydev.core.log.Log; -import org.python.pydev.editor.PyEdit; +import org.python.pydev.parser.PyParser; import org.python.pydev.refactoring.core.base.RefactoringInfo; import org.python.pydev.shared_core.image.IImageHandle; @@ -33,7 +34,7 @@ public final class TddRefactorCompletion extends AbstractTddRefactorCompletion { private PySelection ps; TddRefactorCompletion(String replacementString, IImageHandle image, String displayString, - IContextInformation contextInformation, String additionalProposalInfo, int priority, PyEdit edit, + IContextInformation contextInformation, String additionalProposalInfo, int priority, IPyEdit edit, int locationStrategy, List parametersAfterCall, AbstractPyCreateAction pyCreateAction, PySelection ps) { @@ -68,7 +69,8 @@ public Point getSelection(IDocument document) { public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) { if (edit != null) { //We have to reparse to make sure that we'll have an accurate AST. - edit.getParser().reparseDocument(); + PyParser parser = (PyParser) edit.getParser(); + parser.reparseDocument(); } TemplateProposal executed2 = getExecuted(); if (executed2 != null) { diff --git a/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddRefactorCompletionInModule.java b/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddRefactorCompletionInModule.java index 90d5de311c..31c7fbf183 100644 --- a/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddRefactorCompletionInModule.java +++ b/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddRefactorCompletionInModule.java @@ -15,6 +15,7 @@ import org.eclipse.jface.text.contentassist.IContextInformation; import org.eclipse.swt.graphics.Point; import org.python.pydev.ast.item_pointer.ItemPointer; +import org.python.pydev.core.IPyEdit; import org.python.pydev.core.docutils.PySelection; import org.python.pydev.core.log.Log; import org.python.pydev.editor.PyEdit; @@ -34,7 +35,7 @@ public final class TddRefactorCompletionInModule extends AbstractTddRefactorComp public int locationStrategy = AbstractPyCreateAction.LOCATION_STRATEGY_END; public TddRefactorCompletionInModule(String replacementString, IImageHandle image, String displayString, - IContextInformation contextInformation, String additionalProposalInfo, int priority, PyEdit edit, + IContextInformation contextInformation, String additionalProposalInfo, int priority, IPyEdit edit, File module, List parametersAfterCall, AbstractPyCreateAction pyCreateAction, PySelection ps) { super(edit, replacementString, 0, 0, 0, image, displayString, contextInformation, additionalProposalInfo, diff --git a/plugins/org.python.pydev/src/com/python/pydev/analysis/ctrl_1/UndefinedVariableFixParticipant.java b/plugins/org.python.pydev/src/com/python/pydev/analysis/ctrl_1/UndefinedVariableFixParticipant.java index edd84212d0..c78cc5a62a 100644 --- a/plugins/org.python.pydev/src/com/python/pydev/analysis/ctrl_1/UndefinedVariableFixParticipant.java +++ b/plugins/org.python.pydev/src/com/python/pydev/analysis/ctrl_1/UndefinedVariableFixParticipant.java @@ -75,8 +75,7 @@ public void addProps(MarkerAnnotationAndPosition markerAnnotation, IAnalysisPref int start = markerAnnotation.position.offset; int end = start + markerAnnotation.position.length; UndefinedVariableQuickFixCreator.createImportQuickProposalsFromMarkerSelectedText(edit, ps, offset, - initialNature, - props, astManager, start, end, forceReparseOnApply); + initialNature, props, astManager, start, end, forceReparseOnApply); } }