-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created a Dumper interface, with the methods #dump(T) and #printDump(T). Implemented the Dumper interface when creating the following classes: * ClassDumper * FieldDumper * ConstructorDumper * MethodDumper * AllFieldsDumper * AllConstructorsDumper * AllMethodsDumper Created the TypeDisplayNameFormat enum, which is used to specify the name formats of return types, parameter types and field types. Written unit tests for the new Dumper classes Fixed missing generic in BetterReflectionClass#isAssignableFrom(BetterReflectionClass) method Deprecated BetterReflectionUtils#dumpMethodHeader() and BetterReflectionUtils#generateMethodHeader()
- Loading branch information
1 parent
09d0790
commit fa5a114
Showing
16 changed files
with
1,092 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/top/wavelength/betterreflection/dumper/Dumper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package top.wavelength.betterreflection.dumper; | ||
|
||
/** | ||
* The Dumper interface is responsible for dumping the information related to an object of type T. | ||
* | ||
* @param <T> the type of object to be dumped | ||
* @since 1.2 | ||
*/ | ||
public interface Dumper<T> { | ||
/** | ||
* Dumps the information related to an object of type T. | ||
* | ||
* @param object the object to be dumped | ||
* @return a string containing the dumped information | ||
* @since 1.2 | ||
*/ | ||
String dump(T object); | ||
|
||
/** | ||
* Prints the dumped information of an object. | ||
* | ||
* @param object the object to be dumped | ||
* @since 1.2 | ||
*/ | ||
default void printDump(T object) { | ||
System.out.println(dump(object)); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/top/wavelength/betterreflection/dumper/TypeDisplayNameFormat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package top.wavelength.betterreflection.dumper; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Parameter; | ||
|
||
/** | ||
* TypeDisplayNameFormat is an enumeration that represents different formats for displaying the names of types. | ||
* It provides methods to get the formatted names of classes, methods, fields, and parameters. | ||
* | ||
* @since 1.2 | ||
*/ | ||
public enum TypeDisplayNameFormat { | ||
|
||
FULL_NAME, | ||
CANONICAL_NAME, | ||
TYPE_NAME, | ||
SIMPLE_NAME, | ||
NONE; | ||
|
||
/** | ||
* Returns the name of the given type based on the specified TypeDisplayNameFormat. | ||
* | ||
* @param type The type for which the name will be returned | ||
* @return The formatted name of the type | ||
* @since 1.2 | ||
*/ | ||
public String getName(Class<?> type) { | ||
switch (this) { | ||
case FULL_NAME: | ||
return type.getName(); | ||
case CANONICAL_NAME: | ||
return type.getCanonicalName(); | ||
case TYPE_NAME: | ||
return type.getTypeName(); | ||
case SIMPLE_NAME: | ||
return type.getSimpleName(); | ||
case NONE: | ||
default: | ||
return ""; | ||
} | ||
} | ||
|
||
/** | ||
* Returns the name of the given method's return type based on the specified TypeDisplayNameFormat. | ||
* | ||
* @param method The Method object for which the return type name will be returned | ||
* @return The formatted name of the return type of the method | ||
* @since 1.2 | ||
*/ | ||
public String getName(Method method) { | ||
return getName(method.getReturnType()); | ||
} | ||
|
||
/** | ||
* Returns the name of the given field's type. | ||
* | ||
* @param field The field for which the type name will be returned | ||
* @return The name of the field's type | ||
* @since 1.2 | ||
*/ | ||
public String getName(Field field) { | ||
return getName(field.getType()); | ||
} | ||
|
||
/** | ||
* Returns the name of the given parameter's type based on the specified TypeDisplayNameFormat. | ||
* | ||
* @param parameter The parameter for which the type name will be returned | ||
* @return The formatted name of the parameter's type | ||
* @since 1.2 | ||
*/ | ||
public String getName(Parameter parameter) { | ||
return getName(parameter.getType()); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/top/wavelength/betterreflection/dumper/all/AllConstructorsDumper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package top.wavelength.betterreflection.dumper.all; | ||
|
||
import top.wavelength.betterreflection.BetterReflectionClass; | ||
import top.wavelength.betterreflection.dumper.Dumper; | ||
import top.wavelength.betterreflection.dumper.implementation.ConstructorDumper; | ||
|
||
import java.lang.reflect.Constructor; | ||
|
||
/** | ||
* The AllConstructorsDumper class is responsible for dumping the constructors of a class. | ||
* It implements the Dumper interface and operates on an object of type {@link BetterReflectionClass}. | ||
* | ||
* @since 1.2 | ||
*/ | ||
public class AllConstructorsDumper implements Dumper<BetterReflectionClass<?>> { | ||
|
||
private final ConstructorDumper constructorDumper; | ||
|
||
/** | ||
* Constructs an AllConstructorsDumper with a specified ConstructorDumper. | ||
* | ||
* @param constructorDumper the ConstructorDumper to be used for dumping. | ||
* @since 1.2 | ||
*/ | ||
public AllConstructorsDumper(ConstructorDumper constructorDumper) { | ||
this.constructorDumper = constructorDumper; | ||
} | ||
|
||
/** | ||
* Default constructor for AllConstructorsDumper. | ||
* Initializes a new ConstructorDumper. | ||
* | ||
* @since 1.2 | ||
*/ | ||
public AllConstructorsDumper() { | ||
this(new ConstructorDumper()); | ||
} | ||
|
||
/** | ||
* Dumps all the constructors of a given BetterReflectionClass. | ||
* | ||
* @param clasz the class to be dumped | ||
* @return a string representation of the dumped constructors | ||
* @since 1.2 | ||
*/ | ||
@Override | ||
public String dump(BetterReflectionClass<?> clasz) { | ||
StringBuilder result = new StringBuilder(); | ||
for (Constructor<?> constructor : clasz.getConstructors()) | ||
result.append(constructorDumper.dump(constructor)).append("\n"); | ||
return result.toString(); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/top/wavelength/betterreflection/dumper/all/AllFieldsDumper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package top.wavelength.betterreflection.dumper.all; | ||
|
||
import top.wavelength.betterreflection.BetterReflectionClass; | ||
import top.wavelength.betterreflection.dumper.Dumper; | ||
import top.wavelength.betterreflection.dumper.implementation.FieldDumper; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
/** | ||
* The AllFieldsDumper class is responsible for dumping the fields of a class. | ||
* It implements the Dumper interface and operates on an object of type {@link BetterReflectionClass}. | ||
* | ||
* @since 1.2 | ||
*/ | ||
public class AllFieldsDumper implements Dumper<BetterReflectionClass<?>> { | ||
|
||
private final FieldDumper fieldDumper; | ||
|
||
/** | ||
* Constructs an AllFieldsDumper with a specified FieldDumper. | ||
* | ||
* @param fieldDumper the FieldDumper to be used for dumping. | ||
* @since 1.2 | ||
*/ | ||
public AllFieldsDumper(FieldDumper fieldDumper) { | ||
this.fieldDumper = fieldDumper; | ||
} | ||
|
||
/** | ||
* Default constructor for AllFieldsDumper. | ||
* Initializes a new FieldDumper. | ||
* | ||
* @since 1.2 | ||
*/ | ||
public AllFieldsDumper() { | ||
this(new FieldDumper()); | ||
} | ||
|
||
/** | ||
* Dumps all the fields of a given BetterReflectionClass. | ||
* | ||
* @param clasz the class to be dumped | ||
* @return a string representation of the dumped fields | ||
* @since 1.2 | ||
*/ | ||
@Override | ||
public String dump(BetterReflectionClass<?> clasz) { | ||
StringBuilder result = new StringBuilder(); | ||
for (Field field : clasz.getFields()) | ||
result.append(fieldDumper.dump(field)).append("\n"); | ||
return result.toString(); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/top/wavelength/betterreflection/dumper/all/AllMethodsDumper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package top.wavelength.betterreflection.dumper.all; | ||
|
||
import top.wavelength.betterreflection.BetterReflectionClass; | ||
import top.wavelength.betterreflection.dumper.Dumper; | ||
import top.wavelength.betterreflection.dumper.implementation.MethodDumper; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* The AllMethodsDumper class is responsible for dumping the methods of a class. | ||
* It implements the Dumper interface and operates on an object of type {@link BetterReflectionClass}. | ||
* | ||
* @since 1.2 | ||
*/ | ||
public class AllMethodsDumper implements Dumper<BetterReflectionClass<?>> { | ||
|
||
private final MethodDumper methodDumper; | ||
|
||
/** | ||
* Constructs an AllMethodsDumper with a specified MethodDumper. | ||
* | ||
* @param methodDumper the MethodDumper to be used for dumping. | ||
* @since 1.2 | ||
*/ | ||
public AllMethodsDumper(MethodDumper methodDumper) { | ||
this.methodDumper = methodDumper; | ||
} | ||
|
||
/** | ||
* Default constructor for AllMethodsDumper. | ||
* Initializes a new MethodDumper. | ||
* | ||
* @since 1.2 | ||
*/ | ||
public AllMethodsDumper() { | ||
this(new MethodDumper()); | ||
} | ||
|
||
/** | ||
* Dumps all the methods of a given BetterReflectionClass. | ||
* | ||
* @param clasz the class to be dumped | ||
* @return a string representation of the dumped methods | ||
* @since 1.2 | ||
*/ | ||
@Override | ||
public String dump(BetterReflectionClass<?> clasz) { | ||
StringBuilder result = new StringBuilder(); | ||
for (Method method : clasz.getMethods()) | ||
result.append(methodDumper.dump(method)).append("\n"); | ||
return result.toString(); | ||
} | ||
} |
Oops, something went wrong.