|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2025 ArSysOp. |
| 3 | + * |
| 4 | + * This program and the accompanying materials |
| 5 | + * are made available under the terms of the Eclipse Public License 2.0 |
| 6 | + * which accompanies this distribution, and is available at |
| 7 | + * https://www.eclipse.org/legal/epl-2.0/ |
| 8 | + * |
| 9 | + * SPDX-License-Identifier: EPL-2.0 |
| 10 | + * |
| 11 | + * Contributors: |
| 12 | + * Alexander Fedorov (ArSysOp) - initial API and implementation |
| 13 | + *******************************************************************************/ |
| 14 | +package org.eclipse.pde.api.tools.builder.tests.tags; |
| 15 | + |
| 16 | +import org.eclipse.core.runtime.IPath; |
| 17 | +import org.eclipse.jdt.core.JavaCore; |
| 18 | +import org.eclipse.pde.api.tools.internal.builder.BuilderMessages; |
| 19 | +import org.eclipse.pde.api.tools.internal.problems.ApiProblemFactory; |
| 20 | +import org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor; |
| 21 | +import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblem; |
| 22 | + |
| 23 | +import junit.framework.Test; |
| 24 | + |
| 25 | +/** |
| 26 | + * Tests that the builder finds and properly reports invalid tags on records |
| 27 | + * |
| 28 | + * @since 1.4 |
| 29 | + */ |
| 30 | +public class InvalidRecordTagTests extends TagTest { |
| 31 | + |
| 32 | + public InvalidRecordTagTests(String name) { |
| 33 | + super(name); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * @return the tests for this class |
| 38 | + */ |
| 39 | + public static Test suite() { |
| 40 | + return buildTestSuite(InvalidRecordTagTests.class); |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + protected String getTestingProjectName() { |
| 45 | + return "java17tags"; //$NON-NLS-1$ |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + protected IPath getTestSourcePath() { |
| 50 | + return super.getTestSourcePath().append("record"); //$NON-NLS-1$ |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + protected int getDefaultProblemId() { |
| 55 | + return ApiProblemFactory.createProblemId(IApiProblem.CATEGORY_USAGE, IElementDescriptor.TYPE, IApiProblem.UNSUPPORTED_TAG_USE, IApiProblem.NO_FLAGS); |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + protected String getTestCompliance() { |
| 60 | + return JavaCore.VERSION_14; |
| 61 | + } |
| 62 | + |
| 63 | + public void testInvalidRecordTag1I() { |
| 64 | + x1(true); |
| 65 | + } |
| 66 | + |
| 67 | + public void testInvalidRecordTag1F() { |
| 68 | + x1(false); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Tests having an @noreference tag on a variety of inner / outer / |
| 73 | + * top-level record in package a.b.c |
| 74 | + */ |
| 75 | + private void x1(boolean inc) { |
| 76 | + setExpectedProblemIds(getDefaultProblemSet(3)); |
| 77 | + setExpectedMessageArgs(new String[][] { |
| 78 | + { "@noreference", BuilderMessages.TagValidator_record_not_visible }, //$NON-NLS-1$ |
| 79 | + { "@noreference", BuilderMessages.TagValidator_record_not_visible }, //$NON-NLS-1$ |
| 80 | + { "@noreference", BuilderMessages.TagValidator_record_not_visible }, //$NON-NLS-1$ |
| 81 | + }); |
| 82 | + deployTagTest("test1.java", inc, false); //$NON-NLS-1$ |
| 83 | + } |
| 84 | + |
| 85 | + public void testInvalidRecordTag3I() { |
| 86 | + x3(true); |
| 87 | + } |
| 88 | + |
| 89 | + public void testInvalidRecordTag3F() { |
| 90 | + x3(false); |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * Tests having an @noextend tag on a variety of inner / outer / top-level |
| 95 | + * records in package a.b.c |
| 96 | + */ |
| 97 | + private void x3(boolean inc) { |
| 98 | + setExpectedProblemIds(getDefaultProblemSet(4)); |
| 99 | + setExpectedMessageArgs(new String[][] { |
| 100 | + { "@noextend", BuilderMessages.TagValidator_a_record }, //$NON-NLS-1$ |
| 101 | + { "@noextend", BuilderMessages.TagValidator_a_record }, //$NON-NLS-1$ |
| 102 | + { "@noextend", BuilderMessages.TagValidator_a_record }, //$NON-NLS-1$ |
| 103 | + { "@noextend", BuilderMessages.TagValidator_a_record } //$NON-NLS-1$ |
| 104 | + }); |
| 105 | + deployTagTest("test3.java", inc, false); //$NON-NLS-1$ |
| 106 | + } |
| 107 | + |
| 108 | + public void testInvalidRecordTag4I() { |
| 109 | + x4(true); |
| 110 | + } |
| 111 | + |
| 112 | + public void testInvalidRecordTag4F() { |
| 113 | + x4(false); |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * Tests having an @noextend tag on an record in the default package |
| 118 | + */ |
| 119 | + private void x4(boolean inc) { |
| 120 | + setExpectedProblemIds(getDefaultProblemSet(1)); |
| 121 | + setExpectedMessageArgs(new String[][] { { |
| 122 | + "@noextend", BuilderMessages.TagValidator_a_record } //$NON-NLS-1$ |
| 123 | + }); |
| 124 | + deployTagTest("test4.java", inc, true); //$NON-NLS-1$ |
| 125 | + } |
| 126 | + |
| 127 | + public void testInvalidRecordTag5I() { |
| 128 | + x5(true); |
| 129 | + } |
| 130 | + |
| 131 | + public void testInvalidRecordTag5F() { |
| 132 | + x5(false); |
| 133 | + } |
| 134 | + |
| 135 | + /** |
| 136 | + * Tests having an @nooverride tag on a variety of inner / outer / top-level |
| 137 | + * records in package a.b.c |
| 138 | + */ |
| 139 | + private void x5(boolean inc) { |
| 140 | + setExpectedProblemIds(getDefaultProblemSet(4)); |
| 141 | + setExpectedMessageArgs(new String[][] { |
| 142 | + { "@nooverride", BuilderMessages.TagValidator_a_record }, //$NON-NLS-1$ |
| 143 | + { "@nooverride", BuilderMessages.TagValidator_a_record }, //$NON-NLS-1$ |
| 144 | + { "@nooverride", BuilderMessages.TagValidator_a_record }, //$NON-NLS-1$ |
| 145 | + { "@nooverride", BuilderMessages.TagValidator_a_record } //$NON-NLS-1$ |
| 146 | + }); |
| 147 | + deployTagTest("test5.java", inc, false); //$NON-NLS-1$ |
| 148 | + } |
| 149 | + |
| 150 | + public void testInvalidRecordTag6I() { |
| 151 | + x6(true); |
| 152 | + } |
| 153 | + |
| 154 | + public void testInvalidRecordTag6F() { |
| 155 | + x6(false); |
| 156 | + } |
| 157 | + |
| 158 | + /** |
| 159 | + * Tests having an @nooverride tag on a record in the default package |
| 160 | + */ |
| 161 | + private void x6(boolean inc) { |
| 162 | + setExpectedProblemIds(getDefaultProblemSet(1)); |
| 163 | + setExpectedMessageArgs(new String[][] { { |
| 164 | + "@nooverride", BuilderMessages.TagValidator_a_record } //$NON-NLS-1$ |
| 165 | + }); |
| 166 | + deployTagTest("test6.java", inc, true); //$NON-NLS-1$ |
| 167 | + } |
| 168 | + |
| 169 | + public void testInvalidRecordTag7I() { |
| 170 | + x7(true); |
| 171 | + } |
| 172 | + |
| 173 | + public void testInvalidRecordTag7F() { |
| 174 | + x7(false); |
| 175 | + } |
| 176 | + |
| 177 | + /** |
| 178 | + * Tests having an @noinstantiate on a variety of inner / outer / top-level |
| 179 | + * records in package a.b.c |
| 180 | + */ |
| 181 | + private void x7(boolean inc) { |
| 182 | + setExpectedProblemIds(getDefaultProblemSet(4)); |
| 183 | + setExpectedMessageArgs(new String[][] { |
| 184 | + { "@noinstantiate", BuilderMessages.TagValidator_a_record }, //$NON-NLS-1$ |
| 185 | + { "@noinstantiate", BuilderMessages.TagValidator_a_record }, //$NON-NLS-1$ |
| 186 | + { "@noinstantiate", BuilderMessages.TagValidator_a_record }, //$NON-NLS-1$ |
| 187 | + { "@noinstantiate", BuilderMessages.TagValidator_a_record } //$NON-NLS-1$ |
| 188 | + }); |
| 189 | + deployTagTest("test7.java", inc, false); //$NON-NLS-1$ |
| 190 | + } |
| 191 | + |
| 192 | + public void testInvalidRecordTag8I() { |
| 193 | + x8(true); |
| 194 | + } |
| 195 | + |
| 196 | + public void testInvalidRecordTag8F() { |
| 197 | + x8(false); |
| 198 | + } |
| 199 | + |
| 200 | + /** |
| 201 | + * Tests having an @noinstantiate on a record in the default package |
| 202 | + */ |
| 203 | + private void x8(boolean inc) { |
| 204 | + setExpectedProblemIds(getDefaultProblemSet(1)); |
| 205 | + setExpectedMessageArgs(new String[][] { { |
| 206 | + "@noinstantiate", BuilderMessages.TagValidator_a_record } //$NON-NLS-1$ |
| 207 | + }); |
| 208 | + deployTagTest("test8.java", inc, true); //$NON-NLS-1$ |
| 209 | + } |
| 210 | + |
| 211 | + public void testInvalidRecordTag9I() { |
| 212 | + x9(true); |
| 213 | + } |
| 214 | + |
| 215 | + public void testInvalidRecordTag9F() { |
| 216 | + x9(false); |
| 217 | + } |
| 218 | + |
| 219 | + /** |
| 220 | + * Tests having an @noimplement tag on a variety of inner / outer / |
| 221 | + * top-level records in package a.b.c |
| 222 | + */ |
| 223 | + private void x9(boolean inc) { |
| 224 | + setExpectedProblemIds(getDefaultProblemSet(4)); |
| 225 | + setExpectedMessageArgs(new String[][] { |
| 226 | + { "@noimplement", BuilderMessages.TagValidator_a_record }, //$NON-NLS-1$ |
| 227 | + { "@noimplement", BuilderMessages.TagValidator_a_record }, //$NON-NLS-1$ |
| 228 | + { "@noimplement", BuilderMessages.TagValidator_a_record }, //$NON-NLS-1$ |
| 229 | + { "@noimplement", BuilderMessages.TagValidator_a_record } //$NON-NLS-1$ |
| 230 | + }); |
| 231 | + deployTagTest("test9.java", inc, false); //$NON-NLS-1$ |
| 232 | + } |
| 233 | + |
| 234 | + public void testInvalidRecordTag10I() { |
| 235 | + x10(true); |
| 236 | + } |
| 237 | + |
| 238 | + public void testInvalidRecordTag10F() { |
| 239 | + x10(false); |
| 240 | + } |
| 241 | + |
| 242 | + /** |
| 243 | + * Tests having an @noimplement tag on a record in the default package |
| 244 | + */ |
| 245 | + private void x10(boolean inc) { |
| 246 | + setExpectedProblemIds(getDefaultProblemSet(1)); |
| 247 | + setExpectedMessageArgs(new String[][] { { |
| 248 | + "@noimplement", BuilderMessages.TagValidator_a_record } //$NON-NLS-1$ |
| 249 | + }); |
| 250 | + deployTagTest("test10.java", inc, true); //$NON-NLS-1$ |
| 251 | + } |
| 252 | + |
| 253 | + public void testInvalidRecordTag11I() { |
| 254 | + x11(true); |
| 255 | + } |
| 256 | + |
| 257 | + public void testInvalidRecordTag11F() { |
| 258 | + x11(false); |
| 259 | + } |
| 260 | + |
| 261 | + /** |
| 262 | + * Tests all tags are invalid when parent record is package default |
| 263 | + */ |
| 264 | + private void x11(boolean inc) { |
| 265 | + setExpectedProblemIds(getDefaultProblemSet(1)); |
| 266 | + setExpectedMessageArgs(new String[][] { |
| 267 | + { "@noreference", BuilderMessages.TagValidator_record_not_visible } //$NON-NLS-1$ |
| 268 | + }); |
| 269 | + deployTagTest("test11.java", inc, true); //$NON-NLS-1$ |
| 270 | + } |
| 271 | +} |
0 commit comments