Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

Field.java

00001 package edu.ksu.cis.bandera.jjjc.symboltable;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Bandera, a Java(TM) analysis and transformation toolkit           *
00005  * Copyright (C) 1999, 2000   Robby (robby@cis.ksu.edu)              *
00006  * All rights reserved.                                              *
00007  *                                                                   *
00008  * This work was done as a project in the SAnToS Laboratory,         *
00009  * Department of Computing and Information Sciences, Kansas State    *
00010  * University, USA (http://www.cis.ksu.edu/santos).                  *
00011  * It is understood that any modification not identified as such is  *
00012  * not covered by the preceding statement.                           *
00013  *                                                                   *
00014  * This work is free software; you can redistribute it and/or        *
00015  * modify it under the terms of the GNU Library General Public       *
00016  * License as published by the Free Software Foundation; either      *
00017  * version 2 of the License, or (at your option) any later version.  *
00018  *                                                                   *
00019  * This work is distributed in the hope that it will be useful,      *
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00022  * Library General Public License for more details.                  *
00023  *                                                                   *
00024  * You should have received a copy of the GNU Library General Public *
00025  * License along with this toolkit; if not, write to the             *
00026  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00027  * Boston, MA  02111-1307, USA.                                      *
00028  *                                                                   *
00029  * Java is a trademark of Sun Microsystems, Inc.                     *
00030  *                                                                   *
00031  * To submit a bug report, send a comment, or get the latest news on *
00032  * this project and other SAnToS projects, please visit the web-site *
00033  *                http://www.cis.ksu.edu/santos                      *
00034  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00035 import java.lang.reflect.*;
00036 import edu.ksu.cis.bandera.jjjc.exception.*;
00037 
00038 public class Field implements Named, Typed {
00039     protected int modifiers = 0;
00040     private Type type;
00041     private Name name;
00042     private ClassOrInterfaceType declaringClassOrInterface = null;
00043     protected boolean isArrayLength = false;
00044     protected ArrayType arrayType = null;
00045 /**
00046  * 
00047  * @param name edu.ksu.cis.bandera.jjjc.symboltable.Name
00048  * @param type edu.ksu.cis.bandera.jjjc.symboltable.Type
00049  */
00050 public Field(Name name, Type type) throws InvalidNameException {
00051     if (!(name.isSimpleName()))
00052         throw new InvalidNameException("Cannot have a method named '" + name.toString() + "'");
00053 
00054     this.name = name;
00055     this.type = type;
00056 }
00057 /**
00058  * 
00059  * @return boolean
00060  * @param modifiers int
00061  */
00062 public static boolean areValidClassFieldModifiers(int modifiers) {
00063     if (Modifier.isPublic(modifiers) && Modifier.isProtected(modifiers))
00064         return false;
00065     else if (Modifier.isPublic(modifiers) && Modifier.isPrivate(modifiers))
00066         return false;
00067     else if (Modifier.isProtected(modifiers) && Modifier.isPrivate(modifiers))
00068         return false;
00069     else return true;
00070 }
00071 /**
00072  * 
00073  * @return boolean
00074  * @param modifiers int
00075  */
00076 public static boolean areValidInterfaceFieldModifiers(int modifiers) {
00077     if (Modifier.isProtected(modifiers) || Modifier.isPrivate(modifiers)|| Modifier.isAbstract(modifiers)
00078             || Modifier.isNative(modifiers) || Modifier.isSynchronized(modifiers) || Modifier.isTransient(modifiers)
00079             || Modifier.isVolatile(modifiers))
00080         return false;
00081     else return true;
00082 }
00083 /**
00084  * 
00085  * @return boolean
00086  * @param modifiers int
00087  */
00088 public boolean areValidModifiers(int modifiers) {
00089     return areValidModifiers(modifiers, declaringClassOrInterface.isInterface());
00090 }
00091 /**
00092  * 
00093  * @return boolean
00094  * @param modifiers int
00095  * @param isInterface boolean
00096  */
00097 public static boolean areValidModifiers(int modifiers, boolean isInterface) {
00098     return (isInterface) ? areValidInterfaceFieldModifiers(modifiers) : areValidClassFieldModifiers(modifiers);
00099 }
00100 /**
00101  * 
00102  * @return edu.ksu.cis.bandera.jjjc.symboltable.ClassOrInterfaceType
00103  */
00104 public ClassOrInterfaceType getDeclaringClassOrInterface() throws NotDeclaredException {
00105     if (declaringClassOrInterface == null)
00106         throw new NotDeclaredException("Field named '" + name.toString() + "' has not been declared yet.");
00107     else return declaringClassOrInterface;
00108 }
00109 /**
00110  * 
00111  * @return int
00112  */
00113 public int getModifiers() {
00114     return modifiers;
00115 }
00116 /**
00117  * 
00118  * @return edu.ksu.cis.bandera.jjjc.symboltable.Name
00119  */
00120 public Name getName() {
00121     return name;
00122 }
00123 /**
00124  * 
00125  * @return edu.ksu.cis.bandera.jjjc.symboltable.Type
00126  */
00127 public Type getType() {
00128     return type;
00129 }
00130 /**
00131  * 
00132  * @return boolean
00133  * @param otherType edu.ksu.cis.bandera.jjjc.symboltable.ClassOrInterfaceType
00134  */
00135 public boolean isAccessible(ClassOrInterfaceType otherType) {
00136     if (isArrayLength)
00137         return true;
00138         
00139     if (declaringClassOrInterface == otherType)
00140         return true;
00141     else if (!declaringClassOrInterface.isAccesible(otherType))
00142         return false;
00143     
00144     if (Modifier.isPublic(modifiers))
00145         return true;
00146     else if (Modifier.isPrivate(modifiers))
00147         return false;
00148     else if (Modifier.isProtected(modifiers) && otherType.hasSuperClass(declaringClassOrInterface))
00149         return true;
00150     else return declaringClassOrInterface.getContainingPackage() == otherType.getContainingPackage();
00151 }
00152 /**
00153  * 
00154  * @param declaringClassOrInterface edu.ksu.cis.bandera.jjjc.symboltable.ClassOrInterfaceType
00155  */
00156 public void setDeclaringClassOrInterface(ClassOrInterfaceType declaringClassOrInterface) {
00157     this.declaringClassOrInterface = declaringClassOrInterface;
00158 }
00159 /**
00160  * 
00161  * @param modifiers int
00162  */
00163 public void setModifiers(int modifiers) throws InvalidModifiersException {
00164     if (areValidModifiers(modifiers))
00165         this.modifiers = modifiers;
00166     else
00167         throw new InvalidModifiersException("Invalid modifiers for field named '" + name
00168                 + "' in class or interface type named '" + declaringClassOrInterface.getName() + "'");
00169 }
00170 /**
00171  * 
00172  * @return java.lang.String
00173  */
00174 public String toString() {
00175     return name.toString();
00176 }
00177 }

Generated at Thu Feb 7 06:45:36 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001