• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

future-architect / uroborosql / #715

pending completion
#715

push

web-flow
merge v0.x changes to master (#310)

* v0.x to master merge

* fix nanoseconds diff (java8 to java11)

* eclipse cleanup and  optimize import

* eclipse format

* optimize Imports

* remove unused annotation

* library version up

* migrate v0.x to master
- update java version 8 to 11
- update junit4 to junit5
- library version update

* fix test failed

* remove unused annotation

* fixed bug

* use var

* fix java8 coding style

1154 of 1154 new or added lines in 77 files covered. (100.0%)

7721 of 8533 relevant lines covered (90.48%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.0
/src/main/java/jp/co/future/uroborosql/node/IfNode.java
1
/**
2
 * Copyright (c) 2017-present, Future Corporation
3
 *
4
 * This source code is licensed under the MIT license found in the
5
 * LICENSE file in the root directory of this source tree.
6
 */
7
package jp.co.future.uroborosql.node;
8

9
import org.slf4j.Logger;
10
import org.slf4j.LoggerFactory;
11

12
import jp.co.future.uroborosql.coverage.PassedRoute;
13
import jp.co.future.uroborosql.exception.IllegalBoolExpressionRuntimeException;
14
import jp.co.future.uroborosql.expr.ExpressionParser;
15
import jp.co.future.uroborosql.parser.TransformContext;
16

17
/**
18
 * IF句を表すノード
19
 *
20
 * @author H.Sugimoto
21
 */
22
public class IfNode extends BranchNode {
23
        /** パーサーロガー */
24
        private static final Logger PARSER_LOG = LoggerFactory.getLogger("jp.co.future.uroborosql.parser");
1✔
25

26
        private final ExpressionParser expressionParser;
27
        /** 評価式 */
28
        private final String expression;
29

30
        /** ELSE句 */
31
        private ElseNode elseNode;
32

33
        /** ELSEIF句 */
34
        private IfNode elseIfNode;
35

36
        /**
37
         * コンストラクタ
38
         *
39
         * @param expressionParser ExpressionParser
40
         * @param position 開始位置
41
         * @param expression 評価式
42
         */
43
        public IfNode(final ExpressionParser expressionParser, final int position, final String expression) {
44
                super(position, expression.length() + 6);
1✔
45
                this.expressionParser = expressionParser;
1✔
46
                this.expression = expression.trim();
1✔
47
        }
1✔
48

49
        /**
50
         * 評価式の取得
51
         *
52
         * @return 評価式
53
         */
54
        public String getExpression() {
55
                return expression;
1✔
56
        }
57

58
        /**
59
         * ELSE句の取得
60
         *
61
         * @return ELSE句
62
         */
63
        public ElseNode getElseNode() {
64
                return elseNode;
1✔
65
        }
66

67
        /**
68
         * ELSE句の設定
69
         *
70
         * @param elseNode ELSE句
71
         */
72
        public void setElseNode(final ElseNode elseNode) {
73
                this.elseNode = elseNode;
1✔
74
        }
1✔
75

76
        /**
77
         * ELSEIF句の取得
78
         *
79
         * @return ELSEIF句
80
         */
81
        public IfNode getElseIfNode() {
82
                return elseIfNode;
1✔
83
        }
84

85
        /**
86
         * ELSEIF句の設定
87
         *
88
         * @param elseIfNode ELSEIF句
89
         */
90
        public void setElseIfNode(final IfNode elseIfNode) {
91
                this.elseIfNode = elseIfNode;
1✔
92
        }
1✔
93

94
        @Override
95
        public void accept(final TransformContext transformContext) {
96
                var expr = expressionParser.parse(expression);
1✔
97
                var result = expr.getValue(transformContext);
1✔
98

99
                if (result instanceof Boolean) {
1✔
100
                        var resultValue = (Boolean) result;
1✔
101
                        if (PARSER_LOG.isInfoEnabled()) {
1✔
102
                                if (Boolean.TRUE.toString().equalsIgnoreCase(expression)
×
103
                                                || Boolean.FALSE.toString().equalsIgnoreCase(expression)) {
×
104
                                        // 単純なBoolean評価の場合はログを出力しない
105
                                } else {
106
                                        var builder = expr.dumpNode(transformContext);
×
107
                                        PARSER_LOG.info("Evaluation Expression:[{}], Result:[{}], Parameter:[{}]", expression, resultValue,
×
108
                                                        builder.length() == 0 ? "" : builder.substring(0, builder.length() - 1));
×
109
                                }
110
                        }
111
                        passState(resultValue);
1✔
112
                        if (resultValue) {
1✔
113
                                transformContext.setEnabled(true);
1✔
114
                                super.accept(transformContext);
1✔
115
                        } else if (elseIfNode != null) {
1✔
116
                                elseIfNode.accept(transformContext);
1✔
117
                        } else if (elseNode != null) {
1✔
118
                                elseNode.accept(transformContext);
1✔
119
                        }
120
                } else {
1✔
121
                        throw new IllegalBoolExpressionRuntimeException(expression);
×
122
                }
123
        }
1✔
124

125
        /**
126
         * {@inheritDoc}
127
         *
128
         * @see jp.co.future.uroborosql.node.ContainerNode#passed(PassedRoute)
129
         */
130
        @Override
131
        public void passed(final PassedRoute passed) {
132
                passed.appendBranchState(getPosition(), getPosition() + getLength() - 1, getState());
1✔
133
                super.passed(passed);
1✔
134
                if (elseIfNode != null) {
1✔
135
                        elseIfNode.passed(passed);
1✔
136
                }
137
                if (elseNode != null) {
1✔
138
                        elseNode.passed(passed);
1✔
139
                }
140
        }
1✔
141
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc