You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by jo...@apache.org on 2016/09/29 20:18:30 UTC
[1/2] git commit: [flex-falcon] [refs/heads/develop] - import Alias =
com.example.ClassToImport
Repository: flex-falcon
Updated Branches:
refs/heads/develop 35c5ab2b2 -> e9a7ccfbd
import Alias = com.example.ClassToImport
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/9189c0f9
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/9189c0f9
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/9189c0f9
Branch: refs/heads/develop
Commit: 9189c0f99b94b6e39af381d54f1b197c4aed0ce6
Parents: 1dabb68
Author: Josh Tynjala <jo...@gmail.com>
Authored: Fri Sep 23 17:12:50 2016 -0700
Committer: Josh Tynjala <jo...@gmail.com>
Committed: Mon Sep 26 15:31:22 2016 -0700
----------------------------------------------------------------------
.../compiler/internal/parsing/as/ASParser.g | 11 +-
.../flex/compiler/internal/scopes/ASScope.java | 123 ++++++++++++++++++-
.../compiler/internal/tree/as/ImportNode.java | 42 ++++++-
.../problems/DuplicateImportAliasProblem.java | 42 +++++++
.../flex/compiler/tree/as/IImportNode.java | 7 ++
5 files changed, 221 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/9189c0f9/compiler/src/main/antlr/org/apache/flex/compiler/internal/parsing/as/ASParser.g
----------------------------------------------------------------------
diff --git a/compiler/src/main/antlr/org/apache/flex/compiler/internal/parsing/as/ASParser.g b/compiler/src/main/antlr/org/apache/flex/compiler/internal/parsing/as/ASParser.g
index e5af0f9..20afd5c 100644
--- a/compiler/src/main/antlr/org/apache/flex/compiler/internal/parsing/as/ASParser.g
+++ b/compiler/src/main/antlr/org/apache/flex/compiler/internal/parsing/as/ASParser.g
@@ -472,6 +472,7 @@ importDirective[ContainerNode c]
{
ExpressionNodeBase n = null;
ImportNode i = null;
+ IIdentifierNode alias = null;
}
: importT:TOKEN_KEYWORD_IMPORT
{
@@ -479,11 +480,19 @@ importDirective[ContainerNode c]
i.startBefore(importT);
i.endAfter(importT);
c.addItem(i);
+ if (LA(2) == TOKEN_OPERATOR_ASSIGNMENT)
+ {
+ alias = identifier();
+ match(TOKEN_OPERATOR_ASSIGNMENT);
+ }
}
-
+
n=importName
{
if(n != null) {
+ if(alias != null) {
+ i.setImportAlias(alias.getName());
+ }
i.setImportTarget(n);
i.setEnd(n.getEnd());
encounteredImport(i);
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/9189c0f9/compiler/src/main/java/org/apache/flex/compiler/internal/scopes/ASScope.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/internal/scopes/ASScope.java b/compiler/src/main/java/org/apache/flex/compiler/internal/scopes/ASScope.java
index 953f14b..904c547 100644
--- a/compiler/src/main/java/org/apache/flex/compiler/internal/scopes/ASScope.java
+++ b/compiler/src/main/java/org/apache/flex/compiler/internal/scopes/ASScope.java
@@ -48,8 +48,10 @@ import org.apache.flex.compiler.internal.definitions.InterfaceDefinition;
import org.apache.flex.compiler.internal.definitions.NamespaceDefinition;
import org.apache.flex.compiler.internal.definitions.ScopedDefinitionBase;
import org.apache.flex.compiler.internal.projects.CompilerProject;
+import org.apache.flex.compiler.internal.tree.as.FileNode;
import org.apache.flex.compiler.internal.tree.as.ScopedBlockNode;
import org.apache.flex.compiler.internal.workspaces.Workspace;
+import org.apache.flex.compiler.problems.DuplicateImportAliasProblem;
import org.apache.flex.compiler.projects.ICompilerProject;
import org.apache.flex.compiler.scopes.IDefinitionSet;
import org.apache.flex.compiler.tree.as.IScopedNode;
@@ -108,6 +110,11 @@ public abstract class ASScope extends ASScopeBase
*/
private Object importsInScope = null;
+ /**
+ * List of all aliases for imports in scope
+ */
+ private Map<String, String> aliasToImportQualifiedName = null;
+
private Set<String> packageNames = null;
private Object usedNamespaces = null;
@@ -170,6 +177,23 @@ public abstract class ASScope extends ASScopeBase
CheapArray.add(useDirective, usedNamespaces);
}
+ public boolean hasImportAlias(String alias)
+ {
+ return aliasToImportQualifiedName != null
+ && aliasToImportQualifiedName.containsKey(alias);
+ }
+
+ public void addImport(String target, String alias)
+ {
+ if (aliasToImportQualifiedName == null)
+ {
+ aliasToImportQualifiedName = new HashMap<String, String>();
+ }
+ assert !hasImportAlias(alias) : "addImport() should not be called with an existing alias";
+ addImport(target);
+ aliasToImportQualifiedName.put(alias, target);
+ }
+
public void addImport(String target)
{
if (importsInScope == null)
@@ -408,6 +432,8 @@ public abstract class ASScope extends ASScopeBase
*/
public Set<INamespaceDefinition> getNamespaceSetForName(ICompilerProject project, String name)
{
+ // if the name is an alias, we want the original name -JT
+ name = resolveBaseNameFromAlias(name);
if (namespaceSetSameAsContainingScopeNamespaceSet() && getContainingScope() != null)
{
// If this scope doesn't contribute anything to the namespace set, then just ask our containing
@@ -900,6 +926,63 @@ public abstract class ASScope extends ASScopeBase
getLocalProperty(project, defs, baseName, true);
}
+ protected String resolveBaseNameFromAlias(String possibleAlias)
+ {
+ if (aliasToImportQualifiedName != null
+ && aliasToImportQualifiedName.containsKey(possibleAlias))
+ {
+ String qualifiedName = aliasToImportQualifiedName.get(possibleAlias);
+ int index = qualifiedName.lastIndexOf(".");
+ if (index != -1)
+ {
+ return qualifiedName.substring(index + 1);
+ }
+ return qualifiedName;
+ }
+ ASScope containingScope = getContainingScope();
+ if (containingScope != null)
+ {
+ return containingScope.resolveBaseNameFromAlias(possibleAlias);
+ }
+ return possibleAlias;
+ }
+
+ protected String resolveAliasFromQualifiedImport(String qualifiedName)
+ {
+ if (aliasToImportQualifiedName != null
+ && aliasToImportQualifiedName.containsValue(qualifiedName))
+ {
+ for (String key : aliasToImportQualifiedName.keySet())
+ {
+ if (aliasToImportQualifiedName.get(key).equals(qualifiedName))
+ {
+ return key;
+ }
+ }
+ }
+ ASScope containingScope = getContainingScope();
+ if (containingScope != null)
+ {
+ return containingScope.resolveAliasFromQualifiedImport(qualifiedName);
+ }
+ return null;
+ }
+
+ protected String resolveQualifiedNameFromAlias(String possibleAlias)
+ {
+ if (aliasToImportQualifiedName != null
+ && aliasToImportQualifiedName.containsKey(possibleAlias))
+ {
+ return aliasToImportQualifiedName.get(possibleAlias);
+ }
+ ASScope containingScope = getContainingScope();
+ if (containingScope != null)
+ {
+ return containingScope.resolveQualifiedNameFromAlias(possibleAlias);
+ }
+ return possibleAlias;
+ }
+
/**
* This is called by {@link ASScopeCache} when there was a cache miss.
*
@@ -1026,6 +1109,7 @@ public abstract class ASScope extends ASScopeBase
// This loop may go as far as the file scope, whose containing scope is null.
// But it may break out early; lastSearchScope will keep track of how far it went.
ASScope lastSearchedScope = null;
+ String baseNameForAlias = this.resolveBaseNameFromAlias(baseName);
for (ASScope currentScope = this; currentScope != null; currentScope = currentScope.getContainingScope())
{
// If we're not looking for all matching definitions,
@@ -1034,7 +1118,7 @@ public abstract class ASScope extends ASScopeBase
break;
// Search one scope for any definitions matching baseName and naamespaceSet.
- currentScope.getPropertyForScopeChain(project, accumulator, baseName, nsPred, findAll);
+ currentScope.getPropertyForScopeChain(project, accumulator, baseNameForAlias, nsPred, findAll);
// Keep track of the last scope that was searched.
lastSearchedScope = currentScope;
@@ -1069,7 +1153,42 @@ public abstract class ASScope extends ASScopeBase
if (searchProjectScope)
{
ASProjectScope projectScope = project.getScope();
- projectScope.getPropertyForScopeChain(this, accumulator, baseName, nsPred.getNamespaceSet(), dt);
+ projectScope.getPropertyForScopeChain(this, accumulator, baseNameForAlias, nsPred.getNamespaceSet(), dt);
+ }
+ if(!baseName.equals(baseNameForAlias)) // has alias
+ {
+ // remove anything with the same base name that doesn't have an
+ // alias, unless its base name is equal to the alias. that is the
+ // only time where there will be ambiguity. -JT
+ String alias = baseName; //for clarity
+ ArrayList<IDefinition> toRemove = new ArrayList<IDefinition>();
+ String qualifiedNameForAlias = resolveQualifiedNameFromAlias(alias);
+ for(IDefinition definition : accumulator)
+ {
+ if(!definition.getBaseName().equals(alias)
+ && !definition.getQualifiedName().equals(qualifiedNameForAlias))
+ {
+ toRemove.add(definition);
+ }
+ }
+ // some collections can't remove while iterating, so do it after
+ // collecting all of the definitions to remove -JT
+ accumulator.removeAll(toRemove);
+ }
+ else // no alias
+ {
+ // remove anything that has an alias, unless its alias is equal to
+ // the original base name.
+ ArrayList<IDefinition> toRemove = new ArrayList<IDefinition>();
+ for (IDefinition definition : accumulator)
+ {
+ String otherAlias = resolveAliasFromQualifiedImport(definition.getQualifiedName());
+ if (otherAlias != null && !otherAlias.equals(baseName))
+ {
+ toRemove.add(definition);
+ }
+ }
+ accumulator.removeAll(toRemove);
}
}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/9189c0f9/compiler/src/main/java/org/apache/flex/compiler/internal/tree/as/ImportNode.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/internal/tree/as/ImportNode.java b/compiler/src/main/java/org/apache/flex/compiler/internal/tree/as/ImportNode.java
index 0002474..709e54a 100644
--- a/compiler/src/main/java/org/apache/flex/compiler/internal/tree/as/ImportNode.java
+++ b/compiler/src/main/java/org/apache/flex/compiler/internal/tree/as/ImportNode.java
@@ -34,7 +34,9 @@ import org.apache.flex.compiler.internal.parsing.as.ASTokenTypes;
import org.apache.flex.compiler.internal.scopes.ASScope;
import org.apache.flex.compiler.internal.semantics.PostProcessStep;
import org.apache.flex.compiler.parsing.IASToken;
+import org.apache.flex.compiler.problems.DuplicateImportAliasProblem;
import org.apache.flex.compiler.problems.ICompilerProblem;
+import org.apache.flex.compiler.problems.UnknownImportProblem;
import org.apache.flex.compiler.projects.ICompilerProject;
import org.apache.flex.compiler.tree.ASTNodeID;
import org.apache.flex.compiler.tree.as.IASNode;
@@ -98,6 +100,8 @@ public class ImportNode extends FixedChildrenNode implements IImportNode
protected ImportKind importKind;
+ protected String importAlias;
+
//
// NodeBase overrides
//
@@ -145,7 +149,25 @@ public class ImportNode extends FixedChildrenNode implements IImportNode
protected void analyze(EnumSet<PostProcessStep> set, ASScope scope, Collection<ICompilerProblem> problems)
{
if (set.contains(PostProcessStep.POPULATE_SCOPE))
- scope.addImport(this.getImportName());
+ {
+ if (importAlias != null)
+ {
+ if (scope.hasImportAlias(importAlias))
+ {
+ //we can't have duplicates, or it will be ambiguous -JT
+ FileNode fileNode = (FileNode) getAncestorOfType(FileNode.class);
+ fileNode.addProblem(new DuplicateImportAliasProblem(this, this.getImportAlias()));
+ }
+ else
+ {
+ scope.addImport(this.getImportName(), this.getImportAlias());
+ }
+ }
+ else
+ {
+ scope.addImport(this.getImportName());
+ }
+ }
}
/*
@@ -237,4 +259,22 @@ public class ImportNode extends FixedChildrenNode implements IImportNode
{
this.targetImportNode = targetImportNode;
}
+
+ /**
+ * Gets the optional alias of the import.
+ */
+ public String getImportAlias()
+ {
+ return this.importAlias;
+ }
+
+ /**
+ * Sets the optional alias of the import.
+ *
+ * @param importAlias The alias of the import.
+ */
+ public void setImportAlias(String importAlias)
+ {
+ this.importAlias = importAlias;
+ }
}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/9189c0f9/compiler/src/main/java/org/apache/flex/compiler/problems/DuplicateImportAliasProblem.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/problems/DuplicateImportAliasProblem.java b/compiler/src/main/java/org/apache/flex/compiler/problems/DuplicateImportAliasProblem.java
new file mode 100644
index 0000000..881c709
--- /dev/null
+++ b/compiler/src/main/java/org/apache/flex/compiler/problems/DuplicateImportAliasProblem.java
@@ -0,0 +1,42 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.problems;
+
+import org.apache.flex.compiler.tree.as.IASNode;
+
+/**
+ * Diagnostic emitted when semantic analysis detects
+ * a duplicate import alias.
+ */
+public final class DuplicateImportAliasProblem extends SemanticProblem
+{
+ public static final String DESCRIPTION =
+ "Duplicate import alias: ${importAlias}.";
+
+ public static final int errorCode = 9999;
+ public DuplicateImportAliasProblem(IASNode site, String importAlias)
+ {
+ super(site);
+ this.importAlias = importAlias;
+ }
+
+ public final String importAlias;
+}
+
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/9189c0f9/compiler/src/main/java/org/apache/flex/compiler/tree/as/IImportNode.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/tree/as/IImportNode.java b/compiler/src/main/java/org/apache/flex/compiler/tree/as/IImportNode.java
index 5441e63..d001155 100644
--- a/compiler/src/main/java/org/apache/flex/compiler/tree/as/IImportNode.java
+++ b/compiler/src/main/java/org/apache/flex/compiler/tree/as/IImportNode.java
@@ -96,6 +96,13 @@ public interface IImportNode extends IASNode
IImportTarget getImportTarget();
/**
+ * Returns the alias for this import, if one exists
+ *
+ * @return an alias or null
+ */
+ String getImportAlias();
+
+ /**
* Returns whether an import statement is a wildcard import or not
*
* @return true if a wildcard import
[2/2] git commit: [flex-falcon] [refs/heads/develop] - Merge branch
'develop' into rename-import
Posted by jo...@apache.org.
Merge branch 'develop' into rename-import
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/e9a7ccfb
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/e9a7ccfb
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/e9a7ccfb
Branch: refs/heads/develop
Commit: e9a7ccfbdc15814a858fcbebf0a6112f3f99d922
Parents: 9189c0f 35c5ab2
Author: Josh Tynjala <jo...@gmail.com>
Authored: Thu Sep 29 13:18:09 2016 -0700
Committer: Josh Tynjala <jo...@gmail.com>
Committed: Thu Sep 29 13:18:09 2016 -0700
----------------------------------------------------------------------
Jenkinsfile | 32 +-
.../internal/codegen/js/JSSessionModel.java | 11 +-
.../codegen/js/flexjs/JSFlexJSEmitter.java | 76 +-
.../js/flexjs/JSFlexJSEmitterTokens.java | 5 +
.../codegen/js/goog/JSGoogDocEmitter.java | 7 +
.../internal/codegen/js/jx/AccessorEmitter.java | 431 ++++++-----
.../codegen/js/jx/BinaryOperatorEmitter.java | 23 +-
.../internal/codegen/js/jx/FieldEmitter.java | 26 +-
.../codegen/js/jx/MemberAccessEmitter.java | 14 +-
.../codegen/js/jx/PackageFooterEmitter.java | 760 +++++++++++++------
.../codegen/js/jx/SuperCallEmitter.java | 18 +-
.../codegen/mxml/flexjs/MXMLFlexJSEmitter.java | 210 ++++-
.../mxml/flexjs/MXMLFlexJSPublisher.java | 77 +-
.../js/flexjs/JSCSSCompilationSession.java | 20 +-
.../driver/js/goog/JSGoogConfiguration.java | 46 ++
.../internal/projects/FlexJSProject.java | 24 +
.../apache/flex/compiler/utils/NativeUtils.java | 2 +
.../js/flexjs/TestFlexJSAccessorMembers.java | 48 +-
.../codegen/js/flexjs/TestFlexJSAccessors.java | 29 +-
.../codegen/js/flexjs/TestFlexJSClass.java | 27 +-
.../codegen/js/flexjs/TestFlexJSEmitter.java | 132 ++--
.../js/flexjs/TestFlexJSExpressions.java | 10 +-
.../js/flexjs/TestFlexJSFieldMembers.java | 20 +-
.../js/flexjs/TestFlexJSMethodMembers.java | 2 +-
.../codegen/js/flexjs/TestFlexJSPackage.java | 262 +++----
.../codegen/js/flexjs/TestFlexJSProject.java | 3 +-
.../codegen/js/flexjs/TestFlexJSStatements.java | 17 +-
.../codegen/js/goog/TestGoogProject.java | 5 +-
.../codegen/js/vf2js/TestVF2JSClass.java | 2 +-
.../mxml/flexjs/TestFlexJSMXMLApplication.java | 46 +-
.../mxml/flexjs/TestFlexJSMXMLScript.java | 88 +--
.../flex/compiler/internal/test/TestBase.java | 4 +
.../flexjs/files/FlexJSTest_again_result.js | 80 +-
.../flexjs/files/LocalFunction_result.js | 12 +-
.../flexjs/files/MyInitialView_result.js | 150 ++--
.../files/controllers/MyController_result.js | 16 +-
.../flexjs/files/models/MyModel_result.js | 51 +-
.../flexjs/files/wildcard_import_result.js | 33 +-
.../projects/bad_overrides/Test_result.js | 12 +-
.../projects/bad_overrides/classes/A_result.js | 18 +-
.../projects/bad_overrides/classes/B_result.js | 12 +-
.../projects/bad_overrides/classes/C_result.js | 12 +-
.../bad_overrides/interfaces/IA_result.js | 23 +-
.../bad_overrides/interfaces/IB_result.js | 22 +-
.../bad_overrides/interfaces/IC_result.js | 22 +-
.../flexjs/projects/circular/Base_result.js | 12 +-
.../flexjs/projects/circular/Super_result.js | 12 +-
.../flexjs/projects/interfaces/Test_result.js | 14 +-
.../projects/interfaces/classes/A_result.js | 12 +-
.../projects/interfaces/classes/B_result.js | 12 +-
.../projects/interfaces/classes/C_result.js | 12 +-
.../projects/interfaces/interfaces/IA_result.js | 22 +-
.../projects/interfaces/interfaces/IB_result.js | 2 +-
.../projects/interfaces/interfaces/IC_result.js | 22 +-
.../projects/interfaces/interfaces/ID_result.js | 22 +-
.../projects/interfaces/interfaces/IE_result.js | 14 +-
.../projects/internal/MainClass_result.js | 19 +-
.../projects/internal/OtherClass_result.js | 12 +-
.../flexjs/projects/overrides/Test_result.js | 18 +-
.../projects/overrides/classes/A_result.js | 18 +-
.../projects/overrides/classes/B_result.js | 12 +-
.../projects/overrides/classes/C_result.js | 12 +-
.../projects/overrides/interfaces/IA_result.js | 23 +-
.../projects/overrides/interfaces/IB_result.js | 22 +-
.../projects/overrides/interfaces/IC_result.js | 22 +-
.../AmbiguousDefinition_result.js | 2 +-
.../Event_result.js | 2 +-
.../DifferentPackageAsConflict_result.js | 12 +-
.../Event_result.js | 12 +-
.../mypackage/TestClass_result.js | 12 +-
.../otherpackage/Event_result.js | 12 +-
.../Event_result.js | 12 +-
.../NoConflictNoWindow_result.js | 12 +-
.../mypackage/TestClass_result.js | 12 +-
.../Event_result.js | 12 +-
.../NoConflictUseWindow_result.js | 12 +-
.../mypackage/TestClass_result.js | 12 +-
.../Event_result.js | 12 +-
.../SamePackageAsConflict_result.js | 12 +-
.../mypackage/Event_result.js | 12 +-
.../mypackage/TestClass_result.js | 12 +-
.../Event_result.js | 12 +-
.../UseWindow_result.js | 12 +-
.../mypackage/TestClass_result.js | 12 +-
.../otherpackage/Event_result.js | 12 +-
.../flexjs/projects/super/Base_result.js | 32 +-
.../flexjs/projects/super/Super_result.js | 29 +-
.../projects/xml_requires/XMLRequire_result.js | 12 +-
.../as/codegen/GlobalDirectiveProcessor.java | 6 +
.../semantics/MethodBodySemanticChecker.java | 7 +-
.../src/test/java/as/ASInheritanceTests.java | 87 +++
pom.xml | 11 +-
src/site/asciidoc/featurebranch-autobuild.adoc | 45 ++
.../featurebranch-autobuild-branch-overview.png | Bin 0 -> 309602 bytes
.../featurebranch-autobuild-overview.png | Bin 0 -> 121026 bytes
src/site/site.xml | 5 +-
96 files changed, 2107 insertions(+), 1601 deletions(-)
----------------------------------------------------------------------