Browse Source

refactor:desgin smells refactored

pull/1008/head
Vaibhav Ramchandani 11 months ago
parent
commit
f9054b56f4
  1. 33
      json-path/src/main/java/com/jayway/jsonpath/InvalidCriteriaException.java
  2. 1
      json-path/src/main/java/com/jayway/jsonpath/JsonPathException.java
  3. 31
      json-path/src/main/java/com/jayway/jsonpath/internal/filter/FilterCompiler.java

33
json-path/src/main/java/com/jayway/jsonpath/InvalidCriteriaException.java

@ -1,33 +0,0 @@
/*
* Copyright 2011 the original author or authors.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jayway.jsonpath;
@SuppressWarnings("serial")
public class InvalidCriteriaException extends JsonPathException {
public InvalidCriteriaException() {
}
public InvalidCriteriaException(String message) {
super(message);
}
public InvalidCriteriaException(String message, Throwable cause) {
super(message, cause);
}
public InvalidCriteriaException(Throwable cause) {
super(cause);
}
}

1
json-path/src/main/java/com/jayway/jsonpath/JsonPathException.java

@ -17,6 +17,7 @@ package com.jayway.jsonpath;
public class JsonPathException extends RuntimeException {
public JsonPathException() {
super();
}
public JsonPathException(String message) {

31
json-path/src/main/java/com/jayway/jsonpath/internal/filter/FilterCompiler.java

@ -357,8 +357,17 @@ public class FilterCompiler {
filter.incrementPosition(1); //skip $ and @
while (filter.inBounds()) {
if (filter.currentChar() == OPEN_SQUARE_BRACKET) {
handleSquareBracket();
} else if (shouldBreakParsing()) {
int closingSquareBracketIndex = filter.indexOfMatchingCloseChar(filter.position(), OPEN_SQUARE_BRACKET, CLOSE_SQUARE_BRACKET, true, false);
if (closingSquareBracketIndex == -1) {
throw new InvalidPathException("Square brackets does not match in filter " + filter);
} else {
filter.setPosition(closingSquareBracketIndex + 1);
}
}
boolean closingFunctionBracket = (filter.currentChar() == CLOSE_PARENTHESIS && currentCharIsClosingFunctionBracket(begin));
boolean closingLogicalBracket = (filter.currentChar() == CLOSE_PARENTHESIS && !closingFunctionBracket);
if (!filter.inBounds() || isRelationalOperatorChar(filter.currentChar()) || filter.currentChar() == SPACE || closingLogicalBracket) {
break;
} else {
filter.incrementPosition(1);
@ -370,24 +379,6 @@ public class FilterCompiler {
return ValueNode.createPathNode(path, false, shouldExists);
}
private void handleSquareBracket() {
int closingSquareBracketIndex = filter.indexOfMatchingCloseChar(filter.position(), OPEN_SQUARE_BRACKET, CLOSE_SQUARE_BRACKET, true, false);
if (closingSquareBracketIndex == -1) {
throw new InvalidPathException("Square brackets do not match in filter " + filter);
} else {
filter.setPosition(closingSquareBracketIndex + 1);
}
}
private boolean shouldBreakParsing() {
return !filter.inBounds() || isRelationalOperatorChar(filter.currentChar()) || filter.currentChar() == SPACE || closingLogicalBracket();
}
private boolean closingLogicalBracket() {
boolean closingFunctionBracket = (filter.currentChar() == CLOSE_PARENTHESIS && currentCharIsClosingFunctionBracket(filter.position()));
return (filter.currentChar() == CLOSE_PARENTHESIS && !closingFunctionBracket);
}
private boolean expressionIsTerminated(){
char c = filter.currentChar();

Loading…
Cancel
Save