1 /* 2 * Copyright (C) 2016 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 17 package com.googlecode.android_scripting.language; 18 19 import com.googlecode.android_scripting.rpc.ParameterDescriptor; 20 21 /** 22 * Represents the BeanShell programming language. 23 * 24 * @author igor.v.karp@gmail.com (Igor Karp) 25 */ 26 public class BeanShellLanguage extends Language { 27 28 @Override getImportStatement()29 protected String getImportStatement() { 30 // FIXME(igor.v.karp): this is interpreter specific 31 return "source(\"/sdcard/com.googlecode.bshforandroid/extras/bsh/android.bsh\");\n"; 32 } 33 34 @Override getRpcReceiverDeclaration(String rpcReceiver)35 protected String getRpcReceiverDeclaration(String rpcReceiver) { 36 return rpcReceiver + " = Android();\n"; 37 } 38 39 @Override getMethodCallText(String receiver, String method, ParameterDescriptor[] parameters)40 protected String getMethodCallText(String receiver, String method, 41 ParameterDescriptor[] parameters) { 42 StringBuilder result = 43 new StringBuilder().append(getApplyReceiverText(receiver)).append(getApplyOperatorText()) 44 .append(method); 45 if (parameters.length > 0) { 46 result.append(getLeftParametersText()); 47 } else { 48 result.append(getQuote()); 49 } 50 String separator = ""; 51 for (ParameterDescriptor parameter : parameters) { 52 result.append(separator).append(getValueText(parameter)); 53 separator = getParameterSeparator(); 54 } 55 result.append(getRightParametersText()); 56 57 return result.toString(); 58 } 59 60 @Override getApplyOperatorText()61 protected String getApplyOperatorText() { 62 return ".call(\""; 63 } 64 65 @Override getLeftParametersText()66 protected String getLeftParametersText() { 67 return "\", "; 68 } 69 70 @Override getRightParametersText()71 protected String getRightParametersText() { 72 return ")"; 73 } 74 } 75