Skip to content

Commit

Permalink
Renamed JavaInstance to JavaConstant to prepare better naming distinc…
Browse files Browse the repository at this point in the history
…tion in Jigsaw support.
  • Loading branch information
raphw committed May 31, 2016
1 parent 4a3d624 commit 8167d16
Show file tree
Hide file tree
Showing 21 changed files with 222 additions and 223 deletions.
Expand Up @@ -34,7 +34,7 @@
import net.bytebuddy.implementation.bytecode.member.MethodVariableAccess; import net.bytebuddy.implementation.bytecode.member.MethodVariableAccess;
import net.bytebuddy.matcher.ElementMatcher; import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.pool.TypePool; import net.bytebuddy.pool.TypePool;
import net.bytebuddy.utility.JavaInstance; import net.bytebuddy.utility.JavaConstant;
import org.objectweb.asm.Label; import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
Expand Down Expand Up @@ -2628,11 +2628,11 @@ public byte[] make(Object targetTypeLookup,
List<Class<?>> markerInterfaces, List<Class<?>> markerInterfaces,
List<?> additionalBridges, List<?> additionalBridges,
Collection<? extends ClassFileTransformer> classFileTransformers) { Collection<? extends ClassFileTransformer> classFileTransformers) {
JavaInstance.MethodType factoryMethod = JavaInstance.MethodType.ofLoaded(factoryMethodType); JavaConstant.MethodType factoryMethod = JavaConstant.MethodType.ofLoaded(factoryMethodType);
JavaInstance.MethodType lambdaMethod = JavaInstance.MethodType.ofLoaded(lambdaMethodType); JavaConstant.MethodType lambdaMethod = JavaConstant.MethodType.ofLoaded(lambdaMethodType);
JavaInstance.MethodHandle targetMethod = JavaInstance.MethodHandle.ofLoaded(targetMethodHandle, targetTypeLookup); JavaConstant.MethodHandle targetMethod = JavaConstant.MethodHandle.ofLoaded(targetMethodHandle, targetTypeLookup);
JavaInstance.MethodType specializedLambdaMethod = JavaInstance.MethodType.ofLoaded(specializedLambdaMethodType); JavaConstant.MethodType specializedLambdaMethod = JavaConstant.MethodType.ofLoaded(specializedLambdaMethodType);
Class<?> targetType = JavaInstance.MethodHandle.lookupType(targetTypeLookup); Class<?> targetType = JavaConstant.MethodHandle.lookupType(targetTypeLookup);
String lambdaClassName = targetType.getName() + LAMBDA_TYPE_INFIX + LAMBDA_NAME_COUNTER.incrementAndGet(); String lambdaClassName = targetType.getName() + LAMBDA_TYPE_INFIX + LAMBDA_NAME_COUNTER.incrementAndGet();
DynamicType.Builder<?> builder = byteBuddy DynamicType.Builder<?> builder = byteBuddy
.subclass(factoryMethod.getReturnType(), ConstructorStrategy.Default.NO_CONSTRUCTORS) .subclass(factoryMethod.getReturnType(), ConstructorStrategy.Default.NO_CONSTRUCTORS)
Expand Down Expand Up @@ -2665,7 +2665,7 @@ public byte[] make(Object targetTypeLookup,
lambdaMethodName, lambdaMethodName,
lambdaMethod, lambdaMethod,
targetMethod, targetMethod,
JavaInstance.MethodType.ofLoaded(specializedLambdaMethodType))); JavaConstant.MethodType.ofLoaded(specializedLambdaMethodType)));
} else if (factoryMethod.getReturnType().isAssignableTo(Serializable.class)) { } else if (factoryMethod.getReturnType().isAssignableTo(Serializable.class)) {
builder = builder.defineMethod("readObject", void.class, Visibility.PRIVATE) builder = builder.defineMethod("readObject", void.class, Visibility.PRIVATE)
.withParameters(ObjectInputStream.class) .withParameters(ObjectInputStream.class)
Expand All @@ -2677,7 +2677,7 @@ public byte[] make(Object targetTypeLookup,
.intercept(ExceptionMethod.throwing(NotSerializableException.class, "Non-serializable lambda")); .intercept(ExceptionMethod.throwing(NotSerializableException.class, "Non-serializable lambda"));
} }
for (Object additionalBridgeType : additionalBridges) { for (Object additionalBridgeType : additionalBridges) {
JavaInstance.MethodType additionalBridge = JavaInstance.MethodType.ofLoaded(additionalBridgeType); JavaConstant.MethodType additionalBridge = JavaConstant.MethodType.ofLoaded(additionalBridgeType);
builder = builder.defineMethod(lambdaMethodName, additionalBridge.getReturnType(), MethodManifestation.BRIDGE, Visibility.PUBLIC) builder = builder.defineMethod(lambdaMethodName, additionalBridge.getReturnType(), MethodManifestation.BRIDGE, Visibility.PUBLIC)
.withParameters(additionalBridge.getParameterTypes()) .withParameters(additionalBridge.getParameterTypes())
.intercept(new BridgeMethodImplementation(lambdaMethodName, lambdaMethod)); .intercept(new BridgeMethodImplementation(lambdaMethodName, lambdaMethod));
Expand Down Expand Up @@ -2894,20 +2894,20 @@ protected static class LambdaMethodImplementation implements Implementation {
/** /**
* The handle of the target method of the lambda expression. * The handle of the target method of the lambda expression.
*/ */
private final JavaInstance.MethodHandle targetMethod; private final JavaConstant.MethodHandle targetMethod;


/** /**
* The specialized type of the lambda method. * The specialized type of the lambda method.
*/ */
private final JavaInstance.MethodType specializedLambdaMethod; private final JavaConstant.MethodType specializedLambdaMethod;


/** /**
* Creates a implementation of a lambda expression's functional method. * Creates a implementation of a lambda expression's functional method.
* *
* @param targetMethod The target method of the lambda expression. * @param targetMethod The target method of the lambda expression.
* @param specializedLambdaMethod The specialized type of the lambda method. * @param specializedLambdaMethod The specialized type of the lambda method.
*/ */
protected LambdaMethodImplementation(JavaInstance.MethodHandle targetMethod, JavaInstance.MethodType specializedLambdaMethod) { protected LambdaMethodImplementation(JavaConstant.MethodHandle targetMethod, JavaConstant.MethodType specializedLambdaMethod) {
this.targetMethod = targetMethod; this.targetMethod = targetMethod;
this.specializedLambdaMethod = specializedLambdaMethod; this.specializedLambdaMethod = specializedLambdaMethod;
} }
Expand Down Expand Up @@ -2966,7 +2966,7 @@ protected static class Appender implements ByteCodeAppender {
/** /**
* The specialized type of the lambda method. * The specialized type of the lambda method.
*/ */
private final JavaInstance.MethodType specializedLambdaMethod; private final JavaConstant.MethodType specializedLambdaMethod;


/** /**
* The instrumented type's declared fields. * The instrumented type's declared fields.
Expand All @@ -2981,7 +2981,7 @@ protected static class Appender implements ByteCodeAppender {
* @param declaredFields The instrumented type's declared fields. * @param declaredFields The instrumented type's declared fields.
*/ */
protected Appender(MethodDescription targetMethod, protected Appender(MethodDescription targetMethod,
JavaInstance.MethodType specializedLambdaMethod, JavaConstant.MethodType specializedLambdaMethod,
List<FieldDescription.InDefinedShape> declaredFields) { List<FieldDescription.InDefinedShape> declaredFields) {
this.targetMethod = targetMethod; this.targetMethod = targetMethod;
this.specializedLambdaMethod = specializedLambdaMethod; this.specializedLambdaMethod = specializedLambdaMethod;
Expand Down Expand Up @@ -3062,17 +3062,17 @@ protected static class SerializationImplementation implements Implementation {
/** /**
* The method type of the lambda expression's functional method. * The method type of the lambda expression's functional method.
*/ */
private final JavaInstance.MethodType lambdaMethod; private final JavaConstant.MethodType lambdaMethod;


/** /**
* A handle that references the lambda expressions invocation target. * A handle that references the lambda expressions invocation target.
*/ */
private final JavaInstance.MethodHandle targetMethod; private final JavaConstant.MethodHandle targetMethod;


/** /**
* The specialized method type of the lambda expression's functional method. * The specialized method type of the lambda expression's functional method.
*/ */
private final JavaInstance.MethodType specializedMethod; private final JavaConstant.MethodType specializedMethod;


/** /**
* Creates a new implementation for a serializable's lambda expression's {@code writeReplace} method. * Creates a new implementation for a serializable's lambda expression's {@code writeReplace} method.
Expand All @@ -3087,9 +3087,9 @@ protected static class SerializationImplementation implements Implementation {
protected SerializationImplementation(TypeDescription targetType, protected SerializationImplementation(TypeDescription targetType,
TypeDescription lambdaType, TypeDescription lambdaType,
String lambdaMethodName, String lambdaMethodName,
JavaInstance.MethodType lambdaMethod, JavaConstant.MethodType lambdaMethod,
JavaInstance.MethodHandle targetMethod, JavaConstant.MethodHandle targetMethod,
JavaInstance.MethodType specializedMethod) { JavaConstant.MethodType specializedMethod) {
this.targetType = targetType; this.targetType = targetType;
this.lambdaType = lambdaType; this.lambdaType = lambdaType;
this.lambdaMethodName = lambdaMethodName; this.lambdaMethodName = lambdaMethodName;
Expand Down Expand Up @@ -3185,15 +3185,15 @@ protected static class BridgeMethodImplementation implements Implementation {
/** /**
* The actual type of the lambda expression's functional method. * The actual type of the lambda expression's functional method.
*/ */
private final JavaInstance.MethodType lambdaMethod; private final JavaConstant.MethodType lambdaMethod;


/** /**
* Creates a new bridge method implementation for a lambda expression. * Creates a new bridge method implementation for a lambda expression.
* *
* @param lambdaMethodName The name of the lambda expression's functional method. * @param lambdaMethodName The name of the lambda expression's functional method.
* @param lambdaMethod The actual type of the lambda expression's functional method. * @param lambdaMethod The actual type of the lambda expression's functional method.
*/ */
protected BridgeMethodImplementation(String lambdaMethodName, JavaInstance.MethodType lambdaMethod) { protected BridgeMethodImplementation(String lambdaMethodName, JavaConstant.MethodType lambdaMethod) {
this.lambdaMethodName = lambdaMethodName; this.lambdaMethodName = lambdaMethodName;
this.lambdaMethod = lambdaMethod; this.lambdaMethod = lambdaMethod;
} }
Expand Down
Expand Up @@ -11,7 +11,7 @@
import net.bytebuddy.description.type.TypeList; import net.bytebuddy.description.type.TypeList;
import net.bytebuddy.description.type.TypeVariableToken; import net.bytebuddy.description.type.TypeVariableToken;
import net.bytebuddy.matcher.ElementMatcher; import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.utility.JavaInstance; import net.bytebuddy.utility.JavaConstant;
import net.bytebuddy.utility.JavaType; import net.bytebuddy.utility.JavaType;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type; import org.objectweb.asm.Type;
Expand Down Expand Up @@ -219,8 +219,8 @@ public interface MethodDescription extends TypeVariableSource,
* *
* @param arguments The arguments that the bootstrap method is expected to accept where primitive values * @param arguments The arguments that the bootstrap method is expected to accept where primitive values
* are to be represented as their wrapper types, loaded types by {@link TypeDescription}, * are to be represented as their wrapper types, loaded types by {@link TypeDescription},
* method handles by {@link net.bytebuddy.utility.JavaInstance.MethodHandle} instances and * method handles by {@link JavaConstant.MethodHandle} instances and
* method types by {@link net.bytebuddy.utility.JavaInstance.MethodType} instances. * method types by {@link JavaConstant.MethodType} instances.
* @return {@code true} if the method is a bootstrap method that accepts the given arguments. * @return {@code true} if the method is a bootstrap method that accepts the given arguments.
*/ */
boolean isBootstrap(List<?> arguments); boolean isBootstrap(List<?> arguments);
Expand Down Expand Up @@ -536,8 +536,8 @@ public boolean isBootstrap(List<?> arguments) {
|| argumentType == Float.class || argumentType == Float.class
|| argumentType == Double.class || argumentType == Double.class
|| TypeDescription.class.isAssignableFrom(argumentType) || TypeDescription.class.isAssignableFrom(argumentType)
|| JavaInstance.MethodHandle.class.isAssignableFrom(argumentType) || JavaConstant.MethodHandle.class.isAssignableFrom(argumentType)
|| JavaInstance.MethodType.class.isAssignableFrom(argumentType))) { || JavaConstant.MethodType.class.isAssignableFrom(argumentType))) {
throw new IllegalArgumentException("Not a bootstrap argument: " + argument); throw new IllegalArgumentException("Not a bootstrap argument: " + argument);
} }
} }
Expand All @@ -558,8 +558,8 @@ public boolean isBootstrap(List<?> arguments) {
&& !(parameterType.represents(float.class) && argumentType == Float.class) && !(parameterType.represents(float.class) && argumentType == Float.class)
&& !(parameterType.represents(double.class) && argumentType == Double.class) && !(parameterType.represents(double.class) && argumentType == Double.class)
&& !(parameterType.represents(Class.class) && TypeDescription.class.isAssignableFrom(argumentType)) && !(parameterType.represents(Class.class) && TypeDescription.class.isAssignableFrom(argumentType))
&& !(parameterType.isAssignableFrom(JavaType.METHOD_HANDLE.getTypeStub()) && JavaInstance.MethodHandle.class.isAssignableFrom(argumentType)) && !(parameterType.isAssignableFrom(JavaType.METHOD_HANDLE.getTypeStub()) && JavaConstant.MethodHandle.class.isAssignableFrom(argumentType))
&& !(parameterType.equals(JavaType.METHOD_TYPE.getTypeStub()) && JavaInstance.MethodType.class.isAssignableFrom(argumentType)); && !(parameterType.equals(JavaType.METHOD_TYPE.getTypeStub()) && JavaConstant.MethodType.class.isAssignableFrom(argumentType));
} }
if (finalParameterCheck) { if (finalParameterCheck) {
return index == parameterTypes.size() && parameterType.represents(Object[].class); return index == parameterTypes.size() && parameterType.represents(Object[].class);
Expand Down
Expand Up @@ -10,7 +10,7 @@
import net.bytebuddy.implementation.bytecode.constant.*; import net.bytebuddy.implementation.bytecode.constant.*;
import net.bytebuddy.implementation.bytecode.member.FieldAccess; import net.bytebuddy.implementation.bytecode.member.FieldAccess;
import net.bytebuddy.implementation.bytecode.member.MethodReturn; import net.bytebuddy.implementation.bytecode.member.MethodReturn;
import net.bytebuddy.utility.JavaInstance; import net.bytebuddy.utility.JavaConstant;
import net.bytebuddy.utility.JavaType; import net.bytebuddy.utility.JavaType;
import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
Expand Down Expand Up @@ -118,12 +118,12 @@ public static AssignerConfigurable value(Object fixedValue) {
Assigner.DEFAULT, Assigner.DEFAULT,
Assigner.Typing.STATIC); Assigner.Typing.STATIC);
} else if (JavaType.METHOD_HANDLE.getTypeStub().isAssignableFrom(type)) { } else if (JavaType.METHOD_HANDLE.getTypeStub().isAssignableFrom(type)) {
return new ForPoolValue(new JavaInstanceConstant(JavaInstance.MethodHandle.ofLoaded(fixedValue)), return new ForPoolValue(new JavaConstantValue(JavaConstant.MethodHandle.ofLoaded(fixedValue)),
new TypeDescription.ForLoadedType(type), new TypeDescription.ForLoadedType(type),
Assigner.DEFAULT, Assigner.DEFAULT,
Assigner.Typing.STATIC); Assigner.Typing.STATIC);
} else if (JavaType.METHOD_TYPE.getTypeStub().represents(type)) { } else if (JavaType.METHOD_TYPE.getTypeStub().represents(type)) {
return new ForPoolValue(new JavaInstanceConstant(JavaInstance.MethodType.ofLoaded(fixedValue)), return new ForPoolValue(new JavaConstantValue(JavaConstant.MethodType.ofLoaded(fixedValue)),
new TypeDescription.ForLoadedType(type), new TypeDescription.ForLoadedType(type),
Assigner.DEFAULT, Assigner.DEFAULT,
Assigner.Typing.STATIC); Assigner.Typing.STATIC);
Expand Down Expand Up @@ -174,12 +174,12 @@ public static AssignerConfigurable value(TypeDescription fixedValue) {
} }


/** /**
* Returns the loaded version of the given {@link JavaInstance}. The value is loaded from the written class's constant pool. * Returns the loaded version of the given {@link JavaConstant}. The value is loaded from the written class's constant pool.
* *
* @param fixedValue The type to return from the method. * @param fixedValue The type to return from the method.
* @return An implementation for the given {@code fixedValue}. * @return An implementation for the given {@code fixedValue}.
*/ */
public static AssignerConfigurable value(JavaInstance fixedValue) { public static AssignerConfigurable value(JavaConstant fixedValue) {
return new ForPoolValue(fixedValue.asStackManipulation(), return new ForPoolValue(fixedValue.asStackManipulation(),
fixedValue.getInstanceType(), fixedValue.getInstanceType(),
Assigner.DEFAULT, Assigner.DEFAULT,
Expand Down

0 comments on commit 8167d16

Please sign in to comment.