RFR: 8342336: Optimize ClassFile imports

Chen Liang liach at openjdk.org
Wed Oct 16 10:32:51 UTC 2024


On Sun, 13 Oct 2024 01:42:38 GMT, Shaojin Wen <swen at openjdk.org> wrote:

> This is a code style improvement for imports in the java/lang/classfile and jdk/internal/classfile/impl directories, includes:
> 1. Import in alphabetical order
> 2. Add a blank line between java and jdk imports
> 3. Use import * for a large number of imports

src/java.base/share/classes/java/lang/classfile/AccessFlags.java line 29:

> 27: import java.lang.reflect.AccessFlag;
> 28: import java.util.Set;
> 29: import jdk.internal.classfile.impl.AccessFlagsImpl;

Missing blank line

src/java.base/share/classes/java/lang/classfile/ClassBuilder.java line 1:

> 1: /*

We should sort java.* imports so `lang.classfile` comes before `lang.constant`

src/java.base/share/classes/java/lang/classfile/ClassSignature.java line 28:

> 26: 
> 27: import java.util.List;
> 28: import jdk.internal.classfile.impl.SignaturesImpl;

Need a blank line before

src/java.base/share/classes/java/lang/classfile/CodeBuilder.java line 43:

> 41: 
> 42: import jdk.internal.classfile.impl.*;
> 43: import jdk.internal.classfile.impl.TransformImpl;

Suggestion:

src/java.base/share/classes/java/lang/classfile/Instruction.java line 29:

> 27: 
> 28: import jdk.internal.classfile.impl.AbstractInstruction;
> 29: import java.lang.classfile.instruction.*;

Move this before `jdk.internal` and add blank line.

src/java.base/share/classes/java/lang/classfile/MethodElement.java line 28:

> 26: 
> 27: import java.lang.classfile.attribute.*;
> 28: import jdk.internal.javac.PreviewFeature;

Blank line

src/java.base/share/classes/java/lang/classfile/PseudoInstruction.java line 29:

> 27: import java.lang.classfile.attribute.CodeAttribute;
> 28: import java.lang.classfile.instruction.*;
> 29: import jdk.internal.classfile.impl.AbstractPseudoInstruction;

Blank line

src/java.base/share/classes/java/lang/classfile/constantpool/ModuleEntry.java line 28:

> 26: 
> 27: import java.lang.constant.ModuleDesc;
> 28: import jdk.internal.classfile.impl.AbstractPoolEntry;

Blank line

src/java.base/share/classes/java/lang/classfile/constantpool/PackageEntry.java line 28:

> 26: 
> 27: import java.lang.constant.PackageDesc;
> 28: import jdk.internal.classfile.impl.AbstractPoolEntry;

Blank line

src/java.base/share/classes/jdk/internal/classfile/impl/AnnotationReader.java line 33:

> 31: 
> 32: import static java.lang.classfile.AnnotationValue.*;
> 33: import static java.lang.classfile.TypeAnnotation.TargetInfo.*;

Maybe move all static imports below regular imports...

src/java.base/share/classes/jdk/internal/classfile/impl/BytecodeHelpers.java line 28:

> 26: package jdk.internal.classfile.impl;
> 27: 
> 28: import java.lang.constant.*;

constant comes after classfile

src/java.base/share/classes/jdk/internal/classfile/impl/ClassReaderImpl.java line 34:

> 32: import java.util.Optional;
> 33: import java.util.function.Function;
> 34: import java.lang.classfile.*;

lang.* comes before util.*

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/21482#discussion_r1798683478
PR Review Comment: https://git.openjdk.org/jdk/pull/21482#discussion_r1798683789
PR Review Comment: https://git.openjdk.org/jdk/pull/21482#discussion_r1798684015
PR Review Comment: https://git.openjdk.org/jdk/pull/21482#discussion_r1798684167
PR Review Comment: https://git.openjdk.org/jdk/pull/21482#discussion_r1798684371
PR Review Comment: https://git.openjdk.org/jdk/pull/21482#discussion_r1798684466
PR Review Comment: https://git.openjdk.org/jdk/pull/21482#discussion_r1798684556
PR Review Comment: https://git.openjdk.org/jdk/pull/21482#discussion_r1798686077
PR Review Comment: https://git.openjdk.org/jdk/pull/21482#discussion_r1798686125
PR Review Comment: https://git.openjdk.org/jdk/pull/21482#discussion_r1798686757
PR Review Comment: https://git.openjdk.org/jdk/pull/21482#discussion_r1798690093
PR Review Comment: https://git.openjdk.org/jdk/pull/21482#discussion_r1798692369


More information about the core-libs-dev mailing list