Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Dec 10, 2023
1 parent 7b1a3ac commit 693bb46
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 114 deletions.
11 changes: 11 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@

<module name="TreeWalker">

<property name="tabWidth" value="4"/>

<module name="AnnotationUseStyle"/>

<module name="LeftCurly">
<property name="option" value="eol"/>
</module>
<module name="RightCurly">
<property name="option" value="alone"/>
<property name="tokens" value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO, STATIC_INIT, INSTANCE_INIT"/>
</module>

<!-- Checks for Naming Conventions. -->
<!-- See http://checkstyle.sf.net/config_naming.html -->
Expand Down
13 changes: 0 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<checkstyle.version>10.12.5</checkstyle.version>
<spotbugs.version>4.8.1</spotbugs.version>
<pmd.version>6.55.0</pmd.version>
<spotless.version>2.38.0</spotless.version>
<dependencycheck.version>8.4.3</dependencycheck.version>
</properties>

Expand Down Expand Up @@ -194,18 +193,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless.version}</version>
<configuration>
<java>
<googleJavaFormat>
<version>1.8</version>
</googleJavaFormat>
</java>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/htmlunit/xpath/NodeSetDTM.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ public int previousNode() {

/** {@inheritDoc} */
@Override
public void detach() {}
public void detach() {
}

/** {@inheritDoc} */
@Override
Expand Down Expand Up @@ -222,8 +223,7 @@ public void addNode(final int n) {
* @throws RuntimeException thrown if this NodeSetDTM is not of a mutable type.
*/
public void addNodes(final DTMIterator iterator) {
if (null != iterator) // defensive to fix a bug that Sanjiva reported.
{
if (null != iterator) { // defensive to fix a bug that Sanjiva reported.
int obj;

while (DTM.NULL != (obj = iterator.nextNode())) {
Expand Down Expand Up @@ -268,7 +268,8 @@ public void addNodeInDocOrder(final int node, final boolean test, final XPathCon
if (i != -2) {
insertElementAt(node, i + 1);
}
} else {
}
else {
final int insertIndex = this.size();

boolean foundit = false;
Expand Down
34 changes: 20 additions & 14 deletions src/main/java/org/htmlunit/xpath/axes/WalkerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ static AxesWalker loadWalkers(
// walker.setAnalysis(analysis);
if (null == firstWalker) {
firstWalker = walker;
} else {
}
else {
prevWalker.setNextWalker(walker);
walker.setPrevWalker(prevWalker);
}
Expand Down Expand Up @@ -137,7 +138,8 @@ else if (walksChildrenOnly(analysis) && isOneStep) {

// Use simple child iteration without any test.
iter = new ChildIterator(analysis);
} else {
}
else {
if (DEBUG_ITERATOR_CREATION) diagnoseIterator("ChildTestIterator", analysis, compiler);

// Else use simple node test iteration with predicate test.
Expand All @@ -151,7 +153,8 @@ else if (isOneStep && walksAttributes(analysis)) {
// Then use a simple iteration of the attributes, with node test
// and predicate testing.
iter = new AttributeIterator(compiler, opPos, analysis);
} else if (isOneStep && !walksFilteredList(analysis)) {
}
else if (isOneStep && !walksFilteredList(analysis)) {
if (!walksNamespaces(analysis)
&& (walksInDocOrder(analysis) || isSet(analysis, BIT_PARENT))) {
if (false || DEBUG_ITERATOR_CREATION)
Expand All @@ -160,7 +163,8 @@ else if (isOneStep && walksAttributes(analysis)) {
// Then use a simple iteration of the attributes, with node test
// and predicate testing.
iter = new OneStepIteratorForward(compiler, opPos, analysis);
} else {
}
else {
if (false || DEBUG_ITERATOR_CREATION)
diagnoseIterator("OneStepIterator", analysis, compiler);

Expand Down Expand Up @@ -190,14 +194,16 @@ else if (isOptimizableForDescendantIterator(compiler, firstStepPos)
if (DEBUG_ITERATOR_CREATION) diagnoseIterator("DescendantIterator", analysis, compiler);

iter = new DescendantIterator(compiler, opPos, analysis);
} else {
}
else {
if (isNaturalDocOrder(compiler, firstStepPos, analysis)) {
if (false || DEBUG_ITERATOR_CREATION) {
diagnoseIterator("WalkingIterator", analysis, compiler);
}

iter = new WalkingIterator(compiler, opPos, analysis, true);
} else {
}
else {
// if (DEBUG_ITERATOR_CREATION)
// diagnoseIterator("MatchPatternIterator", analysis, compiler);
//
Expand Down Expand Up @@ -272,8 +278,7 @@ public static int getAxisFromStep(final Compiler compiler, final int stepOpCodeP
* @return One of BIT_ANCESTOR, etc.
*/
public static int getAnalysisBitFromAxes(final int axis) {
switch (axis) // Generate new traverser
{
switch (axis) { // Generate new traverser
case Axis.ANCESTOR:
return BIT_ANCESTOR;
case Axis.ANCESTORORSELF:
Expand Down Expand Up @@ -613,8 +618,7 @@ private static int analyze(final Compiler compiler, int stepOpCodePos)
new Object[] {Integer.toString(stepType)}));
}

if (OpCodes.NODETYPE_NODE == compiler.getOp(stepOpCodePos + 3)) // child::node()
{
if (OpCodes.NODETYPE_NODE == compiler.getOp(stepOpCodePos + 3)) { // child::node()
analysisResult |= BIT_NODETEST_ANY;
}

Expand Down Expand Up @@ -678,8 +682,8 @@ static StepPattern loadSteps(final Compiler compiler, int stepOpCodePos)

if (null == firstStep) {
firstStep = step;
} else {

}
else {
// prevStep.setNextWalker(step);
step.setRelativePathPattern(prevStep);
}
Expand Down Expand Up @@ -752,7 +756,8 @@ static StepPattern loadSteps(final Compiler compiler, int stepOpCodePos)
else if (Axis.DESCENDANT == pat.getAxis()) pat.setAxis(Axis.DESCENDANTORSELF);

pat = attrPat;
} else if (Axis.CHILD == pat.getAxis()) {
}
else if (Axis.CHILD == pat.getAxis()) {
// In this case just change the axis.
// pat.setWhatToShow(whatToShow);
pat.setAxis(Axis.ATTRIBUTE);
Expand Down Expand Up @@ -993,7 +998,8 @@ private static AxesWalker createDefaultWalker(

if (simpleInit) {
ai.initNodeTest(DTMFilter.SHOW_ALL);
} else {
}
else {
final int whatToShow = compiler.getWhatToShow(opPos);

if ((0
Expand Down
61 changes: 40 additions & 21 deletions src/main/java/org/htmlunit/xpath/compiler/Lexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ void tokenize(final String pat, final List<String> targetStrings)
char c = pat.charAt(i);

switch (c) {
case '\"':
{
case '\"': {
if (startSubstring != -1) {
isNum = false;
isStartOfPat = mapPatternElemPos(nesting, isStartOfPat, isAttrName);
isAttrName = false;

if (-1 != posOfNSSep) {
posOfNSSep = mapNSTokens(pat, startSubstring, posOfNSSep, i);
} else {
}
else {
addToTokenQueue(pat.substring(startSubstring, i));
}
}
Expand All @@ -124,7 +124,8 @@ void tokenize(final String pat, final List<String> targetStrings)
addToTokenQueue(pat.substring(startSubstring, i + 1));

startSubstring = -1;
} else {
}
else {
m_processor.error(XPATHErrorResources.ER_EXPECTED_DOUBLE_QUOTE, null);
}
}
Expand All @@ -137,7 +138,8 @@ void tokenize(final String pat, final List<String> targetStrings)

if (-1 != posOfNSSep) {
posOfNSSep = mapNSTokens(pat, startSubstring, posOfNSSep, i);
} else {
}
else {
addToTokenQueue(pat.substring(startSubstring, i));
}
}
Expand All @@ -151,7 +153,8 @@ void tokenize(final String pat, final List<String> targetStrings)
addToTokenQueue(pat.substring(startSubstring, i + 1));

startSubstring = -1;
} else {
}
else {
m_processor.error(XPATHErrorResources.ER_EXPECTED_SINGLE_QUOTE, null);
}
break;
Expand All @@ -166,7 +169,8 @@ void tokenize(final String pat, final List<String> targetStrings)

if (-1 != posOfNSSep) {
posOfNSSep = mapNSTokens(pat, startSubstring, posOfNSSep, i);
} else {
}
else {
addToTokenQueue(pat.substring(startSubstring, i));
}

Expand Down Expand Up @@ -210,14 +214,17 @@ void tokenize(final String pat, final List<String> targetStrings)

if (-1 != posOfNSSep) {
posOfNSSep = mapNSTokens(pat, startSubstring, posOfNSSep, i);
} else {
}
else {
addToTokenQueue(pat.substring(startSubstring, i));
}

startSubstring = -1;
} else if (('/' == c) && isStartOfPat) {
}
else if (('/' == c) && isStartOfPat) {
isStartOfPat = mapPatternElemPos(nesting, isStartOfPat, isAttrName);
} else if ('*' == c) {
}
else if ('*' == c) {
isStartOfPat = mapPatternElemPos(nesting, isStartOfPat, isAttrName);
isAttrName = false;
}
Expand All @@ -234,7 +241,8 @@ void tokenize(final String pat, final List<String> targetStrings)

if ((')' == c) || (']' == c)) {
nesting--;
} else if (('(' == c) || ('[' == c)) {
}
else if (('(' == c) || ('[' == c)) {
nesting++;
}

Expand Down Expand Up @@ -264,7 +272,8 @@ void tokenize(final String pat, final List<String> targetStrings)
if (-1 == startSubstring) {
startSubstring = i;
isNum = Character.isDigit(c);
} else if (isNum) {
}
else if (isNum) {
isNum = Character.isDigit(c);
}
}
Expand All @@ -277,15 +286,19 @@ void tokenize(final String pat, final List<String> targetStrings)
if ((-1 != posOfNSSep)
|| ((m_namespaceContext != null) && (m_namespaceContext.handlesNullPrefixes()))) {
posOfNSSep = mapNSTokens(pat, startSubstring, posOfNSSep, nChars);
} else {
}
else {
addToTokenQueue(pat.substring(startSubstring, nChars));
}
}

if (0 == m_compiler.getTokenQueueSize()) {
m_processor.error(XPATHErrorResources.ER_EMPTY_EXPRESSION, null);
} else if (null != targetStrings) {
recordTokenString(targetStrings);
}
else {
if (null != targetStrings) {
recordTokenString(targetStrings);
}
}

m_processor.m_queueMark = 0;
Expand Down Expand Up @@ -350,7 +363,8 @@ private void resetTokenMark(final int mark) {
if (m_processor.m_queueMark < qsz) {
m_processor.m_token = (String) m_compiler.getTokenQueue().get(m_processor.m_queueMark++);
m_processor.m_tokenChar = m_processor.m_token.charAt(0);
} else {
}
else {
m_processor.m_token = null;
m_processor.m_tokenChar = 0;
}
Expand All @@ -370,7 +384,8 @@ final int getKeywordToken(final String key) {
final Integer itok = (Integer) Keywords.getKeyWord(key);

tok = (null != itok) ? itok.intValue() : 0;
} catch (NullPointerException | ClassCastException npe) {
}
catch (NullPointerException | ClassCastException npe) {
tok = 0;
}

Expand Down Expand Up @@ -413,7 +428,8 @@ private void recordTokenString(final List<String> targetStrings) {
default:
targetStrings.add(PseudoNames.PSEUDONAME_ANY);
}
} else {
}
else {
if (m_processor.tokenIs('@')) {
tokPos++;

Expand Down Expand Up @@ -477,10 +493,12 @@ private int mapNSTokens(
}
uName = m_namespaceContext.getNamespaceForPrefix(prefix);
}
} catch (final ClassCastException cce) {
}
catch (final ClassCastException cce) {
uName = m_namespaceContext.getNamespaceForPrefix(prefix);
}
} else {
}
else {
uName = prefix;
}

Expand All @@ -491,7 +509,8 @@ private int mapNSTokens(
final String s = pat.substring(posOfNSSep + 1, posOfScan);

if (s.length() > 0) addToTokenQueue(s);
} else {
}
else {
m_processor.error(XPATHErrorResources.ER_PREFIX_MUST_RESOLVE, new String[] {prefix});
}

Expand Down
Loading

0 comments on commit 693bb46

Please sign in to comment.