001    /* Copyright (c) 2005-2008, Torbjorn Ekman
002     * All rights reserved.
003     *
004     * Redistribution and use in source and binary forms, with or without
005     * modification, are permitted provided that the following conditions are met:
006     *
007     * 1. Redistributions of source code must retain the above copyright notice,
008     * this list of conditions and the following disclaimer.
009     *
010     * 2. Redistributions in binary form must reproduce the above copyright notice,
011     * this list of conditions and the following disclaimer in the documentation
012     * and/or other materials provided with the distribution.
013     *
014     * 3. Neither the name of the copyright holder nor the names of its
015     * contributors may be used to endorse or promote products derived from this
016     * software without specific prior written permission.
017     *
018     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020     * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021     * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
022     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
024     * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
025     * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
026     * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
027     * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
028     * POSSIBILITY OF SUCH DAMAGE.
029     */
030    
031    aspect Flags {
032      public static final int Modifiers.ACC_PUBLIC       = 0x0001; // class field method
033      public static final int Modifiers.ACC_PRIVATE      = 0x0002; //       field method
034      public static final int Modifiers.ACC_PROTECTED    = 0x0004; //       field method
035      public static final int Modifiers.ACC_STATIC       = 0x0008; //       field method
036      public static final int Modifiers.ACC_FINAL        = 0x0010; // class field method
037      public static final int Modifiers.ACC_SYNCHRONIZED = 0x0020; //             method
038      public static final int Modifiers.ACC_SUPER        = 0x0020; // class
039      public static final int Modifiers.ACC_VOLATILE     = 0x0040; //       field
040      public static final int Modifiers.ACC_TRANSIENT    = 0x0080; //       field
041      public static final int Modifiers.ACC_NATIVE       = 0x0100; //             method
042      public static final int Modifiers.ACC_INTERFACE    = 0x0200; // class
043      public static final int Modifiers.ACC_ABSTRACT     = 0x0400; // class       method
044      public static final int Modifiers.ACC_SYNTHETIC    = 0x1000; //       field method
045      public static final int Modifiers.ACC_STRICT       = 0x0800; //             method
046    
047    
048      // mangle modifiers for nested types
049      public int TypeDecl.mangledFlags(int flags) {
050        boolean privateFlag = (flags & Modifiers.ACC_PRIVATE) != 0;
051        boolean protectedFlag = (flags & Modifiers.ACC_PROTECTED) != 0;
052        flags &= ~ Modifiers.ACC_PRIVATE;
053        flags &= ~ Modifiers.ACC_PROTECTED;
054        if (protectedFlag) {
055          flags |= Modifiers.ACC_PUBLIC;
056        }
057        return flags;
058      }
059    
060    
061    
062      syn lazy int MethodDecl.flags() {
063        int res = 0;
064        if (isPublic()) {
065          res |= Modifiers.ACC_PUBLIC;
066        }
067        if (isPrivate()) {
068          res |= Modifiers.ACC_PRIVATE;
069        }
070        if (isProtected()) {
071          res |= Modifiers.ACC_PROTECTED;
072        }
073        if (isStatic()) {
074          res |= Modifiers.ACC_STATIC;
075        }
076        if (isFinal()) {
077          res |= Modifiers.ACC_FINAL;
078        }
079        if (isSynchronized()) {
080          res |= Modifiers.ACC_SYNCHRONIZED;
081        }
082        if (isNative()) {
083          res |= Modifiers.ACC_NATIVE;
084        }
085        if (isAbstract()) {
086          res |= Modifiers.ACC_ABSTRACT;
087        }
088        if (isStrictfp() || (hostType().isStrictfp() && !hostType().isInterfaceDecl())) {
089          res |= Modifiers.ACC_STRICT;
090        }
091        return res;
092      }
093    
094      syn lazy int ConstructorDecl.flags() {
095        int res = 0;
096        if (isPublic()) {
097          res |= Modifiers.ACC_PUBLIC;
098        }
099        if (isPrivate()) {
100          res |= Modifiers.ACC_PRIVATE;
101        }
102        if (isProtected()) {
103          res |= Modifiers.ACC_PROTECTED;
104        }
105        //if (isSynchronized()) res |= Modifiers.ACC_SYNCHRONIZED;
106        //if (isStrictfp()) res |= Modifiers.ACC_STRICT;
107        return res;
108      }
109    
110      syn lazy int TypeDecl.flags() {
111        int res = 0;
112        if (isPublic()) {
113          res |= Modifiers.ACC_PUBLIC;
114        }
115        if (isPrivate()) {
116          res |= Modifiers.ACC_PRIVATE;
117        }
118        if (isProtected()) {
119          res |= Modifiers.ACC_PROTECTED;
120        }
121        if (isStatic()) {
122          res |= Modifiers.ACC_STATIC;
123        }
124        if (isFinal()) {
125          res |= Modifiers.ACC_FINAL;
126        }
127        // ACC_INTERFACE handled in InterfaceDecl
128        if (isAbstract()) {
129          res |= Modifiers.ACC_ABSTRACT;
130        }
131        return res;
132      }
133    
134      syn lazy int FieldDeclaration.flags() {
135        int res = 0;
136        if (isPublic()) {
137          res |= Modifiers.ACC_PUBLIC;
138        }
139        if (isPrivate()) {
140          res |= Modifiers.ACC_PRIVATE;
141        }
142        if (isProtected()) {
143          res |= Modifiers.ACC_PROTECTED;
144        }
145        if (isStatic()) {
146          res |= Modifiers.ACC_STATIC;
147        }
148        if (isFinal()) {
149          res |= Modifiers.ACC_FINAL;
150        }
151        if (isVolatile()) {
152          res |= Modifiers.ACC_VOLATILE;
153        }
154        if (isTransient()) {
155          res |= Modifiers.ACC_TRANSIENT;
156        }
157        return res;
158      }
159    }