/** * {@inheritDoc} */ public MethodDefinition.ImplementationDefinition<S> constructor(ElementMatcher<? super MethodDescription> matcher) { return invokable(isConstructor().and(matcher)); }
/** * Specifies that any constructor that matches the specified matcher should be removed. * * @param matcher The matcher that decides upon constructor removal. * @return A new member removal instance that removes all previously specified members and any constructor that matches the specified matcher. */ public MemberRemoval stripConstructors(ElementMatcher<? super MethodDescription> matcher) { return stripInvokables(isConstructor().and(matcher)); }
/** * Matches a default constructor, i.e. a constructor without arguments. * * @param <T> The type of the matched object. * @return A matcher that matches a default constructor. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> isDefaultConstructor() { return isConstructor().and(takesArguments(0)); }
/** * Defines a new method visitor wrapper to be applied on any constructor if the given method matcher is matched. * Previously defined entries are applied before the given matcher is applied. * * @param matcher The matcher to identify constructors to be wrapped. * @param methodVisitorWrappers The method visitor wrapper to be applied if the given matcher is matched. * @return A new ASM visitor wrapper that applied the given method visitor wrapper if the supplied matcher is matched. */ public ForDeclaredMethods constructor(ElementMatcher<? super MethodDescription> matcher, List<? extends MethodVisitorWrapper> methodVisitorWrappers) { return invokable(isConstructor().and(matcher), methodVisitorWrappers); }
/** * Substitutes any constructor invocation that matches the given matcher. * * @param matcher The matcher to determine what constructors to substitute. * @return A specification that allows to determine how to substitute any constructor invocations that match the supplied matcher. */ public WithoutSpecification constructor(ElementMatcher<? super MethodDescription> matcher) { return invokable(isConstructor().and(matcher)); }
/** * Adjusts a constructor's modifiers if it fulfills the supplied matcher. * * @param matcher The matcher that determines if a constructor's modifiers should be adjusted. * @param modifierContributors The modifier contributors to enforce. * @return A new modifier adjustment that enforces the given modifier contributors and any previous adjustments. */ public ModifierAdjustment withConstructorModifiers(ElementMatcher<? super MethodDescription> matcher, List<? extends ModifierContributor.ForMethod> modifierContributors) { return withInvokableModifiers(isConstructor().and(matcher), modifierContributors); }
/** * Creates the constructor call singleton. */ ConstructorCall() { objectTypeDefaultConstructor = TypeDescription.OBJECT.getDeclaredMethods().filter(isConstructor()).getOnly(); }
/** * Creates the constructor call singleton. */ StaticFieldConstructor() { objectTypeDefaultConstructor = TypeDescription.OBJECT.getDeclaredMethods().filter(isConstructor()).getOnly(); }
/** * Creates a new executing transformer implementation. */ ConstructorImplementation() { objectConstructor = TypeDescription.OBJECT.getDeclaredMethods().filter(isConstructor()).getOnly(); }
/** * {@inheritDoc} */ public List<MethodDescription.Token> extractConstructors(TypeDescription instrumentedType) { if (instrumentedType.getSuperClass().getDeclaredMethods().filter(isConstructor()).isEmpty()) { throw new IllegalStateException("Cannot define default constructor for class without super class constructor"); } return Collections.singletonList(new MethodDescription.Token(Opcodes.ACC_PUBLIC)); }
@Override public MethodRegistry doInject(MethodRegistry methodRegistry, MethodAttributeAppender.Factory methodAttributeAppenderFactory) { return methodRegistry.append(new LatentMatcher.Resolved<MethodDescription>(isConstructor()), new MethodRegistry.Handler.ForImplementation(SuperMethodCall.INSTANCE), methodAttributeAppenderFactory, Transformer.NoOp.<MethodDescription>make()); } },
@Override public MethodRegistry doInject(MethodRegistry methodRegistry, MethodAttributeAppender.Factory methodAttributeAppenderFactory) { return methodRegistry.append(new LatentMatcher.Resolved<MethodDescription>(isConstructor()), new MethodRegistry.Handler.ForImplementation(SuperMethodCall.INSTANCE), methodAttributeAppenderFactory, Transformer.NoOp.<MethodDescription>make()); } },
@Override public MethodRegistry doInject(MethodRegistry methodRegistry, MethodAttributeAppender.Factory methodAttributeAppenderFactory) { return methodRegistry.append(new LatentMatcher.Resolved<MethodDescription>(isConstructor()), new MethodRegistry.Handler.ForImplementation(SuperMethodCall.INSTANCE), methodAttributeAppenderFactory, Transformer.NoOp.<MethodDescription>make()); }
@Override protected MethodRegistry doInject(MethodRegistry methodRegistry, MethodAttributeAppender.Factory methodAttributeAppenderFactory) { return methodRegistry.append(new LatentMatcher.Resolved<MethodDescription>(isConstructor()), new MethodRegistry.Handler.ForImplementation(SuperMethodCall.INSTANCE), methodAttributeAppenderFactory, Transformer.NoOp.<MethodDescription>make()); } },
/** * Creates a new construction delegate that calls a default constructor. * * @param throwableType The type of the {@link Throwable}. */ public ForDefaultConstructor(TypeDescription throwableType) { this.throwableType = throwableType; this.targetConstructor = throwableType.getDeclaredMethods() .filter(isConstructor().and(takesArguments(0))).getOnly(); }
@Override protected List<MethodDescription.Token> doExtractConstructors(TypeDescription instrumentedType) { TypeDescription.Generic superClass = instrumentedType.getSuperClass(); MethodList<?> defaultConstructors = superClass == null ? new MethodList.Empty<MethodDescription.InGenericShape>() : superClass.getDeclaredMethods().filter(isConstructor().and(takesArguments(0)).<MethodDescription>and(isVisibleTo(instrumentedType))); if (defaultConstructors.size() == 1) { return Collections.singletonList(new MethodDescription.Token(Opcodes.ACC_PUBLIC)); } else { throw new IllegalArgumentException(instrumentedType.getSuperClass() + " declares no constructor that is visible to " + instrumentedType); } }
/** * Creates the singleton instance. */ @SuppressFBWarnings(value = "SE_BAD_FIELD_STORE", justification = "Fields of enumerations are never serialized") AbstractMethodErrorThrow() { TypeDescription abstractMethodError = TypeDescription.ForLoadedType.of(AbstractMethodError.class); MethodDescription constructor = abstractMethodError.getDeclaredMethods() .filter(isConstructor().and(takesArguments(0))).getOnly(); implementation = new Compound(TypeCreation.of(abstractMethodError), Duplication.SINGLE, MethodInvocation.invoke(constructor), Throw.INSTANCE); }
@Override protected List<MethodDescription.Token> doExtractConstructors(TypeDescription instrumentedType) { TypeDescription.Generic superClass = instrumentedType.getSuperClass(); return (superClass == null ? new MethodList.Empty<MethodDescription.InGenericShape>() : superClass.getDeclaredMethods().filter(isConstructor().and(isVisibleTo(instrumentedType)))).asTokenList(is(instrumentedType)); }
@Override protected List<MethodDescription.Token> doExtractConstructors(TypeDescription instrumentedType) { TypeDescription.Generic superClass = instrumentedType.getSuperClass(); return (superClass == null ? new MethodList.Empty<MethodDescription.InGenericShape>() : superClass.getDeclaredMethods().filter(isPublic().and(isConstructor()))).asTokenList(is(instrumentedType)); }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { TypeDescription forwardingType = implementationContext.register(this); return new Compound( TypeCreation.of(forwardingType), Duplication.SINGLE, MethodVariableAccess.allArgumentsOf(sourceMethod), MethodInvocation.invoke(forwardingType.getDeclaredMethods().filter(isConstructor()).getOnly()) ).apply(methodVisitor, implementationContext); }