Skip to content

Commit 1302d70

Browse files
committed
avoid casting, use accessors instead (for properties that have multiple types)
1 parent c95d029 commit 1302d70

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

org/w3c/css/properties/css3/CssTextEmphasisStyle.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ public CssTextEmphasisStyle() {
8181
* Creates a new CssTextEmphasisStyle
8282
*
8383
* @param expression The expression for this property
84-
* @throws org.w3c.css.util.InvalidParamException
85-
* Expressions are incorrect
84+
* @throws org.w3c.css.util.InvalidParamException Expressions are incorrect
8685
*/
8786
public CssTextEmphasisStyle(ApplContext ac, CssExpression expression, boolean check)
8887
throws InvalidParamException {
@@ -102,31 +101,33 @@ public CssTextEmphasisStyle(ApplContext ac, CssExpression expression, boolean ch
102101

103102
switch (val.getType()) {
104103
case CssTypes.CSS_STRING:
105-
CssString s = (CssString) val;
106-
// limit of 1 character + two surrounding quotes
107-
// TODO might be a warning only
108-
if (s.toString().length() != 3) {
109-
throw new InvalidParamException("value",
110-
s, getPropertyName(), ac);
104+
if (val.getRawType() == CssTypes.CSS_STRING) {
105+
CssString s = (CssString) val;
106+
// limit of 1 character + two surrounding quotes
107+
// TODO might be a warning only
108+
if (s.toString().length() != 3) {
109+
throw new InvalidParamException("value",
110+
s, getPropertyName(), ac);
111+
}
111112
}
112113
if (check && expression.getCount() != 1) {
113114
throw new InvalidParamException("value",
114115
val.toString(),
115116
getPropertyName(), ac);
116117
}
117-
value = s;
118+
value = val;
118119
break;
119120
case CssTypes.CSS_IDENT:
120-
CssIdent ident = (CssIdent) val;
121+
CssIdent ident = val.getIdent();
121122
if (inherit.equals(ident)) {
122-
value = inherit;
123+
value = val;
123124
if (check && expression.getCount() != 1) {
124125
throw new InvalidParamException("value",
125126
val.toString(),
126127
getPropertyName(), ac);
127128
}
128129
} else if (none.equals(ident)) {
129-
value = none;
130+
value = val;
130131
if (check && expression.getCount() != 1) {
131132
throw new InvalidParamException("value",
132133
val.toString(),
@@ -168,7 +169,7 @@ public CssTextEmphasisStyle(ApplContext ac, CssExpression expression, boolean ch
168169
val.toString(),
169170
getPropertyName(), ac);
170171
}
171-
ident = (CssIdent) val;
172+
ident = val.getIdent();
172173
} while (!expression.end());
173174
// now construct the value
174175
if (formValue != null && styleValue != null) {

org/w3c/css/properties/css3/CssTextShadow.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ public CssTextShadow() {
3535
* Creates a new CssTextShadow
3636
*
3737
* @param expression The expression for this property
38-
* @throws org.w3c.css.util.InvalidParamException
39-
* Expressions are incorrect
38+
* @throws org.w3c.css.util.InvalidParamException Expressions are incorrect
4039
*/
4140
public CssTextShadow(ApplContext ac, CssExpression expression, boolean check)
4241
throws InvalidParamException {
@@ -55,21 +54,21 @@ public CssTextShadow(ApplContext ac, CssExpression expression, boolean check)
5554
val = expression.getValue();
5655
op = expression.getOperator();
5756

58-
if (inherit.equals(val)) {
57+
if (inherit.equals(val.getIdent())) {
5958
if (expression.getCount() > 1) {
6059
throw new InvalidParamException("value", val,
6160
getPropertyName(), ac);
6261
}
63-
value = inherit;
62+
value = val;
6463
expression.next();
6564
return;
6665
}
67-
if (none.equals(val)) {
66+
if (none.equals(val.getIdent())) {
6867
if (expression.getCount() > 1) {
6968
throw new InvalidParamException("value", val,
7069
getPropertyName(), ac);
7170
}
72-
value = none;
71+
value = val;
7372
expression.next();
7473
return;
7574
}
@@ -132,14 +131,13 @@ public CssValue check(ApplContext ac, CssExpression exp)
132131
throw new InvalidParamException("value",
133132
val, getPropertyName(), ac);
134133
}
134+
// FIXME rewrite potential exceptions
135135
CssColor c = new CssColor(ac, exp, false);
136-
color = c.getColor();
136+
color = val;
137137
// color can be first or last
138138
if (values.size() > 0 && exp.getRemainingCount() != 0) {
139-
if (color != null) {
140-
throw new InvalidParamException("value",
141-
val, getPropertyName(), ac);
142-
}
139+
throw new InvalidParamException("value",
140+
val, getPropertyName(), ac);
143141
}
144142
// no need for exp.next() as CssColor parsing is
145143
// already doing that.

0 commit comments

Comments
 (0)