From a543a53563ef93c9439a7c7f391e7444a4e568a1 Mon Sep 17 00:00:00 2001 From: mace Date: Mon, 3 Dec 2018 13:42:24 +0100 Subject: [PATCH] Add support for /** comments and multiline // comments. --- src/lib/contract/contract-comment.es6 | 12 ++++++++++-- test/test-contracts/Metacoin.edited.commented.sol | 15 ++++++++++++++- test/test-contracts/Metacoin.edited.sol | 15 ++++++++++++++- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/lib/contract/contract-comment.es6 b/src/lib/contract/contract-comment.es6 index 22ddcce..020e1d7 100644 --- a/src/lib/contract/contract-comment.es6 +++ b/src/lib/contract/contract-comment.es6 @@ -34,10 +34,18 @@ export class ContractComment { let oldCommentPosition = line - 2; while (true) { let comment = this.contract.getLineAt(oldCommentPosition).trim(); - if (comment.startsWith(parameterCommentRegex)) { + if (comment.startsWith('/**')) { + // multiline /** comments + return true; + } else if (comment.startsWith(parameterCommentRegex)) { + // param comments oldCommentsParams.push({ line: oldCommentPosition, value: comment }); } else if (comment.startsWith('//')) { - oldCommentsMap[comment.match(generatedCommentRegex)[0]] = comment; + // other comments + let matchedComment = comment.match(generatedCommentRegex); + if (matchedComment != null) { + oldCommentsMap[matchedComment[0]] = comment; + } } else if (!comment.startsWith('function')) { break; } diff --git a/test/test-contracts/Metacoin.edited.commented.sol b/test/test-contracts/Metacoin.edited.commented.sol index 209f9cd..74d28dc 100644 --- a/test/test-contracts/Metacoin.edited.commented.sol +++ b/test/test-contracts/Metacoin.edited.commented.sol @@ -1,12 +1,19 @@ pragma solidity ^0.4.24; -/// @title MetaCoin v.2 +/** +* Different type of comments +* MetaCoin contract is used to.... +*/ contract MetaCoin { /// @notice mapping (address => uint) balances; + // @notice + // This is multiline comment + mapping (address => uint) tokens; + event Transfer(address _from,address _to, uint _amount); /// @notice @@ -16,6 +23,12 @@ contract MetaCoin { balances[tx.origin] = 10000; } + /// @param receiver + /// Another multiline comment, this one is about param receiver + function addToken(address receiver) public { + tokens[receiver] = tokens[receiver] + 1; + } + /// @notice /// @dev /// @param receiver diff --git a/test/test-contracts/Metacoin.edited.sol b/test/test-contracts/Metacoin.edited.sol index 2a5c016..5542b03 100644 --- a/test/test-contracts/Metacoin.edited.sol +++ b/test/test-contracts/Metacoin.edited.sol @@ -1,11 +1,18 @@ pragma solidity ^0.4.24; -/// @title MetaCoin v.2 +/** +* Different type of comments +* MetaCoin contract is used to.... +*/ contract MetaCoin { mapping (address => uint) balances; + // @notice + // This is multiline comment + mapping (address => uint) tokens; + event Transfer(address _from,address _to, uint _amount); /// @notice @@ -15,6 +22,12 @@ contract MetaCoin { balances[tx.origin] = 10000; } + /// @param receiver + /// Another multiline comment, this one is about param receiver + function addToken(address receiver) public { + tokens[receiver] = tokens[receiver] + 1; + } + /// @notice /// @dev /// @param receiver