Tue, 11 Aug 2009 01:13:14 +0100
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
Summary: javac should warn/complain about identifiers with the same name as synthetic symbol
Reviewed-by: jjg
1 /*
2 * Copyright 2000-2003 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
26 package com.sun.tools.javadoc;
28 import static com.sun.tools.javac.code.Flags.*;
30 /**
31 * A class whose instances are filters over Modifier bits.
32 * Filtering is done by returning boolean values.
33 * Classes, methods and fields can be filtered, or filtering
34 * can be done directly on modifier bits.
35 * @see com.sun.tools.javac.code.Flags;
36 * @author Robert Field
37 */
39 public class ModifierFilter {
41 /**
42 * Package private access.
43 * A "pseudo-" modifier bit that can be used in the
44 * constructors of this class to specify package private
45 * access. This is needed since there is no Modifier.PACKAGE.
46 */
47 public static final long PACKAGE = 0x8000000000000000L;
49 /**
50 * All access modifiers.
51 * A short-hand set of modifier bits that can be used in the
52 * constructors of this class to specify all access modifiers,
53 * Same as PRIVATE | PROTECTED | PUBLIC | PACKAGE.
54 */
55 public static final long ALL_ACCESS =
56 PRIVATE | PROTECTED | PUBLIC | PACKAGE;
58 private long oneOf;
59 private long must;
60 private long cannot;
62 private static final int ACCESS_BITS = PRIVATE | PROTECTED | PUBLIC;
64 /**
65 * Constructor - Specify a filter.
66 *
67 * @param oneOf If zero, everything passes the filter.
68 * If non-zero, at least one of the specified
69 * bits must be on in the modifier bits to
70 * pass the filter.
71 */
72 public ModifierFilter(long oneOf) {
73 this(oneOf, 0, 0);
74 }
76 /**
77 * Constructor - Specify a filter.
78 * For example, the filter below will only pass synchronized
79 * methods that are private or package private access and are
80 * not native or static.
81 * <pre>
82 * ModifierFilter( Modifier.PRIVATE | ModifierFilter.PACKAGE,
83 * Modifier.SYNCHRONIZED,
84 * Modifier.NATIVE | Modifier.STATIC)
85 * </pre><p>
86 * Each of the three arguments must either be
87 * zero or the or'ed combination of the bits specified in the
88 * class Modifier or this class. During filtering, these values
89 * are compared against the modifier bits as follows:
90 *
91 * @param oneOf If zero, ignore this argument.
92 * If non-zero, at least one of the bits must be on.
93 * @param must All bits specified must be on.
94 * @param cannot None of the bits specified can be on.
95 */
96 public ModifierFilter(long oneOf, long must, long cannot) {
97 this.oneOf = oneOf;
98 this.must = must;
99 this.cannot = cannot;
100 }
102 /**
103 * Filter on modifier bits.
104 *
105 * @param modifierBits Bits as specified in the Modifier class
106 *
107 * @return Whether the modifierBits pass this filter.
108 */
109 public boolean checkModifier(int modifierBits) {
110 // Add in the "pseudo-" modifier bit PACKAGE, if needed
111 long fmod = ((modifierBits & ACCESS_BITS) == 0) ?
112 modifierBits | PACKAGE :
113 modifierBits;
114 return ((oneOf == 0) || ((oneOf & fmod) != 0)) &&
115 ((must & fmod) == must) &&
116 ((cannot & fmod) == 0);
117 }
119 } // end ModifierFilter