Skip to content

Commit 9aacb1c

Browse files
committed
remove CSSRuleType enum
1 parent 7341f34 commit 9aacb1c

20 files changed

+47
-159
lines changed

src/main/java/com/gargoylesoftware/css/dom/AbstractCSSRuleImpl.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@
2323
*/
2424
public abstract class AbstractCSSRuleImpl extends AbstractLocatable implements Serializable {
2525

26-
public enum CSSRuleType {
27-
MEDIA_RULE,
28-
PAGE_RULE,
29-
IMPORT_RULE,
30-
FONT_FACE_RULE,
31-
CHARSET_RULE,
32-
STYLE_RULE,
33-
UNKNOWN_RULE
34-
}
35-
3626
private CSSStyleSheetImpl parentStyleSheet_;
3727
private AbstractCSSRuleImpl parentRule_;
3828

@@ -58,8 +48,6 @@ public AbstractCSSRuleImpl() {
5848
super();
5949
}
6050

61-
public abstract CSSRuleType getType();
62-
6351
public abstract String getCssText();
6452
public abstract void setCssText(String text);
6553

src/main/java/com/gargoylesoftware/css/dom/CSSCharsetRuleImpl.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ public CSSCharsetRuleImpl(
4141
encoding_ = encoding;
4242
}
4343

44-
public CSSRuleType getType() {
45-
return CSSRuleType.CHARSET_RULE;
46-
}
47-
4844
public void setCssText(final String cssText) throws DOMException {
4945
final CSSStyleSheetImpl parentStyleSheet = getParentStyleSheetImpl();
5046
if (parentStyleSheet != null && parentStyleSheet.isReadOnly()) {
@@ -59,7 +55,7 @@ public void setCssText(final String cssText) throws DOMException {
5955
final AbstractCSSRuleImpl r = parser.parseRule(is);
6056

6157
// The rule must be a charset rule
62-
if (r.getType() == CSSRuleType.CHARSET_RULE) {
58+
if (r instanceof CSSCharsetRuleImpl) {
6359
encoding_ = ((CSSCharsetRuleImpl) r).encoding_;
6460
}
6561
else {

src/main/java/com/gargoylesoftware/css/dom/CSSFontFaceRuleImpl.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ public CSSFontFaceRuleImpl(final CSSStyleSheetImpl parentStyleSheet, final Abstr
3737
super(parentStyleSheet, parentRule);
3838
}
3939

40-
public CSSRuleType getType() {
41-
return CSSRuleType.FONT_FACE_RULE;
42-
}
43-
4440
/**
4541
* {@inheritDoc}
4642
*/
@@ -70,7 +66,7 @@ public void setCssText(final String cssText) throws DOMException {
7066
final AbstractCSSRuleImpl r = parser.parseRule(is);
7167

7268
// The rule must be a font face rule
73-
if (r.getType() == CSSRuleType.FONT_FACE_RULE) {
69+
if (r instanceof CSSFontFaceRuleImpl) {
7470
style_ = ((CSSFontFaceRuleImpl) r).style_;
7571
}
7672
else {

src/main/java/com/gargoylesoftware/css/dom/CSSImportRuleImpl.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ public CSSImportRuleImpl(
5252
media_ = media;
5353
}
5454

55-
public CSSRuleType getType() {
56-
return CSSRuleType.IMPORT_RULE;
57-
}
58-
5955
/**
6056
* {@inheritDoc}
6157
*/
@@ -90,7 +86,7 @@ public void setCssText(final String cssText) throws DOMException {
9086
final AbstractCSSRuleImpl r = parser.parseRule(is);
9187

9288
// The rule must be an import rule
93-
if (r.getType() == CSSRuleType.IMPORT_RULE) {
89+
if (r instanceof CSSImportRuleImpl) {
9490
href_ = ((CSSImportRuleImpl) r).href_;
9591
media_ = ((CSSImportRuleImpl) r).media_;
9692
}

src/main/java/com/gargoylesoftware/css/dom/CSSMediaRuleImpl.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ public CSSMediaRuleImpl(
5353
media_ = media;
5454
}
5555

56-
public CSSRuleType getType() {
57-
return CSSRuleType.MEDIA_RULE;
58-
}
59-
6056
/**
6157
* {@inheritDoc}
6258
*/
@@ -87,7 +83,7 @@ public void setCssText(final String cssText) throws DOMException {
8783
final AbstractCSSRuleImpl r = parser.parseRule(is);
8884

8985
// The rule must be a media rule
90-
if (r.getType() == CSSRuleType.MEDIA_RULE) {
86+
if (r instanceof CSSMediaRuleImpl) {
9187
media_ = ((CSSMediaRuleImpl) r).media_;
9288
cssRules_ = ((CSSMediaRuleImpl) r).cssRules_;
9389
}

src/main/java/com/gargoylesoftware/css/dom/CSSPageRuleImpl.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ public CSSPageRuleImpl(
4242
pseudoPage_ = pseudoPage;
4343
}
4444

45-
public CSSRuleType getType() {
46-
return CSSRuleType.PAGE_RULE;
47-
}
48-
4945
/**
5046
* {@inheritDoc}
5147
*/
@@ -82,7 +78,7 @@ public void setCssText(final String cssText) throws DOMException {
8278
final AbstractCSSRuleImpl r = parser.parseRule(is);
8379

8480
// The rule must be a page rule
85-
if (r.getType() == CSSRuleType.PAGE_RULE) {
81+
if (r instanceof CSSPageRuleImpl) {
8682
pseudoPage_ = ((CSSPageRuleImpl) r).pseudoPage_;
8783
style_ = ((CSSPageRuleImpl) r).style_;
8884
}

src/main/java/com/gargoylesoftware/css/dom/CSSStyleRuleImpl.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ public CSSStyleRuleImpl(final CSSStyleSheetImpl parentStyleSheet,
4949
selectors_ = selectors;
5050
}
5151

52-
public CSSRuleType getType() {
53-
return CSSRuleType.STYLE_RULE;
54-
}
55-
5652
/**
5753
* {@inheritDoc}
5854
*/
@@ -86,7 +82,7 @@ public void setCssText(final String cssText) throws DOMException {
8682
final AbstractCSSRuleImpl r = parser.parseRule(is);
8783

8884
// The rule must be a style rule
89-
if (r.getType() == CSSRuleType.STYLE_RULE) {
85+
if (r instanceof CSSStyleRuleImpl) {
9086
selectors_ = ((CSSStyleRuleImpl) r).selectors_;
9187
style_ = ((CSSStyleRuleImpl) r).style_;
9288
}

src/main/java/com/gargoylesoftware/css/dom/CSSStyleSheetImpl.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.w3c.dom.DOMException;
3131
import org.w3c.dom.Node;
3232

33-
import com.gargoylesoftware.css.dom.AbstractCSSRuleImpl.CSSRuleType;
3433
import com.gargoylesoftware.css.parser.CSSException;
3534
import com.gargoylesoftware.css.parser.CSSOMParser;
3635
import com.gargoylesoftware.css.parser.InputSource;
@@ -65,10 +64,6 @@ public CSSStyleSheetImpl() {
6564
super();
6665
}
6766

68-
public String getType() {
69-
return "text/css";
70-
}
71-
7267
/**
7368
* @return the disable state
7469
*/
@@ -138,23 +133,23 @@ public int insertRule(final String rule, final int index) throws DOMException {
138133
// We need to check that this type of rule can legally go into
139134
// the requested position.
140135
int msg = -1;
141-
if (r.getType() == CSSRuleType.CHARSET_RULE) {
136+
if (r instanceof CSSCharsetRuleImpl) {
142137

143138
// Index must be 0, and there can be only one charset rule
144139
if (index != 0) {
145140
msg = DOMExceptionImpl.CHARSET_NOT_FIRST;
146141
}
147-
else if (getCssRules().item(0).getType() == CSSRuleType.CHARSET_RULE) {
142+
else if (getCssRules().item(0) instanceof CSSCharsetRuleImpl) {
148143
msg = DOMExceptionImpl.CHARSET_NOT_UNIQUE;
149144
}
150145
}
151-
else if (r.getType() == CSSRuleType.IMPORT_RULE) {
146+
else if (r instanceof CSSImportRuleImpl) {
152147
// Import rules must preceed all other rules (except
153148
// charset rules)
154149
if (index <= getCssRules().getLength()) {
155150
for (int i = 0; i < index; i++) {
156-
final CSSRuleType rt = getCssRules().item(i).getType();
157-
if ((rt != CSSRuleType.CHARSET_RULE) && (rt != CSSRuleType.IMPORT_RULE)) {
151+
final AbstractCSSRuleImpl ri = getCssRules().item(i);
152+
if (!(ri instanceof CSSCharsetRuleImpl) && !(ri instanceof CSSImportRuleImpl)) {
158153
msg = DOMExceptionImpl.IMPORT_NOT_FIRST;
159154
break;
160155
}
@@ -164,8 +159,8 @@ else if (r.getType() == CSSRuleType.IMPORT_RULE) {
164159
else {
165160
if (index <= getCssRules().getLength()) {
166161
for (int i = index; i < getCssRules().getLength(); i++) {
167-
final CSSRuleType rt = getCssRules().item(i).getType();
168-
if ((rt == CSSRuleType.CHARSET_RULE) || (rt == CSSRuleType.IMPORT_RULE)) {
162+
final AbstractCSSRuleImpl ri = getCssRules().item(i);
163+
if ((ri instanceof CSSCharsetRuleImpl) || (ri instanceof CSSImportRuleImpl)) {
169164
msg = DOMExceptionImpl.INSERT_BEFORE_IMPORT;
170165
break;
171166
}

src/main/java/com/gargoylesoftware/css/dom/CSSUnknownRuleImpl.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ public CSSUnknownRuleImpl(
4747
text_ = text;
4848
}
4949

50-
public CSSRuleType getType() {
51-
return CSSRuleType.UNKNOWN_RULE;
52-
}
53-
5450
/**
5551
* {@inheritDoc}
5652
*/
@@ -75,7 +71,7 @@ public void setCssText(final String cssText) throws DOMException {
7571
final AbstractCSSRuleImpl r = parser.parseRule(is);
7672

7773
// The rule must be an unknown rule
78-
if (r.getType() == CSSRuleType.UNKNOWN_RULE) {
74+
if (r instanceof CSSUnknownRuleImpl) {
7975
text_ = ((CSSUnknownRuleImpl) r).text_;
8076
}
8177
else {

src/test/java/com/gargoylesoftware/css/dom/CSSCharsetRuleImplTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.junit.Assert;
2020
import org.junit.Test;
2121

22-
import com.gargoylesoftware.css.dom.AbstractCSSRuleImpl.CSSRuleType;
2322
import com.gargoylesoftware.css.parser.CSSOMParser;
2423
import com.gargoylesoftware.css.parser.InputSource;
2524

@@ -38,7 +37,6 @@ public void getCssText() throws Exception {
3837
final CSSCharsetRuleImpl value = parseCharsetRule("@charset \"utf-8\";");
3938

4039
Assert.assertEquals("@charset \"utf-8\";", value.getCssText());
41-
Assert.assertEquals(CSSRuleType.CHARSET_RULE, value.getType());
4240
Assert.assertEquals("@charset \"utf-8\";", value.toString());
4341
}
4442

@@ -50,12 +48,10 @@ public void setCssText() throws Exception {
5048
final CSSCharsetRuleImpl value = parseCharsetRule("@charset \"utf-8\";");
5149

5250
Assert.assertEquals("@charset \"utf-8\";", value.getCssText());
53-
Assert.assertEquals(CSSRuleType.CHARSET_RULE, value.getType());
5451
Assert.assertEquals("@charset \"utf-8\";", value.toString());
5552

5653
value.setCssText("@charset \"ASCII\";");
5754
Assert.assertEquals("@charset \"ASCII\";", value.getCssText());
58-
Assert.assertEquals(CSSRuleType.CHARSET_RULE, value.getType());
5955
Assert.assertEquals("@charset \"ASCII\";", value.toString());
6056

6157
}
@@ -90,7 +86,6 @@ public void setEncoding() throws Exception {
9086
public void type() throws Exception {
9187
final CSSCharsetRuleImpl value = new CSSCharsetRuleImpl(null, null, null);
9288

93-
Assert.assertEquals(CSSRuleType.CHARSET_RULE, value.getType());
9489
Assert.assertEquals("@charset \"\";", value.toString());
9590
}
9691

0 commit comments

Comments
 (0)