Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix final and abstract access modifiers #34

Merged
merged 5 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions src/TcBlack/ObjectDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private TcObject TokenizeFunctionBlock()

List<string> interfaces = new List<string>();
List<string> parents = new List<string>();
string accessModifier = "";
List<string> accessModifier = new List<string>();
Roald87 marked this conversation as resolved.
Show resolved Hide resolved
bool implements = false;
bool extends = false;
foreach (string part in splitDefinition)
Expand All @@ -124,25 +124,19 @@ private TcObject TokenizeFunctionBlock()
extends = true;
implements = false;
}
else if (part.ToLower() == "abstract" || part.ToLower() == "final")
else if (part.ToLower() == "abstract"
|| part.ToLower() == "final"
|| part.ToLower() == "internal"
|| part.ToLower() == "public")
Roald87 marked this conversation as resolved.
Show resolved Hide resolved
{
accessModifier = part;
accessModifier.Add(part);
}
}
string name;
if (accessModifier.Length != 0)
{
// Access modifier exists and name is pushed back one
name = splitDefinition[2];
}
else
{
name = splitDefinition[1];
}
string name = splitDefinition[1 + accessModifier.Count];

return new TcObject(
objectType: "FUNCTION_BLOCK",
accessModifier: accessModifier,
accessModifier: string.Join(" ", accessModifier.ToArray()),
name: name,
dataType: "",
extends: string.Join(", ", parents.ToArray()),
Expand Down
51 changes: 51 additions & 0 deletions src/TcBlackTests/ObjectDefinitionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,57 @@ public void MethodsWithVariousAccessModifiersAndWhiteSpaces(
Assert.Equal(expectedCode, var.Format(ref indents));
}

[Theory]
[InlineData(
"FUNCTION_BLOCK FINAL Sum IMPLEMENTS Interface",
"FUNCTION_BLOCK FINAL Sum IMPLEMENTS Interface"
)]
[InlineData(
"FUNCTION_BLOCK ABSTRACT Sum IMPLEMENTS Interface, interface2",
"FUNCTION_BLOCK ABSTRACT Sum IMPLEMENTS Interface, interface2"
)]
[InlineData(
"FUNCTION_BLOCK INTERNAL FINAL Sum EXTENDS FB_SumParent IMPLEMENTS I_ab",
"FUNCTION_BLOCK INTERNAL FINAL Sum EXTENDS FB_SumParent IMPLEMENTS I_ab"
)]
[InlineData(
"FUNCTION_BLOCK PUBLIC ABSTRACT Sum IMPLEMENTS Interface, interface2",
"FUNCTION_BLOCK PUBLIC ABSTRACT Sum IMPLEMENTS Interface, interface2"
)]
[InlineData(
" PROPERTY PUBLIC ABSTRACT Test:BOOL",
"PROPERTY PUBLIC ABSTRACT Test : BOOL"
)]
[InlineData(
" PROPERTY FINAL Test:BOOL",
"PROPERTY FINAL Test : BOOL"
)]
[InlineData(
"METHOD PROTECTED FINAL Sum : BOOL",
"METHOD PROTECTED FINAL Sum : BOOL"
)]
[InlineData(
"METHOD PROTECTED ABSTRACT Sum : BOOL",
"METHOD PROTECTED ABSTRACT Sum : BOOL"
)]
[InlineData(
"METHOD PRIVATE ABSTRACT Sum : BOOL",
"METHOD PRIVATE ABSTRACT Sum : BOOL"
)]
[InlineData(
"METHOD INTERNAL ABSTRACT Sum : BOOL",
"METHOD INTERNAL ABSTRACT Sum : BOOL"
)]
public void AbstractAndFinalModifiersForMethodsAndFunctionBlocks(
string originalCode, string expectedCode
)
{
ObjectDefinition var =
new ObjectDefinition(originalCode, " ", "\n");
uint indents = 0;
Assert.Equal(expectedCode, var.Format(ref indents));
}

[Theory]
[InlineData(
"METHOD PUBLIC Close : SysFile.SysTypes.RTS_IEC_RESULT;",
Expand Down