< prev index next >

src/java.base/share/classes/java/lang/classfile/ClassFile.java

Print this page

   1 /*
   2  * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any

  37 import java.lang.classfile.constantpool.ConstantPoolBuilder;
  38 import java.lang.classfile.constantpool.Utf8Entry;
  39 import java.lang.classfile.instruction.BranchInstruction;
  40 import java.lang.classfile.instruction.CharacterRange;
  41 import java.lang.classfile.instruction.DiscontinuedInstruction;
  42 import java.lang.classfile.instruction.ExceptionCatch;
  43 import java.lang.classfile.instruction.LineNumber;
  44 import java.lang.classfile.instruction.LocalVariable;
  45 import java.lang.classfile.instruction.LocalVariableType;
  46 import java.lang.constant.ClassDesc;
  47 import java.lang.reflect.AccessFlag;
  48 import java.lang.reflect.ClassFileFormatVersion;
  49 import java.nio.file.Files;
  50 import java.nio.file.Path;
  51 import java.util.List;
  52 import java.util.function.Consumer;
  53 import java.util.function.Function;
  54 
  55 import jdk.internal.classfile.impl.ClassFileImpl;
  56 import jdk.internal.classfile.impl.TemporaryConstantPool;

  57 
  58 import static java.util.Objects.requireNonNull;
  59 import static jdk.internal.constant.ConstantUtils.CD_module_info;
  60 
  61 /**
  62  * Provides ability to parse, transform, and generate {@code class} files.
  63  * A {@code ClassFile} is a context with a set of options that condition how
  64  * parsing and generation are done.
  65  *
  66  * @since 24
  67  */
  68 public sealed interface ClassFile
  69         permits ClassFileImpl {
  70 
  71     /**
  72      * {@return a context with default options}  Each subtype of {@link Option}
  73      * specifies its default.
  74      * <p>
  75      * The default {@link AttributeMapperOption} and {@link
  76      * ClassHierarchyResolverOption} may be unsuitable for some {@code class}

 788     int ACC_PUBLIC = 0x0001;
 789 
 790     /** The bit mask of {@link AccessFlag#PROTECTED} access and property modifier. */
 791     int ACC_PROTECTED = 0x0004;
 792 
 793     /** The bit mask of {@link AccessFlag#PRIVATE} access and property modifier. */
 794     int ACC_PRIVATE = 0x0002;
 795 
 796     /** The bit mask of {@link AccessFlag#INTERFACE} access and property modifier. */
 797     int ACC_INTERFACE = 0x0200;
 798 
 799     /** The bit mask of {@link AccessFlag#ENUM} access and property modifier. */
 800     int ACC_ENUM = 0x4000;
 801 
 802     /** The bit mask of {@link AccessFlag#ANNOTATION} access and property modifier. */
 803     int ACC_ANNOTATION = 0x2000;
 804 
 805     /** The bit mask of {@link AccessFlag#SUPER} access and property modifier. */
 806     int ACC_SUPER = 0x0020;
 807 








 808     /** The bit mask of {@link AccessFlag#ABSTRACT} access and property modifier. */
 809     int ACC_ABSTRACT = 0x0400;
 810 
 811     /** The bit mask of {@link AccessFlag#VOLATILE} access and property modifier. */
 812     int ACC_VOLATILE = 0x0040;
 813 
 814     /** The bit mask of {@link AccessFlag#TRANSIENT} access and property modifier. */
 815     int ACC_TRANSIENT = 0x0080;
 816 
 817     /** The bit mask of {@link AccessFlag#SYNTHETIC} access and property modifier. */
 818     int ACC_SYNTHETIC = 0x1000;
 819 
 820     /** The bit mask of {@link AccessFlag#STATIC} access and property modifier. */
 821     int ACC_STATIC = 0x0008;
 822 
 823     /** The bit mask of {@link AccessFlag#FINAL} access and property modifier. */
 824     int ACC_FINAL = 0x0010;
 825 
 826     /** The bit mask of {@link AccessFlag#SYNCHRONIZED} access and property modifier. */
 827     int ACC_SYNCHRONIZED = 0x0020;
 828 
 829     /** The bit mask of {@link AccessFlag#BRIDGE} access and property modifier. */
 830     int ACC_BRIDGE = 0x0040;
 831 
 832     /** The bit mask of {@link AccessFlag#VARARGS} access and property modifier. */
 833     int ACC_VARARGS = 0x0080;
 834 
 835     /** The bit mask of {@link AccessFlag#NATIVE} access and property modifier. */
 836     int ACC_NATIVE = 0x0100;
 837 
 838     /** The bit mask of {@link AccessFlag#STRICT} access and property modifier. */
 839     int ACC_STRICT = 0x0800;
 840 








 841     /** The bit mask of {@link AccessFlag#MODULE} access and property modifier. */
 842     int ACC_MODULE = 0x8000;
 843 
 844     /** The bit mask of {@link AccessFlag#OPEN} access and property modifier. */
 845     int ACC_OPEN = 0x20;
 846 
 847     /** The bit mask of {@link AccessFlag#MANDATED} access and property modifier. */
 848     int ACC_MANDATED = 0x8000;
 849 
 850     /** The bit mask of {@link AccessFlag#TRANSITIVE} access and property modifier. */
 851     int ACC_TRANSITIVE = 0x20;
 852 
 853     /** The bit mask of {@link AccessFlag#STATIC_PHASE} access and property modifier. */
 854     int ACC_STATIC_PHASE = 0x40;
 855 
 856     /**
 857      * The class major version of the initial version of Java, {@value}.
 858      *
 859      * @see ClassFileFormatVersion#RELEASE_0
 860      * @see ClassFileFormatVersion#RELEASE_1

   1 /*
   2  * Copyright (c) 2022, 2026, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any

  37 import java.lang.classfile.constantpool.ConstantPoolBuilder;
  38 import java.lang.classfile.constantpool.Utf8Entry;
  39 import java.lang.classfile.instruction.BranchInstruction;
  40 import java.lang.classfile.instruction.CharacterRange;
  41 import java.lang.classfile.instruction.DiscontinuedInstruction;
  42 import java.lang.classfile.instruction.ExceptionCatch;
  43 import java.lang.classfile.instruction.LineNumber;
  44 import java.lang.classfile.instruction.LocalVariable;
  45 import java.lang.classfile.instruction.LocalVariableType;
  46 import java.lang.constant.ClassDesc;
  47 import java.lang.reflect.AccessFlag;
  48 import java.lang.reflect.ClassFileFormatVersion;
  49 import java.nio.file.Files;
  50 import java.nio.file.Path;
  51 import java.util.List;
  52 import java.util.function.Consumer;
  53 import java.util.function.Function;
  54 
  55 import jdk.internal.classfile.impl.ClassFileImpl;
  56 import jdk.internal.classfile.impl.TemporaryConstantPool;
  57 import jdk.internal.javac.PreviewFeature;
  58 
  59 import static java.util.Objects.requireNonNull;
  60 import static jdk.internal.constant.ConstantUtils.CD_module_info;
  61 
  62 /**
  63  * Provides ability to parse, transform, and generate {@code class} files.
  64  * A {@code ClassFile} is a context with a set of options that condition how
  65  * parsing and generation are done.
  66  *
  67  * @since 24
  68  */
  69 public sealed interface ClassFile
  70         permits ClassFileImpl {
  71 
  72     /**
  73      * {@return a context with default options}  Each subtype of {@link Option}
  74      * specifies its default.
  75      * <p>
  76      * The default {@link AttributeMapperOption} and {@link
  77      * ClassHierarchyResolverOption} may be unsuitable for some {@code class}

 789     int ACC_PUBLIC = 0x0001;
 790 
 791     /** The bit mask of {@link AccessFlag#PROTECTED} access and property modifier. */
 792     int ACC_PROTECTED = 0x0004;
 793 
 794     /** The bit mask of {@link AccessFlag#PRIVATE} access and property modifier. */
 795     int ACC_PRIVATE = 0x0002;
 796 
 797     /** The bit mask of {@link AccessFlag#INTERFACE} access and property modifier. */
 798     int ACC_INTERFACE = 0x0200;
 799 
 800     /** The bit mask of {@link AccessFlag#ENUM} access and property modifier. */
 801     int ACC_ENUM = 0x4000;
 802 
 803     /** The bit mask of {@link AccessFlag#ANNOTATION} access and property modifier. */
 804     int ACC_ANNOTATION = 0x2000;
 805 
 806     /** The bit mask of {@link AccessFlag#SUPER} access and property modifier. */
 807     int ACC_SUPER = 0x0020;
 808 
 809     /**
 810      * The bit mask of {@link AccessFlag#IDENTITY} access and property modifier.
 811      *
 812      * @since Valhalla
 813      */
 814     @PreviewFeature(feature = PreviewFeature.Feature.VALUE_OBJECTS, reflective = true)
 815     int ACC_IDENTITY = 0x0020;
 816 
 817     /** The bit mask of {@link AccessFlag#ABSTRACT} access and property modifier. */
 818     int ACC_ABSTRACT = 0x0400;
 819 
 820     /** The bit mask of {@link AccessFlag#VOLATILE} access and property modifier. */
 821     int ACC_VOLATILE = 0x0040;
 822 
 823     /** The bit mask of {@link AccessFlag#TRANSIENT} access and property modifier. */
 824     int ACC_TRANSIENT = 0x0080;
 825 
 826     /** The bit mask of {@link AccessFlag#SYNTHETIC} access and property modifier. */
 827     int ACC_SYNTHETIC = 0x1000;
 828 
 829     /** The bit mask of {@link AccessFlag#STATIC} access and property modifier. */
 830     int ACC_STATIC = 0x0008;
 831 
 832     /** The bit mask of {@link AccessFlag#FINAL} access and property modifier. */
 833     int ACC_FINAL = 0x0010;
 834 
 835     /** The bit mask of {@link AccessFlag#SYNCHRONIZED} access and property modifier. */
 836     int ACC_SYNCHRONIZED = 0x0020;
 837 
 838     /** The bit mask of {@link AccessFlag#BRIDGE} access and property modifier. */
 839     int ACC_BRIDGE = 0x0040;
 840 
 841     /** The bit mask of {@link AccessFlag#VARARGS} access and property modifier. */
 842     int ACC_VARARGS = 0x0080;
 843 
 844     /** The bit mask of {@link AccessFlag#NATIVE} access and property modifier. */
 845     int ACC_NATIVE = 0x0100;
 846 
 847     /** The bit mask of {@link AccessFlag#STRICT} access and property modifier. */
 848     int ACC_STRICT = 0x0800;
 849 
 850     /**
 851      * The bit mask of {@link AccessFlag#STRICT_INIT} access and property modifier.
 852      *
 853      * @since Valhalla
 854      */
 855     @PreviewFeature(feature = PreviewFeature.Feature.STRICT_FIELDS, reflective = true)
 856     int ACC_STRICT_INIT = 0x0800;
 857 
 858     /** The bit mask of {@link AccessFlag#MODULE} access and property modifier. */
 859     int ACC_MODULE = 0x8000;
 860 
 861     /** The bit mask of {@link AccessFlag#OPEN} access and property modifier. */
 862     int ACC_OPEN = 0x20;
 863 
 864     /** The bit mask of {@link AccessFlag#MANDATED} access and property modifier. */
 865     int ACC_MANDATED = 0x8000;
 866 
 867     /** The bit mask of {@link AccessFlag#TRANSITIVE} access and property modifier. */
 868     int ACC_TRANSITIVE = 0x20;
 869 
 870     /** The bit mask of {@link AccessFlag#STATIC_PHASE} access and property modifier. */
 871     int ACC_STATIC_PHASE = 0x40;
 872 
 873     /**
 874      * The class major version of the initial version of Java, {@value}.
 875      *
 876      * @see ClassFileFormatVersion#RELEASE_0
 877      * @see ClassFileFormatVersion#RELEASE_1
< prev index next >