97 } 98 99 /** 100 * Constructor for concrete subclasses; uses the argument for the 101 * default value. 102 * 103 * @param defaultValue the value to assign to {@link #DEFAULT_VALUE} 104 * @deprecated Release 6 is obsolete; update to a visitor for a newer 105 * release level. 106 */ 107 @Deprecated(since="9") 108 protected ElementKindVisitor6(R defaultValue) { 109 super(defaultValue); 110 } 111 112 /** 113 * {@inheritDoc} 114 * 115 * The element argument has kind {@code PACKAGE}. 116 * 117 * @param e {@inheritDoc} 118 * @param p {@inheritDoc} 119 * @return {@inheritDoc} 120 */ 121 @Override 122 public R visitPackage(PackageElement e, P p) { 123 assert e.getKind() == PACKAGE: "Bad kind on PackageElement"; 124 return defaultAction(e, p); 125 } 126 127 /** 128 * Visits a type element, dispatching to the visit method for the 129 * specific {@linkplain ElementKind kind} of type, {@code 130 * ANNOTATION_TYPE}, {@code CLASS}, {@code ENUM}, or {@code 131 * INTERFACE}. 132 * 133 * @param e {@inheritDoc} 134 * @param p {@inheritDoc} 135 * @return the result of the kind-specific visit method 136 */ 137 @Override 138 public R visitType(TypeElement e, P p) { 139 ElementKind k = e.getKind(); 140 switch(k) { 141 case ANNOTATION_TYPE: 142 return visitTypeAsAnnotationType(e, p); 143 144 case CLASS: 145 return visitTypeAsClass(e, p); 146 147 case ENUM: 148 return visitTypeAsEnum(e, p); 149 150 case INTERFACE: 151 return visitTypeAsInterface(e, p); 152 153 default: 154 throw new AssertionError("Bad kind " + k + " for TypeElement" + e); 155 } 156 } 157 158 /** 159 * Visits an {@code ANNOTATION_TYPE} type element by calling 160 * {@code defaultAction}. 161 * 162 * @param e the element to visit 163 * @param p a visitor-specified parameter 164 * @return the result of {@code defaultAction} 165 */ 166 public R visitTypeAsAnnotationType(TypeElement e, P p) { 167 return defaultAction(e, p); 168 } 169 170 /** 171 * Visits a {@code CLASS} type element by calling {@code 172 * defaultAction}. 173 * 174 * @param e the element to visit 175 * @param p a visitor-specified parameter 176 * @return the result of {@code defaultAction} 177 */ 178 public R visitTypeAsClass(TypeElement e, P p) { 179 return defaultAction(e, p); 180 } 181 182 /** 183 * Visits an {@code ENUM} type element by calling {@code 184 * defaultAction}. 185 * 186 * @param e the element to visit 187 * @param p a visitor-specified parameter 188 * @return the result of {@code defaultAction} 189 */ 190 public R visitTypeAsEnum(TypeElement e, P p) { 191 return defaultAction(e, p); 192 } 193 194 /** 195 * Visits an {@code INTERFACE} type element by calling {@code 196 * defaultAction}. 197 *. 198 * @param e the element to visit 199 * @param p a visitor-specified parameter 200 * @return the result of {@code defaultAction} 201 */ 202 public R visitTypeAsInterface(TypeElement e, P p) { 203 return defaultAction(e, p); 204 } 205 206 /** 207 * Visits a variable element, dispatching to the visit method for 208 * the specific {@linkplain ElementKind kind} of variable, {@code 209 * ENUM_CONSTANT}, {@code EXCEPTION_PARAMETER}, {@code FIELD}, 210 * {@code LOCAL_VARIABLE}, {@code PARAMETER}, or {@code RESOURCE_VARIABLE}. 211 * 212 * @param e {@inheritDoc} 213 * @param p {@inheritDoc} 214 * @return the result of the kind-specific visit method 215 */ 216 @Override 217 public R visitVariable(VariableElement e, P p) { 218 ElementKind k = e.getKind(); 219 switch(k) { 220 case ENUM_CONSTANT: 221 return visitVariableAsEnumConstant(e, p); 222 223 case EXCEPTION_PARAMETER: 224 return visitVariableAsExceptionParameter(e, p); 225 226 case FIELD: 227 return visitVariableAsField(e, p); 228 229 case LOCAL_VARIABLE: 230 return visitVariableAsLocalVariable(e, p); 231 232 case PARAMETER: 233 return visitVariableAsParameter(e, p); 234 235 case RESOURCE_VARIABLE: 236 return visitVariableAsResourceVariable(e, p); 237 238 default: 239 throw new AssertionError("Bad kind " + k + " for VariableElement" + e); 240 } 241 } 242 243 /** 244 * Visits an {@code ENUM_CONSTANT} variable element by calling 245 * {@code defaultAction}. 246 * 247 * @param e the element to visit 248 * @param p a visitor-specified parameter 249 * @return the result of {@code defaultAction} 250 */ 251 public R visitVariableAsEnumConstant(VariableElement e, P p) { 252 return defaultAction(e, p); 253 } 254 255 /** 256 * Visits an {@code EXCEPTION_PARAMETER} variable element by calling 257 * {@code defaultAction}. 258 * 259 * @param e the element to visit 260 * @param p a visitor-specified parameter 261 * @return the result of {@code defaultAction} 262 */ 263 public R visitVariableAsExceptionParameter(VariableElement e, P p) { 264 return defaultAction(e, p); 265 } 266 267 /** 268 * Visits a {@code FIELD} variable element by calling 269 * {@code defaultAction}. 270 * 271 * @param e the element to visit 272 * @param p a visitor-specified parameter 273 * @return the result of {@code defaultAction} 274 */ 275 public R visitVariableAsField(VariableElement e, P p) { 276 return defaultAction(e, p); 277 } 278 279 /** 280 * Visits a {@code LOCAL_VARIABLE} variable element by calling 281 * {@code defaultAction}. 282 * 283 * @param e the element to visit 284 * @param p a visitor-specified parameter 285 * @return the result of {@code defaultAction} 286 */ 287 public R visitVariableAsLocalVariable(VariableElement e, P p) { 288 return defaultAction(e, p); 289 } 290 291 /** 292 * Visits a {@code PARAMETER} variable element by calling 293 * {@code defaultAction}. 294 * 295 * @param e the element to visit 296 * @param p a visitor-specified parameter 297 * @return the result of {@code defaultAction} 298 */ 299 public R visitVariableAsParameter(VariableElement e, P p) { 300 return defaultAction(e, p); 301 } 302 303 /** 304 * Visits a {@code RESOURCE_VARIABLE} variable element by calling 305 * {@code visitUnknown}. 306 * 307 * @param e the element to visit 308 * @param p a visitor-specified parameter 309 * @return the result of {@code visitUnknown} 310 * 311 * @since 1.7 312 */ 313 public R visitVariableAsResourceVariable(VariableElement e, P p) { 314 return visitUnknown(e, p); 315 } 316 317 /** 318 * Visits an executable element, dispatching to the visit method 319 * for the specific {@linkplain ElementKind kind} of executable, 320 * {@code CONSTRUCTOR}, {@code INSTANCE_INIT}, {@code METHOD}, or 321 * {@code STATIC_INIT}. 322 * 323 * @param e {@inheritDoc} 324 * @param p {@inheritDoc} 325 * @return the result of the kind-specific visit method 326 */ 327 @Override 328 public R visitExecutable(ExecutableElement e, P p) { 329 ElementKind k = e.getKind(); 330 switch(k) { 331 case CONSTRUCTOR: 332 return visitExecutableAsConstructor(e, p); 333 334 case INSTANCE_INIT: 335 return visitExecutableAsInstanceInit(e, p); 336 337 case METHOD: 338 return visitExecutableAsMethod(e, p); 339 340 case STATIC_INIT: 341 return visitExecutableAsStaticInit(e, p); 342 343 default: 344 throw new AssertionError("Bad kind " + k + " for ExecutableElement" + e); 345 } 346 } 347 348 /** 349 * Visits a {@code CONSTRUCTOR} executable element by calling 350 * {@code defaultAction}. 351 * 352 * @param e the element to visit 353 * @param p a visitor-specified parameter 354 * @return the result of {@code defaultAction} 355 */ 356 public R visitExecutableAsConstructor(ExecutableElement e, P p) { 357 return defaultAction(e, p); 358 } 359 360 /** 361 * Visits an {@code INSTANCE_INIT} executable element by calling 362 * {@code defaultAction}. 363 * 364 * @param e the element to visit 365 * @param p a visitor-specified parameter 366 * @return the result of {@code defaultAction} 367 */ 368 public R visitExecutableAsInstanceInit(ExecutableElement e, P p) { 369 return defaultAction(e, p); 370 } 371 372 /** 373 * Visits a {@code METHOD} executable element by calling 374 * {@code defaultAction}. 375 * 376 * @param e the element to visit 377 * @param p a visitor-specified parameter 378 * @return the result of {@code defaultAction} 379 */ 380 public R visitExecutableAsMethod(ExecutableElement e, P p) { 381 return defaultAction(e, p); 382 } 383 384 /** 385 * Visits a {@code STATIC_INIT} executable element by calling 386 * {@code defaultAction}. 387 * 388 * @param e the element to visit 389 * @param p a visitor-specified parameter 390 * @return the result of {@code defaultAction} 391 */ 392 public R visitExecutableAsStaticInit(ExecutableElement e, P p) { 393 return defaultAction(e, p); 394 } 395 396 397 /** 398 * {@inheritDoc} 399 * 400 * The element argument has kind {@code TYPE_PARAMETER}. 401 * 402 * @param e {@inheritDoc} 403 * @param p {@inheritDoc} 404 * @return {@inheritDoc} 405 */ 406 @Override 407 public R visitTypeParameter(TypeParameterElement e, P p) { 408 assert e.getKind() == TYPE_PARAMETER: "Bad kind on TypeParameterElement"; 409 return defaultAction(e, p); 410 } 411 } | 97 } 98 99 /** 100 * Constructor for concrete subclasses; uses the argument for the 101 * default value. 102 * 103 * @param defaultValue the value to assign to {@link #DEFAULT_VALUE} 104 * @deprecated Release 6 is obsolete; update to a visitor for a newer 105 * release level. 106 */ 107 @Deprecated(since="9") 108 protected ElementKindVisitor6(R defaultValue) { 109 super(defaultValue); 110 } 111 112 /** 113 * {@inheritDoc} 114 * 115 * The element argument has kind {@code PACKAGE}. 116 * 117 * @implSpec This implementation calls {@code defaultAction}. 118 * 119 * @param e {@inheritDoc} 120 * @param p {@inheritDoc} 121 * @return {@inheritDoc} 122 */ 123 @Override 124 public R visitPackage(PackageElement e, P p) { 125 assert e.getKind() == PACKAGE: "Bad kind on PackageElement"; 126 return defaultAction(e, p); 127 } 128 129 /** 130 * {@inheritDoc} 131 * 132 * @implSpec This implementation dispatches to the visit method for the 133 * specific {@linkplain ElementKind kind} of type, {@code 134 * ANNOTATION_TYPE}, {@code CLASS}, {@code ENUM}, or {@code 135 * INTERFACE}. 136 * 137 * @param e {@inheritDoc} 138 * @param p {@inheritDoc} 139 * @return the result of the kind-specific visit method 140 */ 141 @Override 142 public R visitType(TypeElement e, P p) { 143 ElementKind k = e.getKind(); 144 switch(k) { 145 case ANNOTATION_TYPE: 146 return visitTypeAsAnnotationType(e, p); 147 148 case CLASS: 149 return visitTypeAsClass(e, p); 150 151 case ENUM: 152 return visitTypeAsEnum(e, p); 153 154 case INTERFACE: 155 return visitTypeAsInterface(e, p); 156 157 default: 158 throw new AssertionError("Bad kind " + k + " for TypeElement" + e); 159 } 160 } 161 162 /** 163 * Visits an {@code ANNOTATION_TYPE} type element. 164 * 165 * @implSpec This implementation calls {@code defaultAction}. 166 * 167 * @param e the element to visit 168 * @param p a visitor-specified parameter 169 * @return the result of {@code defaultAction} 170 */ 171 public R visitTypeAsAnnotationType(TypeElement e, P p) { 172 return defaultAction(e, p); 173 } 174 175 /** 176 * Visits a {@code CLASS} type element. 177 * 178 * @implSpec This implementation calls {@code defaultAction}. 179 * 180 * @param e the element to visit 181 * @param p a visitor-specified parameter 182 * @return the result of {@code defaultAction} 183 */ 184 public R visitTypeAsClass(TypeElement e, P p) { 185 return defaultAction(e, p); 186 } 187 188 /** 189 * Visits an {@code ENUM} type element. 190 * 191 * @implSpec This implementation calls {@code defaultAction}. 192 * 193 * @param e the element to visit 194 * @param p a visitor-specified parameter 195 * @return the result of {@code defaultAction} 196 */ 197 public R visitTypeAsEnum(TypeElement e, P p) { 198 return defaultAction(e, p); 199 } 200 201 /** 202 * Visits an {@code INTERFACE} type element. 203 * 204 * @implSpec This implementation calls {@code defaultAction}. 205 *. 206 * @param e the element to visit 207 * @param p a visitor-specified parameter 208 * @return the result of {@code defaultAction} 209 */ 210 public R visitTypeAsInterface(TypeElement e, P p) { 211 return defaultAction(e, p); 212 } 213 214 /** 215 * Visits a variable element 216 * 217 * @implSpec This implementation dispatches to the visit method for 218 * the specific {@linkplain ElementKind kind} of variable, {@code 219 * ENUM_CONSTANT}, {@code EXCEPTION_PARAMETER}, {@code FIELD}, 220 * {@code LOCAL_VARIABLE}, {@code PARAMETER}, or {@code RESOURCE_VARIABLE}. 221 * 222 * @param e {@inheritDoc} 223 * @param p {@inheritDoc} 224 * @return the result of the kind-specific visit method 225 */ 226 @Override 227 public R visitVariable(VariableElement e, P p) { 228 ElementKind k = e.getKind(); 229 switch(k) { 230 case ENUM_CONSTANT: 231 return visitVariableAsEnumConstant(e, p); 232 233 case EXCEPTION_PARAMETER: 234 return visitVariableAsExceptionParameter(e, p); 235 236 case FIELD: 237 return visitVariableAsField(e, p); 238 239 case LOCAL_VARIABLE: 240 return visitVariableAsLocalVariable(e, p); 241 242 case PARAMETER: 243 return visitVariableAsParameter(e, p); 244 245 case RESOURCE_VARIABLE: 246 return visitVariableAsResourceVariable(e, p); 247 248 default: 249 throw new AssertionError("Bad kind " + k + " for VariableElement" + e); 250 } 251 } 252 253 /** 254 * Visits an {@code ENUM_CONSTANT} variable element. 255 * 256 * @implSpec This implementation calls {@code defaultAction}. 257 *. 258 * @param e the element to visit 259 * @param p a visitor-specified parameter 260 * @return the result of {@code defaultAction} 261 */ 262 public R visitVariableAsEnumConstant(VariableElement e, P p) { 263 return defaultAction(e, p); 264 } 265 266 /** 267 * Visits an {@code EXCEPTION_PARAMETER} variable element. 268 * 269 * @implSpec This implementation calls {@code defaultAction}. 270 *. 271 * @param e the element to visit 272 * @param p a visitor-specified parameter 273 * @return the result of {@code defaultAction} 274 */ 275 public R visitVariableAsExceptionParameter(VariableElement e, P p) { 276 return defaultAction(e, p); 277 } 278 279 /** 280 * Visits a {@code FIELD} variable element. 281 * 282 * @implSpec This implementation calls {@code defaultAction}. 283 *. 284 * @param e the element to visit 285 * @param p a visitor-specified parameter 286 * @return the result of {@code defaultAction} 287 */ 288 public R visitVariableAsField(VariableElement e, P p) { 289 return defaultAction(e, p); 290 } 291 292 /** 293 * Visits a {@code LOCAL_VARIABLE} variable element. 294 * 295 * @implSpec This implementation calls {@code defaultAction}. 296 * 297 * @param e the element to visit 298 * @param p a visitor-specified parameter 299 * @return the result of {@code defaultAction} 300 */ 301 public R visitVariableAsLocalVariable(VariableElement e, P p) { 302 return defaultAction(e, p); 303 } 304 305 /** 306 * Visits a {@code PARAMETER} variable element. 307 * 308 * @implSpec This implementation calls {@code defaultAction}. 309 * 310 * @param e the element to visit 311 * @param p a visitor-specified parameter 312 * @return the result of {@code defaultAction} 313 */ 314 public R visitVariableAsParameter(VariableElement e, P p) { 315 return defaultAction(e, p); 316 } 317 318 /** 319 * Visits a {@code RESOURCE_VARIABLE} variable element. 320 * 321 * @implSpec This implementation calls {@code visitUnknown}. 322 * 323 * @param e the element to visit 324 * @param p a visitor-specified parameter 325 * @return the result of {@code visitUnknown} 326 * 327 * @since 1.7 328 */ 329 public R visitVariableAsResourceVariable(VariableElement e, P p) { 330 return visitUnknown(e, p); 331 } 332 333 /** 334 * {@inheritDoc} 335 * 336 * @implSpec This implementation dispatches to the visit method 337 * for the specific {@linkplain ElementKind kind} of executable, 338 * {@code CONSTRUCTOR}, {@code INSTANCE_INIT}, {@code METHOD}, or 339 * {@code STATIC_INIT}. 340 * 341 * @param e {@inheritDoc} 342 * @param p {@inheritDoc} 343 * @return the result of the kind-specific visit method 344 */ 345 @Override 346 public R visitExecutable(ExecutableElement e, P p) { 347 ElementKind k = e.getKind(); 348 switch(k) { 349 case CONSTRUCTOR: 350 return visitExecutableAsConstructor(e, p); 351 352 case INSTANCE_INIT: 353 return visitExecutableAsInstanceInit(e, p); 354 355 case METHOD: 356 return visitExecutableAsMethod(e, p); 357 358 case STATIC_INIT: 359 return visitExecutableAsStaticInit(e, p); 360 361 default: 362 throw new AssertionError("Bad kind " + k + " for ExecutableElement" + e); 363 } 364 } 365 366 /** 367 * Visits a {@code CONSTRUCTOR} executable element. 368 * 369 * @implSpec This implementation calls {@code defaultAction}. 370 * 371 * @param e the element to visit 372 * @param p a visitor-specified parameter 373 * @return the result of {@code defaultAction} 374 */ 375 public R visitExecutableAsConstructor(ExecutableElement e, P p) { 376 return defaultAction(e, p); 377 } 378 379 /** 380 * Visits an {@code INSTANCE_INIT} executable element. 381 * 382 * @implSpec This implementation calls {@code defaultAction}. 383 * 384 * @param e the element to visit 385 * @param p a visitor-specified parameter 386 * @return the result of {@code defaultAction} 387 */ 388 public R visitExecutableAsInstanceInit(ExecutableElement e, P p) { 389 return defaultAction(e, p); 390 } 391 392 /** 393 * Visits a {@code METHOD} executable element. 394 * 395 * @implSpec This implementation calls {@code defaultAction}. 396 * 397 * @param e the element to visit 398 * @param p a visitor-specified parameter 399 * @return the result of {@code defaultAction} 400 */ 401 public R visitExecutableAsMethod(ExecutableElement e, P p) { 402 return defaultAction(e, p); 403 } 404 405 /** 406 * Visits a {@code STATIC_INIT} executable element. 407 * 408 * @implSpec This implementation calls {@code defaultAction}. 409 * 410 * @param e the element to visit 411 * @param p a visitor-specified parameter 412 * @return the result of {@code defaultAction} 413 */ 414 public R visitExecutableAsStaticInit(ExecutableElement e, P p) { 415 return defaultAction(e, p); 416 } 417 418 /** 419 * {@inheritDoc} 420 * 421 * The element argument has kind {@code TYPE_PARAMETER}. 422 * 423 * @implSpec This implementation calls {@code defaultAction}. 424 * 425 * @param e {@inheritDoc} 426 * @param p {@inheritDoc} 427 * @return {@inheritDoc} 428 */ 429 @Override 430 public R visitTypeParameter(TypeParameterElement e, P p) { 431 assert e.getKind() == TYPE_PARAMETER: "Bad kind on TypeParameterElement"; 432 return defaultAction(e, p); 433 } 434 } |