Thu, 09 Oct 2008 16:07:38 +0100
6406133: JCDiagnostic.getMessage ignores locale argument
Summary: Compiler API should take into account locale settings
Reviewed-by: jjg
duke@1 | 1 | /* |
duke@1 | 2 | * Copyright 1999-2006 Sun Microsystems, Inc. All Rights Reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@1 | 7 | * published by the Free Software Foundation. Sun designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
duke@1 | 9 | * by Sun in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
duke@1 | 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@1 | 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@1 | 23 | * have any questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.tools.javac.tree; |
duke@1 | 27 | |
duke@1 | 28 | import com.sun.tools.javac.util.*; |
duke@1 | 29 | import com.sun.tools.javac.tree.JCTree.*; |
duke@1 | 30 | |
duke@1 | 31 | /** A subclass of Tree.Visitor, this class defines |
duke@1 | 32 | * a general tree translator pattern. Translation proceeds recursively in |
duke@1 | 33 | * left-to-right order down a tree, constructing translated nodes by |
duke@1 | 34 | * overwriting existing ones. There is one visitor method in this class |
duke@1 | 35 | * for every possible kind of tree node. To obtain a specific |
duke@1 | 36 | * translator, it suffices to override those visitor methods which |
duke@1 | 37 | * do some interesting work. The translator class itself takes care of all |
duke@1 | 38 | * navigational aspects. |
duke@1 | 39 | * |
duke@1 | 40 | * <p><b>This is NOT part of any API supported by Sun Microsystems. If |
duke@1 | 41 | * you write code that depends on this, you do so at your own risk. |
duke@1 | 42 | * This code and its internal interfaces are subject to change or |
duke@1 | 43 | * deletion without notice.</b> |
duke@1 | 44 | */ |
duke@1 | 45 | public class TreeTranslator extends JCTree.Visitor { |
duke@1 | 46 | |
duke@1 | 47 | /** Visitor result field: a tree |
duke@1 | 48 | */ |
duke@1 | 49 | protected JCTree result; |
duke@1 | 50 | |
duke@1 | 51 | /** Visitor method: Translate a single node. |
duke@1 | 52 | */ |
duke@1 | 53 | @SuppressWarnings("unchecked") |
duke@1 | 54 | public <T extends JCTree> T translate(T tree) { |
duke@1 | 55 | if (tree == null) { |
duke@1 | 56 | return null; |
duke@1 | 57 | } else { |
duke@1 | 58 | tree.accept(this); |
duke@1 | 59 | JCTree result = this.result; |
duke@1 | 60 | this.result = null; |
duke@1 | 61 | return (T)result; // XXX cast |
duke@1 | 62 | } |
duke@1 | 63 | } |
duke@1 | 64 | |
duke@1 | 65 | /** Visitor method: translate a list of nodes. |
duke@1 | 66 | */ |
duke@1 | 67 | public <T extends JCTree> List<T> translate(List<T> trees) { |
duke@1 | 68 | if (trees == null) return null; |
duke@1 | 69 | for (List<T> l = trees; l.nonEmpty(); l = l.tail) |
duke@1 | 70 | l.head = translate(l.head); |
duke@1 | 71 | return trees; |
duke@1 | 72 | } |
duke@1 | 73 | |
duke@1 | 74 | /** Visitor method: translate a list of variable definitions. |
duke@1 | 75 | */ |
duke@1 | 76 | public List<JCVariableDecl> translateVarDefs(List<JCVariableDecl> trees) { |
duke@1 | 77 | for (List<JCVariableDecl> l = trees; l.nonEmpty(); l = l.tail) |
duke@1 | 78 | l.head = translate(l.head); |
duke@1 | 79 | return trees; |
duke@1 | 80 | } |
duke@1 | 81 | |
duke@1 | 82 | /** Visitor method: translate a list of type parameters. |
duke@1 | 83 | */ |
duke@1 | 84 | public List<JCTypeParameter> translateTypeParams(List<JCTypeParameter> trees) { |
duke@1 | 85 | for (List<JCTypeParameter> l = trees; l.nonEmpty(); l = l.tail) |
duke@1 | 86 | l.head = translate(l.head); |
duke@1 | 87 | return trees; |
duke@1 | 88 | } |
duke@1 | 89 | |
duke@1 | 90 | /** Visitor method: translate a list of case parts of switch statements. |
duke@1 | 91 | */ |
duke@1 | 92 | public List<JCCase> translateCases(List<JCCase> trees) { |
duke@1 | 93 | for (List<JCCase> l = trees; l.nonEmpty(); l = l.tail) |
duke@1 | 94 | l.head = translate(l.head); |
duke@1 | 95 | return trees; |
duke@1 | 96 | } |
duke@1 | 97 | |
duke@1 | 98 | /** Visitor method: translate a list of catch clauses in try statements. |
duke@1 | 99 | */ |
duke@1 | 100 | public List<JCCatch> translateCatchers(List<JCCatch> trees) { |
duke@1 | 101 | for (List<JCCatch> l = trees; l.nonEmpty(); l = l.tail) |
duke@1 | 102 | l.head = translate(l.head); |
duke@1 | 103 | return trees; |
duke@1 | 104 | } |
duke@1 | 105 | |
duke@1 | 106 | /** Visitor method: translate a list of catch clauses in try statements. |
duke@1 | 107 | */ |
duke@1 | 108 | public List<JCAnnotation> translateAnnotations(List<JCAnnotation> trees) { |
duke@1 | 109 | for (List<JCAnnotation> l = trees; l.nonEmpty(); l = l.tail) |
duke@1 | 110 | l.head = translate(l.head); |
duke@1 | 111 | return trees; |
duke@1 | 112 | } |
duke@1 | 113 | |
duke@1 | 114 | /* *************************************************************************** |
duke@1 | 115 | * Visitor methods |
duke@1 | 116 | ****************************************************************************/ |
duke@1 | 117 | |
duke@1 | 118 | public void visitTopLevel(JCCompilationUnit tree) { |
duke@1 | 119 | tree.pid = translate(tree.pid); |
duke@1 | 120 | tree.defs = translate(tree.defs); |
duke@1 | 121 | result = tree; |
duke@1 | 122 | } |
duke@1 | 123 | |
duke@1 | 124 | public void visitImport(JCImport tree) { |
duke@1 | 125 | tree.qualid = translate(tree.qualid); |
duke@1 | 126 | result = tree; |
duke@1 | 127 | } |
duke@1 | 128 | |
duke@1 | 129 | public void visitClassDef(JCClassDecl tree) { |
duke@1 | 130 | tree.mods = translate(tree.mods); |
duke@1 | 131 | tree.typarams = translateTypeParams(tree.typarams); |
duke@1 | 132 | tree.extending = translate(tree.extending); |
duke@1 | 133 | tree.implementing = translate(tree.implementing); |
duke@1 | 134 | tree.defs = translate(tree.defs); |
duke@1 | 135 | result = tree; |
duke@1 | 136 | } |
duke@1 | 137 | |
duke@1 | 138 | public void visitMethodDef(JCMethodDecl tree) { |
duke@1 | 139 | tree.mods = translate(tree.mods); |
duke@1 | 140 | tree.restype = translate(tree.restype); |
duke@1 | 141 | tree.typarams = translateTypeParams(tree.typarams); |
duke@1 | 142 | tree.params = translateVarDefs(tree.params); |
duke@1 | 143 | tree.thrown = translate(tree.thrown); |
duke@1 | 144 | tree.body = translate(tree.body); |
duke@1 | 145 | result = tree; |
duke@1 | 146 | } |
duke@1 | 147 | |
duke@1 | 148 | public void visitVarDef(JCVariableDecl tree) { |
duke@1 | 149 | tree.mods = translate(tree.mods); |
duke@1 | 150 | tree.vartype = translate(tree.vartype); |
duke@1 | 151 | tree.init = translate(tree.init); |
duke@1 | 152 | result = tree; |
duke@1 | 153 | } |
duke@1 | 154 | |
duke@1 | 155 | public void visitSkip(JCSkip tree) { |
duke@1 | 156 | result = tree; |
duke@1 | 157 | } |
duke@1 | 158 | |
duke@1 | 159 | public void visitBlock(JCBlock tree) { |
duke@1 | 160 | tree.stats = translate(tree.stats); |
duke@1 | 161 | result = tree; |
duke@1 | 162 | } |
duke@1 | 163 | |
duke@1 | 164 | public void visitDoLoop(JCDoWhileLoop tree) { |
duke@1 | 165 | tree.body = translate(tree.body); |
duke@1 | 166 | tree.cond = translate(tree.cond); |
duke@1 | 167 | result = tree; |
duke@1 | 168 | } |
duke@1 | 169 | |
duke@1 | 170 | public void visitWhileLoop(JCWhileLoop tree) { |
duke@1 | 171 | tree.cond = translate(tree.cond); |
duke@1 | 172 | tree.body = translate(tree.body); |
duke@1 | 173 | result = tree; |
duke@1 | 174 | } |
duke@1 | 175 | |
duke@1 | 176 | public void visitForLoop(JCForLoop tree) { |
duke@1 | 177 | tree.init = translate(tree.init); |
duke@1 | 178 | tree.cond = translate(tree.cond); |
duke@1 | 179 | tree.step = translate(tree.step); |
duke@1 | 180 | tree.body = translate(tree.body); |
duke@1 | 181 | result = tree; |
duke@1 | 182 | } |
duke@1 | 183 | |
duke@1 | 184 | public void visitForeachLoop(JCEnhancedForLoop tree) { |
duke@1 | 185 | tree.var = translate(tree.var); |
duke@1 | 186 | tree.expr = translate(tree.expr); |
duke@1 | 187 | tree.body = translate(tree.body); |
duke@1 | 188 | result = tree; |
duke@1 | 189 | } |
duke@1 | 190 | |
duke@1 | 191 | public void visitLabelled(JCLabeledStatement tree) { |
duke@1 | 192 | tree.body = translate(tree.body); |
duke@1 | 193 | result = tree; |
duke@1 | 194 | } |
duke@1 | 195 | |
duke@1 | 196 | public void visitSwitch(JCSwitch tree) { |
duke@1 | 197 | tree.selector = translate(tree.selector); |
duke@1 | 198 | tree.cases = translateCases(tree.cases); |
duke@1 | 199 | result = tree; |
duke@1 | 200 | } |
duke@1 | 201 | |
duke@1 | 202 | public void visitCase(JCCase tree) { |
duke@1 | 203 | tree.pat = translate(tree.pat); |
duke@1 | 204 | tree.stats = translate(tree.stats); |
duke@1 | 205 | result = tree; |
duke@1 | 206 | } |
duke@1 | 207 | |
duke@1 | 208 | public void visitSynchronized(JCSynchronized tree) { |
duke@1 | 209 | tree.lock = translate(tree.lock); |
duke@1 | 210 | tree.body = translate(tree.body); |
duke@1 | 211 | result = tree; |
duke@1 | 212 | } |
duke@1 | 213 | |
duke@1 | 214 | public void visitTry(JCTry tree) { |
duke@1 | 215 | tree.body = translate(tree.body); |
duke@1 | 216 | tree.catchers = translateCatchers(tree.catchers); |
duke@1 | 217 | tree.finalizer = translate(tree.finalizer); |
duke@1 | 218 | result = tree; |
duke@1 | 219 | } |
duke@1 | 220 | |
duke@1 | 221 | public void visitCatch(JCCatch tree) { |
duke@1 | 222 | tree.param = translate(tree.param); |
duke@1 | 223 | tree.body = translate(tree.body); |
duke@1 | 224 | result = tree; |
duke@1 | 225 | } |
duke@1 | 226 | |
duke@1 | 227 | public void visitConditional(JCConditional tree) { |
duke@1 | 228 | tree.cond = translate(tree.cond); |
duke@1 | 229 | tree.truepart = translate(tree.truepart); |
duke@1 | 230 | tree.falsepart = translate(tree.falsepart); |
duke@1 | 231 | result = tree; |
duke@1 | 232 | } |
duke@1 | 233 | |
duke@1 | 234 | public void visitIf(JCIf tree) { |
duke@1 | 235 | tree.cond = translate(tree.cond); |
duke@1 | 236 | tree.thenpart = translate(tree.thenpart); |
duke@1 | 237 | tree.elsepart = translate(tree.elsepart); |
duke@1 | 238 | result = tree; |
duke@1 | 239 | } |
duke@1 | 240 | |
duke@1 | 241 | public void visitExec(JCExpressionStatement tree) { |
duke@1 | 242 | tree.expr = translate(tree.expr); |
duke@1 | 243 | result = tree; |
duke@1 | 244 | } |
duke@1 | 245 | |
duke@1 | 246 | public void visitBreak(JCBreak tree) { |
duke@1 | 247 | result = tree; |
duke@1 | 248 | } |
duke@1 | 249 | |
duke@1 | 250 | public void visitContinue(JCContinue tree) { |
duke@1 | 251 | result = tree; |
duke@1 | 252 | } |
duke@1 | 253 | |
duke@1 | 254 | public void visitReturn(JCReturn tree) { |
duke@1 | 255 | tree.expr = translate(tree.expr); |
duke@1 | 256 | result = tree; |
duke@1 | 257 | } |
duke@1 | 258 | |
duke@1 | 259 | public void visitThrow(JCThrow tree) { |
duke@1 | 260 | tree.expr = translate(tree.expr); |
duke@1 | 261 | result = tree; |
duke@1 | 262 | } |
duke@1 | 263 | |
duke@1 | 264 | public void visitAssert(JCAssert tree) { |
duke@1 | 265 | tree.cond = translate(tree.cond); |
duke@1 | 266 | tree.detail = translate(tree.detail); |
duke@1 | 267 | result = tree; |
duke@1 | 268 | } |
duke@1 | 269 | |
duke@1 | 270 | public void visitApply(JCMethodInvocation tree) { |
duke@1 | 271 | tree.meth = translate(tree.meth); |
duke@1 | 272 | tree.args = translate(tree.args); |
duke@1 | 273 | result = tree; |
duke@1 | 274 | } |
duke@1 | 275 | |
duke@1 | 276 | public void visitNewClass(JCNewClass tree) { |
duke@1 | 277 | tree.encl = translate(tree.encl); |
duke@1 | 278 | tree.clazz = translate(tree.clazz); |
duke@1 | 279 | tree.args = translate(tree.args); |
duke@1 | 280 | tree.def = translate(tree.def); |
duke@1 | 281 | result = tree; |
duke@1 | 282 | } |
duke@1 | 283 | |
duke@1 | 284 | public void visitNewArray(JCNewArray tree) { |
duke@1 | 285 | tree.elemtype = translate(tree.elemtype); |
duke@1 | 286 | tree.dims = translate(tree.dims); |
duke@1 | 287 | tree.elems = translate(tree.elems); |
duke@1 | 288 | result = tree; |
duke@1 | 289 | } |
duke@1 | 290 | |
duke@1 | 291 | public void visitParens(JCParens tree) { |
duke@1 | 292 | tree.expr = translate(tree.expr); |
duke@1 | 293 | result = tree; |
duke@1 | 294 | } |
duke@1 | 295 | |
duke@1 | 296 | public void visitAssign(JCAssign tree) { |
duke@1 | 297 | tree.lhs = translate(tree.lhs); |
duke@1 | 298 | tree.rhs = translate(tree.rhs); |
duke@1 | 299 | result = tree; |
duke@1 | 300 | } |
duke@1 | 301 | |
duke@1 | 302 | public void visitAssignop(JCAssignOp tree) { |
duke@1 | 303 | tree.lhs = translate(tree.lhs); |
duke@1 | 304 | tree.rhs = translate(tree.rhs); |
duke@1 | 305 | result = tree; |
duke@1 | 306 | } |
duke@1 | 307 | |
duke@1 | 308 | public void visitUnary(JCUnary tree) { |
duke@1 | 309 | tree.arg = translate(tree.arg); |
duke@1 | 310 | result = tree; |
duke@1 | 311 | } |
duke@1 | 312 | |
duke@1 | 313 | public void visitBinary(JCBinary tree) { |
duke@1 | 314 | tree.lhs = translate(tree.lhs); |
duke@1 | 315 | tree.rhs = translate(tree.rhs); |
duke@1 | 316 | result = tree; |
duke@1 | 317 | } |
duke@1 | 318 | |
duke@1 | 319 | public void visitTypeCast(JCTypeCast tree) { |
duke@1 | 320 | tree.clazz = translate(tree.clazz); |
duke@1 | 321 | tree.expr = translate(tree.expr); |
duke@1 | 322 | result = tree; |
duke@1 | 323 | } |
duke@1 | 324 | |
duke@1 | 325 | public void visitTypeTest(JCInstanceOf tree) { |
duke@1 | 326 | tree.expr = translate(tree.expr); |
duke@1 | 327 | tree.clazz = translate(tree.clazz); |
duke@1 | 328 | result = tree; |
duke@1 | 329 | } |
duke@1 | 330 | |
duke@1 | 331 | public void visitIndexed(JCArrayAccess tree) { |
duke@1 | 332 | tree.indexed = translate(tree.indexed); |
duke@1 | 333 | tree.index = translate(tree.index); |
duke@1 | 334 | result = tree; |
duke@1 | 335 | } |
duke@1 | 336 | |
duke@1 | 337 | public void visitSelect(JCFieldAccess tree) { |
duke@1 | 338 | tree.selected = translate(tree.selected); |
duke@1 | 339 | result = tree; |
duke@1 | 340 | } |
duke@1 | 341 | |
duke@1 | 342 | public void visitIdent(JCIdent tree) { |
duke@1 | 343 | result = tree; |
duke@1 | 344 | } |
duke@1 | 345 | |
duke@1 | 346 | public void visitLiteral(JCLiteral tree) { |
duke@1 | 347 | result = tree; |
duke@1 | 348 | } |
duke@1 | 349 | |
duke@1 | 350 | public void visitTypeIdent(JCPrimitiveTypeTree tree) { |
duke@1 | 351 | result = tree; |
duke@1 | 352 | } |
duke@1 | 353 | |
duke@1 | 354 | public void visitTypeArray(JCArrayTypeTree tree) { |
duke@1 | 355 | tree.elemtype = translate(tree.elemtype); |
duke@1 | 356 | result = tree; |
duke@1 | 357 | } |
duke@1 | 358 | |
duke@1 | 359 | public void visitTypeApply(JCTypeApply tree) { |
duke@1 | 360 | tree.clazz = translate(tree.clazz); |
duke@1 | 361 | tree.arguments = translate(tree.arguments); |
duke@1 | 362 | result = tree; |
duke@1 | 363 | } |
duke@1 | 364 | |
duke@1 | 365 | public void visitTypeParameter(JCTypeParameter tree) { |
duke@1 | 366 | tree.bounds = translate(tree.bounds); |
duke@1 | 367 | result = tree; |
duke@1 | 368 | } |
duke@1 | 369 | |
duke@1 | 370 | @Override |
duke@1 | 371 | public void visitWildcard(JCWildcard tree) { |
duke@1 | 372 | tree.kind = translate(tree.kind); |
duke@1 | 373 | tree.inner = translate(tree.inner); |
duke@1 | 374 | result = tree; |
duke@1 | 375 | } |
duke@1 | 376 | |
duke@1 | 377 | @Override |
duke@1 | 378 | public void visitTypeBoundKind(TypeBoundKind tree) { |
duke@1 | 379 | result = tree; |
duke@1 | 380 | } |
duke@1 | 381 | |
duke@1 | 382 | public void visitErroneous(JCErroneous tree) { |
duke@1 | 383 | result = tree; |
duke@1 | 384 | } |
duke@1 | 385 | |
duke@1 | 386 | public void visitLetExpr(LetExpr tree) { |
duke@1 | 387 | tree.defs = translateVarDefs(tree.defs); |
duke@1 | 388 | tree.expr = translate(tree.expr); |
duke@1 | 389 | result = tree; |
duke@1 | 390 | } |
duke@1 | 391 | |
duke@1 | 392 | public void visitModifiers(JCModifiers tree) { |
duke@1 | 393 | tree.annotations = translateAnnotations(tree.annotations); |
duke@1 | 394 | result = tree; |
duke@1 | 395 | } |
duke@1 | 396 | |
duke@1 | 397 | public void visitAnnotation(JCAnnotation tree) { |
duke@1 | 398 | tree.annotationType = translate(tree.annotationType); |
duke@1 | 399 | tree.args = translate(tree.args); |
duke@1 | 400 | result = tree; |
duke@1 | 401 | } |
duke@1 | 402 | |
duke@1 | 403 | public void visitTree(JCTree tree) { |
duke@1 | 404 | throw new AssertionError(tree); |
duke@1 | 405 | } |
duke@1 | 406 | } |