Skip to content

Commit

Permalink
Update functionDefinition option name
Browse files Browse the repository at this point in the history
  • Loading branch information
poorna2152 committed Apr 4, 2024
1 parent ad4ddd5 commit 9e6172d
Show file tree
Hide file tree
Showing 29 changed files with 72 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ maxLineLength = 80
simpleBlocksInOneLine = true
simpleFunctionsInOneLine = true

[functionDeclaration]
[functionDefinition]
alignMultilineParameters = true

[ifStatement]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,40 +103,39 @@ public void formatCLIOnBallerinaProjectWithConfigurations(String testCase, List<

@DataProvider(name = "provideConfigurationProjects")
private Object[][] provideConfigurationProjects() {
Path basePath = RES_DIR.resolve(Path.of("configurations", "options"));
return new Object[][]{
{"brace", List.of(
RES_DIR.resolve(Path.of("configurations", "options", "brace", "source", "project"))
basePath.resolve(Path.of("brace", "source", "project"))
)},
{"functionCall", List.of(
RES_DIR.resolve(Path.of("configurations", "options", "functionCall", "source", "chopDown")),
RES_DIR.resolve(Path.of("configurations", "options", "functionCall", "source", "noWrap")),
RES_DIR.resolve(Path.of("configurations", "options", "functionCall", "source", "wrap"))
basePath.resolve(Path.of("functionCall", "source", "chopDown")),
basePath.resolve(Path.of("functionCall", "source", "noWrap")),
basePath.resolve(Path.of("functionCall", "source", "wrap"))
)},
{"functionDeclaration", List.of(
RES_DIR.resolve(
Path.of("configurations", "options", "functionDeclaration", "source", "chopDown")),
RES_DIR.resolve(
Path.of("configurations", "options", "functionDeclaration", "source", "noWrap")),
RES_DIR.resolve(Path.of("configurations", "options", "functionDeclaration", "source", "wrap"))
{"functionDefinition", List.of(
basePath.resolve(Path.of("functionDefinition", "source", "chopDown")),
basePath.resolve(Path.of("functionDefinition", "source", "noWrap")),
basePath.resolve(Path.of("functionDefinition", "source", "wrap"))
)},
{"ifStatement", List.of(
RES_DIR.resolve(Path.of("configurations", "options", "ifStatement", "source", "ifelse"))
basePath.resolve(Path.of("ifStatement", "source", "ifelse"))
)},
{"imports", List.of(
RES_DIR.resolve(Path.of("configurations", "options", "imports", "source", "project"))
basePath.resolve(Path.of("imports", "source", "project"))
)},
{"indent", List.of(
RES_DIR.resolve(Path.of("configurations", "options", "indent", "source", "project"))
basePath.resolve(Path.of("indent", "source", "project"))
)},
{"query", List.of(
RES_DIR.resolve(Path.of("configurations", "options", "query", "source", "project"))
basePath.resolve(Path.of("query", "source", "project"))
)}
,
{"spacing", List.of(
RES_DIR.resolve(Path.of("configurations", "options", "spacing", "source", "project"))
basePath.resolve(Path.of("spacing", "source", "project"))
)},
{"wrapping", List.of(
RES_DIR.resolve(Path.of("configurations", "options", "wrapping", "source", "project"))
basePath.resolve(Path.of("wrapping", "source", "project"))
)}
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[functionDeclaration]
[functionDefinition]
parametersWrap = "ChopDown"
alignMultilineParameters = true

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[functionDeclaration]
[functionDefinition]
parametersWrap = "NoWrap"

[wrapping]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[functionDeclaration]
[functionDefinition]
parametersWrap = "Wrap"
alignMultilineParameters = true
newLineAfterLeftParen = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ continuationIndentSize = 4
maxLineLength = 80


[functionDeclaration]
[functionDefinition]
alignMultilineParameters = true
newLineAfterLeftParen = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
import org.ballerinalang.formatter.core.options.BraceStyle;
import org.ballerinalang.formatter.core.options.FormattingOptions;
import org.ballerinalang.formatter.core.options.FunctionCallFormattingOptions;
import org.ballerinalang.formatter.core.options.FunctionDeclFormattingOptions;
import org.ballerinalang.formatter.core.options.FunctionDefFormattingOptions;
import org.ballerinalang.formatter.core.options.WrappingMethod;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -374,7 +374,7 @@ public ResourcePathParameterNode transform(ResourcePathParameterNode resourcePat
@Override
public FunctionSignatureNode transform(FunctionSignatureNode functionSignatureNode) {
int parenTrailingNL = 0;
FunctionDeclFormattingOptions funcOptions = options.functionDeclFormattingOptions();
FunctionDefFormattingOptions funcOptions = options.functionDefFormattingOptions();
if (hasNonWSMinutiae(functionSignatureNode.openParenToken().trailingMinutiae()) ||
funcOptions.newLineAfterLeftParen()) {
parenTrailingNL++;
Expand Down Expand Up @@ -4269,7 +4269,7 @@ private boolean shouldWrapLine(Node node, Node parent) {
case REQUIRED_PARAM:
case REST_PARAM:
case RETURN_TYPE_DESCRIPTOR:
if (options.functionDeclFormattingOptions().parametersWrap() == WrappingMethod.NoWrap) {
if (options.functionDefFormattingOptions().parametersWrap() == WrappingMethod.NoWrap) {
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public enum FormatSection {
BRACES("braces"),
FUNCTION_CALL("functionCall"),
FUNCTION_DECLARATION("functionDeclaration"),
FUNCTION_DEFINITION("functionDefinition"),
IF_STATEMENT("ifStatement"),
IMPORT("import"),
INDENT("indent"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class FormattingOptions {
private final IndentFormattingOptions indentFormattingOptions;
private final WrappingFormattingOptions wrappingFormattingOptions;
private final BraceFormattingOptions braceFormattingOptions;
private final FunctionDeclFormattingOptions functionDeclFormattingOptions;
private final FunctionDefFormattingOptions functionDefFormattingOptions;
private final FunctionCallFormattingOptions functionCallFormattingOptions;
private final IfStatementFormattingOptions ifStatementFormattingOptions;
private final SpacingFormattingOptions spacingFormattingOptions;
Expand All @@ -45,7 +45,7 @@ public class FormattingOptions {
private FormattingOptions(IndentFormattingOptions indentFormattingOptions,
WrappingFormattingOptions wrappingFormattingOptions,
BraceFormattingOptions braceFormattingOptions,
FunctionDeclFormattingOptions functionDeclFormattingOptions,
FunctionDefFormattingOptions functionDefFormattingOptions,
FunctionCallFormattingOptions functionCallFormattingOptions,
IfStatementFormattingOptions ifStatementFormattingOptions,
SpacingFormattingOptions spacingFormattingOptions,
Expand All @@ -55,7 +55,7 @@ private FormattingOptions(IndentFormattingOptions indentFormattingOptions,
this.indentFormattingOptions = indentFormattingOptions;
this.wrappingFormattingOptions = wrappingFormattingOptions;
this.braceFormattingOptions = braceFormattingOptions;
this.functionDeclFormattingOptions = functionDeclFormattingOptions;
this.functionDefFormattingOptions = functionDefFormattingOptions;
this.functionCallFormattingOptions = functionCallFormattingOptions;
this.ifStatementFormattingOptions = ifStatementFormattingOptions;
this.spacingFormattingOptions = spacingFormattingOptions;
Expand Down Expand Up @@ -84,8 +84,8 @@ public BraceFormattingOptions braceFormattingOptions() {
return braceFormattingOptions;
}

public FunctionDeclFormattingOptions functionDeclFormattingOptions() {
return functionDeclFormattingOptions;
public FunctionDefFormattingOptions functionDefFormattingOptions() {
return functionDefFormattingOptions;
}

public FunctionCallFormattingOptions functionCallFormattingOptions() {
Expand Down Expand Up @@ -122,8 +122,8 @@ public static class FormattingOptionsBuilder {
private IndentFormattingOptions indentFormattingOptions = IndentFormattingOptions.builder().build();
private WrappingFormattingOptions wrappingFormattingOptions = WrappingFormattingOptions.builder().build();
private BraceFormattingOptions braceFormattingOptions = BraceFormattingOptions.builder().build();
private FunctionDeclFormattingOptions functionDeclFormattingOptions =
FunctionDeclFormattingOptions.builder().build();
private FunctionDefFormattingOptions functionDefFormattingOptions =
FunctionDefFormattingOptions.builder().build();
private FunctionCallFormattingOptions functionCallFormattingOptions =
FunctionCallFormattingOptions.builder().build();
private IfStatementFormattingOptions ifStatementFormattingOptions =
Expand Down Expand Up @@ -175,7 +175,7 @@ public FormattingOptionsBuilder setWrappingFormattingOptions(

public FormattingOptions build() {
return new FormattingOptions(indentFormattingOptions, wrappingFormattingOptions, braceFormattingOptions,
functionDeclFormattingOptions, functionCallFormattingOptions, ifStatementFormattingOptions,
functionDefFormattingOptions, functionCallFormattingOptions, ifStatementFormattingOptions,
spacingFormattingOptions, forceFormattingOptions, importFormattingOptions, queryFormattingOptions);
}

Expand All @@ -197,8 +197,8 @@ public FormattingOptions build(Path root, Object formatSection) throws Formatter
case INDENT -> indentFormattingOptions = IndentFormattingOptions.builder().build(configs);
case WRAPPING -> wrappingFormattingOptions = WrappingFormattingOptions.builder().build(configs);
case BRACES -> braceFormattingOptions = BraceFormattingOptions.builder().build(configs);
case FUNCTION_DECLARATION ->
functionDeclFormattingOptions = FunctionDeclFormattingOptions.builder().build(configs);
case FUNCTION_DEFINITION ->
functionDefFormattingOptions = FunctionDefFormattingOptions.builder().build(configs);
case FUNCTION_CALL ->
functionCallFormattingOptions = FunctionCallFormattingOptions.builder().build(configs);
case IF_STATEMENT ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
*
* @since 2201.9.0
*/
public class FunctionDeclFormattingOptions {
public class FunctionDefFormattingOptions {

private final WrappingMethod parametersWrap;
private final boolean alignMultilineParameters;
private final boolean newLineAfterLeftParen;
private final boolean rightParenOnNewLine;

private FunctionDeclFormattingOptions(WrappingMethod parametersWrap, boolean alignMultilineParameters,
boolean newLineAfterLeftParen, boolean rightParenOnNewLine) {
private FunctionDefFormattingOptions(WrappingMethod parametersWrap, boolean alignMultilineParameters,
boolean newLineAfterLeftParen, boolean rightParenOnNewLine) {
this.parametersWrap = parametersWrap;
this.alignMultilineParameters = alignMultilineParameters;
this.newLineAfterLeftParen = newLineAfterLeftParen;
Expand All @@ -58,64 +58,64 @@ public boolean rightParenOnNewLine() {
return rightParenOnNewLine;
}

public static FunctionDeclFormattingOptionsBuilder builder() {
return new FunctionDeclFormattingOptions.FunctionDeclFormattingOptionsBuilder();
public static FunctionDefFormattingOptionsBuilder builder() {
return new FunctionDefFormattingOptionsBuilder();
}

public static class FunctionDeclFormattingOptionsBuilder {
public static class FunctionDefFormattingOptionsBuilder {

private static final String PARAMETERS_WRAP = "parametersWrap";
private static final String ALIGN_MULTILINE_PARAMETERS = "alignMultilineParameters";
private static final String NEWLINE_AFTER_LEFT_PAREN = "newLineAfterLeftParen";
private static final String RIGHT_PAREN_ON_NEWLINE = "rightParenOnNewLine";
private WrappingMethod parametersWrap =
WrappingMethod.valueOf(getDefaultString(FormatSection.FUNCTION_DECLARATION, PARAMETERS_WRAP));
WrappingMethod.valueOf(getDefaultString(FormatSection.FUNCTION_DEFINITION, PARAMETERS_WRAP));
private boolean alignMultilineParameters =
getDefaultBoolean(FormatSection.FUNCTION_DECLARATION, ALIGN_MULTILINE_PARAMETERS);
getDefaultBoolean(FormatSection.FUNCTION_DEFINITION, ALIGN_MULTILINE_PARAMETERS);
private boolean newLineAfterLeftParen =
getDefaultBoolean(FormatSection.FUNCTION_DECLARATION, NEWLINE_AFTER_LEFT_PAREN);
getDefaultBoolean(FormatSection.FUNCTION_DEFINITION, NEWLINE_AFTER_LEFT_PAREN);
private boolean rightParenOnNewLine =
getDefaultBoolean(FormatSection.FUNCTION_DECLARATION, RIGHT_PAREN_ON_NEWLINE);
getDefaultBoolean(FormatSection.FUNCTION_DEFINITION, RIGHT_PAREN_ON_NEWLINE);

public FunctionDeclFormattingOptionsBuilder setParametersWrap(WrappingMethod parametersWrap) {
public FunctionDefFormattingOptionsBuilder setParametersWrap(WrappingMethod parametersWrap) {
this.parametersWrap = parametersWrap;
return this;
}

public FunctionDeclFormattingOptionsBuilder setAlignMultilineParameters(boolean alignMultilineParameters) {
public FunctionDefFormattingOptionsBuilder setAlignMultilineParameters(boolean alignMultilineParameters) {
this.alignMultilineParameters = alignMultilineParameters;
return this;
}

public FunctionDeclFormattingOptionsBuilder setNewLineAfterLeftParen(boolean newLineAfterLeftParen) {
public FunctionDefFormattingOptionsBuilder setNewLineAfterLeftParen(boolean newLineAfterLeftParen) {
this.newLineAfterLeftParen = newLineAfterLeftParen;
return this;
}

public FunctionDeclFormattingOptionsBuilder setRightParenOnNewLine(boolean rightParenOnNewLine) {
public FunctionDefFormattingOptionsBuilder setRightParenOnNewLine(boolean rightParenOnNewLine) {
this.rightParenOnNewLine = rightParenOnNewLine;
return this;
}

public FunctionDeclFormattingOptions build() {
return new FunctionDeclFormattingOptions(parametersWrap, alignMultilineParameters,
public FunctionDefFormattingOptions build() {
return new FunctionDefFormattingOptions(parametersWrap, alignMultilineParameters,
newLineAfterLeftParen, rightParenOnNewLine);
}

public FunctionDeclFormattingOptions build(Map<String, Object> configs) throws FormatterException {
for (Map.Entry<String, Object> functionDeclarationEntry : configs.entrySet()) {
String functionDeclarationKey = functionDeclarationEntry.getKey();
switch (functionDeclarationKey) {
public FunctionDefFormattingOptions build(Map<String, Object> configs) throws FormatterException {
for (Map.Entry<String, Object> functionDefinitionEntry : configs.entrySet()) {
String functionDefinitionKey = functionDefinitionEntry.getKey();
switch (functionDefinitionKey) {
case PARAMETERS_WRAP ->
setParametersWrap(WrappingMethod.fromString((String) functionDeclarationEntry.getValue()));
setParametersWrap(WrappingMethod.fromString((String) functionDefinitionEntry.getValue()));
case ALIGN_MULTILINE_PARAMETERS ->
setAlignMultilineParameters((Boolean) functionDeclarationEntry.getValue());
setAlignMultilineParameters((Boolean) functionDefinitionEntry.getValue());
case NEWLINE_AFTER_LEFT_PAREN ->
setNewLineAfterLeftParen((Boolean) functionDeclarationEntry.getValue());
setNewLineAfterLeftParen((Boolean) functionDefinitionEntry.getValue());
case RIGHT_PAREN_ON_NEWLINE ->
setRightParenOnNewLine((Boolean) functionDeclarationEntry.getValue());
setRightParenOnNewLine((Boolean) functionDefinitionEntry.getValue());
default -> throw new FormatterException(
"invalid function declaration formatting option: " + functionDeclarationKey);
"invalid function definition formatting option: " + functionDefinitionKey);
}
}
return build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
}
}
},
"functionDeclaration": {
"functionDefinition": {
"type": "object",
"additionalProperties": false,
"properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ functionCall.alignMultilineArguments=false
functionCall.newLineAfterLeftParen=false
functionCall.rightParenOnNewLine=false

functionDeclaration.parametersWrap=Wrap
functionDeclaration.alignMultilineParameters=false
functionDeclaration.newLineAfterLeftParen=false
functionDeclaration.rightParenOnNewLine=false
functionDefinition.parametersWrap=Wrap
functionDefinition.alignMultilineParameters=false
functionDefinition.newLineAfterLeftParen=false
functionDefinition.rightParenOnNewLine=false

ifStatement.elseOnNewLine=false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class FormatFileResolutionTest {
private final Path resDir = Path.of("src", "test", "resources", "configurations", "resolution");
private final String validRemoteUrl =
"https://gist.githubusercontent.com/ballerina-bot/ae54cc7303e9d474d730d732c1594c61/raw" +
"/db0909d0b66f97cd0035f19bcb7cde9a239f5d54/format.toml";
"/8dc3204aec3f158105a811a6a67488bef45ff742/format.toml";
private final Path validRemote = resDir.resolve("validRemote");
private final Path withTarget = resDir.resolve("withTarget");
private final Path invalidLocal = resDir.resolve("invalidLocal");
Expand Down
Loading

0 comments on commit 9e6172d

Please sign in to comment.