You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2019/01/16 20:07:44 UTC

[royale-compiler] branch develop updated: compiler: added allow-import-aliases command line option

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


The following commit(s) were added to refs/heads/develop by this push:
     new 9d4e101  compiler: added allow-import-aliases command line option
9d4e101 is described below

commit 9d4e10187db5c73645b9b5a150d027869a41a4a8
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Jan 16 12:03:09 2019 -0800

    compiler: added allow-import-aliases command line option
    
    I previously added support for import aliases to the ActionScript parser. However, they were always enabled, even when using the Royale compiler for IDE code intelligence with a different SDK that doesn't support them. To ensure that an appropriate syntax error will appear for other SDKs, and to ensure that new syntax is opt-in, import aliases are disabled by default, and can be enabled by using this new option.
---
 .../royale/compiler/config/Configuration.java      | 23 ++++++++++++++++++++++
 .../royale/compiler/projects/ICompilerProject.java |  7 ++++++-
 .../internal/parsing/as/ConfigProcessor.java       |  6 ++++++
 .../compiler/internal/projects/ASCProject.java     |  6 ++++++
 .../compiler/internal/projects/RoyaleProject.java  | 15 ++++++++++++++
 .../projects/RoyaleProjectConfigurator.java        |  2 ++
 .../semantics/MethodBodySemanticChecker.java       |  7 +++++++
 7 files changed, 65 insertions(+), 1 deletion(-)

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 85f779f..5f8a3e0 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
@@ -1485,6 +1485,29 @@ public class Configuration
     }
 
     //
+    // 'compiler.allow-import-aliases' option
+    //
+
+    private boolean allowImportAliases = false;
+
+    public boolean getCompilerAllowImportAliases()
+    {
+        return allowImportAliases;
+    }
+
+    /**
+     * Whether the compiler will allow imports to include an optional alias for
+     * the definition name.
+     */
+    @Config
+    @Mapping({ "compiler", "allow-import-aliases" })
+    @RoyaleOnly
+    public void setCompilerAllowImportAliases(ConfigurationValue cv, boolean allow)
+    {
+        this.allowImportAliases = allow;
+    }
+
+    //
     // 'compiler.actionscript-file-encoding' option
     //
 
diff --git a/compiler-common/src/main/java/org/apache/royale/compiler/projects/ICompilerProject.java b/compiler-common/src/main/java/org/apache/royale/compiler/projects/ICompilerProject.java
index 332576a..b3eea14 100644
--- a/compiler-common/src/main/java/org/apache/royale/compiler/projects/ICompilerProject.java
+++ b/compiler-common/src/main/java/org/apache/royale/compiler/projects/ICompilerProject.java
@@ -265,6 +265,11 @@ public interface ICompilerProject
     /**
      * @return True if a subclass can have a private API with the same name as a private API in its base classes.
      */
-	boolean getAllowPrivateNameConflicts();
+     boolean getAllowPrivateNameConflicts();
+     
+    /**
+     * @return True if import aliases are allowed.
+     */
+     boolean getAllowImportAliases();
 
 }
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/ConfigProcessor.java b/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/ConfigProcessor.java
index ce540d6..1cf7922 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/ConfigProcessor.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/ConfigProcessor.java
@@ -158,6 +158,12 @@ public class ConfigProcessor
 			// TODO Auto-generated method stub
 			return false;
 		}
+
+		@Override
+		public boolean getAllowImportAliases() {
+			// TODO Auto-generated method stub
+			return false;
+		}
     }
 
     /**
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/projects/ASCProject.java b/compiler/src/main/java/org/apache/royale/compiler/internal/projects/ASCProject.java
index f6b78fa..d229ca3 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/projects/ASCProject.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/projects/ASCProject.java
@@ -80,4 +80,10 @@ public class ASCProject extends CompilerProject implements IASCProject
 		// TODO Auto-generated method stub
 		return false;
 	}
+
+	@Override
+	public boolean getAllowImportAliases() {
+		// TODO Auto-generated method stub
+		return false;
+	}
 }
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProject.java b/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProject.java
index 14d37b6..6a03191 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProject.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProject.java
@@ -2430,6 +2430,21 @@ public class RoyaleProject extends ASProject implements IRoyaleProject, ICompile
     	allowPrivateNameConflicts = allow;
     }
 
+    private boolean allowImportAliases = false;
+    
+    /**
+     * Indicates if import aliases are allowed.
+     */
+    @Override
+    public boolean getAllowImportAliases()
+    {
+    	return allowImportAliases;
+    }
+    public void setAllowImportAliases(boolean allow)
+    {
+    	allowImportAliases = allow;
+    }
+
 	@Override
 	public boolean isPlatformRule(ICSSRule rule) {
 		return true;
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProjectConfigurator.java b/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProjectConfigurator.java
index df8d4fa..409dfd9 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProjectConfigurator.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProjectConfigurator.java
@@ -262,6 +262,8 @@ public class RoyaleProjectConfigurator extends Configurator
 
             project.setStrictXML(configuration.isStrictXML());
             project.setAllowPrivateNameConflicts(configuration.getCompilerAllowPrivateNameConflicts());
+
+            project.setAllowImportAliases(configuration.getCompilerAllowImportAliases());
             
             DataTranscoder.embedClassName = configuration.getByteArrayEmbedClass();
         }
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/MethodBodySemanticChecker.java b/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/MethodBodySemanticChecker.java
index 5b14145..a0b6785 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/MethodBodySemanticChecker.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/MethodBodySemanticChecker.java
@@ -2241,6 +2241,13 @@ public class MethodBodySemanticChecker
     {
         IASNode site = importNode.getImportNameNode();
         
+        String importAlias = importNode.getImportAlias();
+        if (importAlias != null && !project.getAllowImportAliases())
+        {
+            //import aliases need to be enabled
+            addProblem(new SyntaxProblem(importNode, "="));
+        }
+        
         if (!SemanticUtils.isValidImport(importNode, project, currentScope.getInInvisibleCompilationUnit()))
         {
             String importName = importNode.getImportName();