post order, recursive.
103 | * 104 | * @param type the type 105 | * @return type declaration 106 | */ 107 | static String generateTypeDeclaration(final TypeNode type) { 108 | if (!type.isContainer()) { 109 | return TypeMap.TYPE_MAP.get(LanguageType.CPLUSPLUS).get(type.getValue()); 110 | } 111 | 112 | final String containerTypeStr = 113 | TypeMap.TYPE_MAP.get(LanguageType.CPLUSPLUS).get(type.getValue()); 114 | if (type.getKeyType().isPresent()) { 115 | return containerTypeStr + "<" + generateTypeDeclaration(type.getKeyType().get()) + ", " 116 | + generateTypeDeclaration(type.getElementType().get()) + ">"; 117 | } else { 118 | final String typeDeclaration = 119 | containerTypeStr + "<" + generateTypeDeclaration(type.getElementType().get()) + ">"; 120 | return addSharedPtr(type, typeDeclaration); 121 | } 122 | } 123 | 124 | /** 125 | * Generate an empty function with comments. 126 | * @param function Function prototype 127 | * @return source code of a empty function 128 | */ 129 | public static String generateEmptyFunction(final Function function) { 130 | return FunctionGenerator.generateFunction(function, LanguageType.CPLUSPLUS, 0); 131 | } 132 | 133 | private static String addSharedPtr(TypeNode type, String elemType) { 134 | if (type.getValue() == IntermediateType.BINARY_TREE_NODE 135 | || type.getValue() == IntermediateType.LINKED_LIST_NODE) { 136 | return "shared_ptr<" + elemType + ">"; 137 | } else { 138 | return elemType; 139 | } 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/main/java/org/algohub/engine/codegenerator/FunctionGenerator.java: -------------------------------------------------------------------------------- 1 | package org.algohub.engine.codegenerator; 2 | 3 | import org.algohub.engine.pojo.Function; 4 | import org.algohub.engine.type.IntermediateType; 5 | import org.algohub.engine.type.LanguageType; 6 | import org.algohub.engine.type.TypeNode; 7 | 8 | import static org.algohub.engine.codegenerator.Indentation.append; 9 | 10 | 11 | /** 12 | * Generate function declaration for display. 13 | */ 14 | @SuppressWarnings({"PMD.InsufficientStringBufferDeclaration", "PMD.ConsecutiveLiteralAppends", 15 | "PMD.InefficientStringBuffering", "PMD.UseUtilityClass", "PMD.ConsecutiveAppendsShouldReuse"}) 16 | public class FunctionGenerator { 17 | 18 | /** 19 | * Generate parameter declaration. 20 | * 21 | * @param type type 22 | * @param languageType programming language 23 | * @param parameterName parameter name 24 | * @return A block of code to declare a parameter 25 | */ 26 | public static String generateParameterDeclaration(final TypeNode type, 27 | final LanguageType languageType, final String parameterName) { 28 | final StringBuilder result = new StringBuilder(); 29 | final String typeDeclaration = generateTypeDeclaration(type, languageType); 30 | 31 | if (languageType == LanguageType.CPLUSPLUS) { 32 | if (type.isContainer() || type.getValue() == IntermediateType.STRING) { 33 | result.append(typeDeclaration).append("& ").append(parameterName); 34 | } else { 35 | result.append(typeDeclaration).append(' ').append(parameterName); 36 | } 37 | 38 | } else { 39 | result.append(typeDeclaration).append(' ').append(parameterName); 40 | } 41 | return result.toString(); 42 | } 43 | 44 | /** 45 | * Convert a TypeNode to a specific language type declaration. 46 | * 47 | *post order, recursive.
48 | */ 49 | public static String generateTypeDeclaration(final TypeNode type, 50 | final LanguageType languageType) { 51 | switch (languageType) { 52 | case JAVA: 53 | return JavaCodeGenerator.generateTypeDeclaration(type); 54 | case CPLUSPLUS: 55 | return CppCodeGenerator.generateTypeDeclaration(type); 56 | default: 57 | throw new IllegalArgumentException("Unsupported language: " + languageType); 58 | } 59 | } 60 | 61 | /** 62 | * Generate function declaration for Java, C++, C#. 63 | */ 64 | public static String generateFunction(final Function function, final LanguageType languageType, 65 | final int indent) { 66 | final StringBuilder result = new StringBuilder(); 67 | 68 | // function comment 69 | append(result, "/**\n", indent); 70 | for (final Function.Parameter p : function.getParameters()) { 71 | append(result, " * @param " + p.getName() + " " + p.getComment() + "\n", indent); 72 | } 73 | append(result, " * @return " + function.getReturn_().getComment() + "\n", indent); 74 | append(result, " */\n", indent); 75 | 76 | // function body 77 | if (languageType == LanguageType.JAVA) { 78 | append(result, "public ", indent); 79 | result.append(generateTypeDeclaration(function.getReturn_().getType(), languageType)); 80 | } else { 81 | append(result, generateTypeDeclaration(function.getReturn_().getType(), languageType), 82 | indent); 83 | } 84 | result.append(" " + function.getName() + "("); 85 | for (final Function.Parameter p : function.getParameters()) { 86 | result.append(generateParameterDeclaration(p.getType(), languageType, p.getName())) 87 | .append(", "); 88 | } 89 | // delete the last unnecessary " ," 90 | result.delete(result.length() - 2, result.length()); 91 | result.append(") {\n"); 92 | append(result, "// Write your code here\n", indent + 1); 93 | append(result, "}\n", indent); 94 | 95 | return result.toString(); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/org/algohub/engine/codegenerator/Indentation.java: -------------------------------------------------------------------------------- 1 | package org.algohub.engine.codegenerator; 2 | 3 | /** An interface to hold a function. */ 4 | interface Indentation { 5 | /** 6 | * Append with indentation. 7 | */ 8 | @SuppressWarnings("PMD.ShortVariable") 9 | static void append(final StringBuilder sb, final String content, 10 | final int indent) { 11 | for (int i = 0; i < indent; ++i) { 12 | sb.append(" "); 13 | } 14 | sb.append(content); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/algohub/engine/codegenerator/JavaCodeGenerator.java: -------------------------------------------------------------------------------- 1 | package org.algohub.engine.codegenerator; 2 | 3 | import com.google.common.collect.ImmutableMap; 4 | 5 | import org.algohub.engine.pojo.Function; 6 | import org.algohub.engine.type.IntermediateType; 7 | import org.algohub.engine.type.LanguageType; 8 | import org.algohub.engine.type.TypeNode; 9 | 10 | /** 11 | * Generate compilable and runnable Java code. 12 | */ 13 | @SuppressWarnings({"PMD.InsufficientStringBufferDeclaration"}) 14 | public final class JavaCodeGenerator { 15 | /** 16 | * Map intermediate types to real java classes. 17 | */ 18 | public static final ImmutableMappost order, recursive.
32 | */ 33 | private static String generateTypeDeclaration(final TypeNode type, 34 | final IntermediateType parentType) { 35 | if (!type.isContainer()) { 36 | if (parentType == IntermediateType.ARRAY) { 37 | return TypeMap.JAVA_TYPE_MAP.get(type.getValue()); 38 | } else { 39 | return JAVA_CLASS_MAP.get(type.getValue()); 40 | } 41 | } 42 | if (type.getValue() == IntermediateType.ARRAY) { 43 | return generateTypeDeclaration(type.getElementType().get(), type.getValue()) + "[]"; 44 | } else { 45 | final String containerTypeStr = TypeMap.JAVA_TYPE_MAP.get(type.getValue()); 46 | if (type.getKeyType().isPresent()) { 47 | return containerTypeStr + "<" + generateTypeDeclaration(type.getKeyType().get(), 48 | type.getValue()) + ", " + generateTypeDeclaration(type.getElementType().get(), 49 | type.getValue()) + ">"; 50 | } else { 51 | return containerTypeStr + "<" + generateTypeDeclaration(type.getElementType().get(), 52 | type.getValue()) + ">"; 53 | } 54 | } 55 | } 56 | 57 | /** 58 | * Generate a type declaration. 59 | * 60 | *post order, recursive.
61 | * 62 | * @param type the type 63 | * @return type declaration 64 | */ 65 | static String generateTypeDeclaration(final TypeNode type) { 66 | // the parent type should be ARRAY by default 67 | return generateTypeDeclaration(type, IntermediateType.ARRAY); 68 | } 69 | 70 | /** 71 | * Generate an empty function with comments. 72 | * @param function Function prototype 73 | * @return source code of a empty function 74 | */ 75 | public static String generateEmptyFunction(final Function function) { 76 | return "public class Solution {\n" 77 | + FunctionGenerator.generateFunction(function, LanguageType.JAVA, 1) + "}\n"; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/org/algohub/engine/codegenerator/JavaScriptCodeGenerator.java: -------------------------------------------------------------------------------- 1 | package org.algohub.engine.codegenerator; 2 | 3 | import org.algohub.engine.pojo.Function; 4 | 5 | /** 6 | * Generate runnable JavaScript code and call user's function. 7 | */ 8 | @SuppressWarnings({"PMD.InsufficientStringBufferDeclaration"}) 9 | public final class JavaScriptCodeGenerator { 10 | 11 | private JavaScriptCodeGenerator() {} 12 | 13 | /** 14 | * Generate a runnable script for JavaScript. 15 | * 16 | * @param function the function type info 17 | * @return A Compilable and runnable JavaScript script. 18 | */ 19 | public static String generateMain(final Function function) { 20 | final StringBuilder result = new StringBuilder(); 21 | 22 | result.append("input = sys.stdin.read()\njsonValue = json.loads(input)[\"dummy_key\"]\n"); 23 | 24 | final Function.Parameter[] parameters = function.getParameters(); 25 | 26 | for (int i = 0; i < parameters.length; ++i) { 27 | result.append(parameters[i].getName() + " = jsonValue[" + i + "]\n"); 28 | } 29 | 30 | 31 | result.append("result = " + function.getName() + "("); 32 | 33 | 34 | for (final Function.Parameter parameter : parameters) { 35 | result.append(parameter.getName()).append(", "); 36 | } 37 | 38 | // delete the last unnecessary " ," 39 | result.delete(result.length() - 2, result.length()); 40 | result.append(")\nprint(json.dumps(result, separators=(',', ':')))\n"); 41 | 42 | return result.toString(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/algohub/engine/codegenerator/PythonCodeGenerator.java: -------------------------------------------------------------------------------- 1 | package org.algohub.engine.codegenerator; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | 5 | import org.algohub.engine.pojo.Function; 6 | import org.algohub.engine.type.IntermediateType; 7 | import org.algohub.engine.type.LanguageType; 8 | import org.algohub.engine.type.TypeNode; 9 | import org.algohub.engine.util.ObjectMapperInstance; 10 | 11 | /** 12 | * Generate Python code. 13 | */ 14 | @SuppressWarnings({"PMD.InsufficientStringBufferDeclaration"}) 15 | public final class PythonCodeGenerator { 16 | 17 | private PythonCodeGenerator() {} 18 | 19 | /** 20 | * Generate the main function. 21 | * 22 | * @param function Function type info. 23 | * @param fromFile read testcases from file or stdin 24 | * @return the complete source code 25 | */ 26 | @SuppressWarnings({"PMD.PreserveStackTrace"}) 27 | public static String generateMain(final Function function, boolean fromFile) { 28 | final StringBuilder result = new StringBuilder(); 29 | 30 | result.append("import json\nimport collections\nfrom algohub import *\nimport solution\n\n" 31 | + "if __name__ == '__main__':\n"); 32 | 33 | final Function.Parameter[] parameters = function.getParameters(); 34 | try { 35 | for (final Function.Parameter parameter : parameters) { 36 | Indentation.append(result, 37 | parameter.getName() + "_type = TypeNode.from_json('" + ObjectMapperInstance.INSTANCE 38 | .writeValueAsString(parameter.getType()) + "')\n", 1); 39 | 40 | } 41 | Indentation.append(result, 42 | "output_type = TypeNode.from_json('" + ObjectMapperInstance.INSTANCE 43 | .writeValueAsString(function.getReturn_().getType()) + "')\n\n", 1); 44 | } catch (JsonProcessingException e) { // impossible 45 | throw new IllegalStateException(e.getMessage()); 46 | } 47 | 48 | if(fromFile) { 49 | Indentation.append(result, "with open(\"testcases.json\", \"r\") as f:\n", 1); 50 | Indentation.append(result, "raw_testcases = json.loads(f.read())\n", 2); 51 | } else { 52 | Indentation.append(result, "raw_testcases = json.loads(input())\n", 1); 53 | } 54 | Indentation.append(result, "assert isinstance(raw_testcases, list)\n\n", 1); 55 | 56 | Indentation.append(result, "judge_result = JudgeResult(StatusCode.ACCEPTED)\n\n", 1); 57 | 58 | Indentation.append(result, "for i in range(len(raw_testcases)):\n", 1); 59 | Indentation.append(result, "test_case = raw_testcases[i]\n", 2); 60 | for (int i = 0; i < parameters.length; ++i) { 61 | final Function.Parameter parameter = parameters[i]; 62 | Indentation.append(result, 63 | "algohub_" + parameter.getName() + " = from_json(" + "test_case['input'][" + i + "], " 64 | + parameter.getName() + "_type)\n", 2); 65 | } 66 | 67 | Indentation 68 | .append(result, "expected_output = from_json(" + "test_case['output'], output_type)\n\n", 69 | 2); 70 | 71 | Indentation.append(result, "actual_output = solution." + function.getName() + "(", 2); 72 | for (final Function.Parameter parameter : parameters) { 73 | result.append("algohub_").append(parameter.getName()).append(", "); 74 | } 75 | if (parameters.length > 0) { 76 | result.delete(result.length() - 2, result.length()); 77 | } 78 | result.append(")\n\n"); 79 | 80 | Indentation.append(result, "if actual_output == expected_output:\n", 2); 81 | Indentation.append(result, "judge_result.testcase_passed_count += 1\n", 3); 82 | Indentation.append(result, "else:\n", 2); 83 | Indentation.append(result, "judge_result.input = test_case['input']\n", 3); 84 | Indentation.append(result, "judge_result.expected_output = test_case['output']\n", 3); 85 | Indentation.append(result, "judge_result.output = to_json(actual_output, output_type);\n", 3); 86 | Indentation.append(result, "break\n\n", 3); 87 | 88 | Indentation.append(result, 89 | "if judge_result.testcase_passed_count < len(raw_testcases):\n", 1); 90 | Indentation.append(result, "judge_result.status_code = StatusCode.WRONG_ANSWER\n", 2); 91 | Indentation.append(result, "else:\n", 1); 92 | Indentation.append(result, "judge_result.status_code = StatusCode.ACCEPTED\n\n", 2); 93 | 94 | Indentation.append(result, "print(judge_result)\n", 1); 95 | return result.toString(); 96 | } 97 | 98 | /** 99 | * Generate a type declaration. 100 | * 101 | *post order, recursive.
102 | * 103 | * @param type the type 104 | * @return type declaration 105 | */ 106 | static String generateTypeDeclaration(final TypeNode type) { 107 | if (!type.isContainer()) { 108 | return TypeMap.PYTHON_TYPE_MAP.get(type.getValue()); 109 | } 110 | 111 | if (type.getValue() == IntermediateType.ARRAY || type.getValue() == IntermediateType.LIST) { 112 | return generateTypeDeclaration(type.getElementType().get()) + "[]"; 113 | } else { 114 | final String containerTypeStr = TypeMap.PYTHON_TYPE_MAP.get(type.getValue()); 115 | if (type.getKeyType().isPresent()) { 116 | return containerTypeStr + "<" + generateTypeDeclaration(type.getKeyType().get()) 117 | + ", " + generateTypeDeclaration(type.getElementType().get()) 118 | + ">"; 119 | } else { 120 | return containerTypeStr + "<" + generateTypeDeclaration(type.getElementType().get()) + ">"; 121 | } 122 | } 123 | } 124 | 125 | /** 126 | * Generate an empty function with comments. 127 | * @param function Function prototype 128 | * @return source code of a empty function 129 | */ 130 | public static String generateEmptyFunction(final Function function) { 131 | return generateEmptyFunction(function, 0); 132 | } 133 | 134 | static String generateEmptyFunction(final Function function, final int indent) { 135 | final StringBuilder result = new StringBuilder(); 136 | 137 | // function comment 138 | for (final Function.Parameter p : function.getParameters()) { 139 | Indentation.append(result, 140 | "# @param {" + generateTypeDeclaration(p.getType()) 141 | + "} " + p.getName() + " " + p.getComment() + "\n", indent); 142 | } 143 | 144 | final Function.Return return_ = function.getReturn_(); 145 | Indentation.append(result, "# @return {" + 146 | generateTypeDeclaration(return_.getType()) + "} " + return_.getComment() + "\n", indent); 147 | 148 | // function body 149 | Indentation.append(result, "def " + function.getName() + "(", indent); 150 | 151 | for (final Function.Parameter p : function.getParameters()) { 152 | result.append(p.getName()).append(", "); 153 | } 154 | // delete the last unnecessary " ," 155 | result.delete(result.length() - 2, result.length()); 156 | result.append("):\n"); 157 | Indentation.append(result, "# Write your code here\n", indent + 1); 158 | 159 | return result.toString(); 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /src/main/java/org/algohub/engine/codegenerator/RubyCodeGenerator.java: -------------------------------------------------------------------------------- 1 | package org.algohub.engine.codegenerator; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | 5 | import org.algohub.engine.pojo.Function; 6 | import org.algohub.engine.type.IntermediateType; 7 | import org.algohub.engine.type.LanguageType; 8 | import org.algohub.engine.type.TypeNode; 9 | import org.algohub.engine.util.ObjectMapperInstance; 10 | 11 | /** 12 | * Generate runnable Ruby code and call user's function. 13 | */ 14 | @SuppressWarnings({"PMD.InsufficientStringBufferDeclaration"}) 15 | public final class RubyCodeGenerator { 16 | 17 | private RubyCodeGenerator() {} 18 | 19 | /** 20 | * Generate the main function. 21 | * 22 | * @param function Funciton prototype. 23 | * @param fromFile read testcases from file or stdin 24 | * @return the complete source code. 25 | */ 26 | @SuppressWarnings({"PMD.PreserveStackTrace"}) 27 | public static String generateMain(final Function function, boolean fromFile) { 28 | final StringBuilder result = new StringBuilder(); 29 | 30 | result.append("require 'json'\nrequire 'algohub'\nrequire_relative './solution'\n\n\n" 31 | + "if __FILE__ == $0\n"); 32 | 33 | final Function.Parameter[] parameters = function.getParameters(); 34 | try { 35 | for (final Function.Parameter parameter : parameters) { 36 | Indentation.append(result, parameter.getName() + "_type = Algohub::TypeNode.from_json('" 37 | + ObjectMapperInstance.INSTANCE.writeValueAsString(parameter.getType()) + "')\n", 1); 38 | 39 | } 40 | Indentation.append(result, 41 | "output_type = Algohub::TypeNode.from_json('" + ObjectMapperInstance.INSTANCE 42 | .writeValueAsString(function.getReturn_().getType()) + "')\n\n", 1); 43 | } catch (JsonProcessingException e) { // impossible 44 | throw new IllegalStateException(e.getMessage()); 45 | } 46 | 47 | if(fromFile) { 48 | Indentation.append(result, "raw_testcases = JSON.load(IO.read(\"testcases.json\"))\n\n", 1); 49 | } else { 50 | Indentation.append(result, "raw_testcases = JSON.load(STDIN.gets())\n\n", 1); 51 | } 52 | 53 | Indentation.append(result, "judge_result = Algohub::JudgeResult.new(Algohub::StatusCode::ACCEPTED)\n\n", 1); 54 | 55 | Indentation.append(result, "raw_testcases.size.times do |i|\n", 1); 56 | Indentation.append(result, "test_case = raw_testcases[i]\n", 2); 57 | for (int i = 0; i < parameters.length; ++i) { 58 | final Function.Parameter parameter = parameters[i]; 59 | Indentation.append(result, 60 | "algohub_" + parameter.getName() + " = Algohub.from_json(" + "test_case['input'][" + i 61 | + "], " + parameter.getName() + "_type)\n", 2); 62 | } 63 | 64 | Indentation.append(result, 65 | "expected_output = Algohub.from_json(" + "test_case['output'], output_type)\n\n", 2); 66 | 67 | Indentation.append(result, "actual_output = " + function.getName() + "(", 2); 68 | for (final Function.Parameter parameter : parameters) { 69 | result.append("algohub_").append(parameter.getName()).append(", "); 70 | } 71 | if (parameters.length > 0) { 72 | result.delete(result.length() - 2, result.length()); 73 | } 74 | result.append(")\n\n"); 75 | 76 | Indentation.append(result, "if actual_output == expected_output\n", 2); 77 | Indentation.append(result, "judge_result.testcase_passed_count += 1\n", 3); 78 | Indentation.append(result, "else\n", 2); 79 | Indentation.append(result, "judge_result.input = test_case['input']\n", 3); 80 | Indentation.append(result, "judge_result.expected_output = test_case['output']\n", 3); 81 | Indentation.append(result, "judge_result.output = Algohub.to_json(actual_output, output_type)\n", 3); 82 | Indentation.append(result, "break\n", 3); 83 | Indentation.append(result, "end\n", 2); 84 | Indentation.append(result, "end\n\n", 1); 85 | 86 | Indentation.append(result, 87 | "if(judge_result.testcase_passed_count < raw_testcases.size)\n", 1); 88 | Indentation.append(result, "judge_result.status_code = Algohub::StatusCode::WRONG_ANSWER\n", 2); 89 | Indentation.append(result, "else\n", 1); 90 | Indentation.append(result, "judge_result.status_code = Algohub::StatusCode::ACCEPTED\n", 2); 91 | Indentation.append(result, "end\n\n", 1); 92 | 93 | Indentation.append(result, "print(judge_result)\n", 1); 94 | result.append("end\n"); 95 | return result.toString(); 96 | } 97 | 98 | /** 99 | * Generate a type declaration. 100 | * 101 | *post order, recursive.
102 | * 103 | * @param type the type 104 | * @return type declaration 105 | */ 106 | static String generateTypeDeclaration(final TypeNode type) { 107 | if (!type.isContainer()) { 108 | return TypeMap.RUBY_TYPE_MAP.get(type.getValue()); 109 | } 110 | 111 | if (type.getValue() == IntermediateType.ARRAY || type.getValue() == IntermediateType.LIST) { 112 | return generateTypeDeclaration(type.getElementType().get()) + "[]"; 113 | } else { 114 | final String containerTypeStr = TypeMap.RUBY_TYPE_MAP.get(type.getValue()); 115 | if (type.getKeyType().isPresent()) { 116 | return containerTypeStr + "<" + generateTypeDeclaration(type.getKeyType().get()) 117 | + ", " + generateTypeDeclaration(type.getElementType().get()) 118 | + ">"; 119 | } else { 120 | return containerTypeStr + "<" + generateTypeDeclaration(type.getElementType().get()) + ">"; 121 | } 122 | } 123 | } 124 | 125 | /** 126 | * Generate an empty function with comments. 127 | * @param function Function prototype 128 | * @return source code of a empty function 129 | */ 130 | public static String generateEmptyFunction(final Function function) { 131 | final StringBuilder result = new StringBuilder(); 132 | 133 | // function comment 134 | for (final Function.Parameter p : function.getParameters()) { 135 | result.append("# @param {" + generateTypeDeclaration(p.getType())+ "} " + 136 | p.getName() + " " + p.getComment() + "\n"); 137 | } 138 | 139 | final Function.Return return_ = function.getReturn_(); 140 | result.append("# @return {" + generateTypeDeclaration(return_.getType()) + "} " + 141 | return_.getComment() + "\ndef " + function.getName() + "("); 142 | for (final Function.Parameter p : function.getParameters()) { 143 | result.append(p.getName()).append(", "); 144 | } 145 | // delete the last unnecessary " ," 146 | result.delete(result.length() - 2, result.length()); 147 | result.append(")\n # Write your code here\nend"); 148 | 149 | return result.toString(); 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /src/main/java/org/algohub/engine/codegenerator/TypeMap.java: -------------------------------------------------------------------------------- 1 | package org.algohub.engine.codegenerator; 2 | 3 | import com.google.common.collect.ImmutableMap; 4 | 5 | import org.algohub.engine.type.IntermediateType; 6 | import org.algohub.engine.type.LanguageType; 7 | 8 | /** 9 | * Map intermediate types to language related types. 10 | */ 11 | @SuppressWarnings({"PMD.AvoidDuplicateLiterals"}) 12 | final class TypeMap { 13 | /** 14 | * Map intermediate types to Java types. 15 | */ 16 | public static final ImmutableMapUse MethodHandle instead of reflection to gain better 70 | * performance.
71 | */ 72 | public MethodHandle compileStaticMethod(final String className, final String methodName, 73 | final MethodType type, final String source) 74 | throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, 75 | CompileErrorException { 76 | final Map