Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master' into issue_260_error_rec…
Browse files Browse the repository at this point in the history
…overing
  • Loading branch information
flantony committed Aug 22, 2019
2 parents b4e8e76 + adc84e6 commit abaddb8
Showing 1 changed file with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ 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.FunctionalAssemblyExpression
import org.eclipse.xtext.formatting2.AbstractFormatter2
import org.eclipse.xtext.formatting2.IFormattableDocument
import org.eclipse.xtext.formatting2.IHiddenRegionFormatter
Expand Down Expand Up @@ -91,14 +92,16 @@ class SolidityFormatter extends AbstractFormatter2 {
}

def dispatch void format(PragmaDirective it, extension IFormattableDocument document) {
prepend[noSpace]
append[newLines(1, 1, 1); priority = IHiddenRegionFormatter.LOW_PRIORITY;]
}

def dispatch void format(ImportDirective it, extension IFormattableDocument document) {
prepend[newLines]
}

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 [
Expand Down Expand Up @@ -468,6 +471,28 @@ class SolidityFormatter extends AbstractFormatter2 {
]
}

def dispatch void format(FunctionalAssemblyExpression it, extension IFormattableDocument document) {
val int assemblyExpressionLength = getLengthOfAssemblyExpression
if (assemblyExpressionLength >= 80) {
regionFor.keywordPairs('(', ')').forEach [
key.prepend[noSpace]
key.append[newLine]
value.prepend[newLine]
]
parameters.forEach [
prepend[newLine]
indent(document)
append[noSpace]
]
} else {
parameters.forEach [
prepend[oneSpace]
append[noSpace]
]
regionFor.keyword(",").append[oneSpace].prepend[noSpace]
}
}

protected def void newLines(IHiddenRegionFormatter it) {
newLines(1, 2, 3)
}
Expand Down Expand Up @@ -521,4 +546,17 @@ class SolidityFormatter extends AbstractFormatter2 {
}
return (functionKeywordLength + nameLength + parametersLength + modifiersLength + returnParametersLength)
}

protected def int getLengthOfAssemblyExpression(FunctionalAssemblyExpression it) {
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//for each comma+space after parameter
}

var sum = labelLength + parametersLength;
return sum;
}
}

0 comments on commit abaddb8

Please sign in to comment.