Skip to content

Commit 2788e36

Browse files
committed
Add modifier handling.
1 parent 39a9814 commit 2788e36

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

byte-buddy-dep/src/main/java/net/bytebuddy/ByteBuddy.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import net.bytebuddy.description.modifier.Ownership;
2828
import net.bytebuddy.description.modifier.TypeManifestation;
2929
import net.bytebuddy.description.modifier.Visibility;
30+
import net.bytebuddy.description.module.ModuleDescription;
3031
import net.bytebuddy.description.type.PackageDescription;
3132
import net.bytebuddy.description.type.RecordComponentDescription;
3233
import net.bytebuddy.description.type.TypeDefinition;
@@ -797,6 +798,29 @@ public DynamicType.Builder<?> makeRecord() {
797798
.method(isToString()).intercept(RecordObjectMethod.TO_STRING);
798799
}
799800

801+
/**
802+
* Creates a new module with the given name.
803+
*
804+
* @param name The name of the module.
805+
* @return A builder for a new module.
806+
*/
807+
public DynamicType.Builder.ModuleDefinition<?> makeModule(String name) {
808+
return makeModule(name, false);
809+
}
810+
811+
/**
812+
* Creates a new module with the given name.
813+
*
814+
* @param name The name of the module.
815+
* @param open {@code true} if the module is to be opened.
816+
* @return A builder for a new module.
817+
*/
818+
public DynamicType.Builder.ModuleDefinition<?> makeModule(String name, boolean open) {
819+
return subclass(Object.class)
820+
.name(ModuleDescription.MODULE_CLASS_NAME)
821+
.module(name, open ? Opcodes.ACC_OPEN : ModifierContributor.EMPTY_MASK);
822+
}
823+
800824
/**
801825
* <p>
802826
* Creates a new {@link Annotation} type. Annotation properties are implemented as non-static, public methods with the

byte-buddy-dep/src/main/java/net/bytebuddy/description/type/TypeDescription.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,13 @@ public interface TypeDescription extends TypeDefinition, ByteCodeElement, TypeVa
336336
@MaybeNull
337337
ModuleDescription toModuleDescription();
338338

339+
/**
340+
* Returns {@code true} if the represented type includes a module description.
341+
*
342+
* @return {@code true} if the represented type includes a module description.
343+
*/
344+
boolean isModule();
345+
339346
/**
340347
* Returns the annotations that this type declares or inherits from super types.
341348
*
@@ -8013,7 +8020,8 @@ public int getActualModifiers(boolean superFlag) {
80138020
int actualModifiers = getModifiers()
80148021
| (getDeclaredAnnotations().isAnnotationPresent(Deprecated.class) ? Opcodes.ACC_DEPRECATED : EMPTY_MASK)
80158022
| (isRecord() ? Opcodes.ACC_RECORD : EMPTY_MASK)
8016-
| (superFlag ? Opcodes.ACC_SUPER : EMPTY_MASK);
8023+
| (superFlag ? Opcodes.ACC_SUPER : EMPTY_MASK)
8024+
| (isModule() ? Opcodes.ACC_MODULE : EMPTY_MASK);
80178025
if (isPrivate()) {
80188026
return actualModifiers & ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC);
80198027
} else if (isProtected()) {
@@ -8059,6 +8067,13 @@ public String getGenericSignature() {
80598067
}
80608068
}
80618069

8070+
/**
8071+
* {@inheritDoc}
8072+
*/
8073+
public boolean isModule() {
8074+
return toModuleDescription() != null;
8075+
}
8076+
80628077
/**
80638078
* {@inheritDoc}
80648079
*/

byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/scaffold/TypeWriter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5080,7 +5080,8 @@ public void visit(int classFileVersionNumber,
50805080
instrumentedType.getActualModifiers((modifiers & Opcodes.ACC_SUPER) != 0 && !instrumentedType.isInterface())
50815081
| resolveDeprecationModifiers(modifiers)
50825082
// Anonymous types might not preserve their class file's final modifier via their inner class modifier.
5083-
| (((modifiers & Opcodes.ACC_FINAL) != 0 && instrumentedType.isAnonymousType()) ? Opcodes.ACC_FINAL : 0),
5083+
| (((modifiers & Opcodes.ACC_FINAL) != 0 && instrumentedType.isAnonymousType()) ? Opcodes.ACC_FINAL : ModifierContributor.EMPTY_MASK)
5084+
| (instrumentedType.isModule() ? Opcodes.ACC_MODULE : ModifierContributor.EMPTY_MASK),
50845085
instrumentedType.getInternalName(),
50855086
TypeDescription.AbstractBase.RAW_TYPES
50865087
? genericSignature

byte-buddy-dep/src/main/java/net/bytebuddy/pool/TypePool.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3412,13 +3412,21 @@ public PackageDescription getPackage() {
34123412
: name.substring(0, index));
34133413
}
34143414

3415+
/**
3416+
* {@inheritDoc}
3417+
*/
34153418
@MaybeNull
34163419
public ModuleDescription toModuleDescription() {
34173420
return moduleToken == null
34183421
? ModuleDescription.UNDEFINED
34193422
: moduleToken.toModuleDescription(this);
34203423
}
34213424

3425+
@Override
3426+
public boolean isModule() {
3427+
return moduleToken != null;
3428+
}
3429+
34223430
/**
34233431
* {@inheritDoc}
34243432
*/

0 commit comments

Comments
 (0)