Skip to content

Commit 350a708

Browse files
committed
use string accessor instead of casting
1 parent 4152071 commit 350a708

File tree

9 files changed

+95
-83
lines changed

9 files changed

+95
-83
lines changed

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,15 @@ public CssFontFeatureSettings(ApplContext ac, CssExpression expression, boolean
102102
layervalues.add(val);
103103
break;
104104
case CssTypes.CSS_STRING:
105-
if (val.getRawType() == CssTypes.CSS_STRING) {
106-
CssString s = (CssString) val;
107-
int l = s.toString().length();
108-
// limit of 4characters + two surrounding quotes
109-
if (s.toString().length() != 6) {
110-
throw new InvalidParamException("value",
111-
expression.getValue().toString(),
112-
getPropertyName(), ac);
113-
}
114-
// FIXME TODO check
105+
CssString s = val.getString();
106+
int l = s.toString().length();
107+
// limit of 4characters + two surrounding quotes
108+
if (s.toString().length() != 6) {
109+
throw new InvalidParamException("value",
110+
expression.getValue().toString(),
111+
getPropertyName(), ac);
115112
}
113+
// FIXME TODO check
116114
layervalues.add(val);
117115
break;
118116
default:
@@ -124,8 +122,8 @@ public CssFontFeatureSettings(ApplContext ac, CssExpression expression, boolean
124122
if (!layervalues.isEmpty()) {
125123
if ((layervalues.size() == 2) || ((layervalues.size() == 1) && (op == COMMA))) {
126124
if (layervalues.size() == 1) {
127-
values.add(val);
128-
layervalues.clear();
125+
values.add(val);
126+
layervalues.clear();
129127
} else {
130128
values.add(new CssValueList(layervalues));
131129
layervalues = new ArrayList<>();

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

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -55,43 +55,41 @@ public CssFontLanguageOverride(ApplContext ac, CssExpression expression, boolean
5555

5656
switch (val.getType()) {
5757
case CssTypes.CSS_STRING:
58-
if (val.getRawType() == CssTypes.CSS_STRING) {
59-
CssString s = (CssString) val;
60-
int l = s.toString().length();
61-
// limit of 4characters + two surrounding quotes
62-
if ((l < 4) || (l > 6)) {
63-
throw new InvalidParamException("value",
64-
expression.getValue().toString(),
65-
getPropertyName(), ac);
66-
}
67-
// we extract the 2, 3 or 4 letters from the quotes...
68-
String tag = s.toString().substring(1, l - 1).toUpperCase();
69-
// align to 4
70-
switch (tag.length()) {
71-
case 1:
72-
tag = tag.concat(" ");
73-
break;
74-
case 2:
75-
tag = tag.concat(" ");
76-
break;
77-
case 3:
78-
tag = tag.concat(" ");
79-
break;
80-
default:
81-
}
82-
// valid values are specified here.
83-
int idx = Arrays.binarySearch(OpenTypeLanguageSystemTag.tags, tag);
84-
if (idx < 0) {
85-
// TODO specific error code
86-
throw new InvalidParamException("value",
87-
expression.getValue().toString(),
88-
getPropertyName(), ac);
89-
}
90-
// check if deprecated
91-
idx = Arrays.binarySearch(OpenTypeLanguageSystemTag.deprecated_tags, tag);
92-
if (idx >= 0) {
93-
ac.getFrame().addWarning("deprecated", tag);
94-
}
58+
CssString s = val.getString();
59+
int l = s.toString().length();
60+
// limit of 4characters + two surrounding quotes
61+
if ((l < 4) || (l > 6)) {
62+
throw new InvalidParamException("value",
63+
expression.getValue().toString(),
64+
getPropertyName(), ac);
65+
}
66+
// we extract the 2, 3 or 4 letters from the quotes...
67+
String tag = s.toString().substring(1, l - 1).toUpperCase();
68+
// align to 4
69+
switch (tag.length()) {
70+
case 1:
71+
tag = tag.concat(" ");
72+
break;
73+
case 2:
74+
tag = tag.concat(" ");
75+
break;
76+
case 3:
77+
tag = tag.concat(" ");
78+
break;
79+
default:
80+
}
81+
// valid values are specified here.
82+
int idx = Arrays.binarySearch(OpenTypeLanguageSystemTag.tags, tag);
83+
if (idx < 0) {
84+
// TODO specific error code
85+
throw new InvalidParamException("value",
86+
expression.getValue().toString(),
87+
getPropertyName(), ac);
88+
}
89+
// check if deprecated
90+
idx = Arrays.binarySearch(OpenTypeLanguageSystemTag.deprecated_tags, tag);
91+
if (idx >= 0) {
92+
ac.getFrame().addWarning("deprecated", tag);
9593
}
9694
value = val;
9795
break;

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
public class CssFontVariationSettings extends org.w3c.css.properties.css.CssFontVariationSettings {
2727

2828
static final CssIdent normal = CssIdent.getIdent("normal");
29+
2930
/**
3031
* Create a new CssFontVariationSettings
3132
*/
@@ -55,7 +56,7 @@ public CssFontVariationSettings(ApplContext ac, CssExpression expression, boolea
5556
while (!expression.end()) {
5657
val = expression.getValue();
5758
op = expression.getOperator();
58-
59+
5960
switch (val.getType()) {
6061
case CssTypes.CSS_IDENT:
6162
CssIdent id = val.getIdent();
@@ -80,17 +81,15 @@ public CssFontVariationSettings(ApplContext ac, CssExpression expression, boolea
8081
layervalues.add(val);
8182
break;
8283
case CssTypes.CSS_STRING:
83-
if (val.getRawType() == CssTypes.CSS_STRING) {
84-
CssString s = (CssString) val;
85-
int l = s.toString().length();
86-
// limit of 4characters + two surrounding quotes
87-
if (s.toString().length() != 6) {
88-
throw new InvalidParamException("value",
89-
expression.getValue().toString(),
90-
getPropertyName(), ac);
91-
}
92-
// FIXME TODO check
84+
CssString s = val.getString();
85+
int l = s.toString().length();
86+
// limit of 4characters + two surrounding quotes
87+
if (s.toString().length() != 6) {
88+
throw new InvalidParamException("value",
89+
expression.getValue().toString(),
90+
getPropertyName(), ac);
9391
}
92+
// FIXME TODO check
9493
layervalues.add(val);
9594
break;
9695
default:

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,11 @@ protected static CssValue parseNav(ApplContext ac, CssExpression expression,
126126
values.add(val);
127127
break;
128128
case CssTypes.CSS_STRING:
129-
if (val.getRawType() == CssTypes.CSS_STRING) {
130-
CssString s = (CssString) val;
131-
if (s.toString().charAt(1) == '_') {
132-
// TODO better error (do not start with _)
133-
throw new InvalidParamException("value", val,
134-
caller.getPropertyName(), ac);
135-
}
129+
CssString s = val.getString();
130+
if (s.toString().charAt(1) == '_') {
131+
// TODO better error (do not start with _)
132+
throw new InvalidParamException("value", val,
133+
caller.getPropertyName(), ac);
136134
}
137135
values.add(val);
138136
default:

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,20 @@ public CssTextEmphasisStyle(ApplContext ac, CssExpression expression, boolean ch
9393
CssValue val;
9494
char op;
9595

96-
CssIdent styleValue = null;
97-
CssIdent formValue = null;
96+
CssValue styleValue = null;
97+
CssValue formValue = null;
9898

9999
val = expression.getValue();
100100
op = expression.getOperator();
101101

102102
switch (val.getType()) {
103103
case CssTypes.CSS_STRING:
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-
}
104+
CssString s = val.getString();
105+
// limit of 1 character + two surrounding quotes
106+
// TODO might be a warning only
107+
if (s.toString().length() != 3) {
108+
throw new InvalidParamException("value",
109+
s, getPropertyName(), ac);
112110
}
113111
if (check && expression.getCount() != 1) {
114112
throw new InvalidParamException("value",
@@ -119,7 +117,7 @@ public CssTextEmphasisStyle(ApplContext ac, CssExpression expression, boolean ch
119117
break;
120118
case CssTypes.CSS_IDENT:
121119
CssIdent ident = val.getIdent();
122-
if (inherit.equals(ident)) {
120+
if (CssIdent.isCssWide(ident)) {
123121
value = val;
124122
if (check && expression.getCount() != 1) {
125123
throw new InvalidParamException("value",
@@ -139,12 +137,16 @@ public CssTextEmphasisStyle(ApplContext ac, CssExpression expression, boolean ch
139137
do {
140138
match = false;
141139
if (styleValue == null) {
142-
styleValue = getShapeStyle(ident);
143-
match = (styleValue != null);
140+
match = (getShapeStyle(ident) != null);
141+
if (match) {
142+
styleValue = val;
143+
}
144144
}
145145
if (!match && formValue == null) {
146-
formValue = getShapeForm(ident);
147-
match = (formValue != null);
146+
match = (getShapeForm(ident) != null);
147+
if (match) {
148+
formValue = val;
149+
}
148150
}
149151
if (!match) {
150152
throw new InvalidParamException("value",

org/w3c/css/values/CssAttr.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void setValue(CssExpression exp, ApplContext ac)
128128
throw new InvalidParamException("unrecognize", ac);
129129
}
130130
if (val.getType() == CssTypes.CSS_IDENT) {
131-
computed_type = _checkType((CssIdent) val);
131+
computed_type = _checkType(val.getIdent());
132132
value_type = val;
133133
break;
134134
}

org/w3c/css/values/CssString.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,9 @@ public boolean equals(Object value) {
8787
this.value.equals(((CssString) value).value));
8888
}
8989

90+
@Override
91+
public CssString getString()
92+
throws InvalidParamException {
93+
return this;
94+
}
9095
}

org/w3c/css/values/CssValue.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ public CssFunction getFunction() throws InvalidParamException {
9898
throw new ClassCastException("unknown");
9999
}
100100

101+
public CssString getString() throws InvalidParamException {
102+
throw new ClassCastException("unknown");
103+
}
104+
101105
/**
102106
* Does this value contain a "\9" CSS declaration hack?
103107
*/

org/w3c/css/values/CssVariable.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,14 @@ public CssHashIdent getHashIdent() throws InvalidParamException {
356356
return _exp_value.getHashIdent();
357357
}
358358

359+
@Override
360+
public CssString getString() throws InvalidParamException {
361+
if (computed_type != CssTypes.CSS_STRING) {
362+
throw new ClassCastException("unknown");
363+
}
364+
return _exp_value.getString();
365+
}
366+
359367
@Override
360368
public CssFunction getFunction() throws InvalidParamException {
361369
if (computed_type != CssTypes.CSS_FUNCTION) {

0 commit comments

Comments
 (0)