/** * Copyright (c) 2005-2011 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.util.List; import org.eclipse.jface.text.contentassist.ICompletionProposal; import org.python.pydev.core.docutils.PySelection; import org.python.pydev.core.docutils.StringUtils; import org.python.pydev.refactoring.ast.adapters.ModuleAdapter; import org.python.pydev.refactoring.core.base.RefactoringInfo; import com.aptana.shared_core.string.FastStringBuffer; import com.aptana.shared_core.structure.Tuple; /** * This class should be used to generate code for creating a new class. */ public class PyCreateClass extends AbstractPyCreateClassOrMethodOrField { private final static String baseClassStr = "" + "class %s(${object}):\n" + " ${pass}${cursor}\n" + "\n" + "\n" + ""; private final static String baseClassWithInitStr = "" + "class %s(${object}):\n" + " \n" + " def __init__(self, %s):\n" + " ${pass}${cursor}\n" + "\n" + "\n" + ""; public String getCreationStr() { return "class"; } /** * 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 source; if (parametersAfterCall == null || parametersAfterCall.size() == 0) { source = com.aptana.shared_core.string.StringUtils.format(baseClassStr, actTok); } else { FastStringBuffer params = createParametersList(parametersAfterCall); source = com.aptana.shared_core.string.StringUtils.format(baseClassWithInitStr, actTok, params); } Tuple<Integer, String> offsetAndIndent = getLocationOffset(locationStrategy, pySelection, moduleAdapter); return createProposal(pySelection, source, offsetAndIndent); } }