ExpressionSnippet.java revision 3062:15bdc18525ff
1114402Sru/* 2114402Sru * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3114402Sru * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4114402Sru * 5114402Sru * This code is free software; you can redistribute it and/or modify it 6114402Sru * under the terms of the GNU General Public License version 2 only, as 7114402Sru * published by the Free Software Foundation. Oracle designates this 8114402Sru * particular file as subject to the "Classpath" exception as provided 9114402Sru * by Oracle in the LICENSE file that accompanied this code. 10114402Sru * 11114402Sru * This code is distributed in the hope that it will be useful, but WITHOUT 12114402Sru * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13114402Sru * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14114402Sru * version 2 for more details (a copy is included in the LICENSE file that 15114402Sru * accompanied this code). 16114402Sru * 17114402Sru * You should have received a copy of the GNU General Public License version 18114402Sru * 2 along with this work; if not, write to the Free Software Foundation, 19114402Sru * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20114402Sru * 21114402Sru * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22114402Sru * or visit www.oracle.com if you need additional information or have any 23114402Sru * questions. 24114402Sru */ 25114402Srupackage jdk.jshell; 26114402Sru 27114402Sruimport jdk.jshell.Key.ExpressionKey; 28114402Sru 29114402Sru/** 30114402Sru * Snippet for an assignment or variable-value expression. 31114402Sru * The Kind is {@link jdk.jshell.Snippet.Kind#EXPRESSION}. 32114402Sru * <p> 33114402Sru * <code>ExpressionSnippet</code> is immutable: an access to 34114402Sru * any of its methods will always return the same result. 35114402Sru * and thus is thread-safe. 36114402Sru * @jls 15: Expression. 37114402Sru */ 38114402Srupublic class ExpressionSnippet extends Snippet { 39114402Sru 40114402Sru ExpressionSnippet(ExpressionKey key, String userSource, Wrap guts, String name, SubKind subkind) { 41114402Sru super(key, userSource, guts, name, subkind); 42114402Sru } 43114402Sru 44114402Sru /** 45114402Sru * Variable name which is the value of the expression. Since the expression 46114402Sru * is either just a variable identifier or it is an assignment 47114402Sru * to a variable, there is always a variable which is the subject of the 48114402Sru * expression. All other forms of expression become temporary variables 49114402Sru * which are instead referenced by a {@link VarSnippet}. 50114402Sru * @return the name of the variable which is the subject of the expression. 51114402Sru */ 52114402Sru @Override 53114402Sru public String name() { 54114402Sru return key().name(); 55114402Sru } 56114402Sru 57114402Sru /** 58114402Sru * Type of the expression 59114402Sru * @return String representation of the type of the expression. 60114402Sru */ 61114402Sru public String typeName() { 62114402Sru return key().typeName(); 63114402Sru } 64114402Sru 65114402Sru /**** internal access ****/ 66114402Sru 67114402Sru @Override 68114402Sru ExpressionKey key() { 69114402Sru return (ExpressionKey) super.key(); 70114402Sru } 71114402Sru} 72114402Sru