[Pydev-cvs] org.python.pydev.refactoring/tests/org/python/pydev/refactoring/tests/coderefactoring/e
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2008-09-27 20:03:13
|
Update of /cvsroot/pydev/org.python.pydev.refactoring/tests/org/python/pydev/refactoring/tests/coderefactoring/extractmethod In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21605/tests/org/python/pydev/refactoring/tests/coderefactoring/extractmethod Modified Files: MockupExtractMethodRequestProcessor.java ExtractMethodTestSuite.java ExtractMethodTestCase.java MockupExtractMethodConfig.java Log Message: Synching to latest changes: Pydev <ul> <li><strong>Editor</strong>: Cursor settings no longer overridden</li> <li><strong>Code-completion</strong>: If __all__ is defined with runtime elements (and not only in a single assign statement), it's ignored for code-completion purposes</li> <li><strong>Debugger</strong>: Pythonpath the same in debug and regular modes (sys.path[0] is the same directory as the file run)</li> <li><strong>Debugger</strong>: Persist choices done in the debugger when files from the debugger are not found</li> <li><strong>Interpreter config</strong>: "email" automatically added to the "forced builtins"</li> <li><strong>Parser</strong>: Correctly recognizing absolute import with 3 or more levels</li> <li><strong>Syntax check</strong>: Option to do only on active editor</li> </ul> Also: tabs changed for spaces Index: ExtractMethodTestCase.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.refactoring/tests/org/python/pydev/refactoring/tests/coderefactoring/extractmethod/ExtractMethodTestCase.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ExtractMethodTestCase.java 20 Oct 2007 19:31:00 -0000 1.5 --- ExtractMethodTestCase.java 27 Sep 2008 20:00:51 -0000 1.6 *************** *** 32,116 **** public class ExtractMethodTestCase extends AbstractIOTestCase { ! public ExtractMethodTestCase(String name) { ! super(name); ! } ! @Override ! public void runTest() throws Throwable { ! REF.IN_TESTS = true; ! MockupExtractMethodConfig config = initConfig(); ! IDocument doc = new Document(getSource()); ! Module astModule = VisitorFactory.getRootNode(doc); ! String name = getFile().getName(); ! name = name.substring(0, name.length()-4); ! ModuleAdapter module = VisitorFactory.createModuleAdapter(null, new SourceModule(name, getFile(), astModule), new PythonNatureStub()); ! ITextSelection selection = new TextSelection(doc, config.getOffset(), config.getSelectionLength()); ! RefactoringInfo info = new RefactoringInfo(null, doc, selection, null); ! MockupExtractMethodRequestProcessor requestProcessor = setupRequestProcessor(config, module, info); ! IDocument refactoringDoc = applyExtractMethod(info, requestProcessor); ! this.setTestGenerated(refactoringDoc.get()); ! assertEquals(getExpected(), getGenerated()); ! REF.IN_TESTS = false; ! } ! private IDocument applyExtractMethod(RefactoringInfo info, MockupExtractMethodRequestProcessor requestProcessor) ! throws BadLocationException { ! ExtractMethodRequest req = requestProcessor.getRefactoringRequests().get(0); ! ExtractMethodEdit extractMethodEdit = new ExtractMethodEdit(req); ! ExtractCallEdit extractCallEdit = new ExtractCallEdit(req); ! MultiTextEdit edit = new MultiTextEdit(); ! edit.addChild(extractMethodEdit.getEdit()); ! edit.addChild(extractCallEdit.getEdit()); ! IDocument refactoringDoc = new Document(getSource()); ! edit.apply(refactoringDoc); ! return refactoringDoc; ! } ! private MockupExtractMethodRequestProcessor setupRequestProcessor(MockupExtractMethodConfig config, ModuleAdapter module, ! RefactoringInfo info) { ! ModuleAdapter parsedSelection = info.getParsedExtendedSelection(); ! AbstractScopeNode<?> scope = module.getScopeAdapter(info.getExtendedSelection()); ! ParameterReturnDeduce deducer = new ParameterReturnDeduce(scope, info.getExtendedSelection(), module); ! SortedMap<String, String> renameMap = new TreeMap<String, String>(); ! for (String variable : deducer.getParameters()) { ! String newName = variable; ! if (config.getRenameMap().containsKey(variable)) { ! newName = config.getRenameMap().get(variable); ! } ! renameMap.put(variable, newName); ! } ! return new MockupExtractMethodRequestProcessor(scope, info.getExtendedSelection(), parsedSelection, deducer, renameMap, config ! .getOffsetStrategy()); ! } ! private MockupExtractMethodConfig initConfig() { ! MockupExtractMethodConfig config = null; ! XStream xstream = new XStream(); ! xstream.alias("config", MockupExtractMethodConfig.class); ! if (getConfig().length() > 0) { ! config = (MockupExtractMethodConfig) xstream.fromXML(getConfig()); ! } else { ! fail("Could not unserialize configuration"); ! } ! return config; ! } ! @Override ! public String getExpected() { ! return getResult(); ! } } --- 32,116 ---- public class ExtractMethodTestCase extends AbstractIOTestCase { ! public ExtractMethodTestCase(String name) { ! super(name); ! } ! @Override ! public void runTest() throws Throwable { ! REF.IN_TESTS = true; ! MockupExtractMethodConfig config = initConfig(); ! IDocument doc = new Document(getSource()); ! Module astModule = VisitorFactory.getRootNode(doc); ! String name = getFile().getName(); ! name = name.substring(0, name.length()-4); ! ModuleAdapter module = VisitorFactory.createModuleAdapter(null, new SourceModule(name, getFile(), astModule, null), new PythonNatureStub()); ! ITextSelection selection = new TextSelection(doc, config.getOffset(), config.getSelectionLength()); ! RefactoringInfo info = new RefactoringInfo(null, doc, selection, null); ! MockupExtractMethodRequestProcessor requestProcessor = setupRequestProcessor(config, module, info); ! IDocument refactoringDoc = applyExtractMethod(info, requestProcessor); ! this.setTestGenerated(refactoringDoc.get()); ! assertEquals(getExpected(), getGenerated()); ! REF.IN_TESTS = false; ! } ! private IDocument applyExtractMethod(RefactoringInfo info, MockupExtractMethodRequestProcessor requestProcessor) ! throws BadLocationException { ! ExtractMethodRequest req = requestProcessor.getRefactoringRequests().get(0); ! ExtractMethodEdit extractMethodEdit = new ExtractMethodEdit(req); ! ExtractCallEdit extractCallEdit = new ExtractCallEdit(req); ! MultiTextEdit edit = new MultiTextEdit(); ! edit.addChild(extractMethodEdit.getEdit()); ! edit.addChild(extractCallEdit.getEdit()); ! IDocument refactoringDoc = new Document(getSource()); ! edit.apply(refactoringDoc); ! return refactoringDoc; ! } ! private MockupExtractMethodRequestProcessor setupRequestProcessor(MockupExtractMethodConfig config, ModuleAdapter module, ! RefactoringInfo info) { ! ModuleAdapter parsedSelection = info.getParsedExtendedSelection(); ! AbstractScopeNode<?> scope = module.getScopeAdapter(info.getExtendedSelection()); ! ParameterReturnDeduce deducer = new ParameterReturnDeduce(scope, info.getExtendedSelection(), module); ! SortedMap<String, String> renameMap = new TreeMap<String, String>(); ! for (String variable : deducer.getParameters()) { ! String newName = variable; ! if (config.getRenameMap().containsKey(variable)) { ! newName = config.getRenameMap().get(variable); ! } ! renameMap.put(variable, newName); ! } ! return new MockupExtractMethodRequestProcessor(scope, info.getExtendedSelection(), parsedSelection, deducer, renameMap, config ! .getOffsetStrategy()); ! } ! private MockupExtractMethodConfig initConfig() { ! MockupExtractMethodConfig config = null; ! XStream xstream = new XStream(); ! xstream.alias("config", MockupExtractMethodConfig.class); ! if (getConfig().length() > 0) { ! config = (MockupExtractMethodConfig) xstream.fromXML(getConfig()); ! } else { ! fail("Could not unserialize configuration"); ! } ! return config; ! } ! @Override ! public String getExpected() { ! return getResult(); ! } } Index: ExtractMethodTestSuite.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.refactoring/tests/org/python/pydev/refactoring/tests/coderefactoring/extractmethod/ExtractMethodTestSuite.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ExtractMethodTestSuite.java 20 Oct 2007 19:31:00 -0000 1.3 --- ExtractMethodTestSuite.java 27 Sep 2008 20:00:51 -0000 1.4 *************** *** 14,29 **** public class ExtractMethodTestSuite extends AbstractIOTestSuite { ! public static Test suite() { ! TESTDIR = "tests" + File.separator + "python" + File.separator + "coderefactoring" + File.separator + "extractmethod"; ! ExtractMethodTestSuite testSuite = new ExtractMethodTestSuite(); ! testSuite.createTests(); ! return testSuite; ! } ! @Override ! protected IInputOutputTestCase createTestCase(String testCaseName) { ! return new ExtractMethodTestCase(testCaseName); ! } } --- 14,29 ---- public class ExtractMethodTestSuite extends AbstractIOTestSuite { ! public static Test suite() { ! TESTDIR = "tests" + File.separator + "python" + File.separator + "coderefactoring" + File.separator + "extractmethod"; ! ExtractMethodTestSuite testSuite = new ExtractMethodTestSuite(); ! testSuite.createTests(); ! return testSuite; ! } ! @Override ! protected IInputOutputTestCase createTestCase(String testCaseName) { ! return new ExtractMethodTestCase(testCaseName); ! } } Index: MockupExtractMethodConfig.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.refactoring/tests/org/python/pydev/refactoring/tests/coderefactoring/extractmethod/MockupExtractMethodConfig.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** MockupExtractMethodConfig.java 20 Oct 2007 19:31:00 -0000 1.3 --- MockupExtractMethodConfig.java 27 Sep 2008 20:00:51 -0000 1.4 *************** *** 12,47 **** public class MockupExtractMethodConfig { ! private int offset; ! private int selectionLength; ! private int offsetStrategy; ! private Map<String, String> renameMap; ! public MockupExtractMethodConfig() { ! this.offset = 0; ! this.selectionLength = 0; ! this.offsetStrategy = IOffsetStrategy.AFTERINIT; ! } ! public int getOffset() { ! return offset; ! } ! public int getOffsetStrategy() { ! return offsetStrategy; ! } ! public int getSelectionLength() { ! return selectionLength; ! } ! public Map<String, String> getRenameMap() { ! if (renameMap == null) { ! this.renameMap = new HashMap<String, String>(); ! } ! return renameMap; ! } } --- 12,47 ---- public class MockupExtractMethodConfig { ! private int offset; ! private int selectionLength; ! private int offsetStrategy; ! private Map<String, String> renameMap; ! public MockupExtractMethodConfig() { ! this.offset = 0; ! this.selectionLength = 0; ! this.offsetStrategy = IOffsetStrategy.AFTERINIT; ! } ! public int getOffset() { ! return offset; ! } ! public int getOffsetStrategy() { ! return offsetStrategy; ! } ! public int getSelectionLength() { ! return selectionLength; ! } ! public Map<String, String> getRenameMap() { ! if (renameMap == null) { ! this.renameMap = new HashMap<String, String>(); ! } ! return renameMap; ! } } Index: MockupExtractMethodRequestProcessor.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.refactoring/tests/org/python/pydev/refactoring/tests/coderefactoring/extractmethod/MockupExtractMethodRequestProcessor.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** MockupExtractMethodRequestProcessor.java 20 Oct 2007 19:31:00 -0000 1.4 --- MockupExtractMethodRequestProcessor.java 27 Sep 2008 20:00:51 -0000 1.5 *************** *** 18,52 **** public class MockupExtractMethodRequestProcessor implements IRequestProcessor<ExtractMethodRequest> { ! private AbstractScopeNode<?> scopeAdapter; ! private int offsetStrategy; ! private ModuleAdapter parsedSelection; ! private ParameterReturnDeduce deducer; ! private Map<String, String> renameMap; ! private ITextSelection selection; ! public MockupExtractMethodRequestProcessor(AbstractScopeNode<?> scopeAdapter, ITextSelection selection, ModuleAdapter parsedSelection, ! ParameterReturnDeduce deducer, Map<String, String> renameMap, int offsetStrategy) { ! this.scopeAdapter = scopeAdapter; ! this.selection = selection; ! this.parsedSelection = parsedSelection; ! this.offsetStrategy = offsetStrategy; ! this.deducer = deducer; ! this.renameMap = renameMap; ! } ! public List<ExtractMethodRequest> getRefactoringRequests() { ! List<ExtractMethodRequest> requests = new ArrayList<ExtractMethodRequest>(); ! ExtractMethodRequest req = new ExtractMethodRequest("pepticMethod", this.selection, this.scopeAdapter, this.parsedSelection, ! deducer.getParameters(), deducer.getReturns(), this.renameMap, this.offsetStrategy, "\n"); ! requests.add(req); ! return requests; ! } } --- 18,52 ---- public class MockupExtractMethodRequestProcessor implements IRequestProcessor<ExtractMethodRequest> { ! private AbstractScopeNode<?> scopeAdapter; ! private int offsetStrategy; ! private ModuleAdapter parsedSelection; ! private ParameterReturnDeduce deducer; ! private Map<String, String> renameMap; ! private ITextSelection selection; ! public MockupExtractMethodRequestProcessor(AbstractScopeNode<?> scopeAdapter, ITextSelection selection, ModuleAdapter parsedSelection, ! ParameterReturnDeduce deducer, Map<String, String> renameMap, int offsetStrategy) { ! this.scopeAdapter = scopeAdapter; ! this.selection = selection; ! this.parsedSelection = parsedSelection; ! this.offsetStrategy = offsetStrategy; ! this.deducer = deducer; ! this.renameMap = renameMap; ! } ! public List<ExtractMethodRequest> getRefactoringRequests() { ! List<ExtractMethodRequest> requests = new ArrayList<ExtractMethodRequest>(); ! ExtractMethodRequest req = new ExtractMethodRequest("pepticMethod", this.selection, this.scopeAdapter, this.parsedSelection, ! deducer.getParameters(), deducer.getReturns(), this.renameMap, this.offsetStrategy, "\n"); ! requests.add(req); ! return requests; ! } } |