Skip to content

Commit

Permalink
Renamed dispatchers to include the Java version they support.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Jan 21, 2016
1 parent 2bf58a7 commit 8f9e68b
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 100 deletions.
Expand Up @@ -190,7 +190,7 @@ public String toString() {
*
* @param <T> The type of the {@code java.lang.reflect.Executable} that this list represents.
*/
abstract class ForLoadedParameter<T> extends InDefinedShape.AbstractBase {
abstract class ForLoadedParameter<T extends AccessibleObject> extends InDefinedShape.AbstractBase {

/**
* A dispatcher for reading properties from {@code java.lang.reflect.Executable} instances.
Expand All @@ -205,7 +205,7 @@ abstract class ForLoadedParameter<T> extends InDefinedShape.AbstractBase {
try {
Class<?> executableType = Class.forName("java.lang.reflect.Executable");
Class<?> parameterType = Class.forName("java.lang.reflect.Parameter");
dispatcher = new Dispatcher.ForModernVm(executableType.getDeclaredMethod("getParameters"),
dispatcher = new Dispatcher.ForJava8CapableVm(executableType.getDeclaredMethod("getParameters"),
parameterType.getDeclaredMethod("getName"),
parameterType.getDeclaredMethod("isNamePresent"),
parameterType.getDeclaredMethod("getModifiers"));
Expand Down Expand Up @@ -277,7 +277,7 @@ protected interface Dispatcher {
* @param index The parameter's index.
* @return The parameter's modifiers.
*/
int getModifiers(Object executable, int index);
int getModifiers(AccessibleObject executable, int index);

/**
* Returns {@code true} if the given parameter has an explicit name.
Expand All @@ -286,7 +286,7 @@ protected interface Dispatcher {
* @param index The parameter's index.
* @return {@code true} if the given parameter has an explicit name.
*/
boolean isNamePresent(Object executable, int index);
boolean isNamePresent(AccessibleObject executable, int index);

/**
* Returns the given parameter's implicit or explicit name.
Expand All @@ -295,12 +295,12 @@ protected interface Dispatcher {
* @param index The parameter's index.
* @return The parameter's name.
*/
String getName(Object executable, int index);
String getName(AccessibleObject executable, int index);

/**
* A dispatcher for VMs that support the {@code java.lang.reflect.Parameter} API for Java 8+.
*/
class ForModernVm implements Dispatcher {
class ForJava8CapableVm implements Dispatcher {

/**
* A reference to {@code java.lang.reflect.Executable#getParameters}.
Expand Down Expand Up @@ -330,15 +330,15 @@ class ForModernVm implements Dispatcher {
* @param isNamePresent A reference to {@code java.lang.reflect.Parameter#isNamePresent}.
* @param getModifiers A reference to {@code java.lang.reflect.Parameter#getModifiers}.
*/
protected ForModernVm(Method getParameters, Method getName, Method isNamePresent, Method getModifiers) {
protected ForJava8CapableVm(Method getParameters, Method getName, Method isNamePresent, Method getModifiers) {
this.getParameters = getParameters;
this.getName = getName;
this.isNamePresent = isNamePresent;
this.getModifiers = getModifiers;
}

@Override
public int getModifiers(Object executable, int index) {
public int getModifiers(AccessibleObject executable, int index) {
try {
return (Integer) getModifiers.invoke(getParameter(executable, index));
} catch (IllegalAccessException exception) {
Expand All @@ -349,7 +349,7 @@ public int getModifiers(Object executable, int index) {
}

@Override
public boolean isNamePresent(Object executable, int index) {
public boolean isNamePresent(AccessibleObject executable, int index) {
try {
return (Boolean) isNamePresent.invoke(getParameter(executable, index));
} catch (IllegalAccessException exception) {
Expand All @@ -360,7 +360,7 @@ public boolean isNamePresent(Object executable, int index) {
}

@Override
public String getName(Object executable, int index) {
public String getName(AccessibleObject executable, int index) {
try {
return (String) getName.invoke(getParameter(executable, index));
} catch (IllegalAccessException exception) {
Expand Down Expand Up @@ -391,7 +391,7 @@ private Object getParameter(Object executable, int index) {
public boolean equals(Object other) {
if (this == other) return true;
if (other == null || getClass() != other.getClass()) return false;
ForModernVm legal = (ForModernVm) other;
ForJava8CapableVm legal = (ForJava8CapableVm) other;
return getParameters.equals(legal.getParameters)
&& getName.equals(legal.getName)
&& isNamePresent.equals(legal.isNamePresent)
Expand All @@ -409,7 +409,7 @@ public int hashCode() {

@Override
public String toString() {
return "ParameterDescription.ForLoadedParameter.Dispatcher.ForModernVm{" +
return "ParameterDescription.ForLoadedParameter.Dispatcher.ForJava8CapableVm{" +
"getParameters=" + getParameters +
", getName=" + getName +
", isNamePresent=" + isNamePresent +
Expand All @@ -430,17 +430,17 @@ enum ForLegacyVm implements Dispatcher {
INSTANCE;

@Override
public int getModifiers(Object executable, int index) {
public int getModifiers(AccessibleObject executable, int index) {
throw new IllegalStateException("Cannot dispatch method for java.lang.reflect.Parameter");
}

@Override
public boolean isNamePresent(Object executable, int index) {
public boolean isNamePresent(AccessibleObject executable, int index) {
throw new IllegalStateException("Cannot dispatch method for java.lang.reflect.Parameter");
}

@Override
public String getName(Object executable, int index) {
public String getName(AccessibleObject executable, int index) {
throw new IllegalStateException("Cannot dispatch method for java.lang.reflect.Parameter");
}

Expand Down
Expand Up @@ -120,7 +120,7 @@ abstract class ForLoadedExecutable<T> extends AbstractBase<ParameterDescription.
static {
Dispatcher dispatcher;
try {
dispatcher = new Dispatcher.ForModernVm(Class.forName("java.lang.reflect.Executable").getDeclaredMethod("getParameterCount"));
dispatcher = new Dispatcher.ForJava8CapableVm(Class.forName("java.lang.reflect.Executable").getDeclaredMethod("getParameterCount"));
} catch (RuntimeException exception) {
throw exception;
} catch (Exception ignored) {
Expand Down Expand Up @@ -231,7 +231,7 @@ public String toString() {
/**
* A dispatcher for a legacy VM that does support the {@code java.lang.reflect.Parameter} type.
*/
class ForModernVm implements Dispatcher {
class ForJava8CapableVm implements Dispatcher {

/**
* The {@code java.lang.reflect.Executable#getParameterCount()} method.
Expand All @@ -243,7 +243,7 @@ class ForModernVm implements Dispatcher {
*
* @param getParameterCount The {@code java.lang.reflect.Executable#getParameterCount()} method.
*/
protected ForModernVm(Method getParameterCount) {
protected ForJava8CapableVm(Method getParameterCount) {
this.getParameterCount = getParameterCount;
}

Expand Down Expand Up @@ -271,7 +271,7 @@ public ParameterList<ParameterDescription.InDefinedShape> describe(Method method
@Override
public boolean equals(Object other) {
return this == other || !(other == null || getClass() != other.getClass())
&& getParameterCount.equals(((ForModernVm) other).getParameterCount);
&& getParameterCount.equals(((ForJava8CapableVm) other).getParameterCount);
}

@Override
Expand All @@ -281,7 +281,7 @@ public int hashCode() {

@Override
public String toString() {
return "ParameterList.ForLoadedExecutable.Dispatcher.ForModernVm{" +
return "ParameterList.ForLoadedExecutable.Dispatcher.ForJava8CapableVm{" +
"getParameterCount=" + getParameterCount +
'}';
}
Expand Down

0 comments on commit 8f9e68b

Please sign in to comment.