Mon, 03 Jun 2013 17:09:26 -0700
8006615: [doclint] move remaining messages into resource bundle
Reviewed-by: mcimadamore, vromero
1 /*
2 * Copyright (c) 1999, 2012, 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 */
26 package com.sun.tools.javac.comp;
28 import com.sun.tools.javac.tree.*;
29 import java.util.Iterator;
30 import java.util.NoSuchElementException;
32 /** A class for environments, instances of which are passed as
33 * arguments to tree visitors. Environments refer to important ancestors
34 * of the subtree that's currently visited, such as the enclosing method,
35 * the enclosing class, or the enclosing toplevel node. They also contain
36 * a generic component, represented as a type parameter, to carry further
37 * information specific to individual passes.
38 *
39 * <p><b>This is NOT part of any supported API.
40 * If you write code that depends on this, you do so at your own risk.
41 * This code and its internal interfaces are subject to change or
42 * deletion without notice.</b>
43 */
44 public class Env<A> implements Iterable<Env<A>> {
46 /** The next enclosing environment.
47 */
48 public Env<A> next;
50 /** The environment enclosing the current class.
51 */
52 public Env<A> outer;
54 /** The tree with which this environment is associated.
55 */
56 public JCTree tree;
58 /** The enclosing toplevel tree.
59 */
60 public JCTree.JCCompilationUnit toplevel;
62 /** The next enclosing class definition.
63 */
64 public JCTree.JCClassDecl enclClass;
66 /** The next enclosing method definition.
67 */
68 public JCTree.JCMethodDecl enclMethod;
70 /** A generic field for further information.
71 */
72 public A info;
74 /** Is this an environment for evaluating a base clause?
75 */
76 public boolean baseClause = false;
78 /** Create an outermost environment for a given (toplevel)tree,
79 * with a given info field.
80 */
81 public Env(JCTree tree, A info) {
82 this.next = null;
83 this.outer = null;
84 this.tree = tree;
85 this.toplevel = null;
86 this.enclClass = null;
87 this.enclMethod = null;
88 this.info = info;
89 }
91 /** Duplicate this environment, updating with given tree and info,
92 * and copying all other fields.
93 */
94 public Env<A> dup(JCTree tree, A info) {
95 return dupto(new Env<A>(tree, info));
96 }
98 /** Duplicate this environment into a given Environment,
99 * using its tree and info, and copying all other fields.
100 */
101 public Env<A> dupto(Env<A> that) {
102 that.next = this;
103 that.outer = this.outer;
104 that.toplevel = this.toplevel;
105 that.enclClass = this.enclClass;
106 that.enclMethod = this.enclMethod;
107 return that;
108 }
110 /** Duplicate this environment, updating with given tree,
111 * and copying all other fields.
112 */
113 public Env<A> dup(JCTree tree) {
114 return dup(tree, this.info);
115 }
117 /** Return closest enclosing environment which points to a tree with given tag.
118 */
119 public Env<A> enclosing(JCTree.Tag tag) {
120 Env<A> env1 = this;
121 while (env1 != null && !env1.tree.hasTag(tag)) env1 = env1.next;
122 return env1;
123 }
125 @Override
126 public String toString() {
127 return "Env[" + info + (outer == null ? "" : ",outer=" + outer) + "]";
128 }
130 public Iterator<Env<A>> iterator() {
131 return new Iterator<Env<A>>() {
132 Env<A> next = Env.this;
133 public boolean hasNext() {
134 return next.outer != null;
135 }
136 public Env<A> next() {
137 if (hasNext()) {
138 Env<A> current = next;
139 next = current.outer;
140 return current;
141 }
142 throw new NoSuchElementException();
144 }
145 public void remove() {
146 throw new UnsupportedOperationException();
147 }
148 };
149 }
150 }