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 9a651d8077275633240f51c94b47f0ae7e0ac34f
Author: Josh Tynjala <joshtynj...@apache.org>
AuthorDate: Wed Sep 11 13:42:30 2019 -0700

    Configuration: added -warn-this-within-closure compiler option (references 
#90)
---
 .../clients/problems/ProblemSettingsFilter.java        |  4 ++++
 .../apache/royale/compiler/config/Configuration.java   | 18 ++++++++++++++++++
 .../apache/royale/compiler/config/Configurator.java    |  5 +++++
 .../compiler/config/ICompilerProblemSettings.java      |  2 ++
 .../compiler/config/ICompilerSettingsConstants.java    |  1 +
 .../royale/compiler/constants/IASWarningConstants.java |  5 +++++
 .../internal/config/CompilerProblemSettings.java       |  3 +++
 .../compiler/internal/config/ICompilerSettings.java    |  7 +++++++
 .../compiler/problems/ThisUsedInClosureProblem.java    |  2 ++
 9 files changed, 47 insertions(+)

diff --git 
a/compiler-common/src/main/java/org/apache/royale/compiler/clients/problems/ProblemSettingsFilter.java
 
b/compiler-common/src/main/java/org/apache/royale/compiler/clients/problems/ProblemSettingsFilter.java
index 8f857c6..2930c7f 100644
--- 
a/compiler-common/src/main/java/org/apache/royale/compiler/clients/problems/ProblemSettingsFilter.java
+++ 
b/compiler-common/src/main/java/org/apache/royale/compiler/clients/problems/ProblemSettingsFilter.java
@@ -41,6 +41,7 @@ import 
org.apache.royale.compiler.problems.OverlappingSourcePathProblem;
 import org.apache.royale.compiler.problems.ScopedToDefaultNamespaceProblem;
 import org.apache.royale.compiler.problems.SemanticWarningProblem;
 import org.apache.royale.compiler.problems.StrictSemanticsProblem;
+import org.apache.royale.compiler.problems.ThisUsedInClosureProblem;
 import org.apache.royale.compiler.problems.VariableHasNoTypeDeclarationProblem;
 
 /**
@@ -65,6 +66,7 @@ import 
org.apache.royale.compiler.problems.VariableHasNoTypeDeclarationProblem;
  * -warn-instanceof-changes
  * -warn-missing-namespace-decl
  * -warn-no-type-decl
+ * -warn-this-within-closure
  * 
  */
 public class ProblemSettingsFilter implements IProblemFilter
@@ -186,6 +188,8 @@ public class ProblemSettingsFilter implements IProblemFilter
                 ICompilerSettings.WARN_MISSING_NAMESPACE_DECL);
         setShowActionScriptWarning(VariableHasNoTypeDeclarationProblem.class, 
                 ICompilerSettings.WARN_NO_TYPE_DECL);
+        setShowActionScriptWarning(ThisUsedInClosureProblem.class, 
+                ICompilerSettings.WARN_THIS_WITHIN_CLOSURE);
     }
 
     /**
diff --git 
a/compiler-common/src/main/java/org/apache/royale/compiler/config/Configuration.java
 
b/compiler-common/src/main/java/org/apache/royale/compiler/config/Configuration.java
index c1d2ada..3817b3e 100644
--- 
a/compiler-common/src/main/java/org/apache/royale/compiler/config/Configuration.java
+++ 
b/compiler-common/src/main/java/org/apache/royale/compiler/config/Configuration.java
@@ -4053,6 +4053,24 @@ public class Configuration
     }
 
     //
+    // 'compiler.warn-this-within-closure' option
+    //
+
+    private boolean warn_this_within_closure = true;
+
+    public boolean warn_this_within_closure()
+    {
+        return warn_this_within_closure;
+    }
+
+    @Config(advanced = true)
+    @Mapping({ "compiler", "warn-this-within-closure" })
+    public void setCompilerWarnThisWithinClosure(ConfigurationValue cv, 
boolean b)
+    {
+        warn_this_within_closure = b;
+    }
+
+    //
     // compiler.generate-abstract-syntax-tree
     //
 
diff --git 
a/compiler-common/src/main/java/org/apache/royale/compiler/config/Configurator.java
 
b/compiler-common/src/main/java/org/apache/royale/compiler/config/Configurator.java
index 065f7b1..bb90ae6 100644
--- 
a/compiler-common/src/main/java/org/apache/royale/compiler/config/Configurator.java
+++ 
b/compiler-common/src/main/java/org/apache/royale/compiler/config/Configurator.java
@@ -2300,6 +2300,7 @@ public class Configurator implements ICompilerSettings, 
IConfigurator, ICompiler
      * --compiler.warn-slow-text-field-addition
      * --compiler.warn-unlikely-function-value
      * --compiler.warn-xml-class-has-changed
+     * --compiler.warn-this-within-closure
      * </pre>
      * 
      * @param warningCode warning code
@@ -2340,6 +2341,7 @@ public class Configurator implements ICompilerSettings, 
IConfigurator, ICompiler
      * @see #WARN_SLOW_TEXTFIELD_ADDITION
      * @see #WARN_UNLIKELY_FUNCTION_VALUE
      * @see #WARN_XML_CLASS_HAS_CHANGED
+     * @see #WARN_THIS_WITHIN_CLOSURE
      */
     @Override
     public void checkActionScriptWarning(int warningCode, boolean b)
@@ -2456,6 +2458,9 @@ public class Configurator implements ICompilerSettings, 
IConfigurator, ICompiler
         case WARN_XML_CLASS_HAS_CHANGED:
             key = COMPILER_WARN_XML_CLASS_HAS_CHANGED;
             break;
+        case WARN_THIS_WITHIN_CLOSURE:
+            key = COMPILER_WARN_THIS_WITHIN_CLOSURE;
+            break;
         }
         
         if (key != null)
diff --git 
a/compiler-common/src/main/java/org/apache/royale/compiler/config/ICompilerProblemSettings.java
 
b/compiler-common/src/main/java/org/apache/royale/compiler/config/ICompilerProblemSettings.java
index 355987e..9e0ed7c 100644
--- 
a/compiler-common/src/main/java/org/apache/royale/compiler/config/ICompilerProblemSettings.java
+++ 
b/compiler-common/src/main/java/org/apache/royale/compiler/config/ICompilerProblemSettings.java
@@ -157,6 +157,7 @@ public interface ICompilerProblemSettings
       * --compiler.warn-slow-text-field-addition
       * --compiler.warn-unlikely-function-value
       * --compiler.warn-xml-class-has-changed
+      * --compiler.warn-this-within-closure
       * </pre>
       * 
       * @param warningCode warning code, one of:
@@ -198,6 +199,7 @@ public interface ICompilerProblemSettings
       * <li> WARN_SLOW_TEXTFIELD_ADDITION
       * <li> WARN_UNLIKELY_FUNCTION_VALUE
       * <li> WARN_XML_CLASS_HAS_CHANGED
+      * <li> WARN_THIS_WITHIN_CLOSURE
       * </ul>
       * </p>
       */
diff --git 
a/compiler-common/src/main/java/org/apache/royale/compiler/config/ICompilerSettingsConstants.java
 
b/compiler-common/src/main/java/org/apache/royale/compiler/config/ICompilerSettingsConstants.java
index 71a39ec..3dd99ce 100644
--- 
a/compiler-common/src/main/java/org/apache/royale/compiler/config/ICompilerSettingsConstants.java
+++ 
b/compiler-common/src/main/java/org/apache/royale/compiler/config/ICompilerSettingsConstants.java
@@ -51,6 +51,7 @@ public interface ICompilerSettingsConstants
     static final String DEFAULT_BACKGROUND_COLOR                             = 
"--default-background-color";
     static final String DEBUG_PASSWORD                                       = 
"--debug-password";
     static final String SWF_VERSION                                          = 
"--swf-version";
+    static final String COMPILER_WARN_THIS_WITHIN_CLOSURE                    = 
"--compiler.warn-this-within-closure";
     static final String COMPILER_WARN_XML_CLASS_HAS_CHANGED                  = 
"--compiler.warn-xml-class-has-changed";
     static final String COMPILER_WARN_UNLIKELY_FUNCTION_VALUE                = 
"--compiler.warn-unlikely-function-value";
     static final String COMPILER_WARN_SLOW_TEXT_FIELD_ADDITION               = 
"--compiler.warn-slow-text-field-addition";
diff --git 
a/compiler-common/src/main/java/org/apache/royale/compiler/constants/IASWarningConstants.java
 
b/compiler-common/src/main/java/org/apache/royale/compiler/constants/IASWarningConstants.java
index 99db8ef..2b6b337 100644
--- 
a/compiler-common/src/main/java/org/apache/royale/compiler/constants/IASWarningConstants.java
+++ 
b/compiler-common/src/main/java/org/apache/royale/compiler/constants/IASWarningConstants.java
@@ -209,4 +209,9 @@ public interface IASWarningConstants
      * Possible usage of the ActionScript 2.0 <code>XML</code> class.
      */
     static final int XML_CLASS_HAS_CHANGED = 3573;
+
+    /**
+     * Keyword this within closure.
+     */
+    static final int THIS_WITHIN_CLOSURE = 20000;
 }
diff --git 
a/compiler-common/src/main/java/org/apache/royale/compiler/internal/config/CompilerProblemSettings.java
 
b/compiler-common/src/main/java/org/apache/royale/compiler/internal/config/CompilerProblemSettings.java
index 868293f..3bdc442 100644
--- 
a/compiler-common/src/main/java/org/apache/royale/compiler/internal/config/CompilerProblemSettings.java
+++ 
b/compiler-common/src/main/java/org/apache/royale/compiler/internal/config/CompilerProblemSettings.java
@@ -213,6 +213,9 @@ public class CompilerProblemSettings implements 
ICompilerProblemSettings
         case ICompilerSettings.WARN_XML_CLASS_HAS_CHANGED:
             warning = configuration.warn_xml_class_has_changed();
             break;
+        case ICompilerSettings.WARN_THIS_WITHIN_CLOSURE:
+            warning = configuration.warn_this_within_closure();
+            break;
         }
         
         return warning;
diff --git 
a/compiler-common/src/main/java/org/apache/royale/compiler/internal/config/ICompilerSettings.java
 
b/compiler-common/src/main/java/org/apache/royale/compiler/internal/config/ICompilerSettings.java
index 4bc7e75..054de47 100644
--- 
a/compiler-common/src/main/java/org/apache/royale/compiler/internal/config/ICompilerSettings.java
+++ 
b/compiler-common/src/main/java/org/apache/royale/compiler/internal/config/ICompilerSettings.java
@@ -547,6 +547,11 @@ public interface ICompilerSettings extends 
IWriteOnlyProjectSettings
      * Possible usage of the ActionScript 2.0 <code>XML</code> class.
      */
     int WARN_XML_CLASS_HAS_CHANGED = IASWarningConstants.XML_CLASS_HAS_CHANGED;
+
+    /**
+     * Keyword this within closure.
+     */
+    int WARN_THIS_WITHIN_CLOSURE = IASWarningConstants.THIS_WITHIN_CLOSURE;
      
     /**
      * Enables checking of the following ActionScript warnings:
@@ -588,6 +593,7 @@ public interface ICompilerSettings extends 
IWriteOnlyProjectSettings
      * --compiler.warn-slow-text-field-addition
      * --compiler.warn-unlikely-function-value
      * --compiler.warn-xml-class-has-changed
+     * --compiler.warn-this-within-closure
      * </pre>
      * 
      * @param warningCode Warning code.
@@ -629,6 +635,7 @@ public interface ICompilerSettings extends 
IWriteOnlyProjectSettings
      * @see #WARN_SLOW_TEXTFIELD_ADDITION
      * @see #WARN_UNLIKELY_FUNCTION_VALUE
      * @see #WARN_XML_CLASS_HAS_CHANGED
+     * @see #WARN_THIS_WITHIN_CLOSURE
      */
     void checkActionScriptWarning(int warningCode, boolean b);
 
diff --git 
a/compiler/src/main/java/org/apache/royale/compiler/problems/ThisUsedInClosureProblem.java
 
b/compiler-common/src/main/java/org/apache/royale/compiler/problems/ThisUsedInClosureProblem.java
similarity index 96%
rename from 
compiler/src/main/java/org/apache/royale/compiler/problems/ThisUsedInClosureProblem.java
rename to 
compiler-common/src/main/java/org/apache/royale/compiler/problems/ThisUsedInClosureProblem.java
index 8a2dc28..28ef5df 100644
--- 
a/compiler/src/main/java/org/apache/royale/compiler/problems/ThisUsedInClosureProblem.java
+++ 
b/compiler-common/src/main/java/org/apache/royale/compiler/problems/ThisUsedInClosureProblem.java
@@ -29,6 +29,8 @@ public final class ThisUsedInClosureProblem extends 
SemanticWarningProblem
 {
     public static final String DESCRIPTION =
         "Encountered ${THIS} keyword within closure. Value of ${THIS} will not 
be the same as enclosing scope.";
+    
+    public static final int warningCode = 20000;
 
     public ThisUsedInClosureProblem(IASNode site)
     {

Reply via email to