Skip to content

Commit

Permalink
Add generic type arguments to CSS packages.
Browse files Browse the repository at this point in the history
Also, IDE fixes, such as removing unneeded casts and adding override annotation. In preparation of working on #423
  • Loading branch information
danfickle committed Dec 9, 2019
1 parent 73a26c9 commit 6af81c0
Show file tree
Hide file tree
Showing 47 changed files with 502 additions and 295 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1834,6 +1834,7 @@ private CSSName(
*
* @return a string representation of the object.
*/
@Override
public String toString() {
return this.propName;
}
Expand Down Expand Up @@ -1921,7 +1922,7 @@ private static synchronized CSSName addProperty(
* Adds a feature to the Property attribute of the CSSName class
*
* @param propName The feature to be added to the Property attribute
* @param type
* @param type
* @param initialValue
* @param inherit
* @param implemented
Expand Down Expand Up @@ -1959,6 +1960,7 @@ private static synchronized CSSName addProperty(

static {
CSSParser parser = new CSSParser(new CSSErrorHandler() {
@Override
public void error(String uri, String message) {
XRLog.cssParse("(" + uri + ") " + message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ private final static IdentValue addValue(String ident) {
* Most of these throw exceptions--makes use of the interface easier in CS (avoids casting)
*/

@Override
public boolean isDeclaredInherit() {
return this == INHERIT;
}
Expand All @@ -331,42 +332,51 @@ public FSDerivedValue computedValue() {
return this;
}

@Override
public float asFloat() {
throw new XRRuntimeException("Ident value is never a float; wrong class used for derived value.");
}

@Override
public FSColor asColor() {
throw new XRRuntimeException("Ident value is never a color; wrong class used for derived value.");
}

@Override
public float getFloatProportionalTo(CSSName cssName,
float baseValue,
CssContext ctx) {
throw new XRRuntimeException("Ident value (" + toString() + ") is never a length; wrong class used for derived value.");
}

@Override
public String asString() {
return toString();
}

@Override
public String[] asStringArray() {
throw new XRRuntimeException("Ident value is never a string array; wrong class used for derived value.");
}

@Override
public IdentValue asIdentValue() {
return this;
}

@Override
public boolean hasAbsoluteUnit() {
// log and return false
throw new XRRuntimeException("Ident value is never an absolute unit; wrong class used for derived value; this " +
"ident value is a " + this.asString());
}

@Override
public boolean isIdent() {
return true;
}

@Override
public boolean isDependentOnFontSize() {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,44 +82,44 @@ public final class Idents {
/**
* Description of the Field
*/
private final static Map COLOR_MAP;
private final static Map<String, String> COLOR_MAP;
/**
* Description of the Field
*/
private final static Map FONT_SIZES;
private final static Map<String, String> FONT_SIZES;
/**
* Description of the Field
*/
private final static Map FONT_WEIGHTS;
private final static Map<String, String> FONT_WEIGHTS;
/**
* Description of the Field
*/
private final static Map BORDER_WIDTHS;
private final static Map<String, String> BORDER_WIDTHS;
/**
* Description of the Field
*/
private final static Map BACKGROUND_POSITIONS;
private final static Map<String, String> BACKGROUND_POSITIONS;
/**
* Description of the Field
*/
private final static List BACKGROUND_REPEATS;
private final static List<String> BACKGROUND_REPEATS;
/**
* Description of the Field
*/
private final static List BORDER_STYLES;
private final static List<String> BORDER_STYLES;
/**
* Description of the Field
*/
private final static List LIST_TYPES;
private final static List<String> LIST_TYPES;
/**
* Description of the Field
*/
private final static List FONT_STYLES;
private final static List<String> FONT_STYLES;

/**
* Description of the Field
*/
private final static List BACKGROUND_POSITIONS_IDENTS;
private final static List<String> BACKGROUND_POSITIONS_IDENTS;

/**
* Description of the Method
Expand All @@ -136,13 +136,13 @@ public static String convertIdent(CSSName cssName, String ident) {
String val = ident;

if (cssName == CSSName.FONT_SIZE) {
String size = (String) FONT_SIZES.get(ident);
String size = FONT_SIZES.get(ident);
val = (size == null ? ident : size);
} else if (cssName == CSSName.FONT_WEIGHT) {
String size = (String) FONT_WEIGHTS.get(ident);
String size = FONT_WEIGHTS.get(ident);
val = (size == null ? ident : size);
} else if (cssName == CSSName.BACKGROUND_POSITION) {
String pos = (String) BACKGROUND_POSITIONS.get(ident);
String pos = BACKGROUND_POSITIONS.get(ident);
val = (pos == null ? ident : pos);
} else if (
cssName == CSSName.BORDER_BOTTOM_WIDTH ||
Expand All @@ -151,7 +151,7 @@ public static String convertIdent(CSSName cssName, String ident) {
cssName == CSSName.BORDER_WIDTH_SHORTHAND ||
cssName == CSSName.BORDER_TOP_WIDTH) {

String size = (String) BORDER_WIDTHS.get(ident);
String size = BORDER_WIDTHS.get(ident);
val = (size == null ? ident : size);
} else if (
cssName == CSSName.BORDER_BOTTOM_COLOR ||
Expand Down Expand Up @@ -350,7 +350,7 @@ public static String getColorHex(String value) {
if (value == null) {
throw new XRRuntimeException("value is null on getColorHex()");
}
String retval = (String) COLOR_MAP.get(value.toLowerCase());
String retval = COLOR_MAP.get(value.toLowerCase());
if (retval == null) {
if (value.trim().startsWith("rgb(")) {
retval = value;
Expand All @@ -365,7 +365,7 @@ public static String getColorHex(String value) {
}

static {
COLOR_MAP = new HashMap();
COLOR_MAP = new HashMap<>();
/* From CSS 2.1- 4.3.6: Colors
aqua #00ffff
black #000000
Expand Down Expand Up @@ -405,7 +405,7 @@ public static String getColorHex(String value) {
COLOR_MAP.put("yellow", "#ffff00");

//TODO: FONT_SIZES should be determined by the User Interface!
FONT_SIZES = new HashMap();
FONT_SIZES = new HashMap<>();
FONT_SIZES.put("xx-small", "6.9pt");
FONT_SIZES.put("x-small", "8.3pt");
FONT_SIZES.put("small", "10pt");
Expand All @@ -418,7 +418,7 @@ public static String getColorHex(String value) {
FONT_SIZES.put("smaller", "0.8em");
FONT_SIZES.put("larger", "1.2em");

FONT_WEIGHTS = new HashMap();
FONT_WEIGHTS = new HashMap<>();
FONT_WEIGHTS.put("normal", "400");
FONT_WEIGHTS.put("bold", "700");
FONT_WEIGHTS.put("100", "100");
Expand All @@ -434,18 +434,18 @@ public static String getColorHex(String value) {
FONT_WEIGHTS.put("lighter", "lighter");
// NOTE: 'bolder' and 'lighter' need to be handled programmatically

BORDER_WIDTHS = new HashMap();
BORDER_WIDTHS = new HashMap<>();
BORDER_WIDTHS.put("thin", "1px");
BORDER_WIDTHS.put("medium", "2px");
BORDER_WIDTHS.put("thick", "3px");

BACKGROUND_POSITIONS_IDENTS = new ArrayList();
BACKGROUND_POSITIONS_IDENTS = new ArrayList<>();
BACKGROUND_POSITIONS_IDENTS.add("top");
BACKGROUND_POSITIONS_IDENTS.add("center");
BACKGROUND_POSITIONS_IDENTS.add("bottom");
BACKGROUND_POSITIONS_IDENTS.add("right");
BACKGROUND_POSITIONS_IDENTS.add("left");
BACKGROUND_POSITIONS = new HashMap();
BACKGROUND_POSITIONS = new HashMap<>();

// NOTE: combinations of idents for background-positions, are specified in the CSS
// spec; some are disallowed, for example, there is no "top" all by itself. Check
Expand Down Expand Up @@ -478,13 +478,13 @@ public static String getColorHex(String value) {
BACKGROUND_POSITIONS.put("bottom right", "100% 100%");
BACKGROUND_POSITIONS.put("right bottom", "100% 100%");

BACKGROUND_REPEATS = new ArrayList();
BACKGROUND_REPEATS = new ArrayList<>();
BACKGROUND_REPEATS.add("repeat");
BACKGROUND_REPEATS.add("repeat-x");
BACKGROUND_REPEATS.add("repeat-y");
BACKGROUND_REPEATS.add("no-repeat");

BORDER_STYLES = new ArrayList();
BORDER_STYLES = new ArrayList<>();
BORDER_STYLES.add("none");
BORDER_STYLES.add("hidden");
BORDER_STYLES.add("dotted");
Expand All @@ -496,7 +496,7 @@ public static String getColorHex(String value) {
BORDER_STYLES.add("inset");
BORDER_STYLES.add("outset");

LIST_TYPES = new ArrayList();
LIST_TYPES = new ArrayList<>();
LIST_TYPES.add("disc");
LIST_TYPES.add("circle");
LIST_TYPES.add("square");
Expand All @@ -519,7 +519,7 @@ public static String getColorHex(String value) {
LIST_TYPES.add("katakana-iroha");
LIST_TYPES.add("none");

FONT_STYLES = new ArrayList();
FONT_STYLES = new ArrayList<>();
FONT_STYLES.add("normal");
FONT_STYLES.add("italic");
FONT_STYLES.add("oblique");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.util.Map;

public class MarginBoxName {
private static final Map ALL = new HashMap();
private static final Map<String, MarginBoxName> ALL = new HashMap<>();
private static int _maxAssigned = 0;

public final int FS_ID;
Expand Down Expand Up @@ -68,18 +68,21 @@ private final static MarginBoxName addValue(String ident, IdentValue textAlign,
return val;
}

@Override
public String toString() {
return _ident;
}

public static MarginBoxName valueOf(String ident) {
return (MarginBoxName)ALL.get(ident);
return ALL.get(ident);
}

@Override
public int hashCode() {
return FS_ID;
}

@Override
public boolean equals(Object o) {
if (o == null || ! (o instanceof MarginBoxName)) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.util.Map;

public class PageElementPosition {
private static final Map ALL = new HashMap();
private static final Map<String, PageElementPosition> ALL = new HashMap<>();
private static int _maxAssigned = 0;

public final int FS_ID;
Expand All @@ -46,18 +46,21 @@ private final static PageElementPosition addValue(String ident) {
return val;
}

@Override
public String toString() {
return _ident;
}

public static PageElementPosition valueOf(String ident) {
return (PageElementPosition)ALL.get(ident);
return ALL.get(ident);
}

@Override
public int hashCode() {
return FS_ID;
}

@Override
public boolean equals(Object o) {
if (o == null || ! (o instanceof PageElementPosition)) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public final class ValueConstants {
* Type descriptions--a crude approximation taken by scanning CSSValue
* statics
*/
private final static List TYPE_DESCRIPTIONS;
private final static List<String> TYPE_DESCRIPTIONS;
/**
* Description of the Field
*/
private final static Map sacTypesStrings;
private final static Map<Short, String> sacTypesStrings;

/**
* A text representation of the CSS type for this value.
Expand All @@ -61,7 +61,7 @@ public static String cssType(int cssType, int primitiveValueType) {
if (primitiveValueType >= TYPE_DESCRIPTIONS.size()) {
desc = "{unknown: " + primitiveValueType + "}";
} else {
desc = (String) TYPE_DESCRIPTIONS.get(primitiveValueType);
desc = TYPE_DESCRIPTIONS.get(primitiveValueType);
if (desc == null) {
desc = "{UNKNOWN VALUE TYPE}";
}
Expand Down Expand Up @@ -112,7 +112,7 @@ public static short sacPrimitiveTypeForString(String type) {
* @return Returns
*/
public static String stringForSACPrimitiveType(short type) {
return (String) sacTypesStrings.get(new Short(type));
return sacTypesStrings.get(new Short(type));
}

/**
Expand All @@ -127,7 +127,7 @@ public static String stringForSACPrimitiveType(short type) {
//TODO: method may be unnecessary (tobe)
public static boolean isAbsoluteUnit(CSSPrimitiveValue primitive) {
short type = 0;
type = ((CSSPrimitiveValue) primitive).getPrimitiveType();
type = primitive.getPrimitiveType();
return isAbsoluteUnit(type);
}

Expand Down Expand Up @@ -253,8 +253,8 @@ public static boolean isNumber(short cssPrimitiveType) {
}

static {
SortedMap map = new TreeMap();
TYPE_DESCRIPTIONS = new ArrayList();
SortedMap<Short, String> map = new TreeMap<>();
TYPE_DESCRIPTIONS = new ArrayList<>();
try {
Field fields[] = CSSPrimitiveValue.class.getFields();
for (int i = 0; i < fields.length; i++) {
Expand All @@ -278,13 +278,13 @@ public static boolean isNumber(short cssPrimitiveType) {
}
}
// now sort by the key--the short constant for the public fields
List keys = new ArrayList(map.keySet());
List<Short> keys = new ArrayList<>(map.keySet());
Collections.sort(keys);

// then add to our static list, in the order the keys appear. this means
// list.get(index) will return the item at index, which should be the description
// for that constant
Iterator iter = keys.iterator();
Iterator<Short> iter = keys.iterator();
while (iter.hasNext()) {
TYPE_DESCRIPTIONS.add(map.get(iter.next()));
}
Expand All @@ -293,7 +293,7 @@ public static boolean isNumber(short cssPrimitiveType) {
}

// HACK: this is a quick way to perform the lookup, but dumb if the short assigned are > 100; but the compiler will tell us that (PWW 21-01-05)
sacTypesStrings = new HashMap(25);
sacTypesStrings = new HashMap<>(25);
sacTypesStrings.put(new Short(CSSPrimitiveValue.CSS_EMS), "em");
sacTypesStrings.put(new Short(CSSPrimitiveValue.CSS_EXS), "ex");
sacTypesStrings.put(new Short(CSSPrimitiveValue.CSS_PX), "px");
Expand Down
Loading

0 comments on commit 6af81c0

Please sign in to comment.