Java源码示例:org.web3j.protocol.core.methods.response.AbiDefinition
示例1
private MethodSpec buildDeploy(
String className, AbiDefinition functionDefinition,
Class authType, String authName, boolean withGasProvider) {
boolean isPayable = functionDefinition.isPayable();
MethodSpec.Builder methodBuilder = getDeployMethodSpec(
className, authType, authName, isPayable, withGasProvider);
String inputParams = addParameters(methodBuilder, functionDefinition.getInputs());
if (!inputParams.isEmpty()) {
return buildDeployWithParams(
methodBuilder, className, inputParams, authName,
isPayable, withGasProvider);
} else {
return buildDeployNoParams(methodBuilder, className, authName,
isPayable, withGasProvider);
}
}
示例2
MethodSpec buildFunction(
AbiDefinition functionDefinition) throws ClassNotFoundException {
String functionName = functionDefinition.getName();
MethodSpec.Builder methodBuilder =
MethodSpec.methodBuilder(functionName)
.addModifiers(Modifier.PUBLIC);
String inputParams = addParameters(methodBuilder, functionDefinition.getInputs());
List<TypeName> outputParameterTypes = buildTypeNames(functionDefinition.getOutputs());
if (functionDefinition.isConstant()) {
buildConstantFunction(
functionDefinition, methodBuilder, outputParameterTypes, inputParams);
} else {
buildTransactionFunction(
functionDefinition, methodBuilder, inputParams);
}
return methodBuilder.build();
}
示例3
public Contract(String contractName, List<AbiDefinition> abi, String bytecode,
String deployedBytecode,
String sourceMap, String deployedSourceMap, String source, String sourcePath,
JsonNode ast,
Compiler compiler, Map<String, NetworkInfo> networks, String schemaVersion,
Date updatedAt) {
super();
this.contractName = contractName;
this.abi = abi;
this.bytecode = bytecode;
this.deployedBytecode = deployedBytecode;
this.sourceMap = sourceMap;
this.deployedSourceMap = deployedSourceMap;
this.source = source;
this.sourcePath = sourcePath;
this.ast = ast;
this.compiler = compiler;
this.networks = networks;
this.schemaVersion = schemaVersion;
this.updatedAt = updatedAt;
}
示例4
@Test
public void testBuildFunctionTransaction() throws Exception {
AbiDefinition functionDefinition = new AbiDefinition(
false,
Arrays.asList(
new AbiDefinition.NamedType("param", "uint8")),
"functionName",
Collections.emptyList(),
"type",
false);
MethodSpec methodSpec = solidityFunctionWrapper.buildFunction(functionDefinition);
//CHECKSTYLE:OFF
String expected =
"public org.web3j.protocol.core.RemoteCall<org.web3j.protocol.core.methods.response.TransactionReceipt> functionName(java.math.BigInteger param) {\n"
+ " final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(\n"
+ " FUNC_FUNCTIONNAME, \n"
+ " java.util.Arrays.<org.web3j.abi.datatypes.Type>asList(new org.web3j.abi.datatypes.generated.Uint8(param)), \n"
+ " java.util.Collections.<org.web3j.abi.TypeReference<?>>emptyList());\n"
+ " return executeRemoteCallTransaction(function);\n"
+ "}\n";
//CHECKSTYLE:ON
assertThat(methodSpec.toString(), is(expected));
}
示例5
@Test
public void testBuildPayableFunctionTransaction() throws Exception {
AbiDefinition functionDefinition = new AbiDefinition(
false,
Arrays.asList(
new AbiDefinition.NamedType("param", "uint8")),
"functionName",
Collections.emptyList(),
"type",
true);
MethodSpec methodSpec = solidityFunctionWrapper.buildFunction(functionDefinition);
//CHECKSTYLE:OFF
String expected =
"public org.web3j.protocol.core.RemoteCall<org.web3j.protocol.core.methods.response.TransactionReceipt> functionName(java.math.BigInteger param, java.math.BigInteger vonValue) {\n"
+ " final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(\n"
+ " FUNC_FUNCTIONNAME, \n"
+ " java.util.Arrays.<org.web3j.abi.datatypes.Type>asList(new org.web3j.abi.datatypes.generated.Uint8(param)), \n"
+ " java.util.Collections.<org.web3j.abi.TypeReference<?>>emptyList());\n"
+ " return executeRemoteCallTransaction(function, vonValue);\n"
+ "}\n";
//CHECKSTYLE:ON
assertThat(methodSpec.toString(), is(expected));
}
示例6
@Test
public void testBuildFunctionConstantSingleValueReturn() throws Exception {
AbiDefinition functionDefinition = new AbiDefinition(
true,
Arrays.asList(
new AbiDefinition.NamedType("param", "uint8")),
"functionName",
Arrays.asList(
new AbiDefinition.NamedType("result", "int8")),
"type",
false);
MethodSpec methodSpec = solidityFunctionWrapper.buildFunction(functionDefinition);
//CHECKSTYLE:OFF
String expected =
"public org.web3j.protocol.core.RemoteCall<java.math.BigInteger> functionName(java.math.BigInteger param) {\n"
+ " final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(FUNC_FUNCTIONNAME, \n"
+ " java.util.Arrays.<org.web3j.abi.datatypes.Type>asList(new org.web3j.abi.datatypes.generated.Uint8(param)), \n"
+ " java.util.Arrays.<org.web3j.abi.TypeReference<?>>asList(new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.generated.Int8>() {}));\n"
+ " return executeRemoteCallSingleValueReturn(function, java.math.BigInteger.class);\n"
+ "}\n";
//CHECKSTYLE:ON
assertThat(methodSpec.toString(), is(expected));
}
示例7
@Test
public void testBuildFunctionConstantInvalid() throws Exception {
AbiDefinition functionDefinition = new AbiDefinition(
true,
Arrays.asList(
new AbiDefinition.NamedType("param", "uint8")),
"functionName",
Collections.emptyList(),
"type",
false);
MethodSpec methodSpec = solidityFunctionWrapper.buildFunction(functionDefinition);
//CHECKSTYLE:OFF
String expected =
"public void functionName(java.math.BigInteger param) {\n"
+ " throw new RuntimeException(\"cannot call constant function with void return type\");\n"
+ "}\n";
//CHECKSTYLE:ON
assertThat(methodSpec.toString(), is(expected));
}
示例8
@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)));
//CHECKSTYLE:OFF
String expected =
"class testClass {\n" +
" public static final java.lang.String FUNC_FUNCTIONNAME = \"functionName\";\n" +
"}\n";
//CHECKSTYLE:ON
assertThat(builder.build().toString(), is(expected));
}
示例9
@Test
public void testBuildPayableFunctionTransaction() throws Exception {
AbiDefinition functionDefinition =
new AbiDefinition(
false,
Arrays.asList(new AbiDefinition.NamedType("param", "uint8")),
"functionName",
Collections.emptyList(),
"type",
true);
MethodSpec methodSpec = solidityFunctionWrapper.buildFunction(functionDefinition);
String expected =
"public org.web3j.protocol.core.RemoteFunctionCall<org.web3j.protocol.core.methods.response.TransactionReceipt> functionName(java.math.BigInteger param, java.math.BigInteger weiValue) {\n"
+ " final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(\n"
+ " FUNC_FUNCTIONNAME, \n"
+ " java.util.Arrays.<org.web3j.abi.datatypes.Type>asList(new org.web3j.abi.datatypes.generated.Uint8(param)), \n"
+ " java.util.Collections.<org.web3j.abi.TypeReference<?>>emptyList());\n"
+ " return executeRemoteCallTransaction(function, weiValue);\n"
+ "}\n";
assertEquals(methodSpec.toString(), (expected));
}
示例10
private MethodSpec buildDeploy(
String className, AbiDefinition functionDefinition,
Class authType, String authName) {
boolean isPayable = functionDefinition.isPayable();
MethodSpec.Builder methodBuilder = getDeployMethodSpec(
className, authType, authName, isPayable);
String inputParams = addParameters(methodBuilder, functionDefinition.getInputs());
if (!inputParams.isEmpty()) {
return buildDeployWithParams(
methodBuilder, className, inputParams, authName, isPayable);
} else {
return buildDeployNoParams(methodBuilder, className, authName, isPayable);
}
}
示例11
@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";
assertEquals(builder.build().toString(), (expected));
}
示例12
MethodSpec buildFunction(
AbiDefinition functionDefinition) throws ClassNotFoundException {
String functionName = functionDefinition.getName();
MethodSpec.Builder methodBuilder =
MethodSpec.methodBuilder(functionName)
.addModifiers(Modifier.PUBLIC);
String inputParams = addParameters(methodBuilder, functionDefinition.getInputs());
List<TypeName> outputParameterTypes = buildTypeNames(functionDefinition.getOutputs());
if (functionDefinition.isConstant()) {
buildConstantFunction(
functionDefinition, methodBuilder, outputParameterTypes, inputParams);
} else {
buildTransactionFunction(
functionDefinition, methodBuilder, inputParams);
}
return methodBuilder.build();
}
示例13
public Contract(String contractName, List<AbiDefinition> abi, String bytecode,
String deployedBytecode,
String sourceMap, String deployedSourceMap, String source, String sourcePath,
JsonNode ast,
Compiler compiler, Map<String, NetworkInfo> networks, String schemaVersion,
Date updatedAt) {
super();
this.contractName = contractName;
this.abi = abi;
this.bytecode = bytecode;
this.deployedBytecode = deployedBytecode;
this.sourceMap = sourceMap;
this.deployedSourceMap = deployedSourceMap;
this.source = source;
this.sourcePath = sourcePath;
this.ast = ast;
this.compiler = compiler;
this.networks = networks;
this.schemaVersion = schemaVersion;
this.updatedAt = updatedAt;
}
示例14
@Test
public void testBuildingFunctionTransactionThatReturnsValueReportsWarning() throws Exception {
AbiDefinition functionDefinition = new AbiDefinition(
false,
Arrays.asList(
new AbiDefinition.NamedType("param", "uint8")),
"functionName",
Arrays.asList(
new AbiDefinition.NamedType("result", "uint8")),
"type",
false);
solidityFunctionWrapper.buildFunction(functionDefinition);
//CHECKSTYLE:OFF
verify(generationReporter).report(
"Definition of the function functionName returns a value but is not defined as a view function. " +
"Please ensure it contains the view modifier if you want to read the return value");
//CHECKSTYLE:ON
}
示例15
@Test
public void testBuildPayableFunctionTransaction() throws Exception {
AbiDefinition functionDefinition = new AbiDefinition(
false,
Arrays.asList(
new AbiDefinition.NamedType("param", "uint8")),
"functionName",
Collections.emptyList(),
"type",
true);
MethodSpec methodSpec = solidityFunctionWrapper.buildFunction(functionDefinition);
//CHECKSTYLE:OFF
String expected =
"public org.web3j.protocol.core.RemoteCall<org.web3j.protocol.core.methods.response.TransactionReceipt> functionName(java.math.BigInteger param, java.math.BigInteger weiValue) {\n"
+ " final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(\n"
+ " \"functionName\", \n"
+ " java.util.Arrays.<org.web3j.abi.datatypes.Type>asList(new org.web3j.abi.datatypes.generated.Uint8(param)), \n"
+ " java.util.Collections.<org.web3j.abi.TypeReference<?>>emptyList());\n"
+ " return executeRemoteCallTransaction(function, weiValue);\n"
+ "}\n";
//CHECKSTYLE:ON
assertThat(methodSpec.toString(), is(expected));
}
示例16
@Test
public void testBuildFunctionConstantSingleValueReturn() throws Exception {
AbiDefinition functionDefinition = new AbiDefinition(
true,
Arrays.asList(
new AbiDefinition.NamedType("param", "uint8")),
"functionName",
Arrays.asList(
new AbiDefinition.NamedType("result", "int8")),
"type",
false);
MethodSpec methodSpec = solidityFunctionWrapper.buildFunction(functionDefinition);
//CHECKSTYLE:OFF
String expected =
"public org.web3j.protocol.core.RemoteCall<java.math.BigInteger> functionName(java.math.BigInteger param) {\n"
+ " final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(\"functionName\", \n"
+ " java.util.Arrays.<org.web3j.abi.datatypes.Type>asList(new org.web3j.abi.datatypes.generated.Uint8(param)), \n"
+ " java.util.Arrays.<org.web3j.abi.TypeReference<?>>asList(new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.generated.Int8>() {}));\n"
+ " return executeRemoteCallSingleValueReturn(function, java.math.BigInteger.class);\n"
+ "}\n";
//CHECKSTYLE:ON
assertThat(methodSpec.toString(), is(expected));
}
示例17
private List<MethodSpec> buildFunctionDefinitions(
String className,
TypeSpec.Builder classBuilder,
List<AbiDefinition> functionDefinitions)
throws ClassNotFoundException {
Set<String> duplicateFunctionNames = getDuplicateFunctionNames(functionDefinitions);
List<MethodSpec> methodSpecs = new ArrayList<>();
for (AbiDefinition functionDefinition : functionDefinitions) {
if (functionDefinition.getType().equals(TYPE_FUNCTION)) {
String functionName = funcNameToConst(functionDefinition.getName(), true);
boolean useUpperCase = !duplicateFunctionNames.contains(functionName);
methodSpecs.addAll(buildFunctions(functionDefinition, useUpperCase));
} else if (functionDefinition.getType().equals(TYPE_EVENT)) {
methodSpecs.addAll(buildEventFunctions(functionDefinition, classBuilder));
}
}
return methodSpecs;
}
示例18
@Test
public void testBuildingFunctionTransactionThatReturnsValueReportsWarning() throws Exception {
AbiDefinition functionDefinition =
new AbiDefinition(
false,
Arrays.asList(new AbiDefinition.NamedType("param", "uint8")),
"functionName",
Arrays.asList(new AbiDefinition.NamedType("result", "uint8")),
"type",
false);
solidityFunctionWrapper.buildFunction(functionDefinition);
verify(generationReporter)
.report(
"Definition of the function functionName returns a value but is not defined as a view function. "
+ "Please ensure it contains the view modifier if you want to read the return value");
}
示例19
private java.util.Collection<? extends AbiDefinition.NamedType> extractNested(
final AbiDefinition.NamedType namedType) {
if (namedType.getComponents().size() == 0) {
return new ArrayList<>();
} else {
List<AbiDefinition.NamedType> nestedStructs = new ArrayList<>();
namedType
.getComponents()
.forEach(
nestedNamedStruct -> {
nestedStructs.add(nestedNamedStruct);
nestedStructs.addAll(extractNested(nestedNamedStruct));
});
return nestedStructs;
}
}
示例20
private MethodSpec buildDeploy(
String className,
AbiDefinition functionDefinition,
Class authType,
String authName,
boolean withGasProvider)
throws ClassNotFoundException {
boolean isPayable = functionDefinition.isPayable();
MethodSpec.Builder methodBuilder =
getDeployMethodSpec(className, authType, authName, isPayable, withGasProvider);
String inputParams = addParameters(methodBuilder, functionDefinition.getInputs());
if (!inputParams.isEmpty()) {
return buildDeployWithParams(
methodBuilder, className, inputParams, authName, isPayable, withGasProvider);
} else {
return buildDeployNoParams(
methodBuilder, className, authName, isPayable, withGasProvider);
}
}
示例21
private List<ParameterSpec> buildParameterTypes(
List<AbiDefinition.NamedType> namedTypes, boolean primitives)
throws ClassNotFoundException {
List<ParameterSpec> result = new ArrayList<>(namedTypes.size());
for (int i = 0; i < namedTypes.size(); i++) {
AbiDefinition.NamedType namedType = namedTypes.get(i);
String name = createValidParamName(namedType.getName(), i);
String type = namedTypes.get(i).getType();
if (type.startsWith("tuple")) {
result.add(
ParameterSpec.builder(
structClassNameMap.get(namedType.structIdentifier()), name)
.build());
} else {
result.add(ParameterSpec.builder(buildTypeName(type, primitives), name).build());
}
}
return result;
}
示例22
@Test
public void testBuildFunctionConstantSingleValueReturn() throws Exception {
AbiDefinition functionDefinition =
new AbiDefinition(
true,
Arrays.asList(new AbiDefinition.NamedType("param", "uint8")),
"functionName",
Arrays.asList(new AbiDefinition.NamedType("result", "int8")),
"type",
false);
MethodSpec methodSpec = solidityFunctionWrapper.buildFunction(functionDefinition);
String expected =
"public org.web3j.protocol.core.RemoteFunctionCall<java.math.BigInteger> functionName(java.math.BigInteger param) {\n"
+ " final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(FUNC_FUNCTIONNAME, \n"
+ " java.util.Arrays.<org.web3j.abi.datatypes.Type>asList(new org.web3j.abi.datatypes.generated.Uint8(param)), \n"
+ " java.util.Arrays.<org.web3j.abi.TypeReference<?>>asList(new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.generated.Int8>() {}));\n"
+ " return executeRemoteCallSingleValueReturn(function, java.math.BigInteger.class);\n"
+ "}\n";
assertEquals(methodSpec.toString(), (expected));
}
示例23
@Test
public void testBuildFunctionTransaction() throws Exception {
AbiDefinition functionDefinition =
new AbiDefinition(
false,
Arrays.asList(new AbiDefinition.NamedType("param", "uint8")),
"functionName",
Collections.emptyList(),
"type",
false);
MethodSpec methodSpec = solidityFunctionWrapper.buildFunction(functionDefinition);
String expected =
"public org.web3j.protocol.core.RemoteFunctionCall<org.web3j.protocol.core.methods.response.TransactionReceipt> functionName(java.math.BigInteger param) {\n"
+ " final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(\n"
+ " FUNC_FUNCTIONNAME, \n"
+ " java.util.Arrays.<org.web3j.abi.datatypes.Type>asList(new org.web3j.abi.datatypes.generated.Uint8(param)), \n"
+ " java.util.Collections.<org.web3j.abi.TypeReference<?>>emptyList());\n"
+ " return executeRemoteCallTransaction(function);\n"
+ "}\n";
assertEquals(methodSpec.toString(), (expected));
}
示例24
@Test
public void testAbiDefinitionNamedType() {
EqualsVerifier.forClass(AbiDefinition.NamedType.class)
.withPrefabValues(
AbiDefinition.NamedType.class,
new AbiDefinition.NamedType(),
new AbiDefinition.NamedType("name", "uint256"))
.suppress(Warning.NONFINAL_FIELDS)
.suppress(Warning.STRICT_INHERITANCE)
.verify();
}
示例25
private void generate() throws IOException, ClassNotFoundException {
File binaryFile = new File(binaryFileLocation);
if (!binaryFile.exists()) {
exitError("Invalid input binary file specified: " + binaryFileLocation);
}
byte[] bytes = Files.readBytes(new File(binaryFile.toURI()));
String binary = new String(bytes);
File absFile = new File(absFileLocation);
if (!absFile.exists() || !absFile.canRead()) {
exitError("Invalid input ABI file specified: " + absFileLocation);
}
String fileName = absFile.getName();
String contractName = getFileNameNoExtension(fileName);
bytes = Files.readBytes(new File(absFile.toURI()));
String abi = new String(bytes);
List<AbiDefinition> functionDefinitions = loadContractDefinition(absFile);
if (functionDefinitions.isEmpty()) {
exitError("Unable to parse input ABI file");
} else {
String className = Strings.capitaliseFirstLetter(contractName);
System.out.printf("Generating " + basePackageName + "." + className + " ... ");
new SolidityFunctionWrapper(useJavaNativeTypes).generateJavaFiles(contractName, binary, abi, destinationDirLocation.toString(),
basePackageName);
System.out.println("File written to " + destinationDirLocation.toString() + "\n");
}
}
示例26
void generateJavaFiles(
String contractName, String bin, List<AbiDefinition> abi, String destinationDir,
String basePackageName, Map<String, String> addresses)
throws IOException, ClassNotFoundException {
String className = Strings.capitaliseFirstLetter(contractName);
TypeSpec.Builder classBuilder = createClassBuilder(className, bin);
classBuilder.addMethod(buildConstructor(Credentials.class, CREDENTIALS, false));
classBuilder.addMethod(buildConstructor(Credentials.class, CREDENTIALS, true));
classBuilder.addMethod(buildConstructor(TransactionManager.class,
TRANSACTION_MANAGER, false));
classBuilder.addMethod(buildConstructor(TransactionManager.class,
TRANSACTION_MANAGER, true));
classBuilder.addFields(buildFuncNameConstants(abi));
classBuilder.addMethods(
buildFunctionDefinitions(className, classBuilder, abi));
classBuilder.addMethod(buildLoad(className, Credentials.class, CREDENTIALS, false));
classBuilder.addMethod(buildLoad(className, TransactionManager.class,
TRANSACTION_MANAGER, false));
classBuilder.addMethod(buildLoad(className, Credentials.class, CREDENTIALS, true));
classBuilder.addMethod(buildLoad(className, TransactionManager.class,
TRANSACTION_MANAGER, true));
addAddressesSupport(classBuilder, addresses);
write(basePackageName, classBuilder.build(), destinationDir);
}
示例27
@Test
public void testBuildFunctionConstantDynamicArrayRawListReturn() throws Exception {
AbiDefinition functionDefinition =
new AbiDefinition(
true,
Arrays.asList(new AbiDefinition.NamedType("param", "uint8[]")),
"functionName",
Arrays.asList(new AbiDefinition.NamedType("result", "address[]")),
"type",
false);
MethodSpec methodSpec = solidityFunctionWrapper.buildFunction(functionDefinition);
String expected =
"public org.web3j.protocol.core.RemoteFunctionCall<java.util.List> functionName(java.util.List<java.math.BigInteger> param) {\n"
+ " final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(FUNC_FUNCTIONNAME, \n"
+ " java.util.Arrays.<org.web3j.abi.datatypes.Type>asList(new org.web3j.abi.datatypes.DynamicArray<org.web3j.abi.datatypes.generated.Uint8>(\n"
+ " org.web3j.abi.datatypes.generated.Uint8.class,\n"
+ " org.web3j.abi.Utils.typeMap(param, org.web3j.abi.datatypes.generated.Uint8.class))), \n"
+ " java.util.Arrays.<org.web3j.abi.TypeReference<?>>asList(new org.web3j.abi.TypeReference<org.web3j.abi.datatypes.DynamicArray<org.web3j.abi.datatypes.Address>>() {}));\n"
+ " return new org.web3j.protocol.core.RemoteFunctionCall<java.util.List>(function,\n"
+ " new java.util.concurrent.Callable<java.util.List>() {\n"
+ " @java.lang.Override\n"
+ " @java.lang.SuppressWarnings(\"unchecked\")\n"
+ " public java.util.List call() throws java.lang.Exception {\n"
+ " java.util.List<org.web3j.abi.datatypes.Type> result = (java.util.List<org.web3j.abi.datatypes.Type>) executeCallSingleValueReturn(function, java.util.List.class);\n"
+ " return convertToNative(result);\n"
+ " }\n"
+ " });\n"
+ "}\n";
assertEquals(methodSpec.toString(), (expected));
}
示例28
String addParameters(
MethodSpec.Builder methodBuilder, List<AbiDefinition.NamedType> namedTypes) {
List<ParameterSpec> inputParameterTypes = buildParameterTypes(namedTypes);
List<ParameterSpec> nativeInputParameterTypes =
new ArrayList<>(inputParameterTypes.size());
for (ParameterSpec parameterSpec : inputParameterTypes) {
TypeName typeName = getWrapperType(parameterSpec.type);
nativeInputParameterTypes.add(
ParameterSpec.builder(typeName, parameterSpec.name).build());
}
methodBuilder.addParameters(nativeInputParameterTypes);
if (useNativeJavaTypes) {
return Collection.join(
inputParameterTypes,
", \n",
// this results in fully qualified names being generated
this::createMappedParameterTypes);
} else {
return Collection.join(
inputParameterTypes,
", ",
parameterSpec -> parameterSpec.name);
}
}
示例29
static List<ParameterSpec> buildParameterTypes(List<AbiDefinition.NamedType> namedTypes) {
List<ParameterSpec> result = new ArrayList<>(namedTypes.size());
for (int i = 0; i < namedTypes.size(); i++) {
AbiDefinition.NamedType namedType = namedTypes.get(i);
String name = createValidParamName(namedType.getName(), i);
String type = namedTypes.get(i).getType();
result.add(ParameterSpec.builder(buildTypeName(type), name).build());
}
return result;
}
示例30
static List<TypeName> buildTypeNames(List<AbiDefinition.NamedType> namedTypes) {
List<TypeName> result = new ArrayList<>(namedTypes.size());
for (AbiDefinition.NamedType namedType : namedTypes) {
result.add(buildTypeName(namedType.getType()));
}
return result;
}