vieiro commented on code in PR #6178: URL: https://github.com/apache/netbeans/pull/6178#discussion_r1264648449
########## ide/languages.hcl/manifest.mf: ########## @@ -3,4 +3,5 @@ OpenIDE-Module: org.netbeans.modules.languages.hcl OpenIDE-Module-Layer: org/netbeans/modules/languages/hcl/layer.xml OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/languages/hcl/Bundle.properties OpenIDE-Module-Specification-Version: 1.1 +OpenIDE-Module-Java-Dependencies: Java > 11 Review Comment: Is this `>11` correct? Should it be `Java >= 11` instead? ########## ide/languages.hcl/src/org/netbeans/modules/languages/hcl/ast/expression/HCLExpressionFactory.java: ########## @@ -0,0 +1,318 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.netbeans.modules.languages.hcl.ast.expression; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import org.antlr.v4.runtime.tree.ParseTree; +import static org.netbeans.modules.languages.hcl.grammar.HCLLexer.AND; +import static org.netbeans.modules.languages.hcl.grammar.HCLLexer.EQUALS; +import static org.netbeans.modules.languages.hcl.grammar.HCLLexer.GT; +import static org.netbeans.modules.languages.hcl.grammar.HCLLexer.GTE; +import static org.netbeans.modules.languages.hcl.grammar.HCLLexer.LT; +import static org.netbeans.modules.languages.hcl.grammar.HCLLexer.LTE; +import static org.netbeans.modules.languages.hcl.grammar.HCLLexer.MINUS; +import static org.netbeans.modules.languages.hcl.grammar.HCLLexer.NOT; +import static org.netbeans.modules.languages.hcl.grammar.HCLLexer.NOT_EQUALS; +import static org.netbeans.modules.languages.hcl.grammar.HCLLexer.OR; +import static org.netbeans.modules.languages.hcl.grammar.HCLLexer.PERCENT; +import static org.netbeans.modules.languages.hcl.grammar.HCLLexer.PLUS; +import static org.netbeans.modules.languages.hcl.grammar.HCLLexer.SLASH; +import static org.netbeans.modules.languages.hcl.grammar.HCLLexer.STAR; +import org.netbeans.modules.languages.hcl.grammar.HCLParser; + +/** + * + * @author lkishalmi + */ +public class HCLExpressionFactory { + + public static HCLExpression expr(HCLParser.ExpressionContext ctx) throws UnsupportedOperationException { + if (ctx.op != null) { + if (ctx.left != null && ctx.right != null) { + HCLArithmeticOperation.Operator op = binOp(ctx.op.getType()); + return new HCLArithmeticOperation.Binary(op, expr(ctx.left), expr(ctx.right)); + } + if (ctx.right != null) { + switch (ctx.op.getType()) { + case NOT: + return new HCLArithmeticOperation.Unary(HCLArithmeticOperation.Operator.NOT, expr(ctx.right)); + case MINUS: + return new HCLArithmeticOperation.Unary(HCLArithmeticOperation.Operator.MINUS, expr(ctx.right)); + } Review Comment: You may want to add some defensive programming here with a `default: throw new UnsupportedOperationException` here? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
