diff options
Diffstat (limited to 'sl4a/Common/src/com/googlecode/android_scripting/language')
14 files changed, 0 insertions, 872 deletions
diff --git a/sl4a/Common/src/com/googlecode/android_scripting/language/BeanShellLanguage.java b/sl4a/Common/src/com/googlecode/android_scripting/language/BeanShellLanguage.java deleted file mode 100644 index b92d502..0000000 --- a/sl4a/Common/src/com/googlecode/android_scripting/language/BeanShellLanguage.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2016 Google Inc. - * - * Licensed 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 com.googlecode.android_scripting.language; - -import com.googlecode.android_scripting.rpc.ParameterDescriptor; - -/** - * Represents the BeanShell programming language. - * - * @author igor.v.karp@gmail.com (Igor Karp) - */ -public class BeanShellLanguage extends Language { - - @Override - protected String getImportStatement() { - // FIXME(igor.v.karp): this is interpreter specific - return "source(\"/sdcard/com.googlecode.bshforandroid/extras/bsh/android.bsh\");\n"; - } - - @Override - protected String getRpcReceiverDeclaration(String rpcReceiver) { - return rpcReceiver + " = Android();\n"; - } - - @Override - protected String getMethodCallText(String receiver, String method, - ParameterDescriptor[] parameters) { - StringBuilder result = - new StringBuilder().append(getApplyReceiverText(receiver)).append(getApplyOperatorText()) - .append(method); - if (parameters.length > 0) { - result.append(getLeftParametersText()); - } else { - result.append(getQuote()); - } - String separator = ""; - for (ParameterDescriptor parameter : parameters) { - result.append(separator).append(getValueText(parameter)); - separator = getParameterSeparator(); - } - result.append(getRightParametersText()); - - return result.toString(); - } - - @Override - protected String getApplyOperatorText() { - return ".call(\""; - } - - @Override - protected String getLeftParametersText() { - return "\", "; - } - - @Override - protected String getRightParametersText() { - return ")"; - } -} diff --git a/sl4a/Common/src/com/googlecode/android_scripting/language/HtmlLanguage.java b/sl4a/Common/src/com/googlecode/android_scripting/language/HtmlLanguage.java deleted file mode 100644 index e7abf33..0000000 --- a/sl4a/Common/src/com/googlecode/android_scripting/language/HtmlLanguage.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2016 Google Inc. - * - * Licensed 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 com.googlecode.android_scripting.language; - -import com.googlecode.android_scripting.rpc.ParameterDescriptor; - -public class HtmlLanguage extends Language { - - /** Returns the Android package import statement. */ - @Override - protected String getImportStatement() { - return "<html>\n<head>\n<script>"; - } - - @Override - protected String getRpcReceiverDeclaration(String rpcReceiver) { - return String.format("var %s = new Android();\n</script>\n</head>\n<body>\n\n</body>\n</html>", - rpcReceiver); - } - - @Override - protected String getMethodCallText(String receiver, String method, - ParameterDescriptor[] parameters) { - StringBuilder result = - new StringBuilder().append(getApplyReceiverText(receiver)).append(getApplyOperatorText()) - .append(method); - if (parameters.length > 0) { - result.append(getLeftParametersText()); - } else { - result.append(getQuote()); - } - String separator = ""; - for (ParameterDescriptor parameter : parameters) { - result.append(separator).append(getValueText(parameter)); - separator = getParameterSeparator(); - } - result.append(getRightParametersText()); - - return result.toString(); - } - - @Override - protected String getApplyOperatorText() { - return ".call('"; - } - - @Override - protected String getLeftParametersText() { - return "', "; - } - - @Override - protected String getRightParametersText() { - return ")"; - } - - @Override - protected String getQuote() { - return "'"; - } - -} diff --git a/sl4a/Common/src/com/googlecode/android_scripting/language/JavaScriptLanguage.java b/sl4a/Common/src/com/googlecode/android_scripting/language/JavaScriptLanguage.java deleted file mode 100644 index 7e88d3c..0000000 --- a/sl4a/Common/src/com/googlecode/android_scripting/language/JavaScriptLanguage.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2016 Google Inc. - * - * Licensed 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 com.googlecode.android_scripting.language; - -/** - * Represents the JavaScript programming language. - * - * @author igor.v.karp@gmail.com (Igor Karp) - */ -public class JavaScriptLanguage extends Language { - - @Override - protected String getImportStatement() { - // FIXME(igor.v.karp): this is interpreter specific - return "load(\"/sdcard/com.googlecode.rhinoforandroid/extras/rhino/android.js\");\n"; - } - - @Override - protected String getRpcReceiverDeclaration(String rpcReceiver) { - return "var " + rpcReceiver + " = Android();\n"; - } - -} diff --git a/sl4a/Common/src/com/googlecode/android_scripting/language/Language.java b/sl4a/Common/src/com/googlecode/android_scripting/language/Language.java deleted file mode 100644 index 0a8d487..0000000 --- a/sl4a/Common/src/com/googlecode/android_scripting/language/Language.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright (C) 2016 Google Inc. - * - * Licensed 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 com.googlecode.android_scripting.language; - -import com.googlecode.android_scripting.rpc.MethodDescriptor; -import com.googlecode.android_scripting.rpc.ParameterDescriptor; - -import java.util.HashMap; -import java.util.Map; - -/** - * Represents the programming language supported by the SL4A. - * - * @author igor.v.karp@gmail.com (Igor Karp) - */ -public class Language { - - private final static Map<Character, String> AUTO_CLOSE_MAP = buildAutoCloseMap('[', "[]", '{', - "{}", '(', "()", '\'', "''", '"', "\"\""); - - /** Returns the initial template for newly created script. */ - public String getContentTemplate() { - StringBuilder content = new StringBuilder(getImportStatement()); - if (content.length() != 0) { - content.append('\n'); - } - content.append(getRpcReceiverDeclaration(getDefaultRpcReceiver())); - return content.toString(); - } - - /** Returns the Android package import statement. */ - protected String getImportStatement() { - return ""; - } - - /** Returns the RPC receiver declaration. */ - protected String getRpcReceiverDeclaration(String rpcReceiver) { - return ""; - } - - /** Returns the default RPC receiver name. */ - protected String getDefaultRpcReceiver() { - return "droid"; - } - - /** - * Returns the string containing opening and closing tokens if the input is an opening token. - * Returns {@code null} otherwise. - */ - public String autoClose(char token) { - return AUTO_CLOSE_MAP.get(token); - } - - /** Returns the RPC call text with given parameter values. */ - public final String getRpcText(String content, MethodDescriptor rpc, String[] values) { - return getMethodCallText(getRpcReceiverName(content), rpc.getName(), - rpc.getParameterValues(values)); - } - - /** Returns the RPC receiver found in the given script. */ - protected String getRpcReceiverName(String content) { - return getDefaultRpcReceiver(); - } - - /** Returns the method call text in the language. */ - protected String getMethodCallText(String receiver, String method, - ParameterDescriptor[] parameters) { - StringBuilder result = - new StringBuilder().append(getApplyReceiverText(receiver)).append(getApplyOperatorText()) - .append(method).append(getLeftParametersText()); - String separator = ""; - for (ParameterDescriptor parameter : parameters) { - result.append(separator).append(getValueText(parameter)); - separator = getParameterSeparator(); - } - result.append(getRightParametersText()); - - return result.toString(); - } - - /** Returns the apply receiver text. */ - protected String getApplyReceiverText(String receiver) { - return receiver; - } - - /** Returns the apply operator text. */ - protected String getApplyOperatorText() { - return "."; - } - - /** Returns the text to the left of the parameters. */ - protected String getLeftParametersText() { - return "("; - } - - /** Returns the text to the right of the parameters. */ - protected String getRightParametersText() { - return ")"; - } - - /** Returns the parameter separator text. */ - protected String getParameterSeparator() { - return ", "; - } - - /** Returns the text of the quotation. */ - protected String getQuote() { - return "\""; - } - - /** Returns the text of the {@code null} value. */ - protected String getNull() { - return "null"; - } - - /** Returns the text of the {{@code true} value. */ - protected String getTrue() { - return "true"; - } - - /** Returns the text of the false value. */ - protected String getFalse() { - return "false"; - } - - /** Returns the parameter value suitable for code generation. */ - protected String getValueText(ParameterDescriptor parameter) { - if (parameter.getValue() == null) { - return getNullValueText(); - } else if (parameter.getType().equals(String.class)) { - return getStringValueText(parameter.getValue()); - } else if (parameter.getType().equals(Boolean.class)) { - return getBooleanValueText(parameter.getValue()); - } else { - return parameter.getValue(); - } - } - - /** Returns the null value suitable for code generation. */ - private String getNullValueText() { - return getNull(); - } - - /** Returns the string parameter value suitable for code generation. */ - protected String getStringValueText(String value) { - // TODO(igorkarp): do not quote expressions once they could be detected. - return getQuote() + value + getQuote(); - } - - /** Returns the boolean parameter value suitable for code generation. */ - protected String getBooleanValueText(String value) { - if (value.equals(Boolean.TRUE.toString())) { - return getTrue(); - } else if (value.equals(Boolean.FALSE.toString())) { - return getFalse(); - } else { - // If it is neither true nor false it is must be an expression. - return value; - } - } - - private static Map<Character, String> buildAutoCloseMap(char c1, String s1, char c2, String s2, - char c3, String s3, char c4, String s4, char c5, String s5) { - Map<Character, String> map = new HashMap<Character, String>(5); - map.put(c1, s1); - map.put(c2, s2); - map.put(c3, s3); - map.put(c4, s4); - map.put(c5, s5); - return map; - } -} diff --git a/sl4a/Common/src/com/googlecode/android_scripting/language/LuaLanguage.java b/sl4a/Common/src/com/googlecode/android_scripting/language/LuaLanguage.java deleted file mode 100644 index a279434..0000000 --- a/sl4a/Common/src/com/googlecode/android_scripting/language/LuaLanguage.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2016 Google Inc. - * - * Licensed 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 com.googlecode.android_scripting.language; - -/** - * Represents the Lua programming language. - * - * @author igor.v.karp@gmail.com (Igor Karp) - */ -public class LuaLanguage extends Language { - - @Override - protected String getImportStatement() { - return "require \"android\"\n"; - } - - @Override - protected String getDefaultRpcReceiver() { - return "android"; - } -} diff --git a/sl4a/Common/src/com/googlecode/android_scripting/language/PerlLanguage.java b/sl4a/Common/src/com/googlecode/android_scripting/language/PerlLanguage.java deleted file mode 100644 index c5cca0b..0000000 --- a/sl4a/Common/src/com/googlecode/android_scripting/language/PerlLanguage.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2016 Google Inc. - * - * Licensed 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 com.googlecode.android_scripting.language; - -/** - * Represents the Perl programming language. - * - * @author igor.v.karp@gmail.com (Igor Karp) - */ -public class PerlLanguage extends Language { - - @Override - protected String getImportStatement() { - return "use Android;\n"; - } - - @Override - protected String getRpcReceiverDeclaration(String rpcReceiver) { - return "my " + rpcReceiver + " = Android->new();\n"; - } - - @Override - protected String getDefaultRpcReceiver() { - return "$droid"; - } - - @Override - protected String getApplyOperatorText() { - return "->"; - } -} diff --git a/sl4a/Common/src/com/googlecode/android_scripting/language/PhpLanguage.java b/sl4a/Common/src/com/googlecode/android_scripting/language/PhpLanguage.java deleted file mode 100644 index a141a3c..0000000 --- a/sl4a/Common/src/com/googlecode/android_scripting/language/PhpLanguage.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2016 Google Inc. - * - * Licensed 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 com.googlecode.android_scripting.language; - -/** - * Represents the PHP programming language. - * - * @author ivan@irontec.com (Ivan Mosquera Paulo) - */ -public class PhpLanguage extends Language { - - @Override - protected String getImportStatement() { - return "<?php\n\nrequire_once(\"Android.php\");"; - - } - - @Override - protected String getRpcReceiverDeclaration(String rpcReceiver) { - return rpcReceiver + " = new Android();\n"; - } - - @Override - protected String getDefaultRpcReceiver() { - return "$droid"; - } - - @Override - protected String getApplyOperatorText() { - return "->"; - } - - @Override - protected String getQuote() { - return "'"; - } - -}
\ No newline at end of file diff --git a/sl4a/Common/src/com/googlecode/android_scripting/language/PythonLanguage.java b/sl4a/Common/src/com/googlecode/android_scripting/language/PythonLanguage.java deleted file mode 100644 index beb59ae..0000000 --- a/sl4a/Common/src/com/googlecode/android_scripting/language/PythonLanguage.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2016 Google Inc. - * - * Licensed 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 com.googlecode.android_scripting.language; - -/** - * Represents the Python programming language. - * - * @author igor.v.karp@gmail.com (Igor Karp) - */ -public class PythonLanguage extends Language { - - @Override - protected String getImportStatement() { - return "import android\n"; - } - - @Override - protected String getRpcReceiverDeclaration(String rpcReceiver) { - return rpcReceiver + " = android.Android()\n"; - } - - @Override - protected String getQuote() { - return "'"; - } - - @Override - protected String getNull() { - return "None"; - } - - @Override - protected String getTrue() { - return "True"; - } - - @Override - protected String getFalse() { - return "False"; - } -} diff --git a/sl4a/Common/src/com/googlecode/android_scripting/language/RubyLanguage.java b/sl4a/Common/src/com/googlecode/android_scripting/language/RubyLanguage.java deleted file mode 100644 index d6cd189..0000000 --- a/sl4a/Common/src/com/googlecode/android_scripting/language/RubyLanguage.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2016 Google Inc. - * - * Licensed 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 com.googlecode.android_scripting.language; - -/** - * Represents the Ruby programming language. - * - * @author igor.v.karp@gmail.com (Igor Karp) - */ -public class RubyLanguage extends Language { - - @Override - protected String getImportStatement() { - return "require \"android\";\n"; - } - - @Override - protected String getRpcReceiverDeclaration(String rpcReceiver) { - return rpcReceiver + " = Droid.new\n"; - } -} diff --git a/sl4a/Common/src/com/googlecode/android_scripting/language/ShellLanguage.java b/sl4a/Common/src/com/googlecode/android_scripting/language/ShellLanguage.java deleted file mode 100644 index d7bc5a2..0000000 --- a/sl4a/Common/src/com/googlecode/android_scripting/language/ShellLanguage.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2016 Google Inc. - * - * Licensed 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 com.googlecode.android_scripting.language; - -/** - * Represents the Shell programming language. - * - * @author igor.v.karp@gmail.com (Igor Karp) - */ -public class ShellLanguage extends Language { -} diff --git a/sl4a/Common/src/com/googlecode/android_scripting/language/SleepLanguage.java b/sl4a/Common/src/com/googlecode/android_scripting/language/SleepLanguage.java deleted file mode 100644 index 1b623ab..0000000 --- a/sl4a/Common/src/com/googlecode/android_scripting/language/SleepLanguage.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2016 Google Inc. - * - * Licensed 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 com.googlecode.android_scripting.language; - -/** - * Represents the Sleep programming language. - * - * @author tomcatalbino@gmail.com - */ -public class SleepLanguage extends Language { - - @Override - protected String getImportStatement() { - return "import com.googlecode.rpc.*;\n"; - } - - @Override - protected String getRpcReceiverDeclaration(String rpcReceiver) { - return rpcReceiver + " = [new Android];\n"; - } - - @Override - protected String getDefaultRpcReceiver() { - return "$droid"; - } - -} diff --git a/sl4a/Common/src/com/googlecode/android_scripting/language/SquirrelLanguage.java b/sl4a/Common/src/com/googlecode/android_scripting/language/SquirrelLanguage.java deleted file mode 100644 index f9b25bf..0000000 --- a/sl4a/Common/src/com/googlecode/android_scripting/language/SquirrelLanguage.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2016 Google Inc. - * - * Licensed 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 com.googlecode.android_scripting.language; - -/** - * Represents the Squirrel programming language, by Alberto Demichelis - * this file adapted by Andy Tai, atai@atai.org - * based on the Python version by - * @author igor.v.karp@gmail.com (Igor Karp) - */ -public class SquirrelLanguage extends Language { - - @Override - protected String getImportStatement() { - /* initialization code */ - return ""; - } - - @Override - protected String getRpcReceiverDeclaration(String rpcReceiver) { - return rpcReceiver + " <- Android();\n"; - } - - @Override - protected String getQuote() { - return "\""; - } - - @Override - protected String getNull() { - return "null"; - } - - @Override - protected String getTrue() { - return "true"; - } - - @Override - protected String getFalse() { - return "false"; - } -} - diff --git a/sl4a/Common/src/com/googlecode/android_scripting/language/SupportedLanguages.java b/sl4a/Common/src/com/googlecode/android_scripting/language/SupportedLanguages.java deleted file mode 100644 index e496378..0000000 --- a/sl4a/Common/src/com/googlecode/android_scripting/language/SupportedLanguages.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2016 Google Inc. - * - * Licensed 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 com.googlecode.android_scripting.language; - -import com.googlecode.android_scripting.Log; - -import java.util.HashMap; -import java.util.Map; - -public class SupportedLanguages { - - private static enum KnownLanguage { - // SHELL(".sh", ShellLanguage.class), // We don't really support Shell language - HTML(".html", HtmlLanguage.class), BEANSHELL(".bsh", BeanShellLanguage.class), JAVASCRIPT( - ".js", JavaScriptLanguage.class), LUA(".lua", LuaLanguage.class), PERL(".pl", - PerlLanguage.class), PYTHON(".py", PythonLanguage.class), RUBY(".rb", RubyLanguage.class), - TCL(".tcl", TclLanguage.class), PHP(".php", PhpLanguage.class), SLEEP(".sl", - SleepLanguage.class), SQUIRREL(".nut", SquirrelLanguage.class); - - private final String mmExtension; - private final Class<? extends Language> mmClass; - - private KnownLanguage(String ext, Class<? extends Language> clazz) { - mmExtension = ext; - mmClass = clazz; - } - - private String getExtension() { - return mmExtension; - } - - private Class<? extends Language> getLanguageClass() { - return mmClass; - } - } - - private static Map<String, Class<? extends Language>> sSupportedLanguages; - - static { - sSupportedLanguages = new HashMap<String, Class<? extends Language>>(); - for (KnownLanguage language : KnownLanguage.values()) { - sSupportedLanguages.put(language.getExtension(), language.getLanguageClass()); - } - } - - public static Language getLanguageByExtension(String extension) { - extension = extension.toLowerCase(); - if (!extension.startsWith(".")) { - throw new RuntimeException("Extension does not start with a dot: " + extension); - } - Language lang = null; - - Class<? extends Language> clazz = sSupportedLanguages.get(extension); - if (clazz == null) { - clazz = Language.class; // revert to default language. - } - if (clazz != null) { - try { - lang = clazz.newInstance(); - } catch (IllegalAccessException e) { - Log.e(e); - } catch (InstantiationException e) { - Log.e(e); - } - } - return lang; - } - - public static boolean checkLanguageSupported(String name) { - String extension = name.toLowerCase(); - int index = extension.lastIndexOf('.'); - if (index < 0) { - extension = "." + extension; - } else if (index > 0) { - extension = extension.substring(index); - } - return sSupportedLanguages.containsKey(extension); - } -} diff --git a/sl4a/Common/src/com/googlecode/android_scripting/language/TclLanguage.java b/sl4a/Common/src/com/googlecode/android_scripting/language/TclLanguage.java deleted file mode 100644 index 52b8532..0000000 --- a/sl4a/Common/src/com/googlecode/android_scripting/language/TclLanguage.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2016 Google Inc. - * - * Licensed 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 com.googlecode.android_scripting.language; - -/** - * Represents the Tcl programming language. - * - * @author igor.v.karp@gmail.com (Igor Karp) - */ -public class TclLanguage extends Language { - - @Override - protected String getImportStatement() { - return "package require android\n"; - } - - @Override - protected String getRpcReceiverDeclaration(String rpcReceiver) { - return "set " + rpcReceiver + " [android new]\n"; - } - - @Override - protected String getApplyReceiverText(String receiver) { - return "$" + receiver; - } - - @Override - protected String getApplyOperatorText() { - return " "; - } - - @Override - protected String getLeftParametersText() { - return " "; - } - - @Override - protected String getRightParametersText() { - return ""; - } - - @Override - protected String getParameterSeparator() { - return " "; - } -} |