public class SimpleIntercessor extends java.lang.Object implements IIntercessor
Constructor and Description |
---|
SimpleIntercessor() |
Modifier and Type | Method and Description |
---|---|
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.
|
void |
addField(java.lang.reflect.Type clazz,
Field... fields) |
void |
addGenericType(Method met,
TypeVariable<?>... types) |
void |
addGenericType(java.lang.reflect.Type clazz,
TypeVariable<?>... types)
Add the provided generic type to the specified class.
|
void |
addImport(java.lang.reflect.Type clazz,
Class<?>... importObjects) |
void |
addImport(java.lang.reflect.Type clazz,
java.lang.Package... importObjects)
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.
|
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
|
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.
|
void |
implementInterface(java.lang.reflect.Type clazz,
java.lang.reflect.Type interf,
Method[] methods,
java.lang.Class<?>... typeParameters) |
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
|
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.
|
void |
replaceField(java.lang.reflect.Type clazz,
Field... fields) |
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;"));
|
void |
replaceMethod(java.lang.reflect.Type clazz,
Method method,
Method newMethod) |
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.
|
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addAnnotation, addField, addGenericType, addImport, addMethod, commit, implementInterface, removeField, removeMethod, replaceField, replaceImplementation, replaceMethod, setAnnotation, setGenericType
public IIntercessor createIntercessor()
createIntercessor
in interface IIntercessor
public void addField(java.lang.reflect.Type clazz, Field... fields) throws StructuralIntercessionException
addField
in interface IIntercessor
StructuralIntercessionException
IIntercessor.addField(Type, java.lang.reflect.Field...)
public void replaceField(java.lang.reflect.Type clazz, Field... fields) throws StructuralIntercessionException
replaceField
in interface IIntercessor
StructuralIntercessionException
IIntercessor.replaceField(Type, java.lang.reflect.Field...)
public void removeField(java.lang.reflect.Type clazz, Field... fields) throws StructuralIntercessionException
removeField
in interface IIntercessor
StructuralIntercessionException
IIntercessor.removeField(Type, java.lang.reflect.Field...)
public void addMethod(java.lang.reflect.Type clazz, Method... methods) throws StructuralIntercessionException
addMethod
in interface IIntercessor
StructuralIntercessionException
IIntercessor.addMethod(Type, java.lang.reflect.Method...)
public void replaceMethod(java.lang.reflect.Type clazz, Method method, Method newMethod) throws StructuralIntercessionException
replaceMethod
in interface IIntercessor
StructuralIntercessionException
IIntercessor.replaceMethod(Type, java.lang.reflect.Method, java.lang.reflect.Method)
public 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;"));
replaceMethod
in interface IIntercessor
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)public void replaceImplementation(java.lang.reflect.Type clazz, Method... methods) throws StructuralIntercessionException
replaceImplementation
in interface IIntercessor
StructuralIntercessionException
IIntercessor.replaceImplementation(Type, java.lang.reflect.Method...)
public void removeMethod(java.lang.reflect.Type clazz, Method... methods) throws StructuralIntercessionException
removeMethod
in interface IIntercessor
StructuralIntercessionException
IIntercessor.removeMethod(Type, java.lang.reflect.Method...)
public void addPublicInterfaceOf(java.lang.reflect.Type origin, java.lang.reflect.Type destination) throws StructuralIntercessionException
addPublicInterfaceOf
in interface IIntercessor
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)public Class<?> createClassClone(java.lang.String packageName, java.lang.String className, java.lang.reflect.Type origin) throws StructuralIntercessionException
createClassClone
in interface IIntercessor
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)public void addInterface(java.lang.reflect.Type clazz, java.lang.reflect.Type interf, java.lang.reflect.Type... typeParameters) throws StructuralIntercessionException
addInterface
in interface IIntercessor
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)public void addInterface(java.lang.reflect.Type clazz, java.util.Map<java.lang.reflect.Type,java.lang.reflect.Type[]> interfs) throws StructuralIntercessionException
addInterface
in interface IIntercessor
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)public void removeInterface(java.lang.reflect.Type clazz, java.lang.reflect.Type interf) throws StructuralIntercessionException
removeInterface
in interface IIntercessor
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)public void implementInterface(java.lang.reflect.Type clazz, java.lang.reflect.Type interf, Method[] methods, java.lang.Class<?>... typeParameters) throws StructuralIntercessionException
implementInterface
in interface IIntercessor
StructuralIntercessionException
IIntercessor.implementInterface(Type, Type, java.lang.reflect.Method[],
Class...)
public void setSuperclass(java.lang.reflect.Type clazz, java.lang.reflect.Type superclazz, java.lang.reflect.Type... typeParameters) throws StructuralIntercessionException
setSuperclass
in interface IIntercessor
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)public void removeSuperclass(java.lang.reflect.Type clazz) throws StructuralIntercessionException
removeSuperclass
in interface IIntercessor
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)public void addImport(java.lang.reflect.Type clazz, Class<?>... importObjects) throws StructuralIntercessionException
addImport
in interface IIntercessor
StructuralIntercessionException
IIntercessor.addImport(Type, Class...)
public void addImport(java.lang.reflect.Type clazz, java.lang.Package... importObjects) throws StructuralIntercessionException
addImport
in interface IIntercessor
clazz
- A java.lang.Class or a jmplib.reflect.ClassimportObjects
- 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)public java.lang.reflect.AnnotatedElement[] getImports(java.lang.reflect.Type clazz) throws StructuralIntercessionException
getImports
in interface IIntercessor
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)public void setImports(java.lang.reflect.Type clazz, java.lang.reflect.AnnotatedElement... imports) throws StructuralIntercessionException
setImports
in interface IIntercessor
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)public void addAnnotation(java.lang.reflect.Type clazz, java.lang.reflect.Type... annotations) throws StructuralIntercessionException
addAnnotation
in interface IIntercessor
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)public void setAnnotation(java.lang.reflect.Type clazz, java.lang.reflect.Type... annotations) throws StructuralIntercessionException
setAnnotation
in interface IIntercessor
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)public void addAnnotation(Method met, java.lang.reflect.Type... annotations) throws StructuralIntercessionException
addAnnotation
in interface IIntercessor
StructuralIntercessionException
public void setAnnotation(Method met, java.lang.reflect.Type... annotations) throws StructuralIntercessionException
setAnnotation
in interface IIntercessor
StructuralIntercessionException
public void addGenericType(java.lang.reflect.Type clazz, TypeVariable<?>... types) throws StructuralIntercessionException
addGenericType
in interface IIntercessor
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)public void setGenericType(java.lang.reflect.Type clazz, TypeVariable<?>... types) throws StructuralIntercessionException
setGenericType
in interface IIntercessor
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)public void addGenericType(Method met, TypeVariable<?>... types) throws StructuralIntercessionException
addGenericType
in interface IIntercessor
StructuralIntercessionException
public void setGenericType(Method met, TypeVariable<?>... types) throws StructuralIntercessionException
setGenericType
in interface IIntercessor
StructuralIntercessionException
IIntercessor.setGenericType(Method, TypeVariable[])