public class ASProjectScope extends ASScopeBase
A project scope keeps track of, but does not own, all the externally-visible definitions for all the compilation units of a single project, so that multiple compilation units can resolve an identifier to the same definition.
For example, the ClassDefinition for the Sprite class in playerglobal.swc is owned by a single ASFileScope produced from that SWC. But this definition is then shared into the ASProjectScope for each project that uses playerglobal.swc.
Note that a workspace might have some projects whose project scope maps "flash.display.Sprite" to the Sprite class in playerglobal.swc and other projects whose project scope maps this same qualified name to the Sprite class in airglobal.swc.
Unlike other ASScopes, an ASProjectScope does not store information about
import
or use namespace
directives.
Since multiple compilation units need to concurrently access a project scope, it uses a ReadWriteLock to allow either multiple readers with no writer or a single writer with no readers.
A project scope can store a special kind of definition called a definition
promise, represented by ASProjectScope.DefinitionPromise
.
A definition promise is a small object that serves as a placeholder for an
actual definition, which it can produce on demand but at significant expense.
A promise knows only its qualified name and the compilation unit that produced it;
it has no idea whether the actual definition it can produce will turn out
to be a class definition, an interface definition, a function/getter/setter
definition, a variable/constant definition, or a namespace definition.
Promises are created by compilation units corresponding to files on the
source path or library path, but not for files on the source list.
The files on the source path and library path are recursively enumerated,
compilation units are created for each source file and each SWC script,
and each such compilation unit produces a promise to initially populate
the project scope. For example, the file com/whatever/Foo.as
will produce a promise named com.whatever.Foo
.
If code refers to Foo
, the promise will be converted
to an actual definition by parsing the file com/whatever/Foo.as
,
building a syntax tree, building a file scope, etc.
Project scopes support definition shadowing since multiple
definitions with the same qualified name can exist in them
without this being an error.
(For example, monkey-patching UIComponent would cause it to be
on the source path and also in framework.swc.)
Definition priorities, represented by IDefinitionPriority
,
determine which one of the definitions is made visible to the name
resolution algorithm by being stored in the scope's definition store.
The others are stored, invisible to name resolution, in shadow sets
of definitions, in a map that maps a qualified name to a shadow set.
As definitions with a given qualified name are added to and removed from
the scope, which definition is visible, and which are shadowed, can change.
If a compilation unit initially produces definition promises rather than
actual definitions, then it puts promises into the shadow sets rather than
actual definitions; this allows the removeDefinition
method
to be able to remove a definition promise from the project scope
without it ever being converted to an actual definition.
Modifier and Type | Class and Description |
---|---|
static class |
ASProjectScope.DefinitionPromise
Represents a promise to provide an
IDefinition in the future. |
ASScopeBase.FilteredCollection<T>
allNamespacesSet, definitionStore
Constructor and Description |
---|
ASProjectScope(CompilerProject project)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addAllExternallyVisibleDefinitions(ArrayList<IRequest<IFileScopeRequestResult,ICompilationUnit>> scopeRequests)
Adds public and internal definitions of the specified scope requests to
this ASProjectScope scope.
|
void |
addDefinition(IDefinition def)
Adds the specified definition to this scope.
|
protected void |
addDefinitionToStore(IDefinition def)
Helper method called by
ASScopeBase.addDefinition(org.apache.flex.compiler.definitions.IDefinition) (). |
void |
addScopeForCompilationUnit(ICompilationUnit cu,
ASFileScope scope)
Associates an
IASScope for a file or package scope with a
ICompilationUnit . |
void |
addScopeToCompilationUnitScopeList(ASScope scope)
Adds the specified
ASScope to the list of IASScope s
associated with the ICompilationUnit that contains the specified
ASScope . |
Collection<IASScope> |
clearCompilationUnitScopeList(ICompilationUnit compilationUnit)
Clears the list of
IASScope s associated with the specified
ICompilationUnit . |
void |
compact()
Minimizes the memory used by this scope.
|
static ASProjectScope.DefinitionPromise |
createDefinitionPromise(String qname,
ICompilationUnit compilationUnit) |
IDefinition[] |
findAllDefinitionsByName(Multiname multiname) |
void |
findDefinitionByName(Collection<IDefinition> defs,
String baseName,
Set<INamespaceDefinition> namespaceSet) |
void |
findDefinitionByName(ICompilationUnit referencingCU,
Collection<IDefinition> defs,
String baseName,
Set<INamespaceDefinition> namespaceSet,
DependencyType dt) |
IDefinition |
findDefinitionByName(Multiname multiname,
boolean ignoreAmbiguous) |
IDefinition |
findDefinitionByName(String definitionName) |
Collection<IDefinition> |
getAllLocalDefinitions()
Gets all the definitions in this one scope.
|
Collection<IDefinitionSet> |
getAllLocalDefinitionSets()
Gets all the definition sets in this one scope.
|
Collection<String> |
getAllLocalNames()
Gets all the base names of definitions in this one scope.
|
void |
getAllProperties(CompilerProject project,
Collection<IDefinition> defs,
Set<INamespaceDefinition> namespaceSet)
Adds all definitions ( including definitions from base types ) in the
current scope to the specified collections of definitions that have a
namespace qualifier in the specified definition set.
|
Collection<String> |
getAllQualifiedNames()
Gets a collection of the qualified names for all the definitions in this
project scope.
|
ITypeDefinition |
getArrayDefinition() |
ITypeDefinition |
getBooleanDefinition() |
ITypeDefinition |
getClassDefinition() |
ICompilationUnit |
getCompilationUnitForDefinition(IDefinition def)
Gets the
ICompilationUnit that contains the specified
IDefinition . |
ICompilationUnit |
getCompilationUnitForScope(IASScope scope)
Get the ICompilationUnit from which the scope is declared
|
Set<ICompilationUnit> |
getCompilationUnitsByDefinitionName(String name)
Finds all the compilation units in the project that define or should
define a symbol with the specified base name.
|
Collection<IASScope> |
getCompilationUnitScopeList(ICompilationUnit compilationUnit)
Gets the
List of IASScope s that have an associated ASScopeCache or define
IDefinition s currently in the ASProjectScope for the specified ICompilationUnit . |
Set<ICompilationUnit> |
getCompilationUnitsForReferences(Iterable<IResolvedQualifiersReference> references)
Find the
ICompilationUnit 's in the project that define or should
define the definitions that the specified list of references refer to. |
Set<ICompilationUnit> |
getCompilationUnitsForReferences(Iterable<IResolvedQualifiersReference> references,
Collection<IResolvedQualifiersReference> unresolvedReferences)
Find the
ICompilationUnit 's in the project that define or should
define the definitions that the specified list of references refer to. |
static Set<ICompilationUnit> |
getCompilationUnitsWithConflictingDefinitions(IWorkspace workspace,
Iterable<ICompilationUnit> units)
Find all the
ICompilationUnit s that define definitions with the same qualified name as the definitions defined by the
specified Iterable of ICompilationUnit s. |
IASScope |
getContainingScope()
Gets the scope that lexically contains this scope.
|
ITypeDefinition |
getFunctionDefinition() |
ITypeDefinition |
getIntDefinition() |
IDefinitionSet |
getLocalDefinitionSetByName(String name)
Gets the set of definitions in this one scope that have the specified base name.
|
ITypeDefinition |
getNamespaceDefinition() |
ITypeDefinition |
getNumberDefinition() |
ITypeDefinition |
getObjectDefinition() |
CompilerProject |
getProject()
Gets the
CompilerProject that owns this scope. |
void |
getPropertyForScopeChain(ASScope referencingScope,
Collection<IDefinition> defs,
String baseName,
Set<INamespaceDefinition> namespaceSet,
DependencyType dt) |
Set<IDefinition> |
getShadowedDefinitions(IDefinition def)
Gets the set of definitions that have the same qname as specified definition
but are lower priority and thus not visible.
|
ITypeDefinition |
getStringDefinition() |
ITypeDefinition |
getUIntDefinition() |
IDefinition |
getUndefinedValueDefinition() |
ITypeDefinition |
getVectorDefinition() |
ITypeDefinition |
getXMLDefinition() |
ITypeDefinition |
getXMLListDefinition() |
boolean |
isActiveDefinition(IDefinition definition)
Determines if the specified definition is visible in the project scope.
|
boolean |
isValidImport(String importName)
Determines whether a specified import name such as
"MyClass"
, "flash.display.Sprite" or "flash.display. |
AppliedVectorDefinition |
newVectorClass(ITypeDefinition elementType) |
void |
removeCompilationUnits(Collection<ICompilationUnit> compilationUnitsToRemove)
Removes a set of
ICompilationUnit 's from the project scope. |
void |
removeDefinition(IDefinition definition)
Removes the specified definition from this scope.
|
boolean |
verify()
Calling this method from an assert will cause an assertion failure if
there is any
IDefinition in this ASProjectScope for which an
ICompilationUnit can not be found. |
getAllLocalProperties, getDefinition, getLocalProperty, getLocalProperty, getLocalProperty, getScopeNode, isContingentDefinitionNeeded, removeDefinitionFromStore, toString, toStringHeader
public ASProjectScope(CompilerProject project)
project
- The project that owns this project scope.public void addAllExternallyVisibleDefinitions(ArrayList<IRequest<IFileScopeRequestResult,ICompilationUnit>> scopeRequests) throws InterruptedException
scopeRequests
- a list of scope requests that will have their
externally visible definitions added to this project scope.InterruptedException
public CompilerProject getProject()
CompilerProject
that owns this scope.CompilerProject
that owns this scope.public static ASProjectScope.DefinitionPromise createDefinitionPromise(String qname, ICompilationUnit compilationUnit)
public IDefinitionSet getLocalDefinitionSetByName(String name)
IASScope
getLocalDefinitionSetByName
in interface IASScope
getLocalDefinitionSetByName
in class ASScopeBase
name
- A String specifying a base name.IDefinitionSet
containing definitions with that base name,
or null
if there are no such definitions.public Set<ICompilationUnit> getCompilationUnitsForReferences(Iterable<IResolvedQualifiersReference> references)
ICompilationUnit
's in the project that define or should
define the definitions that the specified list of references refer to.
This method will not cause any processing for any compilation unit to be started.
references
- A list of references.ICompilationUnit
's in the project that define
or should define the definitions the specified list of references refer
to.public Set<ICompilationUnit> getCompilationUnitsForReferences(Iterable<IResolvedQualifiersReference> references, Collection<IResolvedQualifiersReference> unresolvedReferences)
ICompilationUnit
's in the project that define or should
define the definitions that the specified list of references refer to.
This method will not cause any processing for any compilation unit to be started.
references
- A list of references.unresolvedReferences
- A collection of references that were not
resolved to compilation units. May be null if the caller is not
interested.ICompilationUnit
's in the project that define
or should define the definitions the specified list of references refer
to.public Set<ICompilationUnit> getCompilationUnitsByDefinitionName(String name)
This method will not cause any processing for any compilation unit to be started.
name
- Base name of a symbol. For example if the definition's
qualified name is: spark.components.Button
its base name is
Button
.public static Set<ICompilationUnit> getCompilationUnitsWithConflictingDefinitions(IWorkspace workspace, Iterable<ICompilationUnit> units)
ICompilationUnit
s that define definitions with the same qualified name as the definitions defined by the
specified Iterable
of ICompilationUnit
s.workspace
- IWorkspace
that the ICompilationUnit
s.units
- Iterable
of ICompilationUnit
s.Set
of ICompilationUnit
s that define definitions with the same qualified name as the definitions defined by the
specified Iterable
of ICompilationUnit
s.public Collection<IDefinitionSet> getAllLocalDefinitionSets()
IASScope
getAllLocalDefinitionSets
in interface IASScope
getAllLocalDefinitionSets
in class ASScopeBase
IDefinitionSet
objects.public Collection<IDefinition> getAllLocalDefinitions()
IASScope
getAllLocalDefinitions
in interface IASScope
getAllLocalDefinitions
in class ASScopeBase
IDefinition
objects.public IDefinition findDefinitionByName(String definitionName)
public IDefinition[] findAllDefinitionsByName(Multiname multiname)
public IDefinition findDefinitionByName(Multiname multiname, boolean ignoreAmbiguous)
public Set<IDefinition> getShadowedDefinitions(IDefinition def)
def
- The definition to get shadowed definitions for. May not be
null.NullPointerException
- if def is null.public void addDefinition(IDefinition def)
ASScopeBase
addDefinition
in class ASScopeBase
def
- The IDefinition
to be added.protected void addDefinitionToStore(IDefinition def)
ASScopeBase
ASScopeBase.addDefinition(org.apache.flex.compiler.definitions.IDefinition)
().
It handles actually adding the definition to the store. It first tries to add it to the current store. If it won't fit, it creates a bigger store and adds it to that.
addDefinitionToStore
in class ASScopeBase
def
- The IDefinition
to be added.public void removeDefinition(IDefinition definition)
ASScopeBase
removeDefinition
in class ASScopeBase
definition
- The IDefinition
to be removed.public void compact()
ASScopeBase
The definition store does not get compacted, but subclasses override this to compact other data structures.
compact
in class ASScopeBase
public Collection<String> getAllLocalNames()
IASScope
getAllLocalNames
in interface IASScope
getAllLocalNames
in class ASScopeBase
public Collection<String> getAllQualifiedNames()
public void addScopeForCompilationUnit(ICompilationUnit cu, ASFileScope scope)
IASScope
for a file or package scope with a
ICompilationUnit
. This association is used to establish
dependencies between ICompilationUnit
's, when resolving
definition across ICompilationUnit
boundaries.cu
- A compilation unit.scope
- An ASFileScope
for a filepublic ICompilationUnit getCompilationUnitForScope(IASScope scope)
scope
- The scope in questionpublic void addScopeToCompilationUnitScopeList(ASScope scope)
ASScope
to the list of IASScope
s
associated with the ICompilationUnit
that contains the specified
ASScope
. This method is called for when a ASScopeCache
is
created for an ASScope
or when IDefinition
s from a ICompilationUnit
does
not have ASProjectScope.DefinitionPromise
s are added to the ASProjectScope
.scope
- The scope to be added.public Collection<IASScope> clearCompilationUnitScopeList(ICompilationUnit compilationUnit)
IASScope
s associated with the specified
ICompilationUnit
.compilationUnit
- The ICompilationUnit
whose associated list
of IASScope
s should be cleared.List
of IASScope
s associated with the
specified ICompilationUnit
before this method was called.public Collection<IASScope> getCompilationUnitScopeList(ICompilationUnit compilationUnit)
List
of IASScope
s that have an associated ASScopeCache
or define
IDefinition
s currently in the ASProjectScope
for the specified ICompilationUnit
.compilationUnit
- ICompilationUnit
of the scopes to querypublic ICompilationUnit getCompilationUnitForDefinition(IDefinition def)
ICompilationUnit
that contains the specified
IDefinition
.def
- IDefinition
whose containing ICompilationUnit
should be returned.ICompilationUnit
that contains the specified
IDefinition
or null.public void removeCompilationUnits(Collection<ICompilationUnit> compilationUnitsToRemove)
ICompilationUnit
's from the project scope.compilationUnitsToRemove
- The collection of compilation units to remove.public IASScope getContainingScope()
IASScope
IASScope
that contains this scope,
or null
if there is no such scope.public AppliedVectorDefinition newVectorClass(ITypeDefinition elementType)
public void getPropertyForScopeChain(ASScope referencingScope, Collection<IDefinition> defs, String baseName, Set<INamespaceDefinition> namespaceSet, DependencyType dt)
public void findDefinitionByName(ICompilationUnit referencingCU, Collection<IDefinition> defs, String baseName, Set<INamespaceDefinition> namespaceSet, DependencyType dt)
public boolean isActiveDefinition(IDefinition definition)
A definition is a project can be hidden by other definitions with same qualified name that have a higher definition priority. A definition's priority is influenced by the following: Whether the definition is from source or library The time stamp associated with a definition
public void findDefinitionByName(Collection<IDefinition> defs, String baseName, Set<INamespaceDefinition> namespaceSet)
public boolean isValidImport(String importName)
"MyClass"
, "flash.display.Sprite"
or "flash.display.*"
is valid, by determining whether it matches the name of any definition in
this project scope.public void getAllProperties(CompilerProject project, Collection<IDefinition> defs, Set<INamespaceDefinition> namespaceSet)
project
- CompilerProject
used to resolve reference to
definitions outside of the ICompilationUnit
that contains this
scope.defs
- Collection that found IDefinition
's are added to.namespaceSet
- Namespace set in which the qualifier of any matching
definition must exist to be considered a match.public final ITypeDefinition getObjectDefinition()
public final ITypeDefinition getStringDefinition()
public final ITypeDefinition getArrayDefinition()
public final ITypeDefinition getXMLDefinition()
public final ITypeDefinition getXMLListDefinition()
public final ITypeDefinition getBooleanDefinition()
public final ITypeDefinition getIntDefinition()
public final ITypeDefinition getUIntDefinition()
public final ITypeDefinition getNumberDefinition()
public final ITypeDefinition getClassDefinition()
public final ITypeDefinition getFunctionDefinition()
public final ITypeDefinition getNamespaceDefinition()
public final ITypeDefinition getVectorDefinition()
public final IDefinition getUndefinedValueDefinition()
public boolean verify()
IDefinition
in this ASProjectScope
for which an
ICompilationUnit
can not be found.verify
in class ASScopeBase
IDefinition
in this ASProjectScope
for which an
ICompilationUnit
can not be found, true otherwise.Copyright © 2016 The Apache Software Foundation. All rights reserved.