eclipse-archived / ceylon.formatter

A formatter for the Ceylon programming language, written in Ceylon.
Apache License 2.0
14 stars 11 forks source link

Redesign FormattingOptions #4

Closed lucaswerkmeister closed 11 years ago

lucaswerkmeister commented 11 years ago

Currently, FormattingOptions and SparseFormattingOptions are abstract. The intended use was to combine a defaultOptions object with built-on-the-fly SparseFormattingOptions using CombinedOptions; however, I see now that this plan is in the current design impossible, because any object extends SparseFormattingOptions would have to explicitly set each unused attribute to null, which was not the original intention.

Instead, I propose the following:

i.e. instead of a separate defaultOptions object, use Ceylon's built-in default attribute mechanism.

This will also allow users to actually create sparse option objects like this:

SparseFormattingOptions {
    optionX=someX;
    // keep optionY
    ...
}

and then combine them with default (e.g. company-issued) options, or just use the default options by using the FormattingOptions class instead of the SparseFormattingOptions class.

lucaswerkmeister commented 11 years ago

Actually... FormattingOptions should of course extend SparseFormattingOptions {optionX=defaultX; ... }. Which leaves FormattingOptions' argument list open... I'm kinda in favour of "empty".

lucaswerkmeister commented 11 years ago

Well, seeing as apparently

  1. I can't use named arguments when specifying the superclass, and
  2. just writing shared actual TypeX optionX; gives the error "forward declaration may not occur in declaration section: indentMode"

I can't write extends SparseFormattingOptions { ... }, but instead have to extends SparseFormattingOptions() { ... }. Meh...

lucaswerkmeister commented 11 years ago

And given that, I have again two options for FormattingOptions:

shared class FormattingOptions(
        indentMode = Spaces(4)) extends SparseFormattingOptions() {

    shared actual default IndentMode indentMode;
}

vs

shared class FormattingOptions() extends SparseFormattingOptions() {

    shared actual default IndentMode indentMode = Spaces(4);
}

where the latter one obviously has the advantage that you can refine the default options (that would be FormattingOptions()) without using CombinedOptions, just like this:

FormattingOptions {
    indentMode = Mixed(Tabs(8), Spaces(4));
    // refine some other options
    // keep the rest
}

I think I'm leaning towards the latter option.

This issue is tagged request for comments. If anyone else is reading this while the issue is still open, please comment! I feel lonely populating these issues all by myself... :-(