45d307b471a1bfe24fac58f81ecbc35d0a7858c8
[policy/apex-pdp.git] / auth / cli-codegen / src / test / java / org / onap / policy / apex / auth / clicodegen / DummyStErrorListener.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.auth.clicodegen;
22
23 import org.stringtemplate.v4.STErrorListener;
24 import org.stringtemplate.v4.misc.STMessage;
25
26 /**
27  * Customized ST error listener.
28  *
29  * @author Sven van der Meer (sven.van.der.meer@ericsson.com)
30  */
31 public class DummyStErrorListener implements STErrorListener {
32
33     /** Counts errors of the listener. */
34     private int errorCount;
35
36     /**
37      * {@inheritDoc}.
38      */
39     @Override
40     public void IOError(final STMessage msg) {
41         switch (msg.error) {
42             default:
43                 this.registerErrors(msg);
44         }
45     }
46
47     /**
48      * {@inheritDoc}.
49      */
50     @Override
51     public void compileTimeError(final STMessage msg) {
52         switch (msg.error) {
53             default:
54                 this.registerErrors(msg);
55         }
56     }
57
58     /**
59      * {@inheritDoc}.
60      */
61     @Override
62     public void internalError(final STMessage msg) {
63         switch (msg.error) {
64             default:
65                 this.registerErrors(msg);
66         }
67     }
68
69     /**
70      * {@inheritDoc}.
71      */
72     @Override
73     public void runTimeError(final STMessage msg) {
74         switch (msg.error) {
75             case NO_SUCH_PROPERTY:
76             case ARGUMENT_COUNT_MISMATCH:
77             case ANON_ARGUMENT_MISMATCH:
78                 break;
79             default:
80                 this.registerErrors(msg);
81         }
82     }
83
84     /**
85      * Registers an error with the local error listener and increases the error count.
86      *
87      * @param msg error message
88      */
89     protected void registerErrors(final STMessage msg) {
90         setErrorCount(getErrorCount() + 1);
91         System.err.println("STG/ST (" + msg.error + ") " + msg.arg + " -> " + msg.cause);
92     }
93
94     /**
95      * Gets the error count.
96      *
97      * @return the error count
98      */
99     protected int getErrorCount() {
100         return errorCount;
101     }
102
103     /**
104      * Sets the error count.
105      *
106      * @param errorCount the new error count
107      */
108     protected void setErrorCount(final int errorCount) {
109         this.errorCount = errorCount;
110     }
111 }