From b7e8af48cb0595f270e07591eb66a20107819278 Mon Sep 17 00:00:00 2001 From: Mazesch Date: Fri, 9 Aug 2019 13:18:21 +0200 Subject: [PATCH 1/9] Formatting works for lines with less than 80 characters --- .../solidity/formatting2/SolidityFormatter.xtend | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend index bf4e04c6..f72a7ebc 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend @@ -39,6 +39,8 @@ import com.yakindu.solidity.solidity.TupleExpression import com.yakindu.solidity.solidity.VariableDefinition import com.yakindu.solidity.solidity.WhileStatement import com.yakindu.solidity.solidity.InlineAssemblyBlock +import com.yakindu.solidity.solidity.InlineAssemblyStatement +import com.yakindu.solidity.solidity.FunctionalAssemblyExpression import org.eclipse.xtext.formatting2.AbstractFormatter2 import org.eclipse.xtext.formatting2.IFormattableDocument import org.eclipse.xtext.formatting2.IHiddenRegionFormatter @@ -468,6 +470,17 @@ class SolidityFormatter extends AbstractFormatter2 { ] } + /* com.yakindu.solidity.solidity.impl.AssemblyLocalBindingImpl@6a1b51a7 (label: size) +com.yakindu.solidity.solidity.impl.AssemblyAssignmentImpl@5ea206bc (leftOperand: o_code, rightOpernd: null) +com.yakindu.solidity.solidity.impl.FunctionalAssemblyExpressionImpl@7b6bcbee (label: extcodecopy) + */ + def dispatch void format(FunctionalAssemblyExpression it, extension IFormattableDocument document) { + parameters.forEach[ + prepend[oneSpace] + append[noSpace] + ] + } + protected def void newLines(IHiddenRegionFormatter it) { newLines(1, 2, 3) } From 6374119d518245314ae98aa7c8b034cc0ee912ce Mon Sep 17 00:00:00 2001 From: Mazesch Date: Fri, 9 Aug 2019 13:18:51 +0200 Subject: [PATCH 2/9] removed junk comments --- .../com/yakindu/solidity/formatting2/SolidityFormatter.xtend | 4 ---- 1 file changed, 4 deletions(-) diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend index f72a7ebc..3e9ce773 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend @@ -470,10 +470,6 @@ class SolidityFormatter extends AbstractFormatter2 { ] } - /* com.yakindu.solidity.solidity.impl.AssemblyLocalBindingImpl@6a1b51a7 (label: size) -com.yakindu.solidity.solidity.impl.AssemblyAssignmentImpl@5ea206bc (leftOperand: o_code, rightOpernd: null) -com.yakindu.solidity.solidity.impl.FunctionalAssemblyExpressionImpl@7b6bcbee (label: extcodecopy) - */ def dispatch void format(FunctionalAssemblyExpression it, extension IFormattableDocument document) { parameters.forEach[ prepend[oneSpace] From 1c8800375b22f5dc529fa494137835e286259a50 Mon Sep 17 00:00:00 2001 From: Mazesch Date: Fri, 9 Aug 2019 13:54:41 +0200 Subject: [PATCH 3/9] added wrapping for more than 80 characters but the function for checking doesnt work yet(getLengthOfAssemblyExpression), maybe use IHiddenRegionFormatter.setOnAutowrap --- .../formatting2/SolidityFormatter.xtend | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend index 3e9ce773..cc2b0592 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend @@ -471,10 +471,26 @@ class SolidityFormatter extends AbstractFormatter2 { } def dispatch void format(FunctionalAssemblyExpression it, extension IFormattableDocument document) { - parameters.forEach[ - prepend[oneSpace] - append[noSpace] - ] + val int assemblyExpressionLength = getLengthOfAssemblyExpression + + if (assemblyExpressionLength >= 80) {//setOnAutoWrap + regionFor.keywordPairs('(', ')').forEach [ + key.prepend[oneSpace] + key.append[newLine] + value.prepend[newLine] + ] + parameters.forEach [ + prepend[newLine] + indent(document) + append[noSpace] + ] + } else { + parameters.forEach [ + prepend[oneSpace] + append[noSpace] + ] + } + } protected def void newLines(IHiddenRegionFormatter it) { @@ -530,4 +546,16 @@ class SolidityFormatter extends AbstractFormatter2 { } return (functionKeywordLength + nameLength + parametersLength + modifiersLength + returnParametersLength) } + + protected def int getLengthOfAssemblyExpression(FunctionalAssemblyExpression it) { + val int labelLength = label.toString.length + val int parametersLength = 0 + + for (parameter : parameters) { + //parametersLength += parameter.regionForEObject.length + //parametersLength += 2; + } + + return labelLength + parametersLength; + } } From a125a5df1bc471e9ffc753c485b2fc1180d9baca Mon Sep 17 00:00:00 2001 From: Mazesch Date: Thu, 15 Aug 2019 11:11:10 +0200 Subject: [PATCH 4/9] fixed getLengthOfAssemblyExpression(FunctionalAssemblyExpression it) and fixed a small indentation error for, where FunctionalAssemblyExpressions had their name be followed by a space and not the opening bracket. --- .../formatting2/SolidityFormatter.xtend | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend index cc2b0592..b1a281a6 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend @@ -472,10 +472,9 @@ class SolidityFormatter extends AbstractFormatter2 { def dispatch void format(FunctionalAssemblyExpression it, extension IFormattableDocument document) { val int assemblyExpressionLength = getLengthOfAssemblyExpression - - if (assemblyExpressionLength >= 80) {//setOnAutoWrap + if (assemblyExpressionLength >= 80) { regionFor.keywordPairs('(', ')').forEach [ - key.prepend[oneSpace] + key.prepend[noSpace] key.append[newLine] value.prepend[newLine] ] @@ -489,8 +488,8 @@ class SolidityFormatter extends AbstractFormatter2 { prepend[oneSpace] append[noSpace] ] + regionFor.keyword(",").append[oneSpace].prepend[noSpace] } - } protected def void newLines(IHiddenRegionFormatter it) { @@ -548,14 +547,15 @@ class SolidityFormatter extends AbstractFormatter2 { } protected def int getLengthOfAssemblyExpression(FunctionalAssemblyExpression it) { - val int labelLength = label.toString.length - val int parametersLength = 0 + var int labelLength = label.length + var int parametersLength = 0// + 2(for open/close brackets) - 2(the last parameter is not followed by comma and space) for (parameter : parameters) { - //parametersLength += parameter.regionForEObject.length - //parametersLength += 2; + parametersLength += parameter.regionForEObject.length + parametersLength += 2//for each comma+space after parameter } - - return labelLength + parametersLength; + + var sum = labelLength + parametersLength; + return sum; } } From 08b3b9026225574cc5053d7cba794f8770d3e0c8 Mon Sep 17 00:00:00 2001 From: Mazesch Date: Thu, 15 Aug 2019 11:15:06 +0200 Subject: [PATCH 5/9] removed unused import --- .../src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend index b1a281a6..753db3b5 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend @@ -39,7 +39,6 @@ import com.yakindu.solidity.solidity.TupleExpression import com.yakindu.solidity.solidity.VariableDefinition import com.yakindu.solidity.solidity.WhileStatement import com.yakindu.solidity.solidity.InlineAssemblyBlock -import com.yakindu.solidity.solidity.InlineAssemblyStatement import com.yakindu.solidity.solidity.FunctionalAssemblyExpression import org.eclipse.xtext.formatting2.AbstractFormatter2 import org.eclipse.xtext.formatting2.IFormattableDocument From ccf4db9113871258863857fd95df4477033573f1 Mon Sep 17 00:00:00 2001 From: Mazesch Date: Fri, 16 Aug 2019 10:51:25 +0200 Subject: [PATCH 6/9] fixed #298 by changing `format(PragmaDirective it, extension IFormattableDocument document)` --- .../com/yakindu/solidity/formatting2/SolidityFormatter.xtend | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend index 753db3b5..af0156d0 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend @@ -92,7 +92,7 @@ class SolidityFormatter extends AbstractFormatter2 { } def dispatch void format(PragmaDirective it, extension IFormattableDocument document) { - prepend[noSpace] + append[newLine] } def dispatch void format(ImportDirective it, extension IFormattableDocument document) { From 827b53ee09509a380c17857d2b7f06c35db89ee5 Mon Sep 17 00:00:00 2001 From: Mazesch Date: Fri, 16 Aug 2019 11:59:11 +0200 Subject: [PATCH 7/9] Fixed indentation space between Contracts and after pragmas --- .../yakindu/solidity/formatting2/SolidityFormatter.xtend | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend index af0156d0..6703375c 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend @@ -92,7 +92,7 @@ class SolidityFormatter extends AbstractFormatter2 { } def dispatch void format(PragmaDirective it, extension IFormattableDocument document) { - append[newLine] + append[newLines(1, 1, 1); priority = IHiddenRegionFormatter.LOW_PRIORITY;] } def dispatch void format(ImportDirective it, extension IFormattableDocument document) { @@ -100,6 +100,8 @@ class SolidityFormatter extends AbstractFormatter2 { } def dispatch void format(ContractDefinition it, extension IFormattableDocument document) { + prepend[newLines(2, 3, 3)] + append[newLines(3, 3, 3); priority = IHiddenRegionFormatter.HIGH_PRIORITY;] interior[indent] regionFor.keywordPairs('{', '}').forEach [ key.append[newLine; priority = IHiddenRegionFormatter.LOW_PRIORITY;].prepend [ @@ -123,7 +125,9 @@ class SolidityFormatter extends AbstractFormatter2 { } def dispatch void format(ConstructorDefinition it, extension IFormattableDocument document) { - prepend[newLines(2, 2, 3)] + prepend[newLines(1, 2, 3)] + + allRegionsFor.keywords("constructor", ",").forEach [ append[oneSpace] ] From eeb62edbf8a9b715397a18ea47e6bd9c941aefb2 Mon Sep 17 00:00:00 2001 From: Mazesch Date: Fri, 16 Aug 2019 12:01:04 +0200 Subject: [PATCH 8/9] Fixed a small change that was at the wrong location --- .../com/yakindu/solidity/formatting2/SolidityFormatter.xtend | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend index 6703375c..fdf880de 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend @@ -125,7 +125,7 @@ class SolidityFormatter extends AbstractFormatter2 { } def dispatch void format(ConstructorDefinition it, extension IFormattableDocument document) { - prepend[newLines(1, 2, 3)] + prepend[newLines(2, 2, 3)] allRegionsFor.keywords("constructor", ",").forEach [ From 1ef3aa3ce4d77a783131d96125e6581d1963c08d Mon Sep 17 00:00:00 2001 From: Mazesch Date: Fri, 16 Aug 2019 12:01:50 +0200 Subject: [PATCH 9/9] removed unused lines --- .../com/yakindu/solidity/formatting2/SolidityFormatter.xtend | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend index fdf880de..9f14db32 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend @@ -126,8 +126,6 @@ class SolidityFormatter extends AbstractFormatter2 { def dispatch void format(ConstructorDefinition it, extension IFormattableDocument document) { prepend[newLines(2, 2, 3)] - - allRegionsFor.keywords("constructor", ",").forEach [ append[oneSpace] ]