Split _genMethodDoc into it and _genFallbackDoc for clarity. Add isFallback boolean

This commit is contained in:
Fabio Berger 2018-09-27 10:57:42 +01:00
parent 1402119c84
commit c55a419178
2 changed files with 33 additions and 22 deletions

View File

@ -117,8 +117,10 @@ function _genDocSection(compiledContract: StandardContractOutput, contractName:
// that's because the type of the events array doesn't have any fields for documentation! // that's because the type of the events array doesn't have any fields for documentation!
break; break;
case 'function': case 'function':
docSection.methods.push(_genMethodDoc(abiDefinition as MethodAbi, compiledContract.devdoc));
break;
case 'fallback': case 'fallback':
docSection.methods.push(_genMethodDoc(abiDefinition, compiledContract.devdoc)); docSection.methods.push(_genFallbackDoc(abiDefinition as FallbackAbi, compiledContract.devdoc));
break; break;
default: default:
throw new Error( throw new Error(
@ -173,39 +175,47 @@ function _devdocMethodDetailsIfExist(
return details; return details;
} }
function _genMethodDoc( function _genFallbackDoc(abiDefinition: FallbackAbi, devdocIfExists: DevdocOutput | undefined): SolidityMethod {
abiDefinition: MethodAbi | FallbackAbi, const methodSignature = `${name}()`;
devdocIfExists: DevdocOutput | undefined,
): SolidityMethod {
const name = abiDefinition.type === 'fallback' ? '' : abiDefinition.name;
const { parameters, methodSignature } =
abiDefinition.type === 'fallback'
? { parameters: [], methodSignature: `${name}()` }
: _genMethodParamsDoc(name, abiDefinition.inputs, devdocIfExists);
const comment = _devdocMethodDetailsIfExist(methodSignature, devdocIfExists); const comment = _devdocMethodDetailsIfExist(methodSignature, devdocIfExists);
const returnType =
abiDefinition.type === 'fallback'
? { name: '', typeDocType: TypeDocTypes.Intrinsic }
: _genMethodReturnTypeDoc(abiDefinition.outputs, methodSignature, devdocIfExists);
const returnComment = const returnComment =
_.isUndefined(devdocIfExists) || _.isUndefined(devdocIfExists.methods[methodSignature]) _.isUndefined(devdocIfExists) || _.isUndefined(devdocIfExists.methods[methodSignature])
? undefined ? undefined
: devdocIfExists.methods[methodSignature].return; : devdocIfExists.methods[methodSignature].return;
const isConstant = abiDefinition.type === 'fallback' ? true : abiDefinition.constant; const methodDoc: SolidityMethod = {
isConstructor: false,
name: '',
callPath: '',
parameters: [],
returnType: { name: 'void', typeDocType: TypeDocTypes.Intrinsic },
returnComment,
isConstant: true,
isPayable: abiDefinition.payable,
isFallback: true,
comment,
};
return methodDoc;
}
function _genMethodDoc(abiDefinition: MethodAbi, devdocIfExists: DevdocOutput | undefined): SolidityMethod {
const { parameters, methodSignature } = _genMethodParamsDoc(name, abiDefinition.inputs, devdocIfExists);
const comment = _devdocMethodDetailsIfExist(methodSignature, devdocIfExists);
const returnType = _genMethodReturnTypeDoc(abiDefinition.outputs, methodSignature, devdocIfExists);
const returnComment =
_.isUndefined(devdocIfExists) || _.isUndefined(devdocIfExists.methods[methodSignature])
? undefined
: devdocIfExists.methods[methodSignature].return;
const methodDoc: SolidityMethod = { const methodDoc: SolidityMethod = {
isConstructor: false, isConstructor: false,
name, name: abiDefinition.name,
callPath: '', callPath: '',
parameters, parameters,
returnType, returnType,
returnComment, returnComment,
isConstant, isConstant: abiDefinition.constant,
isPayable: abiDefinition.payable, isPayable: abiDefinition.payable,
comment, comment,
}; };
@ -254,7 +264,7 @@ function _genMethodParamsDoc(
for (const abiParam of abiParams) { for (const abiParam of abiParams) {
const parameter: Parameter = { const parameter: Parameter = {
name: abiParam.name, name: abiParam.name,
comment: '', comment: '<No comment>',
isOptional: false, // Unsupported in Solidity, until resolution of https://github.com/ethereum/solidity/issues/232 isOptional: false, // Unsupported in Solidity, until resolution of https://github.com/ethereum/solidity/issues/232
type: { name: abiParam.type, typeDocType: TypeDocTypes.Intrinsic }, type: { name: abiParam.type, typeDocType: TypeDocTypes.Intrinsic },
}; };
@ -288,7 +298,7 @@ function _genMethodReturnTypeDoc(
devdocIfExists: DevdocOutput | undefined, devdocIfExists: DevdocOutput | undefined,
): Type { ): Type {
const methodReturnTypeDoc: Type = { const methodReturnTypeDoc: Type = {
name: '', name: 'void',
typeDocType: TypeDocTypes.Intrinsic, typeDocType: TypeDocTypes.Intrinsic,
tupleElements: undefined, tupleElements: undefined,
}; };

View File

@ -519,6 +519,7 @@ export interface TypescriptFunction extends BaseFunction {
export interface SolidityMethod extends BaseMethod { export interface SolidityMethod extends BaseMethod {
isConstant?: boolean; isConstant?: boolean;
isPayable?: boolean; isPayable?: boolean;
isFallback?: boolean;
} }
export interface Source { export interface Source {