Skip to content

Commit

Permalink
Renamed last byte code primitives and refactored to APIs that accept …
Browse files Browse the repository at this point in the history
…type definitions rather than type descriptions.
  • Loading branch information
raphw committed Nov 19, 2016
1 parent 34c6005 commit 146344f
Show file tree
Hide file tree
Showing 26 changed files with 62 additions and 69 deletions.
Expand Up @@ -5042,7 +5042,7 @@ public Size apply(MethodVisitor methodVisitor, Context implementationContext, Me
new StackManipulation.Compound(fieldAccess),
new StackManipulation.Compound(parameterAccess),
MethodInvocation.invoke(targetMethod),
MethodReturn.of(targetMethod.getReturnType().asErasure())
MethodReturn.of(targetMethod.getReturnType())
).apply(methodVisitor, implementationContext).getMaximalSize(), instrumentedMethod.getStackSize());
}

Expand Down Expand Up @@ -5297,8 +5297,8 @@ public Size apply(MethodVisitor methodVisitor, Context implementationContext, Me
bridgeTargetInvocation,
bridgeTargetInvocation.getMethodDescription().getReturnType().asErasure().isAssignableTo(instrumentedMethod.getReturnType().asErasure())
? StackManipulation.Trivial.INSTANCE
: TypeCasting.to(instrumentedMethod.getReceiverType().asErasure()),
MethodReturn.of(instrumentedMethod.getReturnType().asErasure())
: TypeCasting.to(instrumentedMethod.getReceiverType()),
MethodReturn.of(instrumentedMethod.getReturnType())

)).apply(methodVisitor, implementationContext, instrumentedMethod);
}
Expand Down
4 changes: 2 additions & 2 deletions byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java
Expand Up @@ -220,7 +220,7 @@ public class Advice implements AsmVisitorWrapper.ForDeclaredMethods.MethodVisito
* @param methodExit The dispatcher for instrumenting the instrumented method upon exiting.
*/
protected Advice(Dispatcher.Resolved.ForMethodEnter methodEnter, Dispatcher.Resolved.ForMethodExit methodExit) {
this(methodEnter, methodExit, Assigner.DEFAULT, Removal.pop(TypeDescription.THROWABLE), SuperMethodCall.INSTANCE);
this(methodEnter, methodExit, Assigner.DEFAULT, Removal.of(TypeDescription.THROWABLE), SuperMethodCall.INSTANCE);
}

/**
Expand Down Expand Up @@ -1918,7 +1918,7 @@ protected ReadWrite(TypeDefinition typeDefinition, StackManipulation readAssignm

@Override
public StackManipulation resolveWrite() {
return Removal.pop(typeDefinition);
return Removal.of(typeDefinition);
}

@Override
Expand Down
Expand Up @@ -945,7 +945,7 @@ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementa
return new ByteCodeAppender.Simple(
MethodVariableAccess.allArgumentsOf(instrumentedMethod).prependThisReference(),
MethodInvocation.invoke(bridgeTarget).special(superClass),
MethodReturn.of(instrumentedMethod.getReturnType().asErasure())
MethodReturn.of(instrumentedMethod.getReturnType())
).apply(methodVisitor, implementationContext, instrumentedMethod);
}

Expand Down Expand Up @@ -1173,7 +1173,7 @@ public void apply(ClassVisitor classVisitor,
bridgeTarget.getReturnType().asErasure().isAssignableTo(bridgeMethod.getReturnType().asErasure())
? StackManipulation.Trivial.INSTANCE
: TypeCasting.to(bridgeMethod.getReturnType().asErasure()),
MethodReturn.of(bridgeMethod.getReturnType().asErasure())
MethodReturn.of(bridgeMethod.getReturnType())
).apply(methodVisitor, implementationContext, bridgeMethod);
methodVisitor.visitMaxs(size.getOperandStackSize(), size.getLocalVariableSize());
methodVisitor.visitEnd();
Expand Down
Expand Up @@ -210,7 +210,7 @@ public Size apply(MethodVisitor methodVisitor, Context implementationContext, Me
StackManipulation.Size stackSize = new StackManipulation.Compound(
MethodVariableAccess.allArgumentsOf(instrumentedMethod).prependThisReference(),
defaultMethodInvocation,
MethodReturn.of(instrumentedMethod.getReturnType().asErasure())
MethodReturn.of(instrumentedMethod.getReturnType())
).apply(methodVisitor, implementationContext);
return new Size(stackSize.getMaximalSize(), instrumentedMethod.getStackSize());
}
Expand Down
Expand Up @@ -125,7 +125,7 @@ protected StackManipulation setter(FieldDescription fieldDescription, ParameterD
}
return access(fieldDescription,
parameterDescription.getDeclaringMethod(),
new StackManipulation.Compound(MethodVariableAccess.of(fieldDescription.getType().asErasure()).loadFrom(parameterDescription.getOffset()),
new StackManipulation.Compound(MethodVariableAccess.of(fieldDescription.getType()).loadFrom(parameterDescription.getOffset()),
assigner.assign(parameterDescription.getType(), fieldDescription.getType(), typing),
FieldAccess.forField(fieldDescription).write()));
}
Expand Down
Expand Up @@ -212,7 +212,7 @@ protected ByteCodeAppender.Size apply(MethodVisitor methodVisitor,
StackManipulation.Size stackSize = new StackManipulation.Compound(
valueLoadingInstruction,
assignment,
MethodReturn.of(instrumentedMethod.getReturnType().asErasure())
MethodReturn.of(instrumentedMethod.getReturnType())
).apply(methodVisitor, implementationContext);
return new ByteCodeAppender.Size(stackSize.getMaximalSize(), instrumentedMethod.getStackSize());
}
Expand Down
Expand Up @@ -330,7 +330,7 @@ protected enum TerminationHandler {
DROPPING {
@Override
protected StackManipulation resolve(TypeDefinition returnType) {
return Removal.pop(returnType);
return Removal.of(returnType);
}
},

Expand Down
Expand Up @@ -1467,7 +1467,7 @@ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementa
StackManipulation.Size stackSize = new StackManipulation.Compound(
MethodVariableAccess.allArgumentsOf(instrumentedMethod).prependThisReference(),
accessorMethodInvocation,
MethodReturn.of(instrumentedMethod.getReturnType().asErasure())
MethodReturn.of(instrumentedMethod.getReturnType())
).apply(methodVisitor, implementationContext);
return new Size(stackSize.getMaximalSize(), instrumentedMethod.getStackSize());
}
Expand Down Expand Up @@ -1521,7 +1521,7 @@ public Size apply(MethodVisitor methodVisitor, Context implementationContext, Me
? StackManipulation.Trivial.INSTANCE
: MethodVariableAccess.REFERENCE.loadFrom(0),
FieldAccess.forField(fieldDescription).read(),
MethodReturn.of(fieldDescription.getType().asErasure())
MethodReturn.of(fieldDescription.getType())
).apply(methodVisitor, implementationContext);
return new Size(stackSize.getMaximalSize(), instrumentedMethod.getStackSize());
}
Expand Down
Expand Up @@ -184,7 +184,7 @@ protected ByteCodeAppender.Size apply(MethodVisitor methodVisitor,
ArrayFactory.forType(TypeDescription.Generic.OBJECT).withValues(argumentValuesOf(instrumentedMethod)),
MethodInvocation.invoke(INVOCATION_HANDLER_TYPE.getDeclaredMethods().getOnly()),
assigner.assign(TypeDescription.Generic.OBJECT, instrumentedMethod.getReturnType(), Assigner.Typing.DYNAMIC),
MethodReturn.of(instrumentedMethod.getReturnType().asErasure())
MethodReturn.of(instrumentedMethod.getReturnType())
).apply(methodVisitor, implementationContext);
return new ByteCodeAppender.Size(stackSize.getMaximalSize(), instrumentedMethod.getStackSize());
}
Expand Down
Expand Up @@ -1788,7 +1788,7 @@ public Resolved resolve(TypeDescription instrumentedType, MethodDescription inst
if (index >= parameters.size()) {
throw new IllegalStateException("No parameter " + index + " for " + instrumentedMethod);
}
return doResolve(MethodVariableAccess.of(parameters.get(index).getType().asErasure()).loadFrom(parameters.get(index).getOffset()),
return doResolve(MethodVariableAccess.of(parameters.get(index).getType()).loadFrom(parameters.get(index).getOffset()),
parameters.get(index).getType(),
assigner,
typing);
Expand Down Expand Up @@ -2908,7 +2908,7 @@ protected StackManipulation resolve(MethodDescription interceptedMethod, TypeDes
if (!stackManipulation.isValid()) {
throw new IllegalStateException("Cannot return " + returnType + " from " + interceptedMethod);
}
return new StackManipulation.Compound(stackManipulation, MethodReturn.of(interceptedMethod.getReturnType().asErasure()));
return new StackManipulation.Compound(stackManipulation, MethodReturn.of(interceptedMethod.getReturnType()));
}
},

Expand All @@ -2918,9 +2918,9 @@ protected StackManipulation resolve(MethodDescription interceptedMethod, TypeDes
DROPPING {
@Override
protected StackManipulation resolve(MethodDescription interceptedMethod, TypeDescription returnType, Assigner assigner, Assigner.Typing typing) {
return Removal.pop(interceptedMethod.isConstructor()
? interceptedMethod.getDeclaringType().asErasure()
: interceptedMethod.getReturnType().asErasure());
return Removal.of(interceptedMethod.isConstructor()
? interceptedMethod.getDeclaringType()
: interceptedMethod.getReturnType());
}
};

Expand Down
Expand Up @@ -1253,7 +1253,7 @@ protected ForMethodParameter(int index, MethodDescription instrumentedMethod) {
public StackManipulation resolve(ParameterDescription target, Assigner assigner, Assigner.Typing typing) {
ParameterDescription parameterDescription = instrumentedMethod.getParameters().get(index);
StackManipulation stackManipulation = new StackManipulation.Compound(
MethodVariableAccess.of(parameterDescription.getType().asErasure()).loadFrom(parameterDescription.getOffset()),
MethodVariableAccess.of(parameterDescription.getType()).loadFrom(parameterDescription.getOffset()),
assigner.assign(parameterDescription.getType(), target.getType(), typing));
if (!stackManipulation.isValid()) {
throw new IllegalStateException("Cannot assign " + parameterDescription + " to " + target + " for " + instrumentedMethod);
Expand Down Expand Up @@ -2559,8 +2559,7 @@ public StackManipulation resolve(MethodDescription invokedMethod, MethodDescript
if (!stackManipulation.isValid()) {
throw new IllegalStateException("Cannot return " + invokedMethod.getReturnType() + " from " + instrumentedMethod);
}
return new StackManipulation.Compound(stackManipulation,
MethodReturn.of(instrumentedMethod.getReturnType().asErasure()));
return new StackManipulation.Compound(stackManipulation, MethodReturn.of(instrumentedMethod.getReturnType()));
}
},

Expand All @@ -2570,9 +2569,9 @@ public StackManipulation resolve(MethodDescription invokedMethod, MethodDescript
DROPPING {
@Override
protected StackManipulation resolve(MethodDescription invokedMethod, MethodDescription instrumentedMethod, Assigner assigner, Assigner.Typing typing) {
return Removal.pop(invokedMethod.isConstructor()
? invokedMethod.getDeclaringType().asErasure()
: invokedMethod.getReturnType().asErasure());
return Removal.of(invokedMethod.isConstructor()
? invokedMethod.getDeclaringType()
: invokedMethod.getReturnType());
}
};

Expand Down
Expand Up @@ -41,8 +41,8 @@ public Size apply(MethodVisitor methodVisitor,
Context implementationContext,
MethodDescription instrumentedMethod) {
StackManipulation.Size stackSize = new StackManipulation.Compound(
DefaultValue.of(instrumentedMethod.getReturnType().asErasure()),
MethodReturn.of(instrumentedMethod.getReturnType().asErasure())
DefaultValue.of(instrumentedMethod.getReturnType()),
MethodReturn.of(instrumentedMethod.getReturnType())
).apply(methodVisitor, implementationContext);
return new Size(stackSize.getMaximalSize(), instrumentedMethod.getStackSize());
}
Expand Down
Expand Up @@ -143,7 +143,7 @@ protected enum TerminationHandler {
RETURNING {
@Override
protected StackManipulation of(MethodDescription methodDescription) {
return MethodReturn.of(methodDescription.getReturnType().asErasure());
return MethodReturn.of(methodDescription.getReturnType());
}
},

Expand All @@ -153,7 +153,7 @@ protected StackManipulation of(MethodDescription methodDescription) {
DROPPING {
@Override
protected StackManipulation of(MethodDescription methodDescription) {
return Removal.pop(methodDescription.getReturnType().asErasure());
return Removal.of(methodDescription.getReturnType());
}
};

Expand Down
Expand Up @@ -304,8 +304,7 @@ public Size apply(MethodVisitor methodVisitor, Context implementationContext, Me
for (FieldDescription fieldDescription : fieldList) {
fieldLoading[index] = new StackManipulation.Compound(
thisReference,
MethodVariableAccess.of(fieldDescription.getType().asErasure())
.loadFrom(instrumentedMethod.getParameters().get(index).getOffset()),
MethodVariableAccess.of(fieldDescription.getType()).loadFrom(instrumentedMethod.getParameters().get(index).getOffset()),
FieldAccess.forField(fieldDescription).write()
);
index++;
Expand Down Expand Up @@ -427,7 +426,7 @@ public Size apply(MethodVisitor methodVisitor,
new StackManipulation.Compound(fieldLoading),
MethodInvocation.invoke(accessorMethod),
assigner.assign(accessorMethod.getReturnType(), instrumentedMethod.getReturnType(), Assigner.Typing.DYNAMIC),
MethodReturn.of(instrumentedMethod.getReturnType().asErasure())
MethodReturn.of(instrumentedMethod.getReturnType())
).apply(methodVisitor, implementationContext);
return new Size(stackSize.getMaximalSize(), instrumentedMethod.getStackSize());
}
Expand Down
Expand Up @@ -867,7 +867,7 @@ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementa
fieldLoadingInstruction,
MethodVariableAccess.allArgumentsOf(instrumentedMethod).asBridgeOf(proxyMethod),
MethodInvocation.invoke(proxyMethod),
MethodReturn.of(instrumentedMethod.getReturnType().asErasure())
MethodReturn.of(instrumentedMethod.getReturnType())
).apply(methodVisitor, implementationContext);
}

Expand Down
Expand Up @@ -422,8 +422,7 @@ public Size apply(MethodVisitor methodVisitor, Context implementationContext, Me
for (FieldDescription fieldDescription : fieldList) {
fieldLoading[index] = new StackManipulation.Compound(
thisReference,
MethodVariableAccess.of(fieldDescription.getType().asErasure())
.loadFrom(instrumentedMethod.getParameters().get(index).getOffset()),
MethodVariableAccess.of(fieldDescription.getType()).loadFrom(instrumentedMethod.getParameters().get(index).getOffset()),
FieldAccess.forField(fieldDescription).write()
);
index++;
Expand Down
Expand Up @@ -551,7 +551,7 @@ protected StackManipulation resolve(Assigner assigner, MethodDescription source,
? target.getDeclaringType().asGenericType()
: target.getReturnType(),
source.getReturnType(),
RuntimeType.Verifier.check(target)), MethodReturn.of(source.getReturnType().asErasure()));
RuntimeType.Verifier.check(target)), MethodReturn.of(source.getReturnType()));
}
},

Expand All @@ -561,9 +561,9 @@ protected StackManipulation resolve(Assigner assigner, MethodDescription source,
DROPPING {
@Override
protected StackManipulation resolve(Assigner assigner, MethodDescription source, MethodDescription target) {
return Removal.pop(target.isConstructor()
? target.getDeclaringType().asErasure()
: target.getReturnType().asErasure());
return Removal.of(target.isConstructor()
? target.getDeclaringType()
: target.getReturnType());
}
};

Expand Down
Expand Up @@ -86,7 +86,7 @@ public StackManipulation flipOver(TypeDefinition typeDefinition) {
* @param typeDefinition The type to be duplicated.
* @return A stack manipulation that duplicates the given type.
*/
public static Duplication duplicate(TypeDefinition typeDefinition) {
public static Duplication of(TypeDefinition typeDefinition) {
switch (typeDefinition.getStackSize()) {
case SINGLE:
return SINGLE;
Expand Down
Expand Up @@ -57,7 +57,7 @@ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementa
* @param typeDefinition The type to remove from the stack.
* @return A stack manipulation that represents the removal.
*/
public static StackManipulation pop(TypeDefinition typeDefinition) {
public static StackManipulation of(TypeDefinition typeDefinition) {
switch (typeDefinition.getStackSize()) {
case SINGLE:
return SINGLE;
Expand Down
Expand Up @@ -43,7 +43,7 @@ public StackManipulation assign(TypeDescription.Generic source, TypeDescription.
? DefaultValue.of(target)
: StackManipulation.Illegal.INSTANCE;
} else if (/* source != void.class && */ target.represents(void.class)) {
return Removal.pop(source);
return Removal.of(source);
} else /* source != void.class && target != void.class */ {
return chained.assign(source, target, typing);
}
Expand Down

0 comments on commit 146344f

Please sign in to comment.