|
1 | 1 | /******************************************************************************* |
2 | | - * Copyright (c) 2021, 2024 IBM Corporation and others. |
| 2 | + * Copyright (c) 2021, 2025 IBM Corporation and others. |
3 | 3 | * |
4 | 4 | * This program and the accompanying materials are made available under the |
5 | 5 | * terms of the Eclipse Public License v. 2.0 which is available at |
@@ -52,72 +52,85 @@ public void GeneratedAnnotation() throws Exception { |
52 | 52 |
|
53 | 53 | // expected Diagnostics |
54 | 54 |
|
55 | | - Diagnostic d1 = d(15, 19, 31, "A method with the @PostConstruct annotation must be void.", |
| 55 | + Diagnostic d1 = d(19, 19, 31, "A method with the @PostConstruct annotation must be void.", |
56 | 56 | DiagnosticSeverity.Error, "jakarta-annotations", "PostConstructReturnType"); |
57 | 57 |
|
58 | | - Diagnostic d2 = d(20, 16, 28, "A method with the @PostConstruct annotation must not have any parameters.", |
| 58 | + Diagnostic d2 = d(24, 16, 28, "A method with the @PostConstruct annotation must not have any parameters.", |
59 | 59 | DiagnosticSeverity.Error, "jakarta-annotations", "PostConstructParams"); |
60 | 60 |
|
61 | | - Diagnostic d3 = d(25, 16, 28, "A method with the @PostConstruct annotation must not throw checked exceptions.", |
62 | | - DiagnosticSeverity.Warning, "jakarta-annotations", "PostConstructException"); |
| 61 | + Diagnostic d3 = d(28, 16, 28, "A method with the @PostConstruct annotation must not throw checked exceptions.", |
| 62 | + DiagnosticSeverity.Error, "jakarta-annotations", "PostConstructException"); |
63 | 63 |
|
64 | | - assertJavaDiagnostics(diagnosticsParams, utils, d1, d2, d3); |
| 64 | + Diagnostic d4 = d(43, 16, 32, "A method with the @PostConstruct annotation must not throw checked exceptions.", |
| 65 | + DiagnosticSeverity.Error, "jakarta-annotations", "PostConstructException"); |
| 66 | + |
| 67 | + Diagnostic d5 = d(48, 16, 31, "A method with the @PostConstruct annotation must not throw checked exceptions.", |
| 68 | + DiagnosticSeverity.Error, "jakarta-annotations", "PostConstructException"); |
| 69 | + |
| 70 | + assertJavaDiagnostics(diagnosticsParams, utils, d1, d2, d3, d4, d5); |
65 | 71 |
|
66 | 72 | // Starting codeAction tests. |
67 | | - String newText = "package io.openliberty.sample.jakarta.annotations;\n\n" + |
68 | | - "import jakarta.annotation.PostConstruct;\n" + |
69 | | - "import jakarta.annotation.Resource;\n\n" + |
70 | | - "@Resource(type = Object.class, name = \"aa\")\n" + |
71 | | - "public class PostConstructAnnotation {\n\n" + |
72 | | - " private Integer studentId;\n\n private boolean isHappy;\n\n" + |
73 | | - " private boolean isSad;\n\n @PostConstruct()\n" + |
74 | | - " public void getStudentId() {\n return this.studentId;\n" + |
75 | | - " }\n\n @PostConstruct\n public void getHappiness(String type) {\n\n" + |
76 | | - " }\n\n @PostConstruct\n" + |
77 | | - " public void throwTantrum() throws Exception {\n" + |
78 | | - " System.out.println(\"I'm sad\");\n }\n\n" + |
79 | | - " private String emailAddress;\n\n}"; |
| 73 | + String newText = "package io.openliberty.sample.jakarta.annotations;\n\nimport jakarta.annotation.PostConstruct;\n" + |
| 74 | + "import jakarta.annotation.Resource;\n\nimport java.io.IOException;\n\n@Resource(type = Object.class, name = \"aa\")\n" + |
| 75 | + "public class PostConstructAnnotation {\n\n private Integer studentId;\n\n private boolean isHappy;\n\n " + |
| 76 | + "private boolean isSad;\n\n private String emailAddress;\n\n @PostConstruct()\n " + |
| 77 | + "public void getStudentId() {\n return this.studentId;\n }\n\n @PostConstruct\n " + |
| 78 | + "public void getHappiness(String type) {\n }\n\n @PostConstruct\n " + |
| 79 | + "public void throwTantrum() throws Exception {\n System.out.println(\"I'm sad\");\n }\n\n " + |
| 80 | + "@PostConstruct\n public void throwRuntimeException() throws RuntimeException {\n " + |
| 81 | + "System.out.println(\"RuntimeException\");\n }\n\n @PostConstruct\n " + |
| 82 | + "public void throwNullPointerException() throws NullPointerException {\n " + |
| 83 | + "System.out.println(\"NullPointerException\");\n }\n\n @PostConstruct\n " + |
| 84 | + "public void throwIOException() throws IOException {\n System.out.println(\"IOException\");\n }\n\n " + |
| 85 | + "@PostConstruct\n public void throwExceptions() throws CustomCheckedException, CustomUncheckedException, IOException {\n " + |
| 86 | + "System.out.println(\"throwExceptions\");\n }\n\n @PostConstruct\n " + |
| 87 | + "public void throwCustomUnCheckedException() throws CustomUncheckedException {\n " + |
| 88 | + "System.out.println(\"CustomUncheckedException\");\n }\n\n " + |
| 89 | + "@PostConstruct\n public void throwError() throws Error {\n System.out.println(\"throwError\");\n }\n\n}"; |
80 | 90 |
|
81 | 91 | JakartaJavaCodeActionParams codeActionParams2 = createCodeActionParams(uri, d1); |
82 | | - TextEdit te3 = te(0, 0, 31, 1, newText); |
| 92 | + TextEdit te3 = te(0, 0, 62, 1, newText); |
83 | 93 | CodeAction ca3 = ca(uri, "Change return type to void", d1, te3); |
84 | 94 | assertJavaCodeAction(codeActionParams2, utils, ca3); |
85 | 95 |
|
86 | | - String newText1 = "package io.openliberty.sample.jakarta.annotations;\n\n" + |
87 | | - "import jakarta.annotation.PostConstruct;\n" + |
88 | | - "import jakarta.annotation.Resource;\n\n" + |
89 | | - "@Resource(type = Object.class, name = \"aa\")\n" + |
90 | | - "public class PostConstructAnnotation {\n\n" + |
91 | | - " private Integer studentId;\n\n private boolean isHappy;\n\n" + |
92 | | - " private boolean isSad;\n\n @PostConstruct()\n" + |
93 | | - " public Integer getStudentId() {\n return this.studentId;\n" + |
94 | | - " }\n\n public void getHappiness(String type) {\n\n" + |
95 | | - " }\n\n @PostConstruct\n" + |
96 | | - " public void throwTantrum() throws Exception {\n" + |
97 | | - " System.out.println(\"I'm sad\");\n }\n\n" + |
98 | | - " private String emailAddress;\n\n}"; |
99 | | - |
100 | | - String newText2 = "package io.openliberty.sample.jakarta.annotations;\n\n" + |
101 | | - "import jakarta.annotation.PostConstruct;\n" + |
102 | | - "import jakarta.annotation.Resource;\n\n" + |
103 | | - "@Resource(type = Object.class, name = \"aa\")\n" + |
104 | | - "public class PostConstructAnnotation {\n\n " + |
105 | | - "private Integer studentId;\n\n " + |
106 | | - "private boolean isHappy;\n\n " + |
107 | | - "private boolean isSad;\n\n " + |
108 | | - "@PostConstruct()\n " + |
109 | | - "public Integer getStudentId() {\n " + |
110 | | - "return this.studentId;\n }\n\n " + |
111 | | - "@PostConstruct\n " + |
112 | | - "public void getHappiness() {\n\n }\n\n " + |
113 | | - "@PostConstruct\n " + |
114 | | - "public void throwTantrum() throws Exception {\n " + |
115 | | - "System.out.println(\"I'm sad\");\n }\n\n " + |
116 | | - "private String emailAddress;\n\n}"; |
| 96 | + String newText1 = "package io.openliberty.sample.jakarta.annotations;\n\nimport jakarta.annotation.PostConstruct;\n" + |
| 97 | + "import jakarta.annotation.Resource;\n\nimport java.io.IOException;\n\n@Resource(type = Object.class, name = \"aa\")\n" + |
| 98 | + "public class PostConstructAnnotation {\n\n private Integer studentId;\n\n private boolean isHappy;\n\n " + |
| 99 | + "private boolean isSad;\n\n private String emailAddress;\n\n @PostConstruct()\n " + |
| 100 | + "public Integer getStudentId() {\n return this.studentId;\n }\n\n public void getHappiness(String type) {\n }\n\n " + |
| 101 | + "@PostConstruct\n public void throwTantrum() throws Exception {\n System.out.println(\"I'm sad\");\n }\n\n " + |
| 102 | + "@PostConstruct\n public void throwRuntimeException() throws RuntimeException {\n " + |
| 103 | + "System.out.println(\"RuntimeException\");\n }\n\n " + |
| 104 | + "@PostConstruct\n public void throwNullPointerException() throws NullPointerException {\n " + |
| 105 | + "System.out.println(\"NullPointerException\");\n }\n\n @PostConstruct\n " + |
| 106 | + "public void throwIOException() throws IOException {\n System.out.println(\"IOException\");\n }\n\n " + |
| 107 | + "@PostConstruct\n public void throwExceptions() throws CustomCheckedException, CustomUncheckedException, IOException {\n " + |
| 108 | + "System.out.println(\"throwExceptions\");\n }\n\n @PostConstruct\n " + |
| 109 | + "public void throwCustomUnCheckedException() throws CustomUncheckedException {\n " + |
| 110 | + "System.out.println(\"CustomUncheckedException\");\n }\n\n @PostConstruct\n public void throwError() throws Error {\n " + |
| 111 | + "System.out.println(\"throwError\");\n }\n\n}"; |
| 112 | + |
| 113 | + String newText2 = "package io.openliberty.sample.jakarta.annotations;\n\nimport jakarta.annotation.PostConstruct;\n" + |
| 114 | + "import jakarta.annotation.Resource;\n\nimport java.io.IOException;\n\n@Resource(type = Object.class, name = \"aa\")\n" + |
| 115 | + "public class PostConstructAnnotation {\n\n private Integer studentId;\n\n private boolean isHappy;\n\n " + |
| 116 | + "private boolean isSad;\n\n private String emailAddress;\n\n @PostConstruct()\n " + |
| 117 | + "public Integer getStudentId() {\n return this.studentId;\n }\n\n @PostConstruct\n " + |
| 118 | + "public void getHappiness() {\n }\n\n @PostConstruct\n public void throwTantrum() throws Exception {\n " + |
| 119 | + "System.out.println(\"I'm sad\");\n }\n\n @PostConstruct\n public void throwRuntimeException() throws RuntimeException {\n " + |
| 120 | + "System.out.println(\"RuntimeException\");\n }\n\n @PostConstruct\n " + |
| 121 | + "public void throwNullPointerException() throws NullPointerException {\n " + |
| 122 | + "System.out.println(\"NullPointerException\");\n }\n\n " + |
| 123 | + "@PostConstruct\n public void throwIOException() throws IOException {\n " + |
| 124 | + "System.out.println(\"IOException\");\n }\n\n " + |
| 125 | + "@PostConstruct\n public void throwExceptions() throws CustomCheckedException, CustomUncheckedException, IOException {\n " + |
| 126 | + "System.out.println(\"throwExceptions\");\n }\n\n @PostConstruct\n " + |
| 127 | + "public void throwCustomUnCheckedException() throws CustomUncheckedException {\n " + |
| 128 | + "System.out.println(\"CustomUncheckedException\");\n }\n\n " + |
| 129 | + "@PostConstruct\n public void throwError() throws Error {\n System.out.println(\"throwError\");\n }\n\n}"; |
117 | 130 |
|
118 | 131 | JakartaJavaCodeActionParams codeActionParams1 = createCodeActionParams(uri, d2); |
119 | | - TextEdit te = te(0, 0, 31, 1, newText1); |
120 | | - TextEdit te1 = te(0, 0, 31, 1, newText2); |
| 132 | + TextEdit te = te(0, 0, 62, 1, newText1); |
| 133 | + TextEdit te1 = te(0, 0, 62, 1, newText2); |
121 | 134 | CodeAction ca = ca(uri, "Remove @PostConstruct", d2, te); |
122 | 135 | CodeAction ca1 = ca(uri, "Remove all parameters", d2, te1); |
123 | 136 | assertJavaCodeAction(codeActionParams1, utils, ca, ca1); |
|
0 commit comments