2014-12-18 21:56:02 +00:00
|
|
|
/*
|
2020-04-02 23:02:32 +00:00
|
|
|
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
|
2014-12-18 21:56:02 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*/
|
|
|
|
package org.openjdk.asmtools.jasm;
|
|
|
|
|
|
|
|
import static org.openjdk.asmtools.jasm.RuntimeConstants.DEPRECATED_ATTRIBUTE;
|
|
|
|
import static org.openjdk.asmtools.jasm.RuntimeConstants.SYNTHETIC_ATTRIBUTE;
|
|
|
|
import org.openjdk.asmtools.jasm.Tables.AttrTag;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
/**
|
2020-04-02 23:02:32 +00:00
|
|
|
* The common base structure for field_info, method_info, and component_info
|
2014-12-18 21:56:02 +00:00
|
|
|
*/
|
2019-11-06 19:30:00 +00:00
|
|
|
abstract public class MemberData {
|
2014-12-18 21:56:02 +00:00
|
|
|
|
|
|
|
protected int access;
|
2019-11-06 19:30:00 +00:00
|
|
|
protected AttrData syntheticAttr, deprecatedAttr;
|
2014-12-18 21:56:02 +00:00
|
|
|
protected DataVectorAttr<AnnotationData> annotAttrVis = null;
|
|
|
|
protected DataVectorAttr<AnnotationData> annotAttrInv = null;
|
|
|
|
protected DataVectorAttr<TypeAnnotationData> type_annotAttrVis = null;
|
|
|
|
protected DataVectorAttr<TypeAnnotationData> type_annotAttrInv = null;
|
|
|
|
protected ClassData cls;
|
2020-04-02 23:02:32 +00:00
|
|
|
protected AttrData signatureAttr;
|
2014-12-18 21:56:02 +00:00
|
|
|
|
|
|
|
public MemberData(ClassData cls, int access) {
|
|
|
|
this.cls = cls;
|
|
|
|
init(access);
|
|
|
|
}
|
|
|
|
|
2019-11-06 19:30:00 +00:00
|
|
|
public MemberData(ClassData cls) {
|
|
|
|
this.cls = cls;
|
|
|
|
}
|
|
|
|
|
2014-12-18 21:56:02 +00:00
|
|
|
public void init(int access) {
|
|
|
|
this.access = access;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void createPseudoMod() {
|
|
|
|
// If a member has a Pseudo-modifier
|
|
|
|
|
|
|
|
// create the appropriate marker attributes,
|
|
|
|
// and clear the PseudoModifiers from the access flags.
|
|
|
|
if (Modifiers.isSyntheticPseudoMod(access)) {
|
2020-04-02 23:02:32 +00:00
|
|
|
syntheticAttr = new AttrData(cls, AttrTag.ATT_Synthetic.parsekey());
|
2014-12-18 21:56:02 +00:00
|
|
|
access &= ~SYNTHETIC_ATTRIBUTE;
|
|
|
|
}
|
|
|
|
if (Modifiers.isDeprecatedPseudoMod(access)) {
|
2020-04-02 23:02:32 +00:00
|
|
|
deprecatedAttr = new AttrData(cls, AttrTag.ATT_Deprecated.parsekey());
|
2014-12-18 21:56:02 +00:00
|
|
|
access &= ~DEPRECATED_ATTRIBUTE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-02 23:02:32 +00:00
|
|
|
public void setSignatureAttr(ConstantPool.ConstCell value_cpx) {
|
|
|
|
signatureAttr = new CPXAttr(cls, Tables.AttrTag.ATT_Signature.parsekey(), value_cpx);
|
|
|
|
}
|
|
|
|
|
2019-11-06 19:30:00 +00:00
|
|
|
protected abstract DataVector getAttrVector();
|
|
|
|
|
2020-01-06 21:12:12 +00:00
|
|
|
protected final DataVector getDataVector(Data... extraAttrs) {
|
2019-11-06 19:30:00 +00:00
|
|
|
DataVector attrs = new DataVector();
|
2020-01-06 21:12:12 +00:00
|
|
|
for( Data extra : extraAttrs ) {
|
|
|
|
if (extra != null) {
|
|
|
|
attrs.add(extra);
|
|
|
|
}
|
2019-11-06 19:30:00 +00:00
|
|
|
}
|
2020-01-06 21:12:12 +00:00
|
|
|
// common set for [ FieldData, MethodData, RecordData ]
|
2019-11-06 19:30:00 +00:00
|
|
|
if (annotAttrVis != null) {
|
|
|
|
attrs.add(annotAttrVis);
|
|
|
|
}
|
|
|
|
if (annotAttrInv != null) {
|
|
|
|
attrs.add(annotAttrInv);
|
|
|
|
}
|
|
|
|
if (type_annotAttrVis != null) {
|
|
|
|
attrs.add(type_annotAttrVis);
|
|
|
|
}
|
|
|
|
if (type_annotAttrInv != null) {
|
|
|
|
attrs.add(type_annotAttrInv);
|
|
|
|
}
|
|
|
|
return attrs;
|
|
|
|
}
|
|
|
|
|
2020-04-02 23:02:32 +00:00
|
|
|
public void addAnnotations(ArrayList<AnnotationData> list) {
|
|
|
|
for (AnnotationData item : list) {
|
|
|
|
boolean invisible = item.invisible;
|
|
|
|
if (item instanceof TypeAnnotationData) {
|
2014-12-18 21:56:02 +00:00
|
|
|
// Type Annotations
|
2020-04-02 23:02:32 +00:00
|
|
|
TypeAnnotationData ta = (TypeAnnotationData) item;
|
2014-12-18 21:56:02 +00:00
|
|
|
if (invisible) {
|
|
|
|
if (type_annotAttrInv == null) {
|
|
|
|
type_annotAttrInv = new DataVectorAttr(cls,
|
|
|
|
AttrTag.ATT_RuntimeInvisibleTypeAnnotations.parsekey());
|
|
|
|
}
|
2020-04-02 23:02:32 +00:00
|
|
|
type_annotAttrInv.add(ta);
|
2014-12-18 21:56:02 +00:00
|
|
|
} else {
|
|
|
|
if (type_annotAttrVis == null) {
|
|
|
|
type_annotAttrVis = new DataVectorAttr(cls,
|
|
|
|
AttrTag.ATT_RuntimeVisibleTypeAnnotations.parsekey());
|
|
|
|
}
|
2020-04-02 23:02:32 +00:00
|
|
|
type_annotAttrVis.add(ta);
|
2014-12-18 21:56:02 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Regular Annotations
|
|
|
|
if (invisible) {
|
|
|
|
if (annotAttrInv == null) {
|
|
|
|
annotAttrInv = new DataVectorAttr(cls,
|
|
|
|
AttrTag.ATT_RuntimeInvisibleAnnotations.parsekey());
|
|
|
|
}
|
2020-04-02 23:02:32 +00:00
|
|
|
annotAttrInv.add(item);
|
2014-12-18 21:56:02 +00:00
|
|
|
} else {
|
|
|
|
if (annotAttrVis == null) {
|
|
|
|
annotAttrVis = new DataVectorAttr(cls,
|
|
|
|
AttrTag.ATT_RuntimeVisibleAnnotations.parsekey());
|
|
|
|
}
|
2020-04-02 23:02:32 +00:00
|
|
|
annotAttrVis.add(item);
|
2014-12-18 21:56:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|