/** * {@inheritDoc} */ public Builder<S> withHashCodeEquals() { return method(isHashCode()) .intercept(HashCodeMethod.usingDefaultOffset().withIgnoredFields(isSynthetic())) .method(isEquals()) .intercept(EqualsMethod.isolated().withIgnoredFields(isSynthetic())); }
/** * Creates a new Byte Buddy instance with a default configuration that is suitable for most use cases. * * @param classFileVersion The class file version to use for types that are not based on an existing class file. */ public ByteBuddy(ClassFileVersion classFileVersion) { this(classFileVersion, new NamingStrategy.SuffixingRandom(BYTE_BUDDY_DEFAULT_PREFIX), new AuxiliaryType.NamingStrategy.SuffixingRandom(BYTE_BUDDY_DEFAULT_SUFFIX), AnnotationValueFilter.Default.APPEND_DEFAULTS, AnnotationRetention.ENABLED, Implementation.Context.Default.Factory.INSTANCE, MethodGraph.Compiler.DEFAULT, InstrumentedType.Factory.Default.MODIFIABLE, TypeValidation.ENABLED, ClassWriterStrategy.Default.CONSTANT_POOL_RETAINING, new LatentMatcher.Resolved<MethodDescription>(isSynthetic().or(isDefaultFinalizer()))); }
private ProxyDefinitionHelpers() { this.groovyGetMetaClassFilter = isSynthetic().and( named( "getMetaClass" ) .and( returns( td -> "groovy.lang.MetaClass".equals( td.getName() ) ) ) ); this.virtualNotFinalizerFilter = isVirtual().and( not( isFinalizer() ) ); this.hibernateGeneratedMethodFilter = nameStartsWith( "$$_hibernate_" ).and( isVirtual() ); PrivilegedAction<MethodDelegation> delegateToInterceptorDispatcherMethodDelegationPrivilegedAction = new PrivilegedAction<MethodDelegation>() { @Override public MethodDelegation run() { return MethodDelegation.to( ProxyConfiguration.InterceptorDispatcher.class ); } }; this.delegateToInterceptorDispatcherMethodDelegation = System.getSecurityManager() != null ? AccessController.doPrivileged( delegateToInterceptorDispatcherMethodDelegationPrivilegedAction ) : delegateToInterceptorDispatcherMethodDelegationPrivilegedAction.run(); PrivilegedAction<FieldAccessor.PropertyConfigurable> interceptorFieldAccessorPrivilegedAction = new PrivilegedAction<FieldAccessor.PropertyConfigurable>() { @Override public FieldAccessor.PropertyConfigurable run() { return FieldAccessor.ofField( ProxyConfiguration.INTERCEPTOR_FIELD_NAME ) .withAssigner( Assigner.DEFAULT, Assigner.Typing.DYNAMIC ); } }; this.interceptorFieldAccessor = System.getSecurityManager() != null ? AccessController.doPrivileged( interceptorFieldAccessorPrivilegedAction ) : interceptorFieldAccessorPrivilegedAction.run(); }
protected ElementMatcher.Junction<TypeDescription> getTypeMatcher() { return getIncludeTypeMatcher() .and(not(isInterface())) .and(not(isSynthetic())) .and(not(getExtraExcludeTypeMatcher())); }
/** * {@inheritDoc} */ public DynamicType.Builder<?> apply(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassFileLocator classFileLocator) { Enhance enhance = typeDescription.getDeclaredAnnotations().ofType(Enhance.class).loadSilent(); if (typeDescription.getDeclaredMethods().filter(isToString()).isEmpty()) { builder = builder.method(isToString()).intercept(ToStringMethod.prefixedBy(enhance.prefix().getPrefixResolver()) .withIgnoredFields(enhance.includeSyntheticFields() ? ElementMatchers.<FieldDescription>none() : ElementMatchers.<FieldDescription>isSynthetic()) .withIgnoredFields(isAnnotatedWith(Exclude.class))); } return builder; }
new RawMatcher.Disjunction( new RawMatcher.ForElementMatchers(any(), isBootstrapClassLoader().or(isExtensionClassLoader())), new RawMatcher.ForElementMatchers(nameStartsWith("net.bytebuddy.").or(nameStartsWith("sun.reflect.")).<TypeDescription>or(isSynthetic()))), Transformation.Ignored.INSTANCE);
protected ElementMatcher.Junction<MethodDescription> getMethodElementMatcher() { return not(isConstructor()) .and(not(isAbstract())) .and(not(isNative())) .and(not(isFinal())) .and(not(isSynthetic())) .and(not(isTypeInitializer())) .and(getExtraMethodElementMatcher()); }
.withIgnoredFields(enhance.includeSyntheticFields() ? ElementMatchers.<FieldDescription>none() : ElementMatchers.<FieldDescription>isSynthetic()) .withIgnoredFields(new ValueMatcher(ValueHandling.Sort.IGNORE)) .withNonNullableFields(nonNullable(new ValueMatcher(ValueHandling.Sort.REVERSE_NULLABILITY)))); .withIgnoredFields(enhance.includeSyntheticFields() ? ElementMatchers.<FieldDescription>none() : ElementMatchers.<FieldDescription>isSynthetic()) .withIgnoredFields(new ValueMatcher(ValueHandling.Sort.IGNORE)) .withNonNullableFields(nonNullable(new ValueMatcher(ValueHandling.Sort.REVERSE_NULLABILITY)))
/** * Ctor. * @param type Type to call method on. */ public SmtInvokeAtomEqual(final TypeDescription type) { super( type, new ConjunctionMatcher<>( isSynthetic(), named("atom$equal") ) ); } }
/** * Ctor. * * @param type Type to call method on. */ public SmtInvokeAtomHashCode(final TypeDescription type) { super( type, new ConjunctionMatcher<>( isSynthetic(), named("atom$hashCode") ) ); } }
/** * Ctor. * * @param type Type to call method on. */ public SmtInvokeAtomToStringNatural(final TypeDescription type) { super( type, new ConjunctionMatcher<>( isSynthetic(), named("atom$toString$natural") ) ); } }
/** * Ctor. * * @param type Type to call method on. */ public SmtInvokeAtomToString(final TypeDescription type) { super( type, new ConjunctionMatcher<>( isSynthetic(), named("atom$toString") ) ); } }
@Override public final boolean matches(final TypeDescription target) { return target.getDeclaredFields() .filter(not(isSynthetic())) .filter(f -> f.getType().isArray()) .isEmpty(); } }
private ProxyDefinitionHelpers() { this.groovyGetMetaClassFilter = isSynthetic().and( named( "getMetaClass" ) .and( returns( td -> "groovy.lang.MetaClass".equals( td.getName() ) ) ) ); this.virtualNotFinalizerFilter = isVirtual().and( not( isFinalizer() ) ); this.hibernateGeneratedMethodFilter = nameStartsWith( "$$_hibernate_" ).and( isVirtual() ); PrivilegedAction<MethodDelegation> delegateToInterceptorDispatcherMethodDelegationPrivilegedAction = new PrivilegedAction<MethodDelegation>() { @Override public MethodDelegation run() { return MethodDelegation.to( ProxyConfiguration.InterceptorDispatcher.class ); } }; this.delegateToInterceptorDispatcherMethodDelegation = System.getSecurityManager() != null ? AccessController.doPrivileged( delegateToInterceptorDispatcherMethodDelegationPrivilegedAction ) : delegateToInterceptorDispatcherMethodDelegationPrivilegedAction.run(); PrivilegedAction<FieldAccessor.PropertyConfigurable> interceptorFieldAccessorPrivilegedAction = new PrivilegedAction<FieldAccessor.PropertyConfigurable>() { @Override public FieldAccessor.PropertyConfigurable run() { return FieldAccessor.ofField( ProxyConfiguration.INTERCEPTOR_FIELD_NAME ) .withAssigner( Assigner.DEFAULT, Assigner.Typing.DYNAMIC ); } }; this.interceptorFieldAccessor = System.getSecurityManager() != null ? AccessController.doPrivileged( interceptorFieldAccessorPrivilegedAction ) : interceptorFieldAccessorPrivilegedAction.run(); }
@Override public final boolean matches(TypeDescription target) { return target.getDeclaredMethods() .filter(not(isConstructor())) .filter(not(isSynthetic())) .isEmpty(); } }
@Override public final boolean matches(TypeDescription target) { MethodList<MethodDescription.InDefinedShape> declaredMethods = target.getDeclaredMethods() .filter(isStatic()) .filter(not(isSynthetic())); if(target.isEnum()) { declaredMethods = declaredMethods .filter(not(ENUM_METHODS_MATCHER)); } return declaredMethods.isEmpty(); } }
.and(not(isAbstract())) .and(not(isNative())) .and(not(isSynthetic())) .and(not(isTypeInitializer()));
/** * Ctor */ public GenerateObjectMethodsPlugin() { super( new BtApplyIfMatches( new ConjunctionMatcher<>( not(isInterface()), not(isAnnotation()), not(isSynthetic()), new AnnotatedAtom(), not(new ExplicitlyExtendingAnything()) ), new BtValidated( new ValAtom(), new BtSequence( new BtGenerateEquals(), new BtGenerateHashCode(), new BtGenerateToString() ) ) ) ); } }
/** * Ctor. */ public AnnotateClassesPlugin() { super( new BtApplyIfMatches( new ConjunctionMatcher<>( not(isInterface()), not(isAnnotation()), not(isSynthetic()), not(new AnnotatedAtom()), not(new AnnotatedNonAtom()), new ThisOrSuperClassMatcher( new DisjunctionMatcher<>( new AnnotatedAtom(), new ImplementsNoInterfaces(), new ImplementsInterfaceWhichMatches( new AnnotatedAtom() ) ) ) ), new BtAnnotateAtom() ) ); } }