Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLDR-15381 Java formatting with prettier, tabWidth 4 #1911

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's… a little unusual and confusing to have a package.json at the top level. I think it might misrepresent what structure is underneath.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://prettier.io/docs/en/configuration.html could we use a .prettierrc.json file instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I think so

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that might make sense.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #1919

"prettier": {
"overrides": [
{
"files": ["*.java"],
"options": {
"tabWidth": 4
}
}
]
}
}
488 changes: 350 additions & 138 deletions tools/cldr-code/src/main/java/org/unicode/cldr/util/Annotations.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.ibm.icu.dev.util.UnicodeMap;

public class ApproximateWidth {

static UnicodeMap<Integer> data = new UnicodeMap<>();
static Integer defaultWidth;

Expand Down Expand Up @@ -35,14 +36,21 @@ public void handleComment(String line, int commentCharPosition) {
}

@Override
protected boolean handleLine(int lineCount, int start, int end, String[] items) {
protected boolean handleLine(
int lineCount,
int start,
int end,
String[] items
) {
data.putAll(start, end, Integer.parseInt(items[1]));
return true;
}

};

MyFileHander.process(ApproximateWidth.class, "data/ApproximateWidth.txt");
MyFileHander.process(
ApproximateWidth.class,
"data/ApproximateWidth.txt"
);
}

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Comparator;

public class ArrayComparator implements Comparator {

public static final Comparator COMPARABLE = new Comparator() {
@Override
public int compare(Object o1, Object o2) {
Expand All @@ -28,7 +29,9 @@ public ArrayComparator(Comparator[] comparators, int[] reordering) {
}
} else {
if (this.reordering.length != this.comparators.length) {
throw new IllegalArgumentException("comparator and reordering lengths must match");
throw new IllegalArgumentException(
"comparator and reordering lengths must match"
);
}
}
}
Expand Down Expand Up @@ -59,6 +62,7 @@ public int compare(Object a0, Object a1) {
}

static class CatchExceptionComparator implements Comparator {

private Comparator other;

public CatchExceptionComparator(Comparator other) {
Expand All @@ -76,5 +80,4 @@ public int compare(Object arg0, Object arg1) throws RuntimeException {
}
}
}

}
}

Large diffs are not rendered by default.

83 changes: 40 additions & 43 deletions tools/cldr-code/src/main/java/org/unicode/cldr/util/BNF.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package org.unicode.cldr.util;

import com.ibm.icu.text.UnicodeSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -14,9 +15,8 @@
import java.util.Random;
import java.util.Set;

import com.ibm.icu.text.UnicodeSet;

public class BNF {

private Map map = new HashMap();
private Set variables = new HashSet();
private Pick pick = null;
Expand Down Expand Up @@ -66,8 +66,7 @@ public BNF(Random random, Quoter quoter) {

public BNF addRules(String rules) {
t.setSource(rules);
while (addRule()) {
}
while (addRule()) {}
return this; // for chaining
}

Expand All @@ -79,12 +78,12 @@ public BNF complete() {
variables.addAll(t.getLookedUpItems());
if (!ruleSet.equals(variables)) {
String msg = showDiff(variables, ruleSet);
if (msg.length() != 0) msg = "Error: Missing definitions for: " + msg;
if (msg.length() != 0) msg =
"Error: Missing definitions for: " + msg;
String temp = showDiff(ruleSet, variables);
if (temp.length() != 0) temp = "Warning: Defined but not used: " + temp;
if (msg.length() == 0)
msg = temp;
else if (temp.length() != 0) {
if (temp.length() != 0) temp =
"Warning: Defined but not used: " + temp;
if (msg.length() == 0) msg = temp; else if (temp.length() != 0) {
msg = msg + "; " + temp;
}
error(msg);
Expand All @@ -95,9 +94,7 @@ else if (temp.length() != 0) {
if (msg.length() != 0) msg = "Missing definitions for: " + msg;
String temp = showDiff(ruleSet, variables);
if (temp.length() != 0) temp = "Defined but not used: " + temp;
if (msg.length() == 0)
msg = temp;
else if (temp.length() != 0) {
if (msg.length() == 0) msg = temp; else if (temp.length() != 0) {
msg = msg + "; " + temp;
}
error(msg);
Expand Down Expand Up @@ -140,8 +137,7 @@ String showDiff(Set a, Set b) {
}

void error(String msg) {
throw new IllegalArgumentException(msg
+ "\r\n" + t.toString());
throw new IllegalArgumentException(msg + "\r\n" + t.toString());
}

private boolean addRule() {
Expand Down Expand Up @@ -193,37 +189,37 @@ Pick qualify(Pick item) {
int[] weights;
int type = t.next();
switch (type) {
case '@':
return new Pick.Quote(item);
case '~':
return new Pick.Morph(item);
case '?':
int weight = getWeight();
if (weight == NO_WEIGHT) weight = 50;
weights = new int[] { 100 - weight, weight };
return Pick.repeat(0, 1, weights, item);
case '*':
weights = getWeights();
return Pick.repeat(1, maxRepeat, weights, item);
case '+':
weights = getWeights();
return Pick.repeat(1, maxRepeat, weights, item);
case '{':
if (t.next() != Tokenizer.NUMBER) error("missing number");
int start = (int) t.getNumber();
int end = start;
type = t.next();
if (type == ',') {
end = maxRepeat;
case '@':
return new Pick.Quote(item);
case '~':
return new Pick.Morph(item);
case '?':
int weight = getWeight();
if (weight == NO_WEIGHT) weight = 50;
weights = new int[] { 100 - weight, weight };
return Pick.repeat(0, 1, weights, item);
case '*':
weights = getWeights();
return Pick.repeat(1, maxRepeat, weights, item);
case '+':
weights = getWeights();
return Pick.repeat(1, maxRepeat, weights, item);
case '{':
if (t.next() != Tokenizer.NUMBER) error("missing number");
int start = (int) t.getNumber();
int end = start;
type = t.next();
if (type == Tokenizer.NUMBER) {
end = (int) t.getNumber();
if (type == ',') {
end = maxRepeat;
type = t.next();
if (type == Tokenizer.NUMBER) {
end = (int) t.getNumber();
type = t.next();
}
}
}
if (type != '}') error("missing }");
weights = getWeights();
return Pick.repeat(start, end, weights, item);
if (type != '}') error("missing }");
weights = getWeights();
return Pick.repeat(start, end, weights, item);
}
t.backup();
return item;
Expand Down Expand Up @@ -289,7 +285,8 @@ Pick getAlternation() {
last = temp;
lastWeight = weight;
} else {
if (result == null) result = Pick.makeAlternation().or2(lastWeight, last);
if (result == null) result =
Pick.makeAlternation().or2(lastWeight, last);
result = result.or2(weight, temp);
}
int token = t.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public static String toStringHelper(Object object) {
Object value = "no-access";
try {
value = fields[i].get(object);
} catch (Exception e) {
}
} catch (Exception e) {}
if (value == null) continue;
if (gotOne) result.append(", ");
result.append(fields[i].getName()).append('=').append(value);
Expand Down Expand Up @@ -54,11 +53,10 @@ public static int compareToHelper(Object a, Object b, int depth) {
try {
fields[i].get(a);
fields[i].get(b);
} catch (Exception e) {
}
} catch (Exception e) {}
int result = compareToHelper(a, b, depth + 1);
if (result != 0) return result;
}
return 0;
}
}
}
Loading