Refine search
/** * An element matcher that matches any setter for the given property. When given an empty string, any setter named {@code set} * is matched despite that such a setter is not fulfilling the Java bean naming conventions. * * @param property The property to match a setter for. * @param <T> The type of the matched object. * @return A matcher that matches any setter method for the supplied property. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> isSetter(String property) { return isSetter().and(property.length() == 0 ? named("set") : named("set" + Character.toUpperCase(property.charAt(0)) + property.substring(1))); }
/** * An element matcher that matches any getter for the given property. When given an empty string, any getter named {@code get} * is matched despite that such a getter is not fulfilling the Java bean naming conventions. If a getter's type is {@code boolean} * or {@link Boolean}, {@code is} is also accepted as a prefix. * * @param property The property to match a getter for. * @param <T> The type of the matched object. * @return A matcher that matches any getter method for the supplied property. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> isGetter(String property) { return isGetter().and(property.length() == 0 ? named("get").or(named("is")) : named("get" + Character.toUpperCase(property.charAt(0)) + property.substring(1)).or(named("is" + Character.toUpperCase(property.charAt(0)) + property.substring(1)))); }
/** * Only matches the {@link Object#clone()} method, also if it was overridden. * * @param <T> The type of the matched object. * @return A matcher that only matches the {@link Object#clone()} method. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> isClone() { return named("clone").and(takesArguments(0)); }
/** * Only matches the {@link Object#toString()} method, also if it was overridden. * * @param <T> The type of the matched object. * @return A matcher that only matches the {@link Object#toString()} method. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> isHashCode() { return named("hashCode").and(takesArguments(0)).and(returns(int.class)); }
/** * Only matches the {@link Object#equals(Object)} method, also if it was overridden. * * @param <T> The type of the matched object. * @return A matcher that only matches the {@link Object#equals(Object)} method. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> isEquals() { return named("equals").and(takesArguments(TypeDescription.OBJECT)).and(returns(boolean.class)); }
/** * Only matches the {@link Object#toString()} method, also if it was overridden. * * @param <T> The type of the matched object. * @return A matcher that only matches the {@link Object#toString()} method. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> isToString() { return named("toString").and(takesArguments(0)).and(returns(TypeDescription.STRING)); }
/** * Only matches the {@link Object#finalize()} method, even if it was overridden. * * @param <T> The type of the matched object. * @return A matcher that only matches the {@link Object#finalize()} method. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> isFinalizer() { return named("finalize").and(takesArguments(0)).and(returns(TypeDescription.VOID)); }
@Override protected FieldDescription resolve(TypeDescription instrumentedType) { if (!fieldType.asErasure().isVisibleTo(instrumentedType)) { throw new IllegalStateException(fieldType + " is not visible to " + instrumentedType); } else { return instrumentedType.getDeclaredFields() .filter(named(fieldName).and(fieldType(fieldType.asErasure()))) .getOnly(); } } }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Context implementationContext, MethodDescription instrumentedMethod) { return ForInstance.this.apply(methodVisitor, implementationContext, instrumentedMethod, StackManipulation.Trivial.INSTANCE, instrumentedType.getDeclaredFields().filter(named(fieldName).and(genericFieldType(INVOCATION_HANDLER_TYPE))).getOnly()); } }
/** * Makes sure that this transformer is only applied on Freemarker versions {@code >= 2.3.23} where the * {@link Environment#getCurrentTemplate()} method was made public. This prevents nasty * {@link IllegalAccessError}s and {@link NoSuchMethodError}s. */ @Override public boolean isActive() { try { return hasMethodThat(named("getCurrentTemplate") .and(ElementMatchers.<MethodDescription.InDefinedShape>isPublic()) .and(takesArguments(0))) .matches(new TypeDescription.ForLoadedType(Class.forName("freemarker.core.Environment"))); } catch (ClassNotFoundException e) { return false; } }
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(); }
private AnnotatedFieldDescription findField(String owner, String name, String desc) { //Classpool#describe does not accept '/' in the description name as it expects a class name final String cleanedOwner = owner.replace( '/', '.' ); final TypePool.Resolution resolution = classPool.describe( cleanedOwner ); if ( !resolution.isResolved() ) { final String msg = String.format( "Unable to perform extended enhancement - Unable to locate [%s]", cleanedOwner ); throw new EnhancementException( msg ); } FieldList<?> fields = resolution.resolve().getDeclaredFields().filter( named( name ).and( hasDescriptor( desc ) ) ); if ( fields.size() != 1 ) { final String msg = String.format( "Unable to perform extended enhancement - No unique field [%s] defined by [%s]", name, cleanedOwner ); throw new EnhancementException( msg ); } return new AnnotatedFieldDescription( enhancementContext, fields.getOnly() ); }