Skip to content

Commit f49a467

Browse files
committed
introduce Combinator enum
1 parent 3f4b4d6 commit f49a467

File tree

3 files changed

+3413
-3346
lines changed

3 files changed

+3413
-3346
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2019-2024 Ronald Brill.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* https://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
package org.htmlunit.cssparser.parser.selector;
16+
17+
/**
18+
* <p>Combinator enum.</p>
19+
*
20+
* @author Ronald Brill
21+
*/
22+
public enum Combinator {
23+
24+
/** DESCENDANT_COMBINATOR ( ). */
25+
DESCENDANT_COMBINATOR(' '),
26+
27+
/** CHILD_COMBINATOR (&gt;). */
28+
CHILD_COMBINATOR('>'),
29+
30+
/** NEXT_SIBLING_COMBINATOR (+). */
31+
NEXT_SIBLING_COMBINATOR('+'),
32+
33+
/** SUBSEQUENT_SIBLING_COMBINATOR (~). */
34+
SUBSEQUENT_SIBLING_COMBINATOR('~');
35+
36+
private final char combinatorChar_;
37+
38+
Combinator(final char combinatorChar) {
39+
combinatorChar_ = combinatorChar;
40+
}
41+
42+
char getChar() {
43+
return combinatorChar_;
44+
}
45+
46+
/**
47+
* {@inheritDoc}
48+
*/
49+
@Override
50+
public String toString() {
51+
return name() + " ('" + getChar() + "')";
52+
}
53+
}

src/main/java/org/htmlunit/cssparser/parser/selector/RelativeSelector.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
*/
2020
public class RelativeSelector extends AbstractSelector {
2121

22-
private final char combinator_;
22+
private final Combinator combinator_;
2323
private final Selector selector_;
2424

2525
/**
2626
* Ctor.
2727
* @param combinator the combinator to use
2828
* @param selector the selector
2929
*/
30-
public RelativeSelector(final char combinator, final Selector selector) {
30+
public RelativeSelector(final Combinator combinator, final Selector selector) {
3131
combinator_ = combinator;
3232
selector_ = selector;
3333
}
@@ -44,6 +44,13 @@ public SelectorType getSelectorType() {
4444
return SelectorType.RELATIVE_SELECTOR;
4545
}
4646

47+
/**
48+
* @return the combinator
49+
*/
50+
public Combinator getCombinator() {
51+
return combinator_;
52+
}
53+
4754
@Override
4855
public SimpleSelector getSimpleSelector() {
4956
return null;
@@ -52,6 +59,6 @@ public SimpleSelector getSimpleSelector() {
5259
/** {@inheritDoc} */
5360
@Override
5461
public String toString() {
55-
return combinator_ + " " + selector_.toString();
62+
return combinator_.getChar() + " " + selector_.toString();
5663
}
5764
}

0 commit comments

Comments
 (0)