View Javadoc
1 package org.apache.bcel.generic; 2 import org.apache.bcel.Constants; 3 4 /* ==================================================================== 5 * The Apache Software License, Version 1.1 6 * 7 * Copyright (c) 2001 The Apache Software Foundation. All rights 8 * reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in 19 * the documentation and/or other materials provided with the 20 * distribution. 21 * 22 * 3. The end-user documentation included with the redistribution, 23 * if any, must include the following acknowledgment: 24 * "This product includes software developed by the 25 * Apache Software Foundation (http://www.apache.org/)." 26 * Alternately, this acknowledgment may appear in the software itself, 27 * if and wherever such third-party acknowledgments normally appear. 28 * 29 * 4. The names "Apache" and "Apache Software Foundation" and 30 * "Apache BCEL" must not be used to endorse or promote products 31 * derived from this software without prior written permission. For 32 * written permission, please contact apache@apache.org. 33 * 34 * 5. Products derived from this software may not be called "Apache", 35 * "Apache BCEL", nor may "Apache" appear in their name, without 36 * prior written permission of the Apache Software Foundation. 37 * 38 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 39 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 40 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 41 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 42 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 44 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 45 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 46 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 47 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 48 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 49 * SUCH DAMAGE. 50 * ==================================================================== 51 * 52 * This software consists of voluntary contributions made by many 53 * individuals on behalf of the Apache Software Foundation. For more 54 * information on the Apache Software Foundation, please see 55 * <http://www.apache.org/>;. 56 */ 57 58 import org.apache.bcel.classfile.*; 59 import java.util.ArrayList; 60 61 /*** 62 * Super class for FieldGen and MethodGen objects, since they have 63 * some methods in common! 64 * 65 * @version $Id: FieldGenOrMethodGen.java,v 1.2 2002/04/24 08:01:36 mdahm Exp $ 66 * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> 67 */ 68 public abstract class FieldGenOrMethodGen extends AccessFlags 69 implements NamedAndTyped, Cloneable 70 { 71 protected String name; 72 protected Type type; 73 protected ConstantPoolGen cp; 74 private ArrayList attribute_vec = new ArrayList(); 75 76 protected FieldGenOrMethodGen() {} 77 78 public void setType(Type type) { 79 if(type.getType() == Constants.T_ADDRESS) 80 throw new IllegalArgumentException("Type can not be " + type); 81 82 this.type = type; 83 } 84 public Type getType() { return type; } 85 86 /*** @return name of method/field. 87 */ 88 public String getName() { return name; } 89 public void setName(String name) { this.name = name; } 90 91 public ConstantPoolGen getConstantPool() { return cp; } 92 public void setConstantPool(ConstantPoolGen cp) { this.cp = cp; } 93 94 /*** 95 * Add an attribute to this method. Currently, the JVM knows about 96 * the `Code', `ConstantValue', `Synthetic' and `Exceptions' 97 * attributes. Other attributes will be ignored by the JVM but do no 98 * harm. 99 * 100 * @param a attribute to be added 101 */ 102 public void addAttribute(Attribute a) { attribute_vec.add(a); } 103 104 /*** 105 * Remove an attribute. 106 */ 107 public void removeAttribute(Attribute a) { attribute_vec.remove(a); } 108 109 /*** 110 * Remove all attributes. 111 */ 112 public void removeAttributes() { attribute_vec.clear(); } 113 114 /*** 115 * @return all attributes of this method. 116 */ 117 public Attribute[] getAttributes() { 118 Attribute[] attributes = new Attribute[attribute_vec.size()]; 119 attribute_vec.toArray(attributes); 120 return attributes; 121 } 122 123 /*** @return signature of method/field. 124 */ 125 public abstract String getSignature(); 126 127 public Object clone() { 128 try { 129 return super.clone(); 130 } catch(CloneNotSupportedException e) { 131 System.err.println(e); 132 return null; 133 } 134 } 135 }

This page was automatically generated by Maven