net.bytebuddy.implementation.bytecode.constant.JavaConstantValue Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of byte-buddy Show documentation
Show all versions of byte-buddy Show documentation
Byte Buddy is a Java library for creating Java classes at run time.
This artifact is a build of Byte Buddy with all ASM dependencies repackaged into its own name space.
/*
* Copyright 2014 - Present Rafael Winterhalter
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.bytebuddy.implementation.bytecode.constant;
import net.bytebuddy.build.HashCodeAndEqualsPlugin;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.implementation.Implementation;
import net.bytebuddy.implementation.bytecode.StackManipulation;
import net.bytebuddy.utility.ConstantValue;
import net.bytebuddy.utility.JavaConstant;
import net.bytebuddy.jar.asm.ConstantDynamic;
import net.bytebuddy.jar.asm.Handle;
import net.bytebuddy.jar.asm.MethodVisitor;
import net.bytebuddy.jar.asm.Type;
/**
* A constant representing a {@link JavaConstant}. By using this stack manipulation, a value is always
* represented as a constant pool value and no attempt is made to load the value via a specialized byte
* code instruction, in contrast to using {@link ConstantValue#toStackManipulation()}.
*/
@HashCodeAndEqualsPlugin.Enhance
public class JavaConstantValue extends StackManipulation.AbstractBase {
/**
* The instance to load onto the operand stack.
*/
private final JavaConstant constant;
/**
* Creates a constant pool value representing a {@link JavaConstant}.
*
* @param constant The instance to load onto the operand stack.
*/
public JavaConstantValue(JavaConstant constant) {
this.constant = constant;
}
/**
* {@inheritDoc}
*/
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) {
methodVisitor.visitLdcInsn(constant.accept(Visitor.INSTANCE));
return constant.getTypeDescription().getStackSize().toIncreasingSize();
}
/**
* A visitor to resolve a {@link JavaConstant} to a ASM constant pool representation.
*/
public enum Visitor implements JavaConstant.Visitor