mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8331291: java.lang.classfile.Attributes class performs a lot of static initializations
Reviewed-by: liach, redestad, vromero
This commit is contained in:
parent
0c934ff4e2
commit
cfdc64fcb4
149 changed files with 1669 additions and 1323 deletions
File diff suppressed because it is too large
Load diff
|
@ -24,35 +24,45 @@
|
|||
*/
|
||||
package jdk.internal.classfile.impl;
|
||||
|
||||
import java.lang.classfile.Annotation;
|
||||
import java.lang.classfile.Attribute;
|
||||
import java.lang.classfile.AttributeMapper;
|
||||
import java.lang.classfile.AttributedElement;
|
||||
import java.lang.classfile.BufWriter;
|
||||
import java.lang.classfile.ClassReader;
|
||||
import java.lang.classfile.attribute.*;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractAttributeMapper<T extends Attribute<T>>
|
||||
import static java.lang.classfile.Attributes.*;
|
||||
|
||||
public sealed abstract class AbstractAttributeMapper<T extends Attribute<T>>
|
||||
implements AttributeMapper<T> {
|
||||
|
||||
private final String name;
|
||||
private final AttributeMapper.AttributeStability stability;
|
||||
private final boolean allowMultiple;
|
||||
|
||||
protected abstract void writeBody(BufWriter buf, T attr);
|
||||
|
||||
public AbstractAttributeMapper(String name) {
|
||||
this(name, false);
|
||||
public AbstractAttributeMapper(String name, AttributeMapper.AttributeStability stability) {
|
||||
this(name, stability, false);
|
||||
}
|
||||
|
||||
public AbstractAttributeMapper(String name,
|
||||
AttributeMapper.AttributeStability stability,
|
||||
boolean allowMultiple) {
|
||||
this.name = name;
|
||||
this.stability = stability;
|
||||
this.allowMultiple = allowMultiple;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
public final String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeAttribute(BufWriter buf, T attr) {
|
||||
public final void writeAttribute(BufWriter buf, T attr) {
|
||||
buf.writeIndex(buf.constantPool().utf8Entry(name));
|
||||
buf.writeInt(0);
|
||||
int start = buf.size();
|
||||
|
@ -61,6 +71,11 @@ public abstract class AbstractAttributeMapper<T extends Attribute<T>>
|
|||
buf.patchInt(start - 4, 4, written);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttributeMapper.AttributeStability stability() {
|
||||
return stability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowMultiple() {
|
||||
return allowMultiple;
|
||||
|
@ -71,4 +86,739 @@ public abstract class AbstractAttributeMapper<T extends Attribute<T>>
|
|||
return String.format("AttributeMapper[name=%s, allowMultiple=%b, stability=%s]",
|
||||
name, allowMultiple, stability());
|
||||
}
|
||||
|
||||
public static final class AnnotationDefaultMapper extends AbstractAttributeMapper<AnnotationDefaultAttribute> {
|
||||
public static final AnnotationDefaultMapper INSTANCE = new AnnotationDefaultMapper();
|
||||
|
||||
private AnnotationDefaultMapper() {
|
||||
super(NAME_ANNOTATION_DEFAULT, AttributeStability.CP_REFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnnotationDefaultAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundAnnotationDefaultAttr(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, AnnotationDefaultAttribute attr) {
|
||||
attr.defaultValue().writeTo(buf);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class BootstrapMethodsMapper extends AbstractAttributeMapper<BootstrapMethodsAttribute> {
|
||||
public static final BootstrapMethodsMapper INSTANCE = new BootstrapMethodsMapper();
|
||||
|
||||
private BootstrapMethodsMapper() {
|
||||
super(NAME_BOOTSTRAP_METHODS, AttributeStability.CP_REFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BootstrapMethodsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundBootstrapMethodsAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, BootstrapMethodsAttribute attr) {
|
||||
buf.writeList(attr.bootstrapMethods());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CharacterRangeTableMapper extends AbstractAttributeMapper<CharacterRangeTableAttribute> {
|
||||
public static final CharacterRangeTableMapper INSTANCE = new CharacterRangeTableMapper();
|
||||
|
||||
private CharacterRangeTableMapper() {
|
||||
super(NAME_CHARACTER_RANGE_TABLE, AttributeStability.LABELS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharacterRangeTableAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundCharacterRangeTableAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, CharacterRangeTableAttribute attr) {
|
||||
List<CharacterRangeInfo> ranges = attr.characterRangeTable();
|
||||
buf.writeU2(ranges.size());
|
||||
for (CharacterRangeInfo info : ranges) {
|
||||
buf.writeU2(info.startPc());
|
||||
buf.writeU2(info.endPc());
|
||||
buf.writeInt(info.characterRangeStart());
|
||||
buf.writeInt(info.characterRangeEnd());
|
||||
buf.writeU2(info.flags());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CodeMapper extends AbstractAttributeMapper<CodeAttribute> {
|
||||
public static final CodeMapper INSTANCE = new CodeMapper();
|
||||
|
||||
private CodeMapper() {
|
||||
super(NAME_CODE, AttributeStability.CP_REFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodeAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new CodeImpl(e, cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, CodeAttribute attr) {
|
||||
throw new UnsupportedOperationException("Code attribute does not support direct write");
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CompilationIDMapper extends AbstractAttributeMapper<CompilationIDAttribute> {
|
||||
public static final CompilationIDMapper INSTANCE = new CompilationIDMapper();
|
||||
|
||||
private CompilationIDMapper() {
|
||||
super(NAME_COMPILATION_ID, AttributeStability.CP_REFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompilationIDAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundCompilationIDAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, CompilationIDAttribute attr) {
|
||||
buf.writeIndex(attr.compilationId());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ConstantValueMapper extends AbstractAttributeMapper<ConstantValueAttribute> {
|
||||
public static final ConstantValueMapper INSTANCE = new ConstantValueMapper();
|
||||
|
||||
private ConstantValueMapper() {
|
||||
super(NAME_CONSTANT_VALUE, AttributeStability.CP_REFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstantValueAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundConstantValueAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, ConstantValueAttribute attr) {
|
||||
buf.writeIndex(attr.constant());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class DeprecatedMapper extends AbstractAttributeMapper<DeprecatedAttribute> {
|
||||
public static final DeprecatedMapper INSTANCE = new DeprecatedMapper();
|
||||
|
||||
private DeprecatedMapper() {
|
||||
super(NAME_DEPRECATED, AttributeStability.STATELESS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeprecatedAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundDeprecatedAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, DeprecatedAttribute attr) {
|
||||
// empty
|
||||
}
|
||||
}
|
||||
|
||||
public static final class EnclosingMethodMapper extends AbstractAttributeMapper<EnclosingMethodAttribute> {
|
||||
public static final EnclosingMethodMapper INSTANCE = new EnclosingMethodMapper();
|
||||
|
||||
private EnclosingMethodMapper() {
|
||||
super(NAME_ENCLOSING_METHOD, AttributeStability.CP_REFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnclosingMethodAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundEnclosingMethodAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, EnclosingMethodAttribute attr) {
|
||||
buf.writeIndex(attr.enclosingClass());
|
||||
buf.writeIndexOrZero(attr.enclosingMethod().orElse(null));
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ExceptionsMapper extends AbstractAttributeMapper<ExceptionsAttribute> {
|
||||
public static final ExceptionsMapper INSTANCE = new ExceptionsMapper();
|
||||
|
||||
private ExceptionsMapper() {
|
||||
super(NAME_EXCEPTIONS, AttributeStability.CP_REFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExceptionsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundExceptionsAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, ExceptionsAttribute attr) {
|
||||
buf.writeListIndices(attr.exceptions());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class InnerClassesMapper extends AbstractAttributeMapper<InnerClassesAttribute> {
|
||||
public static final InnerClassesMapper INSTANCE = new InnerClassesMapper();
|
||||
|
||||
private InnerClassesMapper() {
|
||||
super(NAME_INNER_CLASSES, AttributeStability.CP_REFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InnerClassesAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundInnerClassesAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, InnerClassesAttribute attr) {
|
||||
List<InnerClassInfo> classes = attr.classes();
|
||||
buf.writeU2(classes.size());
|
||||
for (InnerClassInfo ic : classes) {
|
||||
buf.writeIndex(ic.innerClass());
|
||||
buf.writeIndexOrZero(ic.outerClass().orElse(null));
|
||||
buf.writeIndexOrZero(ic.innerName().orElse(null));
|
||||
buf.writeU2(ic.flagsMask());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class LineNumberTableMapper extends AbstractAttributeMapper<LineNumberTableAttribute> {
|
||||
public static final LineNumberTableMapper INSTANCE = new LineNumberTableMapper();
|
||||
|
||||
private LineNumberTableMapper() {
|
||||
super(NAME_LINE_NUMBER_TABLE, AttributeStability.LABELS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LineNumberTableAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundLineNumberTableAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, LineNumberTableAttribute attr) {
|
||||
List<LineNumberInfo> lines = attr.lineNumbers();
|
||||
buf.writeU2(lines.size());
|
||||
for (LineNumberInfo line : lines) {
|
||||
buf.writeU2(line.startPc());
|
||||
buf.writeU2(line.lineNumber());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class LocalVariableTableMapper extends AbstractAttributeMapper<LocalVariableTableAttribute> {
|
||||
public static final LocalVariableTableMapper INSTANCE = new LocalVariableTableMapper();
|
||||
|
||||
private LocalVariableTableMapper() {
|
||||
super(NAME_LOCAL_VARIABLE_TABLE, AttributeStability.LABELS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalVariableTableAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundLocalVariableTableAttribute(e, cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, LocalVariableTableAttribute attr) {
|
||||
List<LocalVariableInfo> infos = attr.localVariables();
|
||||
buf.writeU2(infos.size());
|
||||
for (LocalVariableInfo info : infos) {
|
||||
buf.writeU2(info.startPc());
|
||||
buf.writeU2(info.length());
|
||||
buf.writeIndex(info.name());
|
||||
buf.writeIndex(info.type());
|
||||
buf.writeU2(info.slot());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class LocalVariableTypeTableMapper extends AbstractAttributeMapper<LocalVariableTypeTableAttribute> {
|
||||
public static final LocalVariableTypeTableMapper INSTANCE = new LocalVariableTypeTableMapper();
|
||||
|
||||
private LocalVariableTypeTableMapper() {
|
||||
super(NAME_LOCAL_VARIABLE_TYPE_TABLE, AttributeStability.LABELS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalVariableTypeTableAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundLocalVariableTypeTableAttribute(e, cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, LocalVariableTypeTableAttribute attr) {
|
||||
List<LocalVariableTypeInfo> infos = attr.localVariableTypes();
|
||||
buf.writeU2(infos.size());
|
||||
for (LocalVariableTypeInfo info : infos) {
|
||||
buf.writeU2(info.startPc());
|
||||
buf.writeU2(info.length());
|
||||
buf.writeIndex(info.name());
|
||||
buf.writeIndex(info.signature());
|
||||
buf.writeU2(info.slot());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class MethodParametersMapper extends AbstractAttributeMapper<MethodParametersAttribute> {
|
||||
public static final MethodParametersMapper INSTANCE = new MethodParametersMapper();
|
||||
|
||||
private MethodParametersMapper() {
|
||||
super(NAME_METHOD_PARAMETERS, AttributeStability.CP_REFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodParametersAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundMethodParametersAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, MethodParametersAttribute attr) {
|
||||
List<MethodParameterInfo> parameters = attr.parameters();
|
||||
buf.writeU1(parameters.size());
|
||||
for (MethodParameterInfo info : parameters) {
|
||||
buf.writeIndexOrZero(info.name().orElse(null));
|
||||
buf.writeU2(info.flagsMask());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ModuleMapper extends AbstractAttributeMapper<ModuleAttribute> {
|
||||
public static final ModuleMapper INSTANCE = new ModuleMapper();
|
||||
|
||||
private ModuleMapper() {
|
||||
super(NAME_MODULE, AttributeStability.CP_REFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundModuleAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, ModuleAttribute attr) {
|
||||
buf.writeIndex(attr.moduleName());
|
||||
buf.writeU2(attr.moduleFlagsMask());
|
||||
buf.writeIndexOrZero(attr.moduleVersion().orElse(null));
|
||||
buf.writeU2(attr.requires().size());
|
||||
for (ModuleRequireInfo require : attr.requires()) {
|
||||
buf.writeIndex(require.requires());
|
||||
buf.writeU2(require.requiresFlagsMask());
|
||||
buf.writeIndexOrZero(require.requiresVersion().orElse(null));
|
||||
}
|
||||
buf.writeU2(attr.exports().size());
|
||||
for (ModuleExportInfo export : attr.exports()) {
|
||||
buf.writeIndex(export.exportedPackage());
|
||||
buf.writeU2(export.exportsFlagsMask());
|
||||
buf.writeListIndices(export.exportsTo());
|
||||
}
|
||||
buf.writeU2(attr.opens().size());
|
||||
for (ModuleOpenInfo open : attr.opens()) {
|
||||
buf.writeIndex(open.openedPackage());
|
||||
buf.writeU2(open.opensFlagsMask());
|
||||
buf.writeListIndices(open.opensTo());
|
||||
}
|
||||
buf.writeListIndices(attr.uses());
|
||||
buf.writeU2(attr.provides().size());
|
||||
for (ModuleProvideInfo provide : attr.provides()) {
|
||||
buf.writeIndex(provide.provides());
|
||||
buf.writeListIndices(provide.providesWith());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ModuleHashesMapper extends AbstractAttributeMapper<ModuleHashesAttribute> {
|
||||
public static final ModuleHashesMapper INSTANCE = new ModuleHashesMapper();
|
||||
|
||||
private ModuleHashesMapper() {
|
||||
super(NAME_MODULE_HASHES, AttributeStability.CP_REFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleHashesAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundModuleHashesAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, ModuleHashesAttribute attr) {
|
||||
buf.writeIndex(attr.algorithm());
|
||||
List<ModuleHashInfo> hashes = attr.hashes();
|
||||
buf.writeU2(hashes.size());
|
||||
for (ModuleHashInfo hash : hashes) {
|
||||
buf.writeIndex(hash.moduleName());
|
||||
buf.writeU2(hash.hash().length);
|
||||
buf.writeBytes(hash.hash());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ModuleMainClassMapper extends AbstractAttributeMapper<ModuleMainClassAttribute> {
|
||||
public static final ModuleMainClassMapper INSTANCE = new ModuleMainClassMapper();
|
||||
|
||||
private ModuleMainClassMapper() {
|
||||
super(NAME_MODULE_MAIN_CLASS, AttributeStability.CP_REFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleMainClassAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundModuleMainClassAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, ModuleMainClassAttribute attr) {
|
||||
buf.writeIndex(attr.mainClass());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ModulePackagesMapper extends AbstractAttributeMapper<ModulePackagesAttribute> {
|
||||
public static final ModulePackagesMapper INSTANCE = new ModulePackagesMapper();
|
||||
|
||||
private ModulePackagesMapper() {
|
||||
super(NAME_MODULE_PACKAGES, AttributeStability.CP_REFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModulePackagesAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundModulePackagesAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, ModulePackagesAttribute attr) {
|
||||
buf.writeListIndices(attr.packages());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ModuleResolutionMapper extends AbstractAttributeMapper<ModuleResolutionAttribute> {
|
||||
public static final ModuleResolutionMapper INSTANCE = new ModuleResolutionMapper();
|
||||
|
||||
private ModuleResolutionMapper() {
|
||||
super(NAME_MODULE_RESOLUTION, AttributeStability.STATELESS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleResolutionAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundModuleResolutionAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, ModuleResolutionAttribute attr) {
|
||||
buf.writeU2(attr.resolutionFlags());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ModuleTargetMapper extends AbstractAttributeMapper<ModuleTargetAttribute> {
|
||||
public static final ModuleTargetMapper INSTANCE = new ModuleTargetMapper();
|
||||
|
||||
private ModuleTargetMapper() {
|
||||
super(NAME_MODULE_TARGET, AttributeStability.CP_REFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleTargetAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundModuleTargetAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, ModuleTargetAttribute attr) {
|
||||
buf.writeIndex(attr.targetPlatform());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class NestHostMapper extends AbstractAttributeMapper<NestHostAttribute> {
|
||||
public static final NestHostMapper INSTANCE = new NestHostMapper();
|
||||
|
||||
private NestHostMapper() {
|
||||
super(NAME_NEST_HOST, AttributeStability.CP_REFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NestHostAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundNestHostAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, NestHostAttribute attr) {
|
||||
buf.writeIndex(attr.nestHost());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class NestMembersMapper extends AbstractAttributeMapper<NestMembersAttribute> {
|
||||
public static final NestMembersMapper INSTANCE = new NestMembersMapper();
|
||||
|
||||
private NestMembersMapper() {
|
||||
super(NAME_NEST_MEMBERS, AttributeStability.CP_REFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NestMembersAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundNestMembersAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, NestMembersAttribute attr) {
|
||||
buf.writeListIndices(attr.nestMembers());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class PermittedSubclassesMapper extends AbstractAttributeMapper<PermittedSubclassesAttribute> {
|
||||
public static final PermittedSubclassesMapper INSTANCE = new PermittedSubclassesMapper();
|
||||
|
||||
private PermittedSubclassesMapper() {
|
||||
super(NAME_PERMITTED_SUBCLASSES, AttributeStability.CP_REFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermittedSubclassesAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundPermittedSubclassesAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, PermittedSubclassesAttribute attr) {
|
||||
buf.writeListIndices(attr.permittedSubclasses());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class RecordMapper extends AbstractAttributeMapper<RecordAttribute> {
|
||||
public static final RecordMapper INSTANCE = new RecordMapper();
|
||||
|
||||
private RecordMapper() {
|
||||
super(NAME_RECORD, AttributeStability.CP_REFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecordAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundRecordAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, RecordAttribute attr) {
|
||||
List<RecordComponentInfo> components = attr.components();
|
||||
buf.writeU2(components.size());
|
||||
for (RecordComponentInfo info : components) {
|
||||
buf.writeIndex(info.name());
|
||||
buf.writeIndex(info.descriptor());
|
||||
buf.writeList(info.attributes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class RuntimeInvisibleAnnotationsMapper extends AbstractAttributeMapper<RuntimeInvisibleAnnotationsAttribute> {
|
||||
public static final RuntimeInvisibleAnnotationsMapper INSTANCE = new RuntimeInvisibleAnnotationsMapper();
|
||||
|
||||
private RuntimeInvisibleAnnotationsMapper() {
|
||||
super(NAME_RUNTIME_INVISIBLE_ANNOTATIONS, AttributeStability.CP_REFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuntimeInvisibleAnnotationsAttribute readAttribute(AttributedElement enclosing, ClassReader cf, int pos) {
|
||||
return new BoundAttribute.BoundRuntimeInvisibleAnnotationsAttribute(cf, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, RuntimeInvisibleAnnotationsAttribute attr) {
|
||||
buf.writeList(attr.annotations());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class RuntimeInvisibleParameterAnnotationsMapper extends AbstractAttributeMapper<RuntimeInvisibleParameterAnnotationsAttribute> {
|
||||
public static final RuntimeInvisibleParameterAnnotationsMapper INSTANCE = new RuntimeInvisibleParameterAnnotationsMapper();
|
||||
|
||||
private RuntimeInvisibleParameterAnnotationsMapper() {
|
||||
super(NAME_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS, AttributeStability.CP_REFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuntimeInvisibleParameterAnnotationsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundRuntimeInvisibleParameterAnnotationsAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, RuntimeInvisibleParameterAnnotationsAttribute attr) {
|
||||
List<List<Annotation>> lists = attr.parameterAnnotations();
|
||||
buf.writeU1(lists.size());
|
||||
for (List<Annotation> list : lists)
|
||||
buf.writeList(list);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class RuntimeInvisibleTypeAnnotationsMapper extends AbstractAttributeMapper<RuntimeInvisibleTypeAnnotationsAttribute> {
|
||||
public static final RuntimeInvisibleTypeAnnotationsMapper INSTANCE = new RuntimeInvisibleTypeAnnotationsMapper();
|
||||
|
||||
private RuntimeInvisibleTypeAnnotationsMapper() {
|
||||
super(NAME_RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, AttributeStability.UNSTABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuntimeInvisibleTypeAnnotationsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundRuntimeInvisibleTypeAnnotationsAttribute(e, cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, RuntimeInvisibleTypeAnnotationsAttribute attr) {
|
||||
buf.writeList(attr.annotations());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class RuntimeVisibleAnnotationsMapper extends AbstractAttributeMapper<RuntimeVisibleAnnotationsAttribute> {
|
||||
public static final RuntimeVisibleAnnotationsMapper INSTANCE = new RuntimeVisibleAnnotationsMapper();
|
||||
|
||||
private RuntimeVisibleAnnotationsMapper() {
|
||||
super(NAME_RUNTIME_VISIBLE_ANNOTATIONS, AttributeStability.CP_REFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuntimeVisibleAnnotationsAttribute readAttribute(AttributedElement enclosing, ClassReader cf, int pos) {
|
||||
return new BoundAttribute.BoundRuntimeVisibleAnnotationsAttribute(cf, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, RuntimeVisibleAnnotationsAttribute attr) {
|
||||
buf.writeList(attr.annotations());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class RuntimeVisibleParameterAnnotationsMapper extends AbstractAttributeMapper<RuntimeVisibleParameterAnnotationsAttribute> {
|
||||
public static final RuntimeVisibleParameterAnnotationsMapper INSTANCE = new RuntimeVisibleParameterAnnotationsMapper();
|
||||
|
||||
private RuntimeVisibleParameterAnnotationsMapper() {
|
||||
super(NAME_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS, AttributeStability.CP_REFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuntimeVisibleParameterAnnotationsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundRuntimeVisibleParameterAnnotationsAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, RuntimeVisibleParameterAnnotationsAttribute attr) {
|
||||
List<List<Annotation>> lists = attr.parameterAnnotations();
|
||||
buf.writeU1(lists.size());
|
||||
for (List<Annotation> list : lists)
|
||||
buf.writeList(list);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class RuntimeVisibleTypeAnnotationsMapper extends AbstractAttributeMapper<RuntimeVisibleTypeAnnotationsAttribute> {
|
||||
public static final RuntimeVisibleTypeAnnotationsMapper INSTANCE = new RuntimeVisibleTypeAnnotationsMapper();
|
||||
|
||||
private RuntimeVisibleTypeAnnotationsMapper() {
|
||||
super(NAME_RUNTIME_VISIBLE_TYPE_ANNOTATIONS, AttributeStability.UNSTABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuntimeVisibleTypeAnnotationsAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundRuntimeVisibleTypeAnnotationsAttribute(e, cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, RuntimeVisibleTypeAnnotationsAttribute attr) {
|
||||
buf.writeList(attr.annotations());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class SignatureMapper extends AbstractAttributeMapper<SignatureAttribute> {
|
||||
public static final SignatureMapper INSTANCE = new SignatureMapper();
|
||||
|
||||
private SignatureMapper() {
|
||||
super(NAME_SIGNATURE, AttributeStability.CP_REFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SignatureAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundSignatureAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, SignatureAttribute attr) {
|
||||
buf.writeIndex(attr.signature());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class SourceDebugExtensionMapper extends AbstractAttributeMapper<SourceDebugExtensionAttribute> {
|
||||
public static final SourceDebugExtensionMapper INSTANCE = new SourceDebugExtensionMapper();
|
||||
|
||||
private SourceDebugExtensionMapper() {
|
||||
super(NAME_SOURCE_DEBUG_EXTENSION, AttributeStability.STATELESS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceDebugExtensionAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundSourceDebugExtensionAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, SourceDebugExtensionAttribute attr) {
|
||||
buf.writeBytes(attr.contents());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class SourceFileMapper extends AbstractAttributeMapper<SourceFileAttribute> {
|
||||
public static final SourceFileMapper INSTANCE = new SourceFileMapper();
|
||||
|
||||
private SourceFileMapper() {
|
||||
super(NAME_SOURCE_FILE, AttributeStability.CP_REFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceFileAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundSourceFileAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, SourceFileAttribute attr) {
|
||||
buf.writeIndex(attr.sourceFile());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class SourceIDMapper extends AbstractAttributeMapper<SourceIDAttribute> {
|
||||
public static final SourceIDMapper INSTANCE = new SourceIDMapper();
|
||||
|
||||
private SourceIDMapper() {
|
||||
super(NAME_SOURCE_ID, AttributeStability.CP_REFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceIDAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundSourceIDAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, SourceIDAttribute attr) {
|
||||
buf.writeIndex(attr.sourceId());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class StackMapTableMapper extends AbstractAttributeMapper<StackMapTableAttribute> {
|
||||
public static final StackMapTableMapper INSTANCE = new StackMapTableMapper();
|
||||
|
||||
private StackMapTableMapper() {
|
||||
super(NAME_STACK_MAP_TABLE, AttributeStability.LABELS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackMapTableAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundStackMapTableAttribute((CodeImpl)e, cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter b, StackMapTableAttribute attr) {
|
||||
StackMapDecoder.writeFrames(b, attr.entries());
|
||||
}
|
||||
}
|
||||
|
||||
public static final class SyntheticMapper extends AbstractAttributeMapper<SyntheticAttribute> {
|
||||
public static final SyntheticMapper INSTANCE = new SyntheticMapper();
|
||||
|
||||
private SyntheticMapper() {
|
||||
super(NAME_SYNTHETIC, AttributeStability.STATELESS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SyntheticAttribute readAttribute(AttributedElement e, ClassReader cf, int p) {
|
||||
return new BoundAttribute.BoundSyntheticAttribute(cf, this, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeBody(BufWriter buf, SyntheticAttribute attr) {
|
||||
// empty
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,8 @@ import java.lang.classfile.constantpool.PackageEntry;
|
|||
import java.lang.classfile.constantpool.Utf8Entry;
|
||||
import jdk.internal.access.SharedSecrets;
|
||||
|
||||
import static java.lang.classfile.Attributes.*;
|
||||
|
||||
public abstract sealed class BoundAttribute<T extends Attribute<T>>
|
||||
extends AbstractElement
|
||||
implements Attribute<T> {
|
||||
|
@ -140,7 +142,7 @@ public abstract sealed class BoundAttribute<T extends Attribute<T>>
|
|||
throw new IllegalArgumentException("attribute " + name.stringValue() + " too big to handle");
|
||||
}
|
||||
|
||||
var mapper = Attributes.standardAttribute(name);
|
||||
var mapper = standardAttribute(name);
|
||||
if (mapper == null) {
|
||||
mapper = customAttributes.apply(name);
|
||||
}
|
||||
|
@ -889,7 +891,7 @@ public abstract sealed class BoundAttribute<T extends Attribute<T>>
|
|||
|
||||
public BoundRuntimeInvisibleAnnotationsAttribute(ClassReader cf,
|
||||
int payloadStart) {
|
||||
super(cf, Attributes.RUNTIME_INVISIBLE_ANNOTATIONS, payloadStart);
|
||||
super(cf, Attributes.runtimeInvisibleAnnotations(), payloadStart);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -907,7 +909,7 @@ public abstract sealed class BoundAttribute<T extends Attribute<T>>
|
|||
|
||||
public BoundRuntimeVisibleAnnotationsAttribute(ClassReader cf,
|
||||
int payloadStart) {
|
||||
super(cf, Attributes.RUNTIME_VISIBLE_ANNOTATIONS, payloadStart);
|
||||
super(cf, Attributes.runtimeVisibleAnnotations(), payloadStart);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -983,4 +985,88 @@ public abstract sealed class BoundAttribute<T extends Attribute<T>>
|
|||
return classReader.readBytes(payloadStart + 8, codeLength());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the attribute mapper for a standard attribute}
|
||||
*
|
||||
* @param name the name of the attribute to find
|
||||
*/
|
||||
public static AttributeMapper<?> standardAttribute(Utf8Entry name) {
|
||||
// critical bootstrap path, so no lambdas nor method handles here
|
||||
return switch (name.hashCode()) {
|
||||
case 0x78147009 ->
|
||||
name.equalsString(NAME_ANNOTATION_DEFAULT) ? annotationDefault() : null;
|
||||
case 0x665e3a3a ->
|
||||
name.equalsString(NAME_BOOTSTRAP_METHODS) ? bootstrapMethods() : null;
|
||||
case 0xcb7e162 ->
|
||||
name.equalsString(NAME_CHARACTER_RANGE_TABLE) ? characterRangeTable() : null;
|
||||
case 0x21e41e7e ->
|
||||
name.equalsString(NAME_CODE) ? code() : null;
|
||||
case 0x5a306b41 ->
|
||||
name.equalsString(NAME_COMPILATION_ID) ? compilationId() : null;
|
||||
case 0x3e191c7c ->
|
||||
name.equalsString(NAME_CONSTANT_VALUE) ? constantValue() : null;
|
||||
case 0x5e88ed0c ->
|
||||
name.equalsString(NAME_DEPRECATED) ? deprecated() : null;
|
||||
case 0x7284695e ->
|
||||
name.equalsString(NAME_ENCLOSING_METHOD) ? enclosingMethod() : null;
|
||||
case 0x21df25db ->
|
||||
name.equalsString(NAME_EXCEPTIONS) ? exceptions() : null;
|
||||
case 0x11392da9 ->
|
||||
name.equalsString(NAME_INNER_CLASSES) ? innerClasses() : null;
|
||||
case 0x167536fc ->
|
||||
name.equalsString(NAME_LINE_NUMBER_TABLE) ? lineNumberTable() : null;
|
||||
case 0x46939abc ->
|
||||
name.equalsString(NAME_LOCAL_VARIABLE_TABLE) ? localVariableTable() : null;
|
||||
case 0x63ee67f4 ->
|
||||
name.equalsString(NAME_LOCAL_VARIABLE_TYPE_TABLE) ? localVariableTypeTable() : null;
|
||||
case 0x2b597e15 ->
|
||||
name.equalsString(NAME_METHOD_PARAMETERS) ? methodParameters() : null;
|
||||
case 0x19f20ade ->
|
||||
name.equalsString(NAME_MODULE) ? module() : null;
|
||||
case 0x47f6395e ->
|
||||
name.equalsString(NAME_MODULE_HASHES) ? moduleHashes() : null;
|
||||
case 0x54db809 ->
|
||||
name.equalsString(NAME_MODULE_MAIN_CLASS) ? moduleMainClass() : null;
|
||||
case 0x1abd1c2c ->
|
||||
name.equalsString(NAME_MODULE_PACKAGES) ? modulePackages() : null;
|
||||
case 0x6ba46dd ->
|
||||
name.equalsString(NAME_MODULE_RESOLUTION) ? moduleResolution() : null;
|
||||
case 0x46f7d91d ->
|
||||
name.equalsString(NAME_MODULE_TARGET) ? moduleTarget() : null;
|
||||
case 0x5137f53 ->
|
||||
name.equalsString(NAME_NEST_HOST) ? nestHost() : null;
|
||||
case 0x4a8fa3b6 ->
|
||||
name.equalsString(NAME_NEST_MEMBERS) ? nestMembers() : null;
|
||||
case 0x55c73cb6 ->
|
||||
name.equalsString(NAME_PERMITTED_SUBCLASSES) ? permittedSubclasses() : null;
|
||||
case 0x3fe76d4e ->
|
||||
name.equalsString(NAME_RECORD) ? record() : null;
|
||||
case 0x180d6925 ->
|
||||
name.equalsString(NAME_RUNTIME_INVISIBLE_ANNOTATIONS) ? runtimeInvisibleAnnotations() : null;
|
||||
case 0x7be22752 ->
|
||||
name.equalsString(NAME_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS) ? runtimeInvisibleParameterAnnotations() : null;
|
||||
case 0x5299824 ->
|
||||
name.equalsString(NAME_RUNTIME_INVISIBLE_TYPE_ANNOTATIONS) ? runtimeInvisibleTypeAnnotations() : null;
|
||||
case 0x3534786e ->
|
||||
name.equalsString(NAME_RUNTIME_VISIBLE_ANNOTATIONS) ? runtimeVisibleAnnotations() : null;
|
||||
case 0xb4b4ac6 ->
|
||||
name.equalsString(NAME_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS) ? runtimeVisibleParameterAnnotations() : null;
|
||||
case 0x6926482 ->
|
||||
name.equalsString(NAME_RUNTIME_VISIBLE_TYPE_ANNOTATIONS) ? runtimeVisibleTypeAnnotations() : null;
|
||||
case 0x16a42b7c ->
|
||||
name.equalsString(NAME_SIGNATURE) ? signature() : null;
|
||||
case 0x400ab245 ->
|
||||
name.equalsString(NAME_SOURCE_DEBUG_EXTENSION) ? sourceDebugExtension() : null;
|
||||
case 0x2af490d4 ->
|
||||
name.equalsString(NAME_SOURCE_FILE) ? sourceFile() : null;
|
||||
case 0x303e0c58 ->
|
||||
name.equalsString(NAME_SOURCE_ID) ? sourceId() : null;
|
||||
case 0x19c7d0cd ->
|
||||
name.equalsString(NAME_STACK_MAP_TABLE) ? stackMapTable() : null;
|
||||
case 0x3dc79b7a ->
|
||||
name.equalsString(NAME_SYNTHETIC) ? synthetic() : null;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,32 +24,36 @@
|
|||
*/
|
||||
package jdk.internal.classfile.impl;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import java.lang.classfile.ClassBuilder;
|
||||
import java.lang.classfile.constantpool.ClassEntry;
|
||||
import java.lang.reflect.AccessFlag;
|
||||
import java.lang.classfile.AccessFlags;
|
||||
import java.lang.classfile.Attribute;
|
||||
import java.lang.classfile.AttributeMapper;
|
||||
import java.lang.classfile.Attributes;
|
||||
import java.lang.classfile.ClassElement;
|
||||
import java.lang.classfile.ClassModel;
|
||||
import java.lang.classfile.ClassReader;
|
||||
import java.lang.classfile.ClassTransform;
|
||||
import java.lang.classfile.ClassFile;
|
||||
import java.lang.classfile.ClassFileVersion;
|
||||
import java.lang.classfile.CustomAttribute;
|
||||
import java.lang.classfile.constantpool.ConstantPool;
|
||||
import java.lang.classfile.constantpool.ConstantPoolBuilder;
|
||||
import java.lang.classfile.FieldModel;
|
||||
import java.lang.classfile.Interfaces;
|
||||
import java.lang.classfile.MethodModel;
|
||||
import java.lang.classfile.Superclass;
|
||||
import java.lang.classfile.attribute.InnerClassesAttribute;
|
||||
import java.lang.classfile.attribute.ModuleAttribute;
|
||||
import java.lang.classfile.attribute.ModuleHashesAttribute;
|
||||
import java.lang.classfile.attribute.ModuleMainClassAttribute;
|
||||
import java.lang.classfile.attribute.ModulePackagesAttribute;
|
||||
import java.lang.classfile.attribute.ModuleResolutionAttribute;
|
||||
import java.lang.classfile.attribute.ModuleTargetAttribute;
|
||||
import java.lang.classfile.attribute.RuntimeInvisibleAnnotationsAttribute;
|
||||
import java.lang.classfile.attribute.RuntimeVisibleAnnotationsAttribute;
|
||||
import java.lang.classfile.attribute.SourceDebugExtensionAttribute;
|
||||
import java.lang.classfile.attribute.SourceFileAttribute;
|
||||
import jdk.internal.access.SharedSecrets;
|
||||
|
||||
public final class ClassImpl
|
||||
|
@ -202,28 +206,21 @@ public final class ClassImpl
|
|||
}
|
||||
|
||||
private boolean verifyModuleAttributes() {
|
||||
if (findAttribute(Attributes.MODULE).isEmpty())
|
||||
if (findAttribute(Attributes.module()).isEmpty())
|
||||
return false;
|
||||
|
||||
Set<AttributeMapper<?>> found = attributes().stream()
|
||||
.map(Attribute::attributeMapper)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
found.removeAll(allowedModuleAttributes);
|
||||
found.retainAll(Attributes.PREDEFINED_ATTRIBUTES);
|
||||
return found.isEmpty();
|
||||
return attributes().stream().allMatch(a ->
|
||||
a instanceof ModuleAttribute
|
||||
|| a instanceof ModulePackagesAttribute
|
||||
|| a instanceof ModuleHashesAttribute
|
||||
|| a instanceof ModuleMainClassAttribute
|
||||
|| a instanceof ModuleResolutionAttribute
|
||||
|| a instanceof ModuleTargetAttribute
|
||||
|| a instanceof InnerClassesAttribute
|
||||
|| a instanceof SourceFileAttribute
|
||||
|| a instanceof SourceDebugExtensionAttribute
|
||||
|| a instanceof RuntimeVisibleAnnotationsAttribute
|
||||
|| a instanceof RuntimeInvisibleAnnotationsAttribute
|
||||
|| a instanceof CustomAttribute);
|
||||
}
|
||||
|
||||
private static final Set<AttributeMapper<?>> allowedModuleAttributes
|
||||
= Set.of(Attributes.MODULE,
|
||||
Attributes.MODULE_HASHES,
|
||||
Attributes.MODULE_MAIN_CLASS,
|
||||
Attributes.MODULE_PACKAGES,
|
||||
Attributes.MODULE_RESOLUTION,
|
||||
Attributes.MODULE_TARGET,
|
||||
Attributes.INNER_CLASSES,
|
||||
Attributes.SOURCE_FILE,
|
||||
Attributes.SOURCE_DEBUG_EXTENSION,
|
||||
Attributes.RUNTIME_VISIBLE_ANNOTATIONS,
|
||||
Attributes.RUNTIME_INVISIBLE_ANNOTATIONS);
|
||||
}
|
||||
|
|
|
@ -290,7 +290,7 @@ public final class ClassReaderImpl
|
|||
|
||||
if (bootstrapMethodsAttribute == null) {
|
||||
bootstrapMethodsAttribute
|
||||
= containedClass.findAttribute(Attributes.BOOTSTRAP_METHODS)
|
||||
= containedClass.findAttribute(Attributes.bootstrapMethods())
|
||||
.orElse(new UnboundAttribute.EmptyBootstrapAttribute());
|
||||
}
|
||||
|
||||
|
@ -324,7 +324,7 @@ public final class ClassReaderImpl
|
|||
|
||||
boolean writeBootstrapMethods(BufWriter buf) {
|
||||
Optional<BootstrapMethodsAttribute> a
|
||||
= containedClass.findAttribute(Attributes.BOOTSTRAP_METHODS);
|
||||
= containedClass.findAttribute(Attributes.bootstrapMethods());
|
||||
if (a.isEmpty())
|
||||
return false;
|
||||
a.get().writeTo(buf);
|
||||
|
|
|
@ -230,7 +230,7 @@ public final class CodeImpl
|
|||
|
||||
private void inflateLineNumbers() {
|
||||
for (Attribute<?> a : attributes()) {
|
||||
if (a.attributeMapper() == Attributes.LINE_NUMBER_TABLE) {
|
||||
if (a.attributeMapper() == Attributes.lineNumberTable()) {
|
||||
BoundLineNumberTableAttribute attr = (BoundLineNumberTableAttribute) a;
|
||||
if (lineNumbers == null)
|
||||
lineNumbers = new int[codeLength + 1];
|
||||
|
@ -252,7 +252,7 @@ public final class CodeImpl
|
|||
}
|
||||
|
||||
private void inflateJumpTargets() {
|
||||
Optional<StackMapTableAttribute> a = findAttribute(Attributes.STACK_MAP_TABLE);
|
||||
Optional<StackMapTableAttribute> a = findAttribute(Attributes.stackMapTable());
|
||||
if (a.isEmpty()) {
|
||||
if (classReader.readU2(6) <= ClassFile.JAVA_6_VERSION) {
|
||||
//fallback to jump targets inflation without StackMapTableAttribute
|
||||
|
@ -325,8 +325,8 @@ public final class CodeImpl
|
|||
}
|
||||
|
||||
private void inflateTypeAnnotations() {
|
||||
findAttribute(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS).ifPresent(RuntimeVisibleTypeAnnotationsAttribute::annotations);
|
||||
findAttribute(Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS).ifPresent(RuntimeInvisibleTypeAnnotationsAttribute::annotations);
|
||||
findAttribute(Attributes.runtimeVisibleTypeAnnotations()).ifPresent(RuntimeVisibleTypeAnnotationsAttribute::annotations);
|
||||
findAttribute(Attributes.runtimeInvisibleTypeAnnotations()).ifPresent(RuntimeInvisibleTypeAnnotationsAttribute::annotations);
|
||||
}
|
||||
|
||||
private void generateCatchTargets(Consumer<CodeElement> consumer) {
|
||||
|
@ -345,7 +345,7 @@ public final class CodeImpl
|
|||
|
||||
private void generateDebugElements(Consumer<CodeElement> consumer) {
|
||||
for (Attribute<?> a : attributes()) {
|
||||
if (a.attributeMapper() == Attributes.CHARACTER_RANGE_TABLE) {
|
||||
if (a.attributeMapper() == Attributes.characterRangeTable()) {
|
||||
var attr = (BoundCharacterRangeTableAttribute) a;
|
||||
int cnt = classReader.readU2(attr.payloadStart);
|
||||
int p = attr.payloadStart + 2;
|
||||
|
@ -357,7 +357,7 @@ public final class CodeImpl
|
|||
consumer.accept(instruction);
|
||||
}
|
||||
}
|
||||
else if (a.attributeMapper() == Attributes.LOCAL_VARIABLE_TABLE) {
|
||||
else if (a.attributeMapper() == Attributes.localVariableTable()) {
|
||||
var attr = (BoundLocalVariableTableAttribute) a;
|
||||
int cnt = classReader.readU2(attr.payloadStart);
|
||||
int p = attr.payloadStart + 2;
|
||||
|
@ -369,7 +369,7 @@ public final class CodeImpl
|
|||
consumer.accept(instruction);
|
||||
}
|
||||
}
|
||||
else if (a.attributeMapper() == Attributes.LOCAL_VARIABLE_TYPE_TABLE) {
|
||||
else if (a.attributeMapper() == Attributes.localVariableTypeTable()) {
|
||||
var attr = (BoundLocalVariableTypeTableAttribute) a;
|
||||
int cnt = classReader.readU2(attr.payloadStart);
|
||||
int p = attr.payloadStart + 2;
|
||||
|
@ -381,10 +381,10 @@ public final class CodeImpl
|
|||
consumer.accept(instruction);
|
||||
}
|
||||
}
|
||||
else if (a.attributeMapper() == Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS) {
|
||||
else if (a.attributeMapper() == Attributes.runtimeVisibleTypeAnnotations()) {
|
||||
consumer.accept((BoundRuntimeVisibleTypeAnnotationsAttribute) a);
|
||||
}
|
||||
else if (a.attributeMapper() == Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS) {
|
||||
else if (a.attributeMapper() == Attributes.runtimeInvisibleTypeAnnotations()) {
|
||||
consumer.accept((BoundRuntimeInvisibleTypeAnnotationsAttribute) a);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -230,7 +230,7 @@ public final class DirectCodeBuilder
|
|||
|
||||
if (context.debugElementsOption() == ClassFile.DebugElementsOption.PASS_DEBUG) {
|
||||
if (!characterRanges.isEmpty()) {
|
||||
Attribute<?> a = new UnboundAttribute.AdHocAttribute<>(Attributes.CHARACTER_RANGE_TABLE) {
|
||||
Attribute<?> a = new UnboundAttribute.AdHocAttribute<>(Attributes.characterRangeTable()) {
|
||||
|
||||
@Override
|
||||
public void writeBody(BufWriter b) {
|
||||
|
@ -262,7 +262,7 @@ public final class DirectCodeBuilder
|
|||
}
|
||||
|
||||
if (!localVariables.isEmpty()) {
|
||||
Attribute<?> a = new UnboundAttribute.AdHocAttribute<>(Attributes.LOCAL_VARIABLE_TABLE) {
|
||||
Attribute<?> a = new UnboundAttribute.AdHocAttribute<>(Attributes.localVariableTable()) {
|
||||
@Override
|
||||
public void writeBody(BufWriter b) {
|
||||
int pos = b.size();
|
||||
|
@ -285,7 +285,7 @@ public final class DirectCodeBuilder
|
|||
}
|
||||
|
||||
if (!localVariableTypes.isEmpty()) {
|
||||
Attribute<?> a = new UnboundAttribute.AdHocAttribute<>(Attributes.LOCAL_VARIABLE_TYPE_TABLE) {
|
||||
Attribute<?> a = new UnboundAttribute.AdHocAttribute<>(Attributes.localVariableTypeTable()) {
|
||||
@Override
|
||||
public void writeBody(BufWriter b) {
|
||||
int pos = b.size();
|
||||
|
@ -312,7 +312,7 @@ public final class DirectCodeBuilder
|
|||
attributes.withAttribute(lineNumberWriter);
|
||||
}
|
||||
|
||||
content = new UnboundAttribute.AdHocAttribute<>(Attributes.CODE) {
|
||||
content = new UnboundAttribute.AdHocAttribute<>(Attributes.code()) {
|
||||
|
||||
private void writeCounters(boolean codeMatch, BufWriterImpl buf) {
|
||||
if (codeMatch) {
|
||||
|
@ -368,7 +368,7 @@ public final class DirectCodeBuilder
|
|||
if (codeAndExceptionsMatch(codeLength)) {
|
||||
switch (context.stackMapsOption()) {
|
||||
case STACK_MAPS_WHEN_REQUIRED -> {
|
||||
attributes.withAttribute(original.findAttribute(Attributes.STACK_MAP_TABLE).orElse(null));
|
||||
attributes.withAttribute(original.findAttribute(Attributes.stackMapTable()).orElse(null));
|
||||
writeCounters(true, buf);
|
||||
}
|
||||
case GENERATE_STACK_MAPS ->
|
||||
|
@ -401,7 +401,7 @@ public final class DirectCodeBuilder
|
|||
private int lastPc, lastLine, writtenLine;
|
||||
|
||||
public DedupLineNumberTableAttribute(ConstantPoolBuilder constantPool, ClassFileImpl context) {
|
||||
super(Attributes.LINE_NUMBER_TABLE);
|
||||
super(Attributes.lineNumberTable());
|
||||
buf = new BufWriterImpl(constantPool, context);
|
||||
lastPc = -1;
|
||||
writtenLine = -1;
|
||||
|
|
|
@ -118,7 +118,7 @@ public final class MethodImpl
|
|||
|
||||
@Override
|
||||
public Optional<CodeModel> code() {
|
||||
return findAttribute(Attributes.CODE).map(a -> (CodeModel) a);
|
||||
return findAttribute(Attributes.code()).map(a -> (CodeModel) a);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -144,7 +144,7 @@ public final class SplitConstantPool implements ConstantPoolBuilder {
|
|||
}
|
||||
else {
|
||||
Attribute<BootstrapMethodsAttribute> a
|
||||
= new UnboundAttribute.AdHocAttribute<>(Attributes.BOOTSTRAP_METHODS) {
|
||||
= new UnboundAttribute.AdHocAttribute<>(Attributes.bootstrapMethods()) {
|
||||
|
||||
@Override
|
||||
public void writeBody(BufWriter b) {
|
||||
|
|
|
@ -380,7 +380,7 @@ public final class StackMapGenerator {
|
|||
* @return <code>StackMapTableAttribute</code> or null if stack map is empty
|
||||
*/
|
||||
public Attribute<? extends StackMapTableAttribute> stackMapTableAttribute() {
|
||||
return frames.isEmpty() ? null : new UnboundAttribute.AdHocAttribute<>(Attributes.STACK_MAP_TABLE) {
|
||||
return frames.isEmpty() ? null : new UnboundAttribute.AdHocAttribute<>(Attributes.stackMapTable()) {
|
||||
@Override
|
||||
public void writeBody(BufWriter b) {
|
||||
b.writeU2(frames.size());
|
||||
|
|
|
@ -149,7 +149,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final ConstantValueEntry entry;
|
||||
|
||||
public UnboundConstantValueAttribute(ConstantValueEntry entry) {
|
||||
super(Attributes.CONSTANT_VALUE);
|
||||
super(Attributes.constantValue());
|
||||
this.entry = entry;
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
extends UnboundAttribute<DeprecatedAttribute>
|
||||
implements DeprecatedAttribute {
|
||||
public UnboundDeprecatedAttribute() {
|
||||
super(Attributes.DEPRECATED);
|
||||
super(Attributes.deprecated());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,7 +172,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
extends UnboundAttribute<SyntheticAttribute>
|
||||
implements SyntheticAttribute {
|
||||
public UnboundSyntheticAttribute() {
|
||||
super(Attributes.SYNTHETIC);
|
||||
super(Attributes.synthetic());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -182,7 +182,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final Utf8Entry signature;
|
||||
|
||||
public UnboundSignatureAttribute(Utf8Entry signature) {
|
||||
super(Attributes.SIGNATURE);
|
||||
super(Attributes.signature());
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
|
@ -198,7 +198,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final List<ClassEntry> exceptions;
|
||||
|
||||
public UnboundExceptionsAttribute(List<ClassEntry> exceptions) {
|
||||
super(Attributes.EXCEPTIONS);
|
||||
super(Attributes.exceptions());
|
||||
this.exceptions = List.copyOf(exceptions);
|
||||
}
|
||||
|
||||
|
@ -214,7 +214,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final AnnotationValue annotationDefault;
|
||||
|
||||
public UnboundAnnotationDefaultAttribute(AnnotationValue annotationDefault) {
|
||||
super(Attributes.ANNOTATION_DEFAULT);
|
||||
super(Attributes.annotationDefault());
|
||||
this.annotationDefault = annotationDefault;
|
||||
}
|
||||
|
||||
|
@ -229,7 +229,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final Utf8Entry sourceFile;
|
||||
|
||||
public UnboundSourceFileAttribute(Utf8Entry sourceFile) {
|
||||
super(Attributes.SOURCE_FILE);
|
||||
super(Attributes.sourceFile());
|
||||
this.sourceFile = sourceFile;
|
||||
}
|
||||
|
||||
|
@ -245,7 +245,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final List<StackMapFrameInfo> entries;
|
||||
|
||||
public UnboundStackMapTableAttribute(List<StackMapFrameInfo> entries) {
|
||||
super(Attributes.STACK_MAP_TABLE);
|
||||
super(Attributes.stackMapTable());
|
||||
this.entries = List.copyOf(entries);
|
||||
}
|
||||
|
||||
|
@ -261,7 +261,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final List<InnerClassInfo> innerClasses;
|
||||
|
||||
public UnboundInnerClassesAttribute(List<InnerClassInfo> innerClasses) {
|
||||
super(Attributes.INNER_CLASSES);
|
||||
super(Attributes.innerClasses());
|
||||
this.innerClasses = List.copyOf(innerClasses);
|
||||
}
|
||||
|
||||
|
@ -277,7 +277,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final List<RecordComponentInfo> components;
|
||||
|
||||
public UnboundRecordAttribute(List<RecordComponentInfo> components) {
|
||||
super(Attributes.RECORD);
|
||||
super(Attributes.record());
|
||||
this.components = List.copyOf(components);
|
||||
}
|
||||
|
||||
|
@ -294,7 +294,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final NameAndTypeEntry method;
|
||||
|
||||
public UnboundEnclosingMethodAttribute(ClassEntry classEntry, NameAndTypeEntry method) {
|
||||
super(Attributes.ENCLOSING_METHOD);
|
||||
super(Attributes.enclosingMethod());
|
||||
this.classEntry = classEntry;
|
||||
this.method = method;
|
||||
}
|
||||
|
@ -316,7 +316,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final List<MethodParameterInfo> parameters;
|
||||
|
||||
public UnboundMethodParametersAttribute(List<MethodParameterInfo> parameters) {
|
||||
super(Attributes.METHOD_PARAMETERS);
|
||||
super(Attributes.methodParameters());
|
||||
this.parameters = List.copyOf(parameters);
|
||||
}
|
||||
|
||||
|
@ -332,7 +332,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
final Utf8Entry moduleTarget;
|
||||
|
||||
public UnboundModuleTargetAttribute(Utf8Entry moduleTarget) {
|
||||
super(Attributes.MODULE_TARGET);
|
||||
super(Attributes.moduleTarget());
|
||||
this.moduleTarget = moduleTarget;
|
||||
}
|
||||
|
||||
|
@ -348,7 +348,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
final ClassEntry mainClass;
|
||||
|
||||
public UnboundModuleMainClassAttribute(ClassEntry mainClass) {
|
||||
super(Attributes.MODULE_MAIN_CLASS);
|
||||
super(Attributes.moduleMainClass());
|
||||
this.mainClass = mainClass;
|
||||
}
|
||||
|
||||
|
@ -365,7 +365,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final List<ModuleHashInfo> hashes;
|
||||
|
||||
public UnboundModuleHashesAttribute(Utf8Entry algorithm, List<ModuleHashInfo> hashes) {
|
||||
super(Attributes.MODULE_HASHES);
|
||||
super(Attributes.moduleHashes());
|
||||
this.algorithm = algorithm;
|
||||
this.hashes = List.copyOf(hashes);
|
||||
}
|
||||
|
@ -387,7 +387,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final Collection<PackageEntry> packages;
|
||||
|
||||
public UnboundModulePackagesAttribute(Collection<PackageEntry> packages) {
|
||||
super(Attributes.MODULE_PACKAGES);
|
||||
super(Attributes.modulePackages());
|
||||
this.packages = List.copyOf(packages);
|
||||
}
|
||||
|
||||
|
@ -403,7 +403,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final int resolutionFlags;
|
||||
|
||||
public UnboundModuleResolutionAttribute(int flags) {
|
||||
super(Attributes.MODULE_RESOLUTION);
|
||||
super(Attributes.moduleResolution());
|
||||
resolutionFlags = flags;
|
||||
}
|
||||
|
||||
|
@ -419,7 +419,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final List<ClassEntry> permittedSubclasses;
|
||||
|
||||
public UnboundPermittedSubclassesAttribute(List<ClassEntry> permittedSubclasses) {
|
||||
super(Attributes.PERMITTED_SUBCLASSES);
|
||||
super(Attributes.permittedSubclasses());
|
||||
this.permittedSubclasses = List.copyOf(permittedSubclasses);
|
||||
}
|
||||
|
||||
|
@ -435,7 +435,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final List<ClassEntry> memberEntries;
|
||||
|
||||
public UnboundNestMembersAttribute(List<ClassEntry> memberEntries) {
|
||||
super(Attributes.NEST_MEMBERS);
|
||||
super(Attributes.nestMembers());
|
||||
this.memberEntries = List.copyOf(memberEntries);
|
||||
}
|
||||
|
||||
|
@ -451,7 +451,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final ClassEntry hostEntry;
|
||||
|
||||
public UnboundNestHostAttribute(ClassEntry hostEntry) {
|
||||
super(Attributes.NEST_HOST);
|
||||
super(Attributes.nestHost());
|
||||
this.hostEntry = hostEntry;
|
||||
}
|
||||
|
||||
|
@ -467,7 +467,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final Utf8Entry idEntry;
|
||||
|
||||
public UnboundCompilationIDAttribute(Utf8Entry idEntry) {
|
||||
super(Attributes.COMPILATION_ID);
|
||||
super(Attributes.compilationId());
|
||||
this.idEntry = idEntry;
|
||||
}
|
||||
|
||||
|
@ -483,7 +483,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final Utf8Entry idEntry;
|
||||
|
||||
public UnboundSourceIDAttribute(Utf8Entry idEntry) {
|
||||
super(Attributes.SOURCE_ID);
|
||||
super(Attributes.sourceId());
|
||||
this.idEntry = idEntry;
|
||||
}
|
||||
|
||||
|
@ -499,7 +499,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final byte[] contents;
|
||||
|
||||
public UnboundSourceDebugExtensionAttribute(byte[] contents) {
|
||||
super(Attributes.SOURCE_DEBUG_EXTENSION);
|
||||
super(Attributes.sourceDebugExtension());
|
||||
this.contents = contents;
|
||||
}
|
||||
|
||||
|
@ -515,7 +515,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final List<CharacterRangeInfo> ranges;
|
||||
|
||||
public UnboundCharacterRangeTableAttribute(List<CharacterRangeInfo> ranges) {
|
||||
super(Attributes.CHARACTER_RANGE_TABLE);
|
||||
super(Attributes.characterRangeTable());
|
||||
this.ranges = List.copyOf(ranges);
|
||||
}
|
||||
|
||||
|
@ -531,7 +531,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final List<LineNumberInfo> lines;
|
||||
|
||||
public UnboundLineNumberTableAttribute(List<LineNumberInfo> lines) {
|
||||
super(Attributes.LINE_NUMBER_TABLE);
|
||||
super(Attributes.lineNumberTable());
|
||||
this.lines = List.copyOf(lines);
|
||||
}
|
||||
|
||||
|
@ -547,7 +547,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final List<LocalVariableInfo> locals;
|
||||
|
||||
public UnboundLocalVariableTableAttribute(List<LocalVariableInfo> locals) {
|
||||
super(Attributes.LOCAL_VARIABLE_TABLE);
|
||||
super(Attributes.localVariableTable());
|
||||
this.locals = List.copyOf(locals);
|
||||
}
|
||||
|
||||
|
@ -563,7 +563,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final List<LocalVariableTypeInfo> locals;
|
||||
|
||||
public UnboundLocalVariableTypeTableAttribute(List<LocalVariableTypeInfo> locals) {
|
||||
super(Attributes.LOCAL_VARIABLE_TYPE_TABLE);
|
||||
super(Attributes.localVariableTypeTable());
|
||||
this.locals = List.copyOf(locals);
|
||||
}
|
||||
|
||||
|
@ -579,7 +579,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final List<Annotation> elements;
|
||||
|
||||
public UnboundRuntimeVisibleAnnotationsAttribute(List<Annotation> elements) {
|
||||
super(Attributes.RUNTIME_VISIBLE_ANNOTATIONS);
|
||||
super(Attributes.runtimeVisibleAnnotations());
|
||||
this.elements = List.copyOf(elements);
|
||||
}
|
||||
|
||||
|
@ -595,7 +595,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final List<Annotation> elements;
|
||||
|
||||
public UnboundRuntimeInvisibleAnnotationsAttribute(List<Annotation> elements) {
|
||||
super(Attributes.RUNTIME_INVISIBLE_ANNOTATIONS);
|
||||
super(Attributes.runtimeInvisibleAnnotations());
|
||||
this.elements = List.copyOf(elements);
|
||||
}
|
||||
|
||||
|
@ -611,7 +611,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final List<List<Annotation>> elements;
|
||||
|
||||
public UnboundRuntimeVisibleParameterAnnotationsAttribute(List<List<Annotation>> elements) {
|
||||
super(Attributes.RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS);
|
||||
super(Attributes.runtimeVisibleParameterAnnotations());
|
||||
this.elements = List.copyOf(elements);
|
||||
}
|
||||
|
||||
|
@ -627,7 +627,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final List<List<Annotation>> elements;
|
||||
|
||||
public UnboundRuntimeInvisibleParameterAnnotationsAttribute(List<List<Annotation>> elements) {
|
||||
super(Attributes.RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS);
|
||||
super(Attributes.runtimeInvisibleParameterAnnotations());
|
||||
this.elements = List.copyOf(elements);
|
||||
}
|
||||
|
||||
|
@ -643,7 +643,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final List<TypeAnnotation> elements;
|
||||
|
||||
public UnboundRuntimeVisibleTypeAnnotationsAttribute(List<TypeAnnotation> elements) {
|
||||
super(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS);
|
||||
super(Attributes.runtimeVisibleTypeAnnotations());
|
||||
this.elements = List.copyOf(elements);
|
||||
}
|
||||
|
||||
|
@ -659,7 +659,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
private final List<TypeAnnotation> elements;
|
||||
|
||||
public UnboundRuntimeInvisibleTypeAnnotationsAttribute(List<TypeAnnotation> elements) {
|
||||
super(Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS);
|
||||
super(Attributes.runtimeInvisibleTypeAnnotations());
|
||||
this.elements = List.copyOf(elements);
|
||||
}
|
||||
|
||||
|
@ -845,7 +845,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
Collection<ClassEntry> uses,
|
||||
Collection<ModuleProvideInfo> provides)
|
||||
{
|
||||
super(Attributes.MODULE);
|
||||
super(Attributes.module());
|
||||
this.moduleName = moduleName;
|
||||
this.moduleFlags = moduleFlags;
|
||||
this.moduleVersion = moduleVersion;
|
||||
|
@ -921,7 +921,7 @@ public abstract sealed class UnboundAttribute<T extends Attribute<T>>
|
|||
extends UnboundAttribute<BootstrapMethodsAttribute>
|
||||
implements BootstrapMethodsAttribute {
|
||||
public EmptyBootstrapAttribute() {
|
||||
super(Attributes.BOOTSTRAP_METHODS);
|
||||
super(Attributes.bootstrapMethods());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -214,7 +214,7 @@ public class Util {
|
|||
var cc = ClassFile.of();
|
||||
var clm = cc.parse(cc.build(cp.classEntry(cls), cp, clb ->
|
||||
clb.withMethod(methodName, methodDesc, acc, mb ->
|
||||
((DirectMethodBuilder)mb).writeAttribute(new UnboundAttribute.AdHocAttribute<CodeAttribute>(Attributes.CODE) {
|
||||
((DirectMethodBuilder)mb).writeAttribute(new UnboundAttribute.AdHocAttribute<CodeAttribute>(Attributes.code()) {
|
||||
@Override
|
||||
public void writeBody(BufWriter b) {
|
||||
b.writeU2(-1);//max stack
|
||||
|
|
|
@ -142,12 +142,12 @@ public final class VerificationWrapper {
|
|||
}
|
||||
|
||||
List<LocalVariableInfo> localVariableTable() {
|
||||
var attro = c.findAttribute(Attributes.LOCAL_VARIABLE_TABLE);
|
||||
var attro = c.findAttribute(Attributes.localVariableTable());
|
||||
return attro.map(lvta -> lvta.localVariables()).orElse(List.of());
|
||||
}
|
||||
|
||||
byte[] stackMapTableRawData() {
|
||||
var attro = c.findAttribute(Attributes.STACK_MAP_TABLE);
|
||||
var attro = c.findAttribute(Attributes.stackMapTable());
|
||||
return attro.map(attr -> ((BoundAttribute) attr).contents()).orElse(null);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue