diff --git a/plugins/com.python.pydev.refactoring/plugin.xml b/plugins/com.python.pydev.refactoring/plugin.xml
index 6239749004..0ac9fa7919 100644
--- a/plugins/com.python.pydev.refactoring/plugin.xml
+++ b/plugins/com.python.pydev.refactoring/plugin.xml
@@ -4,7 +4,7 @@
-
+
@@ -43,7 +43,10 @@
-
+
+
+
+
@@ -51,7 +54,7 @@
-
+
-
-
+
+
@@ -202,11 +205,11 @@
-->
-
+
-
+
-
+
@@ -392,7 +395,7 @@
@@ -430,8 +433,8 @@
label="%peptic.InlineLocalLabel"
menubarPath="org.python.pydev.refactoring.refactoringMenu/pepticRefactoringGroup"
style="push"/>
-
-
+
+
'''
-
+
for action in plugin_install.ACTIONS_AND_BINDING:
cog.outl(template % (action.class_, action.id, action.id, action.desc, action.group))
]]]-->
@@ -538,7 +541,7 @@
label="%peptic.InlineLocalLabel"
menubarPath="org.python.pydev.editor.refactoring/pepticRefactoringGroup">
-
+
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
new file mode 100644
index 0000000000..a0db4b121e
--- /dev/null
+++ b/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddCodeGenerationQuickFixFromMarkersParticipant.java
@@ -0,0 +1,21 @@
+package com.python.pydev.refactoring.tdd;
+
+import com.python.pydev.analysis.additionalinfo.builders.AnalysisRunner;
+import com.python.pydev.analysis.ctrl_1.AbstractAnalysisMarkersParticipants;
+
+public class TddCodeGenerationQuickFixFromMarkersParticipant extends AbstractAnalysisMarkersParticipants {
+
+ private TddQuickFixParticipant tddQuickFixParticipant;
+
+ @Override
+ protected void fillParticipants() {
+ tddQuickFixParticipant = new TddQuickFixParticipant();
+ participants.add(tddQuickFixParticipant);
+ }
+
+ @Override
+ protected String getMarkerType() {
+ return AnalysisRunner.PYDEV_ANALYSIS_PROBLEM_MARKER;
+ }
+
+}
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/TddCodeGenerationQuickFixWithoutMarkersParticipant.java
similarity index 87%
rename from plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddCodeGenerationQuickFixParticipant.java
rename to plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddCodeGenerationQuickFixWithoutMarkersParticipant.java
index c56f8ba859..397ca8e9e4 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/TddCodeGenerationQuickFixWithoutMarkersParticipant.java
@@ -1,9 +1,3 @@
-/**
- * Copyright (c) 2005-2013 by Appcelerator, Inc. All Rights Reserved.
- * Licensed under the terms of the Eclipse Public License (EPL).
- * 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;
import java.io.File;
@@ -23,6 +17,7 @@
import org.python.pydev.ast.refactoring.AbstractPyRefactoring;
import org.python.pydev.ast.refactoring.IPyRefactoring;
import org.python.pydev.ast.refactoring.RefactoringRequest;
+import org.python.pydev.core.IAssistProps;
import org.python.pydev.core.ICompletionCache;
import org.python.pydev.core.IDefinition;
import org.python.pydev.core.IPyEdit;
@@ -51,233 +46,213 @@
import org.python.pydev.shared_core.string.FullRepIterable;
import org.python.pydev.shared_core.string.StringUtils;
-import com.python.pydev.analysis.additionalinfo.builders.AnalysisRunner;
-import com.python.pydev.analysis.ctrl_1.AbstractAnalysisMarkersParticipants;
import com.python.pydev.analysis.refactoring.tdd.AbstractPyCreateAction;
import com.python.pydev.analysis.refactoring.tdd.PyCreateClass;
import com.python.pydev.analysis.refactoring.tdd.PyCreateMethodOrField;
-public class TddCodeGenerationQuickFixParticipant extends AbstractAnalysisMarkersParticipants {
+public class TddCodeGenerationQuickFixWithoutMarkersParticipant implements IAssistProps {
- private TddQuickFixParticipant tddQuickFixParticipant;
+ /**
+ * Just to set in tests to raise an exception.
+ */
+ public static ICallback onGetTddPropsError;
@Override
- protected void fillParticipants() {
- tddQuickFixParticipant = new TddQuickFixParticipant();
- participants.add(tddQuickFixParticipant);
+ public List getProps(PySelection ps, IImageCache imageCache, File f,
+ IPythonNature nature, IPyEdit edit, int offset) throws BadLocationException, MisconfigurationException {
+ List ret = new ArrayList<>();
+ TddCodeGenerationQuickFixWithoutMarkersParticipant.getTddProps(ps, imageCache, f, nature, edit, offset, ret);
+ return ret;
}
@Override
- protected String getMarkerType() {
- return AnalysisRunner.PYDEV_ANALYSIS_PROBLEM_MARKER;
+ public boolean isValid(PySelection ps, String sel, IPyEdit edit, int offset) {
+ return ps.getSelLength() == 0;
}
- @Override
- public List getProps(PySelection ps, IImageCache imageCache, File f,
- IPythonNature nature,
- IPyEdit edit, int offset) throws BadLocationException {
- List ret = super.getProps(ps, imageCache, f, nature, edit, offset);
- TddCodeGenerationQuickFixParticipant.getTddProps(ps, imageCache, f, nature, edit, offset, ret);
- return ret;
- }
+ public static ASTEntry findInitInClass(ClassDef d) {
+ EasyASTIteratorVisitor visitor = EasyASTIteratorVisitor.create(d);
- public static List getTddProps(
- PySelection ps,
- IImageCache imageCache,
- File f,
- IPythonNature nature,
- IPyEdit edit,
- int offset,
- List ret) {
- if (ret == null) {
- ret = new ArrayList();
- }
- if (imageCache == null) {
- imageCache = new DummyImageCache();
+ for (Iterator it = visitor.getMethodsIterator(); it.hasNext();) {
+ ASTEntry next = it.next();
+ if (next.node != null) {
+ String rep = NodeUtils.getRepresentationString(next.node);
+ if ("__init__".equals(rep)) {
+ return next;
+ }
+ }
}
- //Additional option: Generate markers for 'self.' accesses
- int lineOfOffset = ps.getLineOfOffset(offset);
- String lineContents = ps.getLine(lineOfOffset);
+ return null;
+ }
- //Additional option: Generate methods for function calls
- List callsAtLine = ps.getTddPossibleMatchesAtLine();
- if (callsAtLine.size() > 0) {
- //Make sure we don't check the same thing twice.
- Map callsToCheck = new HashMap();
- for (TddPossibleMatches call : callsAtLine) {
- String callString = call.initialPart + call.secondPart;
- callsToCheck.put(callString, call);
+ 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) {
+ ClassDef d = (ClassDef) definition.ast;
+ ASTEntry initEntry = TddCodeGenerationQuickFixWithoutMarkersParticipant.findInitInClass(d);
+
+ if (initEntry == null) {
+ //Give the user a chance to create the __init__.
+ PyCreateMethodOrField pyCreateMethod = new PyCreateMethodOrField();
+ pyCreateMethod.setCreateAs(PyCreateMethodOrField.BOUND_METHOD);
+ String className = NodeUtils.getRepresentationString(d);
+ pyCreateMethod.setCreateInClass(className);
+
+ List parametersAfterCall = callPs.getParametersAfterCall(callPs.getAbsoluteCursorOffset());
+ String displayString = StringUtils.format(
+ "Create %s __init__ (%s)", className,
+ definition.module.getName());
+ 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;
+ ret.add(completion);
+ return true;
+ }
}
+ }
+ return false;
+ }
- CONTINUE_FOR: for (Map.Entry entry : callsToCheck.entrySet()) {
- //we have at least something as SomeClass(a=2,c=3) or self.bar or self.foo.bar() or just foo.bar, etc.
- IPyRefactoring pyRefactoring = AbstractPyRefactoring.getPyRefactoring();
- try {
- TddPossibleMatches possibleMatch = entry.getValue();
- String callWithoutParens = entry.getKey();
+ static void addCreateMethodOption(PySelection ps, IPyEdit edit, List props,
+ String markerContents, List parametersAfterCall, PyCreateMethodOrField pyCreateMethod,
+ String classNameInLine, IImageCache imageCache) {
+ String displayString = StringUtils.format("Create %s %s at %s",
+ markerContents,
+ pyCreateMethod.getCreationStr(), classNameInLine);
+ TddRefactorCompletion tddRefactorCompletion = new TddRefactorCompletion(markerContents,
+ imageCache.get(UIConstants.CREATE_METHOD_ICON), displayString, null, null,
+ IPyCompletionProposal.PRIORITY_CREATE,
+ edit, PyCreateClass.LOCATION_STRATEGY_BEFORE_CURRENT, parametersAfterCall, pyCreateMethod, ps);
+ props.add(tddRefactorCompletion);
+ }
- ItemPointer[] pointers = null;
- PySelection callPs = null;
- TddPossibleMatches lastPossibleMatchNotFound = possibleMatch;
+ static List configCreateAsAndReturnParametersAfterCall(PySelection callPs, boolean isCall,
+ PyCreateMethodOrField pyCreateMethod, List parametersAfterCall, String methodToCreate) {
+ if (isCall) {
+ pyCreateMethod.setCreateAs(PyCreateMethodOrField.BOUND_METHOD);
+ parametersAfterCall = callPs.getParametersAfterCall(callPs.getAbsoluteCursorOffset());
+ } else {
+ if (StringUtils.isAllUpper(methodToCreate)) {
+ pyCreateMethod.setCreateAs(PyCreateMethodOrField.CONSTANT);
- for (int i = 0; i < 10; i++) { //more than 10 attribute accesses in a line? No way!
+ } else {
+ pyCreateMethod.setCreateAs(PyCreateMethodOrField.FIELD);
+ }
+ }
+ return parametersAfterCall;
+ }
- lastPossibleMatchNotFound = possibleMatch;
- if (i > 0) {
- //We have to take 1 level out of the match... i.e.: if it was self.foo.get(), search now for self.foo.
- String line = FullRepIterable.getWithoutLastPart(possibleMatch.full);
- List tddPossibleMatchesAtLine = ps.getTddPossibleMatchesAtLine(line);
- if (tddPossibleMatchesAtLine.size() > 0) {
- possibleMatch = tddPossibleMatchesAtLine.get(0);
- callWithoutParens = possibleMatch.initialPart + possibleMatch.secondPart;
- } else {
- continue CONTINUE_FOR;
- }
- }
- String full = possibleMatch.full;
- int indexOf = lineContents.indexOf(full);
- if (indexOf < 0) {
- Log.log("Did not expect index < 0.");
- continue CONTINUE_FOR;
- }
- callPs = new PySelection(ps.getDoc(),
- ps.getLineOffset() + indexOf + callWithoutParens.length());
+ public static boolean checkCreationBasedOnFoundPointers(IPyEdit edit, PySelection callPs,
+ List ret,
+ TddPossibleMatches possibleMatch, ItemPointer[] pointers, String methodToCreate, PySelection newSelection,
+ IPythonNature nature, IImageCache imageCache) throws MisconfigurationException, Exception {
+ CompletionCache completionCache = new CompletionCache();
+ for (ItemPointer pointer : pointers) {
+ Definition definition = pointer.definition;
- RefactoringRequest request = new RefactoringRequest(f, callPs, null, nature, edit);
- //Don't look in additional info.
- request.setAdditionalInfo(
- RefactoringRequest.FIND_DEFINITION_IN_ADDITIONAL_INFO, false);
- pointers = pyRefactoring.findDefinition(request);
+ try {
+ definition = rebaseToClassDefDefinition(nature, completionCache, definition, null);
+ } catch (CompletionRecursionException e) {
+ Log.log(e); //Just keep going.
+ }
- if (((pointers != null && pointers.length > 0)
- || StringUtils.count(possibleMatch.full, '.') <= 1)) {
- break;
- }
- }
+ if (definition.ast instanceof ClassDef) {
+ ClassDef d = (ClassDef) definition.ast;
+ String fullName = NodeUtils.getRepresentationString(d) + "." + methodToCreate;
+ IToken repInModule = nature.getAstManager().getRepInModule(definition.module, fullName, nature);
+ if (repInModule != null) {
+ //System.out.println("Skipping creation of: " + fullName); //We found it, so, don't suggest it.
+ continue;
+ }
- if (pointers == null || callPs == null) {
- continue CONTINUE_FOR;
- }
+ for (Boolean isCall : new Boolean[] { true, false }) {
+ //Give the user a chance to create the method we didn't find.
+ PyCreateMethodOrField pyCreateMethod = new PyCreateMethodOrField();
+ List parametersAfterCall = null;
+ parametersAfterCall = TddCodeGenerationQuickFixWithoutMarkersParticipant
+ .configCreateAsAndReturnParametersAfterCall(callPs, isCall, pyCreateMethod,
+ parametersAfterCall, methodToCreate);
+ String className = NodeUtils.getRepresentationString(d);
+ pyCreateMethod.setCreateInClass(className);
- if (lastPossibleMatchNotFound != null && lastPossibleMatchNotFound != possibleMatch
- && pointers.length >= 1) {
- //Ok, as we were analyzing a string as self.bar.foo, we didn't find something in a pass
- //i.e.: self.bar.foo, but we found it in a second pass
- //as self.bar, so, this means we have to open the chance to create the 'foo' in self.bar.
- String methodToCreate = FullRepIterable.getLastPart(lastPossibleMatchNotFound.secondPart);
- int absoluteCursorOffset = callPs.getAbsoluteCursorOffset();
- absoluteCursorOffset = absoluteCursorOffset - (1 + methodToCreate.length()); //+1 for the dot removed too.
- PySelection newSelection = new PySelection(callPs.getDoc(), absoluteCursorOffset);
+ String displayString = StringUtils.format(
+ "Create %s %s at %s (%s)", methodToCreate,
+ pyCreateMethod.getCreationStr(), className, definition.module.getName());
- checkCreationBasedOnFoundPointers(edit, callPs, ret, possibleMatch, pointers, methodToCreate,
- newSelection, nature, imageCache);
- continue CONTINUE_FOR;
- }
+ 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;
+ ret.add(completion);
+ }
+ return true;
+ }
+ }
+ return false;
+ }
- if (pointers.length >= 1) {
+ static Definition rebaseToClassDefDefinition(IPythonNature nature, CompletionCache completionCache,
+ Definition definition, CompletionState completionState) throws CompletionRecursionException, Exception {
- //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, 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__
- boolean foundInInit = false;
- for (ItemPointer p : pointers) {
- Definition definition = p.definition;
- try {
- Object peek = definition.scope.getScopeStack().peek();
- if (peek instanceof FunctionDef) {
- FunctionDef functionDef = (FunctionDef) peek;
- String rep = NodeUtils.getRepresentationString(functionDef);
- if (rep != null && rep.equals("__init__")) {
- foundInInit = true;
- break;
- }
- }
- } catch (Exception e) {
- }
- }
- if (!foundInInit) {
- checkMethodCreationAtClass(edit, pyRefactoring, callWithoutParens, callPs, ret,
- lineContents, possibleMatch, f, nature, imageCache);
- }
- }
+ if (completionState == null) {
+ completionState = new CompletionState();
+ }
- } else if (pointers.length == 0) {
- checkMethodCreationAtClass(edit, pyRefactoring, callWithoutParens, callPs, ret, lineContents,
- possibleMatch, f, nature, imageCache);
+ if (definition.ast instanceof ClassDef) {
+ return definition;
+ }
- }
- } catch (Exception e) {
- if (onGetTddPropsError != null) {
- onGetTddPropsError.call(e);
- }
- Log.log(e);
- }
+ if (definition instanceof AssignDefinition || definition.ast instanceof FunctionDef) {
+ //Avoid recursions.
+ completionState.checkDefinitionMemory(definition.module, definition);
+ if (definition instanceof AssignDefinition) {
+ definition = rebaseAssignDefinition((AssignDefinition) definition, nature, completionCache);
+
+ } else { // definition.ast MUST BE FunctionDef
+ definition = rebaseFunctionDef(definition, nature, completionCache);
}
+
+ return rebaseToClassDefDefinition(nature, completionCache, definition, completionState);
}
- return ret;
+ return definition;
}
- public static ICallback onGetTddPropsError;
-
- private static boolean checkMethodCreationAtClass(IPyEdit edit, IPyRefactoring pyRefactoring,
- String callWithoutParens,
- PySelection callPs, List ret, String lineContents,
- TddPossibleMatches possibleMatch,
- 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
- //if it could be a method in a local variable.
- String[] headAndTail = FullRepIterable.headAndTail(callWithoutParens);
- if (headAndTail[0].length() > 0) {
-
- String methodToCreate = headAndTail[1];
- if (headAndTail[0].equals("self")) {
- //creating something in the current class -- note that if it was self.bar here, we'd treat it as regular
- //(i.e.: no special support for self), so, we wouldn't enter here!
- int firstCharPosition = PySelection.getFirstCharPosition(lineContents);
- LineStartingScope scopeStart = callPs.getPreviousLineThatStartsScope(PySelection.CLASS_TOKEN, false,
- firstCharPosition);
- String classNameInLine = null;
- if (scopeStart != null) {
- for (Boolean isCall : new Boolean[] { true, false }) {
- PyCreateMethodOrField pyCreateMethod = new PyCreateMethodOrField();
- List parametersAfterCall = null;
- parametersAfterCall = configCreateAsAndReturnParametersAfterCall(callPs, isCall,
- pyCreateMethod, parametersAfterCall, methodToCreate);
- String startingScopeLineContents = callPs.getLine(scopeStart.iLineStartingScope);
- classNameInLine = PySelection.getClassNameInLine(startingScopeLineContents);
- if (classNameInLine != null && classNameInLine.length() > 0) {
- pyCreateMethod.setCreateInClass(classNameInLine);
-
- addCreateMethodOption(callPs, edit, ret, methodToCreate, parametersAfterCall,
- pyCreateMethod, classNameInLine, imageCache);
- }
- }
- }
- return true;
+ public static Definition rebaseFunctionDef(Definition definition, IPythonNature nature,
+ ICompletionCache completionCache)
+ throws Exception {
+ ITypeInfo type = NodeUtils.getReturnTypeFromFuncDefAST(definition.ast);
+ if (type != null) {
+ // ok, go to the definition of whatever is set
+ IDefinition[] definitions2 = definition.module.findDefinition(
+ CompletionStateFactory.getEmptyCompletionState(type.getActTok(), nature, completionCache),
+ definition.line,
+ definition.col, nature);
+ if (definitions2.length == 1) {
+ return (Definition) definitions2[0];
}
+ }
- int absoluteCursorOffset = callPs.getAbsoluteCursorOffset();
- absoluteCursorOffset = absoluteCursorOffset - (1 + methodToCreate.length()); //+1 for the dot removed too.
- PySelection newSelection = new PySelection(callPs.getDoc(), absoluteCursorOffset);
- request = new RefactoringRequest(f, newSelection, null, nature, edit);
- //Don't look in additional info.
- request.setAdditionalInfo(RefactoringRequest.FIND_DEFINITION_IN_ADDITIONAL_INFO, false);
- request.setAdditionalInfo(RefactoringRequest.FIND_DEFINITION_FOLLOW_PARAM_DECLARATION, true);
- pointers = pyRefactoring.findDefinition(request);
- if (pointers.length == 1) {
- if (checkCreationBasedOnFoundPointers(edit, callPs, ret, possibleMatch, pointers, methodToCreate,
- newSelection, nature, imageCache)) {
- return true;
- }
+ List returns = ReturnVisitor.findReturns((FunctionDef) definition.ast);
+ for (Return returnFound : returns) {
+ String act = NodeUtils.getFullRepresentationString(returnFound.value);
+ if (act == null) {
+ continue;
+ }
+ //ok, go to the definition of whatever is set
+ IDefinition[] definitions2 = definition.module.findDefinition(
+ CompletionStateFactory.getEmptyCompletionState(act, nature, completionCache), definition.line,
+ definition.col, nature);
+ if (definitions2.length == 1) {
+ return (Definition) definitions2[0];
}
}
- return false;
+ return definition;
}
public static Definition rebaseAssignDefinition(AssignDefinition assignDef, IPythonNature nature,
@@ -310,188 +285,211 @@ public static Definition rebaseAssignDefinition(AssignDefinition assignDef, IPyt
return assignDef;
}
- public static Definition rebaseFunctionDef(Definition definition, IPythonNature nature,
- ICompletionCache completionCache)
- throws Exception {
- ITypeInfo type = NodeUtils.getReturnTypeFromFuncDefAST(definition.ast);
- if (type != null) {
- // ok, go to the definition of whatever is set
- IDefinition[] definitions2 = definition.module.findDefinition(
- CompletionStateFactory.getEmptyCompletionState(type.getActTok(), nature, completionCache),
- definition.line,
- definition.col, nature);
- if (definitions2.length == 1) {
- return (Definition) definitions2[0];
- }
- }
+ static boolean checkMethodCreationAtClass(IPyEdit edit, IPyRefactoring pyRefactoring,
+ String callWithoutParens,
+ PySelection callPs, List ret, String lineContents,
+ TddPossibleMatches possibleMatch,
+ 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
+ //if it could be a method in a local variable.
+ String[] headAndTail = FullRepIterable.headAndTail(callWithoutParens);
+ if (headAndTail[0].length() > 0) {
- List returns = ReturnVisitor.findReturns((FunctionDef) definition.ast);
- for (Return returnFound : returns) {
- String act = NodeUtils.getFullRepresentationString(returnFound.value);
- if (act == null) {
- continue;
+ String methodToCreate = headAndTail[1];
+ if (headAndTail[0].equals("self")) {
+ //creating something in the current class -- note that if it was self.bar here, we'd treat it as regular
+ //(i.e.: no special support for self), so, we wouldn't enter here!
+ int firstCharPosition = PySelection.getFirstCharPosition(lineContents);
+ LineStartingScope scopeStart = callPs.getPreviousLineThatStartsScope(PySelection.CLASS_TOKEN, false,
+ firstCharPosition);
+ String classNameInLine = null;
+ if (scopeStart != null) {
+ for (Boolean isCall : new Boolean[] { true, false }) {
+ PyCreateMethodOrField pyCreateMethod = new PyCreateMethodOrField();
+ List parametersAfterCall = null;
+ parametersAfterCall = TddCodeGenerationQuickFixWithoutMarkersParticipant
+ .configCreateAsAndReturnParametersAfterCall(callPs, isCall,
+ pyCreateMethod, parametersAfterCall, methodToCreate);
+ String startingScopeLineContents = callPs.getLine(scopeStart.iLineStartingScope);
+ classNameInLine = PySelection.getClassNameInLine(startingScopeLineContents);
+ if (classNameInLine != null && classNameInLine.length() > 0) {
+ pyCreateMethod.setCreateInClass(classNameInLine);
+
+ TddCodeGenerationQuickFixWithoutMarkersParticipant.addCreateMethodOption(callPs, edit, ret,
+ methodToCreate, parametersAfterCall,
+ pyCreateMethod, classNameInLine, imageCache);
+ }
+ }
+ }
+ return true;
}
- //ok, go to the definition of whatever is set
- IDefinition[] definitions2 = definition.module.findDefinition(
- CompletionStateFactory.getEmptyCompletionState(act, nature, completionCache), definition.line,
- definition.col, nature);
- if (definitions2.length == 1) {
- return (Definition) definitions2[0];
+
+ int absoluteCursorOffset = callPs.getAbsoluteCursorOffset();
+ absoluteCursorOffset = absoluteCursorOffset - (1 + methodToCreate.length()); //+1 for the dot removed too.
+ PySelection newSelection = new PySelection(callPs.getDoc(), absoluteCursorOffset);
+ request = new RefactoringRequest(f, newSelection, null, nature, edit);
+ //Don't look in additional info.
+ request.setAdditionalInfo(RefactoringRequest.FIND_DEFINITION_IN_ADDITIONAL_INFO, false);
+ request.setAdditionalInfo(RefactoringRequest.FIND_DEFINITION_FOLLOW_PARAM_DECLARATION, true);
+ pointers = pyRefactoring.findDefinition(request);
+ if (pointers.length == 1) {
+ if (TddCodeGenerationQuickFixWithoutMarkersParticipant.checkCreationBasedOnFoundPointers(edit, callPs,
+ ret, possibleMatch, pointers, methodToCreate,
+ newSelection, nature, imageCache)) {
+ return true;
+ }
}
}
- return definition;
+ return false;
}
- private static Definition rebaseToClassDefDefinition(IPythonNature nature, CompletionCache completionCache,
- Definition definition, CompletionState completionState) throws CompletionRecursionException, Exception {
-
- if (completionState == null) {
- completionState = new CompletionState();
+ public static List getTddProps(
+ PySelection ps,
+ IImageCache imageCache,
+ File f,
+ IPythonNature nature,
+ IPyEdit edit,
+ int offset,
+ List ret) {
+ if (ret == null) {
+ ret = new ArrayList();
}
-
- if (definition.ast instanceof ClassDef) {
- return definition;
+ if (imageCache == null) {
+ imageCache = new DummyImageCache();
}
+ //Additional option: Generate markers for 'self.' accesses
+ int lineOfOffset = ps.getLineOfOffset(offset);
+ String lineContents = ps.getLine(lineOfOffset);
- if (definition instanceof AssignDefinition || definition.ast instanceof FunctionDef) {
- //Avoid recursions.
- completionState.checkDefinitionMemory(definition.module, definition);
- if (definition instanceof AssignDefinition) {
- definition = rebaseAssignDefinition((AssignDefinition) definition, nature, completionCache);
-
- } else { // definition.ast MUST BE FunctionDef
- definition = rebaseFunctionDef(definition, nature, completionCache);
+ //Additional option: Generate methods for function calls
+ List callsAtLine = ps.getTddPossibleMatchesAtLine();
+ if (callsAtLine.size() > 0) {
+ //Make sure we don't check the same thing twice.
+ Map callsToCheck = new HashMap();
+ for (TddPossibleMatches call : callsAtLine) {
+ String callString = call.initialPart + call.secondPart;
+ callsToCheck.put(callString, call);
}
- return rebaseToClassDefDefinition(nature, completionCache, definition, completionState);
- }
-
- return definition;
- }
+ CONTINUE_FOR: for (Map.Entry entry : callsToCheck.entrySet()) {
+ //we have at least something as SomeClass(a=2,c=3) or self.bar or self.foo.bar() or just foo.bar, etc.
+ IPyRefactoring pyRefactoring = AbstractPyRefactoring.getPyRefactoring();
+ try {
+ TddPossibleMatches possibleMatch = entry.getValue();
+ String callWithoutParens = entry.getKey();
- public static boolean checkCreationBasedOnFoundPointers(IPyEdit edit, PySelection callPs,
- List ret,
- TddPossibleMatches possibleMatch, ItemPointer[] pointers, String methodToCreate, PySelection newSelection,
- IPythonNature nature, IImageCache imageCache) throws MisconfigurationException, Exception {
- CompletionCache completionCache = new CompletionCache();
- for (ItemPointer pointer : pointers) {
- Definition definition = pointer.definition;
+ ItemPointer[] pointers = null;
+ PySelection callPs = null;
+ TddPossibleMatches lastPossibleMatchNotFound = possibleMatch;
- try {
- definition = rebaseToClassDefDefinition(nature, completionCache, definition, null);
- } catch (CompletionRecursionException e) {
- Log.log(e); //Just keep going.
- }
+ for (int i = 0; i < 10; i++) { //more than 10 attribute accesses in a line? No way!
- if (definition.ast instanceof ClassDef) {
- ClassDef d = (ClassDef) definition.ast;
- String fullName = NodeUtils.getRepresentationString(d) + "." + methodToCreate;
- IToken repInModule = nature.getAstManager().getRepInModule(definition.module, fullName, nature);
- if (repInModule != null) {
- //System.out.println("Skipping creation of: " + fullName); //We found it, so, don't suggest it.
- continue;
- }
+ lastPossibleMatchNotFound = possibleMatch;
+ if (i > 0) {
+ //We have to take 1 level out of the match... i.e.: if it was self.foo.get(), search now for self.foo.
+ String line = FullRepIterable.getWithoutLastPart(possibleMatch.full);
+ List tddPossibleMatchesAtLine = ps.getTddPossibleMatchesAtLine(line);
+ if (tddPossibleMatchesAtLine.size() > 0) {
+ possibleMatch = tddPossibleMatchesAtLine.get(0);
+ callWithoutParens = possibleMatch.initialPart + possibleMatch.secondPart;
+ } else {
+ continue CONTINUE_FOR;
+ }
+ }
+ String full = possibleMatch.full;
+ int indexOf = lineContents.indexOf(full);
+ if (indexOf < 0) {
+ Log.log("Did not expect index < 0.");
+ continue CONTINUE_FOR;
+ }
+ callPs = new PySelection(ps.getDoc(),
+ ps.getLineOffset() + indexOf + callWithoutParens.length());
- for (Boolean isCall : new Boolean[] { true, false }) {
- //Give the user a chance to create the method we didn't find.
- PyCreateMethodOrField pyCreateMethod = new PyCreateMethodOrField();
- List parametersAfterCall = null;
- parametersAfterCall = configCreateAsAndReturnParametersAfterCall(callPs, isCall, pyCreateMethod,
- parametersAfterCall, methodToCreate);
- String className = NodeUtils.getRepresentationString(d);
- pyCreateMethod.setCreateInClass(className);
+ RefactoringRequest request = new RefactoringRequest(f, callPs, null, nature, edit);
+ //Don't look in additional info.
+ request.setAdditionalInfo(
+ RefactoringRequest.FIND_DEFINITION_IN_ADDITIONAL_INFO, false);
+ pointers = pyRefactoring.findDefinition(request);
- String displayString = StringUtils.format(
- "Create %s %s at %s (%s)", methodToCreate,
- pyCreateMethod.getCreationStr(), className, definition.module.getName());
+ if (((pointers != null && pointers.length > 0)
+ || StringUtils.count(possibleMatch.full, '.') <= 1)) {
+ break;
+ }
+ }
- 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;
- ret.add(completion);
- }
- return true;
- }
- }
- return false;
- }
+ if (pointers == null || callPs == null) {
+ continue CONTINUE_FOR;
+ }
- private static List configCreateAsAndReturnParametersAfterCall(PySelection callPs, boolean isCall,
- PyCreateMethodOrField pyCreateMethod, List parametersAfterCall, String methodToCreate) {
- if (isCall) {
- pyCreateMethod.setCreateAs(PyCreateMethodOrField.BOUND_METHOD);
- parametersAfterCall = callPs.getParametersAfterCall(callPs.getAbsoluteCursorOffset());
- } else {
- if (StringUtils.isAllUpper(methodToCreate)) {
- pyCreateMethod.setCreateAs(PyCreateMethodOrField.CONSTANT);
+ if (lastPossibleMatchNotFound != null && lastPossibleMatchNotFound != possibleMatch
+ && pointers.length >= 1) {
+ //Ok, as we were analyzing a string as self.bar.foo, we didn't find something in a pass
+ //i.e.: self.bar.foo, but we found it in a second pass
+ //as self.bar, so, this means we have to open the chance to create the 'foo' in self.bar.
+ String methodToCreate = FullRepIterable.getLastPart(lastPossibleMatchNotFound.secondPart);
+ int absoluteCursorOffset = callPs.getAbsoluteCursorOffset();
+ absoluteCursorOffset = absoluteCursorOffset - (1 + methodToCreate.length()); //+1 for the dot removed too.
+ PySelection newSelection = new PySelection(callPs.getDoc(), absoluteCursorOffset);
- } else {
- pyCreateMethod.setCreateAs(PyCreateMethodOrField.FIELD);
- }
- }
- return parametersAfterCall;
- }
+ TddCodeGenerationQuickFixWithoutMarkersParticipant.checkCreationBasedOnFoundPointers(edit,
+ callPs,
+ ret, possibleMatch, pointers, methodToCreate,
+ newSelection, nature, imageCache);
+ continue CONTINUE_FOR;
+ }
- private static void addCreateMethodOption(PySelection ps, IPyEdit edit, List props,
- String markerContents, List parametersAfterCall, PyCreateMethodOrField pyCreateMethod,
- String classNameInLine, IImageCache imageCache) {
- String displayString = StringUtils.format("Create %s %s at %s",
- markerContents,
- pyCreateMethod.getCreationStr(), classNameInLine);
- TddRefactorCompletion tddRefactorCompletion = new TddRefactorCompletion(markerContents,
- imageCache.get(UIConstants.CREATE_METHOD_ICON), displayString, null, null,
- IPyCompletionProposal.PRIORITY_CREATE,
- edit, PyCreateClass.LOCATION_STRATEGY_BEFORE_CURRENT, parametersAfterCall, pyCreateMethod, ps);
- props.add(tddRefactorCompletion);
- }
+ if (pointers.length >= 1) {
- 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) {
- ClassDef d = (ClassDef) definition.ast;
- ASTEntry initEntry = findInitInClass(d);
+ //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 (!TddCodeGenerationQuickFixWithoutMarkersParticipant.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__
+ boolean foundInInit = false;
+ for (ItemPointer p : pointers) {
+ Definition definition = p.definition;
+ try {
+ Object peek = definition.scope.getScopeStack().peek();
+ if (peek instanceof FunctionDef) {
+ FunctionDef functionDef = (FunctionDef) peek;
+ String rep = NodeUtils.getRepresentationString(functionDef);
+ if (rep != null && rep.equals("__init__")) {
+ foundInInit = true;
+ break;
+ }
+ }
+ } catch (Exception e) {
+ }
+ }
+ if (!foundInInit) {
+ TddCodeGenerationQuickFixWithoutMarkersParticipant.checkMethodCreationAtClass(edit,
+ pyRefactoring, callWithoutParens, callPs, ret,
+ lineContents, possibleMatch, f, nature, imageCache);
+ }
+ }
- if (initEntry == null) {
- //Give the user a chance to create the __init__.
- PyCreateMethodOrField pyCreateMethod = new PyCreateMethodOrField();
- pyCreateMethod.setCreateAs(PyCreateMethodOrField.BOUND_METHOD);
- String className = NodeUtils.getRepresentationString(d);
- pyCreateMethod.setCreateInClass(className);
+ } else if (pointers.length == 0) {
+ TddCodeGenerationQuickFixWithoutMarkersParticipant.checkMethodCreationAtClass(edit,
+ pyRefactoring,
+ callWithoutParens, callPs, ret, lineContents,
+ possibleMatch, f, nature, imageCache);
- List parametersAfterCall = callPs.getParametersAfterCall(callPs.getAbsoluteCursorOffset());
- String displayString = StringUtils.format(
- "Create %s __init__ (%s)", className,
- definition.module.getName());
- 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;
- ret.add(completion);
- return true;
+ }
+ } catch (Exception e) {
+ if (TddCodeGenerationQuickFixWithoutMarkersParticipant.onGetTddPropsError != null) {
+ TddCodeGenerationQuickFixWithoutMarkersParticipant.onGetTddPropsError.call(e);
+ }
+ Log.log(e);
}
}
}
- return false;
- }
-
- public static ASTEntry findInitInClass(ClassDef d) {
- EasyASTIteratorVisitor visitor = EasyASTIteratorVisitor.create(d);
- for (Iterator it = visitor.getMethodsIterator(); it.hasNext();) {
- ASTEntry next = it.next();
- if (next.node != null) {
- String rep = NodeUtils.getRepresentationString(next.node);
- if ("__init__".equals(rep)) {
- return next;
- }
- }
- }
- return null;
+ return ret;
}
}
diff --git a/plugins/com.python.pydev.refactoring/tests/com/python/pydev/refactoring/tdd/TddCodeGenerationQuickFixParticipantTest.java b/plugins/com.python.pydev.refactoring/tests/com/python/pydev/refactoring/tdd/TddCodeGenerationQuickFixParticipantTest.java
index 63c22eace6..e73fffca98 100644
--- a/plugins/com.python.pydev.refactoring/tests/com/python/pydev/refactoring/tdd/TddCodeGenerationQuickFixParticipantTest.java
+++ b/plugins/com.python.pydev.refactoring/tests/com/python/pydev/refactoring/tdd/TddCodeGenerationQuickFixParticipantTest.java
@@ -62,7 +62,7 @@ public void setUp() throws Exception {
this.restorePythonPath(false);
codeCompletion = new PyCodeCompletion();
- TddCodeGenerationQuickFixParticipant.onGetTddPropsError = new ICallback() {
+ TddCodeGenerationQuickFixWithoutMarkersParticipant.onGetTddPropsError = new ICallback() {
@Override
public Boolean call(Exception e) {
@@ -108,9 +108,10 @@ public void testCreate() throws Exception {
" obj = makeTestObj2()\n" +
" obj.unimplementedFunction()\n" +
"";
- TddCodeGenerationQuickFixParticipant participant = new TddCodeGenerationQuickFixParticipant();
+
Document doc = new Document(s);
- List props = participant.getTddProps(new PySelection(doc, s.length() - 1), null,
+ List props = TddCodeGenerationQuickFixWithoutMarkersParticipant.getTddProps(
+ new PySelection(doc, s.length() - 1), null,
null,
nature, null, s.length() - 1, null);
assertContains("Create unimplementedFunction method at MyClass (__module_not_in_the_pythonpath__)",
@@ -125,9 +126,10 @@ public void testCreate2() throws Exception {
" obj = MyClass()\n" +
" obj.unimplementedFunction(a.x, 'Some comment in ticket.')\n" +
"";
- TddCodeGenerationQuickFixParticipant participant = new TddCodeGenerationQuickFixParticipant();
+
Document doc = new Document(s);
- List props = participant.getTddProps(new PySelection(doc, s.length() - 1), null,
+ List props = TddCodeGenerationQuickFixWithoutMarkersParticipant.getTddProps(
+ new PySelection(doc, s.length() - 1), null,
null,
nature, null, s.length() - 1, null);
TddRefactorCompletionInModule proposal = (TddRefactorCompletionInModule) assertContains(
@@ -160,9 +162,10 @@ public void testDontCreate() throws Exception {
+
" obj.unimplementedFunction()\n" +
"";
- TddCodeGenerationQuickFixParticipant participant = new TddCodeGenerationQuickFixParticipant();
+
Document doc = new Document(s);
- List props = participant.getTddProps(new PySelection(doc, s.length() - 1), null,
+ List props = TddCodeGenerationQuickFixWithoutMarkersParticipant.getTddProps(
+ new PySelection(doc, s.length() - 1), null,
null,
nature, null, s.length() - 1, null);
assertNotContains("Create unimplementedFunction method at MyClass (__module_not_in_the_pythonpath__)",
@@ -179,9 +182,10 @@ public void testCreateWithTypeAsParam() throws Exception {
"\n" +
"def method(foo: Foo = 'A'):\n" +
" foo.bar()";
- TddCodeGenerationQuickFixParticipant participant = new TddCodeGenerationQuickFixParticipant();
+
Document doc = new Document(s);
- List props = participant.getTddProps(new PySelection(doc, s.length() - 1), null,
+ List props = TddCodeGenerationQuickFixWithoutMarkersParticipant.getTddProps(
+ new PySelection(doc, s.length() - 1), null,
null,
nature, null, s.length() - 1, null);
assertContains("Create bar method at Foo (__module_not_in_the_pythonpath__)",
@@ -201,9 +205,10 @@ public void testCreateWithTypeAsParam2() throws Exception {
"\n" +
"def method(foo = Foo()):\n" +
" foo.bar()";
- TddCodeGenerationQuickFixParticipant participant = new TddCodeGenerationQuickFixParticipant();
+
Document doc = new Document(s);
- List props = participant.getTddProps(new PySelection(doc, s.length() - 1), null,
+ List props = TddCodeGenerationQuickFixWithoutMarkersParticipant.getTddProps(
+ new PySelection(doc, s.length() - 1), null,
null,
nature, null, s.length() - 1, null);
assertContains("Create bar method at Foo (__module_not_in_the_pythonpath__)",
@@ -227,9 +232,10 @@ public void testCreateWithTypeAsAnnotation() throws Exception {
"def method():\n" +
" foo = method2()\n" +
" foo.bar()";
- TddCodeGenerationQuickFixParticipant participant = new TddCodeGenerationQuickFixParticipant();
+
Document doc = new Document(s);
- List props = participant.getTddProps(new PySelection(doc, s.length() - 1), null,
+ List props = TddCodeGenerationQuickFixWithoutMarkersParticipant.getTddProps(
+ new PySelection(doc, s.length() - 1), null,
null,
nature, null, s.length() - 1, null);
assertContains("Create bar method at Foo (__module_not_in_the_pythonpath__)",
diff --git a/plugins/com.python.pydev.refactoring/tests/com/python/pydev/refactoring/tdd/TddTestWorkbench.java b/plugins/com.python.pydev.refactoring/tests/com/python/pydev/refactoring/tdd/TddTestWorkbench.java
index db08bcc273..4cb48fc298 100644
--- a/plugins/com.python.pydev.refactoring/tests/com/python/pydev/refactoring/tdd/TddTestWorkbench.java
+++ b/plugins/com.python.pydev.refactoring/tests/com/python/pydev/refactoring/tdd/TddTestWorkbench.java
@@ -143,7 +143,7 @@ private void checkCreateField() throws CoreException, BadLocationException, Misc
"";
setContentsAndWaitReparseAndError(mod1Contents, false); //no error here
- TddCodeGenerationQuickFixParticipant quickFix = new TddCodeGenerationQuickFixParticipant();
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
IDocument doc = editor.getDocument();
int offset = doc.getLength();
PySelection ps = new PySelection(doc, offset);
@@ -184,7 +184,7 @@ private void checkCreateMethodAtField0() throws CoreException, BadLocationExcept
"";
setContentsAndWaitReparseAndError(mod1Contents, false); //no error here
- TddCodeGenerationQuickFixParticipant quickFix = new TddCodeGenerationQuickFixParticipant();
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
IDocument doc = editor.getDocument();
int offset = doc.getLength();
PySelection ps = new PySelection(doc, offset);
@@ -232,7 +232,7 @@ private void checkCreateMethodAtField() throws CoreException, BadLocationExcepti
"";
setContentsAndWaitReparseAndError(mod1Contents, false); //no error here
- TddCodeGenerationQuickFixParticipant quickFix = new TddCodeGenerationQuickFixParticipant();
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
IDocument doc = editor.getDocument();
int offset = doc.getLength();
PySelection ps = new PySelection(doc, offset);
@@ -283,7 +283,7 @@ private void checkCreateFieldAtField() throws CoreException, BadLocationExceptio
"";
setContentsAndWaitReparseAndError(mod1Contents, false); //no error here
- TddCodeGenerationQuickFixParticipant quickFix = new TddCodeGenerationQuickFixParticipant();
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
IDocument doc = editor.getDocument();
int offset = doc.getLength();
PySelection ps = new PySelection(doc, offset);
@@ -325,7 +325,7 @@ private void checkCreateBoundMethod() throws CoreException, BadLocationException
" self.bar()";
setContentsAndWaitReparseAndError(mod1Contents, false); //no error here
- TddCodeGenerationQuickFixParticipant quickFix = new TddCodeGenerationQuickFixParticipant();
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
IDocument doc = editor.getDocument();
int offset = doc.getLength() - "r()".length();
PySelection ps = new PySelection(doc, offset);
@@ -369,7 +369,7 @@ private void checkCreateNewMethodInClass() throws CoreException, BadLocationExce
" obj.unimplementedFunction()";
setContentsAndWaitReparseAndError(mod1Contents, false); //no error here
- TddCodeGenerationQuickFixParticipant quickFix = new TddCodeGenerationQuickFixParticipant();
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
IDocument doc = editor.getDocument();
int offset = doc.getLength() - "()".length();
PySelection ps = new PySelection(doc, offset);
@@ -419,7 +419,7 @@ private void checkCreateMethod3() throws CoreException, BadLocationException, Mi
"";
setContentsAndWaitReparseAndError(mod1Contents);
- TddCodeGenerationQuickFixParticipant quickFix = new TddCodeGenerationQuickFixParticipant();
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
int offset = mod1Contents.length();
PySelection ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
@@ -461,7 +461,7 @@ private void checkCreateMethod4() throws CoreException, BadLocationException, Mi
"";
setContentsAndWaitReparseAndError(mod1Contents);
- TddCodeGenerationQuickFixParticipant quickFix = new TddCodeGenerationQuickFixParticipant();
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
int offset = mod1Contents.length();
PySelection ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
@@ -503,7 +503,7 @@ private void checkCreateMethod2() throws CoreException, BadLocationException, Mi
"";
setContentsAndWaitReparseAndError(mod1Contents);
- TddCodeGenerationQuickFixParticipant quickFix = new TddCodeGenerationQuickFixParticipant();
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
int offset = mod1Contents.length();
PySelection ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
@@ -534,7 +534,7 @@ private void checkCreateMethod() throws CoreException, BadLocationException, Mis
String mod1Contents = "Foo";
setContentsAndWaitReparseAndError(mod1Contents);
- TddCodeGenerationQuickFixParticipant quickFix = new TddCodeGenerationQuickFixParticipant();
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
PySelection ps = new PySelection(editor.getDocument(), 0);
assertTrue(quickFix.isValid(ps, "", editor, 0));
List props = quickFix.getProps(ps, SharedUiPlugin.getImageCache(),
@@ -559,7 +559,7 @@ private void checkCreateMethod() throws CoreException, BadLocationException, Mis
private void checkCreateMethodAtOtherModule()
throws CoreException, BadLocationException, MisconfigurationException {
String mod1Contents;
- TddCodeGenerationQuickFixParticipant quickFix;
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix;
PySelection ps;
IFile mod2 = initFile.getParent().getFile(new Path("other_module2.py"));
mod2.create(new ByteArrayInputStream("".getBytes()), true, null);
@@ -571,7 +571,7 @@ private void checkCreateMethodAtOtherModule()
"other_module2.Foo(a, b)";
setContentsAndWaitReparseAndError(mod1Contents);
- quickFix = new TddCodeGenerationQuickFixParticipant();
+ quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
int offset = mod1Contents.length() - "o(a, b)".length();
ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
@@ -593,7 +593,7 @@ private void checkCreateMethodAtOtherModule()
private void checkCreateMethodAtOtherModule2() throws CoreException, BadLocationException,
MisconfigurationException {
String mod1Contents;
- TddCodeGenerationQuickFixParticipant quickFix;
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix;
PySelection ps;
IFile mod2 = initFile.getParent().getFile(new Path("other_module3.py"));
String str = "" +
@@ -609,7 +609,7 @@ private void checkCreateMethodAtOtherModule2() throws CoreException, BadLocation
"other_module3.Bar.Foo(10, 20)";
setContentsAndWaitReparseAndError(mod1Contents);
- quickFix = new TddCodeGenerationQuickFixParticipant();
+ quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
int offset = mod1Contents.length() - "o(a, b)".length();
ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
@@ -638,7 +638,7 @@ private void checkCreateMethodAtOtherModule2() throws CoreException, BadLocation
private void checkCreateMethodAtOtherModule4() throws CoreException, BadLocationException,
MisconfigurationException {
String mod1Contents;
- TddCodeGenerationQuickFixParticipant quickFix;
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix;
PySelection ps;
IFile mod2 = initFile.getParent().getFile(new Path("other_module4.py"));
String str = "";
@@ -650,7 +650,7 @@ private void checkCreateMethodAtOtherModule4() throws CoreException, BadLocation
"from pack1.pack2.other_module4 import Foo";
setContentsAndWaitReparseAndError(mod1Contents);
- quickFix = new TddCodeGenerationQuickFixParticipant();
+ quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
int offset = mod1Contents.length();
ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
@@ -673,7 +673,7 @@ private void checkCreateMethodAtOtherModule4() throws CoreException, BadLocation
private void checkCreateNewModule() throws CoreException, BadLocationException, MisconfigurationException {
String mod1Contents;
- TddCodeGenerationQuickFixParticipant quickFix;
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix;
PySelection ps;
IFile mod2 = initFile.getParent().getFile(new Path("module_new.py"));
final List pyEditCreated = new ArrayList();
@@ -693,7 +693,7 @@ public Object call(PyEdit obj) {
"import pack1.pack2.module_new";
setContentsAndWaitReparseAndError(mod1Contents);
- quickFix = new TddCodeGenerationQuickFixParticipant();
+ quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
int offset = mod1Contents.length();
ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
@@ -715,7 +715,7 @@ public Object call(PyEdit obj) {
private void checkCreateNewModule4() throws CoreException, BadLocationException, MisconfigurationException {
String mod1Contents;
- TddCodeGenerationQuickFixParticipant quickFix;
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix;
PySelection ps;
IFile mod3 = initFile.getParent().getFile(new Path("module_new3.py"));
final List pyEditCreated = new ArrayList();
@@ -735,7 +735,7 @@ public Object call(PyEdit obj) {
"from pack1.pack2 import module_new3";
setContentsAndWaitReparseAndError(mod1Contents);
- quickFix = new TddCodeGenerationQuickFixParticipant();
+ quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
int offset = mod1Contents.length();
ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
@@ -757,7 +757,7 @@ public Object call(PyEdit obj) {
private void checkCreateNewModule2() throws CoreException, BadLocationException, MisconfigurationException {
String mod1Contents;
- TddCodeGenerationQuickFixParticipant quickFix;
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix;
PySelection ps;
List props;
IFile mod2 = initFile.getParent().getFile(new Path("pack2a/module_new.py"));
@@ -778,7 +778,7 @@ public Object call(PyEdit obj) {
"import pack1.pack2.pack2a.module_new";
setContentsAndWaitReparseAndError(mod1Contents);
- quickFix = new TddCodeGenerationQuickFixParticipant();
+ quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
int offset = mod1Contents.length();
ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
@@ -802,7 +802,7 @@ public Object call(PyEdit obj) {
private void checkCreateNewModule3() throws CoreException, BadLocationException, MisconfigurationException {
String mod1Contents;
- TddCodeGenerationQuickFixParticipant quickFix;
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix;
PySelection ps;
List props;
IFile mod2 = initFile.getParent().getParent().getParent().getFile(new Path("newpack/module_new.py"));
@@ -824,7 +824,7 @@ public Object call(PyEdit obj) {
"import newpack.module_new";
setContentsAndWaitReparseAndError(mod1Contents);
- quickFix = new TddCodeGenerationQuickFixParticipant();
+ quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
int offset = mod1Contents.length();
ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
@@ -844,7 +844,7 @@ public Object call(PyEdit obj) {
"module_new.NewClass";
setContentsAndWaitReparseAndError(mod1Contents);
- quickFix = new TddCodeGenerationQuickFixParticipant();
+ quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
offset = mod1Contents.length();
ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
@@ -872,7 +872,7 @@ public Object call(PyEdit obj) {
" module_new.NewClass(param)"; //the 'undefined param' will be the error
setContentsAndWaitReparseAndError(mod1Contents);
- quickFix = new TddCodeGenerationQuickFixParticipant();
+ quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
offset = mod1Contents.length();
ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
@@ -905,7 +905,7 @@ public Object call(PyEdit obj) {
}
}
- private ICompletionProposalExtension2 waitForQuickFixProps(TddCodeGenerationQuickFixParticipant quickFix,
+ private ICompletionProposalExtension2 waitForQuickFixProps(TddCodeGenerationQuickFixFromMarkersParticipant quickFix,
PySelection ps, int offset, String expectedCompletion) throws MisconfigurationException,
BadLocationException {
@@ -927,7 +927,7 @@ private ICompletionProposalExtension2 waitForQuickFixProps(TddCodeGenerationQuic
}
- private List waitForQuickFixProps(TddCodeGenerationQuickFixParticipant quickFix,
+ private List waitForQuickFixProps(TddCodeGenerationQuickFixFromMarkersParticipant quickFix,
PySelection ps, int offset) throws BadLocationException, MisconfigurationException {
for (int i = 0; i < 10; i++) {
List props = quickFix.getProps(ps, SharedUiPlugin.getImageCache(),
@@ -945,7 +945,7 @@ private List waitForQuickFixProps(TddCodeGenerationQu
private void checkCreateNewModuleWithClass2()
throws CoreException, BadLocationException, MisconfigurationException {
String mod1Contents;
- TddCodeGenerationQuickFixParticipant quickFix;
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix;
PySelection ps;
List props;
IFile mod2 = initFile.getParent().getParent().getParent().getFile(new Path("newpack2/module_new.py"));
@@ -966,7 +966,7 @@ public Object call(PyEdit obj) {
"from newpack2.module_new import Foo";
setContentsAndWaitReparseAndError(mod1Contents);
- quickFix = new TddCodeGenerationQuickFixParticipant();
+ quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
int offset = mod1Contents.length();
ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
@@ -992,7 +992,7 @@ public Object call(PyEdit obj) {
private void checkCreateNewModuleWithClass3()
throws CoreException, BadLocationException, MisconfigurationException {
String mod1Contents;
- TddCodeGenerationQuickFixParticipant quickFix;
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix;
PySelection ps;
List props;
IFile mod2 = initFile.getParent().getParent().getParent().getFile(new Path("newpack2/module_new9.py"));
@@ -1013,7 +1013,7 @@ public Object call(PyEdit obj) {
"class Foo:\n from newpack2.module_new9 import Foo";
setContentsAndWaitReparseAndError(mod1Contents);
- quickFix = new TddCodeGenerationQuickFixParticipant();
+ quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
int offset = mod1Contents.length();
ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
@@ -1038,7 +1038,7 @@ public Object call(PyEdit obj) {
private void checkCreateNewModuleWithClass() throws CoreException, BadLocationException, MisconfigurationException {
String mod1Contents;
- TddCodeGenerationQuickFixParticipant quickFix;
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix;
PySelection ps;
List props;
IFile mod2 = initFile.getParent().getFolder(new Path("pack3")).getFile(new Path("module_new2.py"));
@@ -1059,7 +1059,7 @@ public Object call(PyEdit obj) {
"from pack1.pack2.pack3.module_new2 import Foo";
setContentsAndWaitReparseAndError(mod1Contents);
- quickFix = new TddCodeGenerationQuickFixParticipant();
+ quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
int offset = mod1Contents.length();
ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
@@ -1094,7 +1094,7 @@ private void checkCreateClass() throws CoreException, BadLocationException, Misc
String mod1Contents = "Foo";
setContentsAndWaitReparseAndError(mod1Contents);
- TddCodeGenerationQuickFixParticipant quickFix = new TddCodeGenerationQuickFixParticipant();
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
PySelection ps = new PySelection(editor.getDocument(), 0);
assertTrue(quickFix.isValid(ps, "", editor, 0));
List props = quickFix.getProps(ps, SharedUiPlugin.getImageCache(),
@@ -1126,7 +1126,7 @@ private void checkCreateMethodAtClass() throws CoreException, BadLocationExcepti
"foo.Met1()";
setContentsAndWaitReparseAndError(mod1Contents);
- TddCodeGenerationQuickFixParticipant quickFix = new TddCodeGenerationQuickFixParticipant();
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
int offset = mod1Contents.length() - 1;
PySelection ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
@@ -1168,7 +1168,7 @@ private void checkCreateFieldAtClass() throws CoreException, BadLocationExceptio
"foo.new_field";
setContentsAndWaitReparseAndError(mod1Contents);
- TddCodeGenerationQuickFixParticipant quickFix = new TddCodeGenerationQuickFixParticipant();
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
int offset = mod1Contents.length() - 1;
PySelection ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
@@ -1208,7 +1208,7 @@ private void checkCreateFieldAtClass5() throws CoreException, BadLocationExcepti
" self.a = 10";
setContentsAndWaitReparseAndError(mod1Contents);
- TddCodeGenerationQuickFixParticipant quickFix = new TddCodeGenerationQuickFixParticipant();
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
int offset = mod1Contents.length() - 1;
PySelection ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
@@ -1248,7 +1248,7 @@ private void checkCreateFieldAtClass3() throws CoreException, BadLocationExcepti
"foo.new_field";
setContentsAndWaitReparseAndError(mod1Contents);
- TddCodeGenerationQuickFixParticipant quickFix = new TddCodeGenerationQuickFixParticipant();
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
int offset = mod1Contents.length() - 1;
PySelection ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
@@ -1291,7 +1291,7 @@ private void checkCreateFieldAtClass4() throws CoreException, BadLocationExcepti
"";
setContentsAndWaitReparseAndError(mod1Contents);
- TddCodeGenerationQuickFixParticipant quickFix = new TddCodeGenerationQuickFixParticipant();
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
int offset = mod1Contents.length() - secondPart.length();
PySelection ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
@@ -1326,7 +1326,7 @@ private void checkCreateConstant() throws CoreException, BadLocationException, M
setContentsAndWaitReparseAndError(mod1Contents);
- TddCodeGenerationQuickFixParticipant quickFix = new TddCodeGenerationQuickFixParticipant();
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
int offset = mod1Contents.length();
PySelection ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
@@ -1361,7 +1361,7 @@ private void checkCreateFieldAtClass2() throws CoreException, BadLocationExcepti
"foo.new_field";
setContentsAndWaitReparseAndError(mod1Contents);
- TddCodeGenerationQuickFixParticipant quickFix = new TddCodeGenerationQuickFixParticipant();
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
int offset = mod1Contents.length() - 1;
PySelection ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
@@ -1395,7 +1395,7 @@ private void checkCreateMethodAtClass2() throws CoreException, BadLocationExcept
"foo.Met1(param1=10)";
setContentsAndWaitReparseAndError(mod1Contents);
- TddCodeGenerationQuickFixParticipant quickFix = new TddCodeGenerationQuickFixParticipant();
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
int offset = mod1Contents.length() - 1;
PySelection ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
@@ -1426,12 +1426,12 @@ private void checkCreateMethodAtClass2() throws CoreException, BadLocationExcept
private void checkCreateClassWithParams() throws CoreException, BadLocationException, MisconfigurationException {
String mod1Contents;
- TddCodeGenerationQuickFixParticipant quickFix;
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix;
PySelection ps;
List props;
mod1Contents = "Foo(call1(ueo), 'aa,bb', 10, cc)";
setContentsAndWaitReparseAndError(mod1Contents);
- quickFix = new TddCodeGenerationQuickFixParticipant();
+ quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
ps = new PySelection(editor.getDocument(), 0);
assertTrue(quickFix.isValid(ps, "", editor, 0));
props = quickFix.getProps(ps, SharedUiPlugin.getImageCache(), editor.getEditorFile(), editor.getPythonNature(),
@@ -1456,12 +1456,12 @@ private void checkCreateClassWithParams() throws CoreException, BadLocationExcep
private void checkCreateClassWithParams2() throws CoreException, BadLocationException, MisconfigurationException {
String mod1Contents;
- TddCodeGenerationQuickFixParticipant quickFix;
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix;
PySelection ps;
List props;
mod1Contents = "Foo(a=10, b=20)";
setContentsAndWaitReparseAndError(mod1Contents);
- quickFix = new TddCodeGenerationQuickFixParticipant();
+ quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
ps = new PySelection(editor.getDocument(), 0);
assertTrue(quickFix.isValid(ps, "", editor, 0));
props = quickFix.getProps(ps, SharedUiPlugin.getImageCache(), editor.getEditorFile(), editor.getPythonNature(),
@@ -1493,7 +1493,7 @@ private void checkCreateClassInit2() throws CoreException, BadLocationException,
private void checkCreateClassInit3() throws CoreException, BadLocationException, MisconfigurationException {
String mod1Contents;
- TddCodeGenerationQuickFixParticipant quickFix;
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix;
PySelection ps;
List props;
mod1Contents = "" +
@@ -1507,7 +1507,7 @@ private void checkCreateClassInit3() throws CoreException, BadLocationException,
+
"Foo(a=10, b=20)";
setContentsAndWaitReparseAndError(mod1Contents);
- quickFix = new TddCodeGenerationQuickFixParticipant();
+ quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
int offset = mod1Contents.length();
ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
@@ -1540,7 +1540,7 @@ private void checkCreateClassInit3() throws CoreException, BadLocationException,
private void baseCheckCreateClassInit(int minusOffset) throws CoreException, BadLocationException,
MisconfigurationException {
String mod1Contents;
- TddCodeGenerationQuickFixParticipant quickFix;
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix;
PySelection ps;
List props;
mod1Contents = "" +
@@ -1551,7 +1551,7 @@ private void baseCheckCreateClassInit(int minusOffset) throws CoreException, Bad
"\n" +
"Foo(a=10, b=20)";
setContentsAndWaitReparseAndError(mod1Contents);
- quickFix = new TddCodeGenerationQuickFixParticipant();
+ quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
int offset = mod1Contents.length() - minusOffset;
ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));
@@ -1582,7 +1582,7 @@ private void baseCheckCreateClassInit(int minusOffset) throws CoreException, Bad
private void checkCreateClassAtOtherModule() throws CoreException, BadLocationException, MisconfigurationException {
String mod1Contents;
- TddCodeGenerationQuickFixParticipant quickFix;
+ TddCodeGenerationQuickFixFromMarkersParticipant quickFix;
PySelection ps;
List props;
IFile mod2 = initFile.getParent().getFile(new Path("other_module.py"));
@@ -1595,7 +1595,7 @@ private void checkCreateClassAtOtherModule() throws CoreException, BadLocationEx
"other_module.Foo";
setContentsAndWaitReparseAndError(mod1Contents);
- quickFix = new TddCodeGenerationQuickFixParticipant();
+ quickFix = new TddCodeGenerationQuickFixFromMarkersParticipant();
int offset = mod1Contents.length() - 1;
ps = new PySelection(editor.getDocument(), offset);
assertTrue(quickFix.isValid(ps, "", editor, offset));