Skip to content

Commit

Permalink
Merge pull request #244 from BalticAmadeus/209-property-setter-and-ge…
Browse files Browse the repository at this point in the history
…tter-method-do-not-indent-correctly

209 Property Setter and Getter method do not indent correctly
  • Loading branch information
PauliusKu authored Oct 2, 2024
2 parents bbe612a + 9c6cd71 commit 31ea33a
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 3 deletions.
25 changes: 25 additions & 0 deletions resources/functionalTests/property/5blocks/input.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": true,
"AblFormatter.propertyFormatting": true }*/
class AClass:
define private property m_Total as integer no-undo
get.
set.

define PUBLIC PROPERTY propertyWidthGetterAndSetter AS SomeClass NO-UNDO
GET:
RETURN ?.
END GET.
SET(INPUT pValue AS SomeClass):
DO:
pValue:CallMethod().
END.
END SET.

define PRIVATE VARIABLE propertyWidthGetter_ AS SomeClass NO-UNDO.
define PROTECTED PROPERTY propertyWidthGetter AS SomeClass NO-UNDO
GET():

RETURN propertyWidthGetter_.
END GET.
end class.
25 changes: 25 additions & 0 deletions resources/functionalTests/property/5blocks/target.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": true,
"AblFormatter.propertyFormatting": true }*/
class AClass:
define private property m_Total as integer no-undo
get.
set.

define PUBLIC PROPERTY propertyWidthGetterAndSetter AS SomeClass NO-UNDO
GET:
RETURN ?.
END GET.
SET(INPUT pValue AS SomeClass):
DO:
pValue:CallMethod().
END.
END SET.

define PRIVATE VARIABLE propertyWidthGetter_ AS SomeClass NO-UNDO.
define PROTECTED PROPERTY propertyWidthGetter AS SomeClass NO-UNDO
GET():

RETURN propertyWidthGetter_.
END GET.
end class.
22 changes: 22 additions & 0 deletions resources/functionalTests/property/5blocks2/input.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": true,
"AblFormatter.propertyFormatting": true }*/

class myRequest implements IWebRequest:
define public property Version as character no-undo
get():
return web-context:get-cgi-value("ENV", "SERVER_PROTOCOL").
end get.
set(cProp as char):
undo, throw new AppError(GetReadOnlyMessage(),?).
end set.

define public property ContentType as character no-undo
get():
return web-context:get-cgi-value("ENV", "CONTENT_TYPE").
end get.
set(cProp as char):
undo, throw new AppError(GetReadOnlyMessage(),?).
end set.

end class.
22 changes: 22 additions & 0 deletions resources/functionalTests/property/5blocks2/target.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": true,
"AblFormatter.propertyFormatting": true }*/

class myRequest implements IWebRequest:
define public property Version as character no-undo
get():
return web-context:get-cgi-value("ENV", "SERVER_PROTOCOL").
end get.
set(cProp as char):
undo, throw new AppError(GetReadOnlyMessage(),?).
end set.

define public property ContentType as character no-undo
get():
return web-context:get-cgi-value("ENV", "CONTENT_TYPE").
end get.
set(cProp as char):
undo, throw new AppError(GetReadOnlyMessage(),?).
end set.

end class.
19 changes: 19 additions & 0 deletions resources/functionalTests/property/5blocks3/input.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": true,
"AblFormatter.propertyFormatting": true }*/

class Writer implements IWebRequest:
define static public property Registry as BuilderRegistry no-undo
get():
define variable oRegistry as BuilderRegistry no-undo.
do:
do transaction:
fun(33).
end.
AuthenticationRequestWriterBuilder:InitializeRegistry(oRegistry).
end.
return AuthenticationRequestWriterBuilder:Registry.
end get.
private set.

end class.
19 changes: 19 additions & 0 deletions resources/functionalTests/property/5blocks3/target.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* formatterSettingsOverride */
/* { "AblFormatter.blockFormatting": true,
"AblFormatter.propertyFormatting": true }*/

class Writer implements IWebRequest:
define static public property Registry as BuilderRegistry no-undo
get():
define variable oRegistry as BuilderRegistry no-undo.
do:
do transaction:
fun(33).
end.
AuthenticationRequestWriterBuilder:InitializeRegistry(oRegistry).
end.
return AuthenticationRequestWriterBuilder:Registry.
end get.
private set.

end class.
19 changes: 16 additions & 3 deletions src/v2/formatters/property/PropertyFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { IFormatter } from "../../formatterFramework/IFormatter";
import { CodeEdit } from "../../model/CodeEdit";
import { FullText } from "../../model/FullText";
import { AFormatter } from "../AFormatter";
import { SyntaxNodeType } from "../../../model/SyntaxNodeType";
import {
definitionKeywords,
SyntaxNodeType,
} from "../../../model/SyntaxNodeType";
import { FormatterHelper } from "../../formatterFramework/FormatterHelper";
import { PropertySettings } from "./PropertySettings";
import { IConfigurationManager } from "../../../utils/IConfigurationManager";
Expand Down Expand Up @@ -72,15 +75,25 @@ export class PropertyFormatter extends AFormatter implements IFormatter {
let newString = "";

switch (node.type) {
case SyntaxNodeType.DefineKeyword:
case definitionKeywords.hasFancy(node.type, ""):
newString = FormatterHelper.getCurrentText(node, fullText);
break;
case SyntaxNodeType.Getter:
case SyntaxNodeType.Setter:
const firstLineWhitespace =
FormatterHelper.getActualStatementIndentation(
node,
fullText
);
const statement = FormatterHelper.addIndentation(
FormatterHelper.getCurrentText(node, fullText).trim(),
-firstLineWhitespace + this.settings.tabSize(),
fullText.eolDelimiter
);
newString =
fullText.eolDelimiter +
" ".repeat(this.startColumn + this.settings.tabSize()) +
FormatterHelper.getCurrentText(node, fullText).trim();
statement;
break;
case SyntaxNodeType.Error:
newString = FormatterHelper.getCurrentText(node, fullText);
Expand Down

0 comments on commit 31ea33a

Please sign in to comment.