private AnnotationList doGetAnnotations() { AnnotationDescription.Loadable<Access> access = fieldDescription.getDeclaringType().asErasure() .getDeclaredAnnotations().ofType( Access.class ); if ( access != null && access.loadSilent().value() == AccessType.PROPERTY ) { Optional<MethodDescription> getter = getGetter(); if ( getter.isPresent() ) { return getter.get().getDeclaredAnnotations(); } else { return fieldDescription.getDeclaredAnnotations(); } } else if ( access != null && access.loadSilent().value() == AccessType.FIELD ) { return fieldDescription.getDeclaredAnnotations(); } else { Optional<MethodDescription> getter = getGetter(); // Note that the order here is important List<AnnotationDescription> annotationDescriptions = new ArrayList<>(); if ( getter.isPresent() ) { annotationDescriptions.addAll( getter.get().getDeclaredAnnotations() ); } annotationDescriptions.addAll( fieldDescription.getDeclaredAnnotations() ); return fieldDescription.getDeclaredAnnotations(); } } }
targetClass = oto.getValue( new MethodDescription.ForLoadedMethod( OneToOne.class.getDeclaredMethod( "targetEntity" ) ) ); targetClass = otm.getValue( new MethodDescription.ForLoadedMethod( OneToMany.class.getDeclaredMethod( "targetEntity" ) ) ); targetClass = mto.getValue( new MethodDescription.ForLoadedMethod( ManyToOne.class.getDeclaredMethod( "targetEntity" ) ) ); targetClass = mtm.getValue( new MethodDescription.ForLoadedMethod( ManyToMany.class.getDeclaredMethod( "targetEntity" ) ) );
/** * {@inheritDoc} */ public AnnotationValue.Loaded<U> load(ClassLoader classLoader) throws ClassNotFoundException { @SuppressWarnings("unchecked") Class<U> annotationType = (Class<U>) Class.forName(annotationDescription.getAnnotationType().getName(), false, classLoader); return new Loaded<U>(annotationDescription.prepare(annotationType).load()); }
targetClass = oto.getValue( new MethodDescription.ForLoadedMethod( OneToOne.class.getDeclaredMethod( "targetEntity" ) ) ); targetClass = otm.getValue( new MethodDescription.ForLoadedMethod( OneToMany.class.getDeclaredMethod( "targetEntity" ) ) ); targetClass = mto.getValue( new MethodDescription.ForLoadedMethod( ManyToOne.class.getDeclaredMethod( "targetEntity" ) ) ); targetClass = mtm.getValue( new MethodDescription.ForLoadedMethod( ManyToMany.class.getDeclaredMethod( "targetEntity" ) ) );
private AnnotationList doGetAnnotations() { AnnotationDescription.Loadable<Access> access = fieldDescription.getDeclaringType().asErasure() .getDeclaredAnnotations().ofType( Access.class ); if ( access != null && access.loadSilent().value() == AccessType.PROPERTY ) { Optional<MethodDescription> getter = getGetter(); if ( getter.isPresent() ) { return getter.get().getDeclaredAnnotations(); } else { return fieldDescription.getDeclaredAnnotations(); } } else if ( access != null && access.loadSilent().value() == AccessType.FIELD ) { return fieldDescription.getDeclaredAnnotations(); } else { Optional<MethodDescription> getter = getGetter(); // Note that the order here is important List<AnnotationDescription> annotationDescriptions = new ArrayList<>(); if ( getter.isPresent() ) { annotationDescriptions.addAll( getter.get().getDeclaredAnnotations() ); } annotationDescriptions.addAll( fieldDescription.getDeclaredAnnotations() ); return fieldDescription.getDeclaredAnnotations(); } } }
private static String getMappedByNotManyToMany(AnnotatedFieldDescription target) { try { AnnotationDescription.Loadable<OneToOne> oto = target.getAnnotation( OneToOne.class ); if ( oto != null ) { return oto.getValue( new MethodDescription.ForLoadedMethod( OneToOne.class.getDeclaredMethod( "mappedBy" ) ) ).resolve( String.class ); } AnnotationDescription.Loadable<OneToMany> otm = target.getAnnotation( OneToMany.class ); if ( otm != null ) { return otm.getValue( new MethodDescription.ForLoadedMethod( OneToMany.class.getDeclaredMethod( "mappedBy" ) ) ).resolve( String.class ); } AnnotationDescription.Loadable<ManyToMany> mtm = target.getAnnotation( ManyToMany.class ); if ( mtm != null ) { return mtm.getValue( new MethodDescription.ForLoadedMethod( ManyToMany.class.getDeclaredMethod( "mappedBy" ) ) ).resolve( String.class ); } } catch (NoSuchMethodException ignored) { } return null; }
public static String getRequestName(MethodDescription instrumentedMethod) { final AnnotationDescription.Loadable<MonitorRequests> monitorRequestsLoadable = instrumentedMethod .getDeclaredAnnotations() .ofType(MonitorRequests.class); if (monitorRequestsLoadable != null) { final MonitorRequests monitorRequests = monitorRequestsLoadable.loadSilent(); if (!monitorRequests.requestName().isEmpty()) { return monitorRequests.requestName(); } if (monitorRequests.resolveNameAtRuntime()) { return null; } } return getBusinessTransationName(instrumentedMethod.getDeclaringType().getTypeName(), instrumentedMethod.getName()); }
private static TypeDescription.Generic target(AnnotatedFieldDescription persistentField) { AnnotationDescription.Loadable<Access> access = persistentField.getDeclaringType().asErasure().getDeclaredAnnotations().ofType( Access.class ); if ( access != null && access.loadSilent().value() == AccessType.FIELD ) { return persistentField.getType(); } else { Optional<MethodDescription> getter = persistentField.getGetter(); if ( getter.isPresent() ) { return getter.get().getReturnType(); } else { return persistentField.getType(); } } }
@Override public boolean matches(MethodDescription.InDefinedShape targetMethod) { final AnnotationList declaredAnnotationsOfType = targetMethod.getDeclaringType().getDeclaredAnnotations(); if (declaredAnnotationsOfType.isAnnotationPresent(Remote.class)) { final Class[] remoteInterfaces = declaredAnnotationsOfType.ofType(Remote.class).loadSilent().value(); if (!new TypeList.ForLoadedTypes(remoteInterfaces).filter(isDeclaredInInterfaceHierarchy(targetMethod)).isEmpty()) { return true; } } return false; } }
@Override public Target resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, Advice.ArgumentHandler argumentHandler, Sort sort) { return Target.ForStackManipulation.of(getAnnotationValue(instrumentedMethod, annotation.loadSilent())); } };
new OffsetMapping.Factory.Illegal<Enter>(Enter.class), new OffsetMapping.Factory.Illegal<Return>(Return.class)), userFactories), adviceMethod.getDeclaredAnnotations().ofType(OnMethodEnter.class).getValue(SUPPRESS_ENTER).resolve(TypeDescription.class), adviceMethod.getDeclaredAnnotations().ofType(OnMethodEnter.class).getValue(SKIP_ON).resolve(TypeDescription.class), classReader); this.namedTypes = namedTypes; prependLineNumber = adviceMethod.getDeclaredAnnotations().ofType(OnMethodEnter.class).getValue(PREPEND_LINE_NUMBER).resolve(Boolean.class);
} else if (parameterType.represents(Method.class)) { return source.isMethod() ? new MethodDelegationBinder.ParameterBinding.Anonymous(methodConstant(annotation.loadSilent(), source.asDefined())) : MethodDelegationBinder.ParameterBinding.Illegal.INSTANCE; } else if (parameterType.represents(Constructor.class)) { return source.isConstructor() ? new MethodDelegationBinder.ParameterBinding.Anonymous(methodConstant(annotation.loadSilent(), source.asDefined())) : MethodDelegationBinder.ParameterBinding.Illegal.INSTANCE; } else if (JavaType.EXECUTABLE.getTypeStub().equals(parameterType)) { return new MethodDelegationBinder.ParameterBinding.Anonymous(methodConstant(annotation.loadSilent(), source.asDefined())); } else if (parameterType.represents(String.class)) { return new MethodDelegationBinder.ParameterBinding.Anonymous(new TextConstant(source.toString()));
throw new IllegalStateException("Expected an array type for all argument annotation on " + source); boolean includeThis = !source.isStatic() && annotation.loadSilent().includeSelf(); List<StackManipulation> stackManipulations = new ArrayList<StackManipulation>(source.getParameters().size() + (includeThis ? 1 : 0)); int offset = source.isStatic() || includeThis ? 0 : 1; if (stackManipulation.isValid()) { stackManipulations.add(stackManipulation); } else if (annotation.loadSilent().value().isStrict()) { return MethodDelegationBinder.ParameterBinding.Illegal.INSTANCE;
Enhance enhance = typeDescription.getDeclaredAnnotations().ofType(Enhance.class).loadSilent(); if (typeDescription.getDeclaredMethods().filter(isHashCode()).isEmpty()) { builder = builder.method(isHashCode()).intercept(enhance.invokeSuper()
throw new IllegalStateException("Cannot assign Method type to " + target); } else if (source.isMethod()) { TypeDescription typeDescription = annotation.getValue(TARGET_TYPE).resolve(TypeDescription.class); Implementation.SpecialMethodInvocation specialMethodInvocation = (typeDescription.represents(void.class) ? MethodLocator.ForImplicitType.INSTANCE if (specialMethodInvocation.isValid()) { return new MethodDelegationBinder.ParameterBinding.Anonymous(new DelegationMethod(specialMethodInvocation, annotation.getValue(CACHED).resolve(Boolean.class), annotation.getValue(PRIVILEGED).resolve(Boolean.class))); } else if (annotation.getValue(NULL_IF_IMPOSSIBLE).resolve(Boolean.class)) { return new MethodDelegationBinder.ParameterBinding.Anonymous(NullConstant.INSTANCE); } else { return MethodDelegationBinder.ParameterBinding.Illegal.INSTANCE; } else if (annotation.getValue(NULL_IF_IMPOSSIBLE).resolve(Boolean.class)) { return new MethodDelegationBinder.ParameterBinding.Anonymous(NullConstant.INSTANCE); } else {
/** * {@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; }
OffsetMapping.ForThrowable.Factory.of(adviceMethod) ), userFactories), adviceMethod.getDeclaredAnnotations().ofType(OnMethodExit.class).getValue(SUPPRESS_EXIT).resolve(TypeDescription.class), adviceMethod.getDeclaredAnnotations().ofType(OnMethodExit.class).getValue(REPEAT_ON).resolve(TypeDescription.class)); backupArguments = adviceMethod.getDeclaredAnnotations().ofType(OnMethodExit.class).getValue(BACKUP_ARGUMENTS).resolve(Boolean.class);
public static String getRequestName(MethodDescription instrumentedMethod) { final AnnotationDescription.Loadable<Traced> monitorRequestsLoadable = instrumentedMethod .getDeclaredAnnotations() .ofType(Traced.class); if (monitorRequestsLoadable != null) { final Traced traced = monitorRequestsLoadable.loadSilent(); if (!traced.requestName().isEmpty()) { return traced.requestName(); } if (traced.resolveNameAtRuntime()) { return null; } } return getBusinessTransationName(instrumentedMethod.getDeclaringType().getTypeName(), instrumentedMethod.getName()); }
/** * {@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; } }
OffsetMapping.ForThrowable.Factory.of(adviceMethod) ), userFactories), adviceMethod.getDeclaredAnnotations().ofType(OnMethodExit.class).getValue(SUPPRESS_EXIT).resolve(TypeDescription.class), adviceMethod.getDeclaredAnnotations().ofType(OnMethodExit.class).getValue(REPEAT_ON).resolve(TypeDescription.class), classReader); backupArguments = adviceMethod.getDeclaredAnnotations().ofType(OnMethodExit.class).getValue(BACKUP_ARGUMENTS).resolve(Boolean.class);