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

ConstructorDeclarationAnnotation.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 ca.mcgill.sable.soot.*;
00036 import ca.mcgill.sable.soot.jimple.*;
00037 import edu.ksu.cis.bandera.jjjc.symboltable.*;
00038 import java.util.*;
00039 import ca.mcgill.sable.util.*;
00040 public class ConstructorDeclarationAnnotation extends BlockStmtAnnotation implements java.lang.Comparable {
00041     private SootMethod sm = null;
00042     private Method m = null;
00043     private Vector annotations = null;
00044 /**
00045  * ConstructorDeclarationAnnotation constructor comment.
00046  * @param node edu.ksu.cis.bandera.jjjc.node.Node
00047  */
00048 public ConstructorDeclarationAnnotation(edu.ksu.cis.bandera.jjjc.node.Node node) {
00049     super(node);
00050 }
00051 public void apply(Switch sw)
00052 {
00053     ((AnnotationSwitch) sw).caseConstructorDeclarationAnnotation(this);
00054 }
00055 /**
00056  * 
00057  * @return java.lang.Object
00058  */
00059 public Object clone() {
00060     ConstructorDeclarationAnnotation result = new ConstructorDeclarationAnnotation((edu.ksu.cis.bandera.jjjc.node.Node) node.clone());
00061 
00062     for (Enumeration e = containedAnnotations.elements(); e.hasMoreElements();) {
00063         result.addAnnotation((Annotation) ((Annotation) e.nextElement()).clone());
00064     }
00065 
00066     result.sm = sm;
00067     result.m = m;
00068     
00069     return result;
00070 }
00071 /**
00072  * 
00073  * @return int
00074  * @param o java.lang.Object
00075  */
00076 public int compareTo(Object o) {
00077     if (o instanceof FieldDeclarationAnnotation) {
00078         return 1;
00079     } else if (o instanceof ConstructorDeclarationAnnotation) {
00080         ConstructorDeclarationAnnotation cda = (ConstructorDeclarationAnnotation) o;
00081         int i = getSootMethod().getParameterCount() - cda.getSootMethod().getParameterCount();
00082         if (i == 0) {
00083             return getSootMethod().toString().compareTo(getSootMethod().toString());
00084         } else { 
00085             return i;
00086         }
00087     } else {
00088         return -1;
00089     }
00090 }
00091 /**
00092  * 
00093  * @return edu.ksu.cis.bandera.annotation.Annotation
00094  * @param index int
00095  */
00096 public Annotation getAnnotationAt(int index) {
00097     if (annotations == null) {
00098         annotations = getAllAnnotations(false);
00099     }
00100     return (Annotation) annotations.elementAt(index + 1);
00101 }
00102 /**
00103  * 
00104  * @return edu.ksu.cis.bandera.jjjc.symboltable.Method
00105  */
00106 public Method getConstructor() {
00107     return m;
00108 }
00109 /**
00110  * 
00111  * @return java.util.Hashtable
00112  * @param annotation edu.ksu.cis.bandera.annotation.Annotation
00113  */
00114 public Hashtable getDeclaredLocalVariablesUntil(Annotation annotation) {
00115     Hashtable result = new Hashtable();
00116     JimpleBody body = (JimpleBody) sm.getBody(Jimple.v());
00117     for (Enumeration e = m.getParameters().elements(); e.hasMoreElements();) {
00118         try {
00119             String name = ((Variable) e.nextElement()).getName().toString().trim();
00120             result.put(name, body.getLocal(name));
00121         } catch (Exception ex) {}
00122     }
00123     Hashtable table = super.getDeclaredLocalVariablesUntil(annotation);
00124     for (Enumeration e = table.keys(); e.hasMoreElements();) {
00125         Object key = e.nextElement();
00126         result.put(key, table.get(key));
00127     }
00128     return result;
00129 }
00130 /**
00131  * 
00132  * @return java.util.Hashtable
00133  */
00134 public Hashtable getParameterLocals() {
00135     Hashtable result = new Hashtable();
00136     JimpleBody body = (JimpleBody) sm.getBody(Jimple.v());
00137     for (Enumeration e = m.getParameters().elements(); e.hasMoreElements();) {
00138         try {
00139             String name = ((Variable) e.nextElement()).getName().toString().trim();
00140             result.put(name, body.getLocal(name));
00141         } catch (Exception ex) {}
00142     }
00143     return result;
00144 }
00145 /**
00146  * 
00147  * @return ca.mcgill.sable.soot.SootMethod
00148  */
00149 public SootMethod getSootMethod() {
00150     return sm;
00151 }
00152 /**
00153  * 
00154  * @return int
00155  * @param annotation edu.ksu.cis.bandera.annotation.Annotation
00156  */
00157 public int indexOf(Annotation annotation) {
00158     if (annotations == null) {
00159         annotations = getAllAnnotations(false);
00160     }
00161     return annotations.indexOf(annotation) + 1;
00162 }
00163 /**
00164  * 
00165  * @param constructor edu.ksu.cis.bandera.jjjc.symboltable.Method
00166  */
00167 public void setConstructor(Method constructor) {
00168     m = constructor;
00169 }
00170 /**
00171  * 
00172  * @param sootMethod ca.mcgill.sable.soot.SootMethod
00173  */
00174 public void setSootMethod(SootMethod sootMethod) {
00175     sm = sootMethod;
00176 }
00177 /**
00178  * 
00179  * @return java.lang.String
00180  */
00181 public String toString() {
00182     String result = "";
00183     try {
00184         boolean isAbstractNative = Modifier.isAbstract(sm.getModifiers()) || Modifier.isNative(sm.getModifiers());
00185         result = Modifier.toString(sm.getModifiers()) + " " + m.getDeclaringClassOrInterface().getName().getLastIdentifier().trim() + "(";
00186         JimpleBody body = (JimpleBody) sm.getBody(Jimple.v());
00187         String parm = "";
00188         for (Enumeration e = m.getParameters().elements(); e.hasMoreElements();) {
00189             Variable v = (Variable) e.nextElement();
00190             if (body.declaresLocal(v.getName().toString().trim()) || isAbstractNative) {
00191                 parm += (v.toString() + ", ");
00192             }
00193         }
00194         if (parm.length() > 1) 
00195             parm = parm.substring(0, parm.length() - 2);
00196         result += (parm + ")");
00197         String exceptions = sm.getExceptions().toString().trim();
00198         exceptions = exceptions.substring(1, exceptions.length() - 1);
00199         if (sm.getExceptions().size() > 0) {
00200             result += (" throws " + exceptions);
00201         }
00202     } catch (Exception e) {}
00203     return result;
00204 }
00205 }

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