/** * Append a referency type * * @param type Type to append * @param nullable Nullness of type * @param output Output to append to * @param <A> Type of output * @return Supplied output to append to */ public <A extends Appendable> A appendReferenceTypeSignature(Generic type, Nullness nullable, A output) { try { if (type.isArray()) { appendArrayTypeSignature(type, nullable, output); } else if (type.getSort() == Sort.VARIABLE) { appendTypeVariableSignature(type, nullable, output); } else { appendClassTypeSignature(type, nullable, output); } return output; } catch (Exception e) { throw new RuntimeException(String.format("Could not write reference type signature %s", type)); } }
/** * Append a type * * @param type Type to append * @param nullable Nullness of type * @param output Output to append to * @param <A> Type of output * @return Supplied output to append to */ public <A extends Appendable> A appendJavaTypeSignature(Generic type, Nullness nullable, A output) { try { if (type.isPrimitive()) { appendBaseType(type, output); } else { appendReferenceTypeSignature(type, nullable, output); } return output; } catch (Exception e) { throw new RuntimeException(String.format("Could not write java type signature %s", type)); } }
/** * Append a method signature * * @param method Method to append signature of * @param output Output to append to * @param <A> Type of output * @return Supplied output to append to */ public <A extends Appendable> A appendMethodSignature(MethodDescription method, A output) { try { if (!method.getTypeVariables().isEmpty()) { appendTypeParameters(method.getTypeVariables(), output); } output.append('('); for (ParameterDescription parameter : method.getParameters()) { Nullness nullable = this.nullability.getParameterNullability(parameter); appendJavaTypeSignature(parameter.getType(), nullable, output); } output.append(')'); Nullness nullable = this.nullability.getReturnValueNullability(method); appendJavaTypeSignature(method.getReturnType(), nullable, output); return output; } catch (Exception e) { throw new RuntimeException(String.format("Could not write method signature %s", method)); } }
appendPackageSpecifier(pakkage, output); appendSimpleClassTypeSignature(ownerType, output); output.append('.'); appendSimpleClassTypeSignature(type, output);
MethodSignatureWriter annotatedSignatureWriter = new MethodSignatureWriter(this.nullability); StringBuilder buf = new StringBuilder(); String plainSignature = this.signatureWriter.appendMethodSignature(method, new StringBuilder()) .toString(); String annotatedSignature = annotatedSignatureWriter.appendMethodSignature(method, new StringBuilder()) .toString();
/** * Append a class or interface bound * * @param bound Bound to append * @param output Output to append to * @param <A> Type of output * @return Supplied output to append to */ public <A extends Appendable> A appendClassOrInterfaceBound(Generic bound, A output) { try { output.append(':'); appendReferenceTypeSignature(bound, Nullness.UNDEFINED, output); return output; } catch (Exception e) { throw new RuntimeException(String.format("Could write class or interface bound %s", bound)); } }
/** * Append an array type signature * * @param type Array type to append * @param nullable Nullness of type * @param output Output to append to * @param <A> Type of output * @return Supplied output to append to */ public <A extends Appendable> A appendArrayTypeSignature(Generic type, Nullness nullable, A output) { try { output.append('[').append(nullable.getMarker()); appendJavaTypeSignature(Validate.notNull(type.getComponentType()), Nullness.UNDEFINED, output); return output; } catch (Exception e) { throw new RuntimeException(String.format("Could not write array type %s", type)); } }
/** * Append a type parameter * * @param typeParameter Type parameters to append * @param output Output to append to * @param <A> Type of output * @return Supplied output to append to */ public <A extends Appendable> A appendTypeParameter(Generic typeParameter, A output) { try { output.append(typeParameter.getSymbol()); TypeList.Generic upperBounds = typeParameter.getUpperBounds(); if (upperBounds.size() == 0) { throw new IllegalArgumentException( String.format("Type parameter '%s' must have upper bounds", typeParameter)); } if (upperBounds.get(0).isInterface()) { output.append(':'); } for (Generic upperBound : upperBounds) { appendClassOrInterfaceBound(upperBound, output); } return output; } catch (Exception e) { throw new RuntimeException(String.format("Could not write type parameter %s", typeParameter)); } }
/** * Append a method signature * * @param method Method to append signature of * @param output Output to append to * @param <A> Type of output * @return Supplied output to append to */ public <A extends Appendable> A appendMethodSignature(MethodDescription method, A output) { try { if (!method.getTypeVariables().isEmpty()) { appendTypeParameters(method.getTypeVariables(), output); } output.append('('); for (ParameterDescription parameter : method.getParameters()) { Nullness nullable = this.nullability.getParameterNullability(parameter); appendJavaTypeSignature(parameter.getType(), nullable, output); } output.append(')'); Nullness nullable = this.nullability.getReturnValueNullability(method); appendJavaTypeSignature(method.getReturnType(), nullable, output); return output; } catch (Exception e) { throw new RuntimeException(String.format("Could not write method signature %s", method)); } }
appendPackageSpecifier(pakkage, output); appendSimpleClassTypeSignature(ownerType, output); output.append('.'); appendSimpleClassTypeSignature(type, output);
MethodSignatureWriter annotatedSignatureWriter = new MethodSignatureWriter(this.nullability); StringBuilder buf = new StringBuilder(); String plainSignature = this.signatureWriter.appendMethodSignature(method, new StringBuilder()) .toString(); String annotatedSignature = annotatedSignatureWriter.appendMethodSignature(method, new StringBuilder()) .toString();
/** * Append a class or interface bound * * @param bound Bound to append * @param output Output to append to * @param <A> Type of output * @return Supplied output to append to */ public <A extends Appendable> A appendClassOrInterfaceBound(Generic bound, A output) { try { output.append(':'); appendReferenceTypeSignature(bound, Nullness.UNDEFINED, output); return output; } catch (Exception e) { throw new RuntimeException(String.format("Could write class or interface bound %s", bound)); } }
/** * Append an array type signature * * @param type Array type to append * @param nullable Nullness of type * @param output Output to append to * @param <A> Type of output * @return Supplied output to append to */ public <A extends Appendable> A appendArrayTypeSignature(Generic type, Nullness nullable, A output) { try { output.append('[').append(nullable.getMarker()); appendJavaTypeSignature(Validate.notNull(type.getComponentType()), Nullness.UNDEFINED, output); return output; } catch (Exception e) { throw new RuntimeException(String.format("Could not write array type %s", type)); } }
/** * Append a type parameter * * @param typeParameter Type parameters to append * @param output Output to append to * @param <A> Type of output * @return Supplied output to append to */ public <A extends Appendable> A appendTypeParameter(Generic typeParameter, A output) { try { output.append(typeParameter.getSymbol()); TypeList.Generic upperBounds = typeParameter.getUpperBounds(); if (upperBounds.size() == 0) { throw new IllegalArgumentException( String.format("Type parameter '%s' must have upper bounds", typeParameter)); } if (upperBounds.get(0).isInterface()) { output.append(':'); } for (Generic upperBound : upperBounds) { appendClassOrInterfaceBound(upperBound, output); } return output; } catch (Exception e) { throw new RuntimeException(String.format("Could not write type parameter %s", typeParameter)); } }
/** * Append a referency type * * @param type Type to append * @param nullable Nullness of type * @param output Output to append to * @param <A> Type of output * @return Supplied output to append to */ public <A extends Appendable> A appendReferenceTypeSignature(Generic type, Nullness nullable, A output) { try { if (type.isArray()) { appendArrayTypeSignature(type, nullable, output); } else if (type.getSort() == Sort.VARIABLE) { appendTypeVariableSignature(type, nullable, output); } else { appendClassTypeSignature(type, nullable, output); } return output; } catch (Exception e) { throw new RuntimeException(String.format("Could not write reference type signature %s", type)); } }
/** * Append a type * * @param type Type to append * @param nullable Nullness of type * @param output Output to append to * @param <A> Type of output * @return Supplied output to append to */ public <A extends Appendable> A appendJavaTypeSignature(Generic type, Nullness nullable, A output) { try { if (type.isPrimitive()) { appendBaseType(type, output); } else { appendReferenceTypeSignature(type, nullable, output); } return output; } catch (Exception e) { throw new RuntimeException(String.format("Could not write java type signature %s", type)); } }
appendReferenceTypeSignature(typeArgument.getLowerBounds().get(0), Nullness.UNDEFINED, output); appendReferenceTypeSignature(upperBounds.get(0), Nullness.UNDEFINED, output); appendReferenceTypeSignature(typeArgument, Nullness.UNDEFINED, output);
appendReferenceTypeSignature(typeArgument.getLowerBounds().get(0), Nullness.UNDEFINED, output); appendReferenceTypeSignature(upperBounds.get(0), Nullness.UNDEFINED, output); appendReferenceTypeSignature(typeArgument, Nullness.UNDEFINED, output);