X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=sli%2Fcommon%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fsdnc%2Fsli%2FSvcLogicExprListener.java;fp=sli%2Fcommon%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fsdnc%2Fsli%2FSvcLogicExprListener.java;h=0000000000000000000000000000000000000000;hb=3cd5e19b313f5835335d04f1f002ff858fcf174f;hp=4fef12fbcbdea4b6f2f2de72bc12d6b368125b4c;hpb=b7cb3b7c57d78b2be23290c201c9517965055d24;p=sdnc%2Fcore.git diff --git a/sli/common/src/main/java/org/openecomp/sdnc/sli/SvcLogicExprListener.java b/sli/common/src/main/java/org/openecomp/sdnc/sli/SvcLogicExprListener.java deleted file mode 100644 index 4fef12f..0000000 --- a/sli/common/src/main/java/org/openecomp/sdnc/sli/SvcLogicExprListener.java +++ /dev/null @@ -1,316 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdnc.sli; - -import java.util.LinkedList; -import java.util.List; - -import org.antlr.v4.runtime.tree.TerminalNode; -import org.openecomp.sdnc.sli.ExprGrammarParser.AddExprContext; -import org.openecomp.sdnc.sli.ExprGrammarParser.AtomContext; -import org.openecomp.sdnc.sli.ExprGrammarParser.CompareExprContext; -import org.openecomp.sdnc.sli.ExprGrammarParser.ConstantContext; -import org.openecomp.sdnc.sli.ExprGrammarParser.ExprContext; -import org.openecomp.sdnc.sli.ExprGrammarParser.FuncExprContext; -import org.openecomp.sdnc.sli.ExprGrammarParser.MultExprContext; -import org.openecomp.sdnc.sli.ExprGrammarParser.ParenExprContext; -import org.openecomp.sdnc.sli.ExprGrammarParser.RelExprContext; -import org.openecomp.sdnc.sli.ExprGrammarParser.VariableContext; -import org.openecomp.sdnc.sli.ExprGrammarParser.VariableLeadContext; -import org.openecomp.sdnc.sli.ExprGrammarParser.VariableTermContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SvcLogicExprListener extends ExprGrammarBaseListener -{ - - - - - private static final Logger LOG = LoggerFactory - .getLogger(SvcLogicExprListener.class); - - private SvcLogicExpression curExpr; - private SvcLogicExpression topExpr; - private LinkedList exprStack; - - public SvcLogicExprListener() - { - exprStack = new LinkedList(); - } - - public SvcLogicExpression getParsedExpr() - { - return(curExpr); - } - - private void pushOperand(SvcLogicExpression operand) - { - if (curExpr == null) - { - curExpr = operand; - } - else - { - curExpr.addOperand(operand); - } - } - - private void pushExpr(SvcLogicExpression expr) - { - LOG.trace("Pushing expression ["+expr.getClass().getName()+"]"); - if (curExpr != null) - { - exprStack.push(curExpr); - } - curExpr = expr; - } - - private void popExpr() - { - if (exprStack.isEmpty()) - { - LOG.trace("Popping last expression"); - topExpr = curExpr; - } - else - { - SvcLogicExpression lastExpr = curExpr; - curExpr = exprStack.pop(); - curExpr.addOperand(lastExpr); - LOG.trace("New curExpr is ["+curExpr.getClass().getName()+"]"); - } - - } - - @Override - public void enterAtom(AtomContext ctx) { - - String atomText = ctx.getText(); - - LOG.trace("enterAtom: text = "+atomText); - - - SvcLogicAtom newAtom = new SvcLogicAtom(atomText); - - pushExpr(newAtom); - } - - - @Override - public void enterMultExpr(MultExprContext ctx) { - LOG.trace("enterMultExpr: text = "+ctx.getText()); - - SvcLogicBinaryExpression curBinExpr = new SvcLogicBinaryExpression(); - pushExpr(curBinExpr); - - List opList = ctx.MULTOP(); - - for (TerminalNode nd : opList) - { - LOG.trace("enterMultExpr: operator - "+nd.getText()); - curBinExpr.addOperator(nd.getText()); - } - - } - - @Override - public void exitMultExpr(MultExprContext ctx) { - - LOG.trace("exitMultExpr: text = "+ctx.getText()); - - popExpr(); - - } - - @Override - public void exitAtom(AtomContext ctx) { - LOG.trace("exitAtom: text = "+ctx.getText()); - popExpr(); - } - - @Override - public void enterAddExpr(AddExprContext ctx) { - LOG.trace("enterAddExpr: text = "+ctx.getText()); - List opList = ctx.ADDOP(); - - - SvcLogicBinaryExpression curBinExpr = new SvcLogicBinaryExpression(); - pushExpr(curBinExpr); - - - for (TerminalNode nd : opList) - { - LOG.trace("enterAddExpr: operator - "+nd.getText()); - curBinExpr.addOperator(nd.getText()); - } - - } - - @Override - public void exitAddExpr(AddExprContext ctx) { - LOG.trace("exitAddExpr: text = "+ctx.getText()); - - popExpr(); - } - - @Override - public void enterFuncExpr(FuncExprContext ctx) { - LOG.trace("enterFuncExpr: text = "+ctx.getText()); - LOG.trace("enterFuncExpr - IDENTIFIER : "+ctx.IDENTIFIER().getText()); - - for (ExprContext expr: ctx.expr()) - { - LOG.trace("enterFuncExpr - expr = "+expr.getText()); - } - - - pushExpr(new SvcLogicFunctionCall(ctx.IDENTIFIER().getText())); - } - - @Override - public void exitFuncExpr(FuncExprContext ctx) { - LOG.trace("exitFuncExpr: text = "+ctx.getText()); - - popExpr(); - } - - @Override - public void enterParenExpr(ParenExprContext ctx) { - LOG.trace("enterParenExpr: text = "+ctx.getText()); - LOG.trace("enterParenExpr: expr = "+ctx.expr().getText()); - } - - @Override - public void exitParenExpr(ParenExprContext ctx) { - LOG.trace("exitParenExpr: text = "+ctx.getText()); - } - - @Override - public void enterRelExpr(RelExprContext ctx) { - LOG.trace("enterRelExpr: text = "+ctx.getText()); - - List opList = ctx.RELOP(); - - - SvcLogicBinaryExpression curBinExpr = new SvcLogicBinaryExpression(); - pushExpr(curBinExpr); - - - for (TerminalNode nd : opList) - { - LOG.trace("enterRelExpr: operator - "+nd.getText()); - curBinExpr.addOperator(nd.getText()); - } - - } - - @Override - public void exitRelExpr(RelExprContext ctx) { - LOG.trace("exitRelExpr: text = "+ctx.getText()); - - popExpr(); - } - - @Override - public void enterCompareExpr(CompareExprContext ctx) { - LOG.trace("enterCompareExpr: text = "+ctx.getText()); - - TerminalNode nd = ctx.COMPAREOP(); - - SvcLogicBinaryExpression curBinExpr = new SvcLogicBinaryExpression(); - pushExpr(curBinExpr); - - LOG.trace("enterCompareExpr: operator - "+nd.getText()); - curBinExpr.addOperator(nd.getText()); - - } - - @Override - public void exitCompareExpr(CompareExprContext ctx) { - LOG.trace("exitCompareExpr : text = "+ctx.getText()); - - popExpr(); - } - - - - @Override - public void enterConstant(ConstantContext ctx) { - LOG.trace("enterConstant: text = "+ctx.getText()); - } - - @Override - public void exitConstant(ConstantContext ctx) { - LOG.trace("exitConstant: text = "+ctx.getText()); - } - - - @Override - public void enterVariable(VariableContext ctx) { - LOG.trace("enterVariable: text = "+ctx.getText()); - - - } - - @Override - public void exitVariable(VariableContext ctx) { - LOG.debug("exitVariable: text ="+ctx.getText()); - - } - - - @Override - public void enterVariableLead(VariableLeadContext ctx) { - - LOG.debug("enterVariableLead: text ="+ctx.getText()); - - - } - - @Override - public void exitVariableLead(VariableLeadContext ctx) { - - LOG.trace("exitVariableLead: text ="+ctx.getText()); - } - - @Override - public void enterVariableTerm(VariableTermContext ctx) { - LOG.trace("enterVariableTerm: text ="+ctx.getText()); - - String name = ctx.getText(); - - int subscrStart = name.indexOf("["); - if (subscrStart > -1) - { - name = name.substring(0, subscrStart); - } - SvcLogicVariableTerm vterm = new SvcLogicVariableTerm(name); - pushExpr(vterm); - } - - @Override - public void exitVariableTerm(VariableTermContext ctx) { - LOG.trace("exitVariableTerm: text="+ctx.getText()); - popExpr(); - } -}