This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit 583f4e2ade3e8d6510395e2254d66236ddf4e9f0
Author: Josh Tynjala <[email protected]>
AuthorDate: Thu Sep 9 14:12:12 2021 -0700

    formatter: fix indentation of methods in interfaces
---
 .../org/apache/royale/formatter/FORMATTER.java     |  7 ++-
 .../royale/formatter/TestInterfaceDeclaration.java | 52 ++++++++++++++++++++++
 2 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java 
b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
index 19970db..7959d31 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -718,7 +718,12 @@ class FORMATTER {
                                                                                
&& prevStackItem.token.getType() != ASTokenTypes.TOKEN_KEYWORD_DEFAULT
                                                                                
&& prevStackItem.blockDepth <= 0) {
                                                                        
blockStack.remove(blockStack.size() - 1);
-                                                                       indent 
= decreaseIndent(indent);
+                                                                       if 
(prevStackItem.token.getType() != ASTokenTypes.TOKEN_KEYWORD_CLASS
+                                                                               
&& prevStackItem.token.getType() != ASTokenTypes.TOKEN_KEYWORD_INTERFACE
+                                                                               
&& prevStackItem.token.getType() != ASTokenTypes.TOKEN_KEYWORD_FUNCTION)
+                                                                       {
+                                                                               
indent = decreaseIndent(indent);
+                                                                       }
                                                                }
                                                        }
                                                }
diff --git 
a/formatter/src/test/java/org/apache/royale/formatter/TestInterfaceDeclaration.java
 
b/formatter/src/test/java/org/apache/royale/formatter/TestInterfaceDeclaration.java
index e259d13..149ab72 100644
--- 
a/formatter/src/test/java/org/apache/royale/formatter/TestInterfaceDeclaration.java
+++ 
b/formatter/src/test/java/org/apache/royale/formatter/TestInterfaceDeclaration.java
@@ -115,4 +115,56 @@ public class TestInterfaceDeclaration extends 
BaseFormatterTests {
                                // @formatter:on
                                result);
        }
+
+       @Test
+       public void testOneMethod() {
+               FORMATTER formatter = new FORMATTER();
+               formatter.insertSpaceAfterKeywordsInControlFlowStatements = 
true;
+               formatter.placeOpenBraceOnNewLine = true;
+               formatter.insertSpaces = false;
+               String result = formatter.formatText(
+               // @formatter:off
+                       "interface MyInterface\n" +
+                       "{\n" +
+                       "\tfunction myMethod():void;\n" +
+                       "}",
+                       // @formatter:on
+                       problems
+               );
+               assertEquals(
+               // @formatter:off
+                               "interface MyInterface\n" +
+                               "{\n" +
+                               "\tfunction myMethod():void;\n" +
+                               "}",
+                               // @formatter:on
+                               result);
+       }
+
+       @Test
+       public void testMultipleMethods() {
+               FORMATTER formatter = new FORMATTER();
+               formatter.insertSpaceAfterKeywordsInControlFlowStatements = 
true;
+               formatter.placeOpenBraceOnNewLine = true;
+               formatter.insertSpaces = false;
+               String result = formatter.formatText(
+               // @formatter:off
+                       "interface MyInterface\n" +
+                       "{\n" +
+                       "\tfunction myMethod1():void;\n" +
+                       "\tfunction myMethod2():void;\n" +
+                       "}",
+                       // @formatter:on
+                       problems
+               );
+               assertEquals(
+               // @formatter:off
+                               "interface MyInterface\n" +
+                               "{\n" +
+                               "\tfunction myMethod1():void;\n" +
+                               "\tfunction myMethod2():void;\n" +
+                               "}",
+                               // @formatter:on
+                               result);
+       }
 }

Reply via email to