PageRenderTime 73ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

/eclipse-cdt-8.1.0/org.eclipse.cdt-CDT_8_1_0/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java

#
Java | 4461 lines | 308 code | 137 blank | 4016 comment | 12 complexity | 48e1bbff9481674f6ce526170df9427a MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. /*******************************************************************************
  2. * Rapperswil, University of applied sciences and others
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors:
  9. * Institute for Software - initial API and implementation
  10. * Sergey Prigogin (Google)
  11. *******************************************************************************/
  12. package org.eclipse.cdt.ui.tests.refactoring.extractfunction;
  13. import java.util.HashMap;
  14. import java.util.List;
  15. import java.util.Map;
  16. import junit.framework.Test;
  17. import org.eclipse.cdt.ui.PreferenceConstants;
  18. import org.eclipse.cdt.ui.tests.refactoring.RefactoringTestBase;
  19. import org.eclipse.cdt.internal.ui.refactoring.CRefactoring;
  20. import org.eclipse.cdt.internal.ui.refactoring.NameInformation;
  21. import org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionInformation;
  22. import org.eclipse.cdt.internal.ui.refactoring.extractfunction.ExtractFunctionRefactoring;
  23. import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
  24. /**
  25. * Tests for Extract Function refactoring.
  26. */
  27. public class ExtractFunctionRefactoringTest extends RefactoringTestBase {
  28. private static final String NO_RETURN_VALUE = "";
  29. private String extractedFunctionName = "extracted";
  30. private String returnValue;
  31. // Map from old names to new ones.
  32. private Map<String, String> parameterRename = new HashMap<String, String>();
  33. // New positions of parameters, or null.
  34. private int[] parameterOrder;
  35. private VisibilityEnum visibility = VisibilityEnum.v_private;
  36. private boolean virtual;
  37. private boolean replaceDuplicates = true;
  38. private ExtractFunctionRefactoring refactoring;
  39. public ExtractFunctionRefactoringTest() {
  40. super();
  41. }
  42. public ExtractFunctionRefactoringTest(String name) {
  43. super(name);
  44. }
  45. public static Test suite() {
  46. return suite(ExtractFunctionRefactoringTest.class);
  47. }
  48. @Override
  49. protected void resetPreferences() {
  50. super.resetPreferences();
  51. getPreferenceStore().setToDefault(PreferenceConstants.FUNCTION_OUTPUT_PARAMETERS_BEFORE_INPUT);
  52. getPreferenceStore().setToDefault(PreferenceConstants.FUNCTION_PASS_OUTPUT_PARAMETERS_BY_POINTER);
  53. }
  54. @Override
  55. protected CRefactoring createRefactoring() {
  56. refactoring = new ExtractFunctionRefactoring(getSelectedTranslationUnit(), getSelection(),
  57. getCProject());
  58. return refactoring;
  59. }
  60. @Override
  61. protected void simulateUserInput() {
  62. ExtractFunctionInformation refactoringInfo = refactoring.getRefactoringInfo();
  63. refactoringInfo.setMethodName(extractedFunctionName);
  64. refactoringInfo.setReplaceDuplicates(replaceDuplicates);
  65. if (refactoringInfo.getMandatoryReturnVariable() == null) {
  66. if (returnValue != null) {
  67. for (NameInformation nameInfo : refactoringInfo.getParameters()) {
  68. nameInfo.setReturnValue(returnValue.equals(getName(nameInfo)));
  69. }
  70. }
  71. }
  72. if (!parameterRename.isEmpty()) {
  73. for (NameInformation nameInfo : refactoringInfo.getParameters()) {
  74. String newName = parameterRename.get(getName(nameInfo));
  75. if (newName != null)
  76. nameInfo.setNewName(newName);
  77. }
  78. }
  79. if (parameterOrder != null) {
  80. List<NameInformation> parameters = refactoringInfo.getParameters();
  81. NameInformation[] originalParameters = parameters.toArray(new NameInformation[parameters.size()]);
  82. for (int i = 0; i < parameterOrder.length; i++) {
  83. parameters.set(parameterOrder[i], originalParameters[i]);
  84. }
  85. }
  86. refactoringInfo.setVisibility(visibility);
  87. refactoringInfo.setVirtual(virtual);
  88. }
  89. private String getName(NameInformation nameInfo) {
  90. return String.valueOf(nameInfo.getName().getSimpleID());
  91. }
  92. //A.h
  93. //#ifndef A_H_
  94. //#define A_H_
  95. //
  96. //class A {
  97. //public:
  98. // A();
  99. // virtual ~A();
  100. // int foo();
  101. //
  102. //private:
  103. // int help();
  104. //};
  105. //
  106. //#endif /*A_H_*/
  107. //====================
  108. //#ifndef A_H_
  109. //#define A_H_
  110. //
  111. //class A {
  112. //public:
  113. // A();
  114. // virtual ~A();
  115. // int foo();
  116. //
  117. //private:
  118. // int help();
  119. // int extracted();
  120. //};
  121. //
  122. //#endif /*A_H_*/
  123. //A.cpp
  124. //#include "A.h"
  125. //
  126. //A::A() {
  127. //}
  128. //
  129. //A::~A() {
  130. //}
  131. //
  132. //int A::foo() {
  133. // /*$*/int i = 2;
  134. // ++i;
  135. // help();/*$$*/
  136. // return i;
  137. //}
  138. //
  139. //int A::help() {
  140. // return 42;
  141. //}
  142. //====================
  143. //#include "A.h"
  144. //
  145. //A::A() {
  146. //}
  147. //
  148. //A::~A() {
  149. //}
  150. //
  151. //int A::extracted() {
  152. // int i = 2;
  153. // ++i;
  154. // help();
  155. // return i;
  156. //}
  157. //
  158. //int A::foo() {
  159. // int i = extracted();
  160. // return i;
  161. //}
  162. //
  163. //int A::help() {
  164. // return 42;
  165. //}
  166. public void testLocalVariableDeclaration_1() throws Exception {
  167. assertRefactoringSuccess();
  168. }
  169. //A.h
  170. //#ifndef A_H_
  171. //#define A_H_
  172. //
  173. //#include "B.h"
  174. //
  175. //class A {
  176. //public:
  177. // A();
  178. // virtual ~A();
  179. // void foo();
  180. // B b;
  181. //
  182. //private:
  183. // int help();
  184. //};
  185. //
  186. //#endif /*A_H_*/
  187. //====================
  188. //#ifndef A_H_
  189. //#define A_H_
  190. //
  191. //#include "B.h"
  192. //
  193. //class A {
  194. //public:
  195. // A();
  196. // virtual ~A();
  197. // void foo();
  198. // B b;
  199. //
  200. //private:
  201. // int help();
  202. // void extracted();
  203. //};
  204. //
  205. //#endif /*A_H_*/
  206. //A.cpp
  207. //#include "A.h"
  208. //
  209. //A::A() {
  210. //}
  211. //
  212. //A::~A() {
  213. //}
  214. //
  215. //void A::foo() {
  216. // /*$*/b = new B();
  217. // help();/*$$*/
  218. //}
  219. //
  220. //int A::help() {
  221. // return 42;
  222. //}
  223. //====================
  224. //#include "A.h"
  225. //
  226. //A::A() {
  227. //}
  228. //
  229. //A::~A() {
  230. //}
  231. //
  232. //void A::extracted() {
  233. // b = new B();
  234. // help();
  235. //}
  236. //
  237. //void A::foo() {
  238. // extracted();
  239. //}
  240. //
  241. //int A::help() {
  242. // return 42;
  243. //}
  244. //B.h
  245. //#ifndef B_H_
  246. //#define B_H_
  247. //
  248. //class B {
  249. //public:
  250. // B();
  251. // virtual ~B();
  252. //};
  253. //
  254. //#endif /*B_H_*/
  255. public void testLocalVariableDeclaration_2() throws Exception {
  256. assertRefactoringSuccess();
  257. }
  258. //main.cpp
  259. //class A {
  260. //public:
  261. // explicit A(const char*);
  262. // void m1() const;
  263. // void m2() const;
  264. //};
  265. //
  266. //void main() {
  267. // /*$*/A a("");
  268. // a.m1();/*$$*/
  269. // A b(a); // nonstandard indent to check that it is preserved
  270. //}
  271. //====================
  272. //class A {
  273. //public:
  274. // explicit A(const char*);
  275. // void m1() const;
  276. // void m2() const;
  277. //};
  278. //
  279. //A extracted() {
  280. // A a("");
  281. // a.m1();
  282. // return a;
  283. //}
  284. //
  285. //void main() {
  286. // A a = extracted();
  287. // A b(a); // nonstandard indent to check that it is preserved
  288. //}
  289. public void testLocalVariableDeclaration_3() throws Exception {
  290. assertRefactoringSuccess();
  291. }
  292. //A.h
  293. //#ifndef A_H_
  294. //#define A_H_
  295. //
  296. //class A {
  297. //public:
  298. // A();
  299. // virtual ~A();
  300. // int foo();
  301. //
  302. //private:
  303. // int help();
  304. //};
  305. //
  306. //#endif /*A_H_*/
  307. //A.cpp
  308. //#include "A.h"
  309. //
  310. //A::A() {
  311. //}
  312. //
  313. //A::~A() {
  314. //}
  315. //
  316. //int A::foo() {
  317. // /*$*/int o = 1;
  318. // int i = 2;
  319. // ++i;
  320. // o++;
  321. // help();/*$$*/
  322. // o++;
  323. // return i;
  324. //}
  325. //
  326. //int A::help() {
  327. // return 42;
  328. //}
  329. public void testTwoLocalVariables() throws Exception {
  330. assertRefactoringFailure();
  331. }
  332. //A.h
  333. //#ifndef A_H_
  334. //#define A_H_
  335. //
  336. //class A {
  337. //public:
  338. // A();
  339. // virtual ~A();
  340. // int foo();
  341. //
  342. //private:
  343. // int help();
  344. //};
  345. //
  346. //#endif /*A_H_*/
  347. //====================
  348. //#ifndef A_H_
  349. //#define A_H_
  350. //
  351. //class A {
  352. //public:
  353. // A();
  354. // virtual ~A();
  355. // int foo();
  356. //
  357. //private:
  358. // int help();
  359. // int extracted(int i);
  360. //};
  361. //
  362. //#endif /*A_H_*/
  363. //A.cpp
  364. //#include "A.h"
  365. //
  366. //A::A() {
  367. //}
  368. //
  369. //A::~A() {
  370. //}
  371. //
  372. //int A::foo() {
  373. // int i = 2;
  374. // //comment
  375. // /*$*/++i;
  376. // help();/*$$*/
  377. // return i;
  378. //}
  379. //
  380. //int A::help() {
  381. // return 42;
  382. //}
  383. //====================
  384. //#include "A.h"
  385. //
  386. //A::A() {
  387. //}
  388. //
  389. //A::~A() {
  390. //}
  391. //
  392. //int A::extracted(int i) {
  393. // //comment
  394. // ++i;
  395. // help();
  396. // return i;
  397. //}
  398. //
  399. //int A::foo() {
  400. // int i = 2;
  401. // //comment
  402. // i = extracted(i);
  403. // return i;
  404. //}
  405. //
  406. //int A::help() {
  407. // return 42;
  408. //}
  409. public void testComment() throws Exception {
  410. assertRefactoringSuccess();
  411. }
  412. //main.cpp
  413. //int main() {
  414. // int i;
  415. // // Comment
  416. // /*$*/i= 7;/*$$*/
  417. // return i;
  418. //}
  419. //====================
  420. //int extracted(int i) {
  421. // // Comment
  422. // i = 7;
  423. // return i;
  424. //}
  425. //
  426. //int main() {
  427. // int i;
  428. // // Comment
  429. // i = extracted(i);
  430. // return i;
  431. //}
  432. public void testLeadingComment() throws Exception {
  433. assertRefactoringSuccess();
  434. }
  435. //main.cpp
  436. //int main() {
  437. // int i;
  438. // /*$*/i= 7;/*$$*/ // Comment
  439. // return i;
  440. //}
  441. //====================
  442. //int extracted(int i) {
  443. // i = 7; // Comment
  444. // return i;
  445. //}
  446. //
  447. //int main() {
  448. // int i;
  449. // i = extracted(i);
  450. // return i;
  451. //}
  452. public void testTraillingComment() throws Exception {
  453. assertRefactoringSuccess();
  454. }
  455. //A.h
  456. //#ifndef A_H_
  457. //#define A_H_
  458. //
  459. //#include "B.h"
  460. //
  461. //class A {
  462. //public:
  463. // A();
  464. // virtual ~A();
  465. // void foo();
  466. // B b;
  467. //
  468. //private:
  469. // int help();
  470. //};
  471. //
  472. //#endif /*A_H_*/
  473. //====================
  474. //#ifndef A_H_
  475. //#define A_H_
  476. //
  477. //#include "B.h"
  478. //
  479. //class A {
  480. //public:
  481. // A();
  482. // virtual ~A();
  483. // void foo();
  484. // B b;
  485. //
  486. //private:
  487. // int help();
  488. // void extracted();
  489. //};
  490. //
  491. //#endif /*A_H_*/
  492. //A.cpp
  493. //#include "A.h"
  494. //
  495. //A::A() {
  496. //}
  497. //
  498. //A::~A() {
  499. //}
  500. //
  501. //void A::foo() {
  502. // /*$*/b = new B();
  503. // help();/*$$*/
  504. //}
  505. //
  506. //int A::help() {
  507. // return 42;
  508. //}
  509. //====================
  510. //#include "A.h"
  511. //
  512. //A::A() {
  513. //}
  514. //
  515. //A::~A() {
  516. //}
  517. //
  518. //void A::extracted() {
  519. // b = new B();
  520. // help();
  521. //}
  522. //
  523. //void A::foo() {
  524. // extracted();
  525. //}
  526. //
  527. //int A::help() {
  528. // return 42;
  529. //}
  530. //B.h
  531. //#ifndef B_H_
  532. //#define B_H_
  533. //
  534. //class B {
  535. //public:
  536. // B();
  537. // virtual ~B();
  538. //};
  539. //
  540. //#endif /*B_H_*/
  541. public void testNamedTypedField() throws Exception {
  542. assertRefactoringSuccess();
  543. }
  544. //A.h
  545. //#ifndef A_H_
  546. //#define A_H_
  547. //
  548. //class A {
  549. //public:
  550. // A();
  551. // virtual ~A();
  552. // int foo();
  553. //
  554. //private:
  555. // int help();
  556. //};
  557. //
  558. //#endif /*A_H_*/
  559. //====================
  560. //#ifndef A_H_
  561. //#define A_H_
  562. //
  563. //class A {
  564. //public:
  565. // A();
  566. // virtual ~A();
  567. // int foo();
  568. //
  569. //private:
  570. // int help();
  571. // int extracted(int i);
  572. //};
  573. //
  574. //#endif /*A_H_*/
  575. //A.cpp
  576. //#include "A.h"
  577. //
  578. //#define TWO 2
  579. //
  580. //A::A() {
  581. //}
  582. //
  583. //A::~A() {
  584. //}
  585. //
  586. //int A::foo() {
  587. // int i = 2;
  588. // /*$*/++i;
  589. // i += TWO;
  590. // help();/*$$*/
  591. // return i;
  592. //}
  593. //
  594. //int A::help() {
  595. // return 42;
  596. //}
  597. //====================
  598. //#include "A.h"
  599. //
  600. //#define TWO 2
  601. //
  602. //A::A() {
  603. //}
  604. //
  605. //A::~A() {
  606. //}
  607. //
  608. //int A::extracted(int i) {
  609. // ++i;
  610. // i += TWO;
  611. // help();
  612. // return i;
  613. //}
  614. //
  615. //int A::foo() {
  616. // int i = 2;
  617. // i = extracted(i);
  618. // return i;
  619. //}
  620. //
  621. //int A::help() {
  622. // return 42;
  623. //}
  624. public void testObjectStyleMacro() throws Exception {
  625. assertRefactoringSuccess();
  626. }
  627. //A.h
  628. //#ifndef A_H_
  629. //#define A_H_
  630. //
  631. //class A {
  632. //public:
  633. // A();
  634. // virtual ~A();
  635. // int foo();
  636. //
  637. //private:
  638. // int help();
  639. //};
  640. //
  641. //#endif /*A_H_*/
  642. //====================
  643. //#ifndef A_H_
  644. //#define A_H_
  645. //
  646. //class A {
  647. //public:
  648. // A();
  649. // virtual ~A();
  650. // int foo();
  651. //
  652. //private:
  653. // int help();
  654. // void extracted(int* j);
  655. //};
  656. //
  657. //#endif /*A_H_*/
  658. //A.cpp
  659. //#include "A.h"
  660. //
  661. //A::A() {
  662. //}
  663. //
  664. //A::~A() {
  665. //}
  666. //
  667. //int A::foo() {
  668. // int* i = new int(2);
  669. // /*$*/++*i;
  670. // help();/*$$*/
  671. // return *i;
  672. //}
  673. //
  674. //int A::help() {
  675. // return 42;
  676. //}
  677. //====================
  678. //#include "A.h"
  679. //
  680. //A::A() {
  681. //}
  682. //
  683. //A::~A() {
  684. //}
  685. //
  686. //void A::extracted(int* j) {
  687. // ++*j;
  688. // help();
  689. //}
  690. //
  691. //int A::foo() {
  692. // int* i = new int(2);
  693. // extracted(i);
  694. // return *i;
  695. //}
  696. //
  697. //int A::help() {
  698. // return 42;
  699. //}
  700. public void testRenamedParameter() throws Exception {
  701. parameterRename.put("i", "j");
  702. assertRefactoringSuccess();
  703. }
  704. //A.c
  705. //struct A {
  706. // int i;
  707. // int j;
  708. //};
  709. //
  710. //int test() {
  711. // struct A a = { 1, 2 };
  712. // return /*$*/a.i + a.j/*$$*/;
  713. //}
  714. //====================
  715. //struct A {
  716. // int i;
  717. // int j;
  718. //};
  719. //
  720. //int extracted(const struct A* a) {
  721. // return a->i + a->j;
  722. //}
  723. //
  724. //int test() {
  725. // struct A a = { 1, 2 };
  726. // return extracted(&a);
  727. //}
  728. public void testInputParameterPassedByPointer() throws Exception {
  729. assertRefactoringSuccess();
  730. }
  731. //A.c
  732. //int test() {
  733. // int i = 0;
  734. // int j = 1;
  735. // /*$*/int k = i;
  736. // i = j;
  737. // j = k;/*$$*/
  738. // return i - j;
  739. //}
  740. //====================
  741. //void swap(int* i, int* j) {
  742. // int k = *i;
  743. // *i = *j;
  744. // *j = k;
  745. //}
  746. //
  747. //int test() {
  748. // int i = 0;
  749. // int j = 1;
  750. // swap(&i, &j);
  751. // return i - j;
  752. //}
  753. public void testOutputParameterPassedByPointer() throws Exception {
  754. extractedFunctionName = "swap";
  755. returnValue = NO_RETURN_VALUE;
  756. assertRefactoringSuccess();
  757. }
  758. //A.h
  759. //class A {
  760. //public:
  761. // int method();
  762. // int const_method() const;
  763. //};
  764. //A.cpp
  765. //#include "A.h"
  766. //
  767. //int test() {
  768. // A a, b;
  769. // return /*$*/a.method() + b.const_method()/*$$*/ + a.const_method();
  770. //}
  771. //====================
  772. //#include "A.h"
  773. //
  774. //int extracted(A b, A* a) {
  775. // return a->method() + b.const_method();
  776. //}
  777. //
  778. //int test() {
  779. // A a, b;
  780. // return extracted(b, &a) + a.const_method();
  781. //}
  782. public void testOutputParameterWithMethodCall() throws Exception {
  783. getPreferenceStore().setValue(PreferenceConstants.FUNCTION_PASS_OUTPUT_PARAMETERS_BY_POINTER, true);
  784. assertRefactoringSuccess();
  785. }
  786. //A.h
  787. //class A {
  788. //public:
  789. // A(int i, const char* s);
  790. // int method();
  791. //};
  792. //A.cpp
  793. //#include "A.h"
  794. //
  795. //void test(int i, const char* s) {
  796. // /*$*/A a(i, s);/*$$*/
  797. // if (i != 0)
  798. // a.method();
  799. //}
  800. //====================
  801. //#include "A.h"
  802. //
  803. //A extracted(int i, const char* s) {
  804. // A a(i, s);
  805. // return a;
  806. //}
  807. //
  808. //void test(int i, const char* s) {
  809. // A a = extracted(i, s);
  810. // if (i != 0)
  811. // a.method();
  812. //}
  813. public void testReturnValueWithCtorInitializer() throws Exception {
  814. assertRefactoringSuccess();
  815. }
  816. //A.h
  817. //#ifndef A_H_
  818. //#define A_H_
  819. //
  820. //class A {
  821. //public:
  822. // A();
  823. // virtual ~A();
  824. // int foo();
  825. //
  826. //private:
  827. // int help();
  828. //};
  829. //
  830. //#endif /*A_H_*/
  831. //====================
  832. //#ifndef A_H_
  833. //#define A_H_
  834. //
  835. //class A {
  836. //public:
  837. // A();
  838. // virtual ~A();
  839. // int foo();
  840. //
  841. //private:
  842. // int help();
  843. // void extracted(int& i);
  844. //};
  845. //
  846. //#endif /*A_H_*/
  847. //A.cpp
  848. //#include "A.h"
  849. //
  850. //A::A() {
  851. //}
  852. //
  853. //A::~A() {
  854. //}
  855. //
  856. //int A::foo() {
  857. // int i = 2;
  858. // /*$*/++i;
  859. // help();/*$$*/
  860. // return i;
  861. //}
  862. //
  863. //int A::help() {
  864. // return 42;
  865. //}
  866. //====================
  867. //#include "A.h"
  868. //
  869. //A::A() {
  870. //}
  871. //
  872. //A::~A() {
  873. //}
  874. //
  875. //void A::extracted(int& i) {
  876. // ++i;
  877. // help();
  878. //}
  879. //
  880. //int A::foo() {
  881. // int i = 2;
  882. // extracted(i);
  883. // return i;
  884. //}
  885. //
  886. //int A::help() {
  887. // return 42;
  888. //}
  889. public void testWithoutReturnValue() throws Exception {
  890. returnValue = NO_RETURN_VALUE;
  891. assertRefactoringSuccess();
  892. }
  893. //A.h
  894. //#ifndef A_H_
  895. //#define A_H_
  896. //
  897. //class A {
  898. //public:
  899. // A();
  900. // virtual ~A();
  901. // int foo();
  902. //
  903. //private:
  904. // int help();
  905. //};
  906. //
  907. //#endif /*A_H_*/
  908. //====================
  909. //#ifndef A_H_
  910. //#define A_H_
  911. //
  912. //class A {
  913. //public:
  914. // A();
  915. // virtual ~A();
  916. // int foo();
  917. //
  918. //private:
  919. // int help();
  920. // int extracted(int i, int b);
  921. //};
  922. //
  923. //#endif /*A_H_*/
  924. //A.cpp
  925. //#include "A.h"
  926. //
  927. //A::A() {
  928. //}
  929. //
  930. //A::~A() {
  931. //}
  932. //
  933. //int A::foo() {
  934. // int i = 2;
  935. // int b = i;
  936. // /*$*/++i;
  937. // i = i + b;
  938. // help();/*$$*/
  939. // ++b;
  940. // return i;
  941. //}
  942. //
  943. //int A::help() {
  944. // return 42;
  945. //}
  946. //====================
  947. //#include "A.h"
  948. //
  949. //A::A() {
  950. //}
  951. //
  952. //A::~A() {
  953. //}
  954. //
  955. //int A::extracted(int i, int b) {
  956. // ++i;
  957. // i = i + b;
  958. // help();
  959. // return i;
  960. //}
  961. //
  962. //int A::foo() {
  963. // int i = 2;
  964. // int b = i;
  965. // i = extracted(i, b);
  966. // ++b;
  967. // return i;
  968. //}
  969. //
  970. //int A::help() {
  971. // return 42;
  972. //}
  973. public void testReturnValueSelection_1() throws Exception {
  974. assertRefactoringSuccess();
  975. }
  976. //A.h
  977. //#ifndef A_H_
  978. //#define A_H_
  979. //
  980. //class A {
  981. //public:
  982. // A();
  983. // virtual ~A();
  984. // int foo();
  985. //
  986. //private:
  987. // int help();
  988. //};
  989. //
  990. //#endif /*A_H_*/
  991. //====================
  992. //#ifndef A_H_
  993. //#define A_H_
  994. //
  995. //class A {
  996. //public:
  997. // A();
  998. // virtual ~A();
  999. // int foo();
  1000. //
  1001. //private:
  1002. // int help();
  1003. // int extracted(int i, int y, float x, B* b);
  1004. //};
  1005. //
  1006. //#endif /*A_H_*/
  1007. //A.cpp
  1008. //#include "A.h"
  1009. //
  1010. //A::A() {
  1011. //}
  1012. //
  1013. //A::~A() {
  1014. //}
  1015. //
  1016. //int A::foo() {
  1017. // int i = 2;
  1018. // float x = i;
  1019. // B* b = new B();
  1020. // int y = x + i;
  1021. // /*$*/++i;
  1022. // b->hello(y);
  1023. // i = i + x;
  1024. // help();/*$$*/
  1025. // ++x;
  1026. // return i;
  1027. //}
  1028. //
  1029. //int A::help() {
  1030. // return 42;
  1031. //}
  1032. //====================
  1033. //#include "A.h"
  1034. //
  1035. //A::A() {
  1036. //}
  1037. //
  1038. //A::~A() {
  1039. //}
  1040. //
  1041. //int A::extracted(int i, int y, float x, B* b) {
  1042. // ++i;
  1043. // b->hello(y);
  1044. // i = i + x;
  1045. // help();
  1046. // return i;
  1047. //}
  1048. //
  1049. //int A::foo() {
  1050. // int i = 2;
  1051. // float x = i;
  1052. // B* b = new B();
  1053. // int y = x + i;
  1054. // i = extracted(i, y, x, b);
  1055. // ++x;
  1056. // return i;
  1057. //}
  1058. //
  1059. //int A::help() {
  1060. // return 42;
  1061. //}
  1062. public void testReturnValueSelection_2() throws Exception {
  1063. assertRefactoringSuccess();
  1064. }
  1065. //A.h
  1066. //#ifndef A_H_
  1067. //#define A_H_
  1068. //
  1069. //#include "B.h"
  1070. //
  1071. //class A {
  1072. //public:
  1073. // A();
  1074. // virtual ~A();
  1075. // int foo();
  1076. //
  1077. //private:
  1078. // int help();
  1079. //};
  1080. //
  1081. //#endif /*A_H_*/
  1082. //====================
  1083. //#ifndef A_H_
  1084. //#define A_H_
  1085. //
  1086. //#include "B.h"
  1087. //
  1088. //class A {
  1089. //public:
  1090. // A();
  1091. // virtual ~A();
  1092. // int foo();
  1093. //
  1094. //private:
  1095. // int help();
  1096. // bool extracted(bool y, float x, int& i, B* b);
  1097. //};
  1098. //
  1099. //#endif /*A_H_*/
  1100. //A.cpp
  1101. //#include "A.h"
  1102. //
  1103. //A::A() {
  1104. //}
  1105. //
  1106. //A::~A() {
  1107. //}
  1108. //
  1109. //int A::foo() {
  1110. // int i = 2;
  1111. // float x = i;
  1112. // B* b = new B();
  1113. // bool y = false;
  1114. // /*$*/++i;
  1115. // b->hello(y);
  1116. // y = !y;
  1117. // i = i + x;
  1118. // help();/*$$*/
  1119. // b->hello(y);
  1120. // ++x;
  1121. // return i;
  1122. //}
  1123. //
  1124. //int A::help() {
  1125. // return 42;
  1126. //}
  1127. //====================
  1128. //#include "A.h"
  1129. //
  1130. //A::A() {
  1131. //}
  1132. //
  1133. //A::~A() {
  1134. //}
  1135. //
  1136. //bool A::extracted(bool y, float x, int& i, B* b) {
  1137. // ++i;
  1138. // b->hello(y);
  1139. // y = !y;
  1140. // i = i + x;
  1141. // help();
  1142. // return y;
  1143. //}
  1144. //
  1145. //int A::foo() {
  1146. // int i = 2;
  1147. // float x = i;
  1148. // B* b = new B();
  1149. // bool y = false;
  1150. // y = extracted(y, x, i, b);
  1151. // b->hello(y);
  1152. // ++x;
  1153. // return i;
  1154. //}
  1155. //
  1156. //int A::help() {
  1157. // return 42;
  1158. //}
  1159. //B.h
  1160. //#ifndef B_H_
  1161. //#define B_H_
  1162. //
  1163. //class B {
  1164. //public:
  1165. // B();
  1166. // virtual ~B();
  1167. // void hello(bool y);
  1168. //};
  1169. //
  1170. //#endif /*B_H_*/
  1171. public void testReturnValueSelection_3() throws Exception {
  1172. assertRefactoringSuccess();
  1173. }
  1174. //A.h
  1175. //#ifndef A_H_
  1176. //#define A_H_
  1177. //
  1178. //#include "B.h"
  1179. //
  1180. //class A {
  1181. //public:
  1182. // A();
  1183. // virtual ~A();
  1184. // int foo();
  1185. //
  1186. //private:
  1187. // int help();
  1188. //};
  1189. //
  1190. //#endif /*A_H_*/
  1191. //====================
  1192. //#ifndef A_H_
  1193. //#define A_H_
  1194. //
  1195. //#include "B.h"
  1196. //
  1197. //class A {
  1198. //public:
  1199. // A();
  1200. // virtual ~A();
  1201. // int foo();
  1202. //
  1203. //private:
  1204. // int help();
  1205. // float extracted(int& i, int y, float x, B* b);
  1206. //};
  1207. //
  1208. //#endif /*A_H_*/
  1209. //A.cpp
  1210. //#include "A.h"
  1211. //
  1212. //A::A() {
  1213. //}
  1214. //
  1215. //A::~A() {
  1216. //}
  1217. //
  1218. //int A::foo() {
  1219. // int i = 2;
  1220. // float x = i;
  1221. // B* b = new B();
  1222. // int y = x + i;
  1223. // /*$*/++i;
  1224. // b->hello(y);
  1225. // i = i + x;
  1226. // help();/*$$*/
  1227. // ++x;
  1228. // return i;
  1229. //}
  1230. //
  1231. //int A::help() {
  1232. // return 42;
  1233. //}
  1234. //====================
  1235. //#include "A.h"
  1236. //
  1237. //A::A() {
  1238. //}
  1239. //
  1240. //A::~A() {
  1241. //}
  1242. //
  1243. //float A::extracted(int& i, int y, float x, B* b) {
  1244. // ++i;
  1245. // b->hello(y);
  1246. // i = i + x;
  1247. // help();
  1248. // return x;
  1249. //}
  1250. //
  1251. //int A::foo() {
  1252. // int i = 2;
  1253. // float x = i;
  1254. // B* b = new B();
  1255. // int y = x + i;
  1256. // x = extracted(i, y, x, b);
  1257. // ++x;
  1258. // return i;
  1259. //}
  1260. //
  1261. //int A::help() {
  1262. // return 42;
  1263. //}
  1264. //B.h
  1265. //#ifndef B_H_
  1266. //#define B_H_
  1267. //
  1268. //class B {
  1269. //public:
  1270. // B();
  1271. // virtual ~B();
  1272. // void hello(float y);
  1273. //};
  1274. //
  1275. //#endif /*B_H_*/
  1276. public void testExplicitlyAssignedReturnValue() throws Exception {
  1277. returnValue = "x";
  1278. assertRefactoringSuccess();
  1279. }
  1280. //A.h
  1281. //#ifndef A_H_
  1282. //#define A_H_
  1283. //
  1284. //#include "B.h"
  1285. //
  1286. //class A {
  1287. //public:
  1288. // A();
  1289. // virtual ~A();
  1290. // int foo();
  1291. //
  1292. //private:
  1293. // int help();
  1294. //};
  1295. //
  1296. //#endif /*A_H_*/
  1297. //====================
  1298. //#ifndef A_H_
  1299. //#define A_H_
  1300. //
  1301. //#include "B.h"
  1302. //
  1303. //class A {
  1304. //public:
  1305. // A();
  1306. // virtual ~A();
  1307. // int foo();
  1308. //
  1309. //private:
  1310. // int help();
  1311. // B* extracted(int& i, int y, float x, B* b);
  1312. //};
  1313. //
  1314. //#endif /*A_H_*/
  1315. //A.cpp
  1316. //#include "A.h"
  1317. //
  1318. //A::A() {
  1319. //}
  1320. //
  1321. //A::~A() {
  1322. //}
  1323. //
  1324. //int A::foo() {
  1325. // int i = 2;
  1326. // float x = i;
  1327. // B* b = new B();
  1328. // int y = x + i;
  1329. // /*$*/++i;
  1330. // b->hello(y);
  1331. // i = i + x;
  1332. // help();/*$$*/
  1333. // b->hello(y);
  1334. // ++x;
  1335. // return i;
  1336. //}
  1337. //
  1338. //int A::help() {
  1339. // return 42;
  1340. //}
  1341. //====================
  1342. //#include "A.h"
  1343. //
  1344. //A::A() {
  1345. //}
  1346. //
  1347. //A::~A() {
  1348. //}
  1349. //
  1350. //B* A::extracted(int& i, int y, float x, B* b) {
  1351. // ++i;
  1352. // b->hello(y);
  1353. // i = i + x;
  1354. // help();
  1355. // return b;
  1356. //}
  1357. //
  1358. //int A::foo() {
  1359. // int i = 2;
  1360. // float x = i;
  1361. // B* b = new B();
  1362. // int y = x + i;
  1363. // b = extracted(i, y, x, b);
  1364. // b->hello(y);
  1365. // ++x;
  1366. // return i;
  1367. //}
  1368. //
  1369. //int A::help() {
  1370. // return 42;
  1371. //}
  1372. //B.h
  1373. //#ifndef B_H_
  1374. //#define B_H_
  1375. //
  1376. //class B {
  1377. //public:
  1378. // B();
  1379. // virtual ~B();
  1380. // void hello(float y);
  1381. //};
  1382. //
  1383. //#endif /*B_H_*/
  1384. public void testExplicitlyAssignedReturnValueAndOutputParameter() throws Exception {
  1385. returnValue = "b";
  1386. assertRefactoringSuccess();
  1387. }
  1388. //A.h
  1389. //#ifndef A_H_
  1390. //#define A_H_
  1391. //
  1392. //class A {
  1393. //public:
  1394. // A();
  1395. // virtual ~A();
  1396. // int foo();
  1397. //
  1398. //private:
  1399. // int help();
  1400. //};
  1401. //
  1402. //#endif /*A_H_*/
  1403. //====================
  1404. //#ifndef A_H_
  1405. //#define A_H_
  1406. //
  1407. //class A {
  1408. //public:
  1409. // A();
  1410. // virtual ~A();
  1411. // int foo();
  1412. //
  1413. //protected:
  1414. // int extracted(int i);
  1415. //
  1416. //private:
  1417. // int help();
  1418. //};
  1419. //
  1420. //#endif /*A_H_*/
  1421. //A.cpp
  1422. //#include "A.h"
  1423. //
  1424. //A::A() {
  1425. //}
  1426. //
  1427. //A::~A() {
  1428. //}
  1429. //
  1430. //int A::foo() {
  1431. // int i = 2;
  1432. // /*$*/++i;
  1433. // help();/*$$*/
  1434. // return i;
  1435. //}
  1436. //
  1437. //int A::help() {
  1438. // return 42;
  1439. //}
  1440. //====================
  1441. //#include "A.h"
  1442. //
  1443. //A::A() {
  1444. //}
  1445. //
  1446. //A::~A() {
  1447. //}
  1448. //
  1449. //int A::extracted(int i) {
  1450. // ++i;
  1451. // help();
  1452. // return i;
  1453. //}
  1454. //
  1455. //int A::foo() {
  1456. // int i = 2;
  1457. // i = extracted(i);
  1458. // return i;
  1459. //}
  1460. //
  1461. //int A::help() {
  1462. // return 42;
  1463. //}
  1464. public void testProtectedVisibility() throws Exception {
  1465. visibility = VisibilityEnum.v_protected;
  1466. assertRefactoringSuccess();
  1467. }
  1468. //A.h
  1469. //#ifndef A_H_
  1470. //#define A_H_
  1471. //
  1472. //class A {
  1473. //public:
  1474. // A();
  1475. // virtual ~A();
  1476. // int foo();
  1477. //
  1478. //private:
  1479. // int help();
  1480. //};
  1481. //
  1482. //#endif /*A_H_*/
  1483. //====================
  1484. //#ifndef A_H_
  1485. //#define A_H_
  1486. //
  1487. //class A {
  1488. //public:
  1489. // A();
  1490. // virtual ~A();
  1491. // int foo();
  1492. // int extracted(int i);
  1493. //
  1494. //private:
  1495. // int help();
  1496. //};
  1497. //
  1498. //#endif /*A_H_*/
  1499. //A.cpp
  1500. //#include "A.h"
  1501. //
  1502. //A::A() {
  1503. //}
  1504. //
  1505. //A::~A() {
  1506. //}
  1507. //
  1508. //int A::foo() {
  1509. // int i = 2;
  1510. // /*$*/++i;
  1511. // help();/*$$*/
  1512. // return i;
  1513. //}
  1514. //
  1515. //int A::help() {
  1516. // return 42;
  1517. //}
  1518. //====================
  1519. //#include "A.h"
  1520. //
  1521. //A::A() {
  1522. //}
  1523. //
  1524. //A::~A() {
  1525. //}
  1526. //
  1527. //int A::extracted(int i) {
  1528. // ++i;
  1529. // help();
  1530. // return i;
  1531. //}
  1532. //
  1533. //int A::foo() {
  1534. // int i = 2;
  1535. // i = extracted(i);
  1536. // return i;
  1537. //}
  1538. //
  1539. //int A::help() {
  1540. // return 42;
  1541. //}
  1542. public void testPublicVisibility() throws Exception {
  1543. visibility = VisibilityEnum.v_public;
  1544. assertRefactoringSuccess();
  1545. }
  1546. //A.h
  1547. //#ifndef A_H_
  1548. //#define A_H_
  1549. //
  1550. //class A {
  1551. //public:
  1552. // A();
  1553. // virtual ~A();
  1554. // int foo() const;
  1555. //
  1556. //private:
  1557. // int help();
  1558. //};
  1559. //
  1560. //#endif /*A_H_*/
  1561. //====================
  1562. //#ifndef A_H_
  1563. //#define A_H_
  1564. //
  1565. //class A {
  1566. //public:
  1567. // A();
  1568. // virtual ~A();
  1569. // int foo() const;
  1570. //
  1571. //private:
  1572. // int help();
  1573. // int extracted(int i) const;
  1574. //};
  1575. //
  1576. //#endif /*A_H_*/
  1577. //A.cpp
  1578. //#include "A.h"
  1579. //
  1580. //A::A() {
  1581. //}
  1582. //
  1583. //A::~A() {
  1584. //}
  1585. //
  1586. //int A::foo() const {
  1587. // int i = 2;
  1588. // /*$*/++i;
  1589. // help();/*$$*/
  1590. // return i;
  1591. //}
  1592. //
  1593. //int A::help() {
  1594. // return 42;
  1595. //}
  1596. //====================
  1597. //#include "A.h"
  1598. //
  1599. //A::A() {
  1600. //}
  1601. //
  1602. //A::~A() {
  1603. //}
  1604. //
  1605. //int A::extracted(int i) const {
  1606. // ++i;
  1607. // help();
  1608. // return i;
  1609. //}
  1610. //
  1611. //int A::foo() const {
  1612. // int i = 2;
  1613. // i = extracted(i);
  1614. // return i;
  1615. //}
  1616. //
  1617. //int A::help() {
  1618. // return 42;
  1619. //}
  1620. public void testConstMethod() throws Exception {
  1621. assertRefactoringSuccess();
  1622. }
  1623. //test.cpp
  1624. //int test(bool param) {
  1625. // int a = 42;
  1626. // char b = '0';
  1627. //
  1628. // if (param) {
  1629. // /*$*/b += a;
  1630. // a += b;/*$$*/
  1631. // } else {
  1632. // b -= a;
  1633. // a -= b;
  1634. // }
  1635. // return a;
  1636. //}
  1637. //====================
  1638. //int extracted(char b, int a) {
  1639. // b += a;
  1640. // a += b;
  1641. // return a;
  1642. //}
  1643. //
  1644. //int test(bool param) {
  1645. // int a = 42;
  1646. // char b = '0';
  1647. //
  1648. // if (param) {
  1649. // a = extracted(b, a);
  1650. // } else {
  1651. // b -= a;
  1652. // a -= b;
  1653. // }
  1654. // return a;
  1655. //}
  1656. public void testOutputParametersDetectionInIfStatement() throws Exception {
  1657. assertRefactoringSuccess();
  1658. }
  1659. //main.c
  1660. //int main() {
  1661. // int a = 42;
  1662. // char b = '0';
  1663. //
  1664. // switch (a) {
  1665. // case 0:
  1666. // /*$*/b += a;
  1667. // a += b;/*$$*/
  1668. // break;
  1669. // case 42:
  1670. // b -= a;
  1671. // a -= b;
  1672. // break;
  1673. // default:
  1674. // b ++;
  1675. // a += b;
  1676. // break;
  1677. // }
  1678. // return b;
  1679. //}
  1680. //====================
  1681. //char extracted(char b, int a) {
  1682. // b += a;
  1683. // a += b;
  1684. // return b;
  1685. //}
  1686. //
  1687. //int main() {
  1688. // int a = 42;
  1689. // char b = '0';
  1690. //
  1691. // switch (a) {
  1692. // case 0:
  1693. // b = extracted(b, a);
  1694. // break;
  1695. // case 42:
  1696. // b -= a;
  1697. // a -= b;
  1698. // break;
  1699. // default:
  1700. // b ++;
  1701. // a += b;
  1702. // break;
  1703. // }
  1704. // return b;
  1705. //}
  1706. public void testOutputParametersDetectionInSwitchStatement_Bug302406() throws Exception {
  1707. assertRefactoringSuccess();
  1708. }
  1709. //test.c
  1710. //void print(int i, double a, double b);
  1711. //
  1712. //void test(double x) {
  1713. // double s = 0;
  1714. // double y = 1;
  1715. // int i;
  1716. // for (i = 0; i < 10; i++) {
  1717. // print(x, s);
  1718. // /*$*/x *= x;
  1719. // y *= i;
  1720. // s += x / y;/*$$*/
  1721. // }
  1722. //}
  1723. //====================
  1724. //void print(int i, double a, double b);
  1725. //
  1726. //extracted(double x, int i, double* y, double* s) {
  1727. // x *= x;
  1728. // *y *= i;
  1729. // *s += x / *y;
  1730. // return x;
  1731. //}
  1732. //
  1733. //void test(double x) {
  1734. // double s = 0;
  1735. // double y = 1;
  1736. // int i;
  1737. // for (i = 0; i < 10; i++) {
  1738. // print(x, s);
  1739. // x = extracted(x, i, &y, &s);
  1740. // }
  1741. //}
  1742. public void testOutputParametersDetectionInForLoop() throws Exception {
  1743. assertRefactoringSuccess();
  1744. }
  1745. //test.c
  1746. //void test() {
  1747. // int i = 0;
  1748. // while (i <= 10)
  1749. // /*$*/i++;/*$$*/
  1750. //}
  1751. //====================
  1752. //int extracted(int i) {
  1753. // i++;
  1754. // return i;
  1755. //}
  1756. //
  1757. //void test() {
  1758. // int i = 0;
  1759. // while (i <= 10)
  1760. // i = extracted(i);
  1761. //}
  1762. public void testOutputParametersDetectionInWhileLoop() throws Exception {
  1763. assertRefactoringSuccess();
  1764. }
  1765. //test.c
  1766. //void test() {
  1767. // int i = 0;
  1768. //loop:
  1769. // if (i > 10) return;
  1770. // /*$*/i++;/*$$*/
  1771. // goto loop;
  1772. //}
  1773. //====================
  1774. //int extracted(int i) {
  1775. // i++;
  1776. // return i;
  1777. //}
  1778. //
  1779. //void test() {
  1780. // int i = 0;
  1781. //loop:
  1782. // if (i > 10) return;
  1783. // i = extracted(i);
  1784. // goto loop;
  1785. //}
  1786. public void testOutputParametersDetectionWithGotoLoopSimple() throws Exception {
  1787. assertRefactoringSuccess();
  1788. }
  1789. //test.c
  1790. //void test() {
  1791. // int a = 0, b = 0, c = 0, d = 0;
  1792. //loop1:
  1793. // if (a > 1) return;
  1794. // goto loop1;
  1795. //loop2:
  1796. // if (b > 2) return;
  1797. //loop3:
  1798. // if (c > 3) return;
  1799. // goto loop2;
  1800. //loop4:
  1801. // if (d > 4) return;
  1802. // goto loop3;
  1803. // /*$*/a++;
  1804. // b++;
  1805. // c++;
  1806. // d++;/*$$*/
  1807. // goto loop4;
  1808. //}
  1809. //====================
  1810. //int extracted(int a, int b, int* c, int* d) {
  1811. // a++;
  1812. // b++;
  1813. // *c++;
  1814. // *d++;
  1815. // return b;
  1816. //}
  1817. //
  1818. //void test() {
  1819. // int a = 0, b = 0, c = 0, d = 0;
  1820. //loop1:
  1821. // if (a > 1) return;
  1822. // goto loop1;
  1823. //loop2:
  1824. // if (b > 2) return;
  1825. //loop3:
  1826. // if (c > 3) return;
  1827. // goto loop2;
  1828. //loop4:
  1829. // if (d > 4) return;
  1830. // goto loop3;
  1831. // b = extracted(a, b, &c, &d);
  1832. // goto loop4;
  1833. //}
  1834. public void testOutputParametersDetectionWithGotoLoopComplex() throws Exception {
  1835. assertRefactoringSuccess();
  1836. }
  1837. //main.cpp
  1838. //void method() {
  1839. // /*$*/for (int var = 0; var < 100; ++var) {
  1840. // if (var < 50)
  1841. // continue;
  1842. // }/*$$*/
  1843. //}
  1844. //====================
  1845. //void loop() {
  1846. // for (int var = 0; var < 100; ++var) {
  1847. // if (var < 50)
  1848. // continue;
  1849. // }
  1850. //}
  1851. //
  1852. //void method() {
  1853. // loop();
  1854. //}
  1855. public void testDoNotReturnVariablesThatAreNotUsed() throws Exception {
  1856. extractedFunctionName = "loop";
  1857. assertRefactoringSuccess();
  1858. }
  1859. //main.h
  1860. //void method() {
  1861. // /*$*/if (true)
  1862. // return;/*$$*/
  1863. // //unreachable
  1864. //}
  1865. public void testDoNotExtractCodeContainingReturn() throws Exception {
  1866. assertRefactoringFailure();
  1867. }
  1868. //A.h
  1869. //void function() {
  1870. // for (int var = 0; var < 100; ++var) {
  1871. // /*$*/if (var < 50)
  1872. // continue;/*$$*/
  1873. // }
  1874. //}
  1875. public void testDoNotExtractCodeContainingContinue() throws Exception {
  1876. assertRefactoringFailure();
  1877. }
  1878. //Test.cpp
  1879. //#define ASSERTM(msg,cond) if (!(cond)) throw cute::test_failure((msg),__FILE__,__LINE__)
  1880. //#define ASSERT(cond) ASSERTM(#cond, cond)
  1881. //
  1882. //void testFuerRainer() {
  1883. // int i = int();
  1884. // /*$*/++i;
  1885. // ASSERT(i);
  1886. // --i;/*$$*/
  1887. //}
  1888. //====================
  1889. //#define ASSERTM(msg,cond) if (!(cond)) throw cute::test_failure((msg),__FILE__,__LINE__)
  1890. //#define ASSERT(cond) ASSERTM(#cond, cond)
  1891. //
  1892. //void runTest(int i) {
  1893. // ++i;
  1894. // ASSERT(i);
  1895. // --i;
  1896. //}
  1897. //
  1898. //void testFuerRainer() {
  1899. // int i = int();
  1900. // runTest(i);
  1901. //}
  1902. public void testCommentsWithMacroCallInSelectedCodeForgetsTheMacro() throws Exception {
  1903. extractedFunctionName = "runTest";
  1904. assertRefactoringSuccess();
  1905. }
  1906. //Test.cpp
  1907. //#include <string>
  1908. //
  1909. //using namespace std;
  1910. //
  1911. //int const INITIAL_CAPACITY = 10;
  1912. //
  1913. //int main() {
  1914. // int m_capacity;
  1915. // /*$*/m_capacity += INITIAL_CAPACITY;
  1916. // string* newElements = new string[m_capacity];/*$$*/
  1917. // newElements[0] = "s";
  1918. //}
  1919. //====================
  1920. //#include <string>
  1921. //
  1922. //using namespace std;
  1923. //
  1924. //int const INITIAL_CAPACITY = 10;
  1925. //
  1926. //string* runTest(int m_capacity) {
  1927. // m_capacity += INITIAL_CAPACITY;
  1928. // string* newElements = new string[m_capacity];
  1929. // return newElements;
  1930. //}
  1931. //
  1932. //int main() {
  1933. // int m_capacity;
  1934. // string* newElements = runTest(m_capacity);
  1935. // newElements[0] = "s";
  1936. //}
  1937. public void testStringArray() throws Exception {
  1938. extractedFunctionName = "runTest";
  1939. assertRefactoringSuccess();
  1940. }
  1941. //A.h
  1942. //#ifndef A_H_
  1943. //#define A_H_
  1944. //
  1945. //class A {
  1946. //public:
  1947. // A();
  1948. // virtual ~A();
  1949. // int foo(int& a);
  1950. //};
  1951. //
  1952. //#endif /*A_H_*/
  1953. //====================
  1954. //#ifndef A_H_
  1955. //#define A_H_
  1956. //
  1957. //class A {
  1958. //public:
  1959. // A();
  1960. // virtual ~A();
  1961. // int foo(int& a);
  1962. //
  1963. //private:
  1964. // void extracted(int b, int c, int& a);
  1965. //};
  1966. //
  1967. //#endif /*A_H_*/
  1968. //A.cpp
  1969. //#include "A.h"
  1970. //
  1971. //A::A() {
  1972. //}
  1973. //
  1974. //A::~A() {
  1975. //}
  1976. //
  1977. //int A::foo(int& a) {
  1978. // int b = 7;
  1979. // int c = 8;
  1980. // /*$*/a = b + c;/*$$*/
  1981. // return a;
  1982. //}
  1983. //====================
  1984. //#include "A.h"
  1985. //
  1986. //A::A() {
  1987. //}
  1988. //
  1989. //A::~A() {
  1990. //}
  1991. //
  1992. //void A::extracted(int b, int c, int& a) {
  1993. // a = b + c;
  1994. //}
  1995. //
  1996. //int A::foo(int& a) {
  1997. // int b = 7;
  1998. // int c = 8;
  1999. // extracted(b, c, a);
  2000. // return a;
  2001. //}
  2002. public void testReferenceVariable_Bug239059() throws Exception {
  2003. assertRefactoringSuccess();
  2004. }
  2005. //Test.h
  2006. //#ifndef TEST_H_
  2007. //#define TEST_H_
  2008. //
  2009. //class RetValueType {
  2010. //};
  2011. //
  2012. //typedef RetValueType RetType;
  2013. //
  2014. //class Test {
  2015. //public:
  2016. // Test();
  2017. // virtual ~Test();
  2018. //private:
  2019. // void test();
  2020. //};
  2021. //
  2022. //#endif /* TEST_H_ */
  2023. //====================
  2024. //#ifndef TEST_H_
  2025. //#define TEST_H_
  2026. //
  2027. //class RetValueType {
  2028. //};
  2029. //
  2030. //typedef RetValueType RetType;
  2031. //
  2032. //class Test {
  2033. //public:
  2034. // Test();
  2035. // virtual ~Test();
  2036. //private:
  2037. // void test();
  2038. // RetType extracted();
  2039. //};
  2040. //
  2041. //#endif /* TEST_H_ */
  2042. //Test.cpp
  2043. //#include "Test.h"
  2044. //
  2045. //Test::Test() {
  2046. //}
  2047. //
  2048. //Test::~Test() {
  2049. //}
  2050. //
  2051. //void Test::test() {
  2052. // RetType v = /*$*/RetType()/*$$*/;
  2053. //}
  2054. //====================
  2055. //#include "Test.h"
  2056. //
  2057. //Test::Test() {
  2058. //}
  2059. //
  2060. //Test::~Test() {
  2061. //}
  2062. //
  2063. //RetType Test::extracted() {
  2064. // return RetType();
  2065. //}
  2066. //
  2067. //void Test::test() {
  2068. // RetType v = extracted();
  2069. //}
  2070. public void testTypedef_Bug241717() throws Exception {
  2071. assertRefactoringSuccess();
  2072. }
  2073. //testString.h
  2074. //namespace test {
  2075. //
  2076. //class string {
  2077. //public:
  2078. // friend string operator+(const string& lhs, const string& rhs) {
  2079. // return rhs;
  2080. // }
  2081. //
  2082. // string operator+(const string& rhs) { return rhs; }
  2083. // string(char* cp) {}
  2084. // string() {};
  2085. //};
  2086. //
  2087. //}
  2088. //Test.cpp
  2089. //#include "testString.h"
  2090. //
  2091. //test::string toXML() {
  2092. // test::string name;
  2093. // name = "hello";
  2094. // return /*$*/"<" + name + ">"/*$$*/ + "</" + name + ">";
  2095. //}
  2096. //
  2097. //int main() {
  2098. // return 0;
  2099. //}
  2100. //====================
  2101. //#include "testString.h"
  2102. //
  2103. //test::string startTag(test::string name) {
  2104. // return "<" + name + ">";
  2105. //}
  2106. //
  2107. //test::string toXML() {
  2108. // test::string name;
  2109. // name = "hello";
  2110. // return startTag(name) + "</" + name + ">";
  2111. //}
  2112. //
  2113. //int main() {
  2114. // return 0;
  2115. //}
  2116. public void testQualifiedReturnTypeName_Bug248238_1() throws Exception {
  2117. extractedFunctionName = "startTag";
  2118. assertRefactoringSuccess();
  2119. }
  2120. //testString.h
  2121. //
  2122. //namespace test {
  2123. //
  2124. //class string2 {
  2125. //public:
  2126. // friend string2 operator+(const string2& lhs, const string2& rhs) {
  2127. // return rhs;
  2128. // }
  2129. //
  2130. // string2 operator+(const string2& rhs) { return rhs; }
  2131. // string2(char* cp) {}
  2132. // string2() {};
  2133. //};
  2134. //
  2135. //typedef string2 string;
  2136. //
  2137. //}
  2138. //Test.cpp
  2139. //#include "testString.h"
  2140. //
  2141. //test::string toXML() {
  2142. // test::string name;
  2143. // name = "hello";
  2144. // return /*$*/"<" + name + ">"/*$$*/ + "</" + name + ">";
  2145. //}
  2146. //
  2147. //int main() {
  2148. // return 0;
  2149. //}
  2150. //====================
  2151. //#include "testString.h"
  2152. //
  2153. //test::string startTag(test::string name) {
  2154. // return "<" + name + ">";
  2155. //}
  2156. //
  2157. //test::string toXML() {
  2158. // test::string name;
  2159. // name = "hello";
  2160. // return startTag(name) + "</" + name + ">";
  2161. //}
  2162. //
  2163. //int main() {
  2164. // return 0;
  2165. //}
  2166. public void testQualifiedReturnTypeName_Bug248238_2() throws Exception {
  2167. extractedFunctionName = "startTag";
  2168. assertRefactoringSuccess();
  2169. }
  2170. //testString.h
  2171. //
  2172. //namespace test {
  2173. //
  2174. //class string {
  2175. //public:
  2176. // friend string operator+(const string& lhs, const string& rhs) {
  2177. // return rhs;
  2178. // }
  2179. //
  2180. // string operator+(const string& rhs) { return rhs; }
  2181. // string(char* cp) {}
  2182. // string() {};
  2183. //};
  2184. //
  2185. //}
  2186. //Test.cpp
  2187. //#include "testString.h"
  2188. //
  2189. //test::string toXML() {
  2190. // test::string name;
  2191. // name = "hello";
  2192. // return "<" + name + ">" + /*$*/"</" + name + ">"/*$$*/;
  2193. //}
  2194. //
  2195. //int main() {
  2196. // return 0;
  2197. //}
  2198. //====================
  2199. //#include "testString.h"
  2200. //
  2201. //const char endTag(test::string name) {
  2202. // return "</" + name + ">";
  2203. //}
  2204. //
  2205. //test::string toXML() {
  2206. // test::string name;
  2207. // name = "hello";
  2208. // return "<" + name + ">" + endTag(name);
  2209. //}
  2210. //
  2211. //int main() {
  2212. // return 0;
  2213. //}
  2214. public void testReturnStatementExpression_Bug248622_1() throws Exception {
  2215. extractedFunctionName = "endTag";
  2216. assertRefactoringSuccess();
  2217. }
  2218. //testString.h
  2219. //
  2220. //namespace test {
  2221. //
  2222. //class string {
  2223. //public:
  2224. // friend string operator+(const string& lhs, const string& rhs) {
  2225. // return rhs;
  2226. // }
  2227. //
  2228. // string operator+(const string& rhs) { return rhs; }
  2229. // string(char* cp) {}
  2230. // string() {};
  2231. //};
  2232. //
  2233. //}
  2234. //Test.cpp
  2235. //#include "testString.h"
  2236. //
  2237. //test::string toXML() {
  2238. // test::string name;
  2239. // name = "hello";
  2240. // return "<" + name + /*$*/">" + "</"/*$$*/ + name + ">";
  2241. //}
  2242. //
  2243. //int main() {
  2244. // return 0;
  2245. //}
  2246. //====================
  2247. //#include "testString.h"
  2248. //
  2249. //const char extracted() {
  2250. // return ">" + "</";
  2251. //}
  2252. //
  2253. //test::string toXML() {
  2254. // test::string name;
  2255. // name = "hello";
  2256. // return "<" + name + extracted() + name + ">";
  2257. //}
  2258. //
  2259. //int main() {
  2260. // return 0;
  2261. //}
  2262. public void testReturnStatementExpression_Bug248622_2() throws Exception {
  2263. assertRefactoringSuccess();
  2264. }
  2265. //main.cpp
  2266. //int main(int argc, char** argv) {
  2267. // /*$*/int a = 0;
  2268. // {
  2269. // a++;
  2270. // }/*$$*/
  2271. //}
  2272. //====================
  2273. //void extracted() {
  2274. // int a = 0;
  2275. // {
  2276. // a++;
  2277. // }
  2278. //}
  2279. //
  2280. //int main(int argc, char** argv) {
  2281. // extracted();
  2282. //}
  2283. public void testBlock_Bug262000() throws Exception {
  2284. assertRefactoringSuccess();
  2285. }
  2286. //classhelper.h
  2287. //// Comment
  2288. ////
  2289. //// Comment
  2290. //// Comment
  2291. //#ifndef utils_classhelper_h_seen
  2292. //#define utils_classhelper_h_seen
  2293. //#define IMPORTANT_VALUE 1
  2294. //#endif
  2295. //test.h
  2296. ///*
  2297. // * Copyright 2009
  2298. // */
  2299. //#ifndef test_h_seen
  2300. //#define test_h_seen
  2301. //
  2302. //#include "classhelper.h"
  2303. //
  2304. //class Test {
  2305. // public:
  2306. // /**
  2307. // * Small class with some comments
  2308. // */
  2309. // Test();
  2310. //
  2311. // /** Calculate important things.
  2312. // * @returns the result of the calculation
  2313. // */
  2314. // int calculateStuff();
  2315. //
  2316. // private:
  2317. // /**
  2318. // * Retain a value for something.
  2319. // */
  2320. // int m_value;
  2321. //};
  2322. //
  2323. //#endif
  2324. //====================
  2325. ///*
  2326. // * Copyright 2009
  2327. // */
  2328. //#ifndef test_h_seen
  2329. //#define test_h_seen
  2330. //
  2331. //#include "classhelper.h"
  2332. //
  2333. //class Test {
  2334. // public:
  2335. // /**
  2336. // * Small class with some comments
  2337. // */
  2338. // Test();
  2339. //
  2340. // /** Calculate important things.
  2341. // * @returns the result of the calculation
  2342. // */
  2343. // int calculateStuff();
  2344. //
  2345. // private:
  2346. // /**
  2347. // * Retain a value for something.
  2348. // */
  2349. // int m_value;
  2350. //
  2351. // int extracted();
  2352. //};
  2353. //
  2354. //#endif
  2355. //test.cpp
  2356. //#include "test.h"
  2357. //
  2358. //Test::Test() {}
  2359. //
  2360. //int Test::calculateStuff() {
  2361. // // refactor these lines to a new method:
  2362. // /*$*/int result = m_value;
  2363. // result += 10;
  2364. // result *= 10;/*$$*/
  2365. // return result;
  2366. //}
  2367. //====================
  2368. //#include "test.h"
  2369. //
  2370. //Test::Test() {}
  2371. //
  2372. //int Test::extracted() {
  2373. // // refactor these lines to a new method:
  2374. // int result = m_value;
  2375. // result += 10;
  2376. // result *= 10;
  2377. // return result;
  2378. //}
  2379. //
  2380. //int Test::calculateStuff() {
  2381. // // refactor these lines to a new method:
  2382. // int result = extracted();
  2383. // return result;
  2384. //}
  2385. public void testCommentsInHeader_Bug264712() throws Exception {
  2386. assertRefactoringSuccess();
  2387. }
  2388. //main.cpp
  2389. //
  2390. //int myFunc() {
  2391. // return 5;
  2392. //}
  2393. //
  2394. //int main() {
  2395. // int a = 0;
  2396. ///*$*/try {
  2397. // a = myFunc();
  2398. // } catch (const int&) {
  2399. // a = 3;
  2400. // }/*$$*/
  2401. // return a;
  2402. //}
  2403. //====================
  2404. //
  2405. //int myFunc() {
  2406. // return 5;
  2407. //}
  2408. //
  2409. //int extracted(int a) {
  2410. // try {
  2411. // a = myFunc();
  2412. // } catch (const int&) {
  2413. // a = 3;
  2414. // }
  2415. // return a;
  2416. //}
  2417. //
  2418. //int main() {
  2419. // int a = 0;
  2420. // a = extracted(a);
  2421. // return a;
  2422. //}
  2423. public void testCatchUnnamedException_Bug281564() throws Exception {
  2424. assertRefactoringSuccess();
  2425. }
  2426. //main.c
  2427. //int main() {
  2428. // int a,b;
  2429. // /*$*/b=a*2;/*$$*/
  2430. // return a;
  2431. //}
  2432. //====================
  2433. //void extracted(int b, int a) {
  2434. // b = a * 2;
  2435. //}
  2436. //
  2437. //int main() {
  2438. // int a,b;
  2439. // extracted(b, a);
  2440. // return a;
  2441. //}
  2442. public void testCFunction_Bug282004() throws Exception {
  2443. assertRefactoringSuccess();
  2444. }
  2445. //main.c
  2446. //int main() {
  2447. // int a, b;
  2448. // /*$*/a = b * 2;/*$$*/
  2449. // return a;
  2450. //}
  2451. //====================
  2452. //int extracted(int a, int b) {
  2453. // a = b * 2;
  2454. // return a;
  2455. //}
  2456. //
  2457. //int main() {
  2458. // int a, b;
  2459. // a = extracted(a, b);
  2460. // return a;
  2461. //}
  2462. public void testCFunction_Bug288268() throws Exception {
  2463. assertRefactoringSuccess();
  2464. }
  2465. //A.h
  2466. //#ifndef A_H_
  2467. //#define A_H_
  2468. //
  2469. //class A {
  2470. //public:
  2471. // A();
  2472. // virtual ~A();
  2473. // int foo();
  2474. //
  2475. //private:
  2476. // int help();
  2477. //};
  2478. //
  2479. //#endif /*A_H_*/
  2480. //====================
  2481. //#ifndef A_H_
  2482. //#define A_H_
  2483. //
  2484. //class A {
  2485. //public:
  2486. // A();
  2487. // virtual ~A();
  2488. // int foo();
  2489. // virtual int extracted(int i);
  2490. //
  2491. //private:
  2492. // int help();
  2493. //};
  2494. //
  2495. //#endif /*A_H_*/
  2496. //A.cpp
  2497. //#include "A.h"
  2498. //
  2499. //A::A() {
  2500. //}
  2501. //
  2502. //A::~A() {
  2503. //}
  2504. //
  2505. //int A::foo() {
  2506. // int i = 2;
  2507. // //comment
  2508. // /*$*/++i;
  2509. // help();/*$$*/
  2510. // return i;
  2511. //}
  2512. //
  2513. //int A::help() {
  2514. // return 42;
  2515. //}
  2516. //====================
  2517. //#include "A.h"
  2518. //
  2519. //A::A() {
  2520. //}
  2521. //
  2522. //A::~A() {
  2523. //}
  2524. //
  2525. //int A::extracted(int i) {
  2526. // //comment
  2527. // ++i;
  2528. // help();
  2529. // return i;
  2530. //}
  2531. //
  2532. //int A::foo() {
  2533. // int i = 2;
  2534. // //comment
  2535. // i = extracted(i);
  2536. // return i;
  2537. //}
  2538. //
  2539. //int A::help() {
  2540. // return 42;
  2541. //}
  2542. public void testVirtual() throws Exception {
  2543. visibility = VisibilityEnum.v_public;
  2544. virtual = true;
  2545. assertRefactoringSuccess();
  2546. }
  2547. //main.c
  2548. //int main() {
  2549. // int f;
  2550. // /*$*/int a = 0;
  2551. // int b = 1;
  2552. //
  2553. // for (int i = 0; i < 10; ++i) {
  2554. // int c = a + b;
  2555. // a = b;
  2556. // b = c;
  2557. // }/*$$*/
  2558. //
  2559. // f = b;
  2560. //}
  2561. //====================
  2562. //int fib() {
  2563. // int a = 0;
  2564. // int b = 1;
  2565. // for (int i = 0; i < 10; ++i) {
  2566. // int c = a + b;
  2567. // a = b;
  2568. // b = c;
  2569. // }
  2570. // return b;
  2571. //}
  2572. //
  2573. //int main() {
  2574. // int f;
  2575. // int b = fib();
  2576. // f = b;
  2577. //}
  2578. public void testHandlingOfBlankLines() throws Exception {
  2579. extractedFunctionName = "fib";
  2580. assertRefactoringSuccess();
  2581. }
  2582. //A.cpp
  2583. //void test() {
  2584. //}
  2585. //
  2586. //template<typename T>
  2587. //int tempFunct() {
  2588. // T i;
  2589. // i = 0;
  2590. // /*$*/i++;
  2591. // i += 3;/*$$*/
  2592. //
  2593. // return 0;
  2594. //}
  2595. //====================
  2596. //void test() {
  2597. //}
  2598. //
  2599. //template<typename T>
  2600. //void extracted(T i) {
  2601. // i++;
  2602. // i += 3;
  2603. //}
  2604. //
  2605. //template<typename T>
  2606. //int tempFunct() {
  2607. // T i;
  2608. // i = 0;
  2609. // extracted(i);
  2610. // return 0;
  2611. //}
  2612. public void testTemplateFunction() throws Exception {
  2613. assertRefactoringSuccess();
  2614. }
  2615. //A.cpp
  2616. //void test() {
  2617. //}
  2618. //
  2619. //template<typename T>
  2620. //int tempFunct(T p) {
  2621. // /*$*/++p;
  2622. // p + 4;/*$$*/
  2623. // return 0;
  2624. //}
  2625. //====================
  2626. //void test() {
  2627. //}
  2628. //
  2629. //template<typename T>
  2630. //void extracted(T p) {
  2631. // ++p;
  2632. // p + 4;
  2633. //}
  2634. //
  2635. //template<typename T>
  2636. //int tempFunct(T p) {
  2637. // extracted(p);
  2638. // return 0;
  2639. //}
  2640. public void testTemplateFunctionWithTemplateParameter() throws Exception {
  2641. assertRefactoringSuccess();
  2642. }
  2643. //A.cpp
  2644. //void test() {
  2645. //}
  2646. //
  2647. //template<typename T>
  2648. //int tempFunct() {
  2649. // /*$*/T p;
  2650. // p = 0;
  2651. // p + 4;/*$$*/
  2652. // p + 2;
  2653. // return 0;
  2654. //}
  2655. //====================
  2656. //void test() {
  2657. //}
  2658. //
  2659. //template<typename T>
  2660. //T extracted() {
  2661. // T p;
  2662. // p = 0;
  2663. // p + 4;
  2664. // return p;
  2665. //}
  2666. //
  2667. //template<typename T>
  2668. //int tempFunct() {
  2669. // T p = extracted();
  2670. // p + 2;
  2671. // return 0;
  2672. //}
  2673. public void testTemplateFunctionWithTemplateTypeDeclaration() throws Exception {
  2674. assertRefactoringSuccess();
  2675. }
  2676. //A.h
  2677. //#ifndef A_H_
  2678. //#define A_H_
  2679. //
  2680. //class A {
  2681. //public:
  2682. // A();
  2683. // virtual ~A();
  2684. // int foo();
  2685. //
  2686. //private:
  2687. // int help();
  2688. //};
  2689. //
  2690. //#endif /*A_H_*/
  2691. //====================
  2692. //#ifndef A_H_
  2693. //#define A_H_
  2694. //
  2695. //class A {
  2696. //public:
  2697. // A();
  2698. // virtual ~A();
  2699. // int foo();
  2700. //
  2701. //private:
  2702. // int help();
  2703. // int extracted(int i);
  2704. //};
  2705. //
  2706. //#endif /*A_H_*/
  2707. //A.cpp
  2708. //#include "A.h"
  2709. //
  2710. //A::A() {
  2711. //}
  2712. //
  2713. //A::~A() {
  2714. // int i = 2;
  2715. // ++i;
  2716. // help();
  2717. //}
  2718. //
  2719. //int A::foo() {
  2720. // int i = 2;
  2721. // /*$*/++i;
  2722. // help();/*$$*/
  2723. // return i;
  2724. //}
  2725. //
  2726. //int A::help() {
  2727. // return 42;
  2728. //}
  2729. //====================
  2730. //#include "A.h"
  2731. //
  2732. //A::A() {
  2733. //}
  2734. //
  2735. //A::~A() {
  2736. // int i = 2;
  2737. // i = extracted(i);
  2738. //}
  2739. //
  2740. //int A::extracted(int i) {
  2741. // ++i;
  2742. // help();
  2743. // return i;
  2744. //}
  2745. //
  2746. //int A::foo() {
  2747. // int i = 2;
  2748. // i = extracted(i);
  2749. // return i;
  2750. //}
  2751. //
  2752. //int A::help() {
  2753. // return 42;
  2754. //}
  2755. public void testDuplicates() throws Exception {
  2756. assertRefactoringSuccess();
  2757. }
  2758. //A.h
  2759. //#ifndef A_H_
  2760. //#define A_H_
  2761. //
  2762. //class A {
  2763. //public:
  2764. // A();
  2765. // virtual ~A();
  2766. // void foo();
  2767. // int i;
  2768. //
  2769. //private:
  2770. // int help();
  2771. //};
  2772. //
  2773. //#endif /*A_H_*/
  2774. //====================
  2775. //#ifndef A_H_
  2776. //#define A_H_
  2777. //
  2778. //class A {
  2779. //public:
  2780. // A();
  2781. // virtual ~A();
  2782. // void foo();
  2783. // int i;
  2784. //
  2785. //private:
  2786. // int help();
  2787. // int extracted(int j, int& a);
  2788. //};
  2789. //
  2790. //#endif /*A_H_*/
  2791. //A.cpp
  2792. //#include "A.h"
  2793. //
  2794. //A::A() {
  2795. //}
  2796. //
  2797. //A::~A() {
  2798. // int j = 0;
  2799. // i++;
  2800. // j++;
  2801. // help();
  2802. //}
  2803. //
  2804. //void A::foo() {
  2805. // int j = 0;
  2806. // int a = 1;
  2807. // /*$*/j++;
  2808. // a++;
  2809. // help();/*$$*/
  2810. // a++;
  2811. // j++;
  2812. //}
  2813. //
  2814. //int A::help() {
  2815. // return 42;
  2816. //}
  2817. //====================
  2818. //#include "A.h"
  2819. //
  2820. //A::A() {
  2821. //}
  2822. //
  2823. //A::~A() {
  2824. // int j = 0;
  2825. // i = extracted(i, j);
  2826. //}
  2827. //
  2828. //int A::extracted(int j, int& a) {
  2829. // j++;
  2830. // a++;
  2831. // help();
  2832. // return j;
  2833. //}
  2834. //
  2835. //void A::foo() {
  2836. // int j = 0;
  2837. // int a = 1;
  2838. // j = extracted(j, a);
  2839. // a++;
  2840. // j++;
  2841. //}
  2842. //
  2843. //int A::help() {
  2844. // return 42;
  2845. //}
  2846. public void testDuplicateWithField() throws Exception {
  2847. assertRefactoringSuccess();
  2848. }
  2849. //A.h
  2850. //#ifndef A_H_
  2851. //#define A_H_
  2852. //
  2853. //class A {
  2854. //public:
  2855. // A();
  2856. // virtual ~A();
  2857. // void foo();
  2858. // int i;
  2859. // int field;
  2860. //
  2861. //private:
  2862. // int help();
  2863. //};
  2864. //
  2865. //#endif /*A_H_*/
  2866. //====================
  2867. //#ifndef A_H_
  2868. //#define A_H_
  2869. //
  2870. //class A {
  2871. //public:
  2872. // A();
  2873. // virtual ~A();
  2874. // void foo();
  2875. // int i;
  2876. // int field;
  2877. //
  2878. //private:
  2879. // int help();
  2880. // int extracted(int j);
  2881. //};
  2882. //
  2883. //#endif /*A_H_*/
  2884. //A.cpp
  2885. //#include "A.h"
  2886. //
  2887. //A::A() {
  2888. //}
  2889. //
  2890. //A::~A() {
  2891. // int j = 0;
  2892. // int a = 1;
  2893. // a++;
  2894. // j++;
  2895. // help();
  2896. //}
  2897. //
  2898. //void A::foo() {
  2899. // int j = 0;
  2900. //
  2901. // /*$*/field++;
  2902. // j++;
  2903. // help();/*$$*/
  2904. // field++;
  2905. // j++;
  2906. //}
  2907. //
  2908. //int A::help() {
  2909. // return 42;
  2910. //}
  2911. //====================
  2912. //#include "A.h"
  2913. //
  2914. //A::A() {
  2915. //}
  2916. //
  2917. //A::~A() {
  2918. // int j = 0;
  2919. // int a = 1;
  2920. // a++;
  2921. // j++;
  2922. // help();
  2923. //}
  2924. //
  2925. //int A::extracted(int j) {
  2926. // field++;
  2927. // j++;
  2928. // help();
  2929. // return j;
  2930. //}
  2931. //
  2932. //void A::foo() {
  2933. // int j = 0;
  2934. //
  2935. // j = extracted(j);
  2936. // field++;
  2937. // j++;
  2938. //}
  2939. //
  2940. //int A::help() {
  2941. // return 42;
  2942. //}
  2943. public void testDuplicateWithFieldInMarkedScope() throws Exception {
  2944. assertRefactoringSuccess();
  2945. }
  2946. //A.h
  2947. //#ifndef A_H_
  2948. //#define A_H_
  2949. //
  2950. //class A {
  2951. //public:
  2952. // A();
  2953. // virtual ~A();
  2954. // int foo();
  2955. //
  2956. //private:
  2957. // int help();
  2958. //};
  2959. //
  2960. //#endif /*A_H_*/
  2961. //====================
  2962. //#ifndef A_H_
  2963. //#define A_H_
  2964. //
  2965. //class A {
  2966. //public:
  2967. // A();
  2968. // virtual ~A();
  2969. // int foo();
  2970. //
  2971. //private:
  2972. // int help();
  2973. // int extracted(int i, float& j);
  2974. //};
  2975. //
  2976. //#endif /*A_H_*/
  2977. //A.cpp
  2978. //#include "A.h"
  2979. //
  2980. //A::A() {
  2981. //}
  2982. //
  2983. //A::~A() {
  2984. // int oo = 99;
  2985. // float blabla = 0;
  2986. // ++oo;
  2987. // blabla += 1;
  2988. // help();
  2989. // blabla += 1;
  2990. //}
  2991. //
  2992. //int A::foo() {
  2993. // int i = 2;
  2994. // float j = 8989;
  2995. // /*$*/++i;
  2996. // j+=1;
  2997. // help();/*$$*/
  2998. // j++;
  2999. // return i;
  3000. //}
  3001. //
  3002. //int A::help() {
  3003. // return 42;
  3004. //}
  3005. //====================
  3006. //#include "A.h"
  3007. //
  3008. //A::A() {
  3009. //}
  3010. //
  3011. //A::~A() {
  3012. // int oo = 99;
  3013. // float blabla = 0;
  3014. // oo = extracted(oo, blabla);
  3015. // blabla += 1;
  3016. //}
  3017. //
  3018. //int A::extracted(int i, float& j) {
  3019. // ++i;
  3020. // j += 1;
  3021. // help();
  3022. // return i;
  3023. //}
  3024. //
  3025. //int A::foo() {
  3026. // int i = 2;
  3027. // float j = 8989;
  3028. // i = extracted(i, j);
  3029. // j++;
  3030. // return i;
  3031. //}
  3032. //
  3033. //int A::help() {
  3034. // return 42;
  3035. //}
  3036. public void testDuplicatesWithDifferentNames() throws Exception {
  3037. assertRefactoringSuccess();
  3038. }
  3039. //A.h
  3040. //#ifndef A_H_
  3041. //#define A_H_
  3042. //
  3043. //class A {
  3044. //public:
  3045. // A();
  3046. // virtual ~A();
  3047. // int foo();
  3048. //
  3049. //private:
  3050. // int help();
  3051. //};
  3052. //
  3053. //#endif /*A_H_*/
  3054. //====================
  3055. //#ifndef A_H_
  3056. //#define A_H_
  3057. //
  3058. //class A {
  3059. //public:
  3060. // A();
  3061. // virtual ~A();
  3062. // int foo();
  3063. //
  3064. //private:
  3065. // int help();
  3066. // int extracted(int j, int i);
  3067. //};
  3068. //
  3069. //#endif /*A_H_*/
  3070. //A.cpp
  3071. //#include "A.h"
  3072. //
  3073. //A::A() {
  3074. //}
  3075. //
  3076. //A::~A() {
  3077. // int aa = 9;
  3078. // int bb = 99;
  3079. // aa += bb;
  3080. // help();
  3081. //}
  3082. //
  3083. //int A::foo() {
  3084. // int i = 2;
  3085. // int j = 3;
  3086. // /*$*/i += j;
  3087. // help();/*$$*/
  3088. // return i;
  3089. //}
  3090. //
  3091. //int A::help() {
  3092. // return 42;
  3093. //}
  3094. //====================
  3095. //#include "A.h"
  3096. //
  3097. //A::A() {
  3098. //}
  3099. //
  3100. //A::~A() {
  3101. // int aa = 9;
  3102. // int bb = 99;
  3103. // aa = extracted(bb, aa);
  3104. //}
  3105. //
  3106. //int A::extracted(int j, int i) {
  3107. // i += j;
  3108. // help();
  3109. // return i;
  3110. //}
  3111. //
  3112. //int A::foo() {
  3113. // int i = 2;
  3114. // int j = 3;
  3115. // i = extracted(j, i);
  3116. // return i;
  3117. //}
  3118. //
  3119. //int A::help() {
  3120. // return 42;
  3121. //}
  3122. public void testDuplicatesWithDifferentNamesAndReordering() throws Exception {
  3123. parameterOrder = new int[] { 1, 0 };
  3124. assertRefactoringSuccess();
  3125. }
  3126. //A.h
  3127. //#ifndef A_H_
  3128. //#define A_H_
  3129. //
  3130. //class A {
  3131. //public:
  3132. // A();
  3133. // virtual ~A();
  3134. // int foo();
  3135. //
  3136. //private:
  3137. // int help();
  3138. //};
  3139. //
  3140. //#endif /*A_H_*/
  3141. //====================
  3142. //#ifndef A_H_
  3143. //#define A_H_
  3144. //
  3145. //class A {
  3146. //public:
  3147. // A();
  3148. // virtual ~A();
  3149. // int foo();
  3150. //
  3151. //private:
  3152. // int help();
  3153. // void extracted(int& i, float j);
  3154. //};
  3155. //
  3156. //#endif /*A_H_*/
  3157. //A.cpp
  3158. //#include "A.h"
  3159. //
  3160. //A::A() {
  3161. //}
  3162. //
  3163. //A::~A() {
  3164. // int oo = 99;
  3165. // float blabla = 0;
  3166. // ++oo;
  3167. // blabla += 1;
  3168. // help();
  3169. //}
  3170. //
  3171. //int A::foo() {
  3172. // int i = 2;
  3173. // float j = 8989;
  3174. // /*$*/++i;
  3175. // j+=1;
  3176. // help();/*$$*/
  3177. // return i;
  3178. //}
  3179. //
  3180. //int A::help() {
  3181. // return 42;
  3182. //}
  3183. //====================
  3184. //#include "A.h"
  3185. //
  3186. //A::A() {
  3187. //}
  3188. //
  3189. //A::~A() {
  3190. // int oo = 99;
  3191. // float blabla = 0;
  3192. // extracted(oo, blabla);
  3193. //}
  3194. //
  3195. //void A::extracted(int& i, float j) {
  3196. // ++i;
  3197. // j += 1;
  3198. // help();
  3199. //}
  3200. //
  3201. //int A::foo() {
  3202. // int i = 2;
  3203. // float j = 8989;
  3204. // extracted(i, j);
  3205. // return i;
  3206. //}
  3207. //
  3208. //int A::help() {
  3209. // return 42;
  3210. //}
  3211. public void testDuplicatesWithDifferentNamesAndOutputParameter() throws Exception {
  3212. returnValue = NO_RETURN_VALUE;
  3213. assertRefactoringSuccess();
  3214. }
  3215. //A.h
  3216. //#ifndef A_H_
  3217. //#define A_H_
  3218. //
  3219. //class A {
  3220. //public:
  3221. // A();
  3222. // virtual ~A();
  3223. // void foo();
  3224. //
  3225. //private:
  3226. // int help();
  3227. //};
  3228. //
  3229. //#endif /*A_H_*/
  3230. //====================
  3231. //#ifndef A_H_
  3232. //#define A_H_
  3233. //
  3234. //class A {
  3235. //public:
  3236. // A();
  3237. // virtual ~A();
  3238. // void foo();
  3239. //
  3240. //private:
  3241. // int help();
  3242. // void extracted(int i);
  3243. //};…

Large files files are truncated, but you can click here to view the full file