diff --git a/ethereumj-core/src/main/java/org/ethereum/solidity/compiler/CompilationResult.java b/ethereumj-core/src/main/java/org/ethereum/solidity/compiler/CompilationResult.java index 52f0b86bc1..c5dd28453c 100644 --- a/ethereumj-core/src/main/java/org/ethereum/solidity/compiler/CompilationResult.java +++ b/ethereumj-core/src/main/java/org/ethereum/solidity/compiler/CompilationResult.java @@ -48,6 +48,9 @@ public class CompilationResult { } } + /** + * @return the contract's path given this compilation result contains exactly one contract + */ @JsonIgnore public Path getContractPath() { if (contracts.size() > 1) { throw new UnsupportedOperationException("Source contains more than 1 contact. Please specify the contract name. Available keys (" + getContractKeys() + ")."); @@ -57,6 +60,9 @@ public class CompilationResult { } } + /** + * @return the contract's name given this compilation result contains exactly one contract + */ @JsonIgnore public String getContractName() { if (contracts.size() > 1) { throw new UnsupportedOperationException("Source contains more than 1 contact. Please specify the contract name. Available keys (" + getContractKeys() + ")."); @@ -66,6 +72,10 @@ public class CompilationResult { } } + /** + * @param contractName The contract name + * @return the first contract found for a given contract name; use {@link #getContract(Path, String)} if this compilation result contains more than one contract with the same name + */ @JsonIgnore public ContractMetadata getContract(String contractName) { if (contractName == null && contracts.size() == 1) { return contracts.values().iterator().next(); @@ -79,17 +89,28 @@ public class CompilationResult { return entry.getValue(); } } - throw new UnsupportedOperationException("Source contains more than 1 contact. Please specify a valid contract name. Available keys (" + getContractKeys() + ")."); + throw new UnsupportedOperationException("No contract found with name '" + contractName + "'. Please specify a valid contract name. Available keys (" + getContractKeys() + ")."); } + /** + * @param contractPath The contract path + * @param contractName The contract name + * @return the contract with key {@code contractPath:contractName} if it exists; {@code null} otherwise + */ @JsonIgnore public ContractMetadata getContract(Path contractPath, String contractName) { return contracts.get(contractPath.toAbsolutePath().toString() + ':' + contractName); } + /** + * @return all contracts from this compilation result + */ @JsonIgnore public List getContracts() { return new ArrayList<>(contracts.values()); } + /** + * @return all keys from this compilation result + */ @JsonIgnore public List getContractKeys() { return new ArrayList<>(contracts.keySet()); } diff --git a/ethereumj-core/src/test/java/org/ethereum/solidity/CompilerTest.java b/ethereumj-core/src/test/java/org/ethereum/solidity/CompilerTest.java index fe90f1df15..535ae4e273 100644 --- a/ethereumj-core/src/test/java/org/ethereum/solidity/CompilerTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/solidity/CompilerTest.java @@ -135,6 +135,10 @@ public void compileFilesTest() throws IOException { System.out.println("Err: '" + res.errors + "'"); CompilationResult result = CompilationResult.parse(res.output); + Assert.assertEquals(2, result.getContractKeys().size()); + Assert.assertEquals(result.getContract("test3"), result.getContract(source,"test3")); + Assert.assertNotNull(result.getContract("test1")); + CompilationResult.ContractMetadata a = result.getContract(source, "test3"); CallTransaction.Contract contract = new CallTransaction.Contract(a.abi); System.out.print(contract.functions[0].toString());