Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2022, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package io.github.dmlloyd.classfile.impl;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import io.github.dmlloyd.classfile.Annotation;
import io.github.dmlloyd.classfile.AnnotationValue;
import io.github.dmlloyd.classfile.Attribute;
import io.github.dmlloyd.classfile.AttributeMapper;
import io.github.dmlloyd.classfile.Attributes;
import io.github.dmlloyd.classfile.BootstrapMethodEntry;
import io.github.dmlloyd.classfile.constantpool.ClassEntry;
import io.github.dmlloyd.classfile.TypeAnnotation;
import io.github.dmlloyd.classfile.attribute.AnnotationDefaultAttribute;
import io.github.dmlloyd.classfile.attribute.BootstrapMethodsAttribute;
import io.github.dmlloyd.classfile.attribute.CharacterRangeInfo;
import io.github.dmlloyd.classfile.attribute.CharacterRangeTableAttribute;
import io.github.dmlloyd.classfile.attribute.CompilationIDAttribute;
import io.github.dmlloyd.classfile.attribute.ConstantValueAttribute;
import io.github.dmlloyd.classfile.attribute.DeprecatedAttribute;
import io.github.dmlloyd.classfile.attribute.EnclosingMethodAttribute;
import io.github.dmlloyd.classfile.attribute.ExceptionsAttribute;
import io.github.dmlloyd.classfile.attribute.InnerClassInfo;
import io.github.dmlloyd.classfile.attribute.InnerClassesAttribute;
import io.github.dmlloyd.classfile.attribute.LineNumberInfo;
import io.github.dmlloyd.classfile.attribute.LineNumberTableAttribute;
import io.github.dmlloyd.classfile.attribute.LocalVariableInfo;
import io.github.dmlloyd.classfile.attribute.LocalVariableTableAttribute;
import io.github.dmlloyd.classfile.attribute.LocalVariableTypeInfo;
import io.github.dmlloyd.classfile.attribute.LocalVariableTypeTableAttribute;
import io.github.dmlloyd.classfile.attribute.MethodParameterInfo;
import io.github.dmlloyd.classfile.attribute.MethodParametersAttribute;
import io.github.dmlloyd.classfile.attribute.ModuleAttribute;
import io.github.dmlloyd.classfile.attribute.ModuleExportInfo;
import io.github.dmlloyd.classfile.attribute.ModuleHashInfo;
import io.github.dmlloyd.classfile.attribute.ModuleHashesAttribute;
import io.github.dmlloyd.classfile.attribute.ModuleMainClassAttribute;
import io.github.dmlloyd.classfile.attribute.ModuleOpenInfo;
import io.github.dmlloyd.classfile.attribute.ModulePackagesAttribute;
import io.github.dmlloyd.classfile.attribute.ModuleProvideInfo;
import io.github.dmlloyd.classfile.attribute.ModuleRequireInfo;
import io.github.dmlloyd.classfile.attribute.ModuleResolutionAttribute;
import io.github.dmlloyd.classfile.attribute.ModuleTargetAttribute;
import io.github.dmlloyd.classfile.attribute.NestHostAttribute;
import io.github.dmlloyd.classfile.attribute.NestMembersAttribute;
import io.github.dmlloyd.classfile.attribute.PermittedSubclassesAttribute;
import io.github.dmlloyd.classfile.attribute.RecordAttribute;
import io.github.dmlloyd.classfile.attribute.RecordComponentInfo;
import io.github.dmlloyd.classfile.attribute.RuntimeInvisibleAnnotationsAttribute;
import io.github.dmlloyd.classfile.attribute.RuntimeInvisibleParameterAnnotationsAttribute;
import io.github.dmlloyd.classfile.attribute.RuntimeInvisibleTypeAnnotationsAttribute;
import io.github.dmlloyd.classfile.attribute.RuntimeVisibleAnnotationsAttribute;
import io.github.dmlloyd.classfile.attribute.RuntimeVisibleParameterAnnotationsAttribute;
import io.github.dmlloyd.classfile.attribute.RuntimeVisibleTypeAnnotationsAttribute;
import io.github.dmlloyd.classfile.attribute.SignatureAttribute;
import io.github.dmlloyd.classfile.attribute.SourceDebugExtensionAttribute;
import io.github.dmlloyd.classfile.attribute.SourceFileAttribute;
import io.github.dmlloyd.classfile.attribute.SourceIDAttribute;
import io.github.dmlloyd.classfile.attribute.StackMapTableAttribute;
import io.github.dmlloyd.classfile.attribute.StackMapFrameInfo;
import io.github.dmlloyd.classfile.attribute.SyntheticAttribute;
import io.github.dmlloyd.classfile.constantpool.ConstantValueEntry;
import io.github.dmlloyd.classfile.constantpool.ModuleEntry;
import io.github.dmlloyd.classfile.constantpool.NameAndTypeEntry;
import io.github.dmlloyd.classfile.constantpool.PackageEntry;
import io.github.dmlloyd.classfile.constantpool.Utf8Entry;
public abstract sealed class UnboundAttribute>
extends AbstractElement
implements Attribute, Util.Writable {
protected final AttributeMapper mapper;
public UnboundAttribute(AttributeMapper mapper) {
this.mapper = mapper;
}
@Override
public AttributeMapper attributeMapper() {
return mapper;
}
@Override
public String attributeName() {
return mapper.name();
}
@Override
@SuppressWarnings("unchecked")
public void writeTo(BufWriterImpl buf) {
mapper.writeAttribute(buf, (T) this);
}
@Override
public void writeTo(DirectClassBuilder builder) {
builder.writeAttribute(this);
}
@Override
public void writeTo(DirectCodeBuilder builder) {
builder.writeAttribute(this);
}
@Override
public void writeTo(DirectMethodBuilder builder) {
builder.writeAttribute(this);
}
@Override
public void writeTo(DirectFieldBuilder builder) {
builder.writeAttribute(this);
}
@Override
public String toString() {
return String.format("Attribute[name=%s]", mapper.name());
}
public static final class UnboundConstantValueAttribute
extends UnboundAttribute
implements ConstantValueAttribute {
private final ConstantValueEntry entry;
public UnboundConstantValueAttribute(ConstantValueEntry entry) {
super(Attributes.constantValue());
this.entry = entry;
}
@Override
public ConstantValueEntry constant() {
return entry;
}
}
public static final class UnboundDeprecatedAttribute
extends UnboundAttribute
implements DeprecatedAttribute {
public UnboundDeprecatedAttribute() {
super(Attributes.deprecated());
}
}
public static final class UnboundSyntheticAttribute
extends UnboundAttribute
implements SyntheticAttribute {
public UnboundSyntheticAttribute() {
super(Attributes.synthetic());
}
}
public static final class UnboundSignatureAttribute
extends UnboundAttribute
implements SignatureAttribute {
private final Utf8Entry signature;
public UnboundSignatureAttribute(Utf8Entry signature) {
super(Attributes.signature());
this.signature = signature;
}
@Override
public Utf8Entry signature() {
return signature;
}
}
public static final class UnboundExceptionsAttribute
extends UnboundAttribute
implements ExceptionsAttribute {
private final List exceptions;
public UnboundExceptionsAttribute(List exceptions) {
super(Attributes.exceptions());
this.exceptions = List.copyOf(exceptions);
}
@Override
public List exceptions() {
return exceptions;
}
}
public static final class UnboundAnnotationDefaultAttribute
extends UnboundAttribute
implements AnnotationDefaultAttribute {
private final AnnotationValue annotationDefault;
public UnboundAnnotationDefaultAttribute(AnnotationValue annotationDefault) {
super(Attributes.annotationDefault());
this.annotationDefault = annotationDefault;
}
@Override
public AnnotationValue defaultValue() {
return annotationDefault;
}
}
public static final class UnboundSourceFileAttribute extends UnboundAttribute
implements SourceFileAttribute {
private final Utf8Entry sourceFile;
public UnboundSourceFileAttribute(Utf8Entry sourceFile) {
super(Attributes.sourceFile());
this.sourceFile = sourceFile;
}
@Override
public Utf8Entry sourceFile() {
return sourceFile;
}
}
public static final class UnboundStackMapTableAttribute extends UnboundAttribute
implements StackMapTableAttribute {
private final List entries;
public UnboundStackMapTableAttribute(List entries) {
super(Attributes.stackMapTable());
this.entries = List.copyOf(entries);
}
@Override
public List entries() {
return entries;
}
}
public static final class UnboundInnerClassesAttribute
extends UnboundAttribute
implements InnerClassesAttribute {
private final List innerClasses;
public UnboundInnerClassesAttribute(List innerClasses) {
super(Attributes.innerClasses());
this.innerClasses = List.copyOf(innerClasses);
}
@Override
public List classes() {
return innerClasses;
}
}
public static final class UnboundRecordAttribute
extends UnboundAttribute
implements RecordAttribute {
private final List components;
public UnboundRecordAttribute(List components) {
super(Attributes.record());
this.components = List.copyOf(components);
}
@Override
public List components() {
return components;
}
}
public static final class UnboundEnclosingMethodAttribute
extends UnboundAttribute
implements EnclosingMethodAttribute {
private final ClassEntry classEntry;
private final NameAndTypeEntry method;
public UnboundEnclosingMethodAttribute(ClassEntry classEntry, NameAndTypeEntry method) {
super(Attributes.enclosingMethod());
this.classEntry = classEntry;
this.method = method;
}
@Override
public ClassEntry enclosingClass() {
return classEntry;
}
@Override
public Optional enclosingMethod() {
return Optional.ofNullable(method);
}
}
public static final class UnboundMethodParametersAttribute
extends UnboundAttribute
implements MethodParametersAttribute {
private final List parameters;
public UnboundMethodParametersAttribute(List parameters) {
super(Attributes.methodParameters());
this.parameters = List.copyOf(parameters);
}
@Override
public List parameters() {
return parameters;
}
}
public static final class UnboundModuleTargetAttribute
extends UnboundAttribute
implements ModuleTargetAttribute {
final Utf8Entry moduleTarget;
public UnboundModuleTargetAttribute(Utf8Entry moduleTarget) {
super(Attributes.moduleTarget());
this.moduleTarget = moduleTarget;
}
@Override
public Utf8Entry targetPlatform() {
return moduleTarget;
}
}
public static final class UnboundModuleMainClassAttribute
extends UnboundAttribute
implements ModuleMainClassAttribute {
final ClassEntry mainClass;
public UnboundModuleMainClassAttribute(ClassEntry mainClass) {
super(Attributes.moduleMainClass());
this.mainClass = mainClass;
}
@Override
public ClassEntry mainClass() {
return mainClass;
}
}
public static final class UnboundModuleHashesAttribute
extends UnboundAttribute
implements ModuleHashesAttribute {
private final Utf8Entry algorithm;
private final List hashes;
public UnboundModuleHashesAttribute(Utf8Entry algorithm, List hashes) {
super(Attributes.moduleHashes());
this.algorithm = algorithm;
this.hashes = List.copyOf(hashes);
}
@Override
public Utf8Entry algorithm() {
return algorithm;
}
@Override
public List hashes() {
return hashes;
}
}
public static final class UnboundModulePackagesAttribute
extends UnboundAttribute
implements ModulePackagesAttribute {
private final Collection packages;
public UnboundModulePackagesAttribute(Collection packages) {
super(Attributes.modulePackages());
this.packages = List.copyOf(packages);
}
@Override
public List packages() {
return List.copyOf(packages);
}
}
public static final class UnboundModuleResolutionAttribute
extends UnboundAttribute
implements ModuleResolutionAttribute {
private final int resolutionFlags;
public UnboundModuleResolutionAttribute(int flags) {
super(Attributes.moduleResolution());
resolutionFlags = flags;
}
@Override
public int resolutionFlags() {
return resolutionFlags;
}
}
public static final class UnboundPermittedSubclassesAttribute
extends UnboundAttribute
implements PermittedSubclassesAttribute {
private final List permittedSubclasses;
public UnboundPermittedSubclassesAttribute(List permittedSubclasses) {
super(Attributes.permittedSubclasses());
this.permittedSubclasses = List.copyOf(permittedSubclasses);
}
@Override
public List permittedSubclasses() {
return permittedSubclasses;
}
}
public static final class UnboundNestMembersAttribute
extends UnboundAttribute
implements NestMembersAttribute {
private final List memberEntries;
public UnboundNestMembersAttribute(List memberEntries) {
super(Attributes.nestMembers());
this.memberEntries = List.copyOf(memberEntries);
}
@Override
public List nestMembers() {
return memberEntries;
}
}
public static final class UnboundNestHostAttribute
extends UnboundAttribute
implements NestHostAttribute {
private final ClassEntry hostEntry;
public UnboundNestHostAttribute(ClassEntry hostEntry) {
super(Attributes.nestHost());
this.hostEntry = hostEntry;
}
@Override
public ClassEntry nestHost() {
return hostEntry;
}
}
public static final class UnboundCompilationIDAttribute
extends UnboundAttribute
implements CompilationIDAttribute {
private final Utf8Entry idEntry;
public UnboundCompilationIDAttribute(Utf8Entry idEntry) {
super(Attributes.compilationId());
this.idEntry = idEntry;
}
@Override
public Utf8Entry compilationId() {
return idEntry;
}
}
public static final class UnboundSourceIDAttribute
extends UnboundAttribute
implements SourceIDAttribute {
private final Utf8Entry idEntry;
public UnboundSourceIDAttribute(Utf8Entry idEntry) {
super(Attributes.sourceId());
this.idEntry = idEntry;
}
@Override
public Utf8Entry sourceId() {
return idEntry;
}
}
public static final class UnboundSourceDebugExtensionAttribute
extends UnboundAttribute
implements SourceDebugExtensionAttribute {
private final byte[] contents;
public UnboundSourceDebugExtensionAttribute(byte[] contents) {
super(Attributes.sourceDebugExtension());
this.contents = contents;
}
@Override
public byte[] contents() {
return contents;
}
}
public static final class UnboundCharacterRangeTableAttribute
extends UnboundAttribute
implements CharacterRangeTableAttribute {
private final List ranges;
public UnboundCharacterRangeTableAttribute(List ranges) {
super(Attributes.characterRangeTable());
this.ranges = List.copyOf(ranges);
}
@Override
public List characterRangeTable() {
return ranges;
}
}
public static final class UnboundLineNumberTableAttribute
extends UnboundAttribute
implements LineNumberTableAttribute {
private final List lines;
public UnboundLineNumberTableAttribute(List lines) {
super(Attributes.lineNumberTable());
this.lines = List.copyOf(lines);
}
@Override
public List lineNumbers() {
return lines;
}
}
public static final class UnboundLocalVariableTableAttribute
extends UnboundAttribute
implements LocalVariableTableAttribute {
private final List locals;
public UnboundLocalVariableTableAttribute(List locals) {
super(Attributes.localVariableTable());
this.locals = List.copyOf(locals);
}
@Override
public List localVariables() {
return locals;
}
}
public static final class UnboundLocalVariableTypeTableAttribute
extends UnboundAttribute
implements LocalVariableTypeTableAttribute {
private final List locals;
public UnboundLocalVariableTypeTableAttribute(List locals) {
super(Attributes.localVariableTypeTable());
this.locals = List.copyOf(locals);
}
@Override
public List localVariableTypes() {
return locals;
}
}
public static final class UnboundRuntimeVisibleAnnotationsAttribute
extends UnboundAttribute
implements RuntimeVisibleAnnotationsAttribute {
private final List elements;
public UnboundRuntimeVisibleAnnotationsAttribute(List elements) {
super(Attributes.runtimeVisibleAnnotations());
this.elements = List.copyOf(elements);
}
@Override
public List annotations() {
return elements;
}
}
public static final class UnboundRuntimeInvisibleAnnotationsAttribute
extends UnboundAttribute
implements RuntimeInvisibleAnnotationsAttribute {
private final List elements;
public UnboundRuntimeInvisibleAnnotationsAttribute(List elements) {
super(Attributes.runtimeInvisibleAnnotations());
this.elements = List.copyOf(elements);
}
@Override
public List annotations() {
return elements;
}
}
public static final class UnboundRuntimeVisibleParameterAnnotationsAttribute
extends UnboundAttribute
implements RuntimeVisibleParameterAnnotationsAttribute {
private final List> elements;
public UnboundRuntimeVisibleParameterAnnotationsAttribute(List> elements) {
super(Attributes.runtimeVisibleParameterAnnotations());
this.elements = List.copyOf(elements);
}
@Override
public List> parameterAnnotations() {
return elements;
}
}
public static final class UnboundRuntimeInvisibleParameterAnnotationsAttribute
extends UnboundAttribute
implements RuntimeInvisibleParameterAnnotationsAttribute {
private final List> elements;
public UnboundRuntimeInvisibleParameterAnnotationsAttribute(List> elements) {
super(Attributes.runtimeInvisibleParameterAnnotations());
// deep copy
this.elements = elements.stream().map(List::copyOf).toList();
}
@Override
public List> parameterAnnotations() {
return elements;
}
}
public static final class UnboundRuntimeVisibleTypeAnnotationsAttribute
extends UnboundAttribute
implements RuntimeVisibleTypeAnnotationsAttribute {
private final List elements;
public UnboundRuntimeVisibleTypeAnnotationsAttribute(List elements) {
super(Attributes.runtimeVisibleTypeAnnotations());
this.elements = List.copyOf(elements);
}
@Override
public List annotations() {
return elements;
}
}
public static final class UnboundRuntimeInvisibleTypeAnnotationsAttribute
extends UnboundAttribute
implements RuntimeInvisibleTypeAnnotationsAttribute {
private final List elements;
public UnboundRuntimeInvisibleTypeAnnotationsAttribute(List elements) {
super(Attributes.runtimeInvisibleTypeAnnotations());
this.elements = List.copyOf(elements);
}
@Override
public List annotations() {
return elements;
}
}
public record UnboundCharacterRangeInfo(int startPc, int endPc,
int characterRangeStart,
int characterRangeEnd,
int flags)
implements CharacterRangeInfo { }
public record UnboundInnerClassInfo(ClassEntry innerClass,
Optional outerClass,
Optional innerName,
int flagsMask)
implements InnerClassInfo {}
public record UnboundLineNumberInfo(int startPc, int lineNumber)
implements LineNumberInfo { }
public record UnboundLocalVariableInfo(int startPc, int length,
Utf8Entry name,
Utf8Entry type,
int slot)
implements LocalVariableInfo { }
public record UnboundLocalVariableTypeInfo(int startPc, int length,
Utf8Entry name,
Utf8Entry signature,
int slot)
implements LocalVariableTypeInfo { }
public record UnboundMethodParameterInfo(Optional name, int flagsMask)
implements MethodParameterInfo {}
public record UnboundModuleExportInfo(PackageEntry exportedPackage,
int exportsFlagsMask,
List exportsTo)
implements ModuleExportInfo {
public UnboundModuleExportInfo(PackageEntry exportedPackage, int exportsFlagsMask,
List exportsTo) {
this.exportedPackage = exportedPackage;
this.exportsFlagsMask = exportsFlagsMask;
this.exportsTo = List.copyOf(exportsTo);
}
}
public record UnboundModuleHashInfo(ModuleEntry moduleName,
byte[] hash) implements ModuleHashInfo { }
public record UnboundModuleOpenInfo(PackageEntry openedPackage, int opensFlagsMask,
List opensTo)
implements ModuleOpenInfo {
public UnboundModuleOpenInfo(PackageEntry openedPackage, int opensFlagsMask,
List opensTo) {
this.openedPackage = openedPackage;
this.opensFlagsMask = opensFlagsMask;
this.opensTo = List.copyOf(opensTo);
}
}
public record UnboundModuleProvideInfo(ClassEntry provides,
List providesWith)
implements ModuleProvideInfo {
public UnboundModuleProvideInfo(ClassEntry provides, List providesWith) {
this.provides = provides;
this.providesWith = List.copyOf(providesWith);
}
}
public record UnboundModuleRequiresInfo(ModuleEntry requires, int requiresFlagsMask,
Optional requiresVersion)
implements ModuleRequireInfo {}
public record UnboundRecordComponentInfo(Utf8Entry name,
Utf8Entry descriptor,
List> attributes)
implements RecordComponentInfo {
public UnboundRecordComponentInfo(Utf8Entry name, Utf8Entry descriptor, List> attributes) {
this.name = name;
this.descriptor = descriptor;
this.attributes = List.copyOf(attributes);
}
}
public record UnboundTypeAnnotation(TargetInfo targetInfo,
List targetPath,
Annotation annotation) implements TypeAnnotation {
public UnboundTypeAnnotation {
targetPath = List.copyOf(targetPath);
}
}
public record TypePathComponentImpl(Kind typePathKind, int typeArgumentIndex)
implements TypeAnnotation.TypePathComponent {}
public static final class UnboundModuleAttribute extends UnboundAttribute implements ModuleAttribute {
private final ModuleEntry moduleName;
private final int moduleFlags;
private final Utf8Entry moduleVersion;
private final List requires;
private final List exports;
private final List opens;
private final List uses;
private final List provides;
public UnboundModuleAttribute(ModuleEntry moduleName,
int moduleFlags,
Utf8Entry moduleVersion,
Collection requires,
Collection exports,
Collection opens,
Collection uses,
Collection provides)
{
super(Attributes.module());
this.moduleName = moduleName;
this.moduleFlags = moduleFlags;
this.moduleVersion = moduleVersion;
this.requires = List.copyOf(requires);
this.exports = List.copyOf(exports);
this.opens = List.copyOf(opens);
this.uses = List.copyOf(uses);
this.provides = List.copyOf(provides);
}
@Override
public ModuleEntry moduleName() {
return moduleName;
}
@Override
public int moduleFlagsMask() {
return moduleFlags;
}
@Override
public Optional moduleVersion() {
return Optional.ofNullable(moduleVersion);
}
@Override
public List requires() {
return requires;
}
@Override
public List exports() {
return exports;
}
@Override
public List opens() {
return opens;
}
@Override
public List uses() {
return uses;
}
@Override
public List provides() {
return provides;
}
}
public abstract static non-sealed class AdHocAttribute>
extends UnboundAttribute {
public AdHocAttribute(AttributeMapper mapper) {
super(mapper);
}
public abstract void writeBody(BufWriterImpl b);
@Override
public void writeTo(BufWriterImpl b) {
b.writeIndex(b.constantPool().utf8Entry(mapper.name()));
int lengthIndex = b.skip(4);
writeBody(b);
int written = b.size() - lengthIndex - 4;
b.patchInt(lengthIndex, written);
}
}
public static final class EmptyBootstrapAttribute
extends UnboundAttribute
implements BootstrapMethodsAttribute {
public EmptyBootstrapAttribute() {
super(Attributes.bootstrapMethods());
}
@Override
public int bootstrapMethodsSize() {
return 0;
}
@Override
public List bootstrapMethods() {
return List.of();
}
}
}