Skip to content

SolidityCode

UrsZeidler edited this page Feb 19, 2017 · 16 revisions

Generated Solidity code

The code generator uses the stereotypes defines in the profile and their properties to define what is generated. For example some code for a function. As the generator produced a skeleton of the code, I would not advice to save the implementation in the model but to use the protected user code instead, this way it is easy to start with a new implementation of the model. Also the editor for the code properties are not very well suited. Instead use the solidity editor and configure your solc compiler for the builder.

If enabled in the preferences there is some java script code generated and/or java code.

packages and solidity files

Uml is namespace aware and support packages, a package containing a class tagged with a Contract or Library stereotype will be generated as a file with the name of package and the suffix '.sol'. This is like the unit concept in pascal, not a real namespace.

contract constructors/default function

The constructor is defined by an operation with the contract name. The default function is defined by a property of the contact stereotype.

This is still possible but deprecated: A constructor for a contract is defined by the properties ConstructorArgs and ConstructorCode in the Contract stereotype. A constructor is generated when the ConstructorCode is not null.

visibilities

The code generator maps the uml visibility as follows:

uml solidity
private private
protected internal
package external
public public

this is applied to properties and operation tagged with the Function stereotype.

protected user code

The Function stereotype has a property functionCode where you could store the actual code. But as this is not a nice code editor the generated code contains special sections where the code is protected from being overridden by the generator.

As the generation will override the files from time to time the user code can be placed between the comment lines:

// Start of user code Class2.operations
// TODO implement
// End of user code

This text will be protected and preserved between the code generations.

an example

In this useless example where all features are used.

/*
 * A comment on the whole model.
 */


library Library {
	
	function test1() public   {
	    
	        // Start of user code Library.function.test1
			// TODO implement
		    // End of user code
	}
		
	
}


/*
 * A simple interface.
 */
contract InterfaceTest {

	
	function simpleMethod() public  
	
	function method1() public   constant  returns (bool )
	
	function method2(uint p1,string p2) public  
	
	function method3(int p,string p2) public   returns (uint8 r1,bytes32 r2)
}


contract Interface1 is InterfaceTest {

	
	function Operation1() public  
}

/*
 * The different kind of methods, also implementing the interface.
 */
contract MethodFeatures is InterfaceTest {

    // Start of user code MethodFeatures.attributes
	    	// TODO implement
	        // End of user code

	
	event TestEvent(address t1,int t2);
	
	
	function simpleMethod() public   {
	    
	        // Start of user code InterfaceTest.function.simpleMethod
	    		// TODO implement
	    	    // End of user code
	}
		
	
	function method1() public   constant  returns (bool ) {
	    
	        // Start of user code InterfaceTest.function.method1
	    		// TODO implement
	    	    // End of user code
	}
		
	
	function method2(uint p1,string p2) public   {
	    
	        // Start of user code InterfaceTest.function.method2
	    		// TODO implement
	    	    // End of user code
	}
		
	
	function method3(int p,string p2) public   returns (uint8 r1,bytes32 r2) {
	    
	        // Start of user code InterfaceTest.function.method3
	    		// TODO implement
	    	    // End of user code
	}
		
	/*
	 * kommentar 2
	 */
	function simpleOperation() public   {
	    
	        // Start of user code MethodFeatures.function.simpleOperation
	    		// TODO implement
	    	    // End of user code
	}
		
	
	
	function privateFunction() private   {
	    
	        // Start of user code MethodFeatures.function.privateFunction
	    		// TODO implement
	    	    // End of user code
	}
		
	
	
	function protectedFunction() inheritable   {
	    
	        // Start of user code MethodFeatures.function.protectedFunction
	    		// TODO implement
	    	    // End of user code
	}
		
	
	
	function packageFunction() external   {
	    
	        // Start of user code MethodFeatures.function.packageFunction
	    		// TODO implement
	    	    // End of user code
	}
		
	
	
	function functionReturn() public   constant  returns (int ) {
	    
	        // Start of user code MethodFeatures.function.functionReturn
	    		// TODO implement
	    	    // End of user code
	}
		
	
	
	function moreParameters(uint test1,address test2) public   returns (bool test3,string test4) {
	    
	        // Start of user code MethodFeatures.function.moreParameters
	    		// TODO implement
	    	    // End of user code
	}
		
	

    // Start of user code MethodFeatures.operations
	    	// TODO implement
	        // End of user code

}

/*
 * An example for properties and inner types.
 */
contract Class2 {
    enum Enumeration { test1,test2 }
    
    struct TestStruct {
    	uint test1;
    }

	string public Attribute1;
	uint private Attribute2;
	string public Attribute3 = "TestString";
	int[4] public Attribute4;
	address public Attribute5;
	mapping (address=>string)public Attribute6;
    // Start of user code Class2.attributes
	    	// TODO implement
	        // End of user code

	
	// getAttribute1
	function getAttribute1() returns(string) {
		return Attribute1;
	}
	// setAttribute1
	function setAttribute1 (Attribute1 aAttribute1) {
		Attribute1 = aAttribute1;
	}
	 
	
	
	// setAttribute2
	function setAttribute2 (Attribute2 aAttribute2) {
		Attribute2 = aAttribute2;
	}
	 
	
	
	// getAttribute3
	function getAttribute3() returns(string) {
		return Attribute3;
	}
	// setAttribute3
	function setAttribute3 (Attribute3 aAttribute3) {
		Attribute3 = aAttribute3;
	}
	 
	
	

    // Start of user code Class2.operations
	    	// TODO implement
	        // End of user code

}

/*
 * Shows how a delegation property works.
 */
contract Delegation {

	MethodFeatures public methodfeatures;
    // Start of user code Delegation.attributes
	    	// TODO implement
	        // End of user code

	
	// delegate functions from methodfeatures
	function methodfeatures_simpleOperation()  {
		methodfeatures.simpleOperation();    
	    // Start of user code MethodFeatures.delegate.function.simpleOperation
	    		// TODO implement
	    	    // End of user code
	}
	function methodfeatures_functionReturn()  constant  returns (int ) {
		return methodfeatures.functionReturn();
	    // Start of user code MethodFeatures.delegate.function.functionReturn
	    		// TODO implement
	    	    // End of user code
	}
	function methodfeatures_moreParameters(uint test1,address test2)  returns (bool test3,string test4) {
		var (test3,test4) = methodfeatures.moreParameters(test1,test2);
	    // Start of user code MethodFeatures.delegate.function.moreParameters
	    		// TODO implement
	    	    // End of user code
	}
	
	

    // Start of user code Delegation.operations
	    	// TODO implement
	        // End of user code

}

/*
 * An abstract method leads to an abstract Contact.
 */
contract Inherited is MethodFeatures {

	bool public Attribute1;
    // Start of user code Iherent.attributes
	    	// TODO implement
	        // End of user code

	
	/*
	 * An abstract method.
	 */
	function anotherOP() public  
	

    // Start of user code Iherent.operations
	    	// TODO implement
	        // End of user code

}

/*
 * This class will implemented the abstract method.
 */
contract Class3 is Inherited {

    // Start of user code Class3.attributes
	    	// TODO implement
	        // End of user code

	
	/*
	 * An abstract method.
	 */
	function anotherOP() public   {
	    
	        // Start of user code Iherent.function.anotherOP
	    		// TODO implement
	    	    // End of user code
	}
		

    // Start of user code Class3.operations
	    	// TODO implement
	        // End of user code

}

/*
 * This class also implements a SCA.
 */
contract Class4 is Class3 {

    // Start of user code Class4.attributes
	    	// TODO implement
	        // End of user code

	
	/*
	 * Get the total token supply.
	 */
	function totalSupply() public   constant  returns (uint256 supply) {
	    
	        // Start of user code TransferableFungible.function.totalSupply
	    		// TODO implement
	    	    // End of user code
	}
		
	/*
	 * Get the account balance of another account with address _owner.
	 */
	function balanceOf(address _owner) public   constant  returns (uint256 balance) {
	    
	        // Start of user code TransferableFungible.function.balanceOf
	    		// TODO implement
	    	    // End of user code
	}
		
	/*
	 * Send _value amount of tokens to address _to.
	 */
	function transfer(address _to,uint256 _value,bool success) public   {
	    
	        // Start of user code TransferableFungible.function.transfer
	    		// TODO implement
	    	    // End of user code
	}
		
	/*
	 * Send _value amount of tokens from address _from to address _to.
	 */
	function transferFrom(address _from,address _to,uint256 _value) public   returns (bool success) {
	    
	        // Start of user code TransferableFungible.function.transferFrom
	    		// TODO implement
	    	    // End of user code
	}
		

    // Start of user code Class4.operations
	    	// TODO implement
	        // End of user code

}

/*
 * A modifier is defines as a constraint 
 where the name is the name and the expression is the code.
 */
contract Modifiers {

    // Start of user code Modifiers.attributes
		// TODO implement
	    // End of user code

	modifier modifier1
	{
	    test code
	    _
	}
	
	
	function Operation1-modifier1() public modifier1
	  {
	    
	        // Start of user code Modifiers.function.Operation1-modifier1
			// TODO implement
		    // End of user code
	}
		
	

    // Start of user code Modifiers.operations
		// TODO implement
	    // End of user code

}


contract Modifier1 is Modifiers {

    // Start of user code Modifier1.attributes
		// TODO implement
	    // End of user code

	
	
	function Operation2() public modifier1
	  {
	    
	        // Start of user code Modifier1.function.Operation2
			// TODO implement
		    // End of user code
	}
		
	

    // Start of user code Modifier1.operations
		// TODO implement
	    // End of user code

}
Clone this wiki locally