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


Java TypeDescription.isAssignableTo方法代码示例

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


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

示例1: resolve

import net.bytebuddy.description.type.TypeDescription; //导入方法依赖的package包/类
@Override
public Object[] resolve() {
    TypeDescription componentTypeDescription = typePool.describe(componentTypeReference.lookup()).resolve();
    Class<?> componentType;
    if (componentTypeDescription.represents(Class.class)) {
        componentType = TypeDescription.class;
    } else if (componentTypeDescription.isAssignableTo(Enum.class)) { // Enums can implement annotation interfaces, check this first.
        componentType = EnumerationDescription.class;
    } else if (componentTypeDescription.isAssignableTo(Annotation.class)) {
        componentType = AnnotationDescription.class;
    } else if (componentTypeDescription.represents(String.class)) {
        componentType = String.class;
    } else {
        throw new IllegalStateException("Unexpected complex array component type " + componentTypeDescription);
    }
    Object[] array = (Object[]) Array.newInstance(componentType, values.size());
    int index = 0;
    for (AnnotationValue<?, ?> annotationValue : values) {
        Array.set(array, index++, annotationValue.resolve());
    }
    return array;
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:23,代码来源:TypePool.java

示例2: resolve

import net.bytebuddy.description.type.TypeDescription; //导入方法依赖的package包/类
@Override
public StackManipulation resolve(MethodDescription invokedMethod, MethodDescription instrumentedMethod, TypeDescription instrumentedType, Assigner assigner, Assigner.Typing typing) {
    FieldLocator.Resolution resolution = fieldLocatorFactory.make(instrumentedType).locate(name);
    if (!resolution.isResolved()) {
        throw new IllegalStateException("Could not locate field name " + name + " on " + instrumentedType);
    } else if (!resolution.getField().isStatic() && !instrumentedType.isAssignableTo(resolution.getField().getDeclaringType().asErasure())) {
        throw new IllegalStateException("Cannot access " + resolution.getField() + " from " + instrumentedType);
    } else if (!invokedMethod.isInvokableOn(resolution.getField().getType().asErasure())) {
        throw new IllegalStateException("Cannot invoke " + invokedMethod + " on " + resolution.getField());
    } else if (!invokedMethod.isAccessibleTo(instrumentedType)) {
        throw new IllegalStateException("Cannot access " + invokedMethod + " from " + instrumentedType);
    }
    StackManipulation stackManipulation = assigner.assign(resolution.getField().getType(), invokedMethod.getDeclaringType().asGenericType(), typing);
    if (!stackManipulation.isValid()) {
        throw new IllegalStateException("Cannot invoke " + invokedMethod + " on " + resolution.getField());
    }
    return new StackManipulation.Compound(invokedMethod.isStatic()
            ? StackManipulation.Trivial.INSTANCE
            : MethodVariableAccess.loadThis(), FieldAccess.forField(resolution.getField()).read(), stackManipulation);
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:21,代码来源:MethodCall.java

示例3: of

import net.bytebuddy.description.type.TypeDescription; //导入方法依赖的package包/类
/**
 * Creates a record for a visibility bridge.
 *
 * @param instrumentedType  The instrumented type.
 * @param bridgeTarget      The target method of the visibility bridge.
 * @param attributeAppender The attribute appender to apply to the visibility bridge.
 * @return A record describing the visibility bridge.
 */
public static Record of(TypeDescription instrumentedType, MethodDescription bridgeTarget, MethodAttributeAppender attributeAppender) {
    // Default method bridges must be dispatched on an implemented interface type, not considering the declaring type.
    TypeDefinition bridgeType = null;
    if (bridgeTarget.isDefaultMethod()) {
        TypeDescription declaringType = bridgeTarget.getDeclaringType().asErasure();
        for (TypeDescription interfaceType : instrumentedType.getInterfaces().asErasures().filter(isSubTypeOf(declaringType))) {
            if (bridgeType == null || declaringType.isAssignableTo(bridgeType.asErasure())) {
                bridgeType = interfaceType;
            }
        }
    }
    // Non-default method or default method that is inherited by a super class.
    if (bridgeType == null) {
        bridgeType = instrumentedType.getSuperClass();
    }
    return new OfVisibilityBridge(new VisibilityBridge(instrumentedType, bridgeTarget),
            bridgeTarget,
            bridgeType.asErasure(),
            attributeAppender);
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:29,代码来源:TypeWriter.java

示例4: getCommonSuperClass

import net.bytebuddy.description.type.TypeDescription; //导入方法依赖的package包/类
@Override
protected String getCommonSuperClass(String leftTypeName, String rightTypeName) {
    TypeDescription leftType = typePool.describe(leftTypeName.replace('/', '.')).resolve();
    TypeDescription rightType = typePool.describe(rightTypeName.replace('/', '.')).resolve();
    if (leftType.isAssignableFrom(rightType)) {
        return leftType.getInternalName();
    } else if (leftType.isAssignableTo(rightType)) {
        return rightType.getInternalName();
    } else if (leftType.isInterface() || rightType.isInterface()) {
        return TypeDescription.OBJECT.getInternalName();
    } else {
        do {
            leftType = leftType.getSuperClass().asErasure();
        } while (!leftType.isAssignableFrom(rightType));
        return leftType.getInternalName();
    }
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:18,代码来源:TypeWriter.java

示例5: fieldLocator

import net.bytebuddy.description.type.TypeDescription; //导入方法依赖的package包/类
@Override
protected FieldLocator fieldLocator(TypeDescription instrumentedType) {
    if (!declaringType.represents(TargetType.class) && !instrumentedType.isAssignableTo(declaringType)) {
        throw new IllegalStateException(declaringType + " is no super type of " + instrumentedType);
    }
    return new FieldLocator.ForExactType(TargetType.resolve(declaringType, instrumentedType));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:8,代码来源:Advice.java

示例6: isDefaultValue

import net.bytebuddy.description.type.TypeDescription; //导入方法依赖的package包/类
@Override
public boolean isDefaultValue(AnnotationValue<?, ?> annotationValue) {
    if (!isDefaultValue()) {
        return false;
    }
    TypeDescription returnType = getReturnType().asErasure();
    Object value = annotationValue.resolve();
    return (returnType.represents(boolean.class) && value instanceof Boolean)
            || (returnType.represents(byte.class) && value instanceof Byte)
            || (returnType.represents(char.class) && value instanceof Character)
            || (returnType.represents(short.class) && value instanceof Short)
            || (returnType.represents(int.class) && value instanceof Integer)
            || (returnType.represents(long.class) && value instanceof Long)
            || (returnType.represents(float.class) && value instanceof Float)
            || (returnType.represents(double.class) && value instanceof Double)
            || (returnType.represents(String.class) && value instanceof String)
            || (returnType.isAssignableTo(Enum.class) && value instanceof EnumerationDescription && isEnumerationType(returnType, (EnumerationDescription) value))
            || (returnType.isAssignableTo(Annotation.class) && value instanceof AnnotationDescription && isAnnotationType(returnType, (AnnotationDescription) value))
            || (returnType.represents(Class.class) && value instanceof TypeDescription)
            || (returnType.represents(boolean[].class) && value instanceof boolean[])
            || (returnType.represents(byte[].class) && value instanceof byte[])
            || (returnType.represents(char[].class) && value instanceof char[])
            || (returnType.represents(short[].class) && value instanceof short[])
            || (returnType.represents(int[].class) && value instanceof int[])
            || (returnType.represents(long[].class) && value instanceof long[])
            || (returnType.represents(float[].class) && value instanceof float[])
            || (returnType.represents(double[].class) && value instanceof double[])
            || (returnType.represents(String[].class) && value instanceof String[])
            || (returnType.isAssignableTo(Enum[].class) && value instanceof EnumerationDescription[] && isEnumerationType(returnType.getComponentType(), (EnumerationDescription[]) value))
            || (returnType.isAssignableTo(Annotation[].class) && value instanceof AnnotationDescription[] && isAnnotationType(returnType.getComponentType(), (AnnotationDescription[]) value))
            || (returnType.represents(Class[].class) && value instanceof TypeDescription[]);
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:33,代码来源:MethodDescription.java

示例7: prepare

import net.bytebuddy.description.type.TypeDescription; //导入方法依赖的package包/类
@Override
public Prepared prepare(TypeDescription instrumentedType) {
    if (!instrumentedType.isAssignableTo(fieldDescription.getDeclaringType().asErasure())) {
        throw new IllegalStateException(fieldDescription + " is not declared by " + instrumentedType);
    } else if (!fieldDescription.isVisibleTo(instrumentedType)) {
        throw new IllegalStateException("Cannot access " + fieldDescription + " from " + instrumentedType);
    }
    return this;
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:10,代码来源:FieldAccessor.java

示例8: resolve

import net.bytebuddy.description.type.TypeDescription; //导入方法依赖的package包/类
@Override
public Resolved resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, Assigner.Typing typing) {
    if (instrumentedMethod.isStatic()) {
        throw new IllegalStateException("Cannot get this instance from static method: " + instrumentedMethod);
    } else if (!instrumentedType.isAssignableTo(typeDescription)) {
        throw new IllegalStateException(instrumentedType + " is not assignable to " + instrumentedType);
    }
    return new Resolved.Simple(MethodVariableAccess.loadThis(), typeDescription);
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:10,代码来源:InvokeDynamic.java

示例9: combine

import net.bytebuddy.description.type.TypeDescription; //导入方法依赖的package包/类
/**
 * Combines the two given stores.
 *
 * @param left  The left store to be combined.
 * @param right The right store to be combined.
 * @param <W>   The type of the harmonized key of both stores.
 * @return An entry representing the combination of both stores.
 */
private static <W> Entry<W> combine(Entry<W> left, Entry<W> right) {
    Set<MethodDescription> leftMethods = left.getCandidates(), rightMethods = right.getCandidates();
    LinkedHashSet<MethodDescription> combined = new LinkedHashSet<MethodDescription>(leftMethods.size() + rightMethods.size());
    combined.addAll(leftMethods);
    combined.addAll(rightMethods);
    for (MethodDescription leftMethod : leftMethods) {
        TypeDescription leftType = leftMethod.getDeclaringType().asErasure();
        for (MethodDescription rightMethod : rightMethods) {
            TypeDescription rightType = rightMethod.getDeclaringType().asErasure();
            if (leftType.equals(rightType)) {
                break;
            } else if (leftType.isAssignableTo(rightType)) {
                combined.remove(rightMethod);
                break;
            } else if (leftType.isAssignableFrom(rightType)) {
                combined.remove(leftMethod);
                break;
            }
        }
    }
    Key.Harmonized<W> key = left.getKey().combineWith(right.getKey());
    Visibility visibility = left.getVisibility().expandTo(right.getVisibility());
    return combined.size() == 1
            ? new Entry.Resolved<W>(key, combined.iterator().next(), visibility, Entry.Resolved.NOT_MADE_VISIBLE)
            : new Entry.Ambiguous<W>(key, combined, visibility);
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:35,代码来源:MethodGraph.java

示例10: throwing

import net.bytebuddy.description.type.TypeDescription; //导入方法依赖的package包/类
/**
 * Creates an implementation that creates a new instance of the given isThrowable type on each method invocation
 * which is then thrown immediately. For this to be possible, the given type must define a default constructor
 * which is visible from the instrumented type.
 *
 * @param exceptionType The type of the isThrowable.
 * @return An implementation that will throw an instance of the isThrowable on each method invocation of the
 * instrumented methods.
 */
public static Implementation throwing(TypeDescription exceptionType) {
    if (!exceptionType.isAssignableTo(Throwable.class)) {
        throw new IllegalArgumentException(exceptionType + " does not extend throwable");
    }
    return new ExceptionMethod(exceptionType, new ConstructionDelegate.ForDefaultConstructor(exceptionType));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:16,代码来源:ExceptionMethod.java

示例11: canThrow

import net.bytebuddy.description.type.TypeDescription; //导入方法依赖的package包/类
/**
 * Matches a {@link MethodDescription} by its capability to throw a given
 * checked exception. For specifying a non-checked exception, any method is matched.
 *
 * @param exceptionType The type of the exception that should be declared by the method to be matched.
 * @param <T>           The type of the matched object.
 * @return A matcher that matches a method description by its declaration of throwing a checked exception.
 */
public static <T extends MethodDescription> ElementMatcher.Junction<T> canThrow(TypeDescription exceptionType) {
    return exceptionType.isAssignableTo(RuntimeException.class) || exceptionType.isAssignableTo(Error.class)
            ? new BooleanMatcher<T>(true)
            : ElementMatchers.<T>declaresGenericException(new CollectionItemMatcher<TypeDescription.Generic>(erasure(isSuperTypeOf(exceptionType))));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:14,代码来源:ElementMatchers.java

示例12: declaresException

import net.bytebuddy.description.type.TypeDescription; //导入方法依赖的package包/类
/**
 * Matches a method that declares the given generic exception type as a (erased) exception type.
 *
 * @param exceptionType The exception type that is matched.
 * @param <T>           The type of the matched object.
 * @return A matcher that matches any method that exactly matches the provided exception.
 */
public static <T extends MethodDescription> ElementMatcher.Junction<T> declaresException(TypeDescription exceptionType) {
    return exceptionType.isAssignableTo(Throwable.class)
            ? ElementMatchers.<T>declaresGenericException(new CollectionItemMatcher<TypeDescription.Generic>(erasure(exceptionType)))
            : new BooleanMatcher<T>(false);
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:13,代码来源:ElementMatchers.java


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