/** * {@inheritDoc} */ public List<MethodDescription.Token> extractConstructors(TypeDescription instrumentedType) { List<MethodDescription.Token> tokens = doExtractConstructors(instrumentedType), stripped = new ArrayList<MethodDescription.Token>(tokens.size()); for (MethodDescription.Token token : tokens) { stripped.add(new MethodDescription.Token(token.getName(), resolveModifier(token.getModifiers()), token.getTypeVariableTokens(), token.getReturnType(), token.getParameterTokens(), token.getExceptionTypes(), token.getAnnotations(), token.getDefaultValue(), TypeDescription.Generic.UNDEFINED)); } return stripped; }
/** * {@inheritDoc} */ public WithFlexibleName withMethod(MethodDescription.Token token) { return new Default(name, modifiers, superClass, typeVariables, interfaceTypes, fieldTokens, CompoundList.of(methodTokens, token.accept(Generic.Visitor.Substitutor.ForDetachment.of(this))), annotationDescriptions, typeInitializer, loadedTypeInitializer, declaringType, enclosingMethod, enclosingType, declaredTypes, anonymousClass, localClass, nestHost, nestMembers); }
/** * {@inheritDoc} */ public MethodDescription.Token asToken(ElementMatcher<? super TypeDescription> matcher) { TypeDescription.Generic receiverType = getReceiverType(); return new MethodDescription.Token(getInternalName(), getModifiers(), getTypeVariables().asTokenList(matcher), getReturnType().accept(new TypeDescription.Generic.Visitor.Substitutor.ForDetachment(matcher)), getParameters().asTokenList(matcher), getExceptionTypes().accept(new TypeDescription.Generic.Visitor.Substitutor.ForDetachment(matcher)), getDeclaredAnnotations(), getDefaultValue(), receiverType == null ? TypeDescription.Generic.UNDEFINED : receiverType.accept(new TypeDescription.Generic.Visitor.Substitutor.ForDetachment(matcher))); }
/** * {@inheritDoc} */ public Token accept(TypeDescription.Generic.Visitor<? extends TypeDescription.Generic> visitor) { return new Token(name, modifiers, getTypeVariableTokens().accept(visitor), returnType.accept(visitor), getParameterTokens().accept(visitor), getExceptionTypes().accept(visitor), annotations, defaultValue, receiverType == null ? TypeDescription.Generic.UNDEFINED : receiverType.accept(visitor)); }
/** * Creates a new latent method description. All provided types are attached to this instance before they are returned. * * @param declaringType The declaring type of the method. * @param token A token representing the method's shape. */ public Latent(TypeDescription declaringType, MethodDescription.Token token) { this(declaringType, token.getName(), token.getModifiers(), token.getTypeVariableTokens(), token.getReturnType(), token.getParameterTokens(), token.getExceptionTypes(), token.getAnnotations(), token.getDefaultValue(), token.getReceiverType()); }
/** * {@inheritDoc} */ public MethodDescription.Token transform(TypeDescription instrumentedType, MethodDescription.Token target) { return new MethodDescription.Token(target.getName(), resolver.resolve(target.getModifiers()), target.getTypeVariableTokens(), target.getReturnType(), target.getParameterTokens(), target.getExceptionTypes(), target.getAnnotations(), target.getDefaultValue(), target.getReceiverType()); } }
/** * {@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 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); } }
/** * {@inheritDoc} */ public MethodDefinition.ParameterDefinition.Initial<U> defineMethod(String name, TypeDefinition returnType, int modifiers) { return new MethodDefinitionAdapter(new MethodDescription.Token(name, modifiers, returnType.asGenericType())); }
/** * {@inheritDoc} */ public int size() { return token.getParameterTokens().size(); } }
/** * {@inheritDoc} */ public int getModifiers() { return token.getModifiers(); }
/** * {@inheritDoc} */ public AnnotationList getDeclaredAnnotations() { return token.getAnnotations(); }
/** * {@inheritDoc} */ public ParameterDescription get(int index) { return new TransformedParameter(index, token.getParameterTokens().get(index)); }
/** * {@inheritDoc} */ public MethodDefinition.ParameterDefinition.Initial<U> defineConstructor(int modifiers) { return new MethodDefinitionAdapter(new MethodDescription.Token(modifiers)); }
/** * {@inheritDoc} */ public TypeDescription.Generic getReceiverType() { TypeDescription.Generic receiverType = token.getReceiverType(); return receiverType == null ? TypeDescription.Generic.UNDEFINED : receiverType.accept(new AttachmentVisitor()); }
/** * {@inheritDoc} */ public TypeList.Generic getExceptionTypes() { return new TypeList.Generic.ForDetachedTypes(token.getExceptionTypes(), new AttachmentVisitor()); }
/** * {@inheritDoc} */ public ElementMatcher<? super MethodDescription> resolve(TypeDescription typeDescription) { return new ResolvedMatcher(token.asSignatureToken(typeDescription)); }
/** * {@inheritDoc} */ public AnnotationValue<?, ?> getDefaultValue() { return token.getDefaultValue(); }
/** * {@inheritDoc} */ public String getInternalName() { return token.getName(); }