1 /* 2 * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.mirror.util; 27 28 import com.sun.mirror.declaration.*; 29 30 /** 31 * A visitor for declarations that scans declarations contained within 32 * the given declaration. For example, when visiting a class, the 33 * methods, fields, constructors, and nested types of the class are 34 * also visited. 35 * 36 * <p> To control the processing done on a declaration, users of this 37 * class pass in their own visitors for pre and post processing. The 38 * preprocessing visitor is called before the contained declarations 39 * are scanned; the postprocessing visitor is called after the 40 * contained declarations are scanned. 41 * 42 * @deprecated All components of this API have been superseded by the 43 * standardized annotation processing API. The replacement for the 44 * functionality of this class is {@link 45 * javax.lang.model.util.ElementScanner6}. 46 * 47 * @author Joseph D. Darcy 48 * @author Scott Seligman 49 * @since 1.5 50 */ 51 @Deprecated 52 @SuppressWarnings("deprecation") 53 class DeclarationScanner implements DeclarationVisitor { 54 protected DeclarationVisitor pre; 55 protected DeclarationVisitor post; 56 57 DeclarationScanner(DeclarationVisitor pre, DeclarationVisitor post) { 58 this.pre = pre; 59 this.post = post; 60 } 61 62 /** 63 * Visits a declaration. 64 * 65 * @param d the declaration to visit 66 */ 67 public void visitDeclaration(Declaration d) { 68 d.accept(pre); 69 d.accept(post); 70 } 71 72 /** 73 * Visits a package declaration. 74 * 75 * @param d the declaration to visit 76 */ 77 public void visitPackageDeclaration(PackageDeclaration d) { 78 d.accept(pre); 79 80 for(ClassDeclaration classDecl: d.getClasses()) { 81 classDecl.accept(this); 82 } 83 84 for(InterfaceDeclaration interfaceDecl: d.getInterfaces()) { 85 interfaceDecl.accept(this); 86 } 87 88 d.accept(post); 89 } 90 91 /** 92 * Visits a member or constructor declaration. 93 * 94 * @param d the declaration to visit 95 */ 96 public void visitMemberDeclaration(MemberDeclaration d) { 97 visitDeclaration(d); 98 } 99 100 /** 101 * Visits a type declaration. 102 * 103 * @param d the declaration to visit 104 */ 105 public void visitTypeDeclaration(TypeDeclaration d) { 106 d.accept(pre); 107 108 for(TypeParameterDeclaration tpDecl: d.getFormalTypeParameters()) { 109 tpDecl.accept(this); 110 } 111 112 for(FieldDeclaration fieldDecl: d.getFields()) { 113 fieldDecl.accept(this); 114 } 115 116 for(MethodDeclaration methodDecl: d.getMethods()) { 117 methodDecl.accept(this); 118 } 119 120 for(TypeDeclaration typeDecl: d.getNestedTypes()) { 121 typeDecl.accept(this); 122 } 123 124 d.accept(post); 125 } 126 127 /** 128 * Visits a class declaration. 129 * 130 * @param d the declaration to visit 131 */ 132 public void visitClassDeclaration(ClassDeclaration d) { 133 d.accept(pre); 134 135 for(TypeParameterDeclaration tpDecl: d.getFormalTypeParameters()) { 136 tpDecl.accept(this); 137 } 138 139 for(FieldDeclaration fieldDecl: d.getFields()) { 140 fieldDecl.accept(this); 141 } 142 143 for(MethodDeclaration methodDecl: d.getMethods()) { 144 methodDecl.accept(this); 145 } 146 147 for(TypeDeclaration typeDecl: d.getNestedTypes()) { 148 typeDecl.accept(this); 149 } 150 151 for(ConstructorDeclaration ctorDecl: d.getConstructors()) { 152 ctorDecl.accept(this); 153 } 154 155 d.accept(post); 156 } 157 158 /** 159 * Visits an enum declaration. 160 * 161 * @param d the declaration to visit 162 */ 163 public void visitEnumDeclaration(EnumDeclaration d) { 164 visitClassDeclaration(d); 165 } 166 167 /** 168 * Visits an interface declaration. 169 * 170 * @param d the declaration to visit 171 */ 172 public void visitInterfaceDeclaration(InterfaceDeclaration d) { 173 visitTypeDeclaration(d); 174 } 175 176 /** 177 * Visits an annotation type declaration. 178 * 179 * @param d the declaration to visit 180 */ 181 public void visitAnnotationTypeDeclaration(AnnotationTypeDeclaration d) { 182 visitInterfaceDeclaration(d); 183 } 184 185 /** 186 * Visits a field declaration. 187 * 188 * @param d the declaration to visit 189 */ 190 public void visitFieldDeclaration(FieldDeclaration d) { 191 visitMemberDeclaration(d); 192 } 193 194 /** 195 * Visits an enum constant declaration. 196 * 197 * @param d the declaration to visit 198 */ 199 public void visitEnumConstantDeclaration(EnumConstantDeclaration d) { 200 visitFieldDeclaration(d); 201 } 202 203 /** 204 * Visits a method or constructor declaration. 205 * 206 * @param d the declaration to visit 207 */ 208 public void visitExecutableDeclaration(ExecutableDeclaration d) { 209 d.accept(pre); 210 211 for(TypeParameterDeclaration tpDecl: d.getFormalTypeParameters()) { 212 tpDecl.accept(this); 213 } 214 215 for(ParameterDeclaration pDecl: d.getParameters()) { 216 pDecl.accept(this); 217 } 218 219 d.accept(post); 220 } 221 222 /** 223 * Visits a constructor declaration. 224 * 225 * @param d the declaration to visit 226 */ 227 public void visitConstructorDeclaration(ConstructorDeclaration d) { 228 visitExecutableDeclaration(d); 229 } 230 231 /** 232 * Visits a method declaration. 233 * 234 * @param d the declaration to visit 235 */ 236 public void visitMethodDeclaration(MethodDeclaration d) { 237 visitExecutableDeclaration(d); 238 } 239 240 /** 241 * Visits an annotation type element declaration. 242 * 243 * @param d the declaration to visit 244 */ 245 public void visitAnnotationTypeElementDeclaration( 246 AnnotationTypeElementDeclaration d) { 247 visitMethodDeclaration(d); 248 } 249 250 /** 251 * Visits a parameter declaration. 252 * 253 * @param d the declaration to visit 254 */ 255 public void visitParameterDeclaration(ParameterDeclaration d) { 256 visitDeclaration(d); 257 } 258 259 /** 260 * Visits a type parameter declaration. 261 * 262 * @param d the declaration to visit 263 */ 264 public void visitTypeParameterDeclaration(TypeParameterDeclaration d) { 265 visitDeclaration(d); 266 } 267 }