Skip to content

Commit 832412e

Browse files
committed
refactoring
1 parent df16677 commit 832412e

File tree

13 files changed

+86
-78
lines changed

13 files changed

+86
-78
lines changed

src/main/java/com/igormaznitsa/prologparser/AstItem.java

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -167,26 +167,26 @@ private boolean isPrecedenceOk() {
167167
final Op wrappedOperator = (Op) ((TermWrapper) this.savedTerm).getWrappedTerm();
168168
switch (wrappedOperator.getAssoc()) {
169169
case FX:
170-
return this.leftItem == null &&
171-
(this.rightItem != null && this.rightItem.getPrecedence() < thisPrecedence);
170+
return this.leftItem == null
171+
&& (this.rightItem != null && this.rightItem.getPrecedence() < thisPrecedence);
172172
case FY:
173-
return this.leftItem == null &&
174-
(this.rightItem != null && this.rightItem.getPrecedence() <= thisPrecedence);
173+
return this.leftItem == null
174+
&& (this.rightItem != null && this.rightItem.getPrecedence() <= thisPrecedence);
175175
case YF:
176-
return (this.leftItem != null && this.leftItem.getPrecedence() <= thisPrecedence) &&
177-
this.rightItem == null;
176+
return (this.leftItem != null && this.leftItem.getPrecedence() <= thisPrecedence)
177+
&& this.rightItem == null;
178178
case XF:
179-
return (this.leftItem != null && this.leftItem.getPrecedence() < thisPrecedence) &&
180-
this.rightItem == null;
179+
return (this.leftItem != null && this.leftItem.getPrecedence() < thisPrecedence)
180+
&& this.rightItem == null;
181181
case XFX:
182-
return (this.leftItem != null && this.leftItem.getPrecedence() < thisPrecedence) &&
183-
(this.rightItem != null && this.rightItem.getPrecedence() < thisPrecedence);
182+
return (this.leftItem != null && this.leftItem.getPrecedence() < thisPrecedence)
183+
&& (this.rightItem != null && this.rightItem.getPrecedence() < thisPrecedence);
184184
case XFY:
185-
return (this.leftItem != null && this.leftItem.getPrecedence() < thisPrecedence) &&
186-
(this.rightItem != null && this.rightItem.getPrecedence() <= thisPrecedence);
185+
return (this.leftItem != null && this.leftItem.getPrecedence() < thisPrecedence)
186+
&& (this.rightItem != null && this.rightItem.getPrecedence() <= thisPrecedence);
187187
case YFX:
188-
return (this.leftItem != null && this.leftItem.getPrecedence() <= thisPrecedence) &&
189-
(this.rightItem != null && this.rightItem.getPrecedence() < thisPrecedence);
188+
return (this.leftItem != null && this.leftItem.getPrecedence() <= thisPrecedence)
189+
&& (this.rightItem != null && this.rightItem.getPrecedence() < thisPrecedence);
190190
default:
191191
throw new CriticalUnexpectedError();
192192
}
@@ -228,9 +228,9 @@ PrologTerm convertToTermAndRelease(final PrologParser parser) {
228228
}
229229

230230
if (this.leftItem == null) {
231-
if (this.rightItem.getType() == TermType.STRUCT &&
232-
this.rightItem.savedTerm.isAnyBlock() &&
233-
!((PrologStruct) this.rightItem.savedTerm).isEmpty()) {
231+
if (this.rightItem.getType() == TermType.STRUCT
232+
&& this.rightItem.savedTerm.isAnyBlock()
233+
&& !((PrologStruct) this.rightItem.savedTerm).isEmpty()) {
234234

235235
final PrologTerm rightTerm = this.rightItem.convertToTermAndRelease(parser);
236236
Op operator = (Op) wrapper.getWrappedTerm();
@@ -299,8 +299,8 @@ PrologTerm convertToTermAndRelease(final PrologParser parser) {
299299
final PrologTerm right;
300300

301301
if (!isPrecedenceOk()) {
302-
if (this.rightItem != null && this.rightItem.isOperator() &&
303-
this.rightItem.getOpAssoc().isPrefix()) {
302+
if (this.rightItem != null && this.rightItem.isOperator()
303+
&& this.rightItem.getOpAssoc().isPrefix()) {
304304
left = this.leftItem == null ? null : this.leftItem.convertToTermAndRelease(parser);
305305
right = new PrologStruct(Op.VIRTUAL_OPERATOR_BLOCK,
306306
new PrologTerm[] {this.rightItem.convertToTermAndRelease(parser)});
@@ -337,18 +337,18 @@ PrologTerm convertToTermAndRelease(final PrologParser parser) {
337337
break;
338338
case STRUCT: {
339339
final PrologStruct thisStruct = (PrologStruct) this.savedTerm;
340-
if ((thisStruct.getFunctor() == Op.VIRTUAL_OPERATOR_BLOCK ||
341-
thisStruct.getFunctor() == Op.VIRTUAL_OPERATOR_CURLY_BLOCK)
340+
if ((thisStruct.getFunctor() == Op.VIRTUAL_OPERATOR_BLOCK
341+
|| thisStruct.getFunctor() == Op.VIRTUAL_OPERATOR_CURLY_BLOCK)
342342
&& thisStruct.getArity() == 1) {
343343

344344
final PrologTerm thatTerm = thisStruct.getTermAt(0);
345345

346-
if (thatTerm.getType() == TermType.STRUCT &&
347-
(thatTerm.getFunctor() == Op.VIRTUAL_OPERATOR_BLOCK ||
348-
thatTerm.getFunctor() == Op.VIRTUAL_OPERATOR_CURLY_BLOCK)) {
346+
if (thatTerm.getType() == TermType.STRUCT
347+
&& (thatTerm.getFunctor() == Op.VIRTUAL_OPERATOR_BLOCK
348+
|| thatTerm.getFunctor() == Op.VIRTUAL_OPERATOR_CURLY_BLOCK)) {
349349
// rolling normal blocks
350-
result = thatTerm.isBlock() && this.isBlock() &&
351-
(this.parentItem == null || this.parentItem.isBlock()) ? thatTerm : thisStruct;
350+
result = thatTerm.isBlock() && this.isBlock()
351+
&& (this.parentItem == null || this.parentItem.isBlock()) ? thatTerm : thisStruct;
352352
} else {
353353
result = thisStruct;
354354
}

src/main/java/com/igormaznitsa/prologparser/ParserContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public interface ParserContext {
7070
int FLAG_ZERO_QUOTATION_ALLOWS_WHITESPACE_CHAR = 64;
7171

7272
/**
73-
* Check that the context contains an operator starts with some string
73+
* Check that the context contains an operator starts with some string.
7474
*
7575
* @param source source prolog parser making request, must not be null
7676
* @param namePrefix string to be used to look for operator starts with it, must not be null

src/main/java/com/igormaznitsa/prologparser/PrologParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,8 @@ private PrologTerm readBlock(final Koi7CharOpMap endOperators) {
592592
}
593593
} else if (currentTreeItem.getPrecedence() > readAtomPrecedence) {
594594
// new has greater precedence
595-
if (readAtomTreeItem.getType() != TermType.OPERATOR &&
596-
currentTreeItem.getRightBranch() != null) {
595+
if (readAtomTreeItem.getType() != TermType.OPERATOR
596+
&& currentTreeItem.getRightBranch() != null) {
597597
// it's a ground atom and its right branch is not empty
598598
throw new PrologParserException(
599599
"There is no any operator before the atom",

src/main/java/com/igormaznitsa/prologparser/exceptions/CharBufferOverflowException.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
package com.igormaznitsa.prologparser.exceptions;
2323

2424
/**
25-
* Specialized exception shows that allowed char buffer size of one buffers in a tokenizer is reached.
25+
* Specialized exception shows that allowed char buffer size of one buffers
26+
* in a tokenizer is reached.
2627
*/
2728
public class CharBufferOverflowException extends PrologParserException {
2829

@@ -33,7 +34,8 @@ public class CharBufferOverflowException extends PrologParserException {
3334
/**
3435
* Constructor.
3536
*
36-
* @param bufferText current buffer content which is cause of the error, can be null but in the case it will be converted into empty string.
37+
* @param bufferText current buffer content which is cause of the error, can be null but
38+
* in the case it will be converted into empty string.
3739
*/
3840
public CharBufferOverflowException(final String bufferText) {
3941
super("Char buffer limit is reached", -1, -1);

src/main/java/com/igormaznitsa/prologparser/terms/OpContainer.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,30 +87,33 @@ public boolean add(final Op operator) {
8787

8888
switch (operator.getAssoc()) {
8989
case FX:
90-
case FY:
90+
case FY: {
9191
if (this.opFZ != null) {
9292
return false;
9393
}
9494
this.opFZ = operator;
9595
this.numberAtContainer++;
96-
break;
96+
}
97+
break;
9798
case XF:
98-
case YF:
99+
case YF: {
99100
if (this.opZF != null) {
100101
return false;
101102
}
102103
this.opZF = operator;
103104
this.numberAtContainer++;
104-
break;
105+
}
106+
break;
105107
case XFX:
106108
case XFY:
107-
case YFX:
109+
case YFX: {
108110
if (this.opZFZ != null) {
109111
return false;
110112
}
111113
this.opZFZ = operator;
112114
this.numberAtContainer++;
113-
break;
115+
}
116+
break;
114117
default:
115118
throw new CriticalUnexpectedError();
116119
}

src/main/java/com/igormaznitsa/prologparser/terms/PrologCompound.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public PrologCompound(final String text) {
3232
}
3333

3434
/**
35-
* Get element for its position
35+
* Get element for its position.
3636
*
3737
* @param position zero-based element position
3838
* @return element in position

src/main/java/com/igormaznitsa/prologparser/terms/PrologInt.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public Number getNumber() {
110110
}
111111

112112
/**
113-
* Get the value as BigInteger
113+
* Get the value as BigInteger.
114114
*
115115
* @return the value as BigInteger
116116
*/

src/main/java/com/igormaznitsa/prologparser/terms/PrologList.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public void setHead(final PrologTerm term) {
138138
}
139139

140140
/**
141-
* Get the current tail element
141+
* Get the current tail element.
142142
*
143143
* @return the current tail element, can be null
144144
*/
@@ -147,7 +147,7 @@ public PrologTerm getTail() {
147147
}
148148

149149
/**
150-
* Set the current tail element
150+
* Set the current tail element.
151151
*
152152
* @param term the new tail element, can be null
153153
*/

src/main/java/com/igormaznitsa/prologparser/terms/PrologNumeric.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ public String getText() {
5555
}
5656

5757
/**
58-
* Check that the number is negative one
58+
* Check that the number is negative one.
5959
*
6060
* @return true if the number is negative one, false otherwise
6161
*/
6262
public abstract boolean isNegative();
6363

6464
/**
65-
* Make negative representation of the numeric term
65+
* Make negative representation of the numeric term.
6666
*
6767
* @return the negative variant of the numeric
6868
*/

src/main/java/com/igormaznitsa/prologparser/terms/PrologTerm.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ public static Quotation findQuotation(final String atomText) {
7070
result = SINGLE;
7171
} else {
7272
char chr = atomText.charAt(0);
73-
if (!Character.isLetter(chr) || Character.isDigit(chr) || Character.isUpperCase(chr) ||
74-
Character.isISOControl(chr) || Character.isWhitespace(chr)) {
73+
if (!Character.isLetter(chr) || Character.isDigit(chr) || Character.isUpperCase(chr)
74+
|| Character.isISOControl(chr) || Character.isWhitespace(chr)) {
7575
result = SINGLE;
7676
} else {
7777

7878
for (int i = 1; i < atomText.length(); i++) {
7979
chr = atomText.charAt(i);
80-
if (Character.isWhitespace(chr) || (chr != '_' && !Character.isLetterOrDigit(chr)) ||
81-
Character.isISOControl(chr)) {
80+
if (Character.isWhitespace(chr) || (chr != '_' && !Character.isLetterOrDigit(chr))
81+
|| Character.isISOControl(chr)) {
8282
result = SINGLE;
8383
break;
8484
}

0 commit comments

Comments
 (0)