/** * {@inheritDoc} */ public boolean isConstantBootstrap() { ParameterList<?> parameters = getParameters(); return !parameters.isEmpty() && getParameters().get(0).getType().asErasure().equals(JavaType.METHOD_HANDLES_LOOKUP.getTypeStub()) && isBootstrap(TypeDescription.CLASS); }
/** * {@inheritDoc} */ public boolean isDefaultValue() { return !isConstructor() && !isStatic() && getReturnType().asErasure().isAnnotationReturnType() && getParameters().isEmpty(); }
/** * {@inheritDoc} */ public DynamicType.Builder<?> apply(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassFileLocator classFileLocator) { for (MethodDescription.InDefinedShape methodDescription : typeDescription.getDeclaredMethods() .filter(not(isBridge()).<MethodDescription>and(isAnnotatedWith(Enhance.class)))) { if (methodDescription.isAbstract()) { throw new IllegalStateException("Cannot cache the value of an abstract method: " + methodDescription); } else if (!methodDescription.getParameters().isEmpty()) { throw new IllegalStateException("Cannot cache the value of a method with parameters: " + methodDescription); } else if (methodDescription.getReturnType().represents(void.class)) { throw new IllegalStateException("Cannot cache void result for " + methodDescription); } String name = methodDescription.getDeclaredAnnotations().ofType(Enhance.class).loadSilent().value(); if (name.length() == 0) { name = methodDescription.getName() + NAME_INFIX + randomString.nextString(); } builder = builder .defineField(name, methodDescription.getReturnType().asErasure(), methodDescription.isStatic() ? Ownership.STATIC : Ownership.MEMBER, Visibility.PRIVATE, SyntheticState.SYNTHETIC, FieldPersistence.TRANSIENT) .visit(Advice.withCustomMapping() .bind(CacheField.class, new CacheFieldOffsetMapping(name)) .to(adviceByType.get(methodDescription.getReturnType().isPrimitive() ? methodDescription.getReturnType().asErasure() : TypeDescription.OBJECT), this.classFileLocator) .on(is(methodDescription))); } return builder; }
if (!instrumentedMethod.isStatic() || !instrumentedMethod.getParameters().isEmpty()) { if (!expandFrames && (instrumentedMethod.isStatic() ? 0 : 1) + instrumentedMethod.getParameters().size() < 4) { Object[] localVariable = new Object[(instrumentedMethod.isStatic() ? 0 : 1) + instrumentedMethod.getParameters().size()];
private static boolean isAccessor(MethodDescription method) { if (method.getDeclaringType().represents(Object.class)) { return false; } String methodName = method.getName(); Generic returnType = method.getReturnType(); ParameterList<?> args = method.getParameters(); boolean isSetter = Generic.VOID.equals(returnType) && args.size() == 1 && ReflectTools.isSetterName(methodName); boolean isGetter = !Generic.VOID.equals(returnType) && args.isEmpty() && ReflectTools.isGetterName(methodName, returnType.represents(boolean.class)); return isSetter || isGetter; }
private static boolean isAccessor(MethodDescription method) { if (method.getDeclaringType().represents(Object.class)) { return false; } String methodName = method.getName(); Generic returnType = method.getReturnType(); ParameterList<?> args = method.getParameters(); boolean isSetter = Generic.VOID.equals(returnType) && args.size() == 1 && ReflectTools.isSetterName(methodName); boolean isGetter = !Generic.VOID.equals(returnType) && args.isEmpty() && ReflectTools.isGetterName(methodName, returnType.represents(boolean.class)); return isSetter || isGetter; }