Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
Completely fix formatter config inlineAnnotations
Browse files Browse the repository at this point in the history
The previous fix (677b021) wasn't enough - it still broke when the
option was 'all'. To truly fix this, we need to be able to disable the
text preference when it's created, before its listeners are attached.
(Some other tabs can apparently enable and disable preferences during
initialization without update problems - my best guess is that it's only
problematic for string properties, but I didn't investigate it too
much.)

Also, the handling of this "union" option was pretty broken. Now we
simply display 'all' in the text field when 'all' is checked (which makes
sense because that's what we'll write to the config file). When that
checkbox is unchecked, we insert the default inline annotations into the
textfield.

Also fixes the validity test. It's allowed to declare any annotations as
inline, so we shouldn't have a list of "allowed" annotations; instead,
we now only check if it's a valid annotation name.

Includes a workaround for ceylon/ceylon-spec#1106.
  • Loading branch information
lucaswerkmeister committed Oct 2, 2014
1 parent b67e224 commit 9da356a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,4 @@ public class CeylonFormatterConstants {
// required for preview setup
public static final String FORMATTER_LINE_SPLIT = "lineSplit";
public static final String FORMATTER_TAB_SIZE = "tabSize";

public static final List<String> acceptedInlineAnnotations = Collections.unmodifiableList(
Arrays.asList(new String[] { "abstract",
"actual", "annotation", "default", "final", "formal", "late",
"native", "optional", "shared", "variable" }));
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import static com.redhat.ceylon.eclipse.code.style.CeylonFormatterConstants.*;

import org.apache.commons.lang.StringUtils;

import ceylon.formatter.options.FormattingOptions;
import ceylon.formatter.options.IndentMode;
import ceylon.formatter.options.Mixed;
Expand Down Expand Up @@ -35,7 +33,6 @@ public class FormatterPreferences {
private VariableOptions options;
private String space_AfterParamListClosingParen_Number;
private String maxLineLength_Number;
private String inlineAnnotations_List;

public FormatterPreferences(FormattingOptions options) {
this.options = new VariableOptions(options);
Expand Down Expand Up @@ -236,16 +233,12 @@ public String get(String key) {
}
break;
case FORMATTER_inlineAnnotations_List:
if (! (options.getInlineAnnotations() instanceof ceylon.formatter.options.All)) {
if (options.getInlineAnnotations() instanceof ceylon.formatter.options.All) {
ret = "all";
} else {
@SuppressWarnings("unchecked") // checked by Ceylon type info
ceylon.language.Iterable<? extends String, ? extends Object> it = (ceylon.language.Iterable<? extends String, ? extends Object>)options.getInlineAnnotations();
ret = ceylon.language.String.join(",", it);
this.inlineAnnotations_List = ret; // save
}
if (this.inlineAnnotations_List != null) {
ret = this.inlineAnnotations_List;
} else {
ret = StringUtils.join(acceptedInlineAnnotations, ',');
}
break;
case FORMATTER_lineBreak:
Expand Down Expand Up @@ -471,16 +464,19 @@ public void put(String key, String value) {
if (TRUE.equals(value)) {
options.setInlineAnnotations(all_.get_());
} else {
if (this.inlineAnnotations_List == null) {
options.setInlineAnnotations(StringUtils.join(acceptedInlineAnnotations, ','));
} else {
options.setInlineAnnotations(acceptedInlineAnnotations.toArray());
}
options.setInlineAnnotations(FormattingOptions.$default$inlineAnnotations(null, null, null, null, null, null, null, null));
}
break;
case FORMATTER_inlineAnnotations_List:
String[] anns = value == null ? new String[] {} : value.split(",");
options.setInlineAnnotations(anns);
if (value == null) {
options.setInlineAnnotations(all_.get_());
} else {
if (value.equals("all")) {
options.setInlineAnnotations(all_.get_());
} else {
options.setInlineAnnotations(ceylon.language.String.split(value.replace(',', ' ')).sequence()); // TODO remove .sequence() when ceylon/ceylon-spec#1106 is fixed
}
}
break;
case FORMATTER_lineBreak:
if (ceylon.formatter.options.lf_.get_().toString().equals(value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,24 @@ protected void doCreatePreferences(Composite composite, int numColumns) {
public String isValid(String l) {
String[] tokens = l.split(",");
for (String token : tokens) {
if (!acceptedInlineAnnotations.contains(token.trim())) {
return "Invalid Annotation: " + token;
for (int i = 0; i < token.length(); i += Character.isBmpCodePoint(i) ? 1 : 2) {
int cp = token.codePointAt(i);
if (!Character.isLetterOrDigit(cp) && cp != '_'
|| Character.isUpperCase(cp)
|| i == 0 && Character.isDigit(cp)) {
StringBuilder ret = new StringBuilder();
ret.append("Invalid character in annotation name: \'");
ret.appendCodePoint(cp);
ret.append('\'');
return ret.toString();
}
}
}
return null;
}
});
},
/* enabled = */ !allAnnotations.getChecked());

if (allAnnotations.getChecked()) {
annotationsList.setEnabled(false);
}

allAnnotations.addObserver(new Observer() {
public void update(Observable o, Object arg) {
updatePreferences((String) arg, annotationsList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -973,8 +973,16 @@ protected NumberPreference createCompactNumberPref(Composite composite,
protected StringPreference createStringPref(Composite composite,
int numColumns, String name, String key,
IInputValidator inputValidator) {
return createStringPref(composite, numColumns, name, key, inputValidator, true);
}

protected StringPreference createStringPref(Composite composite,
int numColumns, String name, String key,
IInputValidator inputValidator, boolean enabled) {
StringPreference pref = new StringPreference(composite, numColumns,
workingValues, key, name, inputValidator);
if (!enabled)
pref.setEnabled(false);
fDefaultFocusManager.add(pref);
pref.addObserver(fUpdater);
return pref;
Expand Down

0 comments on commit 9da356a

Please sign in to comment.