1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22 package com.sun.org.apache.bcel.internal.generic; 23 import com.sun.org.apache.bcel.internal.Constants; 24 25 26 import com.sun.org.apache.bcel.internal.classfile.*; 27 import java.util.ArrayList; 28 29 /** 30 * Super class for FieldGen and MethodGen objects, since they have 31 * some methods in common! 32 * 33 * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> 34 */ 35 public abstract class FieldGenOrMethodGen extends AccessFlags 36 implements NamedAndTyped, Cloneable 37 { 38 protected String name; 39 protected Type type; 40 protected ConstantPoolGen cp; 41 private ArrayList attribute_vec = new ArrayList(); 42 43 protected FieldGenOrMethodGen() {} 44 45 public void setType(Type type) { 46 if(type.getType() == Constants.T_ADDRESS) 47 throw new IllegalArgumentException("Type can not be " + type); 48 49 this.type = type; 50 } 51 public Type getType() { return type; } 52 53 /** @return name of method/field. 54 */ 55 public String getName() { return name; } 56 public void setName(String name) { this.name = name; } 57 58 public ConstantPoolGen getConstantPool() { return cp; } 59 public void setConstantPool(ConstantPoolGen cp) { this.cp = cp; } 60 61 /** 62 * Add an attribute to this method. Currently, the JVM knows about 63 * the `Code', `ConstantValue', `Synthetic' and `Exceptions' 64 * attributes. Other attributes will be ignored by the JVM but do no 65 * harm. 66 * 67 * @param a attribute to be added 68 */ 69 public void addAttribute(Attribute a) { attribute_vec.add(a); } 70 71 /** 72 * Remove an attribute. 73 */ 74 public void removeAttribute(Attribute a) { attribute_vec.remove(a); } 75 76 /** 77 * Remove all attributes. 78 */ 79 public void removeAttributes() { attribute_vec.clear(); } 80 81 /** 82 * @return all attributes of this method. 83 */ 84 public Attribute[] getAttributes() { 85 Attribute[] attributes = new Attribute[attribute_vec.size()]; 86 attribute_vec.toArray(attributes); 87 return attributes; 88 } 89 90 /** @return signature of method/field. 91 */ 92 public abstract String getSignature(); 93 94 public Object clone() { 95 try { 96 return super.clone(); 97 } catch(CloneNotSupportedException e) { 98 System.err.println(e); 99 return null; 100 } 101 } 102 }