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

FieldDeclarationAnnotation.java

00001 package edu.ksu.cis.bandera.annotation;
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 edu.ksu.cis.bandera.jjjc.node.*;
00036 import edu.ksu.cis.bandera.jjjc.util.*;
00037 import edu.ksu.cis.bandera.jjjc.symboltable.*;
00038 import ca.mcgill.sable.soot.*;
00039 import ca.mcgill.sable.soot.jimple.*;
00040 import ca.mcgill.sable.util.*;
00041 import java.util.*;
00042 public class FieldDeclarationAnnotation extends SpecializedAnnotation implements java.lang.Comparable {
00043     private SootField sf;
00044     private Field f;
00045 /**
00046  * FieldDeclarationAnnotation constructor comment.
00047  * @param node edu.ksu.cis.bandera.jjjc.node.Node
00048  */
00049 public FieldDeclarationAnnotation(edu.ksu.cis.bandera.jjjc.node.Node node) {
00050     super(node);
00051 }
00052     public void apply(Switch sw)
00053     {
00054         ((AnnotationSwitch) sw).caseFieldDeclarationAnnotation(this);
00055     }
00056 /**
00057  * 
00058  * @return java.lang.Object
00059  */
00060 public Object clone() {
00061     FieldDeclarationAnnotation result = new FieldDeclarationAnnotation((Node) node.clone());
00062     /*
00063     Stmt[] stmts = getStatements();
00064     
00065     for (int i = 0; i < stmts.length; i++) {
00066         result.addStmt(JimpleStmtCloner.clone(stmts[i]));
00067     }
00068     */
00069     result.sf = sf;
00070     result.f = f;
00071     return result;
00072 }
00073 /**
00074  * 
00075  * @return int
00076  * @param o java.lang.Object
00077  */
00078 public int compareTo(Object o) {
00079     if (o instanceof FieldDeclarationAnnotation) {
00080         FieldDeclarationAnnotation fda = (FieldDeclarationAnnotation) o;
00081         return getField().getName().compareTo(fda.getField().getName());
00082     } else {
00083         return -1;
00084     }
00085 }
00086 /**
00087  * 
00088  * @return edu.ksu.cis.bandera.jjjc.symboltable.Field
00089  */
00090 public Field getField() {
00091     return f;
00092 }
00093 /**
00094  * 
00095  * @return ca.mcgill.sable.soot.SootField
00096  */
00097 public SootField getSootField() {
00098     return sf;
00099 }
00100 /**
00101  * 
00102  * @return ca.mcgill.sable.soot.jimple.Stmt[]
00103  */
00104 public Stmt[] getStatements() {
00105     return toArray();
00106 }
00107 /**
00108  * 
00109  * @return boolean
00110  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00111  */
00112 public boolean removeStmt(Stmt stmt) {
00113     return remove(stmt);
00114 }
00115 /**
00116  * 
00117  * @return boolean
00118  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00119  */
00120 public boolean removeStmtByMark(Stmt stmt) {
00121     return removeByMark(stmt);
00122 }
00123 /**
00124  * 
00125  * @return boolean
00126  * @param oldStmt ca.mcgill.sable.soot.jimple.Stmt
00127  * @param newStmt ca.mcgill.sable.soot.jimple.Stmt
00128  */
00129 public boolean replaceStmt(Stmt oldStmt, Stmt newStmt) {
00130     return replace(oldStmt, newStmt);
00131 }
00132 /**
00133  * 
00134  * @return boolean
00135  * @param oldStmt ca.mcgill.sable.soot.jimple.Stmt
00136  * @param newStmt ca.mcgill.sable.soot.jimple.Stmt
00137  */
00138 public boolean replaceStmtByMark(Stmt oldStmt, Stmt newStmt) {
00139     return replaceByMark(oldStmt, newStmt);
00140 }
00141 /**
00142  * 
00143  * @param field edu.ksu.cis.bandera.jjjc.symboltable.Field
00144  */
00145 public void setField(Field field) {
00146     f = field;
00147 }
00148 /**
00149  * 
00150  * @param sootField ca.mcgill.sable.soot.SootField
00151  */
00152 public void setSootField(SootField sootField) {
00153     sf = sootField;
00154 }
00155 /**
00156  * 
00157  * @return java.lang.String
00158  */
00159 public String toString() {
00160     AFieldDeclaration node = (AFieldDeclaration) this.node;
00161     
00162     String result = node.getType().toString();
00163 
00164     Object[] modifiers = node.getModifier().toArray();
00165     for (int i = modifiers.length - 1; i >= 0; i--) {
00166         result = modifiers[i].toString() + result;
00167     }
00168 
00169     Object[] fields = node.getVariableDeclarator().toArray();
00170         
00171     for (int i = 0; i < fields.length; i++) {
00172         if (fields[i] instanceof AAssignedVariableDeclarator) {
00173             String name = ((AAssignedVariableDeclarator) fields[i]).getVariableDeclaratorId().toString().trim();
00174 
00175             if (name.equals(sf.getName().trim())) {
00176                 result += fields[i].toString().trim();
00177                 break;
00178             }
00179         } else {
00180             String name = ((AIdVariableDeclarator) fields[i]).getVariableDeclaratorId().toString().trim();
00181 
00182             if (name.equals(sf.getName().trim())) {
00183                 result += name;
00184                 break;
00185             }
00186         }
00187     }
00188 
00189     return result;
00190 }
00191 }

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