PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/projects/netbeans-7.3/java.hints/test/unit/src/org/netbeans/modules/java/hints/errors/ChangeMethodReturnTypeTest.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 104 lines | 51 code | 12 blank | 41 comment | 0 complexity | 08470bb7baadf220fa249d06f74e6e7c MD5 | raw file
  1. /*
  2. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  3. *
  4. * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
  5. *
  6. * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  7. * Other names may be trademarks of their respective owners.
  8. *
  9. * The contents of this file are subject to the terms of either the GNU
  10. * General Public License Version 2 only ("GPL") or the Common Development and
  11. * Distribution License("CDDL") (collectively, the "License"). You may not use
  12. * this file except in compliance with the License. You can obtain a copy of
  13. * the License at http://www.netbeans.org/cddl-gplv2.html or
  14. * nbbuild/licenses/CDDL-GPL-2-CP. See the License for the specific language
  15. * governing permissions and limitations under the License. When distributing
  16. * the software, include this License Header Notice in each file and include
  17. * the License file at nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
  18. * particular file as subject to the "Classpath" exception as provided by
  19. * Oracle in the GPL Version 2 section of the License file that accompanied
  20. * this code. If applicable, add the following below the License Header, with
  21. * the fields enclosed by brackets [] replaced by your own identifying
  22. * information: "Portions Copyrighted [year] [name of copyright owner]"
  23. *
  24. * If you wish your version of this file to be governed by only the CDDL or
  25. * only the GPL Version 2, indicate your decision by adding "[Contributor]
  26. * elects to include this software in this distribution under the [CDDL or GPL
  27. * Version 2] license." If you do not indicate a single choice of license, a
  28. * recipient has the option to distribute your version of this file under
  29. * either the CDDL, the GPL Version 2 or to extend the choice of license to its
  30. * licensees as provided above. However, if you add GPL Version 2 code and
  31. * therefore, elected the GPL Version 2 license, then the option applies only
  32. * if the new code is made subject to such option by the copyright holder.
  33. *
  34. * Contributor(s):
  35. *
  36. * Portions Copyrighted 2011 Sun Microsystems, Inc.
  37. */
  38. package org.netbeans.modules.java.hints.errors;
  39. import com.sun.source.util.TreePath;
  40. import java.util.List;
  41. import org.netbeans.api.java.source.CompilationInfo;
  42. import org.netbeans.modules.java.hints.infrastructure.ErrorHintsTestBase;
  43. import org.netbeans.spi.editor.hints.Fix;
  44. import org.openide.util.NbBundle;
  45. /**
  46. *
  47. * @author lahvac
  48. */
  49. public class ChangeMethodReturnTypeTest extends ErrorHintsTestBase {
  50. public ChangeMethodReturnTypeTest(String name) {
  51. super(name);
  52. }
  53. public void testVoidToInt() throws Exception {
  54. performFixTest("test/Test.java",
  55. "package test; public class Test { private void t() { return 1|;} }",
  56. "FIX_ChangeMethodReturnType int",
  57. "package test; public class Test { private int t() { return 1;} }");
  58. }
  59. public void testStringToInt() throws Exception {
  60. performFixTest("test/Test.java",
  61. "package test; public class Test { private String t() { return 1|;} }",
  62. "FIX_ChangeMethodReturnType int",
  63. "package test; public class Test { private int t() { return 1;} }");
  64. }
  65. public void test200467() throws Exception {
  66. performFixTest("test/Test.java",
  67. "package test; import java.util.List; public class Test { <A> void getMForm() { List<? extends A> a = null; return a|; } }",
  68. "FIX_ChangeMethodReturnType List&lt;? extends A>",
  69. "package test; import java.util.List; public class Test { <A> List<? extends A> getMForm() { List<? extends A> a = null; return a; } }");
  70. }
  71. public void test201546() throws Exception {
  72. performAnalysisTest("test/Test.java",
  73. "package test; public class Test { Test() { return 1|; } }");
  74. }
  75. public void test203360() throws Exception {
  76. performFixTest("test/Test.java",
  77. "package test; import java.util.Collections; public class Test { private int t() { return Collections.emptyList(|); } }",
  78. "FIX_ChangeMethodReturnType List&lt;Object>",
  79. "package test; import java.util.Collections;import java.util.List; public class Test { private List<Object> t() { return Collections.emptyList(); } }");
  80. }
  81. @Override
  82. protected List<Fix> computeFixes(CompilationInfo info, int pos, TreePath path) throws Exception {
  83. return new ChangeMethodReturnType().run(info, null, pos, path, null);
  84. }
  85. @Override
  86. protected String toDebugString(CompilationInfo info, Fix f) {
  87. return f.getText();
  88. }
  89. static {
  90. NbBundle.setBranding("test");
  91. }
  92. }