forked from hyperledger-web3j/web3j
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for generating Java source from Truffle .json contract files.
- Loading branch information
Showing
15 changed files
with
2,612 additions
and
53 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
codegen/src/main/java/org/web3j/codegen/FunctionWrapperGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package org.web3j.codegen; | ||
|
||
import java.io.File; | ||
|
||
import static org.web3j.codegen.Console.exitError; | ||
|
||
/** | ||
* Abstract base class for the concrete function wrapper generators. | ||
*/ | ||
abstract class FunctionWrapperGenerator { | ||
|
||
static final String JAVA_TYPES_ARG = "--javaTypes"; | ||
static final String SOLIDITY_TYPES_ARG = "--solidityTypes"; | ||
|
||
final File destinationDirLocation; | ||
final String basePackageName; | ||
final boolean useJavaNativeTypes; | ||
|
||
FunctionWrapperGenerator( | ||
String destinationDirLocation, | ||
String basePackageName, | ||
boolean useJavaNativeTypes) { | ||
|
||
this.destinationDirLocation = new File(destinationDirLocation); | ||
this.basePackageName = basePackageName; | ||
this.useJavaNativeTypes = useJavaNativeTypes; | ||
} | ||
|
||
static boolean useJavaNativeTypes(String argVal, String usageString) { | ||
boolean useJavaNativeTypes = true; | ||
if (SOLIDITY_TYPES_ARG.equals(argVal)) { | ||
useJavaNativeTypes = false; | ||
} else if (JAVA_TYPES_ARG.equals(argVal)) { | ||
useJavaNativeTypes = true; | ||
} else { | ||
exitError(usageString); | ||
} | ||
return useJavaNativeTypes; | ||
} | ||
|
||
static String parsePositionalArg(String[] args, int idx) { | ||
if (args != null && args.length > idx) { | ||
return args[idx]; | ||
} else { | ||
return ""; | ||
} | ||
} | ||
|
||
static String parseParameterArgument(String[] args, String... parameters) { | ||
for (String parameter : parameters) { | ||
for (int i = 0; i < args.length; i++) { | ||
if (args[i].equals(parameter) | ||
&& i + 1 < args.length) { | ||
String parameterValue = args[i + 1]; | ||
if (!parameterValue.startsWith("-")) { | ||
return parameterValue; | ||
} | ||
} | ||
} | ||
} | ||
return ""; | ||
} | ||
|
||
static String getFileNameNoExtension(String fileName) { | ||
String[] splitName = fileName.split("\\.(?=[^.]*$)"); | ||
return splitName[0]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.