1 /******************************************************************************* 2 * Copyright (c) 2008, 2018 IBM Corporation and others. 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 * IBM Corporation - 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.problems.ApiProblemFactory; 19 import org.eclipse.pde.api.tools.internal.provisional.descriptors.IElementDescriptor; 20 import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblem; 21 22 import junit.framework.Test; 23 24 /** 25 * Tests invalid duplicate tags placed on members 26 * 27 * @since 1.0.0 28 */ 29 public class InvalidDuplicateTagsTests extends TagTest { 30 31 private int fPid = -1; 32 InvalidDuplicateTagsTests(String name)33 public InvalidDuplicateTagsTests(String name) { 34 super(name); 35 } 36 37 @Override getDefaultProblemId()38 protected int getDefaultProblemId() { 39 return fPid; 40 } 41 42 /** 43 * Must be called before a call {@link #getDefaultProblemId()} 44 * 45 * @param element 46 * @param kind 47 */ setProblemId(int element, int kind)48 private void setProblemId(int element, int kind) { 49 fPid = ApiProblemFactory.createProblemId(IApiProblem.CATEGORY_USAGE, element, kind, IApiProblem.NO_FLAGS); 50 } 51 52 /** 53 * @return the tests for this class 54 */ suite()55 public static Test suite() { 56 return buildTestSuite(InvalidDuplicateTagsTests.class); 57 } 58 59 @Override getTestSourcePath()60 protected IPath getTestSourcePath() { 61 return super.getTestSourcePath().append("duplicates"); //$NON-NLS-1$ 62 } 63 64 @Override getTestCompliance()65 protected String getTestCompliance() { 66 return JavaCore.VERSION_1_5; 67 } 68 69 /** 70 * Tests a class that has duplicate tags is properly detected using an 71 * incremental build 72 */ testClassWithDuplicateTagsI()73 public void testClassWithDuplicateTagsI() { 74 x1(true); 75 } 76 77 /** 78 * Tests a class that has duplicate tags is properly detected using a full 79 * build 80 */ testClassWithDuplicateTagsF()81 public void testClassWithDuplicateTagsF() { 82 x1(false); 83 } 84 x1(boolean inc)85 private void x1(boolean inc) { 86 setProblemId(IElementDescriptor.TYPE, IApiProblem.DUPLICATE_TAG_USE); 87 setExpectedProblemIds(getDefaultProblemSet(2)); 88 setExpectedMessageArgs(new String[][] { { "@noextend" }, //$NON-NLS-1$ 89 { "@noinstantiate" } //$NON-NLS-1$ 90 }); 91 deployTagTest("test1.java", inc, false); //$NON-NLS-1$ 92 } 93 94 /** 95 * Tests that an interface with duplicate tags is properly using an 96 * incremental build 97 */ testInterfaceWithDuplicateTagsI()98 public void testInterfaceWithDuplicateTagsI() { 99 x2(true); 100 } 101 102 /** 103 * Tests that an interface with duplicate tags is properly detected using a 104 * full build 105 */ testInterfaceWithDuplicateTagsF()106 public void testInterfaceWithDuplicateTagsF() { 107 x2(false); 108 } 109 x2(boolean inc)110 private void x2(boolean inc) { 111 setProblemId(IElementDescriptor.TYPE, IApiProblem.DUPLICATE_TAG_USE); 112 setExpectedProblemIds(getDefaultProblemSet(2)); 113 setExpectedMessageArgs(new String[][] { { "@noimplement" }, //$NON-NLS-1$ 114 { "@noimplement" } //$NON-NLS-1$ 115 }); 116 deployTagTest("test2.java", inc, false); //$NON-NLS-1$ 117 } 118 119 /** 120 * Tests that a class field with duplicate tags is properly detected using 121 * an incremental build 122 */ testClassFieldWithDuplicateTagsI()123 public void testClassFieldWithDuplicateTagsI() { 124 x3(true); 125 } 126 127 /** 128 * Tests that a class field with duplicate tags is properly detected using a 129 * full build 130 */ testClassFieldWithDuplicateTagsF()131 public void testClassFieldWithDuplicateTagsF() { 132 x3(false); 133 } 134 x3(boolean inc)135 private void x3(boolean inc) { 136 setProblemId(IElementDescriptor.FIELD, IApiProblem.DUPLICATE_TAG_USE); 137 setExpectedProblemIds(getDefaultProblemSet(2)); 138 setExpectedMessageArgs(new String[][] { { "@noreference" }, //$NON-NLS-1$ 139 { "@noreference" } //$NON-NLS-1$ 140 }); 141 deployTagTest("test3.java", inc, false); //$NON-NLS-1$ 142 } 143 144 /** 145 * Tests that an interface field with duplicate tags is properly detected 146 * using an incremental build 147 */ testInterfaceFieldWithDuplicateTagsI()148 public void testInterfaceFieldWithDuplicateTagsI() { 149 x4(true); 150 } 151 152 /** 153 * Tests that an interface field with duplicate tags is properly detected 154 * using a full build 155 */ testInterfaceFieldWithDuplicateTagsF()156 public void testInterfaceFieldWithDuplicateTagsF() { 157 x4(false); 158 } 159 x4(boolean inc)160 private void x4(boolean inc) { 161 setProblemId(IElementDescriptor.FIELD, IApiProblem.DUPLICATE_TAG_USE); 162 setExpectedProblemIds(getDefaultProblemSet(2)); 163 setExpectedMessageArgs(new String[][] { { "@noreference" }, //$NON-NLS-1$ 164 { "@noreference" } //$NON-NLS-1$ 165 }); 166 deployTagTest("test4.java", inc, false); //$NON-NLS-1$ 167 } 168 169 /** 170 * Tests that an enum field with duplicate tags is properly detected using 171 * an incremental build 172 */ testEnumFieldWithDuplicateTagsI()173 public void testEnumFieldWithDuplicateTagsI() { 174 x5(true); 175 } 176 177 /** 178 * Tests that an enum field with duplicate tags is properly detected using a 179 * full build 180 */ testEnumFieldWithDuplicateTagsF()181 public void testEnumFieldWithDuplicateTagsF() { 182 x5(false); 183 } 184 x5(boolean inc)185 private void x5(boolean inc) { 186 setProblemId(IElementDescriptor.FIELD, IApiProblem.DUPLICATE_TAG_USE); 187 setExpectedProblemIds(getDefaultProblemSet(3)); 188 setExpectedMessageArgs(new String[][] { { "@noreference" }, //$NON-NLS-1$ 189 { "@noreference" }, //$NON-NLS-1$ 190 { "@noreference" } //$NON-NLS-1$ 191 }); 192 deployTagTest("test5.java", inc, false); //$NON-NLS-1$ 193 } 194 195 /** 196 * Tests that a class method with duplicate tags is properly detected using 197 * an incremental build 198 */ testClassMethodWithDuplicateTagsI()199 public void testClassMethodWithDuplicateTagsI() { 200 x6(true); 201 } 202 203 /** 204 * Tests that a class method with duplicate tags is properly detected using 205 * a full build 206 */ testClassMethodWithDuplicateTagsF()207 public void testClassMethodWithDuplicateTagsF() { 208 x6(false); 209 } 210 x6(boolean inc)211 private void x6(boolean inc) { 212 setProblemId(IElementDescriptor.METHOD, IApiProblem.DUPLICATE_TAG_USE); 213 setExpectedProblemIds(getDefaultProblemSet(4)); 214 setExpectedMessageArgs(new String[][] { { "@noreference" }, //$NON-NLS-1$ 215 { "@noreference" }, //$NON-NLS-1$ 216 { "@nooverride" }, //$NON-NLS-1$ 217 { "@nooverride" } //$NON-NLS-1$ 218 }); 219 deployTagTest("test6.java", inc, false); //$NON-NLS-1$ 220 } 221 222 /** 223 * Tests that an interface method with duplicate tags is properly detected 224 * using an incremental build 225 */ testInterfaceMethodWithDuplicateTagsI()226 public void testInterfaceMethodWithDuplicateTagsI() { 227 x7(true); 228 } 229 230 /** 231 * Tests that an interface method with duplicate tags is properly detected 232 * using a full build 233 */ testInterfaceMethodWithDuplicateTagsF()234 public void testInterfaceMethodWithDuplicateTagsF() { 235 x7(false); 236 } 237 x7(boolean inc)238 private void x7(boolean inc) { 239 setProblemId(IElementDescriptor.METHOD, IApiProblem.DUPLICATE_TAG_USE); 240 setExpectedProblemIds(getDefaultProblemSet(4)); 241 setExpectedMessageArgs(new String[][] { { "@noreference" }, //$NON-NLS-1$ 242 { "@noreference" }, //$NON-NLS-1$ 243 { "@noreference" }, //$NON-NLS-1$ 244 { "@noreference" }, //$NON-NLS-1$ 245 }); 246 deployTagTest("test7.java", inc, false); //$NON-NLS-1$ 247 } 248 249 /** 250 * Tests that an enum method with duplicate tags is properly detected using 251 * an incremental build 252 */ testEnumMethodWithDuplicateTagsI()253 public void testEnumMethodWithDuplicateTagsI() { 254 x8(true); 255 } 256 257 /** 258 * Tests that an interface method with duplicate tags is properly detected 259 * using a full build 260 */ testEnumMethodWithDuplicateTagsF()261 public void testEnumMethodWithDuplicateTagsF() { 262 x8(false); 263 } 264 x8(boolean inc)265 private void x8(boolean inc) { 266 setProblemId(IElementDescriptor.METHOD, IApiProblem.DUPLICATE_TAG_USE); 267 setExpectedProblemIds(getDefaultProblemSet(4)); 268 setExpectedMessageArgs(new String[][] { { "@noreference" }, //$NON-NLS-1$ 269 { "@noreference" }, //$NON-NLS-1$ 270 { "@noreference" }, //$NON-NLS-1$ 271 { "@noreference" }, //$NON-NLS-1$ 272 }); 273 deployTagTest("test8.java", inc, false); //$NON-NLS-1$ 274 } 275 } 276