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
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);
|
||||
}
|
||||
|
||||
|
@ -284,7 +284,7 @@ final class FingerPrint {
|
||||
case MethodModel mm -> {
|
||||
if (isPublic(mm.flags())) {
|
||||
Set<String> exceptionSet = new HashSet<>();
|
||||
mm.findAttribute(Attributes.EXCEPTIONS).ifPresent(ea ->
|
||||
mm.findAttribute(Attributes.exceptions()).ifPresent(ea ->
|
||||
ea.exceptions().forEach(e ->
|
||||
exceptionSet.add(e.asInternalName())));
|
||||
// treat type descriptor as a proxy for signature because signature
|
||||
|
@ -478,7 +478,7 @@ public class AttributeWriter extends BasicWriter {
|
||||
println("Record:");
|
||||
indent(+1);
|
||||
for (var componentInfo : attr.components()) {
|
||||
var sigAttr = componentInfo.findAttribute(Attributes.SIGNATURE);
|
||||
var sigAttr = componentInfo.findAttribute(Attributes.signature());
|
||||
print(getJavaName(
|
||||
new ClassWriter.SignaturePrinter(options.verbose).print(
|
||||
sigAttr.map(SignatureAttribute::asTypeSignature)
|
||||
|
@ -141,7 +141,7 @@ public class ClassWriter extends BasicWriter {
|
||||
}
|
||||
}
|
||||
|
||||
cm.findAttribute(Attributes.SOURCE_FILE).ifPresent(sfa ->
|
||||
cm.findAttribute(Attributes.sourceFile()).ifPresent(sfa ->
|
||||
println("Compiled from \"" + sfa.sourceFile().stringValue() + "\""));
|
||||
|
||||
if (options.sysInfo || options.verbose) {
|
||||
@ -151,7 +151,7 @@ public class ClassWriter extends BasicWriter {
|
||||
writeModifiers(getClassModifiers(cm.flags().flagsMask()));
|
||||
|
||||
if ((classModel.flags().flagsMask() & ACC_MODULE) != 0) {
|
||||
var attr = classModel.findAttribute(Attributes.MODULE);
|
||||
var attr = classModel.findAttribute(Attributes.module());
|
||||
if (attr.isPresent()) {
|
||||
var modAttr = attr.get();
|
||||
if ((modAttr.moduleFlagsMask() & ACC_OPEN) != 0) {
|
||||
@ -178,7 +178,7 @@ public class ClassWriter extends BasicWriter {
|
||||
}
|
||||
|
||||
try {
|
||||
var sigAttr = classModel.findAttribute(Attributes.SIGNATURE).orElse(null);
|
||||
var sigAttr = classModel.findAttribute(Attributes.signature()).orElse(null);
|
||||
if (sigAttr == null) {
|
||||
// use info from class file header
|
||||
if ((classModel.flags().flagsMask() & ACC_INTERFACE) == 0
|
||||
@ -399,13 +399,13 @@ public class ClassWriter extends BasicWriter {
|
||||
writeModifiers(flags.flags().stream().filter(fl -> fl.sourceModifier())
|
||||
.map(fl -> Modifier.toString(fl.mask())).toList());
|
||||
print(() -> sigPrinter.print(
|
||||
f.findAttribute(Attributes.SIGNATURE)
|
||||
f.findAttribute(Attributes.signature())
|
||||
.map(SignatureAttribute::asTypeSignature)
|
||||
.orElseGet(() -> Signature.of(f.fieldTypeSymbol()))));
|
||||
print(" ");
|
||||
print(() -> f.fieldName().stringValue());
|
||||
if (options.showConstants) {
|
||||
var a = f.findAttribute(Attributes.CONSTANT_VALUE);
|
||||
var a = f.findAttribute(Attributes.constantValue());
|
||||
if (a.isPresent()) {
|
||||
print(" = ");
|
||||
var cv = a.get();
|
||||
@ -480,7 +480,7 @@ public class ClassWriter extends BasicWriter {
|
||||
writeModifiers(modifiers);
|
||||
|
||||
try {
|
||||
var sigAttr = m.findAttribute(Attributes.SIGNATURE);
|
||||
var sigAttr = m.findAttribute(Attributes.signature());
|
||||
MethodSignature d;
|
||||
if (sigAttr.isEmpty()) {
|
||||
d = MethodSignature.parseFrom(m.methodType().stringValue());
|
||||
@ -507,7 +507,7 @@ public class ClassWriter extends BasicWriter {
|
||||
break;
|
||||
}
|
||||
|
||||
var e_attr = m.findAttribute(Attributes.EXCEPTIONS);
|
||||
var e_attr = m.findAttribute(Attributes.exceptions());
|
||||
// if there are generic exceptions, there must be erased exceptions
|
||||
if (e_attr.isPresent()) {
|
||||
var exceptions = e_attr.get();
|
||||
@ -559,9 +559,9 @@ public class ClassWriter extends BasicWriter {
|
||||
}
|
||||
|
||||
if (options.showLineAndLocalVariableTables) {
|
||||
code.findAttribute(Attributes.LINE_NUMBER_TABLE)
|
||||
code.findAttribute(Attributes.lineNumberTable())
|
||||
.ifPresent(a -> attrWriter.write(a, code));
|
||||
code.findAttribute(Attributes.LOCAL_VARIABLE_TABLE)
|
||||
code.findAttribute(Attributes.localVariableTable())
|
||||
.ifPresent(a -> attrWriter.write(a, code));
|
||||
}
|
||||
}
|
||||
@ -589,7 +589,7 @@ public class ClassWriter extends BasicWriter {
|
||||
public static final int ACC_STATIC_PHASE = 0x0040;
|
||||
|
||||
void writeDirectives() {
|
||||
var attr = classModel.findAttribute(Attributes.MODULE);
|
||||
var attr = classModel.findAttribute(Attributes.module());
|
||||
if (attr.isEmpty())
|
||||
return;
|
||||
|
||||
|
@ -674,7 +674,7 @@ public class JavapTask implements DisassemblerTool.DisassemblerTask, Messages {
|
||||
|
||||
if (options.showInnerClasses) {
|
||||
ClassModel cm = cfInfo.cm;
|
||||
var a = cm.findAttribute(java.lang.classfile.Attributes.INNER_CLASSES);
|
||||
var a = cm.findAttribute(java.lang.classfile.Attributes.innerClasses());
|
||||
if (a.isPresent()) {
|
||||
var inners = a.get();
|
||||
try {
|
||||
|
@ -80,7 +80,7 @@ public class LocalVariableTableWriter extends InstructionDetailWriter {
|
||||
public void reset(CodeModel attr) {
|
||||
codeAttr = attr;
|
||||
pcMap = new HashMap<>();
|
||||
var lvt = attr.findAttribute(Attributes.LOCAL_VARIABLE_TABLE);
|
||||
var lvt = attr.findAttribute(Attributes.localVariableTable());
|
||||
|
||||
if (lvt.isEmpty())
|
||||
return;
|
||||
|
@ -80,7 +80,7 @@ public class LocalVariableTypeTableWriter extends InstructionDetailWriter {
|
||||
public void reset(CodeModel attr) {
|
||||
codeAttr = attr;
|
||||
pcMap = new HashMap<>();
|
||||
var lvt = attr.findAttribute(Attributes.LOCAL_VARIABLE_TYPE_TABLE);
|
||||
var lvt = attr.findAttribute(Attributes.localVariableTypeTable());
|
||||
|
||||
if (lvt.isEmpty())
|
||||
return;
|
||||
|
@ -105,7 +105,7 @@ public class SourceWriter extends InstructionDetailWriter {
|
||||
private void setLineMap(CodeModel attr) {
|
||||
SortedMap<Integer, SortedSet<Integer>> map = new TreeMap<>();
|
||||
SortedSet<Integer> allLines = new TreeSet<>();
|
||||
for (var t : attr.findAttributes(Attributes.LINE_NUMBER_TABLE)) {
|
||||
for (var t : attr.findAttributes(Attributes.lineNumberTable())) {
|
||||
for (var e: t.lineNumbers()) {
|
||||
int start_pc = e.startPc();
|
||||
int line = e.lineNumber();
|
||||
@ -145,7 +145,7 @@ public class SourceWriter extends InstructionDetailWriter {
|
||||
// InnerClasses and EnclosingMethod attributes.
|
||||
try {
|
||||
String className = cf.thisClass().asInternalName();
|
||||
var sf = cf.findAttribute(Attributes.SOURCE_FILE);
|
||||
var sf = cf.findAttribute(Attributes.sourceFile());
|
||||
if (sf.isEmpty()) {
|
||||
report(messages.getMessage("err.no.SourceFile.attribute"));
|
||||
return null;
|
||||
|
@ -62,7 +62,7 @@ public class StackMapWriter extends InstructionDetailWriter {
|
||||
}
|
||||
|
||||
void setStackMap(CodeAttribute code) {
|
||||
StackMapTableAttribute attr = code.findAttribute(Attributes.STACK_MAP_TABLE)
|
||||
StackMapTableAttribute attr = code.findAttribute(Attributes.stackMapTable())
|
||||
.orElse(null);
|
||||
if (attr == null) {
|
||||
map = null;
|
||||
|
@ -76,10 +76,10 @@ public class TypeAnnotationWriter extends InstructionDetailWriter {
|
||||
pcMap = new HashMap<>();
|
||||
codeAttribute = attr;
|
||||
check(NoteKind.VISIBLE,
|
||||
m.findAttribute(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS)
|
||||
m.findAttribute(Attributes.runtimeVisibleTypeAnnotations())
|
||||
.map(a -> a.annotations()));
|
||||
check(NoteKind.INVISIBLE,
|
||||
m.findAttribute(Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS)
|
||||
m.findAttribute(Attributes.runtimeInvisibleTypeAnnotations())
|
||||
.map(a -> a.annotations()));
|
||||
}
|
||||
|
||||
|
@ -597,7 +597,7 @@ public class Dependencies {
|
||||
|
||||
void scanAttributes(AttributedElement attrs) {
|
||||
try {
|
||||
var sa = attrs.findAttribute(Attributes.SIGNATURE).orElse(null);
|
||||
var sa = attrs.findAttribute(Attributes.signature()).orElse(null);
|
||||
if (sa != null) {
|
||||
switch (attrs) {
|
||||
case ClassModel _ -> scan(sa.asClassSignature());
|
||||
@ -606,14 +606,14 @@ public class Dependencies {
|
||||
}
|
||||
}
|
||||
|
||||
var rvaa = attrs.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).orElse(null);
|
||||
var rvaa = attrs.findAttribute(Attributes.runtimeVisibleAnnotations()).orElse(null);
|
||||
if (rvaa != null) {
|
||||
for (var anno : rvaa.annotations()) {
|
||||
scan(anno.classSymbol());
|
||||
}
|
||||
}
|
||||
|
||||
var rvpaa = attrs.findAttribute(Attributes.RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS).orElse(null);
|
||||
var rvpaa = attrs.findAttribute(Attributes.runtimeVisibleParameterAnnotations()).orElse(null);
|
||||
if (rvpaa != null) {
|
||||
for (var parameter : rvpaa.parameterAnnotations()) {
|
||||
for (var anno : parameter) {
|
||||
@ -622,7 +622,7 @@ public class Dependencies {
|
||||
}
|
||||
}
|
||||
|
||||
var exceptions = attrs.findAttribute(Attributes.EXCEPTIONS).orElse(null);
|
||||
var exceptions = attrs.findAttribute(Attributes.exceptions()).orElse(null);
|
||||
if (exceptions != null) {
|
||||
for (var e : exceptions.exceptions()) {
|
||||
addClass(e);
|
||||
|
@ -678,7 +678,7 @@ public class TestResolvedJavaMethod extends MethodUniverse {
|
||||
Map<String, ResolvedJavaMethod> methodMap = buildMethodMap(type);
|
||||
ClassModel cf = readClassfile(c);
|
||||
for (MethodModel cm : cf.methods()) {
|
||||
cm.findAttribute(Attributes.CODE).ifPresent(codeAttr -> {
|
||||
cm.findAttribute(Attributes.code()).ifPresent(codeAttr -> {
|
||||
String key = cm.methodName().stringValue() + ":" + cm.methodType().stringValue();
|
||||
HotSpotResolvedJavaMethod m = (HotSpotResolvedJavaMethod) Objects.requireNonNull(methodMap.get(key));
|
||||
boolean isMethodWithManyArgs = c == getClass() && m.getName().equals("methodWithManyArgs");
|
||||
|
@ -134,7 +134,7 @@ public class TestBCI {
|
||||
this.name = m.methodName().stringValue();
|
||||
this.desc = m.methodTypeSymbol();
|
||||
m.code().orElseThrow(() -> new IllegalArgumentException("Missing Code in " + m))
|
||||
.findAttribute(Attributes.LINE_NUMBER_TABLE)
|
||||
.findAttribute(Attributes.lineNumberTable())
|
||||
.orElseThrow(() -> new IllegalArgumentException("Missing LineNumberTable in " + m))
|
||||
.lineNumbers().forEach(entry ->
|
||||
bciToLineNumbers.computeIfAbsent(entry.startPc(), _ -> new TreeSet<>())
|
||||
|
@ -125,7 +125,7 @@ public class LambdaAsm {
|
||||
for (var m : cf.methods()) {
|
||||
String mname = m.methodName().stringValue();
|
||||
if (mname.equals(mthd)) {
|
||||
for (var a : m.findAttributes(Attributes.CODE)) {
|
||||
for (var a : m.findAttributes(Attributes.code())) {
|
||||
count++;
|
||||
checkMethod(cf.thisClass().asInternalName(), mname,
|
||||
cf.constantPool(), a);
|
||||
|
@ -120,9 +120,9 @@ class AdvancedTransformationsTest {
|
||||
ClassDesc.ofDescriptor(RawBytecodeHelper.class.descriptorString()), ClassDesc.of("remapped.RemappedBytecode")))
|
||||
.orElse(ClassHierarchyResolver.defaultResolver())
|
||||
)).verify(remapped));
|
||||
remapped.fields().forEach(f -> f.findAttribute(Attributes.SIGNATURE).ifPresent(sa ->
|
||||
remapped.fields().forEach(f -> f.findAttribute(Attributes.signature()).ifPresent(sa ->
|
||||
verifySignature(f.fieldTypeSymbol(), sa.asTypeSignature())));
|
||||
remapped.methods().forEach(m -> m.findAttribute(Attributes.SIGNATURE).ifPresent(sa -> {
|
||||
remapped.methods().forEach(m -> m.findAttribute(Attributes.signature()).ifPresent(sa -> {
|
||||
var md = m.methodTypeSymbol();
|
||||
var ms = sa.asMethodSignature();
|
||||
verifySignature(md.returnType(), ms.result());
|
||||
@ -173,7 +173,7 @@ class AdvancedTransformationsTest {
|
||||
cc.parse(
|
||||
cc.buildModule(
|
||||
ModuleAttribute.of(ModuleDesc.of("MyModule"), mab ->
|
||||
mab.uses(foo).provides(foo, foo)))))).findAttribute(Attributes.MODULE).get();
|
||||
mab.uses(foo).provides(foo, foo)))))).findAttribute(Attributes.module()).get();
|
||||
assertEquals(ma.uses().get(0).asSymbol(), bar);
|
||||
var provides = ma.provides().get(0);
|
||||
assertEquals(provides.provides().asSymbol(), bar);
|
||||
|
@ -54,7 +54,7 @@ class AnnotationModelTest {
|
||||
@Test
|
||||
void readAnnos() {
|
||||
var model = ClassFile.of().parse(fileBytes);
|
||||
var annotations = model.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).get().annotations();
|
||||
var annotations = model.findAttribute(Attributes.runtimeVisibleAnnotations()).get().annotations();
|
||||
|
||||
assertEquals(annotations.size(), 3);
|
||||
}
|
||||
|
55
test/jdk/jdk/classfile/AttributesTest.java
Normal file
55
test/jdk/jdk/classfile/AttributesTest.java
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8331291
|
||||
* @summary Testing Attributes API.
|
||||
* @run junit AttributesTest
|
||||
*/
|
||||
import java.lang.classfile.AttributeMapper;
|
||||
import java.lang.classfile.Attributes;
|
||||
import java.lang.classfile.constantpool.Utf8Entry;
|
||||
import java.lang.reflect.Field;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import jdk.internal.classfile.impl.BoundAttribute;
|
||||
import jdk.internal.classfile.impl.TemporaryConstantPool;
|
||||
|
||||
class AttributesTest {
|
||||
|
||||
@Test
|
||||
void testAttributesMapping() throws Exception {
|
||||
var cp = TemporaryConstantPool.INSTANCE;
|
||||
for (Field f : Attributes.class.getDeclaredFields()) {
|
||||
if (f.getName().startsWith("NAME_") && f.getType() == String.class) {
|
||||
Utf8Entry attrName = cp.utf8Entry((String)f.get(null));
|
||||
AttributeMapper<?> mapper = BoundAttribute.standardAttribute(attrName);
|
||||
assertNotNull(mapper, attrName.stringValue() + " 0x" + Integer.toHexString(attrName.hashCode()));
|
||||
assertEquals(attrName.stringValue(), mapper.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -61,7 +61,7 @@ class BoundAttributeTest {
|
||||
});
|
||||
ClassModel model = cc.parse(raw);
|
||||
MethodParametersAttribute methodParametersAttribute = model.methods().get(0)
|
||||
.findAttribute(Attributes.METHOD_PARAMETERS)
|
||||
.findAttribute(Attributes.methodParameters())
|
||||
.orElseThrow(() -> new AssertionFailedError("Attribute not present"));
|
||||
// MethodParametersAttribute#parameters() materializes the parameters
|
||||
List<MethodParameterInfo> parameters = assertDoesNotThrow(methodParametersAttribute::parameters);
|
||||
|
@ -83,7 +83,7 @@ class CorpusTest {
|
||||
var dcob = (DirectCodeBuilder)cob;
|
||||
var curPc = dcob.curPc();
|
||||
switch (coe) {
|
||||
case LineNumber ln -> dcob.writeAttribute(new UnboundAttribute.AdHocAttribute<>(Attributes.LINE_NUMBER_TABLE) {
|
||||
case LineNumber ln -> dcob.writeAttribute(new UnboundAttribute.AdHocAttribute<>(Attributes.lineNumberTable()) {
|
||||
@Override
|
||||
public void writeBody(BufWriter b) {
|
||||
b.writeU2(1);
|
||||
@ -91,14 +91,14 @@ class CorpusTest {
|
||||
b.writeU2(ln.line());
|
||||
}
|
||||
});
|
||||
case LocalVariable lv -> dcob.writeAttribute(new UnboundAttribute.AdHocAttribute<>(Attributes.LOCAL_VARIABLE_TABLE) {
|
||||
case LocalVariable lv -> dcob.writeAttribute(new UnboundAttribute.AdHocAttribute<>(Attributes.localVariableTable()) {
|
||||
@Override
|
||||
public void writeBody(BufWriter b) {
|
||||
b.writeU2(1);
|
||||
lv.writeTo(b);
|
||||
}
|
||||
});
|
||||
case LocalVariableType lvt -> dcob.writeAttribute(new UnboundAttribute.AdHocAttribute<>(Attributes.LOCAL_VARIABLE_TYPE_TABLE) {
|
||||
case LocalVariableType lvt -> dcob.writeAttribute(new UnboundAttribute.AdHocAttribute<>(Attributes.localVariableTypeTable()) {
|
||||
@Override
|
||||
public void writeBody(BufWriter b) {
|
||||
b.writeU2(1);
|
||||
|
@ -66,9 +66,9 @@ class FilterDeadLabelsTest {
|
||||
}))).methods().get(0).code().get();
|
||||
|
||||
assertTrue(code.exceptionHandlers().isEmpty());
|
||||
code.findAttribute(Attributes.LOCAL_VARIABLE_TABLE).ifPresent(a -> assertTrue(a.localVariables().isEmpty()));
|
||||
code.findAttribute(Attributes.LOCAL_VARIABLE_TYPE_TABLE).ifPresent(a -> assertTrue(a.localVariableTypes().isEmpty()));
|
||||
code.findAttribute(Attributes.CHARACTER_RANGE_TABLE).ifPresent(a -> assertTrue(a.characterRangeTable().isEmpty()));
|
||||
code.findAttribute(Attributes.localVariableTable()).ifPresent(a -> assertTrue(a.localVariables().isEmpty()));
|
||||
code.findAttribute(Attributes.localVariableTypeTable()).ifPresent(a -> assertTrue(a.localVariableTypes().isEmpty()));
|
||||
code.findAttribute(Attributes.characterRangeTable()).ifPresent(a -> assertTrue(a.characterRangeTable().isEmpty()));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
|
@ -127,7 +127,7 @@ class LimitsTest {
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
ClassFile.of().parse(ClassFile.of().build(ClassDesc.of("LookupSwitchClass"), cb -> cb.withMethod(
|
||||
"lookupSwitchMethod", MethodTypeDesc.of(ConstantDescs.CD_void), 0, 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
|
||||
@ -152,7 +152,7 @@ class LimitsTest {
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
ClassFile.of().parse(ClassFile.of().build(ClassDesc.of("TableSwitchClass"), cb -> cb.withMethod(
|
||||
"tableSwitchMethod", MethodTypeDesc.of(ConstantDescs.CD_void), 0, 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
|
||||
|
@ -94,8 +94,8 @@ class LowJCovAttributeTest {
|
||||
}
|
||||
}
|
||||
for (MethodModel m : classLow.methods()) {
|
||||
m.findAttribute(Attributes.CODE).ifPresent(code ->
|
||||
((CodeModel) code).findAttribute(Attributes.CHARACTER_RANGE_TABLE).ifPresent(attr -> {
|
||||
m.findAttribute(Attributes.code()).ifPresent(code ->
|
||||
((CodeModel) code).findAttribute(Attributes.characterRangeTable()).ifPresent(attr -> {
|
||||
for (CharacterRangeInfo cr : attr.characterRangeTable()) {
|
||||
printf(" %d-%d -> %d/%d-%d/%d (%x)%n", cr.startPc(), cr.endPc(),
|
||||
cr.characterRangeStart() >> 10, cr.characterRangeStart() & 0x3FF,
|
||||
@ -156,7 +156,7 @@ class LowJCovAttributeTest {
|
||||
// }
|
||||
// writeAndCompareAttributes(classLow, cp);
|
||||
// for (MethodLow m : classLow.methodsLow()) {
|
||||
// m.findAttribute(Attributes.CODE).ifPresent(code ->
|
||||
// m.findAttribute(Attributes.code()).ifPresent(code ->
|
||||
// writeAndCompareAttributes(code, cp));
|
||||
// }
|
||||
// }
|
||||
|
@ -174,7 +174,7 @@ class LvtTest {
|
||||
|
||||
var c = cc.parse(bytes);
|
||||
var main = c.methods().get(1);
|
||||
var lvt = main.code().get().findAttribute(Attributes.LOCAL_VARIABLE_TABLE).get();
|
||||
var lvt = main.code().get().findAttribute(Attributes.localVariableTable()).get();
|
||||
var lvs = lvt.localVariables();
|
||||
|
||||
assertEquals(lvs.size(), 3);
|
||||
@ -278,7 +278,7 @@ class LvtTest {
|
||||
});
|
||||
var c = cc.parse(bytes);
|
||||
var main = c.methods().get(1);
|
||||
var lvtt = main.code().get().findAttribute(Attributes.LOCAL_VARIABLE_TYPE_TABLE).get();
|
||||
var lvtt = main.code().get().findAttribute(Attributes.localVariableTypeTable()).get();
|
||||
var lvts = lvtt.localVariableTypes();
|
||||
|
||||
/* From javap:
|
||||
|
@ -120,7 +120,7 @@ class MassAdaptCopyPrimitiveMatchCodeTest {
|
||||
cb.with(e);
|
||||
});
|
||||
//TODO: work-around to compiler bug generating multiple constant pool entries within records
|
||||
if (cm.findAttribute(Attributes.RECORD).isPresent()) {
|
||||
if (cm.findAttribute(Attributes.record()).isPresent()) {
|
||||
System.err.printf("MassAdaptCopyPrimitiveMatchCodeTest: Ignored because it is a record%n - %s%n", name);
|
||||
return;
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ class ModuleBuilderTest {
|
||||
.with(ModuleMainClassAttribute.of(ClassDesc.of("overwritten.main.Class"))));
|
||||
moduleModel = cc.parse(modInfo);
|
||||
attr = ((ModuleAttribute) moduleModel.attributes().stream()
|
||||
.filter(a -> a.attributeMapper() == Attributes.MODULE)
|
||||
.filter(a -> a.attributeMapper() == Attributes.module())
|
||||
.findFirst()
|
||||
.orElseThrow());
|
||||
}
|
||||
@ -103,7 +103,7 @@ class ModuleBuilderTest {
|
||||
// Verify
|
||||
var cm = cc.parse(modBytes);
|
||||
|
||||
var attr =cm.findAttribute(Attributes.MODULE).get();
|
||||
var attr =cm.findAttribute(Attributes.module()).get();
|
||||
assertEquals(attr.moduleName().name().stringValue(), modName.name());
|
||||
assertEquals(attr.moduleFlagsMask(), 0);
|
||||
assertEquals(attr.moduleVersion().get().stringValue(), modVsn);
|
||||
@ -181,13 +181,13 @@ class ModuleBuilderTest {
|
||||
|
||||
@Test
|
||||
void verifyPackages() {
|
||||
ModulePackagesAttribute a = moduleModel.findAttribute(Attributes.MODULE_PACKAGES).orElseThrow();
|
||||
ModulePackagesAttribute a = moduleModel.findAttribute(Attributes.modulePackages()).orElseThrow();
|
||||
assertEquals(a.packages().stream().map(pe -> pe.asSymbol().name()).toList(), List.of("foo.bar.baz", "quux"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void verifyMainclass() {
|
||||
ModuleMainClassAttribute a = moduleModel.findAttribute(Attributes.MODULE_MAIN_CLASS).orElseThrow();
|
||||
ModuleMainClassAttribute a = moduleModel.findAttribute(Attributes.moduleMainClass()).orElseThrow();
|
||||
assertEquals(a.mainClass().asInternalName(), "overwritten/main/Class");
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ class SignaturesTest {
|
||||
.filter(p -> Files.isRegularFile(p) && p.toString().endsWith(".class")).forEach(path -> {
|
||||
try {
|
||||
var cm = ClassFile.of().parse(path);
|
||||
cm.findAttribute(Attributes.SIGNATURE).ifPresent(csig -> {
|
||||
cm.findAttribute(Attributes.signature()).ifPresent(csig -> {
|
||||
assertEquals(
|
||||
ClassSignature.parseFrom(csig.signature().stringValue()).signatureString(),
|
||||
csig.signature().stringValue(),
|
||||
@ -141,7 +141,7 @@ class SignaturesTest {
|
||||
csc.incrementAndGet();
|
||||
});
|
||||
for (var m : cm.methods()) {
|
||||
m.findAttribute(Attributes.SIGNATURE).ifPresent(msig -> {
|
||||
m.findAttribute(Attributes.signature()).ifPresent(msig -> {
|
||||
assertEquals(
|
||||
MethodSignature.parseFrom(msig.signature().stringValue()).signatureString(),
|
||||
msig.signature().stringValue(),
|
||||
@ -150,7 +150,7 @@ class SignaturesTest {
|
||||
});
|
||||
}
|
||||
for (var f : cm.fields()) {
|
||||
f.findAttribute(Attributes.SIGNATURE).ifPresent(fsig -> {
|
||||
f.findAttribute(Attributes.signature()).ifPresent(fsig -> {
|
||||
assertEquals(
|
||||
Signature.parseFrom(fsig.signature().stringValue()).signatureString(),
|
||||
fsig.signature().stringValue(),
|
||||
@ -158,8 +158,8 @@ class SignaturesTest {
|
||||
fsc.incrementAndGet();
|
||||
});
|
||||
}
|
||||
cm.findAttribute(Attributes.RECORD).ifPresent(reca
|
||||
-> reca.components().forEach(rc -> rc.findAttribute(Attributes.SIGNATURE).ifPresent(rsig -> {
|
||||
cm.findAttribute(Attributes.record()).ifPresent(reca
|
||||
-> reca.components().forEach(rc -> rc.findAttribute(Attributes.signature()).ifPresent(rsig -> {
|
||||
assertEquals(
|
||||
Signature.parseFrom(rsig.signature().stringValue()).signatureString(),
|
||||
rsig.signature().stringValue(),
|
||||
@ -182,7 +182,7 @@ class SignaturesTest {
|
||||
@Test
|
||||
void testClassSignatureClassDesc() throws IOException {
|
||||
var observerCf = ClassFile.of().parse(Path.of(System.getProperty("test.classes"), "SignaturesTest$Observer.class"));
|
||||
var sig = observerCf.findAttribute(Attributes.SIGNATURE).orElseThrow().asClassSignature();
|
||||
var sig = observerCf.findAttribute(Attributes.signature()).orElseThrow().asClassSignature();
|
||||
var arrayListSig = sig.superclassSignature(); // ArrayList
|
||||
var arrayListTypeArg = (TypeArg.Bounded) arrayListSig.typeArgs().getFirst(); // Outer<String>.Inner<Long>
|
||||
assertEquals(TypeArg.Bounded.WildcardIndicator.NONE, arrayListTypeArg.wildcardIndicator());
|
||||
|
@ -93,7 +93,7 @@ class TestRecordComponent {
|
||||
cb.with(ce);
|
||||
};
|
||||
ClassModel newModel = cc.parse(cc.transform(cm, xform));
|
||||
RecordAttribute ra = newModel.findAttribute(Attributes.RECORD).orElseThrow();
|
||||
RecordAttribute ra = newModel.findAttribute(Attributes.record()).orElseThrow();
|
||||
assertEquals(ra.components().size(), 2, "Should have two components");
|
||||
assertEquals(ra.components().get(0).name().stringValue(), "fooXYZ");
|
||||
assertEquals(ra.components().get(1).name().stringValue(), "barXYZ");
|
||||
@ -110,7 +110,7 @@ class TestRecordComponent {
|
||||
count.addAndGet(rm.components().size());
|
||||
}});
|
||||
assertEquals(count.get(), 2);
|
||||
assertEquals(cm.findAttribute(Attributes.RECORD).orElseThrow().components().size(), 2);
|
||||
assertEquals(cm.findAttribute(Attributes.record()).orElseThrow().components().size(), 2);
|
||||
|
||||
count.set(0);
|
||||
}
|
||||
|
@ -54,8 +54,9 @@ public class AnnotationsExamples {
|
||||
* Find classes with annotations of a certain type
|
||||
*/
|
||||
public void findAnnotation(ClassModel m) {
|
||||
if (m.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).isPresent()) {
|
||||
RuntimeVisibleAnnotationsAttribute a = m.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).get();
|
||||
var rvaa = m.findAttribute(Attributes.runtimeVisibleAnnotations());
|
||||
if (rvaa.isPresent()) {
|
||||
RuntimeVisibleAnnotationsAttribute a = rvaa.get();
|
||||
for (Annotation ann : a.annotations()) {
|
||||
if (ann.className().stringValue().equals("Ljava/lang/FunctionalInterface;"))
|
||||
System.out.println(m.thisClass().asInternalName());
|
||||
@ -68,9 +69,9 @@ public class AnnotationsExamples {
|
||||
*/
|
||||
public void swapAnnotation(ClassModel m) {
|
||||
ClassModel m2 = m;
|
||||
|
||||
if (m.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).isPresent()) {
|
||||
RuntimeVisibleAnnotationsAttribute a = m.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).get();
|
||||
var rvaa = m.findAttribute(Attributes.runtimeVisibleAnnotations());
|
||||
if (rvaa.isPresent()) {
|
||||
RuntimeVisibleAnnotationsAttribute a = rvaa.get();
|
||||
var cc = ClassFile.of();
|
||||
for (Annotation ann : a.annotations()) {
|
||||
if (ann.className().stringValue().equals("Ljava/lang/annotation/Documented;")) {
|
||||
@ -78,9 +79,9 @@ public class AnnotationsExamples {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m2.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).isPresent()) {
|
||||
RuntimeVisibleAnnotationsAttribute a = m2.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).get();
|
||||
rvaa = m2.findAttribute(Attributes.runtimeVisibleAnnotations());
|
||||
if (rvaa.isPresent()) {
|
||||
RuntimeVisibleAnnotationsAttribute a = rvaa.get();
|
||||
for (Annotation ann : a.annotations()) {
|
||||
if (ann.className().stringValue().equals("Ljava/lang/annotation/Documented;"))
|
||||
throw new RuntimeException();
|
||||
@ -112,9 +113,9 @@ public class AnnotationsExamples {
|
||||
*/
|
||||
public void addAnnotation(ClassModel m) {
|
||||
ClassModel m2 = m;
|
||||
|
||||
if (m.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).isPresent()) {
|
||||
RuntimeVisibleAnnotationsAttribute a = m.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).get();
|
||||
var rvaa = m.findAttribute(Attributes.runtimeVisibleAnnotations());
|
||||
if (rvaa.isPresent()) {
|
||||
RuntimeVisibleAnnotationsAttribute a = rvaa.get();
|
||||
var cc = ClassFile.of();
|
||||
for (Annotation ann : a.annotations()) {
|
||||
if (ann.className().stringValue().equals("Ljava/lang/FunctionalInterface;")) {
|
||||
@ -135,7 +136,7 @@ public class AnnotationsExamples {
|
||||
}
|
||||
}
|
||||
|
||||
int size = m2.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).orElseThrow().annotations().size();
|
||||
int size = m2.findAttribute(Attributes.runtimeVisibleAnnotations()).orElseThrow().annotations().size();
|
||||
if (size !=2) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
ClassPrinter.toJson(m2, ClassPrinter.Verbosity.TRACE_ALL, sb::append);
|
||||
|
@ -54,14 +54,14 @@ public class ModuleExamples {
|
||||
ClassModel cm = ClassFile.of().parse(JRT.getPath("modules/java.base/module-info.class"));
|
||||
System.out.println("Is JVMS $4.7 compatible module-info: " + cm.isModuleInfo());
|
||||
|
||||
ModuleAttribute ma = cm.findAttribute(Attributes.MODULE).orElseThrow();
|
||||
ModuleAttribute ma = cm.findAttribute(Attributes.module()).orElseThrow();
|
||||
System.out.println("Module name: " + ma.moduleName().name().stringValue());
|
||||
System.out.println("Exports: " + ma.exports());
|
||||
|
||||
ModuleMainClassAttribute mmca = cm.findAttribute(Attributes.MODULE_MAIN_CLASS).orElse(null);
|
||||
ModuleMainClassAttribute mmca = cm.findAttribute(Attributes.moduleMainClass()).orElse(null);
|
||||
System.out.println("Does the module have a MainClassAttribute?: " + (mmca != null));
|
||||
|
||||
ModulePackagesAttribute mmp = cm.findAttribute(Attributes.MODULE_PACKAGES).orElseThrow();
|
||||
ModulePackagesAttribute mmp = cm.findAttribute(Attributes.modulePackages()).orElseThrow();
|
||||
System.out.println("Packages?: " + mmp.packages());
|
||||
}
|
||||
|
||||
|
@ -243,75 +243,75 @@ public record ClassRecord(
|
||||
.map(e -> (Attribute<?>) e)
|
||||
.collect(toMap(Attribute::attributeName, e -> e));
|
||||
return new AttributesRecord(
|
||||
mapAttr(attrs, ANNOTATION_DEFAULT, a -> ElementValueRecord.ofElementValue(a.defaultValue())),
|
||||
mapAttr(attrs, annotationDefault(), a -> ElementValueRecord.ofElementValue(a.defaultValue())),
|
||||
cp == null ? null : IntStream.range(0, cp.bootstrapMethodCount()).mapToObj(i -> BootstrapMethodRecord.ofBootstrapMethodEntry(cp.bootstrapMethodEntry(i))).collect(toSetOrNull()),
|
||||
mapAttr(attrs, CODE, a -> CodeRecord.ofStreamingElements(a.maxStack(), a.maxLocals(), a.codeLength(), a::elementStream, a, new CodeNormalizerHelper(a.codeArray()), cf)),
|
||||
mapAttr(attrs, COMPILATION_ID, a -> a.compilationId().stringValue()),
|
||||
mapAttr(attrs, CONSTANT_VALUE, a -> ConstantPoolEntryRecord.ofCPEntry(a.constant())),
|
||||
mapAttr(attrs, DEPRECATED, a -> DefinedValue.DEFINED),
|
||||
mapAttr(attrs, ENCLOSING_METHOD, a -> EnclosingMethodRecord.ofEnclosingMethodAttribute(a)),
|
||||
mapAttr(attrs, EXCEPTIONS, a -> new HashSet<>(a.exceptions().stream().map(e -> e.asInternalName()).toList())),
|
||||
mapAttr(attrs, INNER_CLASSES, a -> a.classes().stream().collect(toMap(ic -> ic.innerClass().asInternalName(), ic -> InnerClassRecord.ofInnerClassInfo(ic)))),
|
||||
mapAttr(attrs, METHOD_PARAMETERS, a -> a.parameters().stream().map(mp -> MethodParameterRecord.ofMethodParameter(mp)).toList()),
|
||||
mapAttr(attrs, MODULE, a -> ModuleRecord.ofModuleAttribute(a)),
|
||||
mapAttr(attrs, MODULE_HASHES, a -> ModuleHashesRecord.ofModuleHashesAttribute(a)),
|
||||
mapAttr(attrs, MODULE_MAIN_CLASS, a -> a.mainClass().asInternalName()),
|
||||
mapAttr(attrs, MODULE_PACKAGES, a -> a.packages().stream().map(p -> p.name().stringValue()).collect(toSet())),
|
||||
mapAttr(attrs, MODULE_RESOLUTION, a -> a.resolutionFlags()),
|
||||
mapAttr(attrs, MODULE_TARGET, a -> a.targetPlatform().stringValue()),
|
||||
mapAttr(attrs, NEST_HOST, a -> a.nestHost().asInternalName()),
|
||||
mapAttr(attrs, NEST_MEMBERS, a -> a.nestMembers().stream().map(m -> m.asInternalName()).collect(toSet())),
|
||||
mapAttr(attrs, PERMITTED_SUBCLASSES, a -> new HashSet<>(a.permittedSubclasses().stream().map(e -> e.asInternalName()).toList())),
|
||||
mapAttr(attrs, RECORD, a -> a.components().stream().map(rc -> RecordComponentRecord.ofRecordComponent(rc, cf)).toList()),
|
||||
mapAttr(attrs, code(), a -> CodeRecord.ofStreamingElements(a.maxStack(), a.maxLocals(), a.codeLength(), a::elementStream, a, new CodeNormalizerHelper(a.codeArray()), cf)),
|
||||
mapAttr(attrs, compilationId(), a -> a.compilationId().stringValue()),
|
||||
mapAttr(attrs, constantValue(), a -> ConstantPoolEntryRecord.ofCPEntry(a.constant())),
|
||||
mapAttr(attrs, Attributes.deprecated(), a -> DefinedValue.DEFINED),
|
||||
mapAttr(attrs, enclosingMethod(), a -> EnclosingMethodRecord.ofEnclosingMethodAttribute(a)),
|
||||
mapAttr(attrs, exceptions(), a -> new HashSet<>(a.exceptions().stream().map(e -> e.asInternalName()).toList())),
|
||||
mapAttr(attrs, innerClasses(), a -> a.classes().stream().collect(toMap(ic -> ic.innerClass().asInternalName(), ic -> InnerClassRecord.ofInnerClassInfo(ic)))),
|
||||
mapAttr(attrs, methodParameters(), a -> a.parameters().stream().map(mp -> MethodParameterRecord.ofMethodParameter(mp)).toList()),
|
||||
mapAttr(attrs, module(), a -> ModuleRecord.ofModuleAttribute(a)),
|
||||
mapAttr(attrs, moduleHashes(), a -> ModuleHashesRecord.ofModuleHashesAttribute(a)),
|
||||
mapAttr(attrs, moduleMainClass(), a -> a.mainClass().asInternalName()),
|
||||
mapAttr(attrs, modulePackages(), a -> a.packages().stream().map(p -> p.name().stringValue()).collect(toSet())),
|
||||
mapAttr(attrs, moduleResolution(), a -> a.resolutionFlags()),
|
||||
mapAttr(attrs, moduleTarget(), a -> a.targetPlatform().stringValue()),
|
||||
mapAttr(attrs, nestHost(), a -> a.nestHost().asInternalName()),
|
||||
mapAttr(attrs, nestMembers(), a -> a.nestMembers().stream().map(m -> m.asInternalName()).collect(toSet())),
|
||||
mapAttr(attrs, permittedSubclasses(), a -> new HashSet<>(a.permittedSubclasses().stream().map(e -> e.asInternalName()).toList())),
|
||||
mapAttr(attrs, record(), a -> a.components().stream().map(rc -> RecordComponentRecord.ofRecordComponent(rc, cf)).toList()),
|
||||
elements.get().filter(e -> e instanceof RuntimeVisibleAnnotationsAttribute).map(e -> (RuntimeVisibleAnnotationsAttribute) e).flatMap(a -> a.annotations().stream())
|
||||
.map(AnnotationRecord::ofAnnotation).collect(toSetOrNull()),
|
||||
elements.get().filter(e -> e instanceof RuntimeInvisibleAnnotationsAttribute).map(e -> (RuntimeInvisibleAnnotationsAttribute) e).flatMap(a -> a.annotations().stream())
|
||||
.map(AnnotationRecord::ofAnnotation).collect(toSetOrNull()),
|
||||
mapAttr(attrs, RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS, a -> a.parameterAnnotations().stream().map(list -> list.stream().map(AnnotationRecord::ofAnnotation).collect(toSet())).toList()),
|
||||
mapAttr(attrs, RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS, a -> a.parameterAnnotations().stream().map(list -> list.stream().map(AnnotationRecord::ofAnnotation).collect(toSet())).toList()),
|
||||
mapAttr(attrs, RUNTIME_VISIBLE_TYPE_ANNOTATIONS, a -> a.annotations().stream().map(TypeAnnotationRecord::ofTypeAnnotation).collect(toSet())),
|
||||
mapAttr(attrs, RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, a -> a.annotations().stream().map(TypeAnnotationRecord::ofTypeAnnotation).collect(toSet())),
|
||||
mapAttr(attrs, SIGNATURE, a -> a.signature().stringValue()),
|
||||
mapAttr(attrs, SOURCE_DEBUG_EXTENSION, a -> new String(a.contents(), StandardCharsets.UTF_8)),
|
||||
mapAttr(attrs, SOURCE_FILE, a -> a.sourceFile().stringValue()),
|
||||
mapAttr(attrs, SOURCE_ID, a -> a.sourceId().stringValue()),
|
||||
mapAttr(attrs, SYNTHETIC, a -> DefinedValue.DEFINED)
|
||||
mapAttr(attrs, runtimeVisibleParameterAnnotations(), a -> a.parameterAnnotations().stream().map(list -> list.stream().map(AnnotationRecord::ofAnnotation).collect(toSet())).toList()),
|
||||
mapAttr(attrs, runtimeInvisibleParameterAnnotations(), a -> a.parameterAnnotations().stream().map(list -> list.stream().map(AnnotationRecord::ofAnnotation).collect(toSet())).toList()),
|
||||
mapAttr(attrs, runtimeVisibleTypeAnnotations(), a -> a.annotations().stream().map(TypeAnnotationRecord::ofTypeAnnotation).collect(toSet())),
|
||||
mapAttr(attrs, runtimeInvisibleTypeAnnotations(), a -> a.annotations().stream().map(TypeAnnotationRecord::ofTypeAnnotation).collect(toSet())),
|
||||
mapAttr(attrs, signature(), a -> a.signature().stringValue()),
|
||||
mapAttr(attrs, sourceDebugExtension(), a -> new String(a.contents(), StandardCharsets.UTF_8)),
|
||||
mapAttr(attrs, sourceFile(), a -> a.sourceFile().stringValue()),
|
||||
mapAttr(attrs, sourceId(), a -> a.sourceId().stringValue()),
|
||||
mapAttr(attrs, synthetic(), a -> DefinedValue.DEFINED)
|
||||
);
|
||||
}
|
||||
|
||||
public static AttributesRecord ofAttributes(AttributeFinder af, CompatibilityFilter... cf) {
|
||||
return new AttributesRecord(
|
||||
af.findAndMap(Attributes.ANNOTATION_DEFAULT, a -> ElementValueRecord.ofElementValue(a.defaultValue())),
|
||||
af.findAndMap(Attributes.BOOTSTRAP_METHODS, a -> a.bootstrapMethods().stream().map(bm -> BootstrapMethodRecord.ofBootstrapMethodEntry(bm)).collect(toSet())),
|
||||
af.findAndMap(Attributes.CODE, a -> CodeRecord.ofCodeAttribute(a, cf)),
|
||||
af.findAndMap(Attributes.COMPILATION_ID, a -> a.compilationId().stringValue()),
|
||||
af.findAndMap(Attributes.CONSTANT_VALUE, a -> ConstantPoolEntryRecord.ofCPEntry(a.constant())),
|
||||
af.findAndMap(Attributes.DEPRECATED, a -> DefinedValue.DEFINED),
|
||||
af.findAndMap(Attributes.ENCLOSING_METHOD, a -> EnclosingMethodRecord.ofEnclosingMethodAttribute(a)),
|
||||
af.findAndMap(Attributes.EXCEPTIONS, a -> a.exceptions().stream().map(e -> e.asInternalName()).collect(toSet())),
|
||||
af.findAndMap(Attributes.INNER_CLASSES, a -> a.classes().stream().collect(toMap(ic -> ic.innerClass().asInternalName(), ic -> InnerClassRecord.ofInnerClassInfo(ic)))),
|
||||
af.findAndMap(Attributes.METHOD_PARAMETERS, a -> a.parameters().stream().map(mp -> MethodParameterRecord.ofMethodParameter(mp)).toList()),
|
||||
af.findAndMap(Attributes.MODULE, a -> ModuleRecord.ofModuleAttribute(a)),
|
||||
af.findAndMap(Attributes.MODULE_HASHES, a -> ModuleHashesRecord.ofModuleHashesAttribute(a)),
|
||||
af.findAndMap(Attributes.MODULE_MAIN_CLASS, a -> a.mainClass().asInternalName()),
|
||||
af.findAndMap(Attributes.MODULE_PACKAGES, a -> a.packages().stream().map(p -> p.name().stringValue()).collect(toSet())),
|
||||
af.findAndMap(Attributes.MODULE_RESOLUTION, a -> a.resolutionFlags()),
|
||||
af.findAndMap(Attributes.MODULE_TARGET, a -> a.targetPlatform().stringValue()),
|
||||
af.findAndMap(Attributes.NEST_HOST, a -> a.nestHost().asInternalName()),
|
||||
af.findAndMap(Attributes.NEST_MEMBERS, a -> a.nestMembers().stream().map(m -> m.asInternalName()).collect(toSet())),
|
||||
af.findAndMap(Attributes.PERMITTED_SUBCLASSES, a -> a.permittedSubclasses().stream().map(e -> e.asInternalName()).collect(toSet())),
|
||||
af.findAndMap(RECORD, a -> a.components().stream().map(rc -> RecordComponentRecord.ofRecordComponent(rc, cf)).toList()),
|
||||
af.findAll(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).flatMap(a -> a.annotations().stream()).map(AnnotationRecord::ofAnnotation).collect(toSetOrNull()),
|
||||
af.findAll(Attributes.RUNTIME_INVISIBLE_ANNOTATIONS).flatMap(a -> a.annotations().stream()).map(AnnotationRecord::ofAnnotation).collect(toSetOrNull()),
|
||||
af.findAndMap(Attributes.RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS, a -> a.parameterAnnotations().stream().map(list -> list.stream().map(AnnotationRecord::ofAnnotation).collect(toSet())).toList()),
|
||||
af.findAndMap(Attributes.RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS, a -> a.parameterAnnotations().stream().map(list -> list.stream().map(AnnotationRecord::ofAnnotation).collect(toSet())).toList()),
|
||||
af.findAndMap(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, a -> a.annotations().stream().map(TypeAnnotationRecord::ofTypeAnnotation).collect(toSet())),
|
||||
af.findAndMap(Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, a -> a.annotations().stream().map(TypeAnnotationRecord::ofTypeAnnotation).collect(toSet())),
|
||||
af.findAndMap(Attributes.SIGNATURE, a -> a.signature().stringValue()),
|
||||
af.findAndMap(Attributes.SOURCE_DEBUG_EXTENSION, a -> new String(a.contents(), StandardCharsets.UTF_8)),
|
||||
af.findAndMap(Attributes.SOURCE_FILE, a -> a.sourceFile().stringValue()),
|
||||
af.findAndMap(Attributes.SOURCE_ID, a -> a.sourceId().stringValue()),
|
||||
af.findAndMap(Attributes.SYNTHETIC, a -> DefinedValue.DEFINED));
|
||||
af.findAndMap(annotationDefault(), a -> ElementValueRecord.ofElementValue(a.defaultValue())),
|
||||
af.findAndMap(bootstrapMethods(), a -> a.bootstrapMethods().stream().map(bm -> BootstrapMethodRecord.ofBootstrapMethodEntry(bm)).collect(toSet())),
|
||||
af.findAndMap(code(), a -> CodeRecord.ofCodeAttribute(a, cf)),
|
||||
af.findAndMap(compilationId(), a -> a.compilationId().stringValue()),
|
||||
af.findAndMap(constantValue(), a -> ConstantPoolEntryRecord.ofCPEntry(a.constant())),
|
||||
af.findAndMap(Attributes.deprecated(), a -> DefinedValue.DEFINED),
|
||||
af.findAndMap(enclosingMethod(), a -> EnclosingMethodRecord.ofEnclosingMethodAttribute(a)),
|
||||
af.findAndMap(exceptions(), a -> a.exceptions().stream().map(e -> e.asInternalName()).collect(toSet())),
|
||||
af.findAndMap(innerClasses(), a -> a.classes().stream().collect(toMap(ic -> ic.innerClass().asInternalName(), ic -> InnerClassRecord.ofInnerClassInfo(ic)))),
|
||||
af.findAndMap(methodParameters(), a -> a.parameters().stream().map(mp -> MethodParameterRecord.ofMethodParameter(mp)).toList()),
|
||||
af.findAndMap(module(), a -> ModuleRecord.ofModuleAttribute(a)),
|
||||
af.findAndMap(moduleHashes(), a -> ModuleHashesRecord.ofModuleHashesAttribute(a)),
|
||||
af.findAndMap(moduleMainClass(), a -> a.mainClass().asInternalName()),
|
||||
af.findAndMap(modulePackages(), a -> a.packages().stream().map(p -> p.name().stringValue()).collect(toSet())),
|
||||
af.findAndMap(moduleResolution(), a -> a.resolutionFlags()),
|
||||
af.findAndMap(moduleTarget(), a -> a.targetPlatform().stringValue()),
|
||||
af.findAndMap(nestHost(), a -> a.nestHost().asInternalName()),
|
||||
af.findAndMap(nestMembers(), a -> a.nestMembers().stream().map(m -> m.asInternalName()).collect(toSet())),
|
||||
af.findAndMap(permittedSubclasses(), a -> a.permittedSubclasses().stream().map(e -> e.asInternalName()).collect(toSet())),
|
||||
af.findAndMap(record(), a -> a.components().stream().map(rc -> RecordComponentRecord.ofRecordComponent(rc, cf)).toList()),
|
||||
af.findAll(runtimeVisibleAnnotations()).flatMap(a -> a.annotations().stream()).map(AnnotationRecord::ofAnnotation).collect(toSetOrNull()),
|
||||
af.findAll(runtimeInvisibleAnnotations()).flatMap(a -> a.annotations().stream()).map(AnnotationRecord::ofAnnotation).collect(toSetOrNull()),
|
||||
af.findAndMap(runtimeVisibleParameterAnnotations(), a -> a.parameterAnnotations().stream().map(list -> list.stream().map(AnnotationRecord::ofAnnotation).collect(toSet())).toList()),
|
||||
af.findAndMap(runtimeInvisibleParameterAnnotations(), a -> a.parameterAnnotations().stream().map(list -> list.stream().map(AnnotationRecord::ofAnnotation).collect(toSet())).toList()),
|
||||
af.findAndMap(runtimeVisibleTypeAnnotations(), a -> a.annotations().stream().map(TypeAnnotationRecord::ofTypeAnnotation).collect(toSet())),
|
||||
af.findAndMap(runtimeInvisibleTypeAnnotations(), a -> a.annotations().stream().map(TypeAnnotationRecord::ofTypeAnnotation).collect(toSet())),
|
||||
af.findAndMap(signature(), a -> a.signature().stringValue()),
|
||||
af.findAndMap(sourceDebugExtension(), a -> new String(a.contents(), StandardCharsets.UTF_8)),
|
||||
af.findAndMap(sourceFile(), a -> a.sourceFile().stringValue()),
|
||||
af.findAndMap(sourceId(), a -> a.sourceId().stringValue()),
|
||||
af.findAndMap(synthetic(), a -> DefinedValue.DEFINED));
|
||||
}
|
||||
}
|
||||
|
||||
@ -353,12 +353,12 @@ public record ClassRecord(
|
||||
|
||||
static CodeAttributesRecord ofAttributes(AttributeFinder af, CodeNormalizerHelper code, CodeAttribute lr, CompatibilityFilter... cf) {
|
||||
return new CodeAttributesRecord(
|
||||
af.findAll(Attributes.CHARACTER_RANGE_TABLE).flatMap(a -> a.characterRangeTable().stream()).map(cr -> CharacterRangeRecord.ofCharacterRange(cr, code)).collect(toSetOrNull()),
|
||||
af.findAll(Attributes.LINE_NUMBER_TABLE).flatMap(a -> a.lineNumbers().stream()).map(ln -> new LineNumberRecord(ln.lineNumber(), code.targetIndex(ln.startPc()))).collect(toSetOrNull()),
|
||||
af.findAll(Attributes.LOCAL_VARIABLE_TABLE).flatMap(a -> a.localVariables().stream()).map(lv -> LocalVariableRecord.ofLocalVariableInfo(lv, code)).collect(toSetOrNull()),
|
||||
af.findAll(Attributes.LOCAL_VARIABLE_TYPE_TABLE).flatMap(a -> a.localVariableTypes().stream()).map(lv -> LocalVariableTypeRecord.ofLocalVariableTypeInfo(lv, code)).collect(toSetOrNull()),
|
||||
af.findAndMap(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, a -> a.annotations().stream().map(ann -> TypeAnnotationRecord.ofTypeAnnotation(ann, lr, code)).collect(toSet())),
|
||||
af.findAndMap(Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, a -> a.annotations().stream().map(ann -> TypeAnnotationRecord.ofTypeAnnotation(ann, lr, code)).collect(toSet())));
|
||||
af.findAll(Attributes.characterRangeTable()).flatMap(a -> a.characterRangeTable().stream()).map(cr -> CharacterRangeRecord.ofCharacterRange(cr, code)).collect(toSetOrNull()),
|
||||
af.findAll(Attributes.lineNumberTable()).flatMap(a -> a.lineNumbers().stream()).map(ln -> new LineNumberRecord(ln.lineNumber(), code.targetIndex(ln.startPc()))).collect(toSetOrNull()),
|
||||
af.findAll(Attributes.localVariableTable()).flatMap(a -> a.localVariables().stream()).map(lv -> LocalVariableRecord.ofLocalVariableInfo(lv, code)).collect(toSetOrNull()),
|
||||
af.findAll(Attributes.localVariableTypeTable()).flatMap(a -> a.localVariableTypes().stream()).map(lv -> LocalVariableTypeRecord.ofLocalVariableTypeInfo(lv, code)).collect(toSetOrNull()),
|
||||
af.findAndMap(Attributes.runtimeVisibleTypeAnnotations(), a -> a.annotations().stream().map(ann -> TypeAnnotationRecord.ofTypeAnnotation(ann, lr, code)).collect(toSet())),
|
||||
af.findAndMap(Attributes.runtimeInvisibleTypeAnnotations(), a -> a.annotations().stream().map(ann -> TypeAnnotationRecord.ofTypeAnnotation(ann, lr, code)).collect(toSet())));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ class RebuildingTransformation {
|
||||
// first pass transforms bound to unbound instructions
|
||||
cob3.transforming(new CodeRebuildingTransform(), cob4 -> {
|
||||
com.forEachElement(cob4::with);
|
||||
com.findAttribute(Attributes.STACK_MAP_TABLE).ifPresent(cob4::with);
|
||||
com.findAttribute(Attributes.stackMapTable()).ifPresent(cob4::with);
|
||||
}))));
|
||||
case AnnotationDefaultAttribute a -> mb.with(AnnotationDefaultAttribute.of(transformAnnotationValue(a.defaultValue())));
|
||||
case DeprecatedAttribute a -> mb.with(DeprecatedAttribute.of());
|
||||
|
@ -164,7 +164,7 @@ public class CallerSensitiveFinder {
|
||||
|
||||
private static final String CALLER_SENSITIVE_ANNOTATION = "Ljdk/internal/reflect/CallerSensitive;";
|
||||
private static boolean isCallerSensitive(MethodModel m) {
|
||||
var attr = m.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).orElse(null);
|
||||
var attr = m.findAttribute(Attributes.runtimeVisibleAnnotations()).orElse(null);
|
||||
if (attr != null) {
|
||||
for (var ann : attr.annotations()) {
|
||||
if (ann.className().equalsString(CALLER_SENSITIVE_ANNOTATION)) {
|
||||
|
@ -238,7 +238,7 @@ public class CheckCSMs {
|
||||
private static boolean isCallerSensitive(MethodModel m)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
var attr = m.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).orElse(null);
|
||||
var attr = m.findAttribute(Attributes.runtimeVisibleAnnotations()).orElse(null);
|
||||
if (attr != null) {
|
||||
for (var ann : attr.annotations()) {
|
||||
if (ann.className().equalsString(CALLER_SENSITIVE_ANNOTATION)) {
|
||||
@ -250,7 +250,7 @@ public class CheckCSMs {
|
||||
}
|
||||
|
||||
private static boolean isCallerSensitiveAdapter(MethodModel m) {
|
||||
var attr = m.findAttribute(Attributes.RUNTIME_INVISIBLE_ANNOTATIONS).orElse(null);
|
||||
var attr = m.findAttribute(Attributes.runtimeInvisibleAnnotations()).orElse(null);
|
||||
|
||||
if (attr != null) {
|
||||
for (var ann : attr.annotations()) {
|
||||
|
@ -137,16 +137,16 @@ public class StripJavaDebugAttributesPluginTest {
|
||||
ClassModel classFile = ClassFile.of().parse(strippedClassFile);
|
||||
for (MethodModel method : classFile.methods()) {
|
||||
String methodName = method.methodName().stringValue();
|
||||
CodeAttribute code = method.findAttribute(Attributes.CODE).orElseThrow();
|
||||
if (code.findAttribute(Attributes.LINE_NUMBER_TABLE).orElse(null) != null) {
|
||||
CodeAttribute code = method.findAttribute(Attributes.code()).orElseThrow();
|
||||
if (code.findAttribute(Attributes.lineNumberTable()).orElse(null) != null) {
|
||||
throw new AssertionError("Debug attribute was not removed: " + "LINE_NUMBER_TABLE" +
|
||||
" from method " + classFile.thisClass().asInternalName() + "#" + methodName);
|
||||
}
|
||||
if (code.findAttribute(Attributes.LOCAL_VARIABLE_TABLE).orElse(null) != null) {
|
||||
if (code.findAttribute(Attributes.localVariableTable()).orElse(null) != null) {
|
||||
throw new AssertionError("Debug attribute was not removed: " + "LOCAL_VARIABLE_TABLE" +
|
||||
" from method " + classFile.thisClass().asInternalName() + "#" + methodName);
|
||||
}
|
||||
if (code.findAttribute(Attributes.LOCAL_VARIABLE_TYPE_TABLE).orElse(null) != null) {
|
||||
if (code.findAttribute(Attributes.localVariableTypeTable()).orElse(null) != null) {
|
||||
throw new AssertionError("Debug attribute was not removed: " + "LOCAL_VARIABLE_TYPE_TABLE" +
|
||||
" from method " + classFile.thisClass().asInternalName() + "#" + methodName);
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ public class T4241573 {
|
||||
System.err.println("verify: " + f);
|
||||
try {
|
||||
ClassModel cf = ClassFile.of().parse(f.toPath());
|
||||
SourceFileAttribute sfa = cf.findAttribute(Attributes.SOURCE_FILE).orElseThrow();
|
||||
SourceFileAttribute sfa = cf.findAttribute(Attributes.sourceFile()).orElseThrow();
|
||||
String found = sfa.sourceFile().stringValue();
|
||||
String expect = f.getName().replaceAll("([$.].*)?\\.class", ".java");
|
||||
if (!expect.equals(found)) {
|
||||
|
@ -163,7 +163,7 @@ public class T7003595 {
|
||||
throw new Error("Classfile not found: " + filename);
|
||||
}
|
||||
|
||||
InnerClassesAttribute innerClasses = cf.findAttribute(Attributes.INNER_CLASSES).orElse(null);
|
||||
InnerClassesAttribute innerClasses = cf.findAttribute(Attributes.innerClasses()).orElse(null);
|
||||
|
||||
ArrayList<String> foundInnerSig = new ArrayList<>();
|
||||
if (innerClasses != null) {
|
||||
|
@ -56,7 +56,7 @@ public class RedundantByteCodeInArrayTest {
|
||||
//lets get all the methods in the class file.
|
||||
for (MethodModel method : classFile.methods()) {
|
||||
if (method.methodName().equalsString("arrMethod")) {
|
||||
CodeAttribute code = method.findAttribute(Attributes.CODE).orElse(null);
|
||||
CodeAttribute code = method.findAttribute(Attributes.code()).orElse(null);
|
||||
assert code != null;
|
||||
if (code.maxLocals() > 4)
|
||||
throw new AssertionError("Too many locals for method arrMethod");
|
||||
|
@ -125,7 +125,7 @@ public class AnonymousClassFlags {
|
||||
}
|
||||
|
||||
private static int lookupInnerFlags(ClassModel classFile, String innerName) {
|
||||
InnerClassesAttribute inners = classFile.findAttribute(Attributes.INNER_CLASSES).orElse(null);
|
||||
InnerClassesAttribute inners = classFile.findAttribute(Attributes.innerClasses()).orElse(null);
|
||||
if (inners == null) {
|
||||
throw new AssertionError("InnerClasses attribute missing in class " + classFile.thisClass().asInternalName());
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ class ClassFileVisitor extends MethodParametersTester.Visitor {
|
||||
isStatic = false;
|
||||
isAnon = false;
|
||||
|
||||
classFile.findAttribute(Attributes.INNER_CLASSES).ifPresent(this::visitInnerClasses);
|
||||
classFile.findAttribute(Attributes.innerClasses()).ifPresent(this::visitInnerClasses);
|
||||
isAnon = isInner & isAnon;
|
||||
|
||||
sb.append(isStatic ? "static " : "")
|
||||
|
@ -86,7 +86,7 @@ public class LegacyOutputTest {
|
||||
}
|
||||
ClassModel classFile = ClassFile.of().parse(Paths.get("Test.class"));
|
||||
MethodModel method = getMethod(classFile, "f");
|
||||
MethodParametersAttribute attribute = method.findAttribute(Attributes.METHOD_PARAMETERS).orElse(null);
|
||||
MethodParametersAttribute attribute = method.findAttribute(Attributes.methodParameters()).orElse(null);
|
||||
if (attribute == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -175,8 +175,8 @@ public class MethodParametersTest {
|
||||
if (!baz.methods().get(0).methodName().equalsString("<init>"))
|
||||
throw new Exception("Classfile Baz badly formed: method has name " +
|
||||
baz.methods().get(0).methodName().stringValue());
|
||||
MethodParametersAttribute mpattr = baz.methods().get(0).findAttribute(Attributes.METHOD_PARAMETERS).orElse(null);
|
||||
CodeAttribute cattr = baz.methods().get(0).findAttribute(Attributes.CODE).orElse(null);;
|
||||
MethodParametersAttribute mpattr = baz.methods().get(0).findAttribute(Attributes.methodParameters()).orElse(null);
|
||||
CodeAttribute cattr = baz.methods().get(0).findAttribute(Attributes.code()).orElse(null);;
|
||||
if (null == mpattr)
|
||||
throw new Exception("Classfile Baz badly formed: no method parameters info");
|
||||
if (null == cattr)
|
||||
|
@ -195,7 +195,7 @@ public class ImplicitParameters extends TestRunner {
|
||||
}
|
||||
|
||||
private void checkParameters(MethodModel method, int... parametersFlags) {
|
||||
MethodParametersAttribute methodParameters = method.findAttribute(Attributes.METHOD_PARAMETERS).orElseThrow();
|
||||
MethodParametersAttribute methodParameters = method.findAttribute(Attributes.methodParameters()).orElseThrow();
|
||||
Assert.checkNonNull(methodParameters, "MethodParameters attribute must be present");
|
||||
List<MethodParameterInfo> table = methodParameters.parameters();
|
||||
Assert.check(table.size() == parametersFlags.length, () -> "Expected " + parametersFlags.length
|
||||
|
@ -24,13 +24,12 @@
|
||||
import jdk.test.lib.compiler.CompilerUtils;
|
||||
import toolbox.ToolBox;
|
||||
|
||||
import java.lang.classfile.Attributes;
|
||||
import java.lang.classfile.BootstrapMethodEntry;
|
||||
import java.lang.classfile.ClassFile;
|
||||
import java.lang.classfile.ClassModel;
|
||||
import java.lang.classfile.CodeElement;
|
||||
import java.lang.classfile.CodeModel;
|
||||
import java.lang.classfile.MethodModel;
|
||||
import java.lang.classfile.attribute.CodeAttribute;
|
||||
import java.lang.classfile.constantpool.MethodHandleEntry;
|
||||
import java.lang.classfile.instruction.InvokeDynamicInstruction;
|
||||
import java.nio.file.Path;
|
||||
@ -87,7 +86,7 @@ public class TestIndyStringConcat {
|
||||
|
||||
for (MethodModel method : classFile.methods()) {
|
||||
if (method.methodName().equalsString(methodName)) {
|
||||
CodeAttribute code = method.findAttribute(Attributes.CODE).orElseThrow();
|
||||
CodeModel code = method.code().orElseThrow();
|
||||
for (CodeElement i : code.elementList()) {
|
||||
if (i instanceof InvokeDynamicInstruction indy) {
|
||||
BootstrapMethodEntry bsmSpec = indy.invokedynamic().bootstrap();
|
||||
|
@ -104,7 +104,7 @@ public class WellKnownTypeSignatures {
|
||||
|
||||
for (MethodModel method : classFile.methods()) {
|
||||
if (method.methodName().equalsString("main")) {
|
||||
CodeAttribute code = method.findAttribute(Attributes.CODE).orElseThrow();
|
||||
CodeAttribute code = method.findAttribute(Attributes.code()).orElseThrow();
|
||||
for (CodeElement i : code.elementList()) {
|
||||
if (i instanceof InvokeDynamicInstruction) {
|
||||
InvokeDynamicInstruction indy = (InvokeDynamicInstruction) i;
|
||||
|
@ -182,7 +182,7 @@ public class Test {
|
||||
|
||||
for (MethodModel method : classFile.methods()) {
|
||||
if (method.methodName().equalsString("main")) {
|
||||
CodeAttribute code = method.findAttribute(Attributes.CODE).orElseThrow();
|
||||
CodeAttribute code = method.findAttribute(Attributes.code()).orElseThrow();
|
||||
for (CodeElement i : code.elementList()) {
|
||||
if (i instanceof InvokeDynamicInstruction) {
|
||||
InvokeDynamicEntry indyInfo = ((InvokeDynamicInstruction) i).invokedynamic();
|
||||
|
@ -63,9 +63,9 @@ public class AnnotationsAreNotCopiedToBridgeMethodsTest {
|
||||
ClassModel classFile = ClassFile.of().parse(cfilePath);
|
||||
for (MethodModel method : classFile.methods()) {
|
||||
if ((method.flags().flagsMask() & ClassFile.ACC_BRIDGE) != 0) {
|
||||
Assert.checkNonNull(method.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS),
|
||||
Assert.checkNonNull(method.findAttribute(Attributes.runtimeVisibleAnnotations()),
|
||||
"Annotations hasn't been copied to bridge method");
|
||||
Assert.checkNonNull(method.findAttribute(Attributes.RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS),
|
||||
Assert.checkNonNull(method.findAttribute(Attributes.runtimeVisibleParameterAnnotations()),
|
||||
"Annotations hasn't been copied to bridge method");
|
||||
}
|
||||
}
|
||||
|
@ -94,8 +94,8 @@ public class DebugPointerAtBadPositionTest {
|
||||
for (MethodModel m : classFile.methods()) {
|
||||
if (m.methodName().equalsString(methodToFind)) {
|
||||
methodFound = true;
|
||||
CodeAttribute code = m.findAttribute(Attributes.CODE).orElseThrow();
|
||||
LineNumberTableAttribute lnt = code.findAttribute(Attributes.LINE_NUMBER_TABLE).orElseThrow();
|
||||
CodeAttribute code = m.findAttribute(Attributes.code()).orElseThrow();
|
||||
LineNumberTableAttribute lnt = code.findAttribute(Attributes.lineNumberTable()).orElseThrow();
|
||||
Assert.check(lnt.lineNumbers().size() == expectedLNT.length,
|
||||
foundLNTLengthDifferentThanExpMsg);
|
||||
int i = 0;
|
||||
|
@ -101,8 +101,8 @@ public class InlinedFinallyConfuseDebuggersTest {
|
||||
for (MethodModel m : classFile.methods()) {
|
||||
if (m.methodName().equalsString(methodToFind)) {
|
||||
methodFound = true;
|
||||
CodeAttribute code = m.findAttribute(Attributes.CODE).orElseThrow();
|
||||
LineNumberTableAttribute lnt = code.findAttribute(Attributes.LINE_NUMBER_TABLE).orElseThrow();
|
||||
CodeAttribute code = m.findAttribute(Attributes.code()).orElseThrow();
|
||||
LineNumberTableAttribute lnt = code.findAttribute(Attributes.lineNumberTable()).orElseThrow();
|
||||
Assert.check(lnt.lineNumbers().size() == expectedLNT.length,
|
||||
"The LineNumberTable found has a length different to the expected one");
|
||||
int i = 0;
|
||||
|
@ -68,7 +68,7 @@ public class DoubleCastTest {
|
||||
static void check(MethodModel m) throws Exception {
|
||||
boolean last_is_cast = false;
|
||||
ClassEntry last_ref = null;
|
||||
CodeAttribute ea = m.findAttribute(Attributes.CODE).orElseThrow();
|
||||
CodeAttribute ea = m.findAttribute(Attributes.code()).orElseThrow();
|
||||
for (int i = 0; i < ea.elementList().size(); ++i) {
|
||||
CodeElement ce = ea.elementList().get(i);
|
||||
if (ce instanceof TypeCheckInstruction ins && ins.opcode() == Opcode.CHECKCAST) {
|
||||
|
@ -167,7 +167,7 @@ public class T7093325 extends ComboInstance<T7093325> {
|
||||
return;
|
||||
}
|
||||
|
||||
CodeAttribute code = test_method.findAttribute(Attributes.CODE).orElse(null);
|
||||
CodeAttribute code = test_method.findAttribute(Attributes.code()).orElse(null);
|
||||
|
||||
if (code == null) {
|
||||
fail("Code attribute not found in method test()");
|
||||
|
@ -48,7 +48,7 @@ public class InnerClassAttrMustNotHaveStrictFPFlagTest {
|
||||
|
||||
void analyzeClassFile(File path) throws Exception {
|
||||
ClassModel classFile = ClassFile.of().parse(path.toPath());
|
||||
InnerClassesAttribute innerClasses = classFile.findAttribute(Attributes.INNER_CLASSES).orElse(null);
|
||||
InnerClassesAttribute innerClasses = classFile.findAttribute(Attributes.innerClasses()).orElse(null);
|
||||
assert innerClasses != null;
|
||||
for (InnerClassInfo classInfo : innerClasses.classes()) {
|
||||
Assert.check(classInfo.flagsMask() != ClassFile.ACC_STRICT,
|
||||
|
@ -163,8 +163,8 @@ public class WrongLNTForLambdaTest {
|
||||
for (MethodModel method : classFile.methods()) {
|
||||
if (method.methodName().equalsString(methodToFind)) {
|
||||
methodFound = true;
|
||||
CodeAttribute code = method.findAttribute(Attributes.CODE).orElseThrow();
|
||||
LineNumberTableAttribute lnt = code.findAttribute(Attributes.LINE_NUMBER_TABLE).orElseThrow();
|
||||
CodeAttribute code = method.findAttribute(Attributes.code()).orElseThrow();
|
||||
LineNumberTableAttribute lnt = code.findAttribute(Attributes.lineNumberTable()).orElseThrow();
|
||||
Assert.check(lnt.lineNumbers().size() == expectedLNT.length,
|
||||
"The LineNumberTable found has a length different to the expected one");
|
||||
int i = 0;
|
||||
|
@ -64,7 +64,7 @@ public class DeadCodeGeneratedForEmptyTryTest {
|
||||
constantPool = classFile.constantPool();
|
||||
for (MethodModel method: classFile.methods()) {
|
||||
if (method.methodName().equalsString("methodToLookFor")) {
|
||||
CodeAttribute codeAtt = method.findAttribute(Attributes.CODE).orElseThrow();
|
||||
CodeAttribute codeAtt = method.findAttribute(Attributes.code()).orElseThrow();
|
||||
codeAtt.elementList().stream()
|
||||
.filter(ce -> ce instanceof Instruction)
|
||||
.forEach(ins -> checkIndirectRefToString((Instruction) ins));
|
||||
|
@ -106,7 +106,7 @@ public class NoDeadCodeGenerationOnTrySmtTest {
|
||||
for (MethodModel m : classFile.methods()) {
|
||||
if (m.methodName().equalsString(methodToFind)) {
|
||||
numberOfmethodsFound++;
|
||||
CodeAttribute code = m.findAttribute(Attributes.CODE).orElseThrow();
|
||||
CodeAttribute code = m.findAttribute(Attributes.code()).orElseThrow();
|
||||
Assert.check(code.exceptionHandlers().size() == expectedExceptionTable.length,
|
||||
"The ExceptionTable found has a length different to the expected one");
|
||||
int i = 0;
|
||||
|
@ -52,9 +52,9 @@ public class DontGenerateLVTForGNoneOpTest {
|
||||
void checkClassFile(final File cfile) throws Exception {
|
||||
ClassModel classFile = ClassFile.of().parse(cfile.toPath());
|
||||
for (MethodModel method : classFile.methods()) {
|
||||
CodeAttribute code = method.findAttribute(Attributes.CODE).orElse(null);
|
||||
CodeAttribute code = method.findAttribute(Attributes.code()).orElse(null);
|
||||
if (code != null) {
|
||||
if (code.findAttribute(Attributes.LOCAL_VARIABLE_TABLE).orElse(null) != null) {
|
||||
if (code.findAttribute(Attributes.localVariableTable()).orElse(null) != null) {
|
||||
throw new AssertionError("LVT shouldn't be generated for g:none");
|
||||
}
|
||||
}
|
||||
|
@ -92,8 +92,8 @@ public class MissingLNTEntryForBreakContinueTest {
|
||||
ClassModel classFile = ClassFile.of().parse(file.toPath());
|
||||
for (MethodModel m : classFile.methods()) {
|
||||
if (m.methodName().equalsString("foo")) {
|
||||
CodeAttribute code = m.findAttribute(Attributes.CODE).orElseThrow();
|
||||
LineNumberTableAttribute lnt = code.findAttribute(Attributes.LINE_NUMBER_TABLE).orElseThrow();
|
||||
CodeAttribute code = m.findAttribute(Attributes.code()).orElseThrow();
|
||||
LineNumberTableAttribute lnt = code.findAttribute(Attributes.lineNumberTable()).orElseThrow();
|
||||
checkLNT(lnt, MyAttr.lineNumber);
|
||||
}
|
||||
}
|
||||
|
@ -88,8 +88,8 @@ public class MissingLNTEntryForFinalizerTest {
|
||||
ClassModel classFile = ClassFile.of().parse(file.toPath());
|
||||
for (MethodModel m : classFile.methods()) {
|
||||
if (m.methodName().equalsString("foo")) {
|
||||
CodeAttribute code = m.findAttribute(Attributes.CODE).orElseThrow();
|
||||
LineNumberTableAttribute lnt = code.findAttribute(Attributes.LINE_NUMBER_TABLE).orElseThrow();
|
||||
CodeAttribute code = m.findAttribute(Attributes.code()).orElseThrow();
|
||||
LineNumberTableAttribute lnt = code.findAttribute(Attributes.lineNumberTable()).orElseThrow();
|
||||
checkLNT(lnt, MyAttr.lineNumber);
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public class NoLocalsMustBeReservedForDCEedVarsTest {
|
||||
ClassModel classFile = ClassFile.of().parse(cfile.toPath());
|
||||
for (MethodModel method: classFile.methods()) {
|
||||
if (method.methodName().stringValue().equals("foo")) {
|
||||
CodeAttribute codeAttr = method.findAttribute(Attributes.CODE).orElse(null);
|
||||
CodeAttribute codeAttr = method.findAttribute(Attributes.code()).orElse(null);
|
||||
assert codeAttr != null;
|
||||
Assert.check(codeAttr.maxLocals() == 0, "max locals found " + codeAttr.maxLocals());
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ public class TestConstantDynamic extends ComboInstance<TestConstantDynamic> {
|
||||
fail("Test method not found");
|
||||
return;
|
||||
}
|
||||
CodeAttribute ea = testMethod.findAttribute(Attributes.CODE).orElse(null);
|
||||
CodeAttribute ea = testMethod.findAttribute(Attributes.code()).orElse(null);
|
||||
if (ea == null) {
|
||||
fail("Code attribute for test() method not found");
|
||||
return;
|
||||
@ -216,7 +216,7 @@ public class TestConstantDynamic extends ComboInstance<TestConstantDynamic> {
|
||||
return;
|
||||
}
|
||||
|
||||
BootstrapMethodsAttribute bsm_attr = cf.findAttribute(Attributes.BOOTSTRAP_METHODS).orElseThrow();
|
||||
BootstrapMethodsAttribute bsm_attr = cf.findAttribute(Attributes.bootstrapMethods()).orElseThrow();
|
||||
if (bsm_attr.bootstrapMethods().size() != 1) {
|
||||
fail("Bad number of method specifiers " +
|
||||
"in BootstrapMethods attribute");
|
||||
@ -251,7 +251,7 @@ public class TestConstantDynamic extends ComboInstance<TestConstantDynamic> {
|
||||
return;
|
||||
}
|
||||
|
||||
LineNumberTableAttribute lnt = ea.findAttribute(Attributes.LINE_NUMBER_TABLE).orElse(null);
|
||||
LineNumberTableAttribute lnt = ea.findAttribute(Attributes.lineNumberTable()).orElse(null);
|
||||
|
||||
if (lnt == null) {
|
||||
fail("No LineNumberTable attribute");
|
||||
|
@ -101,7 +101,7 @@ public class TwrSimpleClose {
|
||||
ClassModel cf = ClassFile.of().parse(new ByteArrayInputStream(data).readAllBytes());
|
||||
|
||||
for (MethodModel m : cf.methods()) {
|
||||
CodeAttribute codeAttr = m.findAttribute(Attributes.CODE).orElseThrow();
|
||||
CodeAttribute codeAttr = m.findAttribute(Attributes.code()).orElseThrow();
|
||||
for (CodeElement ce : codeAttr.elementList()) {
|
||||
if (ce instanceof InvokeInstruction ins && ins.opcode() == Opcode.INVOKEVIRTUAL) {
|
||||
MemberRefEntry method = ins.method();
|
||||
|
@ -63,21 +63,21 @@ public record ApplicableAnnotationsOnRecords(@FieldAnnotation @MethodAnnotation
|
||||
if (methodName.equals("toString") || methodName.equals("hashCode") || methodName.equals("equals") || methodName.equals("main")) {
|
||||
// ignore
|
||||
} else if (methodName.equals("<init>")) {
|
||||
var paAnnos = mm.findAttribute(Attributes.RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS).orElseThrow().parameterAnnotations();
|
||||
var paAnnos = mm.findAttribute(Attributes.runtimeVisibleParameterAnnotations()).orElseThrow().parameterAnnotations();
|
||||
Assert.check(paAnnos.size() > 0);
|
||||
for (var pa : paAnnos) {
|
||||
Assert.check(pa.size() == 1);
|
||||
Assert.check(Objects.equals(pa.get(0).classSymbol().descriptorString(), "LParameterAnnotation;"));
|
||||
}
|
||||
} else {
|
||||
var annos = mm.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).orElseThrow().annotations();
|
||||
var annos = mm.findAttribute(Attributes.runtimeVisibleAnnotations()).orElseThrow().annotations();
|
||||
Assert.check(annos.size() == 1);
|
||||
Assert.check(Objects.equals(annos.get(0).classSymbol().descriptorString(), "LMethodAnnotation;"));
|
||||
}
|
||||
}
|
||||
Assert.check(cm.fields().size() > 0);
|
||||
for (FieldModel fm : cm.fields()) {
|
||||
var annos = fm.findAttribute(Attributes.RUNTIME_VISIBLE_ANNOTATIONS).orElseThrow().annotations();
|
||||
var annos = fm.findAttribute(Attributes.runtimeVisibleAnnotations()).orElseThrow().annotations();
|
||||
Assert.check(annos.size() == 1);
|
||||
Assert.check(Objects.equals(annos.getFirst().classSymbol().descriptorString(), "LFieldAnnotation;"));
|
||||
}
|
||||
|
@ -197,15 +197,15 @@ public class TypeAnnotationsPositionsOnRecords {
|
||||
|
||||
// utility methods
|
||||
void findAnnotations(ClassModel cm, AttributedElement m, List<TypeAnnotation> annos) {
|
||||
findAnnotations(cm, m, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, annos);
|
||||
findAnnotations(cm, m, Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, annos);
|
||||
findAnnotations(cm, m, Attributes.runtimeVisibleTypeAnnotations(), annos);
|
||||
findAnnotations(cm, m, Attributes.runtimeInvisibleTypeAnnotations(), annos);
|
||||
}
|
||||
|
||||
<T extends Attribute<T>> void findAnnotations(ClassModel cf, AttributedElement m, AttributeMapper<T> attrName, List<TypeAnnotation> annos) {
|
||||
Attribute<T> attr = m.findAttribute(attrName).orElse(null);
|
||||
addAnnos(annos, attr);
|
||||
if (m instanceof MethodModel) {
|
||||
CodeAttribute cattr = m.findAttribute(Attributes.CODE).orElse(null);
|
||||
CodeAttribute cattr = m.findAttribute(Attributes.code()).orElse(null);
|
||||
if (cattr != null) {
|
||||
attr = cattr.findAttribute(attrName).orElse(null);
|
||||
addAnnos(annos, attr);
|
||||
|
@ -110,15 +110,15 @@ public class VariablesDeclaredWithVarTest {
|
||||
}
|
||||
|
||||
void findAnnotations(ClassModel cf, MethodModel m, List<TypeAnnotation> annos) {
|
||||
findAnnotations(cf, m, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, annos);
|
||||
findAnnotations(cf, m, Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, annos);
|
||||
findAnnotations(cf, m, Attributes.runtimeVisibleTypeAnnotations(), annos);
|
||||
findAnnotations(cf, m, Attributes.runtimeInvisibleTypeAnnotations(), annos);
|
||||
}
|
||||
|
||||
<T extends Attribute<T>> void findAnnotations(ClassModel cf, AttributedElement m, AttributeMapper<T> attrName, List<TypeAnnotation> annos) {
|
||||
Attribute<T> attr = m.findAttribute(attrName).orElse(null);
|
||||
addAnnos(annos, attr);
|
||||
if (m instanceof MethodModel) {
|
||||
CodeAttribute cattr = m.findAttribute(Attributes.CODE).orElse(null);
|
||||
CodeAttribute cattr = m.findAttribute(Attributes.code()).orElse(null);
|
||||
if (cattr != null) {
|
||||
attr = cattr.findAttribute(attrName).orElse(null);
|
||||
addAnnos(annos, attr);
|
||||
|
@ -100,7 +100,7 @@ public class AnonymousClassTest {
|
||||
static void testAnonymousClassDeclaration() throws Exception {
|
||||
ClassModel cm = ClassFile.of().parse(Paths.get(ToolBox.testClasses, "AnonymousClassTest$1.class"));
|
||||
RuntimeVisibleTypeAnnotationsAttribute rvta =
|
||||
cm.findAttribute(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS).orElse(null);
|
||||
cm.findAttribute(Attributes.runtimeVisibleTypeAnnotations()).orElse(null);
|
||||
assert rvta != null;
|
||||
assertEquals(
|
||||
Set.of(
|
||||
@ -115,7 +115,7 @@ public class AnonymousClassTest {
|
||||
ClassModel cm = ClassFile.of().parse(Paths.get(ToolBox.testClasses, "AnonymousClassTest.class"));
|
||||
MethodModel method = findMethod(cm, "f");
|
||||
Set<TypeAnnotation> annotations = getRuntimeVisibleTypeAnnotations(method);
|
||||
CodeAttribute cAttr = method.findAttribute(Attributes.CODE).orElse(null);
|
||||
CodeAttribute cAttr = method.findAttribute(Attributes.code()).orElse(null);
|
||||
assertEquals(
|
||||
Set.of("@LAnonymousClassTest$TA;(0) NEW, offset=0, location=[INNER_TYPE]"),
|
||||
annotations.stream().map(a -> annotationDebugString(cm, cAttr, a)).collect(toSet()));
|
||||
@ -126,7 +126,7 @@ public class AnonymousClassTest {
|
||||
ClassFile.of().parse(Paths.get(ToolBox.testClasses, "AnonymousClassTest$Inner.class"));
|
||||
MethodModel method = findMethod(cm, "g");
|
||||
Set<TypeAnnotation> annotations = getRuntimeVisibleTypeAnnotations(method);
|
||||
CodeAttribute cAttr = method.findAttribute(Attributes.CODE).orElse(null);
|
||||
CodeAttribute cAttr = method.findAttribute(Attributes.code()).orElse(null);
|
||||
// The annotation needs two INNER_TYPE type path entries to apply to
|
||||
// AnonymousClassTest$Inner$1.
|
||||
assertEquals(
|
||||
@ -141,7 +141,7 @@ public class AnonymousClassTest {
|
||||
ClassFile.of().parse(Paths.get(ToolBox.testClasses, "AnonymousClassTest.class"));
|
||||
MethodModel method = findMethod(cm, "g");
|
||||
Set<TypeAnnotation> annotations = getRuntimeVisibleTypeAnnotations(method);
|
||||
CodeAttribute cAttr = method.findAttribute(Attributes.CODE).orElse(null);
|
||||
CodeAttribute cAttr = method.findAttribute(Attributes.code()).orElse(null);
|
||||
// Only @TA(4) is propagated to the anonymous class declaration.
|
||||
assertEquals(
|
||||
Set.of("@LAnonymousClassTest$TA;(4) NEW, offset=0, location=[INNER_TYPE]"),
|
||||
@ -152,7 +152,7 @@ public class AnonymousClassTest {
|
||||
ClassModel cm =
|
||||
ClassFile.of().parse(Paths.get(ToolBox.testClasses, "AnonymousClassTest$2.class"));
|
||||
RuntimeVisibleTypeAnnotationsAttribute rvta =
|
||||
cm.findAttribute(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS).orElse(null);
|
||||
cm.findAttribute(Attributes.runtimeVisibleTypeAnnotations()).orElse(null);
|
||||
assert rvta != null;
|
||||
assertEquals(
|
||||
Set.of(
|
||||
@ -168,14 +168,14 @@ public class AnonymousClassTest {
|
||||
ClassModel cm = ClassFile.of().parse(Paths.get(ToolBox.testClasses, "AnonymousClassTest.class"));
|
||||
MethodModel method = findMethod(cm, "<init>");
|
||||
Set<TypeAnnotation> annotations = getRuntimeVisibleTypeAnnotations(method);
|
||||
CodeAttribute cAttr1 = method.findAttribute(Attributes.CODE).orElse(null);
|
||||
CodeAttribute cAttr1 = method.findAttribute(Attributes.code()).orElse(null);
|
||||
assertEquals(
|
||||
Set.of("@LAnonymousClassTest$TA;(5) NEW, offset=4, location=[INNER_TYPE]"),
|
||||
annotations.stream().map(a -> annotationDebugString(cm, cAttr1, a)).collect(toSet()) );
|
||||
|
||||
method = findMethod(cm, "<clinit>");
|
||||
annotations = getRuntimeVisibleTypeAnnotations(method);
|
||||
CodeAttribute cAttr2 = method.findAttribute(Attributes.CODE).orElse(null);
|
||||
CodeAttribute cAttr2 = method.findAttribute(Attributes.code()).orElse(null);
|
||||
assertEquals(
|
||||
Set.of("@LAnonymousClassTest$TA;(6) NEW, offset=16, location=[INNER_TYPE]"),
|
||||
annotations.stream().map(a -> annotationDebugString(cm, cAttr2, a)).collect(toSet()) );
|
||||
@ -184,14 +184,14 @@ public class AnonymousClassTest {
|
||||
// Returns the Method's RuntimeVisibleTypeAnnotations, and asserts that there are no RVTIs
|
||||
// erroneously associated with the Method instead of its Code attribute.
|
||||
private static Set<TypeAnnotation> getRuntimeVisibleTypeAnnotations(MethodModel method) {
|
||||
if (method.findAttribute(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS).orElse(null) != null) {
|
||||
if (method.findAttribute(Attributes.runtimeVisibleTypeAnnotations()).orElse(null) != null) {
|
||||
throw new AssertionError(
|
||||
"expected no RuntimeVisibleTypeAnnotations attribute on enclosing method");
|
||||
}
|
||||
CodeAttribute code = method.findAttribute(Attributes.CODE).orElse(null);
|
||||
CodeAttribute code = method.findAttribute(Attributes.code()).orElse(null);
|
||||
assert code != null;
|
||||
RuntimeVisibleTypeAnnotationsAttribute rvta =
|
||||
code.findAttribute(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS).orElse(null);
|
||||
code.findAttribute(Attributes.runtimeVisibleTypeAnnotations()).orElse(null);
|
||||
assert rvta != null;
|
||||
return new HashSet<>(rvta.annotations());
|
||||
}
|
||||
|
@ -88,10 +88,10 @@ public class ClassfileTestHelper {
|
||||
|
||||
// 'local' determines whether to look for annotations in code attribute or not.
|
||||
void test(AttributedElement m, Boolean local) {
|
||||
test(m, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, local);
|
||||
test(m, Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, local);
|
||||
test(m, Attributes.RUNTIME_VISIBLE_ANNOTATIONS, local);
|
||||
test(m, Attributes.RUNTIME_INVISIBLE_ANNOTATIONS, local);
|
||||
test(m, Attributes.runtimeVisibleTypeAnnotations(), local);
|
||||
test(m, Attributes.runtimeInvisibleTypeAnnotations(), local);
|
||||
test(m, Attributes.runtimeVisibleAnnotations(), local);
|
||||
test(m, Attributes.runtimeInvisibleAnnotations(), local);
|
||||
}
|
||||
|
||||
// Test the result of MethodModel.findAttribute according to expectations
|
||||
@ -164,7 +164,7 @@ public class ClassfileTestHelper {
|
||||
CodeAttribute cAttr;
|
||||
Attribute<T> attr = null;
|
||||
if (local) {
|
||||
cAttr = m.findAttribute(Attributes.CODE).orElse(null);
|
||||
cAttr = m.findAttribute(Attributes.code()).orElse(null);
|
||||
if (cAttr != null) {
|
||||
attr = cAttr.findAttribute(annName).orElse(null);
|
||||
}
|
||||
|
@ -71,8 +71,8 @@ public class NoTargetAnnotations extends ClassfileTestHelper {
|
||||
|
||||
|
||||
void testDeclaration(AttributedElement m) {
|
||||
testDecl(m, Attributes.RUNTIME_VISIBLE_ANNOTATIONS);
|
||||
testDecl(m, Attributes.RUNTIME_INVISIBLE_ANNOTATIONS);
|
||||
testDecl(m, Attributes.runtimeVisibleAnnotations());
|
||||
testDecl(m, Attributes.runtimeInvisibleAnnotations());
|
||||
}
|
||||
|
||||
// test the result of AttributedElement.findAttribute according to expectations
|
||||
|
@ -63,10 +63,10 @@ public class TestAnonInnerClasses extends ClassfileTestHelper {
|
||||
File testSrc = new File(System.getProperty("test.src"));
|
||||
|
||||
AttributeMapper<?> [] AnnoAttributes = new AttributeMapper<?>[]{
|
||||
Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS,
|
||||
Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS,
|
||||
Attributes.RUNTIME_VISIBLE_ANNOTATIONS,
|
||||
Attributes.RUNTIME_INVISIBLE_ANNOTATIONS
|
||||
Attributes.runtimeVisibleTypeAnnotations(),
|
||||
Attributes.runtimeInvisibleTypeAnnotations(),
|
||||
Attributes.runtimeVisibleAnnotations(),
|
||||
Attributes.runtimeInvisibleAnnotations()
|
||||
};
|
||||
|
||||
// template for source files
|
||||
@ -175,7 +175,7 @@ public class TestAnonInnerClasses extends ClassfileTestHelper {
|
||||
((MethodModel) m).methodName().stringValue() : ((FieldModel) m).fieldName().stringValue();
|
||||
attr = m.findAttribute(AnnoType).orElse(null);
|
||||
//fetch index annotations from code attribute.
|
||||
CAttr = m.findAttribute(Attributes.CODE).orElse(null);
|
||||
CAttr = m.findAttribute(Attributes.code()).orElse(null);
|
||||
if (CAttr != null) {
|
||||
cattr = CAttr.findAttribute(AnnoType).orElse(null);
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ public class TestNewCastArray {
|
||||
memberName = mm.methodName().stringValue();
|
||||
if(codeattr) {
|
||||
//fetch index of and code attribute and annotations from code attribute.
|
||||
cAttr = mm.findAttribute(Attributes.CODE).orElse(null);
|
||||
cAttr = mm.findAttribute(Attributes.code()).orElse(null);
|
||||
if(cAttr != null) {
|
||||
attr = cAttr.findAttribute(name).orElse(null);
|
||||
}
|
||||
@ -99,7 +99,7 @@ public class TestNewCastArray {
|
||||
case FieldModel fm -> {
|
||||
memberName = fm.fieldName().stringValue();
|
||||
if(codeattr) {
|
||||
cAttr = fm.findAttribute(Attributes.CODE).orElse(null);
|
||||
cAttr = fm.findAttribute(Attributes.code()).orElse(null);
|
||||
if(cAttr != null) {
|
||||
attr = cAttr.findAttribute(name).orElse(null);
|
||||
}
|
||||
@ -207,14 +207,14 @@ public class TestNewCastArray {
|
||||
assert cm != null;
|
||||
if(clazz.startsWith("Test1")) {
|
||||
for (FieldModel fm: cm.fields())
|
||||
test(clazz, fm, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, false);
|
||||
test(clazz, fm, Attributes.runtimeVisibleTypeAnnotations(), false);
|
||||
for (MethodModel mm: cm.methods())
|
||||
test(clazz, mm, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, false);
|
||||
test(clazz, mm, Attributes.runtimeVisibleTypeAnnotations(), false);
|
||||
} else {
|
||||
for (FieldModel fm: cm.fields())
|
||||
test(clazz, fm, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, true);
|
||||
test(clazz, fm, Attributes.runtimeVisibleTypeAnnotations(), true);
|
||||
for (MethodModel mm: cm.methods())
|
||||
test(clazz, mm, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, true);
|
||||
test(clazz, mm, Attributes.runtimeVisibleTypeAnnotations(), true);
|
||||
}
|
||||
}
|
||||
report();
|
||||
|
@ -58,9 +58,9 @@ public class TypeAnnotationPropagationTest extends ClassfileTestHelper {
|
||||
}
|
||||
|
||||
assert f != null;
|
||||
CodeAttribute cattr = f.findAttribute(Attributes.CODE).orElse(null);
|
||||
CodeAttribute cattr = f.findAttribute(Attributes.code()).orElse(null);
|
||||
assert cattr != null;
|
||||
RuntimeVisibleTypeAnnotationsAttribute attr = cattr.findAttribute(Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS).orElse(null);
|
||||
RuntimeVisibleTypeAnnotationsAttribute attr = cattr.findAttribute(Attributes.runtimeVisibleTypeAnnotations()).orElse(null);
|
||||
|
||||
assert attr != null;
|
||||
List<TypeAnnotation.LocalVarTargetInfo> annosPosition = ((TypeAnnotation.LocalVarTarget) attr.annotations().get(0).targetInfo()).table();
|
||||
|
@ -37,8 +37,8 @@ public class ReferenceInfoUtil {
|
||||
|
||||
/////////////////// Extract type annotations //////////////////
|
||||
private static void findAnnotations(ClassModel cm, List<TAD> annos) {
|
||||
findAnnotations(cm, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, annos);
|
||||
findAnnotations(cm, Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, annos);
|
||||
findAnnotations(cm, Attributes.runtimeVisibleTypeAnnotations(), annos);
|
||||
findAnnotations(cm, Attributes.runtimeInvisibleTypeAnnotations(), annos);
|
||||
|
||||
for (FieldModel f : cm.fields()) {
|
||||
findAnnotations(f, annos);
|
||||
@ -49,8 +49,8 @@ public class ReferenceInfoUtil {
|
||||
}
|
||||
|
||||
private static void findAnnotations(AttributedElement ae, List<TAD> annos) {
|
||||
findAnnotations(ae, Attributes.RUNTIME_VISIBLE_TYPE_ANNOTATIONS, annos);
|
||||
findAnnotations(ae, Attributes.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS, annos);
|
||||
findAnnotations(ae, Attributes.runtimeVisibleTypeAnnotations(), annos);
|
||||
findAnnotations(ae, Attributes.runtimeInvisibleTypeAnnotations(), annos);
|
||||
}
|
||||
|
||||
// test the result of Attributes.getIndex according to expectations
|
||||
@ -78,7 +78,7 @@ public class ReferenceInfoUtil {
|
||||
} else throw new AssertionError();
|
||||
}
|
||||
if (m instanceof MethodModel mm) {
|
||||
CodeAttribute cAttr = mm.findAttribute(Attributes.CODE).orElse(null);
|
||||
CodeAttribute cAttr = mm.findAttribute(Attributes.code()).orElse(null);
|
||||
if (cAttr != null) {
|
||||
Attribute<T> attr2 = cAttr.findAttribute(attrName).orElse(null);;
|
||||
if (attr2 != null) {
|
||||
|
@ -100,7 +100,7 @@ public class DuplicatedCheckcastTest extends TestRunner {
|
||||
ArrayList<Instruction> checkCastList = new ArrayList<>();
|
||||
for (MethodModel method : cf.methods()) {
|
||||
if (method.methodName().equalsString("test")) {
|
||||
CodeAttribute code_attribute = method.findAttribute(Attributes.CODE).orElseThrow();
|
||||
CodeAttribute code_attribute = method.findAttribute(Attributes.code()).orElseThrow();
|
||||
for (CodeElement ce : code_attribute.elementList()) {
|
||||
if (ce instanceof Instruction instruction && Opcode.CHECKCAST == instruction.opcode()) {
|
||||
checkCastList.add(instruction);
|
||||
|
@ -47,14 +47,14 @@ public class SyntheticClasses {
|
||||
for (File classFile : Objects.requireNonNull(testClasses.listFiles(f -> f.getName().endsWith(".class")))) {
|
||||
ClassModel cf = ClassFile.of().parse(classFile.toPath());
|
||||
if (cf.thisClass().asInternalName().matches(".*\\$[0-9]+")) {
|
||||
EnclosingMethodAttribute encl = cf.findAttribute(Attributes.ENCLOSING_METHOD).orElse(null);
|
||||
EnclosingMethodAttribute encl = cf.findAttribute(Attributes.enclosingMethod()).orElse(null);
|
||||
if (encl != null) {
|
||||
if (encl.enclosingMethodName().isPresent())
|
||||
throw new IllegalStateException("Invalid EnclosingMethod.method: " +
|
||||
encl.enclosingMethodName().get().stringValue() + ".");
|
||||
}
|
||||
}
|
||||
InnerClassesAttribute attr = cf.findAttribute(Attributes.INNER_CLASSES).orElse(null);
|
||||
InnerClassesAttribute attr = cf.findAttribute(Attributes.innerClasses()).orElse(null);
|
||||
if (attr != null) {
|
||||
for (InnerClassInfo info : attr.classes()) {
|
||||
if (cf.majorVersion() < 51)
|
||||
|
@ -77,7 +77,7 @@ public class AnnotationDefaultTest extends TestResult {
|
||||
String methodName = method.methodName().stringValue();
|
||||
printf("Testing method : %s\n", methodName);
|
||||
AnnotationDefaultAttribute attr =
|
||||
method.findAttribute(Attributes.ANNOTATION_DEFAULT).orElse(null);
|
||||
method.findAttribute(Attributes.annotationDefault()).orElse(null);
|
||||
|
||||
if (hasDefault && !checkNotNull(attr, "Attribute is not null")
|
||||
|| !hasDefault && checkNull(attr, "Attribute is null")) {
|
||||
|
@ -163,7 +163,7 @@ public class EnclosingMethodTest extends TestResult {
|
||||
checkEquals(countEnclosingMethodAttributes(classFile), 1l,
|
||||
"number of the EnclosingMethod attribute in the class is one : "
|
||||
+ clazz);
|
||||
EnclosingMethodAttribute attr = classFile.findAttribute(Attributes.ENCLOSING_METHOD).orElse(null);
|
||||
EnclosingMethodAttribute attr = classFile.findAttribute(Attributes.enclosingMethod()).orElse(null);
|
||||
|
||||
if (!checkNotNull(attr, "the EnclosingMethod attribute is not null : " + className)) {
|
||||
// stop checking, attr is null. test case failed
|
||||
|
@ -72,15 +72,15 @@ public class LineNumberTestBase extends TestBase {
|
||||
classFile = ClassFile.of().parse(input.readAllBytes());
|
||||
}
|
||||
for (MethodModel m : classFile.methods()) {
|
||||
CodeAttribute code_attribute = m.findAttribute(Attributes.CODE).orElse(null);
|
||||
CodeAttribute code_attribute = m.findAttribute(Attributes.code()).orElse(null);
|
||||
|
||||
assert code_attribute != null;
|
||||
assertEquals(
|
||||
countAttributes(Attributes.LINE_NUMBER_TABLE, code_attribute),
|
||||
countAttributes(Attributes.lineNumberTable(), code_attribute),
|
||||
1,
|
||||
"Can be more than one LNT attribute, but javac should generate only one.");
|
||||
|
||||
LineNumberTableAttribute tableAttribute = code_attribute.findAttribute(Attributes.LINE_NUMBER_TABLE).orElse(null);
|
||||
LineNumberTableAttribute tableAttribute = code_attribute.findAttribute(Attributes.lineNumberTable()).orElse(null);
|
||||
assert tableAttribute != null;
|
||||
checkAttribute(testCase, tableAttribute, code_attribute.codeLength());
|
||||
Set<Integer> methodCoveredLines =
|
||||
|
@ -24,10 +24,10 @@ public class T8050993 {
|
||||
Set<Integer> expectedLineNumbers = new HashSet<>(Arrays.asList(49, 50, 47, 48));
|
||||
for (MethodModel m : someTestIn.methods()) {
|
||||
if (m.methodName().equalsString("method")) {
|
||||
CodeAttribute code_attribute = m.findAttribute(Attributes.CODE).orElse(null);
|
||||
CodeAttribute code_attribute = m.findAttribute(Attributes.code()).orElse(null);
|
||||
assert code_attribute != null;
|
||||
for (Attribute<?> at : code_attribute.attributes()) {
|
||||
if (Attributes.LINE_NUMBER_TABLE.equals(at)) {
|
||||
if (Attributes.lineNumberTable().equals(at)) {
|
||||
assert at instanceof LineNumberTableAttribute;
|
||||
LineNumberTableAttribute att = (LineNumberTableAttribute) at;
|
||||
Set<Integer> actualLinesNumbers = Arrays.stream(att.lineNumbers().toArray(new LineNumberInfo[0]))
|
||||
|
@ -104,7 +104,7 @@ public abstract class LocalVariableTestBase extends TestBase {
|
||||
String mName = m.methodName().stringValue();
|
||||
if (methodName.equals(mName)) {
|
||||
System.out.println("Testing local variable table in method " + mName);
|
||||
CodeAttribute code_attribute = m.findAttribute(Attributes.CODE).orElse(null);
|
||||
CodeAttribute code_attribute = m.findAttribute(Attributes.code()).orElse(null);
|
||||
assert code_attribute != null;
|
||||
List<? extends VariableTable> variableTables = getVariableTables(code_attribute);
|
||||
generalLocalVariableTableCheck(variableTables);
|
||||
|
@ -70,7 +70,7 @@ public class ModuleTestBase {
|
||||
|
||||
protected void testModuleAttribute(Path modulePath, ModuleDescriptor moduleDescriptor) throws Exception {
|
||||
ClassModel classFile = ClassFile.of().parse(modulePath.resolve("module-info.class"));
|
||||
ModuleAttribute moduleAttribute = classFile.findAttribute(Attributes.MODULE).orElse(null);
|
||||
ModuleAttribute moduleAttribute = classFile.findAttribute(Attributes.module()).orElse(null);
|
||||
assert moduleAttribute != null;
|
||||
testModuleName(moduleDescriptor, moduleAttribute);
|
||||
testModuleFlags(moduleDescriptor, moduleAttribute);
|
||||
|
@ -134,7 +134,7 @@ public class Driver extends TestResult {
|
||||
// test class signature
|
||||
testAttribute(
|
||||
className,
|
||||
() -> classFile.findAttribute(Attributes.SIGNATURE).orElse(null),
|
||||
() -> classFile.findAttribute(Attributes.signature()).orElse(null),
|
||||
getClassExpectedSignature(className, clazz).get(className));
|
||||
|
||||
testFields(getExpectedFieldSignatures(clazz), classFile);
|
||||
@ -173,7 +173,7 @@ public class Driver extends TestResult {
|
||||
}
|
||||
testAttribute(
|
||||
methodName,
|
||||
() -> method.findAttribute(Attributes.SIGNATURE).orElse(null),
|
||||
() -> method.findAttribute(Attributes.signature()).orElse(null),
|
||||
expectedSignatures.get(methodName));
|
||||
foundMethods.add(methodName);
|
||||
}
|
||||
@ -204,7 +204,7 @@ public class Driver extends TestResult {
|
||||
printf("Testing field %s\n", fieldName);
|
||||
testAttribute(
|
||||
fieldName,
|
||||
() -> field.findAttribute(Attributes.SIGNATURE).orElse(null),
|
||||
() -> field.findAttribute(Attributes.signature()).orElse(null),
|
||||
expectedSignatures.get(fieldName));
|
||||
foundFields.add(fieldName);
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public class NoSourceFileAttribute extends TestBase {
|
||||
|
||||
public void test() throws IOException {
|
||||
assertNull(
|
||||
ClassFile.of().parse(getClassFile(NoSourceFileAttribute.class).toPath()).findAttribute(Attributes.SOURCE_FILE).orElse(null),
|
||||
ClassFile.of().parse(getClassFile(NoSourceFileAttribute.class).toPath()).findAttribute(Attributes.sourceFile()).orElse(null),
|
||||
"Classfile should have no SourceFile attribute when compiled without debug information.");
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ public class SourceFileTestBase extends TestBase {
|
||||
|
||||
SourceFileAttribute attribute = sourceFileAttributes.get(0);
|
||||
|
||||
assertEquals(attribute.attributeName(), Attributes.SOURCE_FILE.name(), "Incorrect attribute name");
|
||||
assertEquals(attribute.attributeName(), Attributes.sourceFile().name(), "Incorrect attribute name");
|
||||
assertEquals(attribute.sourceFile().stringValue(), fileName,
|
||||
"Incorrect source file name");
|
||||
assertEquals(((BoundAttribute<?>)attribute).payloadLen(), 2, "Incorrect attribute length");
|
||||
|
@ -118,7 +118,7 @@ public class SyntheticTestDriver extends TestResult {
|
||||
foundClasses.add(className);
|
||||
if (testAttribute(
|
||||
classFile,
|
||||
() -> classFile.findAttribute(Attributes.SYNTHETIC).orElse(null),
|
||||
() -> classFile.findAttribute(Attributes.synthetic()).orElse(null),
|
||||
classFile.flags()::flags,
|
||||
expectedClasses.keySet(),
|
||||
className,
|
||||
@ -136,7 +136,7 @@ public class SyntheticTestDriver extends TestResult {
|
||||
foundMethods.add(methodName);
|
||||
if (testAttribute(
|
||||
classFile,
|
||||
() -> method.findAttribute(Attributes.SYNTHETIC).orElse(null),
|
||||
() -> method.findAttribute(Attributes.synthetic()).orElse(null),
|
||||
method.flags()::flags,
|
||||
expectedMethods,
|
||||
methodName,
|
||||
@ -162,7 +162,7 @@ public class SyntheticTestDriver extends TestResult {
|
||||
foundFields.add(fieldName);
|
||||
if (testAttribute(
|
||||
classFile,
|
||||
() -> field.findAttribute(Attributes.SYNTHETIC).orElse(null),
|
||||
() -> field.findAttribute(Attributes.synthetic()).orElse(null),
|
||||
field.flags()::flags,
|
||||
expectedFields,
|
||||
fieldName,
|
||||
|
@ -96,11 +96,11 @@ public abstract class RuntimeAnnotationsTestBase extends AnnotationsTestBase {
|
||||
Map<String, Annotation> actualInvisible = collectAnnotations(
|
||||
member,
|
||||
attributedElement,
|
||||
Attributes.RUNTIME_INVISIBLE_ANNOTATIONS);
|
||||
Attributes.runtimeInvisibleAnnotations());
|
||||
Map<String, Annotation> actualVisible = collectAnnotations(
|
||||
member,
|
||||
attributedElement,
|
||||
Attributes.RUNTIME_VISIBLE_ANNOTATIONS);
|
||||
Attributes.runtimeVisibleAnnotations());
|
||||
|
||||
checkEquals(actualInvisible.keySet(),
|
||||
member.getRuntimeInvisibleAnnotations(), "RuntimeInvisibleAnnotations");
|
||||
|
@ -104,10 +104,10 @@ public class RuntimeParameterAnnotationsForLambdaTest extends RuntimeParameterAn
|
||||
protected void testAttributes(
|
||||
TestCase.TestMethodInfo testMethod,
|
||||
MethodModel method) {
|
||||
RuntimeInvisibleParameterAnnotationsAttribute invAttr = method.findAttribute(Attributes.RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS).orElse(null);
|
||||
checkNull(invAttr, String.format("%s should be null", Attributes.RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS));
|
||||
RuntimeVisibleParameterAnnotationsAttribute vAttr = method.findAttribute(Attributes.RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS).orElse(null);
|
||||
checkNull(vAttr, String.format("%s should be null", Attributes.RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS));
|
||||
RuntimeInvisibleParameterAnnotationsAttribute invAttr = method.findAttribute(Attributes.runtimeInvisibleParameterAnnotations()).orElse(null);
|
||||
checkNull(invAttr, String.format("%s should be null", Attributes.runtimeInvisibleParameterAnnotations()));
|
||||
RuntimeVisibleParameterAnnotationsAttribute vAttr = method.findAttribute(Attributes.runtimeVisibleParameterAnnotations()).orElse(null);
|
||||
checkNull(vAttr, String.format("%s should be null", Attributes.runtimeVisibleParameterAnnotations()));
|
||||
}
|
||||
|
||||
public String generateLambdaSource(TestCase.TestMethodInfo method) {
|
||||
|
@ -67,12 +67,12 @@ public abstract class RuntimeParameterAnnotationsTestBase extends AnnotationsTes
|
||||
classFile,
|
||||
testMethod,
|
||||
method,
|
||||
Attributes.RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS);
|
||||
Attributes.runtimeInvisibleParameterAnnotations());
|
||||
List<Map<String, Annotation>> actualVisible = collectAnnotations(
|
||||
classFile,
|
||||
testMethod,
|
||||
method,
|
||||
Attributes.RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS);
|
||||
Attributes.runtimeVisibleParameterAnnotations());
|
||||
|
||||
List<TestCase.TestParameterInfo> parameters = testMethod.parameters;
|
||||
for (int i = 0; i < parameters.size(); ++i) {
|
||||
|
@ -84,7 +84,7 @@ public class DeprecatedPackageTest extends TestResult {
|
||||
new String[]{"package-info.java", package_info},
|
||||
new String[]{"notDeprecated.java", src})
|
||||
.getClasses().get(CLASS_NAME));
|
||||
DeprecatedAttribute attr = cm.findAttribute(Attributes.DEPRECATED).orElse(null);
|
||||
DeprecatedAttribute attr = cm.findAttribute(Attributes.deprecated()).orElse(null);
|
||||
checkNull(attr, "Class can not have deprecated attribute : " + CLASS_NAME);
|
||||
} catch (Exception e) {
|
||||
addFailure(e);
|
||||
|
@ -243,7 +243,7 @@ public class DeprecatedTest extends TestResult {
|
||||
.findFirst().orElse(null);
|
||||
echo("Testing outer class : " + outerClassName);
|
||||
ClassModel cf = readClassFile(classes.get(outerClassName));
|
||||
DeprecatedAttribute attr = cf.findAttribute(Attributes.DEPRECATED).orElse(null);
|
||||
DeprecatedAttribute attr = cf.findAttribute(Attributes.deprecated()).orElse(null);
|
||||
testAttribute(outerClassName, attr, cf);
|
||||
testInnerClasses(cf, classes);
|
||||
testMethods(cf);
|
||||
@ -255,13 +255,13 @@ public class DeprecatedTest extends TestResult {
|
||||
|
||||
private void testInnerClasses(ClassModel cf, Map<String, ? extends JavaFileObject> classes)
|
||||
throws IOException {
|
||||
InnerClassesAttribute innerAttr = cf.findAttribute(Attributes.INNER_CLASSES).orElse(null);
|
||||
InnerClassesAttribute innerAttr = cf.findAttribute(Attributes.innerClasses()).orElse(null);
|
||||
assert innerAttr != null;
|
||||
for (InnerClassInfo innerClass : innerAttr.classes()) {
|
||||
String innerClassName = innerClass.innerClass().name().stringValue();
|
||||
echo("Testing inner class : " + innerClassName);
|
||||
ClassModel innerCf = readClassFile(classes.get(innerClassName));
|
||||
DeprecatedAttribute attr = innerCf.findAttribute(Attributes.DEPRECATED).orElse(null);
|
||||
DeprecatedAttribute attr = innerCf.findAttribute(Attributes.deprecated()).orElse(null);
|
||||
assert innerClass.innerName().isPresent();
|
||||
String innerClassSimpleName = innerClass.innerName().get().stringValue();
|
||||
testAttribute(innerClassSimpleName, attr, innerCf);
|
||||
@ -276,7 +276,7 @@ public class DeprecatedTest extends TestResult {
|
||||
for (MethodModel m : cf.methods()) {
|
||||
String methodName = m.methodName().stringValue();
|
||||
echo("Testing method : " + methodName);
|
||||
DeprecatedAttribute attr = m.findAttribute(Attributes.DEPRECATED).orElse(null);
|
||||
DeprecatedAttribute attr = m.findAttribute(Attributes.deprecated()).orElse(null);
|
||||
testAttribute(methodName, attr, cf);
|
||||
}
|
||||
}
|
||||
@ -285,7 +285,7 @@ public class DeprecatedTest extends TestResult {
|
||||
for (FieldModel f : cm.fields()) {
|
||||
String fieldName = f.fieldName().stringValue();
|
||||
echo("Testing field : " + fieldName);
|
||||
DeprecatedAttribute attr = f.findAttribute(Attributes.DEPRECATED).orElse(null);
|
||||
DeprecatedAttribute attr = f.findAttribute(Attributes.deprecated()).orElse(null);
|
||||
testAttribute(fieldName, attr, cm);
|
||||
}
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ public class InnerClassesHierarchyTest extends TestResult {
|
||||
continue;
|
||||
}
|
||||
ClassModel cf = readClassFile(currentClassName);
|
||||
InnerClassesAttribute attr = cf.findAttribute(Attributes.INNER_CLASSES).orElse(null);
|
||||
InnerClassesAttribute attr = cf.findAttribute(Attributes.innerClasses()).orElse(null);
|
||||
checkNotNull(attr, "Class should not contain "
|
||||
+ "inner classes attribute : " + currentClassName);
|
||||
checkTrue(innerClasses.containsKey(currentClassName),
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user