Skip to content

Commit b23e559

Browse files
committed
adjust code for jdk17
1 parent a8caaa1 commit b23e559

21 files changed

Lines changed: 170 additions & 376 deletions

src/main/java/org/htmlunit/cssparser/dom/AbstractColor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
*/
2828
public class AbstractColor implements Serializable {
2929

30-
private String function_;
31-
private CSSValueImpl cssValue_;
30+
private final String function_;
31+
private final CSSValueImpl cssValue_;
3232

3333
/**
3434
* Constructor that reads the values from the given

src/main/java/org/htmlunit/cssparser/dom/CSSCharsetRuleImpl.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,7 @@ public void setCssText(final String cssText) throws DOMException {
6363
DOMExceptionImpl.EXPECTING_CHARSET_RULE);
6464
}
6565
}
66-
catch (final CSSException e) {
67-
throw new DOMExceptionImpl(
68-
DOMException.SYNTAX_ERR,
69-
DOMExceptionImpl.SYNTAX_ERROR,
70-
e.getMessage());
71-
}
72-
catch (final IOException e) {
66+
catch (final CSSException | IOException e) {
7367
throw new DOMExceptionImpl(
7468
DOMException.SYNTAX_ERR,
7569
DOMExceptionImpl.SYNTAX_ERROR,
@@ -92,10 +86,9 @@ public boolean equals(final Object obj) {
9286
if (this == obj) {
9387
return true;
9488
}
95-
if (!(obj instanceof CSSCharsetRuleImpl)) {
89+
if (!(obj instanceof CSSCharsetRuleImpl ccr)) {
9690
return false;
9791
}
98-
final CSSCharsetRuleImpl ccr = (CSSCharsetRuleImpl) obj;
9992
return super.equals(obj)
10093
&& ParserUtils.equals(getEncoding(), ccr.getEncoding());
10194
}

src/main/java/org/htmlunit/cssparser/dom/CSSFontFaceRuleImpl.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,7 @@ public void setCssText(final String cssText) throws DOMException {
7575
DOMExceptionImpl.EXPECTING_FONT_FACE_RULE);
7676
}
7777
}
78-
catch (final CSSException e) {
79-
throw new DOMExceptionImpl(
80-
DOMException.SYNTAX_ERR,
81-
DOMExceptionImpl.SYNTAX_ERROR,
82-
e.getMessage());
83-
}
84-
catch (final IOException e) {
78+
catch (final CSSException | IOException e) {
8579
throw new DOMExceptionImpl(
8680
DOMException.SYNTAX_ERR,
8781
DOMExceptionImpl.SYNTAX_ERROR,
@@ -113,10 +107,9 @@ public boolean equals(final Object obj) {
113107
if (this == obj) {
114108
return true;
115109
}
116-
if (!(obj instanceof CSSFontFaceRuleImpl)) {
110+
if (!(obj instanceof CSSFontFaceRuleImpl cffr)) {
117111
return false;
118112
}
119-
final CSSFontFaceRuleImpl cffr = (CSSFontFaceRuleImpl) obj;
120113
return super.equals(obj)
121114
&& ParserUtils.equals(getStyle(), cffr.getStyle());
122115
}

src/main/java/org/htmlunit/cssparser/dom/CSSImportRuleImpl.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,7 @@ public void setCssText(final String cssText) throws DOMException {
8787
DOMExceptionImpl.EXPECTING_IMPORT_RULE);
8888
}
8989
}
90-
catch (final CSSException e) {
91-
throw new DOMExceptionImpl(
92-
DOMException.SYNTAX_ERR,
93-
DOMExceptionImpl.SYNTAX_ERROR,
94-
e.getMessage());
95-
}
96-
catch (final IOException e) {
90+
catch (final CSSException | IOException e) {
9791
throw new DOMExceptionImpl(
9892
DOMException.SYNTAX_ERR,
9993
DOMExceptionImpl.SYNTAX_ERROR,
@@ -140,10 +134,9 @@ public boolean equals(final Object obj) {
140134
if (this == obj) {
141135
return true;
142136
}
143-
if (!(obj instanceof CSSImportRuleImpl)) {
137+
if (!(obj instanceof CSSImportRuleImpl cir)) {
144138
return false;
145139
}
146-
final CSSImportRuleImpl cir = (CSSImportRuleImpl) obj;
147140
return super.equals(obj)
148141
&& ParserUtils.equals(getHref(), cir.getHref())
149142
&& ParserUtils.equals(getMedia(), cir.getMedia());

src/main/java/org/htmlunit/cssparser/dom/CSSMediaRuleImpl.java

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,7 @@ public void setCssText(final String cssText) throws DOMException {
8383
DOMExceptionImpl.EXPECTING_MEDIA_RULE);
8484
}
8585
}
86-
catch (final CSSException e) {
87-
throw new DOMExceptionImpl(
88-
DOMException.SYNTAX_ERR,
89-
DOMExceptionImpl.SYNTAX_ERROR,
90-
e.getMessage());
91-
}
92-
catch (final IOException e) {
86+
catch (final CSSException | IOException e) {
9387
throw new DOMExceptionImpl(
9488
DOMException.SYNTAX_ERR,
9589
DOMExceptionImpl.SYNTAX_ERROR,
@@ -145,13 +139,7 @@ public void insertRule(final String rule, final int index) throws DOMException {
145139
DOMExceptionImpl.INDEX_OUT_OF_BOUNDS,
146140
e.getMessage());
147141
}
148-
catch (final CSSException e) {
149-
throw new DOMExceptionImpl(
150-
DOMException.SYNTAX_ERR,
151-
DOMExceptionImpl.SYNTAX_ERROR,
152-
e.getMessage());
153-
}
154-
catch (final IOException e) {
142+
catch (final CSSException | IOException e) {
155143
throw new DOMExceptionImpl(
156144
DOMException.SYNTAX_ERR,
157145
DOMExceptionImpl.SYNTAX_ERROR,
@@ -196,10 +184,9 @@ public boolean equals(final Object obj) {
196184
if (this == obj) {
197185
return true;
198186
}
199-
if (!(obj instanceof CSSMediaRuleImpl)) {
187+
if (!(obj instanceof CSSMediaRuleImpl cmr)) {
200188
return false;
201189
}
202-
final CSSMediaRuleImpl cmr = (CSSMediaRuleImpl) obj;
203190
return super.equals(obj)
204191
&& ParserUtils.equals(getMediaList(), cmr.getMediaList())
205192
&& ParserUtils.equals(getCssRules(), cmr.getCssRules());

src/main/java/org/htmlunit/cssparser/dom/CSSPageRuleImpl.java

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,7 @@ public void setCssText(final String cssText) throws DOMException {
9494
DOMExceptionImpl.EXPECTING_PAGE_RULE);
9595
}
9696
}
97-
catch (final CSSException e) {
98-
throw new DOMExceptionImpl(
99-
DOMException.SYNTAX_ERR,
100-
DOMExceptionImpl.SYNTAX_ERROR,
101-
e.getMessage());
102-
}
103-
catch (final IOException e) {
97+
catch (final CSSException | IOException e) {
10498
throw new DOMExceptionImpl(
10599
DOMException.SYNTAX_ERR,
106100
DOMExceptionImpl.SYNTAX_ERROR,
@@ -140,13 +134,7 @@ public void setSelectorText(final String selectorText) throws DOMException {
140134
DOMExceptionImpl.EXPECTING_PAGE_RULE);
141135
}
142136
}
143-
catch (final CSSException e) {
144-
throw new DOMExceptionImpl(
145-
DOMException.SYNTAX_ERR,
146-
DOMExceptionImpl.SYNTAX_ERROR,
147-
e.getMessage());
148-
}
149-
catch (final IOException e) {
137+
catch (final CSSException | IOException e) {
150138
throw new DOMExceptionImpl(
151139
DOMException.SYNTAX_ERR,
152140
DOMExceptionImpl.SYNTAX_ERROR,
@@ -174,10 +162,9 @@ public boolean equals(final Object obj) {
174162
if (this == obj) {
175163
return true;
176164
}
177-
if (!(obj instanceof CSSPageRuleImpl)) {
165+
if (!(obj instanceof CSSPageRuleImpl cpr)) {
178166
return false;
179167
}
180-
final CSSPageRuleImpl cpr = (CSSPageRuleImpl) obj;
181168
return super.equals(obj)
182169
&& ParserUtils.equals(getSelectorText(), cpr.getSelectorText())
183170
&& ParserUtils.equals(getStyle(), cpr.getStyle());

src/main/java/org/htmlunit/cssparser/dom/CSSRuleListImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,9 @@ public boolean equals(final Object obj) {
9898
if (this == obj) {
9999
return true;
100100
}
101-
if (!(obj instanceof CSSRuleListImpl)) {
101+
if (!(obj instanceof CSSRuleListImpl crl)) {
102102
return false;
103103
}
104-
final CSSRuleListImpl crl = (CSSRuleListImpl) obj;
105104
return equalsRules(crl);
106105
}
107106

src/main/java/org/htmlunit/cssparser/dom/CSSStyleDeclarationImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,9 @@ public boolean equals(final Object obj) {
257257
if (this == obj) {
258258
return true;
259259
}
260-
if (!(obj instanceof CSSStyleDeclarationImpl)) {
260+
if (!(obj instanceof CSSStyleDeclarationImpl csd)) {
261261
return false;
262262
}
263-
final CSSStyleDeclarationImpl csd = (CSSStyleDeclarationImpl) obj;
264263

265264
// don't use parentRule in equals()
266265
// recursive loop -> stack overflow!

src/main/java/org/htmlunit/cssparser/dom/CSSStyleRuleImpl.java

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,7 @@ public void setCssText(final String cssText) throws DOMException {
9999
DOMExceptionImpl.EXPECTING_STYLE_RULE);
100100
}
101101
}
102-
catch (final CSSException e) {
103-
throw new DOMExceptionImpl(
104-
DOMException.SYNTAX_ERR,
105-
DOMExceptionImpl.SYNTAX_ERROR,
106-
e.getMessage());
107-
}
108-
catch (final IOException e) {
102+
catch (final CSSException | IOException e) {
109103
throw new DOMExceptionImpl(
110104
DOMException.SYNTAX_ERR,
111105
DOMExceptionImpl.SYNTAX_ERROR,
@@ -130,13 +124,7 @@ public void setSelectorText(final String selectorText) throws DOMException {
130124
final CSSOMParser parser = new CSSOMParser();
131125
selectors_ = parser.parseSelectors(selectorText);
132126
}
133-
catch (final CSSException e) {
134-
throw new DOMExceptionImpl(
135-
DOMException.SYNTAX_ERR,
136-
DOMExceptionImpl.SYNTAX_ERROR,
137-
e.getMessage());
138-
}
139-
catch (final IOException e) {
127+
catch (final CSSException | IOException e) {
140128
throw new DOMExceptionImpl(
141129
DOMException.SYNTAX_ERR,
142130
DOMExceptionImpl.SYNTAX_ERROR,
@@ -169,10 +157,9 @@ public boolean equals(final Object obj) {
169157
if (this == obj) {
170158
return true;
171159
}
172-
if (!(obj instanceof CSSStyleRuleImpl)) {
160+
if (!(obj instanceof CSSStyleRuleImpl csr)) {
173161
return false;
174162
}
175-
final CSSStyleRuleImpl csr = (CSSStyleRuleImpl) obj;
176163
return super.equals(obj)
177164
&& ParserUtils.equals(getSelectorText(), csr.getSelectorText())
178165
&& ParserUtils.equals(getStyle(), csr.getStyle());

src/main/java/org/htmlunit/cssparser/dom/CSSStyleSheetImpl.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,7 @@ else if (r instanceof CSSImportRuleImpl) {
210210
DOMExceptionImpl.INDEX_OUT_OF_BOUNDS,
211211
e.getMessage());
212212
}
213-
catch (final CSSException e) {
214-
throw new DOMExceptionImpl(
215-
DOMException.SYNTAX_ERR,
216-
DOMExceptionImpl.SYNTAX_ERROR,
217-
e.getMessage());
218-
}
219-
catch (final IOException e) {
213+
catch (final CSSException | IOException e) {
220214
throw new DOMExceptionImpl(
221215
DOMException.SYNTAX_ERR,
222216
DOMExceptionImpl.SYNTAX_ERROR,
@@ -322,10 +316,9 @@ public boolean equals(final Object obj) {
322316
if (this == obj) {
323317
return true;
324318
}
325-
if (!(obj instanceof CSSStyleSheetImpl)) {
319+
if (!(obj instanceof CSSStyleSheetImpl css)) {
326320
return false;
327321
}
328-
final CSSStyleSheetImpl css = (CSSStyleSheetImpl) obj;
329322
boolean eq = ParserUtils.equals(getCssRules(), css.getCssRules());
330323
eq = eq && (getDisabled() == css.getDisabled());
331324
eq = eq && ParserUtils.equals(getHref(), css.getHref());

0 commit comments

Comments
 (0)