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 */ 25 public class BeanShellLanguage extends Language { 26 27 @Override getImportStatement()28 protected String getImportStatement() { 29 // FIXME(igor.v.karp): this is interpreter specific 30 return "source(\"/sdcard/com.googlecode.bshforandroid/extras/bsh/android.bsh\");\n"; 31 } 32 33 @Override getRpcReceiverDeclaration(String rpcReceiver)34 protected String getRpcReceiverDeclaration(String rpcReceiver) { 35 return rpcReceiver + " = Android();\n"; 36 } 37 38 @Override getMethodCallText(String receiver, String method, ParameterDescriptor[] parameters)39 protected String getMethodCallText(String receiver, String method, 40 ParameterDescriptor[] parameters) { 41 StringBuilder result = 42 new StringBuilder().append(getApplyReceiverText(receiver)).append(getApplyOperatorText()) 43 .append(method); 44 if (parameters.length > 0) { 45 result.append(getLeftParametersText()); 46 } else { 47 result.append(getQuote()); 48 } 49 String separator = ""; 50 for (ParameterDescriptor parameter : parameters) { 51 result.append(separator).append(getValueText(parameter)); 52 separator = getParameterSeparator(); 53 } 54 result.append(getRightParametersText()); 55 56 return result.toString(); 57 } 58 59 @Override getApplyOperatorText()60 protected String getApplyOperatorText() { 61 return ".call(\""; 62 } 63 64 @Override getLeftParametersText()65 protected String getLeftParametersText() { 66 return "\", "; 67 } 68 69 @Override getRightParametersText()70 protected String getRightParametersText() { 71 return ")"; 72 } 73 } 74