private static boolean isOutputType(TypeName type) { return type.equals(OUTPUT) || (type instanceof ParameterizedTypeName && ((ParameterizedTypeName) type).rawType.equals(OUTPUT)); }
private static boolean isStateValueType(TypeName type) { return type.equals(STATE_VALUE) || (type instanceof ParameterizedTypeName && ((ParameterizedTypeName) type).rawType.equals(STATE_VALUE)); }
public static boolean isAnnotatedWithExternalAnnotation( MethodParamModel methodParamModel, TypeName annotationType) { for (AnnotationSpec annotation : methodParamModel.getExternalAnnotations()) { if (annotation.type.equals(annotationType)) { return true; } } return false; }
@Override public boolean equals(Object o) { if (o instanceof PropDefaultModel) { final PropDefaultModel p = (PropDefaultModel) o; return mType.equals(p.mType) && mName.equals(p.mName) && mModifiers.equals(p.mModifiers) && mResType == p.mResType && mResId == p.mResId; } return false; }
private static List<MethodParamModel> findComponentsInImpl(SpecModel specModel) { final List<MethodParamModel> componentsInImpl = new ArrayList<>(); for (PropModel prop : specModel.getProps()) { TypeName typeName = prop.getTypeName(); if (typeName instanceof ParameterizedTypeName) { typeName = ((ParameterizedTypeName) typeName).rawType; } if (typeName.equals(ClassNames.COMPONENT) || typeName.equals(ClassNames.SECTION)) { componentsInImpl.add(prop); } } return componentsInImpl; }
@Override public void addToBuilder(@NonNull TypeSpec.Builder builder, @NonNull ClassName builderName, @NonNull CodeBlock.Builder constructorAlways, @NonNull CodeBlock.Builder constructorWhenAnnotationPresent, CodeBlock.Builder constructorWhenAnnotationMissing) { final MethodSpec.Builder method = baseMethod(builderName); if (getType().equals(TypeName.VOID)) { method.addStatement("$L.$L($L)", Strings.FIELD_DELEGATE, getName(), parameters.stream().map(p -> p.name).collect(Collectors.joining(", "))) .addStatement("return this"); } else { method.addStatement("return $L.$L($L)", Strings.FIELD_DELEGATE, getName(), parameters.stream().map(p -> p.name).collect(Collectors.joining(", "))); } builder.addMethod(method.build()); }
@Override CodeWriter emit(CodeWriter out) throws IOException { if (lowerBounds.size() == 1) { return out.emit("? super $T", lowerBounds.get(0)); } return upperBounds.get(0).equals(TypeName.OBJECT) ? out.emit("?") : out.emit("? extends $T", upperBounds.get(0)); }
static List<SpecModelValidationError> validateGetMountType(MountSpecModel specModel) { List<SpecModelValidationError> validationErrors = new ArrayList<>(); if (!specModel.getMountType().equals(ClassNames.COMPONENT_LIFECYCLE_MOUNT_TYPE_DRAWABLE) && !specModel.getMountType().equals(ClassNames.COMPONENT_LIFECYCLE_MOUNT_TYPE_VIEW)) { validationErrors.add( new SpecModelValidationError( specModel.getRepresentedObject(), "onCreateMountContent's return type should be either a View or a Drawable " + "subclass.")); } return validationErrors; }
/** * @return true if this prop has a default specified in the given set of defaults, false * otherwise. */ public boolean hasDefault(ImmutableList<PropDefaultModel> propDefaults) { for (PropDefaultModel propDefault : propDefaults) { if (propDefault.mType.equals(mParamModel.getTypeName()) && propDefault.mName.equals(mParamModel.getName())) { return true; } } return false; }
private static boolean isFromEventTypeSpecifiedInAnnotation( MethodParamModel methodParamModel, TypeName eventFieldType) { FromEvent fromEvent = (FromEvent) MethodParamModelUtils.getAnnotation(methodParamModel, FromEvent.class); TypeName baseClassType; try { baseClassType = ClassName.get(fromEvent.baseClass()); } catch (MirroredTypeException mte) { baseClassType = ClassName.get(mte.getTypeMirror()); } return baseClassType.equals(eventFieldType); } }
/** * We consider an optional parameter as something that comes immediately after defined parameters * and is not a special litho parameter (like a prop, state, etc...). This method verifies that * optional parameters are the right type and have no additional annotations. */ private static boolean shouldIncludeOptionalParameter( MethodParamModel methodParamModel, MethodParamModel extraOptionalParameter) { return methodParamModel instanceof SimpleMethodParamModel && methodParamModel.getTypeName().equals(extraOptionalParameter.getTypeName()) && methodParamModel.getAnnotations().isEmpty(); }
static List<SpecModelValidationError> validateShouldUseDisplayLists(MountSpecModel specModel) { List<SpecModelValidationError> validationErrors = new ArrayList<>(); if (specModel.shouldUseDisplayList() && !specModel.getMountType().equals(ClassNames.COMPONENT_LIFECYCLE_MOUNT_TYPE_DRAWABLE)) { validationErrors.add( new SpecModelValidationError( specModel.getRepresentedObject(), "shouldUseDisplayList = true can only be used on MountSpecs that mount a drawable.")); } return validationErrors; } }
/** Compares two {@link MethodParamModel}s based on name and annotations only. */ public static Comparator<MethodParamModel> shallowParamComparator() { return Comparator.nullsLast( Comparator.comparing(MethodParamModel::getName) .thenComparing( (a, b) -> (a.getTypeName() == null && a.getTypeName() == b.getTypeName()) || a.getTypeName().equals(b.getTypeName()) ? 0 : -1) .thenComparing((a, b) -> a.getAnnotations().equals(b.getAnnotations()) ? 0 : -1)); } }
private static boolean hasMatchingField( MethodParamModel param, ImmutableList<FieldModel> fields) { for (FieldModel field : fields) { if (param.getName().equals(field.field.name) && (param.getTypeName().box().equals(field.field.type.box()) || isFromEventTypeSpecifiedInAnnotation(param, field.field.type))) { return true; } } return false; }
private static boolean definesStateValue(SpecModel specModel, String name, TypeName type) { for (StateParamModel stateValue : specModel.getStateValues()) { if (stateValue.getName().equals(name) && stateValue.getTypeName().box().equals(type.box())) { return true; } } return false; }
public static boolean isPropOutput(SpecModel specModel, MethodParamModel methodParamModel) { final PropModel prop = getPropWithName(specModel, methodParamModel.getName()); return prop != null && methodParamModel.getTypeName() instanceof ParameterizedTypeName && ((ParameterizedTypeName) methodParamModel.getTypeName()).rawType.equals(OUTPUT) && ((ParameterizedTypeName) methodParamModel.getTypeName()).typeArguments.size() == 1 && ((ParameterizedTypeName) methodParamModel.getTypeName()).typeArguments.get(0) .equals(prop.getTypeName().box()); }
/** * Compare a given {@link PropModel} to the underlying propmodel of this instance. If a cached * name is provided, it will override the check with the underlying model. */ public boolean isSameUnderlyingPropModel(PropModel propModel, @Nullable String cachedName) { return (propModel.getName().equals(getName()) || propModel.getName().equals(cachedName)) && propModel.getTypeName().box().equals(mUnderlyingPropModel.getTypeName().box()) && propModel.isOptional() == isOptional() && propModel.getResType() == getResType() && propModel.getVarArgsSingleName().equals(getVarArgsSingleName()); } }
public static boolean isStateOutput(SpecModel specModel, MethodParamModel methodParamModel) { final StateParamModel stateValue = SpecModelUtils.getStateValueWithName(specModel, methodParamModel.getName()); return stateValue != null && methodParamModel.getTypeName() instanceof ParameterizedTypeName && ((ParameterizedTypeName) methodParamModel.getTypeName()).rawType.equals(OUTPUT) && ((ParameterizedTypeName) methodParamModel.getTypeName()).typeArguments.size() == 1 && ((ParameterizedTypeName) methodParamModel.getTypeName()).typeArguments.get(0) .equals(stateValue.getTypeName().box()); }
public static boolean isStateValue(SpecModel specModel, MethodParamModel methodParamModel) { final StateParamModel stateValue = SpecModelUtils.getStateValueWithName(specModel, methodParamModel.getName()); return stateValue != null && methodParamModel.getTypeName() instanceof ParameterizedTypeName && ((ParameterizedTypeName) methodParamModel.getTypeName()).rawType .equals(ClassNames.STATE_VALUE) && ((ParameterizedTypeName) methodParamModel.getTypeName()).typeArguments.size() == 1 && ((ParameterizedTypeName) methodParamModel.getTypeName()).typeArguments.get(0) .equals(stateValue.getTypeName().box()); }
public boolean isSameUnderlyingStateValueModel(StateParamModel stateParamModel) { return stateParamModel.getName().equals(getName()) && stateParamModel.getTypeName().box().equals(mUnderlyingStateParamModel.getTypeName().box()) && stateParamModel.canUpdateLazily() == canUpdateLazily(); } }