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, printWidth 120 #1919

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
11 changes: 11 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"overrides": [
{
"files": ["*.java"],
"options": {
"tabWidth": 4,
"printWidth": 120
}
}
]
}
226 changes: 137 additions & 89 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 @@ -39,7 +40,6 @@ 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");
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 Down Expand Up @@ -59,6 +60,7 @@ public int compare(Object a0, Object a1) {
}

static class CatchExceptionComparator implements Comparator {

private Comparator other;

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

}
}

Large diffs are not rendered by default.

74 changes: 34 additions & 40 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 @@ -82,9 +81,7 @@ public BNF complete() {
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 (msg.length() == 0) msg = temp; else if (temp.length() != 0) {
msg = msg + "; " + temp;
}
error(msg);
Expand All @@ -95,9 +92,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 +135,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 +187,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
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;
}
}
}
70 changes: 37 additions & 33 deletions tools/cldr-code/src/main/java/org/unicode/cldr/util/Builder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.unicode.cldr.util;

import com.ibm.icu.text.Transform;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -12,8 +13,6 @@
import java.util.SortedMap;
import java.util.SortedSet;

import com.ibm.icu.text.Transform;

/**
* Convenience class for building collections and maps. Allows them to be built by chaining, making it simpler to
* set as parameters and fields. Also supplies some operations that are missing on the JDK maps and collections,
Expand Down Expand Up @@ -47,6 +46,7 @@
* @author markdavis
*/
public final class Builder {

enum EqualAction {
/**
* If you try to add an item that is already there, or change the mapping, do whatever the source collation or
Expand All @@ -64,7 +64,7 @@ enum EqualAction {
/**
* If you try to add an item that is already there, or change the mapping, throw an exception.
*/
THROW
THROW,
}

public static <E, C extends Collection<E>> CBuilder<E, C> with(C collection, EqualAction ea) {
Expand All @@ -86,6 +86,7 @@ public static <K, V, M extends Map<K, V>> MBuilder<K, V, M> with(M map) {
// ===== Collections ======

public static final class CBuilder<E, U extends Collection<E>> {

public EqualAction getEqualAction() {
return equalAction;
}
Expand All @@ -102,20 +103,20 @@ public CBuilder<E, U> clear() {

public CBuilder<E, U> add(E e) {
switch (equalAction) {
case NATIVE:
break;
case REPLACE:
collection.remove(e);
break;
case RETAIN:
if (collection.contains(e)) {
return this;
}
break;
case THROW:
if (collection.contains(e)) {
throw new IllegalArgumentException("Map already contains " + e);
}
case NATIVE:
break;
case REPLACE:
collection.remove(e);
break;
case RETAIN:
if (collection.contains(e)) {
return this;
}
break;
case THROW:
if (collection.contains(e)) {
throw new IllegalArgumentException("Map already contains " + e);
}
}
collection.add(e);
return this;
Expand Down Expand Up @@ -319,20 +320,20 @@ public MBuilder<K, V, M> clear() {

public MBuilder<K, V, M> put(K key, V value) {
switch (equalAction) {
case NATIVE:
break;
case REPLACE:
map.remove(key);
break;
case RETAIN:
if (map.containsKey(key)) {
return this;
}
break;
case THROW:
if (map.containsKey(key)) {
throw new IllegalArgumentException("Map already contains " + key);
}
case NATIVE:
break;
case REPLACE:
map.remove(key);
break;
case RETAIN:
if (map.containsKey(key)) {
return this;
}
break;
case THROW:
if (map.containsKey(key)) {
throw new IllegalArgumentException("Map already contains " + key);
}
}
map.put(key, value);
return this;
Expand Down Expand Up @@ -500,8 +501,11 @@ private MBuilder(M map, EqualAction ea) {
}
}

public static <E> Collection<E> getMatchingItems(Transform<E, Boolean> predicate, Collection<E> collection,
Collection<E> matchingItems) {
public static <E> Collection<E> getMatchingItems(
Transform<E, Boolean> predicate,
Collection<E> collection,
Collection<E> matchingItems
) {
for (E item : collection) {
if (predicate.transform(item)) {
matchingItems.add(item);
Expand Down
Loading