REQ-2135: simplify code
This commit is contained in:
parent
c2881b2396
commit
289202ba85
@ -20,26 +20,26 @@ class AnalyzeVisitor implements SQLASTVisitor {
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLBinaryOpExpr x) {
|
||||
String column = EvalVisitor.findColumn(x.getLeft());
|
||||
String column = EvalValueVisitor.findColumn(x.getLeft());
|
||||
if (column == null) return;
|
||||
if (shouldCollectAsFailMatch(x)) {
|
||||
Object value = record.getValue(column, SetTypeVisitor.getType(x));
|
||||
Object value = record.getValue(column, EvalTypeVisitor.getType(x));
|
||||
analyzeResult.addFailMatch(new FailMatch(x, column, value));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLInListExpr x) {
|
||||
String column = EvalVisitor.findColumn(x.getExpr());
|
||||
String column = EvalValueVisitor.findColumn(x.getExpr());
|
||||
if (column == null) return;
|
||||
if (shouldCollectAsFailMatch(x)) {
|
||||
Object value = record.getValue(column, SetTypeVisitor.getType(x));
|
||||
Object value = record.getValue(column, EvalTypeVisitor.getType(x));
|
||||
analyzeResult.addFailMatch(new FailMatch(x, column, value));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shouldCollectAsFailMatch(SQLObject x) {
|
||||
Object value = EvalVisitor.getValue(x);
|
||||
Object value = EvalValueVisitor.getValue(x);
|
||||
if (value instanceof Boolean && (Boolean) value)
|
||||
return false;
|
||||
SQLObject parent = x.getParent();
|
||||
|
||||
@ -17,11 +17,13 @@ import java.util.Date;
|
||||
/**
|
||||
* @author yanglin
|
||||
*/
|
||||
class SetTypeVisitor implements SQLASTVisitor {
|
||||
class EvalTypeVisitor implements SQLASTVisitor {
|
||||
|
||||
private static final String TYPE = "type";
|
||||
private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.Ss");
|
||||
static final SetTypeVisitor INSTANCE = new SetTypeVisitor();
|
||||
static final EvalTypeVisitor INSTANCE = new EvalTypeVisitor();
|
||||
|
||||
private EvalTypeVisitor() {}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLNumberExpr x) {
|
||||
@ -34,7 +34,7 @@ import static java.util.stream.Collectors.toSet;
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
class EvalVisitor implements SQLASTVisitor {
|
||||
class EvalValueVisitor implements SQLASTVisitor {
|
||||
|
||||
private static final String VALUE = "value";
|
||||
|
||||
@ -101,7 +101,7 @@ class EvalVisitor implements SQLASTVisitor {
|
||||
}
|
||||
String column = findColumn(x.getExpr());
|
||||
Object value = column != null
|
||||
? record.getValue(column, SetTypeVisitor.getType(x))
|
||||
? record.getValue(column, EvalTypeVisitor.getType(x))
|
||||
: x.getExpr().getAttribute(VALUE);
|
||||
Set<Object> listValues = targetList.stream()
|
||||
.map(t -> t.getAttribute(VALUE))
|
||||
@ -139,7 +139,7 @@ class EvalVisitor implements SQLASTVisitor {
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLCharExpr x) {
|
||||
Date date = SetTypeVisitor.asDate(x);
|
||||
Date date = EvalTypeVisitor.asDate(x);
|
||||
if (date != null)
|
||||
x.putAttribute(VALUE, date);
|
||||
else
|
||||
@ -149,7 +149,7 @@ class EvalVisitor implements SQLASTVisitor {
|
||||
@Override
|
||||
public void endVisit(SQLIdentifierExpr x) {
|
||||
String column = findColumn(x);
|
||||
Object value = record.getValue(column, SetTypeVisitor.getType(x.getParent()));
|
||||
Object value = record.getValue(column, EvalTypeVisitor.getType(x.getParent()));
|
||||
x.putAttribute(VALUE, value);
|
||||
}
|
||||
|
||||
@ -36,8 +36,8 @@ public class SimpleAnalyzer {
|
||||
return result;
|
||||
}
|
||||
Record record = new Record(value);
|
||||
whereExpr.accept(SetTypeVisitor.INSTANCE);
|
||||
whereExpr.accept(new EvalVisitor(record));
|
||||
whereExpr.accept(EvalTypeVisitor.INSTANCE);
|
||||
whereExpr.accept(new EvalValueVisitor(record));
|
||||
AnalyzeVisitor analyzeVisitor = new AnalyzeVisitor(record);
|
||||
whereExpr.accept(analyzeVisitor);
|
||||
return analyzeVisitor.getAnalyzeResult();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user