/** * {@inheritDoc} */ public boolean matches(T target) { return target.isAssignableFrom(typeDescription); }
/** * {@inheritDoc} */ public Boolean onNonGenericType(Generic typeDescription) { return this.typeDescription.isAssignableFrom(typeDescription.asErasure()); } }
@Override protected FieldDescription resolve(TypeDescription instrumentedType) { if (!fieldDescription.isStatic() && !fieldDescription.getDeclaringType().asErasure().isAssignableFrom(instrumentedType)) { throw new IllegalStateException(fieldDescription + " is no member of " + instrumentedType); } else if (!fieldDescription.isAccessibleTo(instrumentedType)) { throw new IllegalStateException("Cannot access " + fieldDescription + " from " + instrumentedType); } return fieldDescription; }
if (instrumentedMethod.isStatic()) { throw new IllegalStateException("toString method must not be static: " + instrumentedMethod); } else if (!instrumentedMethod.getReturnType().asErasure().isAssignableFrom(String.class)) { throw new IllegalStateException("toString method does not return String-compatible type: " + instrumentedMethod);
/** * {@inheritDoc} */ public boolean isSpecializableFor(TypeDescription targetType) { if (isStatic()) { // Static private methods are never specializable, check static property first return false; } else if (isPrivate() || isConstructor()) { return getDeclaringType().equals(targetType); } else { return !isAbstract() && getDeclaringType().asErasure().isAssignableFrom(targetType); } }
combined.remove(rightMethod); break; } else if (leftType.isAssignableFrom(rightType)) { combined.remove(leftMethod); break;
/** * {@inheritDoc} */ public boolean isInvokableOn(TypeDescription typeDescription) { return !isStatic() && !isTypeInitializer() && isVisibleTo(typeDescription) && (isVirtual() ? getDeclaringType().asErasure().isAssignableFrom(typeDescription) : getDeclaringType().asErasure().equals(typeDescription)); }
/** * {@inheritDoc} */ 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(); } } }
/** * {@inheritDoc} */ public Resolution resolve(MethodDescription source, MethodDelegationBinder.MethodBinding left, MethodDelegationBinder.MethodBinding right) { TypeDescription leftType = left.getTarget().getDeclaringType().asErasure(); TypeDescription rightType = right.getTarget().getDeclaringType().asErasure(); if (leftType.equals(rightType)) { return Resolution.AMBIGUOUS; } else if (leftType.isAssignableFrom(rightType)) { return Resolution.RIGHT; } else if (leftType.isAssignableTo(rightType)) { return Resolution.LEFT; } else { return Resolution.AMBIGUOUS; } } }
/** * {@inheritDoc} */ public boolean isInvokeBootstrap() { TypeDescription returnType = getReturnType().asErasure(); if ((isMethod() && (!isStatic() || !(JavaType.CALL_SITE.getTypeStub().isAssignableFrom(returnType) || JavaType.CALL_SITE.getTypeStub().isAssignableTo(returnType)))) || (isConstructor() && !JavaType.CALL_SITE.getTypeStub().isAssignableFrom(getDeclaringType().asErasure()))) { return false; } return isBootstrap(JavaType.METHOD_TYPE.getTypeStub()); }
/** * {@inheritDoc} */ public boolean isVisibleTo(TypeDescription typeDescription) { return getDeclaringType().asErasure().isVisibleTo(typeDescription) && (isPublic() || typeDescription.equals(getDeclaringType().asErasure()) || (isProtected() && getDeclaringType().asErasure().isAssignableFrom(typeDescription)) || (!isPrivate() && typeDescription.isSamePackage(getDeclaringType().asErasure()))); }
/** * {@inheritDoc} */ public boolean isVisibleTo(TypeDescription typeDescription) { return (isVirtual() || getDeclaringType().asErasure().isVisibleTo(typeDescription)) && (isPublic() || typeDescription.equals(getDeclaringType().asErasure()) || isProtected() && getDeclaringType().asErasure().isAssignableFrom(typeDescription) || !isPrivate() && typeDescription.isSamePackage(getDeclaringType().asErasure())); }
if (superClass != null && sourceType.isAssignableFrom(superClass.asErasure())) { return true; if (sourceType.isAssignableFrom(interfaceType)) { return true;
} else { if (leftParameterType.isAssignableFrom(rightParameterType)) { return Resolution.RIGHT; } else if (rightParameterType.isAssignableFrom(leftParameterType)) { return Resolution.LEFT; } else {
/** * {@inheritDoc} */ public OffsetMapping make(ParameterDescription.InDefinedShape target, AnnotationDescription.Loadable<Origin> annotation, AdviceType adviceType) { if (target.getType().asErasure().represents(Class.class)) { return OffsetMapping.ForInstrumentedType.INSTANCE; } else if (target.getType().asErasure().represents(Method.class)) { return OffsetMapping.ForInstrumentedMethod.METHOD; } else if (target.getType().asErasure().represents(Constructor.class)) { return OffsetMapping.ForInstrumentedMethod.CONSTRUCTOR; } else if (JavaType.EXECUTABLE.getTypeStub().equals(target.getType().asErasure())) { return OffsetMapping.ForInstrumentedMethod.EXECUTABLE; } else if (target.getType().asErasure().isAssignableFrom(String.class)) { return ForOrigin.parse(annotation.loadSilent().value()); } else { throw new IllegalStateException("Non-supported type " + target.getType() + " for @Origin annotation"); } } }
/** * Checks if this method is a bootstrap method while expecting the supplied type as a type representation. * * @param typeType The type of the bootstrap method's type representation. * @return {@code true} if this method is a bootstrap method assuming the supplied type representation. */ private boolean isBootstrap(TypeDescription typeType) { TypeList parameterTypes = getParameters().asTypeList().asErasures(); switch (parameterTypes.size()) { case 0: return false; case 1: return parameterTypes.getOnly().represents(Object[].class); case 2: return JavaType.METHOD_HANDLES_LOOKUP.getTypeStub().isAssignableTo(parameterTypes.get(0)) && parameterTypes.get(1).represents(Object[].class); case 3: return JavaType.METHOD_HANDLES_LOOKUP.getTypeStub().isAssignableTo(parameterTypes.get(0)) && (parameterTypes.get(1).represents(Object.class) || parameterTypes.get(1).represents(String.class)) && (parameterTypes.get(2).represents(Object[].class) || parameterTypes.get(2).isAssignableFrom(typeType)); default: return JavaType.METHOD_HANDLES_LOOKUP.getTypeStub().isAssignableTo(parameterTypes.get(0)) && (parameterTypes.get(1).represents(Object.class) || parameterTypes.get(1).represents(String.class)) && parameterTypes.get(2).isAssignableFrom(typeType); } }
Assigner assigner, Assigner.Typing typing) { if (!target.getType().asErasure().isAssignableFrom(Method.class)) { throw new IllegalStateException("Cannot assign Method type to " + target); } else if (source.isMethod()) {
/** * {@inheritDoc} */ public MethodDelegationBinder.ParameterBinding<?> bind(final AnnotationDescription.Loadable<SuperMethod> annotation, MethodDescription source, ParameterDescription target, Implementation.Target implementationTarget, Assigner assigner, Assigner.Typing typing) { if (!target.getType().asErasure().isAssignableFrom(Method.class)) { throw new IllegalStateException("Cannot assign Method type to " + target); } else if (source.isMethod()) { Implementation.SpecialMethodInvocation specialMethodInvocation = annotation.loadSilent().fallbackToDefault() ? implementationTarget.invokeDominant(source.asSignatureToken()) : implementationTarget.invokeSuper(source.asSignatureToken()); if (specialMethodInvocation.isValid()) { return new MethodDelegationBinder.ParameterBinding.Anonymous(new DelegationMethod(specialMethodInvocation, annotation.loadSilent().cached(), annotation.loadSilent().privileged())); } else if (annotation.loadSilent().nullIfImpossible()) { return new MethodDelegationBinder.ParameterBinding.Anonymous(NullConstant.INSTANCE); } else { return MethodDelegationBinder.ParameterBinding.Illegal.INSTANCE; } } else if (annotation.loadSilent().nullIfImpossible()) { return new MethodDelegationBinder.ParameterBinding.Anonymous(NullConstant.INSTANCE); } else { return MethodDelegationBinder.ParameterBinding.Illegal.INSTANCE; } }
} else if (type == Double.class) { return setsValue(DoubleConstant.forValue((Double) value), double.class); } else if (JavaType.METHOD_HANDLE.getTypeStub().isAssignableFrom(type)) { return setsValue(new JavaConstantValue(JavaConstant.MethodHandle.ofLoaded(value)), type); } else if (JavaType.METHOD_TYPE.getTypeStub().represents(type)) {
} 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)) {