Skip to content

Commit 25ef7d0

Browse files
committed
Add additional properties on class reader representation.
1 parent 49503e5 commit 25ef7d0

File tree

2 files changed

+138
-12
lines changed

2 files changed

+138
-12
lines changed

byte-buddy-dep/src/main/java/net/bytebuddy/utility/AsmClassReader.java

Lines changed: 137 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package net.bytebuddy.utility;
1717

18+
import jdk.internal.org.objectweb.asm.Opcodes;
1819
import net.bytebuddy.ClassFileVersion;
1920
import net.bytebuddy.build.AccessControllerPlugin;
2021
import net.bytebuddy.build.HashCodeAndEqualsPlugin;
@@ -26,6 +27,9 @@
2627
import org.objectweb.asm.ClassVisitor;
2728

2829
import java.security.PrivilegedAction;
30+
import java.util.Arrays;
31+
import java.util.Collections;
32+
import java.util.List;
2933

3034
/**
3135
* A facade for creating a class reader that accepts {@link ClassVisitor} instances and reader flags.
@@ -48,24 +52,37 @@ public interface AsmClassReader {
4852
<T> T unwrap(Class<T> type);
4953

5054
/**
51-
* Returns the internal name of the represented type's super class or {@code null} if there is none.
52-
* The super class is - after possibility - read without parsing the entire class file.
55+
* Returns the modifiers of the represented class. The property is read, if possible, without parsing the entire
56+
* class file.
5357
*
54-
* @return The internal name of the represented type's super class or {@code null} if there is none.
58+
* @return The modifiers of the represented class.
5559
*/
56-
@MaybeNull
57-
String getSuperClassName();
60+
int getModifiers();
5861

5962
/**
60-
* Returns an array of internal names of the represented type's interface types, or {@code null} if
61-
* none are defined. The interface types are - after possibility - read without parsing the entire
62-
* class file.
63+
* Returns the internal name of the represented class. The property is read, if possible, without parsing
64+
* the entire class file.
6365
*
64-
* @return An array of internal names of the represented type's interface types, or {@code null} if
65-
* none are defined.
66+
* @return The internal name of the represented class.
67+
*/
68+
String getInternalName();
69+
70+
/**
71+
* Returns the internal name of the represented class's super class, or {@code null} if no such class exists.
72+
* The property is read, if possible, without parsing the entire class file.
73+
*
74+
* @return The internal name of the represented class's super class, or {@code null} if no such class exists.
6675
*/
6776
@MaybeNull
68-
String[] getInterfaceTypeName();
77+
String getSuperClassInternalName();
78+
79+
/**
80+
* Returns the internal names of the represented class's interfaces. The property is read, if possible,
81+
* without parsing the entire class file.
82+
*
83+
* @return Returns the internal names of the represented class's interfaces.
84+
*/
85+
List<String> getInterfaceInternalNames();
6986

7087
/**
7188
* Accepts a class visitor to read a class.
@@ -238,6 +255,35 @@ public <T> T unwrap(Class<T> type) {
238255
: null;
239256
}
240257

258+
/**
259+
* {@inheritDoc}
260+
*/
261+
public int getModifiers() {
262+
return classReader.getAccess();
263+
}
264+
265+
/**
266+
* {@inheritDoc}
267+
*/
268+
public String getInternalName() {
269+
return classReader.getClassName();
270+
}
271+
272+
/**
273+
* {@inheritDoc}
274+
*/
275+
public String getSuperClassInternalName() {
276+
return classReader.getSuperName();
277+
}
278+
279+
/**
280+
* {@inheritDoc}
281+
*/
282+
public List<String> getInterfaceInternalNames() {
283+
String[] value = classReader.getInterfaces();
284+
return value == null ? Collections.emptyList() : Arrays.asList(value);
285+
}
286+
241287
/**
242288
* {@inheritDoc}
243289
*/
@@ -298,6 +344,52 @@ public <T> T unwrap(Class<T> type) {
298344
: null;
299345
}
300346

347+
/**
348+
* {@inheritDoc}
349+
*/
350+
public int getModifiers() {
351+
return DISPATCHER.getAccess(classReader);
352+
}
353+
354+
/**
355+
* {@inheritDoc}
356+
*/
357+
public String getInternalName() {
358+
return DISPATCHER.getClassName(classReader);
359+
}
360+
361+
/**
362+
* {@inheritDoc}
363+
*/
364+
@MaybeNull
365+
public String getSuperClassInternalName() {
366+
return DISPATCHER.getSuperClass(classReader);
367+
}
368+
369+
/**
370+
* {@inheritDoc}
371+
*/
372+
public List<String> getInterfaceInternalNames() {
373+
String[] value = DISPATCHER.getInterfaces(classReader);
374+
return value == null ? Collections.emptyList() : Arrays.asList(value);
375+
}
376+
377+
/**
378+
* {@inheritDoc}
379+
*/
380+
@MaybeNull
381+
public String getSuperClassName() {
382+
return DISPATCHER.getSuperClass(classReader);
383+
}
384+
385+
/**
386+
* {@inheritDoc}
387+
*/
388+
@MaybeNull
389+
public String[] getInterfaceTypeName() {
390+
return DISPATCHER.getInterfaces(classReader);
391+
}
392+
301393
/**
302394
* {@inheritDoc}
303395
*/
@@ -330,6 +422,40 @@ protected interface JdkClassReader {
330422
@JavaDispatcher.IsConstructor
331423
Object make(byte[] binaryRepresentation, Attribute[] attribute);
332424

425+
/**
426+
* Returns the access flags of the underlying {@code codes.rafael.asmjdkbridge.JdkClassReader}.
427+
*
428+
* @param classReader The class reader that is being queried.
429+
* @return The access flags of the underlying {@code codes.rafael.asmjdkbridge.JdkClassReader}.
430+
*/
431+
int getAccess(Object classReader);
432+
433+
/**
434+
* Returns the internal name of the represented type.
435+
*
436+
* @param classReader The class reader that is being queried.
437+
* @return The internal name of the represented type.
438+
*/
439+
String getClassName(Object classReader);
440+
441+
/**
442+
* Returns the internal name of the represented type's super class or {@code null} if there is none.
443+
*
444+
* @param classReader The class reader that is being queried.
445+
* @return The internal name of the represented type's super class or {@code null} if there is none.
446+
*/
447+
@MaybeNull
448+
String getSuperClass(Object classReader);
449+
450+
/**
451+
* Returns an array of internal names of the represented type's interface types, or {@code null} if none.
452+
*
453+
* @param classReader The class reader that is being queried.
454+
* @return An array of internal names of the represented type's interface types, or {@code null} if none.
455+
*/
456+
@MaybeNull
457+
String[] getInterfaces(Object classReader);
458+
333459
/**
334460
* Accepts a class reader to visit the represented class file.
335461
*

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
<bytecode.test.version>1.6</bytecode.test.version>
7171
<pitest.target>net.bytebuddy</pitest.target>
7272
<version.asm>9.8</version.asm>
73-
<version.asmjdkbridge>0.0.9</version.asmjdkbridge>
73+
<version.asmjdkbridge>0.0.10</version.asmjdkbridge>
7474
<version.jna>5.12.1</version.jna>
7575
<version.junit>4.13.2</version.junit>
7676
<version.mockito>2.28.2</version.mockito>

0 commit comments

Comments
 (0)