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;
}
} else {
pattern = com.aptana.shared_core.string.StringUtils.format("self.%s = ${None}${cursor}", actTok);
offsetAndIndent = new Tuple<Integer, String>(-1, ""); //offset will be from the pass stmt
}
return createProposal(pySelection, pattern, offsetAndIndent, false, replacePassStatement);
} else {
//Create the __init__ with the field declaration!
body = com.aptana.shared_core.string.StringUtils.format("self.%s = ${None}${cursor}", actTok);
actTok = "__init__";
locationStrategy = AbstractPyCreateAction.LOCATION_STRATEGY_FIRST_METHOD;
}
break;
}
} else {
//We should create in a class and couldn't find it!
return null;
}
}
String params = "";
String source;
if (parametersAfterCall != null && parametersAfterCall.size() > 0) {
params = createParametersList(parametersAfterCall).toString();
}
Tuple<Integer, String> offsetAndIndent;
Pass replacePassStatement = null;
if (targetClass != null) {
replacePassStatement = getLastPassFromNode(targetClass.getASTNode());
offsetAndIndent = getLocationOffset(locationStrategy, pySelection, moduleAdapter, targetClass);
} else {
offsetAndIndent = getLocationOffset(locationStrategy, pySelection, moduleAdapter);
}