Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finished reoganizing ClassDiscovery system.
The changes include support for ConstructorMirrors now and general support for finding constructors. Additionally, completed changes to AnnotationChecks, to allow for @ForceImplementation on methods now, as well as constructors.
- Loading branch information
1 parent
acae175
commit a94cc98
Showing
17 changed files
with
10,421 additions
and
139 deletions.
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
152 changes: 152 additions & 0 deletions
152
...ain/java/com/laytonsmith/PureUtilities/ClassLoading/ClassMirror/AbstractMethodMirror.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,152 @@ | ||
package com.laytonsmith.PureUtilities.ClassLoading.ClassMirror; | ||
|
||
import com.laytonsmith.PureUtilities.Common.StringUtils; | ||
import java.lang.reflect.Executable; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
* An {@link AbstractMethodMirror} encompasses both methods and constructors. | ||
*/ | ||
public abstract class AbstractMethodMirror extends AbstractElementMirror { | ||
private static final long serialVersionUID = 1L; | ||
|
||
private final List<ClassReferenceMirror> params; | ||
private boolean isVararg = false; | ||
private boolean isSynthetic = false; | ||
|
||
private Executable underlyingMethod = null; | ||
|
||
public AbstractMethodMirror(ClassReferenceMirror parentClass, List<AnnotationMirror> annotations, ModifierMirror modifiers, | ||
ClassReferenceMirror type, String name, List<ClassReferenceMirror> params, boolean isVararg, boolean isSynthetic){ | ||
super(parentClass, annotations, modifiers, type, name); | ||
this.params = params; | ||
this.isVararg = isVararg; | ||
this.isSynthetic = isSynthetic; | ||
} | ||
|
||
public AbstractMethodMirror(Executable method){ | ||
super(method); | ||
this.underlyingMethod = method; | ||
this.params = null; | ||
} | ||
|
||
/* package */ AbstractMethodMirror(ClassReferenceMirror parentClass, ModifierMirror modifiers, ClassReferenceMirror type, | ||
String name, List<ClassReferenceMirror> params, boolean isVararg, boolean isSynthetic){ | ||
super(parentClass, null, modifiers, type, name); | ||
annotations = new ArrayList<>(); | ||
this.params = params; | ||
this.isVararg = isVararg; | ||
this.isSynthetic = isSynthetic; | ||
} | ||
|
||
/** | ||
* Returns a list of params in this method. | ||
* @return | ||
*/ | ||
public List<ClassReferenceMirror> getParams(){ | ||
if(underlyingMethod != null){ | ||
List<ClassReferenceMirror> list = new ArrayList<>(); | ||
for(Class p : underlyingMethod.getParameterTypes()){ | ||
list.add(ClassReferenceMirror.fromClass(p)); | ||
} | ||
return list; | ||
} | ||
return new ArrayList<>(params); | ||
} | ||
|
||
/** | ||
* Returns true if this method is vararg. | ||
* @return | ||
*/ | ||
public boolean isVararg(){ | ||
if(underlyingMethod != null){ | ||
return underlyingMethod.isVarArgs(); | ||
} | ||
return isVararg; | ||
} | ||
|
||
/** | ||
* Returns true if this method is synthetic. | ||
* @return | ||
*/ | ||
public boolean isSynthetic(){ | ||
if(underlyingMethod != null){ | ||
return underlyingMethod.isSynthetic(); | ||
} | ||
return isSynthetic; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
if(underlyingMethod != null){ | ||
return underlyingMethod.toString(); | ||
} | ||
List<String> sParams = new ArrayList<>(); | ||
for(int i = 0; i < params.size(); i++){ | ||
if(i == params.size() - 1 && isVararg){ | ||
sParams.add(params.get(i).getComponentType().toString() + "..."); | ||
} else { | ||
sParams.add(params.get(i).toString()); | ||
} | ||
} | ||
return StringUtils.Join(annotations, "\n") + (annotations.isEmpty()?"":"\n") + (modifiers.toString() | ||
+ " " + type).trim() + " " + name + "(" + StringUtils.Join(sParams, ", ") + "){}"; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if(!(obj instanceof MethodMirror)){ | ||
return false; | ||
} | ||
if(!super.equals(obj)){ | ||
return false; | ||
} | ||
AbstractMethodMirror m = (AbstractMethodMirror)obj; | ||
return | ||
this.params.equals(m.params) | ||
&& this.isVararg == m.isVararg | ||
&& this.isSynthetic == m.isSynthetic; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int hash = 5; | ||
hash = 31 * hash + super.hashCode(); | ||
hash = 31 * hash + Objects.hashCode(this.params); | ||
hash = 31 * hash + (this.isVararg ? 1 : 0); | ||
hash = 31 * hash + (this.isSynthetic ? 1 : 0); | ||
return hash; | ||
} | ||
|
||
/** | ||
* Returns the underlying executable (or null, if it was constructed artificially). | ||
* @return | ||
*/ | ||
protected Executable getExecutable(){ | ||
return underlyingMethod; | ||
} | ||
|
||
/** | ||
* Loads the class that contains this method, using the default class loader. | ||
* @return | ||
* @throws java.lang.ClassNotFoundException | ||
*/ | ||
public Class loadParentClass() throws ClassNotFoundException{ | ||
return loadParentClass(AbstractMethodMirror.class.getClassLoader(), true); | ||
} | ||
|
||
/** | ||
* Loads the class that contains this method, using the default class loader. | ||
* @param loader | ||
* @param initialize | ||
* @return | ||
* @throws java.lang.ClassNotFoundException | ||
*/ | ||
public Class loadParentClass(ClassLoader loader, boolean initialize) throws ClassNotFoundException{ | ||
ClassReferenceMirror p = getDeclaringClass(); | ||
Objects.requireNonNull(p, "Declaring class is null!"); | ||
return p.loadClass(loader, initialize); | ||
} | ||
} |
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
Oops, something went wrong.