/**
* Returns a proposal that can be used to generate the code.
*/
public ICompletionProposal createProposal(RefactoringInfo refactoringInfo, String actTok, int locationStrategy,
List<String> parametersAfterCall) {
PySelection pySelection = refactoringInfo.getPySelection();
ModuleAdapter moduleAdapter = refactoringInfo.getModuleAdapter();
String decorators = "";
IClassDefAdapter targetClass = null;
String body = "${pass}";
if (createInClass != null) {
List<IClassDefAdapter> classes = moduleAdapter.getClasses();
for (IClassDefAdapter iClassDefAdapter : classes) {
if (createInClass.equals(iClassDefAdapter.getName())) {
targetClass = iClassDefAdapter;
break;
}
}
if (targetClass != null) {
switch (createAs) {
case BOUND_METHOD:
parametersAfterCall = checkFirst(parametersAfterCall, "self");
break;
case CLASSMETHOD:
parametersAfterCall = checkFirst(parametersAfterCall, "cls");
decorators = "@classmethod\n";
break;
case STATICMETHOD:
decorators = "@staticmethod\n";
break;
case CONSTANT:
String indent = targetClass.getNodeBodyIndent();
Pass replacePassStatement = getLastPassFromNode(targetClass.getASTNode());
String constant = com.aptana.shared_core.string.StringUtils.format("\n%s = ${None}${cursor}\n", actTok);
Tuple<Integer, String> offsetAndIndent;
offsetAndIndent = getLocationOffset(AbstractPyCreateAction.LOCATION_STRATEGY_FIRST_METHOD,
pySelection, moduleAdapter, targetClass);
return createProposal(pySelection, constant, offsetAndIndent, false, replacePassStatement);
case FIELD:
parametersAfterCall = checkFirst(parametersAfterCall, "self");
FunctionDefAdapter firstInit = targetClass.getFirstInit();
if (firstInit != null) {
FunctionDef astNode = firstInit.getASTNode();
replacePassStatement = getLastPassFromNode(astNode);
//Create the field as the last line in the __init__
int nodeLastLine = firstInit.getNodeLastLine() - 1;
indent = firstInit.getNodeBodyIndent();
String pattern;
if (replacePassStatement == null) {
pattern = com.aptana.shared_core.string.StringUtils.format("\nself.%s = ${None}${cursor}", actTok);
try {
IRegion region = pySelection.getDoc().getLineInformation(nodeLastLine);
int offset = region.getOffset() + region.getLength();
offsetAndIndent = new Tuple<Integer, String>(offset, indent);
} catch (BadLocationException e) {
Log.log(e);
return null;