فهرست منبع

Swift language module cleanup

Jan Wittler 4 سال پیش
والد
کامیت
cc6adb3438
1فایلهای تغییر یافته به همراه12 افزوده شده و 5 حذف شده
  1. 12 5
      languages/swift/src/main/java/de/jplag/swift/JPlagSwiftListener.java

+ 12 - 5
languages/swift/src/main/java/de/jplag/swift/JPlagSwiftListener.java

@@ -150,7 +150,6 @@ public class JPlagSwiftListener extends Swift5ParserBaseListener {
 
 
     @Override
     @Override
     public void enterConstant_declaration(Constant_declarationContext context) {
     public void enterConstant_declaration(Constant_declarationContext context) {
-        // TODO: differentiate between property and local variable
         transformToken(PROPERTY_DECLARATION, context.getStart(), context.getStop());
         transformToken(PROPERTY_DECLARATION, context.getStart(), context.getStop());
         super.enterConstant_declaration(context);
         super.enterConstant_declaration(context);
     }
     }
@@ -187,8 +186,7 @@ public class JPlagSwiftListener extends Swift5ParserBaseListener {
 
 
     @Override
     @Override
     public void enterGetter_setter_block(Getter_setter_blockContext context) {
     public void enterGetter_setter_block(Getter_setter_blockContext context) {
-        // if (implicit getter) var example: Int { /* */ }
-        if (context.getChildCount() == 1 && context.getChild(0) instanceof Code_blockContext) {
+        if (isComputedReadOnlyVariableGetterContext(context)) {
             transformToken(PROPERTY_ACCESSOR_BEGIN, context.getStart());
             transformToken(PROPERTY_ACCESSOR_BEGIN, context.getStart());
         }
         }
         super.enterGetter_setter_block(context);
         super.enterGetter_setter_block(context);
@@ -196,13 +194,22 @@ public class JPlagSwiftListener extends Swift5ParserBaseListener {
 
 
     @Override
     @Override
     public void exitGetter_setter_block(Getter_setter_blockContext context) {
     public void exitGetter_setter_block(Getter_setter_blockContext context) {
-        // if (implicit getter) var example: Int { /* */ }
-        if (context.getChildCount() == 1 && context.getChild(0) instanceof Code_blockContext) {
+        if (isComputedReadOnlyVariableGetterContext(context)) {
             transformToken(PROPERTY_ACCESSOR_END, context.getStop());
             transformToken(PROPERTY_ACCESSOR_END, context.getStop());
         }
         }
         super.exitGetter_setter_block(context);
         super.exitGetter_setter_block(context);
     }
     }
 
 
+    /**
+     * Indicates whether the given context encodes a computed read-only variable getter. An example of this is
+     * <code>var example: Int { return 1 }</code>.
+     * @param context
+     * @return
+     */
+    private boolean isComputedReadOnlyVariableGetterContext(Getter_setter_blockContext context) {
+        return context.getChildCount() == 1 && context.getChild(0) instanceof Code_blockContext;
+    }
+
     @Override
     @Override
     public void exitWillSet_clause(WillSet_clauseContext context) {
     public void exitWillSet_clause(WillSet_clauseContext context) {
         transformToken(PROPERTY_ACCESSOR_END, context.getStop());
         transformToken(PROPERTY_ACCESSOR_END, context.getStop());