flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject svn commit: r1413061 [14/14] - in /incubator/flex/falcon/trunk/compiler.js: ./ bin/ build/ in/ intermediates/ localization/ localization/src/ localization/src/org/ localization/src/org/apache/ localization/src/org/apache/flex/ localization/src/org/apac...
Date Fri, 23 Nov 2012 20:58:56 GMT
Added: incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/ASScopeUtils.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/ASScopeUtils.java?rev=1413061&view=auto
==============================================================================
--- incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/ASScopeUtils.java (added)
+++ incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/ASScopeUtils.java Fri Nov 23 20:58:50 2012
@@ -0,0 +1,388 @@
+/*
+ *
+ *  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.internal.legacy;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.flex.compiler.common.ASModifier;
+import org.apache.flex.compiler.common.Multiname;
+import org.apache.flex.compiler.definitions.IDefinition;
+import org.apache.flex.compiler.definitions.INamespaceDefinition;
+import org.apache.flex.compiler.internal.legacy.ASDefinitionFilter.RequireImportsValue;
+import org.apache.flex.compiler.internal.projects.CompilerProject;
+import org.apache.flex.compiler.internal.scopes.ASProjectScope;
+import org.apache.flex.compiler.internal.scopes.ASScope;
+import org.apache.flex.compiler.internal.scopes.ASScopeBase;
+import org.apache.flex.compiler.internal.scopes.ASScopeBase.FilteredCollection;
+import org.apache.flex.compiler.internal.workspaces.Workspace;
+import org.apache.flex.compiler.projects.ICompilerProject;
+import org.apache.flex.compiler.scopes.IASScope;
+
+import com.google.common.base.Predicate;
+
+/**
+ * This class contains static methods that used to be instance methods of an
+ * {@link IASScope}. They now take a new first parameter which is the old
+ * <code>this</code> scope. The methods are no longer part of
+ * <code>IASScope</code> because {@link ASDefinitionFilter} has been removed
+ * from the compiler.
+ */
+public class ASScopeUtils
+{
+    /**
+     * Finds all definitions in the specified scope (and possibly also its
+     * enclosing and inherited scopes, depending on the filter) that meet the
+     * filter criteria.
+     * 
+     * @param thisScope The {@link IASScope} in which the search starts.
+     * @param project The {@link ICompilerProject} to use for resolving
+     * references.
+     * @param filter The {@Link ASDefinitionFilter} that determines the
+     * scope chain and the criteria that the definitions must meet.
+     * @param definitions The list to which the {@link IDefinition} objects are
+     * added.
+     */
+    public static void findAllDefinitions(IASScope thisScope, ICompilerProject project,
+                                          ASDefinitionFilter filter,
+                                          List<IDefinition> definitions)
+    {
+        CompilerProject compilerProject = (CompilerProject)project;
+
+        // Project scopes are a special case.
+        if (thisScope instanceof ASProjectScope)
+        {
+            Set<INamespaceDefinition> namespaceSet = crackFilter(compilerProject, null, filter);
+
+            Predicate<IDefinition> filterPredicate = filter.computePredicate(compilerProject, null);
+            Collection<IDefinition> foundDefinitions = new FilteredCollection<IDefinition>(filterPredicate, definitions);
+
+            ((ASProjectScope)thisScope).getAllProperties(compilerProject, foundDefinitions, namespaceSet);
+            return;
+        }
+
+        // All other scopes use this logic.
+        else
+        {
+            ASScope scope = (ASScope)thisScope;
+
+            Set<INamespaceDefinition> namespaceSet = crackFilter(project, scope, filter);
+
+            Predicate<IDefinition> filterPredicate = filter.computePredicate(project, scope);
+            Collection<IDefinition> foundDefinitions = new FilteredCollection<IDefinition>(filterPredicate, definitions);
+
+            if (filter.searchInheritedScopes() && filter.searchContainingScope())
+            {
+                // The filter wants to look at inherited scopes and containing scopes.
+                // This must be a findprop variant of find all definitions.
+                ASScope currentScope = scope;
+                while (currentScope != null)
+                {
+                    currentScope.getAllPropertiesForScopeChain(compilerProject, foundDefinitions, namespaceSet);
+                    currentScope = currentScope.getContainingScope();
+                }
+
+                if (filter.needsDifferentProjectPredicate())
+                    foundDefinitions = adjustPredicateForProject(scope, project, filter, definitions);
+
+                // Check the project scope.
+                ASProjectScope projectScope = compilerProject.getScope();
+                projectScope.getAllProperties(compilerProject, foundDefinitions, namespaceSet);
+            }
+            else if (filter.searchInheritedScopes())
+            {
+                // The filter wants to look at inherited scopes but not at containing scopes.
+                if (!(filter.requiresModifier(ASModifier.STATIC) || filter.excludesModifier(ASModifier.STATIC)))
+                {
+                    // Find both static and instance properties.
+                    // This is what CodeModel does to try and hint some stuff inside a class.
+                    // It's basically a lexical lookup that stops at the file scope,
+                    // so we use  the scope chain version of lookup.
+                    scope.getAllPropertiesForScopeChain(compilerProject, foundDefinitions, namespaceSet);
+                }
+                else
+                {
+                    // This must be a getprop variant of find all definitions.
+                    scope.getAllPropertiesForMemberAccess(compilerProject, foundDefinitions, namespaceSet);
+                }
+            }
+            else if (filter.searchContainingScope())
+            {
+                // The filter wants to look at lexical scopes, but not at the inherited scopes.
+                // This type of lookup has no meaning in AS3 but CodeModel uses it.
+                boolean requireStatic = filter.requiresModifier(ASModifier.STATIC);
+                boolean excludeStatic = filter.excludesModifier(ASModifier.STATIC);
+                if (!requireStatic || !excludeStatic)
+                {
+                    ASScope currentScope = scope;
+                    while (currentScope != null)
+                    {
+                        currentScope.getAllLocalProperties(compilerProject, foundDefinitions, namespaceSet, null);
+                        currentScope = currentScope.getContainingScope();
+                    }
+                }
+
+                if (filter.needsDifferentProjectPredicate())
+                    foundDefinitions = adjustPredicateForProject(scope, project, filter, definitions);
+
+                // Check the project scope.
+                ASProjectScope projectScope = compilerProject.getScope();
+                projectScope.getAllProperties(compilerProject, foundDefinitions, namespaceSet);
+            }
+            else
+            {
+                // The filter wants to look only at the specified scope
+                // and not any containing or inherited scopes.
+                scope.getAllLocalProperties(compilerProject, foundDefinitions, namespaceSet, null);
+            }
+        }
+    }
+
+    /**
+     * Finds the definitions in the specified scope (and possibly also its
+     * enclosing and inherited scopes, depending on the filter) that have the
+     * specified base name and that meet the filter criteria.
+     * 
+     * @param thisScope The {@link IASScope} in which the search starts.
+     * @param project The {@link ICompilerProject} to use for resolving
+     * references.
+     * @param name The base name of the definitions to be found.
+     * @param filter The {@Link ASDefinitionFilter} that determines the
+     * scope chain and the criteria that the definitions must meet.
+     * @param definitions The list to which the {@link IDefinition} objects are
+     * added.
+     */
+    public static void findAllDefinitionsByName(IASScope thisScope, ICompilerProject project,
+                                                String name, ASDefinitionFilter filter,
+                                                List<IDefinition> definitions)
+    {
+        findDefinitionsByNameImpl(thisScope, project, name, filter, definitions, true);
+    }
+
+    /**
+     * Finds the first definition in the specified scope (and possibly also its
+     * enclosing and inherited scopes, depending on the filter) that has the
+     * specified base name and that meets the filter criteria.
+     * 
+     * @param thisScope The {@link IASScope} in which the search starts.
+     * @param project The {@link ICompilerProject} to use for resolving
+     * references.
+     * @param name The base name of the definition to be found.
+     * @param filter The {@Link ASDefinitionFilter} that determines the
+     * scope chain and the criteria that the definition must meet.
+     * @return definitions The {@link IDefinition}, if one was found, or
+     * <code>null</code>.
+     */
+    public static IDefinition findDefinitionByName(IASScope thisScope, ICompilerProject project,
+                                                   String name, ASDefinitionFilter filter)
+    {
+        List<IDefinition> definitions = new ArrayList<IDefinition>(1);
+        findDefinitionsByNameImpl(thisScope, project, name, filter, definitions, false);
+        return definitions.size() > 0 ? definitions.get(0) : null;
+    }
+
+    private static void findDefinitionsByNameImpl(IASScope thisScope, ICompilerProject project,
+                                                  String name, ASDefinitionFilter filter,
+                                                  List<IDefinition> definitions, boolean findAll)
+    {
+        CompilerProject compilerProject = (CompilerProject)project;
+
+        if (thisScope instanceof ASProjectScope)
+        {
+            Multiname multiName = crackNameAndFilter(project, name, filter);
+            String baseName = multiName.getBaseName();
+            Set<INamespaceDefinition> namespaceSet = multiName.getNamespaceSet();
+
+            Predicate<IDefinition> filterPredicate = filter.computePredicate(project, null);
+            Collection<IDefinition> foundDefinitions = new FilteredCollection<IDefinition>(filterPredicate, definitions);
+
+            ((ASProjectScope)thisScope).getLocalProperty(project, foundDefinitions, baseName, namespaceSet);
+        }
+        else
+        {
+            ASScope scope = (ASScope)thisScope;
+
+            Multiname multiName = crackNameAndFilter(project, name, filter, scope);
+            String baseName = multiName.getBaseName();
+            Set<INamespaceDefinition> namespaceSet = multiName.getNamespaceSet();
+
+            Predicate<IDefinition> predicate = filter.computePredicate(project, scope);
+            Collection<IDefinition> foundDefinitions = new FilteredCollection<IDefinition>(predicate, definitions);
+
+            if (filter.searchInheritedScopes() && filter.searchContainingScope())
+            {
+                // The filter wants to look at inherited scopes and containing scopes,
+                // so this must be a findprop.
+                // TODO If we adjust the ASScope cache to cache ambiguous definition
+                // sets then we can call through to the ASScope cache here, if findAll is false.
+                scope.findProperty(foundDefinitions, compilerProject, baseName, namespaceSet, null, findAll);
+            }
+            else if (filter.searchInheritedScopes())
+            {
+                // The filter wants to look at inherited scopes but not at containing scopes,
+                // so this must be a getprop.
+                scope.getPropertyForMemberAccess(compilerProject, foundDefinitions, baseName, namespaceSet, findAll);
+            }
+            else if (filter.searchContainingScope())
+            {
+                // The filter wants to look at containing scopes but not at inherited scopes.
+                // This type of lookup has no meaning in AS3.
+                ASScope currentScope = scope;
+                while ((currentScope != null) && ((foundDefinitions.size() == 0) || findAll))
+                {
+                    currentScope.getLocalProperty(project, foundDefinitions, baseName, namespaceSet);
+                    currentScope = currentScope.getContainingScope();
+                }
+
+                if ((foundDefinitions.size() == 0) || findAll)
+                {
+                    // Check project scope if we still don't have a definition.
+                    // The project scope can not introduce ambiguities to the
+                    // file scopes's definitions for the purpose of this method.
+                    ASProjectScope projectScope = compilerProject.getScope();
+                    projectScope.getLocalProperty(project, foundDefinitions, baseName, namespaceSet);
+                }
+            }
+            else
+            {
+                // The filter wants to look only at the specified scope
+                // and not any containing or inherited scopes.
+                scope.getLocalProperty(project, foundDefinitions, baseName, namespaceSet);
+            }
+        }
+    }
+
+    /**
+     * Constructs a {@link Multiname} by parsing the specified name string and
+     * extracting information from the specified {@link ASDefinitionFilter}
+     * 
+     * @param project {@link ICompilerProject} whose symbol table is used to
+     * resolve namespace references in the "use namespace" set in the
+     * {@link ASDefnitionFilter}.
+     * @param name Either a simple definition name or a dotted qname.
+     * @param filter
+     * @return A new {@link Multiname} created from information in the specified
+     * name and {@link ASDefinitionFilter}.
+     */
+    private static Multiname crackNameAndFilter(ICompilerProject project, String name, ASDefinitionFilter filter)
+    {
+        return crackNameAndFilter(project, name, filter, null);
+    }
+
+    /**
+     * Constructs a {@link Multiname} by parsing the specified name string and
+     * extracting information from the specified {@link ASDefinitionFilter}
+     * 
+     * @param project {@link ICompilerProject} whose symbol table is used to
+     * resolve namespace references in the "use namespace" set in the
+     * {@link ASDefnitionFilter}.
+     * @param name Either a simple definition name or a dotted qname.
+     * @param filter
+     * @param scope the scope we are doing the lookup in - this is used to
+     * determine if any interface namespaces need to be added to the namespace
+     * set
+     * @return A new {@link Multiname} created from information in the specified
+     * name and {@link ASDefinitionFilter}.
+     */
+    private static Multiname crackNameAndFilter(ICompilerProject project, String name,
+                                                ASDefinitionFilter filter, ASScope scope)
+    {
+        Workspace workspace = (Workspace)project.getWorkspace();
+        if (name != null)
+        {
+            final int lastIndexOfDot = name != null ? name.lastIndexOf('.') : -1;
+            if (lastIndexOfDot != -1)
+            {
+                Set<INamespaceDefinition> namespaceSet = null;
+
+                final String definitionName = name.substring(lastIndexOfDot + 1);
+
+                String packageName = name.substring(0, lastIndexOfDot);
+                INamespaceDefinition publicPackageNS =
+                        workspace.getPackageNamespaceDefinitionCache().get(packageName, false);
+                namespaceSet = new HashSet<INamespaceDefinition>(1);
+                ASDefinitionFilter.AccessValue primaryAccessRule =
+                        filter.getPrimaryAccessRule();
+                if ((primaryAccessRule == ASDefinitionFilter.AccessValue.ALL) ||
+                    (primaryAccessRule == ASDefinitionFilter.AccessValue.INTERNAL))
+                {
+                    INamespaceDefinition internalPackageNS =
+                            workspace.getPackageNamespaceDefinitionCache().get(packageName, true);
+                    namespaceSet.add(internalPackageNS);
+                }
+                namespaceSet.add(publicPackageNS);
+
+                return new Multiname(namespaceSet, definitionName);
+            }
+        }
+
+        // We will filter the funcs and vars in ASScopeBase.applyFilter
+        if (filter.getRequireImportsValue() != RequireImportsValue.YES)
+            return new Multiname(ASScopeBase.allNamespacesSet, name);
+        else
+            return new Multiname(filter.getNamespaceSetForName(project, scope, name), name);
+    }
+
+    /**
+     * Constructs a set of {@link INamespaceDefinition} by extracting
+     * information from the specified {@link ASDefinitionFilter}.
+     * 
+     * @param project {@link ICompilerProject} whose symbol table is used to
+     * resolve namespace references in the "use namespace" set in the
+     * {@link ASDefnitionFilter}.
+     * @param filter
+     * @return A new set of {@link INamespaceDefinition} created from
+     * information in the {@link ASDefinitionFilter}.
+     */
+    private static Set<INamespaceDefinition> crackFilter(ICompilerProject project, ASScope scope,
+                                                         ASDefinitionFilter filter)
+    {
+        // Check for user defined namespace access value.
+        ASDefinitionFilter.AccessValue accessValue = filter.getPrimaryAccessRule();
+        if (accessValue != null)
+        {
+            // If there is a namespace definition on the access value, we're filtering
+            // on this one specific namespace in the set.
+            // No need to do instanceof SpecialAccessValue, as getNamespaceDef() is on the
+            // base class, and will just return null when not of type SpecialAccessValue.
+            INamespaceDefinition namespaceAccessValue = accessValue.getNamespaceDef();
+            if (namespaceAccessValue != null)
+                return Collections.singleton(namespaceAccessValue);
+        }
+
+        Set<INamespaceDefinition> namespaceSet = ASScopeBase.allNamespacesSet;
+        if (filter.getRequireImportsValue() == ASDefinitionFilter.RequireImportsValue.YES)
+            namespaceSet = filter.getNamespaceSet(project, scope);
+
+        return namespaceSet;
+    }
+
+    private static Collection<IDefinition> adjustPredicateForProject(ASScope scope, ICompilerProject project,
+                                                                     ASDefinitionFilter filter,
+                                                                     List<IDefinition> definitions)
+    {
+        Predicate<IDefinition> projectPredicate = filter.computeProjectPredicate(project, scope);
+        return new FilteredCollection<IDefinition>(projectPredicate, definitions);
+    }
+}

Propchange: incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/ASScopeUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/DefinitionFilterContext.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/DefinitionFilterContext.java?rev=1413061&view=auto
==============================================================================
--- incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/DefinitionFilterContext.java (added)
+++ incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/DefinitionFilterContext.java Fri Nov 23 20:58:50 2012
@@ -0,0 +1,45 @@
+/*
+ *
+ *  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.internal.legacy;
+
+import org.apache.flex.compiler.definitions.IDefinition;
+import org.apache.flex.compiler.internal.definitions.ScopedDefinitionBase;
+
+public class DefinitionFilterContext extends ScopeFilterContext implements IFilterContext
+{
+    public DefinitionFilterContext(IDefinition def)
+    {
+        super((def instanceof ScopedDefinitionBase) ? ((ScopedDefinitionBase)def).getContainedScope() : null);
+    }
+
+    /**
+     * Determine whether this lookup is from a static context (e.g. somewhere
+     * within a static method)
+     * 
+     * @return true if the lookup is being performed in a static context
+     */
+    @Override
+    public boolean isInStaticContext()
+    {
+        // This should never be true if we're resolving something in an IDefinition
+        // as those are always type annotations, base classes, etc
+        return false;
+    }
+}

Propchange: incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/DefinitionFilterContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/FilterPredicate.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/FilterPredicate.java?rev=1413061&view=auto
==============================================================================
--- incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/FilterPredicate.java (added)
+++ incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/FilterPredicate.java Fri Nov 23 20:58:50 2012
@@ -0,0 +1,100 @@
+/*
+ *
+ *  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.internal.legacy;
+
+import java.util.Set;
+
+import org.apache.flex.compiler.definitions.IDefinition;
+import org.apache.flex.compiler.definitions.IFunctionDefinition;
+import org.apache.flex.compiler.definitions.INamespaceDefinition;
+import org.apache.flex.compiler.definitions.IPackageDefinition;
+import org.apache.flex.compiler.definitions.IVariableDefinition;
+import org.apache.flex.compiler.internal.scopes.ASScope;
+import org.apache.flex.compiler.internal.scopes.ASScopeBase;
+import org.apache.flex.compiler.projects.ICompilerProject;
+
+import com.google.common.base.Predicate;
+
+/**
+ * Predicate implementation that applies any filter constraints that are not
+ * handled by the namespace set.
+ */
+public class FilterPredicate implements Predicate<IDefinition>
+{
+    /**
+     * @param scope ASScope that is used to compute the namespace set, if the
+     * filter forced the use of the {@link ASScopeBase#allNamespacesSet}. This
+     * will be used when the require imports value is set to
+     * ONLY_FOR_FUNCTIONS_AND_VARIABLES. The parameter can be null for scope
+     * that can not have imports.
+     * @param filter {@link com.adobe.flexbuilder.codemodel.definitions.filters.ASDefinitionFilter}
+     * to apply
+     */
+    public FilterPredicate(ICompilerProject project,
+                           ASScope scope,
+                           ASDefinitionFilter filter)
+    {
+        requireImportsForFuncsAndVars = filter.getRequireImportsValue() == ASDefinitionFilter.RequireImportsValue.ONLY_FOR_FUNCTIONS_AND_VARIABLES;
+        this.project = project;
+        this.scope = scope;
+        this.filter = filter;
+    }
+
+    private final boolean requireImportsForFuncsAndVars;
+    private final ICompilerProject project;
+    private final ASScope scope;
+    private final ASDefinitionFilter filter;
+    private Set<INamespaceDefinition> nsset;
+
+    @Override
+    public boolean apply(IDefinition def)
+    {
+        // incomplete code can create definitions with no name
+        // for example, private var ; will create a variable definition with no name
+        // CM clients (code-hinting) don't require these definitions
+        // So, filter them out here
+        if (def.getBaseName().isEmpty())
+            return false;
+
+        // CM clients never want to see package definitions that
+        // inside of source file.  They only want to see package definitions
+        // from the package name index
+        if ((def instanceof IPackageDefinition) && (def.getContainingScope() != null))
+            return false;
+        if (filter.matchesClassificationRule(def) &&
+                filter.matchesModifierRules(def) &&
+                filter.matchesIncludeImplicitsAndConstructorsRule(def, scope))
+        {
+            // Do the filtering for funcs and vars, if neccessary
+            if (requireImportsForFuncsAndVars && (def instanceof IFunctionDefinition || def instanceof IVariableDefinition))
+            {
+                if (nsset == null)
+                    nsset = filter.getNamespaceSet(project, scope);
+                if (nsset.contains(def.resolveNamespace(project)))
+                    return true;
+            }
+            else
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+}

Propchange: incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/FilterPredicate.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/IFilterContext.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/IFilterContext.java?rev=1413061&view=auto
==============================================================================
--- incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/IFilterContext.java (added)
+++ incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/IFilterContext.java Fri Nov 23 20:58:50 2012
@@ -0,0 +1,75 @@
+/*
+ *
+ *  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.internal.legacy;
+
+import java.util.Set;
+
+import org.apache.flex.compiler.definitions.INamespaceDefinition;
+import org.apache.flex.compiler.projects.ICompilerProject;
+
+public interface IFilterContext
+{
+    /**
+     * Determine whether this lookup is from a static context (e.g. somewhere
+     * within a static method)
+     * 
+     * @return true if the lookup is being performed in a static context
+     */
+    boolean isInStaticContext();
+
+    /**
+     * Returns a Set of {@link INamespaceDefinition}'s which are "open" in this
+     * context. This set should namespace's like:
+     * <ul>
+     * <li>public namespace's for imported packages</li>
+     * <li>public namespace for the unnamed package</li>
+     * <li>namespace's referenced from a "use namespace" directive in this or
+     * any containing lexical scopes</li>
+     * <li>file private name space for the file that contains this context</li>
+     * <li>internal namespace for the package that contains this context</li>
+     * <li>class private, protected and static protected namespace's for the
+     * class that contains this context</li>
+     * </ul>
+     * 
+     * @return The Set of {@link INamespaceDefinition}'s which are "open" in
+     * this context.
+     */
+    Set<INamespaceDefinition> getNamespaceSet(ICompilerProject project);
+
+    /**
+     * Returns a Set of {@link INamespaceDefinition}'s which are "open" in this
+     * context for the given name. This set should namespace's like:
+     * <ul>
+     * <li>public namespace's for imported packages, or imported definitions
+     * (import a.b.Foo)</li>
+     * <li>public namespace for the unnamed package</li>
+     * <li>namespace's referenced from a "use namespace" directive in this or
+     * any containing lexical scopes</li>
+     * <li>file private name space for the file that contains this context</li>
+     * <li>internal namespace for the package that contains this context</li>
+     * <li>class private, protected and static protected namespace's for the
+     * class that contains this context</li>
+     * </ul>
+     * 
+     * @return The Set of {@link INamespaceDefinition}'s which are "open" in
+     * this context.
+     */
+    Set<INamespaceDefinition> getNamespaceSet(ICompilerProject project, String name);
+}

Propchange: incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/IFilterContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/MemberedDefinitionUtils.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/MemberedDefinitionUtils.java?rev=1413061&view=auto
==============================================================================
--- incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/MemberedDefinitionUtils.java (added)
+++ incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/MemberedDefinitionUtils.java Fri Nov 23 20:58:50 2012
@@ -0,0 +1,128 @@
+/*
+ *
+ *  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.internal.legacy;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.flex.compiler.common.ASModifier;
+import org.apache.flex.compiler.definitions.IClassDefinition;
+import org.apache.flex.compiler.definitions.IDefinition;
+import org.apache.flex.compiler.definitions.IMemberedDefinition;
+import org.apache.flex.compiler.internal.scopes.TypeScope;
+import org.apache.flex.compiler.projects.ICompilerProject;
+import org.apache.flex.compiler.scopes.IASScope;
+
+/**
+ * This class contains static methods that used to be instance methods of
+ * {@link IMemberedDefinition}. They now take a new first parameter which is the
+ * <code>IMemberDefinitionm</code>. The methods are no longer part of
+ * <code>IMemberedDefinition</code> because {@link ASDefinitionFilter} has been
+ * removed from the compiler.
+ */
+public class MemberedDefinitionUtils
+{
+    /**
+     * Look up a member by name within an {@link IMemberedDefinition}.
+     * 
+     * @param memberedDefinition The {@link IMemberedDefinition} whose member is
+     * being looked up.
+     * @param project Project whose symbol table is used to resolve base types.
+     * @param name the name of the member
+     * @param filter the {@link ASDefinitionFilter} used to match the member we
+     * are looking for
+     * @return the specified member or null if the member could not be found
+     */
+    public static IDefinition getMemberByName(IMemberedDefinition memberedDefinition,
+                                              ICompilerProject project, String name,
+                                              ASDefinitionFilter filter)
+    {
+        IASScope scope = memberedDefinition.getContainedScope();
+        return ASScopeUtils.findDefinitionByName(scope, project, name, filter);
+    }
+
+    /**
+     * Look up a member by name within an {@link IMemberedDefinition}
+     * 
+     * @param memberedDefinition The {@link IMemberedDefinition} whose members
+     * are being looked up.
+     * @param project Project whose symbol table is used to resolve base types.
+     * @param name the name of the member
+     * @param filter the {@link ASDefinitionFilter} used to match the member we
+     * are looking for
+     * @return the specified member or null if the member could not be found
+     */
+    public static IDefinition[] getAllMembersByName(IMemberedDefinition memberedDefinition,
+                                                    ICompilerProject project, String name,
+                                                    ASDefinitionFilter filter)
+    {
+        assert !filter.searchContainingScope();
+
+        List<IDefinition> definitions = new ArrayList<IDefinition>();
+
+        IASScope scope = memberedDefinition.getContainedScope();
+        if (memberedDefinition instanceof IClassDefinition)
+        {
+            if (filter.requiresModifier(ASModifier.STATIC))
+                scope = ((TypeScope)scope).getStaticScope();
+            else if (filter.excludesModifier(ASModifier.STATIC))
+                scope = ((TypeScope)scope).getInstanceScope();
+        }
+
+        ASScopeUtils.findAllDefinitionsByName(scope, project, name, filter, definitions);
+        return definitions.toArray(new IDefinition[0]);
+    }
+
+    /**
+     * Get an array containing all of the members contained within an
+     * {@link IMemberedDefinition}. If the hierarchy of this type allows for
+     * overriding member definitions, then this list could contain shadowed
+     * member signatures, since this returns all members from the hierarchy of
+     * this type
+     * 
+     * @param memberedDefinition The {@link IMemberedDefinition} whose members
+     * are being looked up.
+     * @param project Project whose symbol table is used to resolve base types.
+     * @param filter ASDefinitionFilter describing the members that should be
+     * included
+     * @return an array containing all of the members matching the
+     * {@link ASDefinitionFilter}
+     */
+    public static IDefinition[] getAllMembers(IMemberedDefinition memberedDefinition,
+                                              ICompilerProject project,
+                                              ASDefinitionFilter filter)
+    {
+        assert !filter.searchContainingScope();
+
+        List<IDefinition> definitions = new ArrayList<IDefinition>();
+
+        IASScope scope = memberedDefinition.getContainedScope();
+        if (memberedDefinition instanceof IClassDefinition)
+        {
+            if (filter.requiresModifier(ASModifier.STATIC))
+                scope = ((TypeScope)scope).getStaticScope();
+            else if (filter.excludesModifier(ASModifier.STATIC))
+                scope = ((TypeScope)scope).getInstanceScope();
+        }
+
+        ASScopeUtils.findAllDefinitions(scope, project, filter, definitions);
+        return definitions.toArray(new IDefinition[0]);
+    }
+}

Propchange: incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/MemberedDefinitionUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/NodeFilterContext.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/NodeFilterContext.java?rev=1413061&view=auto
==============================================================================
--- incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/NodeFilterContext.java (added)
+++ incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/NodeFilterContext.java Fri Nov 23 20:58:50 2012
@@ -0,0 +1,175 @@
+/*
+ *
+ *  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.internal.legacy;
+
+import java.lang.ref.WeakReference;
+import java.util.Set;
+
+import org.apache.flex.compiler.common.ASModifier;
+import org.apache.flex.compiler.definitions.INamespaceDefinition;
+import org.apache.flex.compiler.internal.scopes.ASScope;
+import org.apache.flex.compiler.internal.tree.as.FunctionNode;
+import org.apache.flex.compiler.internal.tree.as.LanguageIdentifierNode;
+import org.apache.flex.compiler.projects.ICompilerProject;
+import org.apache.flex.compiler.scopes.IASScope;
+import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.ILanguageIdentifierNode;
+import org.apache.flex.compiler.tree.as.IScopedDefinitionNode;
+import org.apache.flex.compiler.tree.as.IScopedNode;
+
+/**
+ * An IFilterContext implementation based on an IASNode. Provided for backwards
+ * compatibility of ASDefinitionFilter methods which expect to operate on
+ * IASNodes
+ */
+public class NodeFilterContext extends ScopeFilterContext implements IFilterContext
+{
+    private WeakReference<IASNode> nodeContext;
+
+    /**
+     * Find the scope that will determine the namespaces in effect for a node
+     * example: for a ClassNode, we will get the block scope that is a direct
+     * child of the class node. Other types of nodes may need to walk up the
+     * tree...
+     * 
+     * @param node is the node whose scope we care about. may be null
+     * @return the scope for the node. may be null. Note: I *think* the return
+     * is only null if a null node is passed in.
+     */
+    private static ASScope getScopeOfNamespaceSetForNode(IASNode node)
+    {
+
+        ASScope ret = null;
+        IScopedNode scopedNode = null;
+
+        // search up the node tree until we find someone who can give us a scope,
+        // either IScopedNode or IScopedDefinition
+        // When loop is done, scopedNode should be set to the node we found
+        while ((scopedNode == null) && (node != null))
+        {
+            if (node instanceof IScopedNode)
+            {
+                scopedNode = (IScopedNode)node;
+            }
+            else if (node instanceof IScopedDefinitionNode)
+            {
+                IScopedDefinitionNode scopedDefinitionNode = (IScopedDefinitionNode)node;
+                scopedNode = scopedDefinitionNode.getScopedNode();
+            }
+            if (scopedNode == null)
+            {
+                node = node.getParent();
+            }
+        }
+
+        // if we found a scoped node, get the scope out of it
+        if (scopedNode != null)
+        {
+            IASScope scope = scopedNode.getScope();
+            assert (scope instanceof ASScope);
+            if (scope instanceof ASScope)
+            {
+                ret = (ASScope)scope;
+            }
+        }
+        return ret;
+    }
+
+    public NodeFilterContext(IASNode context)
+    {
+        super(getScopeOfNamespaceSetForNode(context));
+        this.nodeContext = new WeakReference<IASNode>(context);
+    }
+
+    /**
+     * Determine whether this lookup is from a static context (e.g. somewhere
+     * within a static method)
+     * 
+     * @return true if the lookup is being performed in a static context
+     */
+    @Override
+    public boolean isInStaticContext()
+    {
+        IASNode node = nodeContext.get();
+        if (node != null)
+        {
+            return isInStaticContext(node);
+        }
+        return false;
+    }
+
+    /**
+     * Determine whether this node is in a static context (e.g. somewhere within
+     * a static method)
+     * 
+     * @return true if the node is in a static context
+     */
+    public static boolean isInStaticContext(IASNode node)
+    {
+        IASNode current = node.getParent();
+        while (current != null && !(current instanceof FunctionNode))
+            current = current.getParent();
+        if (current instanceof FunctionNode && ((FunctionNode)current).hasModifier(ASModifier.STATIC))
+            return true;
+        return false;
+    }
+
+    @Override
+    public Set<INamespaceDefinition> getNamespaceSet(ICompilerProject project)
+    {
+        Set<INamespaceDefinition> nsset = super.getNamespaceSet(project);
+        IASNode n = nodeContext.get();
+        if (isSuper(n))
+        {
+            // If our node is 'super' then we need to adjust the namespace set to account for the super
+            // classes protected namespace
+            nsset = getScope().adjustNamespaceSetForSuper(((LanguageIdentifierNode)n).resolveType(project), nsset);
+        }
+        return nsset;
+    }
+
+    @Override
+    public Set<INamespaceDefinition> getNamespaceSet(ICompilerProject project, String name)
+    {
+        Set<INamespaceDefinition> nsset = super.getNamespaceSet(project, name);
+        IASNode n = nodeContext.get();
+        if (isSuper(n))
+        {
+            // If our node is 'super' then we need to adjust the namespace set to account for the super
+            // classes protected namespace
+            nsset = getScope().adjustNamespaceSetForSuper(((LanguageIdentifierNode)n).resolveType(project), nsset);
+        }
+        return nsset;
+    }
+
+    /**
+     * @return true if the node passed in is 'super'
+     */
+    private boolean isSuper(IASNode n)
+    {
+        boolean isSuper = false;
+        if (n != null)
+        {
+            if (n instanceof LanguageIdentifierNode && ((LanguageIdentifierNode)n).getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.SUPER)
+                isSuper = true;
+        }
+        return isSuper;
+    }
+}

Propchange: incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/NodeFilterContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/ScopeFilterContext.java
URL: http://svn.apache.org/viewvc/incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/ScopeFilterContext.java?rev=1413061&view=auto
==============================================================================
--- incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/ScopeFilterContext.java (added)
+++ incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/ScopeFilterContext.java Fri Nov 23 20:58:50 2012
@@ -0,0 +1,89 @@
+/*
+ *
+ *  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.internal.legacy;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.flex.compiler.common.ASImportTarget;
+import org.apache.flex.compiler.common.IImportTarget;
+import org.apache.flex.compiler.definitions.INamespaceDefinition;
+import org.apache.flex.compiler.internal.projects.CompilerProject;
+import org.apache.flex.compiler.internal.scopes.ASFileScope;
+import org.apache.flex.compiler.internal.scopes.ASScope;
+import org.apache.flex.compiler.internal.workspaces.Workspace;
+import org.apache.flex.compiler.projects.ICompilerProject;
+
+public abstract class ScopeFilterContext implements IFilterContext
+{
+    protected ScopeFilterContext(ASScope scope)
+    {
+        this.scope = scope;
+    }
+
+    private final ASScope scope;
+
+    public static Set<INamespaceDefinition> getNamespaceSet(ICompilerProject project, ASScope scope)
+    {
+        return getNamespaceSet(project, scope, null);
+    }
+
+    public static Set<INamespaceDefinition> getNamespaceSet(ICompilerProject project, ASScope scope, String name)
+    {
+        if (scope == null)
+        {
+            Set<INamespaceDefinition> nsSet = new HashSet<INamespaceDefinition>();
+
+            ((CompilerProject)project).addGlobalUsedNamespacesToNamespaceSet(nsSet);
+
+            for (String importStr : ASFileScope.getImplicitImportsForAS())
+            {
+                Workspace workspace = (Workspace)project.getWorkspace();
+                IImportTarget importTarget = ASImportTarget.get(workspace, importStr);
+                INamespaceDefinition packagePublicNamespace = importTarget.getNamespace();
+                nsSet.add(packagePublicNamespace);
+            }
+
+            return nsSet;
+        }
+
+        return name != null ? scope.getNamespaceSetForName(project, name) : scope.getNamespaceSet(project);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Set<INamespaceDefinition> getNamespaceSet(ICompilerProject project)
+    {
+        return getNamespaceSet(project, scope);
+    }
+
+    @Override
+    public Set<INamespaceDefinition> getNamespaceSet(ICompilerProject project, String name)
+    {
+        return getNamespaceSet(project, scope, name);
+    }
+
+    protected ASScope getScope()
+    {
+        return scope;
+    }
+}

Propchange: incubator/flex/falcon/trunk/compiler.js/src/org/apache/flex/compiler/internal/legacy/ScopeFilterContext.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message