void collect() { collectGeneratedCandidateMethods(getTypeElement()); Instantiator encodingInstantiator = protoclass.encodingInstantiator(); @Nullable InstantiationCreator instantiationCreator = encodingInstantiator.creatorFor((Parameterizable) type.element); for (ValueAttribute attribute : attributes) { attribute.initAndValidate(instantiationCreator); } if (instantiationCreator != null) { type.additionalImports(instantiationCreator.imports); } type.attributes.addAll(attributes); type.accessorMapping = accessorMapping; }
private void printFormalTypeParameters(Parameterizable e, boolean pad) { List<? extends TypeParameterElement> typeParams = e.getTypeParameters(); if (typeParams.size() > 0) { writer.print("<"); boolean first = true; for(TypeParameterElement tpe: typeParams) { if (!first) writer.print(", "); printAnnotationsInline(tpe); writer.print(tpe.toString()); first = false; } writer.print(">"); if (pad) writer.print(" "); } }
private TypeExtractor getTypeExtractor() { if (typeExtractor == null) { this.typeExtractor = new TypeExtractor( Proto.TYPE_FACTORY, (Parameterizable) element); } return typeExtractor; }
private Type.Parameters initParameters(Parameterizable context) { Type.Parameters parameters = factory.parameters(); for (TypeParameterElement p : context.getTypeParameters()) { String name = p.getSimpleName().toString(); // <T extends Cls<T>>: when parsing bounds for T, T should be already defined for recursion Type.Parameters parameterForRecursion = parameters.recursive(name); List<Type.Defined> bounds = getBounds(parameterForRecursion, p); parameters = parameters.introduce(name, bounds); } return parameters; }
private List<String> getTypeParameterNames(Parameterizable element) { List<String> names = new ArrayList<>(); for (TypeParameterElement p : element.getTypeParameters()) { names.add(p.getSimpleName().toString()); } return names; }
private static int findTypeArgInList(Parameterizable hasTypeParams, String typeArgName) { List<? extends TypeParameterElement> typeParameters = hasTypeParams.getTypeParameters(); for (int i = 0; i < typeParameters.size(); i++) { if (typeParameters.get(i).getSimpleName().contentEquals(typeArgName)) { return i; } } return -1; }
public TypeExtractor(Type.Factory factory, Parameterizable context) { this.factory = factory; this.parameters = initParameters(context); this.parser = new Type.Parser(factory, parameters); }
public @Nullable InstantiationCreator creatorFor(Parameterizable element) { return !isEmpty() ? new InstantiationCreator(element) : null; }
InstantiationCreator(Parameterizable parameterizable) { this.typeExtractor = new TypeExtractor(typeFactory, parameterizable); }