public interface IIntercessor
Modifier and Type | Method and Description |
---|---|
default void |
addAnnotation(java.lang.reflect.Method met,
java.lang.reflect.Type... annotations)
Add the provided annotations to the specified method.
|
void |
addAnnotation(Method met,
java.lang.reflect.Type... annotations) |
void |
addAnnotation(java.lang.reflect.Type clazz,
java.lang.reflect.Type... annotations)
Add the provided annotations to the specified class.
|
default void |
addField(java.lang.reflect.Type clazz,
java.lang.reflect.Field... fields)
Adds fields to the specified class
For example:
Intercessor.addField(Person.class, new jmplib.reflect.Field(String.class, "lastName"));
|
void |
addField(java.lang.reflect.Type clazz,
Field... fields) |
default void |
addGenericType(java.lang.reflect.Method met,
TypeVariable<?>... types)
Add the provided generic types to the specified method.
|
void |
addGenericType(Method met,
TypeVariable<?>... types) |
void |
addGenericType(java.lang.reflect.Type clazz,
TypeVariable<?>... types)
Add the provided generic type to the specified class.
|
default void |
addImport(java.lang.reflect.Type clazz,
java.lang.Class<?>... imports)
Add the provided imports to the source file that defines the specified class.
|
void |
addImport(java.lang.reflect.Type clazz,
Class<?>... imports) |
void |
addImport(java.lang.reflect.Type clazz,
java.lang.Package... imports)
Add the provided imports to the source file that defines the specified class.
|
void |
addInterface(java.lang.reflect.Type clazz,
java.util.Map<java.lang.reflect.Type,java.lang.reflect.Type[]> interfs)
Version of the previous method able to add multiple interfaces.
|
void |
addInterface(java.lang.reflect.Type clazz,
java.lang.reflect.Type interf,
java.lang.reflect.Type... typeParameters)
Adds an interface to the provided class.
|
default void |
addMethod(java.lang.reflect.Type clazz,
java.lang.reflect.Method... methods)
Adds methods to the specified class
For example:
// Declaring MethodType
MethodType mt = MethodType.methodType(int.class, int.class);
// Adding method to Counter
Intercessor.addMethod(Counter.class, new jmplib.reflect.Method("sum", mt,
"return this.counter += value;", "value"));
|
void |
addMethod(java.lang.reflect.Type clazz,
Method... methods) |
void |
addPublicInterfaceOf(java.lang.reflect.Type origin,
java.lang.reflect.Type destination)
Adds all the members of the public interface of the specified class to
another class
|
default void |
commit()
Performs the operations indicated to the intercessor, if the intercessor has
the ability to store the operations until they are executed at the same time.
|
Class<?> |
createClassClone(java.lang.String packageName,
java.lang.String className,
java.lang.reflect.Type origin)
Creates a class clone of the specified class with the specified name and
belonging to the provided package
|
IIntercessor |
createIntercessor()
Creates an instance of the intercessor implementing this interface
|
java.lang.reflect.AnnotatedElement[] |
getImports(java.lang.reflect.Type clazz)
Get the imports of the source file that defines the specified class.
|
default void |
implementInterface(java.lang.reflect.Type clazz,
java.lang.reflect.Type interf,
java.lang.reflect.Method[] methods,
java.lang.Class<?>... typeParameters)
Version of the addInterface method that also allow to add a series of method
that belong to the interface to be implemented.
|
void |
implementInterface(java.lang.reflect.Type clazz,
java.lang.reflect.Type interf,
Method[] methods,
java.lang.Class<?>... typeParameters) |
default void |
removeField(java.lang.reflect.Type clazz,
java.lang.reflect.Field... fields)
Removes fields in the specified class
For example:
Intercessor.deleteField(Person.class, new jmplib.reflect.Field("lastName"));
|
void |
removeField(java.lang.reflect.Type clazz,
Field... fields) |
void |
removeInterface(java.lang.reflect.Type clazz,
java.lang.reflect.Type interf)
Removes an interface from a class
|
default void |
removeMethod(java.lang.reflect.Type clazz,
java.lang.reflect.Method... methods)
Removes a series of methods from the specified class
For example:
// Deleting method
Intercessor.deleteMethod(Dog.class, new jmplib.reflect.Method("bark"));
Dog dog = new Dog();
dog.bark(); // Throws RuntimeException
|
void |
removeMethod(java.lang.reflect.Type clazz,
Method... methods) |
void |
removeSuperclass(java.lang.reflect.Type clazz)
Removes the superclass of an existing class, setting it to Object.
|
default void |
replaceField(java.lang.reflect.Type clazz,
java.lang.reflect.Field... fields)
Replaces fields in the specified class
For example:
Intercessor.replaceField(Calculator.class, new jmplib.reflect.Field("lastResult", double.class));
|
void |
replaceField(java.lang.reflect.Type clazz,
Field... fields) |
default void |
replaceImplementation(java.lang.reflect.Type clazz,
java.lang.reflect.Method... methods)
Replace the implementation of a series of methods of the specified class
For example, modifying the method to use a new field called lastResult:
// Modify a the method code
Intercessor.replaceImplementation(Calculator.class, new jmplib.reflect.Method("sum",
"this.lastResult = a + b;"
+ "return this.lastResult;"));
|
void |
replaceImplementation(java.lang.reflect.Type clazz,
Method... methods) |
void |
replaceMethod(java.lang.reflect.Type clazz,
java.util.Map<Method,Method> methods)
Replaces a series of methods from the specified class
For example, modifying the method to acept a more generic type (Dog ->
Animal):
// Creating MethodType
MethodType newType = MethodType.methodType(void.class, Pet.class);
// Modifying the method
Intercessor.replaceMethod(Owner.class, new jmplib.reflect.Method("addPet", newType,
"this.pet = dog;"));
|
default void |
replaceMethod(java.lang.reflect.Type clazz,
java.lang.reflect.Method method,
java.lang.reflect.Method newMethod)
Replaces a method of the specified class
|
void |
replaceMethod(java.lang.reflect.Type clazz,
Method method,
Method newMethod) |
default void |
setAnnotation(java.lang.reflect.Method met,
java.lang.reflect.Type... annotations)
Replace the annotations of a method with the provided ones.
|
void |
setAnnotation(Method met,
java.lang.reflect.Type... annotations) |
void |
setAnnotation(java.lang.reflect.Type clazz,
java.lang.reflect.Type... annotations)
Replace the annotations of the specified class with the provided ones.
|
default void |
setGenericType(java.lang.reflect.Method met,
TypeVariable<?>... types)
Replace the generic types of a method with the provided ones.
|
void |
setGenericType(Method met,
TypeVariable<?>... types) |
void |
setGenericType(java.lang.reflect.Type clazz,
TypeVariable<?>... types)
Replace the generic types of the specified class with the provided ones.
|
void |
setImports(java.lang.reflect.Type clazz,
java.lang.reflect.AnnotatedElement... imports)
Replace the imports of the source file that defines the specified class with
the provided ones.
|
void |
setSuperclass(java.lang.reflect.Type clazz,
java.lang.reflect.Type superclazz,
java.lang.reflect.Type... typeParameters)
Changes the superclass of an existing class, modifying member visibilities
accordingly.
|
IIntercessor createIntercessor()
default void addField(java.lang.reflect.Type clazz, java.lang.reflect.Field... fields) throws StructuralIntercessionException
For example:
Intercessor.addField(Person.class, new jmplib.reflect.Field(String.class, "lastName"));
clazz
- A java.lang.Class or a jmplib.reflect.Classfields
- Set of jmplib.reflect.Field or java.lang.reflect.Field to addStructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)void addField(java.lang.reflect.Type clazz, Field... fields) throws StructuralIntercessionException
StructuralIntercessionException
addField(Type, java.lang.reflect.Field...)
default void replaceField(java.lang.reflect.Type clazz, java.lang.reflect.Field... fields) throws StructuralIntercessionException
For example:
Intercessor.replaceField(Calculator.class, new jmplib.reflect.Field("lastResult", double.class));
clazz
- A java.lang.Class or a jmplib.reflect.Classfields
- Set of jmplib.reflect.Field or java.lang.reflect.Field to replace.
The field name is used to identify the field to replace. The rest
of the information is taken from the Field class.StructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)void replaceField(java.lang.reflect.Type clazz, Field... fields) throws StructuralIntercessionException
default void removeField(java.lang.reflect.Type clazz, java.lang.reflect.Field... fields) throws StructuralIntercessionException
For example:
Intercessor.deleteField(Person.class, new jmplib.reflect.Field("lastName"));
clazz
- A java.lang.Class or a jmplib.reflect.Classfields
- Set of jmplib.reflect.Field or java.lang.reflect.Field to remove.
The field name is used to identify the field to replace.StructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)void removeField(java.lang.reflect.Type clazz, Field... fields) throws StructuralIntercessionException
StructuralIntercessionException
removeField(Type, java.lang.reflect.Field...)
default void addMethod(java.lang.reflect.Type clazz, java.lang.reflect.Method... methods) throws StructuralIntercessionException
For example:
// Declaring MethodType
MethodType mt = MethodType.methodType(int.class, int.class);
// Adding method to Counter
Intercessor.addMethod(Counter.class, new jmplib.reflect.Method("sum", mt,
"return this.counter += value;", "value"));
clazz
- A java.lang.Class or a jmplib.reflect.Classmethods
- Set of jmplib.reflect.Method or java.lang.reflect.Method to add.StructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)void addMethod(java.lang.reflect.Type clazz, Method... methods) throws StructuralIntercessionException
StructuralIntercessionException
addMethod(Type, java.lang.reflect.Method...)
default void replaceMethod(java.lang.reflect.Type clazz, java.lang.reflect.Method method, java.lang.reflect.Method newMethod) throws StructuralIntercessionException
clazz
- A java.lang.Class or a jmplib.reflect.Classmethod
- jmplib.reflect.Method or java.lang.reflect.Method that identifies
the method to be replacednewMethod
- jmplib.reflect.Method or java.lang.reflect.Method that identifies
the new method to replace withStructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)void replaceMethod(java.lang.reflect.Type clazz, Method method, Method newMethod) throws StructuralIntercessionException
void replaceMethod(java.lang.reflect.Type clazz, java.util.Map<Method,Method> methods) throws StructuralIntercessionException
For example, modifying the method to acept a more generic type (Dog -> Animal):
// Creating MethodType
MethodType newType = MethodType.methodType(void.class, Pet.class);
// Modifying the method
Intercessor.replaceMethod(Owner.class, new jmplib.reflect.Method("addPet", newType,
"this.pet = dog;"));
clazz
- A java.lang.Class or a jmplib.reflect.Classmethods
- Set of jmplib.reflect.Method or java.lang.reflect.Method to
replace. The method name and type is used to identify the method
to replace. The rest of the information is taken from the Method
class.StructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)default void replaceImplementation(java.lang.reflect.Type clazz, java.lang.reflect.Method... methods) throws StructuralIntercessionException
For example, modifying the method to use a new field called lastResult:
// Modify a the method code
Intercessor.replaceImplementation(Calculator.class, new jmplib.reflect.Method("sum",
"this.lastResult = a + b;"
+ "return this.lastResult;"));
clazz
- A java.lang.Class or a jmplib.reflect.Classmethods
- Set of jmplib.reflect.Method or java.lang.reflect.Method to
replace its implementation. The method name and type is used to
identify the method to replace. The rest of the information is
taken from the Method class.StructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)void replaceImplementation(java.lang.reflect.Type clazz, Method... methods) throws StructuralIntercessionException
default void removeMethod(java.lang.reflect.Type clazz, java.lang.reflect.Method... methods) throws StructuralIntercessionException
For example:
// Deleting method
Intercessor.deleteMethod(Dog.class, new jmplib.reflect.Method("bark"));
Dog dog = new Dog();
dog.bark(); // Throws RuntimeException
clazz
- A java.lang.Class or a jmplib.reflect.Classmethods
- Set of jmplib.reflect.Method or java.lang.reflect.Method to
remove. The method name and type is used to identify the method to
remove. The rest of the information is taken from the Method
class.StructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)void removeMethod(java.lang.reflect.Type clazz, Method... methods) throws StructuralIntercessionException
void addPublicInterfaceOf(java.lang.reflect.Type origin, java.lang.reflect.Type destination) throws StructuralIntercessionException
origin
- A java.lang.Class or a jmplib.reflect.Classdestination
- A java.lang.Class or a jmplib.reflect.ClassStructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)Class<?> createClassClone(java.lang.String packageName, java.lang.String className, java.lang.reflect.Type origin) throws StructuralIntercessionException
packageName
- Package name of the new class to be createdclassName
- Name of the newly created classorigin
- A java.lang.Class or a jmplib.reflect.ClassStructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)void addInterface(java.lang.reflect.Type clazz, java.lang.reflect.Type interf, java.lang.reflect.Type... typeParameters) throws StructuralIntercessionException
clazz
- A java.lang.Class or a jmplib.reflect.Classinterf
- A java.lang.Class or a jmplib.reflect.Class representing an
interface to addtypeParameters
- Types of the generic parameters of the interface to be added. This
is an optional parameter. However, if specified, it must comply
with the expected type parameter number of the passed interface.
Example:
To add the Comparable interface to the Dog object, the call should be:
Intercessor.addInterface(Dog.class, Comparable.class);
The call will fail if the Dog class do not have a compareTo(Object) method already added.
If we need to add the Comparable
Intercessor.addInterface(Dog.class, Comparable.class, Dog.class);
The call will fail if the Dog class do not have a compareTo(Dog)
method already added.
StructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)void addInterface(java.lang.reflect.Type clazz, java.util.Map<java.lang.reflect.Type,java.lang.reflect.Type[]> interfs) throws StructuralIntercessionException
clazz
- A java.lang.Class or a jmplib.reflect.Classinterfs
- A collection of objects representing interfaces and their type
parametersStructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)void removeInterface(java.lang.reflect.Type clazz, java.lang.reflect.Type interf) throws StructuralIntercessionException
clazz
- A java.lang.Class or a jmplib.reflect.Classinterf
- A java.lang.Class or a jmplib.reflect.Class representing an
interfaceStructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)default void implementInterface(java.lang.reflect.Type clazz, java.lang.reflect.Type interf, java.lang.reflect.Method[] methods, java.lang.Class<?>... typeParameters) throws StructuralIntercessionException
clazz
- A java.lang.Class or a jmplib.reflect.Classinterf
- A java.lang.Class or a jmplib.reflect.Class representing an
interfacemethods
- Method of the interfacetypeParameters
- Types of the generic parameters of the interface to be added. This
is an optional parameter. However, if specified, it must comply
with the expected type parameter number of the passed interface.
Example:
To add the Comparable interface to the Dog object, the call should be:
Intercessor.addInterface(Dog.class, Comparable.class);
The call will fail if the Dog class do not have a compareTo(Object) method already added.
If we need to add the Comparable
Intercessor.addInterface(Dog.class, Comparable.class, Dog.class);
The call will fail if the Dog class do not have a compareTo(Dog)
method already added.
StructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)void implementInterface(java.lang.reflect.Type clazz, java.lang.reflect.Type interf, Method[] methods, java.lang.Class<?>... typeParameters) throws StructuralIntercessionException
void setSuperclass(java.lang.reflect.Type clazz, java.lang.reflect.Type superclazz, java.lang.reflect.Type... typeParameters) throws StructuralIntercessionException
clazz
- A java.lang.Class or a jmplib.reflect.Classsuperclazz
- A java.lang.Class or a jmplib.reflect.ClasstypeParameters
- Type parameters of the new superclassStructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)void removeSuperclass(java.lang.reflect.Type clazz) throws StructuralIntercessionException
clazz
- A java.lang.Class or a jmplib.reflect.ClassStructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)default void addImport(java.lang.reflect.Type clazz, java.lang.Class<?>... imports) throws StructuralIntercessionException
clazz
- A java.lang.Class or a jmplib.reflect.Classimports
- Classes to add as imports to the source file of the classStructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)void addImport(java.lang.reflect.Type clazz, java.lang.Package... imports) throws StructuralIntercessionException
clazz
- A java.lang.Class or a jmplib.reflect.Classimports
- Packages to add as imports to the source file of the classStructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)void addImport(java.lang.reflect.Type clazz, Class<?>... imports) throws StructuralIntercessionException
StructuralIntercessionException
addImport(Type, Class...)
java.lang.reflect.AnnotatedElement[] getImports(java.lang.reflect.Type clazz) throws StructuralIntercessionException
clazz
- A java.lang.Class or a jmplib.reflect.ClassStructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)void setImports(java.lang.reflect.Type clazz, java.lang.reflect.AnnotatedElement... imports) throws StructuralIntercessionException
clazz
- A java.lang.Class or a jmplib.reflect.Classimports
- Modifies the import set of the file that defines the provided classStructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)void addAnnotation(java.lang.reflect.Type clazz, java.lang.reflect.Type... annotations) throws StructuralIntercessionException
clazz
- A java.lang.Class or a jmplib.reflect.Classannotations
- Set of annotations to be used to add to the existing ones.StructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)void setAnnotation(java.lang.reflect.Type clazz, java.lang.reflect.Type... annotations) throws StructuralIntercessionException
clazz
- A java.lang.Class or a jmplib.reflect.Classannotations
- Set of annotations to be used to replace the existing ones.StructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)default void addAnnotation(java.lang.reflect.Method met, java.lang.reflect.Type... annotations) throws StructuralIntercessionException
met
- A java.lang.reflect.Method or a jmplib.reflect.Method instanceannotations
- Set of annotations to be used to add to the existing ones.StructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)void addAnnotation(Method met, java.lang.reflect.Type... annotations) throws StructuralIntercessionException
StructuralIntercessionException
default void setAnnotation(java.lang.reflect.Method met, java.lang.reflect.Type... annotations) throws StructuralIntercessionException
met
- Method to add annotations toannotations
- Set of annotations to be used to replace the existing ones.StructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)void setAnnotation(Method met, java.lang.reflect.Type... annotations) throws StructuralIntercessionException
StructuralIntercessionException
void addGenericType(java.lang.reflect.Type clazz, TypeVariable<?>... types) throws StructuralIntercessionException
clazz
- A java.lang.Class or a jmplib.reflect.Classtypes
- Set of generic types to be used to add to the existing ones.StructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)void setGenericType(java.lang.reflect.Type clazz, TypeVariable<?>... types) throws StructuralIntercessionException
clazz
- A java.lang.Class or a jmplib.reflect.Classtypes
- Set of generic types to be used to replace the existing ones.StructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)default void addGenericType(java.lang.reflect.Method met, TypeVariable<?>... types) throws StructuralIntercessionException
met
- A java.lang.reflect.Method or a jmplib.reflect.Method instancetypes
- Set of annotations to be used to add to the existing ones.StructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)void addGenericType(Method met, TypeVariable<?>... types) throws StructuralIntercessionException
StructuralIntercessionException
default void setGenericType(java.lang.reflect.Method met, TypeVariable<?>... types) throws StructuralIntercessionException
met
- Method to change the generic types totypes
- Set of annotations to be used to replace the existing ones.StructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)void setGenericType(Method met, TypeVariable<?>... types) throws StructuralIntercessionException
StructuralIntercessionException
setGenericType(Method, TypeVariable[])
default void commit() throws StructuralIntercessionException
StructuralIntercessionException
- If problems with the metaprogramming primitives are detected (exception
message indicates the concrete problem, as it wraps the inner exception)