当前位置: 首页>>代码示例>>Java>>正文


Java TypeDescription.STRING属性代码示例

本文整理汇总了Java中net.bytebuddy.description.type.TypeDescription.STRING属性的典型用法代码示例。如果您正苦于以下问题:Java TypeDescription.STRING属性的具体用法?Java TypeDescription.STRING怎么用?Java TypeDescription.STRING使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在net.bytebuddy.description.type.TypeDescription的用法示例。


在下文中一共展示了TypeDescription.STRING属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: of

/**
 * Creates a binding for a fixed {@link String} or primitive value.
 *
 * @param annotationType The annotation type.
 * @param value          The primitive (wrapper) value or {@link String} value to bind.
 * @param <S>            The annotation type.
 * @return A factory for creating an offset mapping that binds the supplied value.
 */
public static <S extends Annotation> OffsetMapping.Factory<S> of(Class<S> annotationType, Object value) {
    StackManipulation stackManipulation;
    TypeDescription typeDescription;
    if (value == null) {
        return new OfDefaultValue<S>(annotationType);
    } else if (value instanceof Boolean) {
        stackManipulation = IntegerConstant.forValue((Boolean) value);
        typeDescription = new TypeDescription.ForLoadedType(boolean.class);
    } else if (value instanceof Byte) {
        stackManipulation = IntegerConstant.forValue((Byte) value);
        typeDescription = new TypeDescription.ForLoadedType(byte.class);
    } else if (value instanceof Short) {
        stackManipulation = IntegerConstant.forValue((Short) value);
        typeDescription = new TypeDescription.ForLoadedType(short.class);
    } else if (value instanceof Character) {
        stackManipulation = IntegerConstant.forValue((Character) value);
        typeDescription = new TypeDescription.ForLoadedType(char.class);
    } else if (value instanceof Integer) {
        stackManipulation = IntegerConstant.forValue((Integer) value);
        typeDescription = new TypeDescription.ForLoadedType(int.class);
    } else if (value instanceof Long) {
        stackManipulation = LongConstant.forValue((Long) value);
        typeDescription = new TypeDescription.ForLoadedType(long.class);
    } else if (value instanceof Float) {
        stackManipulation = FloatConstant.forValue((Float) value);
        typeDescription = new TypeDescription.ForLoadedType(float.class);
    } else if (value instanceof Double) {
        stackManipulation = DoubleConstant.forValue((Double) value);
        typeDescription = new TypeDescription.ForLoadedType(double.class);
    } else if (value instanceof String) {
        stackManipulation = new TextConstant((String) value);
        typeDescription = TypeDescription.STRING;
    } else {
        throw new IllegalStateException("Not a constant value: " + value);
    }
    return new Factory<S>(annotationType, stackManipulation, typeDescription.asGenericType());
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:45,代码来源:Advice.java

示例2: value

/**
 * <p>
 * Returns a fixed value from any intercepted method. The fixed value is stored in the constant pool if this is possible.
 * Java is capable of storing any primitive value, {@link String} values and {@link Class} references in the constant pool.
 * Since Java 7, {@code MethodHandle} as well as {@code MethodType} references are also supported. Alternatively, the fixed
 * value is stored in a static field.
 * </p>
 * <p>
 * When a value is stored in the class's constant pool, its identity is lost. If an object's identity is important, the
 * {@link FixedValue#reference(Object)} method should be used instead.
 * </p>
 * <p>
 * <b>Important</b>: When supplying a method handle or a method type, all types that are implied must be visible to the instrumented
 * type or an {@link IllegalAccessException} will be thrown at runtime.
 * </p>
 *
 * @param fixedValue The fixed value to return from the method.
 * @return An implementation for the given {@code value}.
 */
public static AssignerConfigurable value(Object fixedValue) {
    Class<?> type = fixedValue.getClass();
    if (type == String.class) {
        return new ForPoolValue(new TextConstant((String) fixedValue), TypeDescription.STRING);
    } else if (type == Class.class) {
        return new ForPoolValue(ClassConstant.of(new TypeDescription.ForLoadedType((Class<?>) fixedValue)), TypeDescription.CLASS);
    } else if (type == Boolean.class) {
        return new ForPoolValue(IntegerConstant.forValue((Boolean) fixedValue), boolean.class);
    } else if (type == Byte.class) {
        return new ForPoolValue(IntegerConstant.forValue((Byte) fixedValue), byte.class);
    } else if (type == Short.class) {
        return new ForPoolValue(IntegerConstant.forValue((Short) fixedValue), short.class);
    } else if (type == Character.class) {
        return new ForPoolValue(IntegerConstant.forValue((Character) fixedValue), char.class);
    } else if (type == Integer.class) {
        return new ForPoolValue(IntegerConstant.forValue((Integer) fixedValue), int.class);
    } else if (type == Long.class) {
        return new ForPoolValue(LongConstant.forValue((Long) fixedValue), long.class);
    } else if (type == Float.class) {
        return new ForPoolValue(FloatConstant.forValue((Float) fixedValue), float.class);
    } else if (type == Double.class) {
        return new ForPoolValue(DoubleConstant.forValue((Double) fixedValue), double.class);
    } else if (JavaType.METHOD_HANDLE.getTypeStub().isAssignableFrom(type)) {
        return new ForPoolValue(new JavaConstantValue(JavaConstant.MethodHandle.ofLoaded(fixedValue)), type);
    } else if (JavaType.METHOD_TYPE.getTypeStub().represents(type)) {
        return new ForPoolValue(new JavaConstantValue(JavaConstant.MethodType.ofLoaded(fixedValue)), type);
    } else {
        return reference(fixedValue);
    }
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:49,代码来源:FixedValue.java

示例3: testHasSignature

@Test
public void testHasSignature() throws Exception {
    MethodDescription.SignatureToken signatureToken = new MethodDescription.SignatureToken("toString", TypeDescription.STRING, Collections.<TypeDescription>emptyList());
    assertThat(ElementMatchers.hasSignature(signatureToken)
            .matches(new MethodDescription.ForLoadedMethod(Object.class.getDeclaredMethod("toString"))), is(true));
    assertThat(ElementMatchers.hasSignature(signatureToken)
            .matches(new MethodDescription.ForLoadedMethod(Object.class.getDeclaredMethod("hashCode"))), is(false));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:8,代码来源:ElementMatchersTest.java

示例4: resolve

@Override
public Resolved resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, Assigner.Typing typing) {
    return new Resolved.Simple(new TextConstant(value), TypeDescription.STRING);
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:4,代码来源:InvokeDynamic.java

示例5: bind

@Override
public ParameterBinding<?> bind(AnnotationDescription.Loadable<S> annotation,
                                MethodDescription source,
                                ParameterDescription target,
                                Implementation.Target implementationTarget,
                                Assigner assigner,
                                Assigner.Typing typing) {
    Object value = bind(annotation, source, target);
    if (value == null) {
        return new ParameterBinding.Anonymous(DefaultValue.of(target.getType()));
    }
    StackManipulation stackManipulation;
    TypeDescription suppliedType;
    if (value instanceof Boolean) {
        stackManipulation = IntegerConstant.forValue((Boolean) value);
        suppliedType = new TypeDescription.ForLoadedType(boolean.class);
    } else if (value instanceof Byte) {
        stackManipulation = IntegerConstant.forValue((Byte) value);
        suppliedType = new TypeDescription.ForLoadedType(byte.class);
    } else if (value instanceof Short) {
        stackManipulation = IntegerConstant.forValue((Short) value);
        suppliedType = new TypeDescription.ForLoadedType(short.class);
    } else if (value instanceof Character) {
        stackManipulation = IntegerConstant.forValue((Character) value);
        suppliedType = new TypeDescription.ForLoadedType(char.class);
    } else if (value instanceof Integer) {
        stackManipulation = IntegerConstant.forValue((Integer) value);
        suppliedType = new TypeDescription.ForLoadedType(int.class);
    } else if (value instanceof Long) {
        stackManipulation = LongConstant.forValue((Long) value);
        suppliedType = new TypeDescription.ForLoadedType(long.class);
    } else if (value instanceof Float) {
        stackManipulation = FloatConstant.forValue((Float) value);
        suppliedType = new TypeDescription.ForLoadedType(float.class);
    } else if (value instanceof Double) {
        stackManipulation = DoubleConstant.forValue((Double) value);
        suppliedType = new TypeDescription.ForLoadedType(double.class);
    } else if (value instanceof String) {
        stackManipulation = new TextConstant((String) value);
        suppliedType = TypeDescription.STRING;
    } else if (value instanceof Class) {
        stackManipulation = ClassConstant.of(new TypeDescription.ForLoadedType((Class<?>) value));
        suppliedType = TypeDescription.CLASS;
    } else if (value instanceof TypeDescription) {
        stackManipulation = ClassConstant.of((TypeDescription) value);
        suppliedType = TypeDescription.CLASS;
    } else if (JavaType.METHOD_HANDLE.getTypeStub().isInstance(value)) {
        stackManipulation = JavaConstant.MethodHandle.ofLoaded(value).asStackManipulation();
        suppliedType = JavaType.METHOD_HANDLE.getTypeStub();
    } else if (value instanceof JavaConstant.MethodHandle) {
        stackManipulation = new JavaConstantValue((JavaConstant.MethodHandle) value);
        suppliedType = JavaType.METHOD_HANDLE.getTypeStub();
    } else if (JavaType.METHOD_TYPE.getTypeStub().isInstance(value)) {
        stackManipulation = new JavaConstantValue(JavaConstant.MethodType.ofLoaded(value));
        suppliedType = JavaType.METHOD_HANDLE.getTypeStub();
    } else if (value instanceof JavaConstant.MethodType) {
        stackManipulation = new JavaConstantValue((JavaConstant.MethodType) value);
        suppliedType = JavaType.METHOD_HANDLE.getTypeStub();
    } else {
        throw new IllegalStateException("Not able to save in class's constant pool: " + value);
    }
    return new ParameterBinding.Anonymous(new StackManipulation.Compound(
            stackManipulation,
            assigner.assign(suppliedType.asGenericType(), target.getType(), typing)
    ));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:66,代码来源:TargetMethodAnnotationDrivenBinder.java


注:本文中的net.bytebuddy.description.type.TypeDescription.STRING属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。