DestructuringDeclTreeImpl.java revision 1739:4a6a1fd3d3dd
155682Smarkm/* 2233294Sstas * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3233294Sstas * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4233294Sstas * 555682Smarkm * This code is free software; you can redistribute it and/or modify it 6233294Sstas * under the terms of the GNU General Public License version 2 only, as 7233294Sstas * published by the Free Software Foundation. Oracle designates this 8233294Sstas * particular file as subject to the "Classpath" exception as provided 955682Smarkm * by Oracle in the LICENSE file that accompanied this code. 10233294Sstas * 11233294Sstas * This code is distributed in the hope that it will be useful, but WITHOUT 1255682Smarkm * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13233294Sstas * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14233294Sstas * version 2 for more details (a copy is included in the LICENSE file that 15233294Sstas * accompanied this code). 1655682Smarkm * 17233294Sstas * You should have received a copy of the GNU General Public License version 18233294Sstas * 2 along with this work; if not, write to the Free Software Foundation, 19233294Sstas * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2055682Smarkm * 21233294Sstas * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22233294Sstas * or visit www.oracle.com if you need additional information or have any 23233294Sstas * questions. 24233294Sstas */ 25233294Sstas 26233294Sstaspackage jdk.nashorn.api.tree; 27233294Sstas 28233294Sstasimport jdk.nashorn.internal.ir.ExpressionStatement; 29233294Sstasimport jdk.nashorn.internal.parser.TokenType; 30233294Sstas 31233294Sstas// This implementation of VariableTree represents a destructuring declaration 3255682Smarkmfinal class DestructuringDeclTreeImpl extends StatementTreeImpl 3355682Smarkm implements VariableTree { 3455682Smarkm 3555682Smarkm private final TokenType declType; 3655682Smarkm private final ExpressionTree lhs; 3755682Smarkm private final ExpressionTree init; 3855682Smarkm 3955682Smarkm DestructuringDeclTreeImpl(ExpressionStatement exprStat, final ExpressionTree lhs, final ExpressionTree init) { 4055682Smarkm super(exprStat); 4155682Smarkm assert exprStat.destructuringDeclarationType() != null : "expecting a destructuring decl. statement"; 4255682Smarkm 4355682Smarkm this.declType = exprStat.destructuringDeclarationType(); 4455682Smarkm this.lhs = lhs; 4555682Smarkm this.init = init; 4655682Smarkm } 4755682Smarkm 4855682Smarkm @Override 4955682Smarkm public Kind getKind() { 5055682Smarkm return Kind.VARIABLE; 5155682Smarkm } 5255682Smarkm 5355682Smarkm @Override 5455682Smarkm public ExpressionTree getBinding() { 5555682Smarkm return lhs; 5655682Smarkm } 5755682Smarkm 58233294Sstas @Override 5955682Smarkm public ExpressionTree getInitializer() { 6055682Smarkm return init; 6155682Smarkm } 6278527Sassar 6378527Sassar @Override 6455682Smarkm public boolean isConst() { 65233294Sstas return declType == TokenType.CONST; 6655682Smarkm } 6755682Smarkm 6855682Smarkm @Override 69178825Sdfr public boolean isLet() { 70178825Sdfr return declType == TokenType.LET; 7155682Smarkm } 72178825Sdfr 7355682Smarkm @Override 74233294Sstas public <R,D> R accept(final TreeVisitor<R,D> visitor, final D data) { 7555682Smarkm return visitor.visitVariable(this, data); 7655682Smarkm } 7755682Smarkm} 7855682Smarkm