1 /* 2 * Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.openjdk.asmtools.jasm; 24 25 import static org.openjdk.asmtools.jasm.RuntimeConstants.DEPRECATED_ATTRIBUTE; 26 import static org.openjdk.asmtools.jasm.RuntimeConstants.SYNTHETIC_ATTRIBUTE; 27 import org.openjdk.asmtools.jasm.Tables.AttrTag; 28 import java.util.ArrayList; 29 30 /** 31 * The common base structure for field_info, method_info, and component_info 32 */ 33 abstract public class MemberData { 34 35 protected int access; 36 protected AttrData syntheticAttr, deprecatedAttr; 37 protected DataVectorAttr<AnnotationData> annotAttrVis = null; 38 protected DataVectorAttr<AnnotationData> annotAttrInv = null; 39 protected DataVectorAttr<TypeAnnotationData> type_annotAttrVis = null; 40 protected DataVectorAttr<TypeAnnotationData> type_annotAttrInv = null; 41 protected ClassData cls; 42 protected AttrData signatureAttr; 43 44 public MemberData(ClassData cls, int access) { 45 this.cls = cls; 46 init(access); 47 } 48 49 public MemberData(ClassData cls) { 50 this.cls = cls; 51 } 52 53 public void init(int access) { 54 this.access = access; 55 } 56 57 public void createPseudoMod() { 58 // If a member has a Pseudo-modifier 59 60 // create the appropriate marker attributes, 61 // and clear the PseudoModifiers from the access flags. 62 if (Modifiers.isSyntheticPseudoMod(access)) { 63 syntheticAttr = new AttrData(cls, AttrTag.ATT_Synthetic.parsekey()); 64 access &= ~SYNTHETIC_ATTRIBUTE; 65 } 66 if (Modifiers.isDeprecatedPseudoMod(access)) { 67 deprecatedAttr = new AttrData(cls, AttrTag.ATT_Deprecated.parsekey()); 68 access &= ~DEPRECATED_ATTRIBUTE; 69 } 70 } 71 72 public void setSignatureAttr(ConstantPool.ConstCell value_cpx) { 73 signatureAttr = new CPXAttr(cls, Tables.AttrTag.ATT_Signature.parsekey(), value_cpx); 74 } 75 76 protected abstract DataVector getAttrVector(); 77 78 protected final DataVector getDataVector(Data... extraAttrs) { 79 DataVector attrs = new DataVector(); 80 for( Data extra : extraAttrs ) { 81 if (extra != null) { 82 attrs.add(extra); 83 } 84 } 85 // common set for [ FieldData, MethodData, RecordData ] 86 if (annotAttrVis != null) { 87 attrs.add(annotAttrVis); 88 } 89 if (annotAttrInv != null) { 90 attrs.add(annotAttrInv); 91 } 92 if (type_annotAttrVis != null) { 93 attrs.add(type_annotAttrVis); 94 } 95 if (type_annotAttrInv != null) { 96 attrs.add(type_annotAttrInv); 97 } 98 return attrs; 99 } 100 101 public void addAnnotations(ArrayList<AnnotationData> list) { 102 for (AnnotationData item : list) { 103 boolean invisible = item.invisible; 104 if (item instanceof TypeAnnotationData) { 105 // Type Annotations 106 TypeAnnotationData ta = (TypeAnnotationData) item; 107 if (invisible) { 108 if (type_annotAttrInv == null) { 109 type_annotAttrInv = new DataVectorAttr(cls, 110 AttrTag.ATT_RuntimeInvisibleTypeAnnotations.parsekey()); 111 } 112 type_annotAttrInv.add(ta); 113 } else { 114 if (type_annotAttrVis == null) { 115 type_annotAttrVis = new DataVectorAttr(cls, 116 AttrTag.ATT_RuntimeVisibleTypeAnnotations.parsekey()); 117 } 118 type_annotAttrVis.add(ta); 119 } 120 } else { 121 // Regular Annotations 122 if (invisible) { 123 if (annotAttrInv == null) { 124 annotAttrInv = new DataVectorAttr(cls, 125 AttrTag.ATT_RuntimeInvisibleAnnotations.parsekey()); 126 } 127 annotAttrInv.add(item); 128 } else { 129 if (annotAttrVis == null) { 130 annotAttrVis = new DataVectorAttr(cls, 131 AttrTag.ATT_RuntimeVisibleAnnotations.parsekey()); 132 } 133 annotAttrVis.add(item); 134 } 135 } 136 } 137 } 138 }