< prev index next >

src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/FieldOrMethod.java

Print this page


   1 /*
   2  * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
   3  */
   4 /*
   5  * Licensed to the Apache Software Foundation (ASF) under one or more
   6  * contributor license agreements.  See the NOTICE file distributed with
   7  * this work for additional information regarding copyright ownership.
   8  * The ASF licenses this file to You under the Apache License, Version 2.0
   9  * (the "License"); you may not use this file except in compliance with
  10  * the License.  You may obtain a copy of the License at
  11  *
  12  *      http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 package com.sun.org.apache.bcel.internal.classfile;
  21 
  22 import java.io.DataInput;
  23 import java.io.DataInputStream;
  24 import java.io.DataOutputStream;
  25 import java.io.IOException;
  26 
  27 import com.sun.org.apache.bcel.internal.Const;
  28 
  29 /**
  30  * Abstract super class for fields and methods.
  31  *
  32  * @version $Id$
  33  * @LastModified: Jun 2019
  34  */
  35 public abstract class FieldOrMethod extends AccessFlags implements Cloneable, Node {
  36     private int name_index; // Points to field name in constant pool
  37     private int signature_index; // Points to encoded signature
  38     private Attribute[] attributes; // Collection of attributes
  39     private int attributes_count; // No. of attributes
  40 
  41     // @since 6.0
  42     private AnnotationEntry[] annotationEntries; // annotations defined on the field or method
  43 
  44     private ConstantPool constant_pool;
  45 
  46     private String signatureAttributeString = null;
  47     private boolean searchedForSignatureAttribute = false;
  48 
  49     FieldOrMethod() {
  50     }
  51 
  52 
  53     /**
  54      * Initialize from another object. Note that both objects use the same
  55      * references (shallow copy). Use clone() for a physical copy.
  56      */
  57     protected FieldOrMethod(final FieldOrMethod c) {
  58         this(c.getAccessFlags(), c.getNameIndex(), c.getSignatureIndex(),
  59                 c.getAttributes(), c.getConstantPool());
  60     }
  61 
  62 
  63     /**
  64      * Construct object from file stream.
  65      *
  66      * @param file Input stream
  67      * @throws IOException
  68      * @throws ClassFormatException
  69      * @deprecated (6.0) Use {@link #FieldOrMethod(java.io.DataInput, ConstantPool)} instead.
  70      */
  71     @java.lang.Deprecated
  72     protected FieldOrMethod(final DataInputStream file, final ConstantPool constant_pool) throws IOException,

  73             ClassFormatException {
  74         this((DataInput) file, constant_pool);
  75     }
  76 
  77     /**
  78      * Construct object from file stream.
  79      * @param file Input stream
  80      * @throws IOException
  81      * @throws ClassFormatException
  82      */
  83     protected FieldOrMethod(final DataInput file,
  84             final ConstantPool constant_pool) throws IOException, ClassFormatException {
  85         this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), null,
  86                 constant_pool);
  87         final int attributes_count = file.readUnsignedShort();
  88         attributes = new Attribute[attributes_count];
  89         for (int i = 0; i < attributes_count; i++) {
  90             attributes[i] = Attribute.readAttribute(file, constant_pool);
  91         }
  92         this.attributes_count = attributes_count; // init deprecated field
  93     }
  94 
  95 
  96     /**
  97      * @param access_flags Access rights of method
  98      * @param name_index Points to field name in constant pool
  99      * @param signature_index Points to encoded signature
 100      * @param attributes Collection of attributes
 101      * @param constant_pool Array of constants
 102      */
 103     protected FieldOrMethod(final int access_flags, final int name_index, final int signature_index,
 104             final Attribute[] attributes, final ConstantPool constant_pool) {


   1 /*
   2  * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
   3  */
   4 /*
   5  * Licensed to the Apache Software Foundation (ASF) under one or more
   6  * contributor license agreements.  See the NOTICE file distributed with
   7  * this work for additional information regarding copyright ownership.
   8  * The ASF licenses this file to You under the Apache License, Version 2.0
   9  * (the "License"); you may not use this file except in compliance with
  10  * the License.  You may obtain a copy of the License at
  11  *
  12  *      http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 package com.sun.org.apache.bcel.internal.classfile;
  21 
  22 import java.io.DataInput;
  23 import java.io.DataInputStream;
  24 import java.io.DataOutputStream;
  25 import java.io.IOException;
  26 
  27 import com.sun.org.apache.bcel.internal.Const;
  28 
  29 /**
  30  * Abstract super class for fields and methods.
  31  *
  32  * @LastModified: Jan 2020

  33  */
  34 public abstract class FieldOrMethod extends AccessFlags implements Cloneable, Node {
  35     private int name_index; // Points to field name in constant pool
  36     private int signature_index; // Points to encoded signature
  37     private Attribute[] attributes; // Collection of attributes
  38     private int attributes_count; // No. of attributes
  39 
  40     // @since 6.0
  41     private AnnotationEntry[] annotationEntries; // annotations defined on the field or method
  42 
  43     private ConstantPool constant_pool;
  44 
  45     private String signatureAttributeString = null;
  46     private boolean searchedForSignatureAttribute = false;
  47 
  48     FieldOrMethod() {
  49     }
  50 
  51 
  52     /**
  53      * Initialize from another object. Note that both objects use the same
  54      * references (shallow copy). Use clone() for a physical copy.
  55      */
  56     protected FieldOrMethod(final FieldOrMethod c) {
  57         this(c.getAccessFlags(), c.getNameIndex(), c.getSignatureIndex(),
  58                 c.getAttributes(), c.getConstantPool());
  59     }
  60 
  61 
  62     /**
  63      * Construct object from file stream.
  64      *
  65      * @param file Input stream
  66      * @throws IOException
  67      * @throws ClassFormatException
  68      * @deprecated (6.0) Use {@link #FieldOrMethod(java.io.DataInput, ConstantPool)} instead.
  69      */
  70     @java.lang.Deprecated
  71     protected FieldOrMethod(final DataInputStream file, final ConstantPool constant_pool)
  72             throws IOException,
  73             ClassFormatException {
  74         this((DataInput) file, constant_pool);
  75     }
  76 
  77     /**
  78      * Construct object from file stream.
  79      * @param file Input stream
  80      * @throws IOException
  81      * @throws ClassFormatException
  82      */
  83     protected FieldOrMethod(final DataInput file, final ConstantPool constant_pool)
  84             throws IOException, ClassFormatException {
  85         this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), null,
  86                 constant_pool);
  87         final int attributes_count = file.readUnsignedShort();
  88         attributes = new Attribute[attributes_count];
  89         for (int i = 0; i < attributes_count; i++) {
  90             attributes[i] = Attribute.readAttribute(file, constant_pool);
  91         }
  92         this.attributes_count = attributes_count; // init deprecated field
  93     }
  94 
  95 
  96     /**
  97      * @param access_flags Access rights of method
  98      * @param name_index Points to field name in constant pool
  99      * @param signature_index Points to encoded signature
 100      * @param attributes Collection of attributes
 101      * @param constant_pool Array of constants
 102      */
 103     protected FieldOrMethod(final int access_flags, final int name_index, final int signature_index,
 104             final Attribute[] attributes, final ConstantPool constant_pool) {


< prev index next >