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.classfile; 23 24 import java.io.DataInput; 25 import java.io.DataOutputStream; 26 import java.io.IOException; 27 28 import com.sun.org.apache.bcel.internal.Const; 29 30 /** 31 * Entry of the parameters table. 32 * 33 * @see <a href="http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.24"> 34 * The class File Format : The MethodParameters Attribute</a> 35 * @since 6.0 36 */ 37 public class MethodParameter implements Cloneable { 38 39 /** Index of the CONSTANT_Utf8_info structure in the constant_pool table representing the name of the parameter */ 40 private int name_index; 41 42 /** The access flags */ 43 private int access_flags; 44 45 public MethodParameter() { 46 } 47 48 /** 49 * Construct object from input stream. 50 * 51 * @param input Input stream 52 * @throws java.io.IOException 53 * @throws ClassFormatException 54 */ 55 MethodParameter(final DataInput input) throws IOException { 56 name_index = input.readUnsignedShort(); 57 access_flags = input.readUnsignedShort(); 58 } 59 60 public int getNameIndex() { 61 return name_index; 62 } 63 64 public void setNameIndex(final int name_index) { 65 this.name_index = name_index; 66 } 67 68 /** 69 * Returns the name of the parameter. 70 */ 71 public String getParameterName(final ConstantPool constant_pool) { 72 if (name_index == 0) { 73 return null; 74 } 75 return ((ConstantUtf8) constant_pool.getConstant(name_index, Const.CONSTANT_Utf8)).getBytes(); 76 } 77 78 public int getAccessFlags() { 79 return access_flags; 80 } 81 82 public void setAccessFlags(final int access_flags) { 83 this.access_flags = access_flags; 84 } 85 86 public boolean isFinal() { 87 return (access_flags & Const.ACC_FINAL) != 0; 88 } 89 90 public boolean isSynthetic() { 91 return (access_flags & Const.ACC_SYNTHETIC) != 0; 92 } 93 94 public boolean isMandated() { 95 return (access_flags & Const.ACC_MANDATED) != 0; 96 } 97 98 /** 99 * Dump object to file stream on binary format. 100 * 101 * @param file Output file stream 102 * @throws IOException 103 */ 104 public final void dump(final DataOutputStream file) throws IOException { 105 file.writeShort(name_index); 106 file.writeShort(access_flags); 107 } 108 109 /** 110 * @return deep copy of this object 111 */ 112 public MethodParameter copy() { 113 try { 114 return (MethodParameter) clone(); 115 } catch (final CloneNotSupportedException e) { 116 // TODO should this throw? 117 } 118 return null; 119 } 120 }