@Test public void testBuildFuncNameConstants() throws Exception { AbiDefinition functionDefinition = new AbiDefinition( false, Arrays.asList( new AbiDefinition.NamedType("param", "uint8")), "functionName", Collections.emptyList(), "function", true); TypeSpec.Builder builder = TypeSpec.classBuilder("testClass"); builder.addFields(solidityFunctionWrapper .buildFuncNameConstants(Collections.singletonList(functionDefinition))); String expected = "class testClass {\n" + " public static final java.lang.String FUNC_FUNCTIONNAME = \"functionName\";\n" + "}\n"; assertThat(builder.build().toString(), is(expected)); }
public Iterable<FieldSpec> buildFuncNameConstants(List<AbiDefinition> functionDefinitions) { List<FieldSpec> fields = new ArrayList<>(); Set<String> fieldNames = new HashSet<>(); fieldNames.add(Contract.FUNC_DEPLOY); for (AbiDefinition functionDefinition : functionDefinitions) { if (functionDefinition.getType().equals("function")) { String funcName = functionDefinition.getName(); if (!fieldNames.contains(funcName)) { FieldSpec field = FieldSpec.builder(String.class, funcNameToConst(funcName), Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL) .initializer("$S", funcName) .build(); fields.add(field); fieldNames.add(funcName); } } } return fields; }
SolidityFunctionWrapper extends Generator { public Iterable<FieldSpec> buildFuncNameConstants(List<AbiDefinition> functionDefinitions) { List<FieldSpec> fields = new ArrayList<>(); Set<String> fieldNames = new HashSet<>(); fieldNames.add(Contract.FUNC_DEPLOY); for (AbiDefinition functionDefinition : functionDefinitions) { if (functionDefinition.getType().equals("function")) { String funcName = functionDefinition.getName(); if (!fieldNames.contains(funcName)) { FieldSpec field = FieldSpec.builder(String.class, funcNameToConst(funcName), Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL) .initializer("$S", funcName) .build(); fields.add(field); fieldNames.add(funcName); } } } return fields; } }
SolidityFunctionWrapper extends Generator { public Iterable<FieldSpec> buildFuncNameConstants(List<AbiDefinition> functionDefinitions) { List<FieldSpec> fields = new ArrayList<>(); Set<String> fieldNames = new HashSet<>(); fieldNames.add(Contract.FUNC_DEPLOY); for (AbiDefinition functionDefinition : functionDefinitions) { if (functionDefinition.getType().equals("function")) { String funcName = functionDefinition.getName(); if (!fieldNames.contains(funcName)) { FieldSpec field = FieldSpec.builder(String.class, funcNameToConst(funcName), Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL) .initializer("$S", funcName) .build(); fields.add(field); fieldNames.add(funcName); } } } return fields; } SolidityFunctionWrapper(boolean useNativeJavaTypes);  SolidityFunctionWrapper(boolean useNativeJavaTypes, GenerationReporter reporter); }
SolidityFunctionWrapper extends Generator { public Iterable<FieldSpec> buildFuncNameConstants(List<AbiDefinition> functionDefinitions) { List<FieldSpec> fields = new ArrayList<>(); Set<String> fieldNames = new HashSet<>(); fieldNames.add(Contract.FUNC_DEPLOY); for (AbiDefinition functionDefinition : functionDefinitions) { if (functionDefinition.getType().equals("function")) { String funcName = functionDefinition.getName(); if (!fieldNames.contains(funcName)) { FieldSpec field = FieldSpec.builder(String.class, funcNameToConst(funcName), Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL) .initializer("$S", funcName) .build(); fields.add(field); fieldNames.add(funcName); } } } return fields; } SolidityFunctionWrapper(boolean useNativeJavaTypes);  SolidityFunctionWrapper(boolean useNativeJavaTypes, GenerationReporter reporter); @SuppressWarnings("unchecked") void generateJavaFiles(
            String contractName, String bin, String abi, String destinationDir,
            String basePackageName); Iterable<FieldSpec> buildFuncNameConstants(List<AbiDefinition> functionDefinitions); static TypeName getNativeType(TypeName typeName); static TypeName getNativeType(ParameterizedTypeName parameterizedTypeName); static TypeName getEventNativeType(TypeName typeName); static String createValidParamName(String name, int idx); static List<TypeName> buildTypeNames(List<AbiDefinition.NamedType> namedTypes); MethodSpec buildFunction(
            AbiDefinition functionDefinition); MethodSpec buildEventFunction(
            String responseClassName,
            String functionName,
            List<NamedTypeName> indexedParameters,
            List<NamedTypeName> nonIndexedParameters); List<MethodSpec> buildEventFunctions(
            AbiDefinition functionDefinition,
            TypeSpec.Builder classBuilder); CodeBlock buildTypedResponse(
            String objectName,
            List<com.peersafe.codegen.SolidityFunctionWrapper.NamedTypeName> indexedParameters,
            List<com.peersafe.codegen.SolidityFunctionWrapper.NamedTypeName> nonIndexedParameters,
            boolean observable); static TypeName buildTypeName(String typeDeclaration); }
SolidityFunctionWrapper extends Generator { public Iterable<FieldSpec> buildFuncNameConstants(List<AbiDefinition> functionDefinitions) { List<FieldSpec> fields = new ArrayList<>(); Set<String> fieldNames = new HashSet<>(); fieldNames.add(Contract.FUNC_DEPLOY); for (AbiDefinition functionDefinition : functionDefinitions) { if (functionDefinition.getType().equals("function")) { String funcName = functionDefinition.getName(); if (!fieldNames.contains(funcName)) { FieldSpec field = FieldSpec.builder(String.class, funcNameToConst(funcName), Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL) .initializer("$S", funcName) .build(); fields.add(field); fieldNames.add(funcName); } } } return fields; } SolidityFunctionWrapper(boolean useNativeJavaTypes);  SolidityFunctionWrapper(boolean useNativeJavaTypes, GenerationReporter reporter); @SuppressWarnings("unchecked") void generateJavaFiles(
            String contractName, String bin, String abi, String destinationDir,
            String basePackageName); Iterable<FieldSpec> buildFuncNameConstants(List<AbiDefinition> functionDefinitions); static TypeName getNativeType(TypeName typeName); static TypeName getNativeType(ParameterizedTypeName parameterizedTypeName); static TypeName getEventNativeType(TypeName typeName); static String createValidParamName(String name, int idx); static List<TypeName> buildTypeNames(List<AbiDefinition.NamedType> namedTypes); MethodSpec buildFunction(
            AbiDefinition functionDefinition); MethodSpec buildEventFunction(
            String responseClassName,
            String functionName,
            List<NamedTypeName> indexedParameters,
            List<NamedTypeName> nonIndexedParameters); List<MethodSpec> buildEventFunctions(
            AbiDefinition functionDefinition,
            TypeSpec.Builder classBuilder); CodeBlock buildTypedResponse(
            String objectName,
            List<com.peersafe.codegen.SolidityFunctionWrapper.NamedTypeName> indexedParameters,
            List<com.peersafe.codegen.SolidityFunctionWrapper.NamedTypeName> nonIndexedParameters,
            boolean observable); static TypeName buildTypeName(String typeDeclaration);  }