Package org.apache.flex.compiler.internal.scopes

Examples of org.apache.flex.compiler.internal.scopes.ASScope


        public static INamespaceDefinition resolveNamespaceReferenceInDirective(ICompilerProject project,
                                                                        UserDefinedNamespaceReference namespaceReference,
                                                                        INamespaceDirective containingDirective,
                                                                        NamespaceForwardReferencePredicate pred)
        {
            ASScope scope = namespaceReference.getScope();

            assert scope != null : "All UserDefinedNamespaceReferences should have a scope!";

            pred = pred.copy();
            if( containingDirective instanceof IDefinition )
                pred.addRef((IDefinition)containingDirective);

            NamespaceDirectiveResolver resolver =
                    new NamespaceDirectiveResolver(project, scope, pred);

            INamespaceDirective currentDirective = scope.getFirstNamespaceDirective();
            // make a resolver to hold the resolution state as we walk through the directives.
            // loop over the directives till we find the directive containing the
            // reference are trying to resolve.
            while (containingDirective != currentDirective)
            {
View Full Code Here


     * @param project Project we are in
     */
    public void adjustVectorMethods(ICompilerProject project)
    {
        VectorInformation vecInfo = VectorInformation.getInformation();
        ASScope scope = getContainedScope();

        // Copy the methods from the base class, so they report themselves as belonging
        // to the instantiated Vector class instead of Vector$object, etc.
        IASScope baseClassScope = baseClass.getContainedScope();
        for (IDefinition defaultDef : baseClassScope.getAllLocalDefinitions())
        {
            String name = defaultDef.getBaseName();
            VectorInformation.FunctionInfo info = vecInfo.getFunctionInfo(name);
            if (defaultDef instanceof FunctionDefinition)
            {
                FunctionDefinition defaultFunc = (FunctionDefinition)defaultDef;
                // Override the base class definition with one that has the correct signature

                FunctionDefinition newDef;
                if (defaultDef instanceof GetterDefinition)
                {
                    newDef = new GetterDefinition(name);
                    newDef.setReturnTypeReference(defaultFunc.getReturnTypeReference());
                    newDef.setTypeReference(defaultFunc.getTypeReference());
                }
                else if (defaultDef instanceof SetterDefinition)
                {
                    newDef = new SetterDefinition(name);
                    newDef.setReturnTypeReference(defaultFunc.getReturnTypeReference());
                    newDef.setTypeReference(defaultFunc.getTypeReference());
                }
                else
                {
                    newDef = new FunctionDefinition(name);
                    newDef.setReturnTypeReference(defaultFunc.getReturnTypeReference());
                }

                ASScope newScope = new FunctionScope(scope);
                newDef.setContainedScope(newScope);

                newDef.setNamespaceReference(defaultDef.getNamespaceReference());

                if (info != null)
                {
                    if (info.returnIsTypeOfCollection())
                        newDef.setReturnTypeReference(ReferenceFactory.resolvedReference(elementType));
                    else if (info.returnIsVector())
                        newDef.setReturnTypeReference(ReferenceFactory.resolvedReference(this));
                }
                ParameterDefinition[] params = defaultFunc.getParameters();

                if (params != null)
                {
                    VectorInformation.ArgumentInfo[] args = info != null ? info.getArgumentInfo() : null;
                    ParameterDefinition[] newParams = new ParameterDefinition[params.length];
                    for (int i = 0, l = params.length; i < l; ++i)
                    {
                        if (args != null && i < args.length)
                        {
                            newParams[i] = copyParameter(project, params[i], args[i]);
                            if (args[i].returnIsVector())
                                newParams[i].setTypeReference(ReferenceFactory.resolvedReference(this));
                            else if (args[i].returnIsTypeOfCollection())
                                newParams[i].setTypeReference(ReferenceFactory.resolvedReference(elementType));
                        }
                        else
                        {
                            newParams[i] = copyParameter(project, params[i], null);
                        }
                        newScope.addDefinition(newParams[i]);

                    }
                    newDef.setParameters(newParams);
                }
                scope.addDefinition(newDef);
View Full Code Here

                                               MXMLNodeInfo info)
    {
        if (attribute.isSpecialAttribute(ATTRIBUTE_SOURCE))
        {
            MXMLClassDefinitionNode classNode = getContainingClassNode();
            ASScope classScope = (ASScope)classNode.getClassDefinition().getContainedScope();

            // Resolve the attribute value to a normalized path.
            // Doing so makes this compilation unit dependent on that file.
            String sourcePath = resolveSourceAttributePath(builder, attribute, info);
            if (sourcePath != null)
View Full Code Here

        }

        final MXMLDialect mxmlDialect = builder.getMXMLDialect();
        final String sourcePath = tag.getParent().getFileSpecification().getPath();
        final MXMLClassDefinitionNode classNode = getContainingClassNode();
        final ASScope classScope = (ASScope)classNode.getClassDefinition().getContainedScope();
        final CompilerProject project = builder.getProject();
        final OffsetLookup offsetLookup = classScope.getFileScope().getOffsetLookup();

        setSourcePath(sourcePath);
        try
        {
            // parse inline ActionScript
View Full Code Here

        IWorkspace workspace = project.getWorkspace();
        IResolvedQualifiersReference ref = ReferenceFactory.packageQualifiedReference(workspace, deferredInstanceFromFunctionClass);
      
        IScopedNode scopedNode = anInstanceNode.getContainingScope();
        IASScope iscope = scopedNode.getScope();
        ASScope scope = (ASScope)iscope;
       
        if (ref == null)
            assert false;
        IDefinition def = ref.resolve(project, scope, DependencyType.EXPRESSION, false);
        if (def == null)
View Full Code Here

        }
        // Resolve the outer document, and if it doesn't resolve to the contingent
        // definition, that means there is already an existing definition declared
        // which is an error.
        ClassDefinition componentClass = (ClassDefinition)node.getContainedClassDefinition();
        ASScope classScope = componentClass.getContainedScope();
        IDefinition outerDocument = classScope.getPropertyFromDef(
            getProject(), componentClass, IMXMLLanguageConstants.PROPERTY_OUTER_DOCUMENT, false);
        assert (outerDocument != null) : "outerDocument should never be null, as always added";
        if (!outerDocument.isContingent())
        {
            ICompilerProblem problem = new MXMLOuterDocumentAlreadyDeclaredProblem(outerDocument);
View Full Code Here

     */
    public void validateClassImplementsAllMethods(ICompilerProject project, ClassDefinition cls, Collection<ICompilerProblem> problems)
    {
        // Interface methods must be implemented by public methods
        INamespaceDefinition publicNs = NamespaceDefinition.getPublicNamespaceDefinition();
        ASScope classScope = cls.getContainedScope();

        for (IDefinitionSet defSet : this.getContainedScope().getAllLocalDefinitionSets())
        {
            for (int i = 0, l = defSet.getSize(); i < l; ++i)
            {
                IDefinition def = defSet.getDefinition(i);
                if (def instanceof FunctionDefinition)
                {
                    FunctionDefinition interfMethod = (FunctionDefinition)def;

                    // Skip any implicit methods added for CM compat
                    if (interfMethod.isImplicit())
                        continue;

                    // Skip the constructor method of the interface.
                    if (interfMethod.getBaseName().equals(getBaseName()))
                        continue;

                    IDefinition c = classScope.getQualifiedPropertyFromDef(project,
                                                                                    cls,
                                                                                    interfMethod.getBaseName(),
                                                                                    publicNs,
                                                                                    false);
                    // Match up getters and setters
View Full Code Here

    //

    @Override
    public IDefinition resolve(ICompilerProject project)
    {
        ASScope asScope = getASScope();

        if (asScope == null)
            return null;

        // attributes are not statically knowable
        if (this.isAttributeIdentifier())
            return null;

        // If this is a reference to a known package, then we can't resolve to anything
        if (isPartOfPackageReference())
            return null;

        IDefinition result = null;
        final String name = getName();
        IQualifiers qualifier = null;

        if (isQualifiedRef())
        {
            qualifier = resolveQualifier(project);

            // If we can't resolve the qualifier, then we can't resolve the entire expression
            if (qualifier == null)
                return null;
        }

        boolean isMemberRef = isMemberRef();

        if (isMemberRef && baseIsPackage())
        {
            // If our base refers to a package, then we're really a qualified name
            // and not a regular member acces (a.b.C means find C in package a.b, if a.b is a package)
            // convert the name to a fully qualified name, and look that up via findProperty
            ExpressionNodeBase base = getBaseExpression();

            String packageName = base.computeSimpleReference();
            Workspace workspace = (Workspace)project.getWorkspace();
            qualifier = workspace.getPackageNamespaceDefinitionCache().get(packageName, false);

            // Set this to false, so we'll fall through to the findProperty case
            // below, instead of trying to call resolveMemberRef
            isMemberRef = false;
        }
        if (isNameNode())
        {
            // If we are the name node for a declaration, just grab the definition
            // don't have to look anywhere else
            IDefinitionNode defNode = getParentAsDefinition();
            if (defNode != null)
                result = defNode.getDefinition();
        }
        else if (isMemberRef)
        {
            result = resolveMemberRef(project, asScope, name, qualifier);
        }
        else
        {
            if (qualifier == null)
                result = asScope.findProperty(project, name, getDependencyType(), isTypeRef());
            else
                result = asScope.findPropertyQualified(project, qualifier, name, getDependencyType(), isTypeRef());
        }

        return result;
    }
View Full Code Here

        IDefinition def = resolve(project);

        if (canEarlyBind(project, def))
            return ((DefinitionBase)def).getMName(project);

        ASScope scope = getASScope();

        if (isQualifiedRef())
        {
            // If we're a qualified name, and the qualifier resolves to a compile
            // time constant, return a QName
            // otherwise emit a RTQname - the CG will have to take care of generating the code to
            // evaluate the qualifier and place it on the stack.
            IQualifiers qual = resolveQualifier(project);

            Nsset namespaceSet;
            int nameKind;

            if (qual != null )
            {
                if( qual.getNamespaceCount() == 1 )
                {
                    // Qualifier resolved to 1 namespace, so we can emit a QName
                    NamespaceDefinition ns = (NamespaceDefinition)qual.getFirst();
                    nameKind = isAttributeIdentifier() ? CONSTANT_QnameA : CONSTANT_Qname;
                    if (isMemberRef())
                    {
                        ExpressionNodeBase baseExpr = getBaseExpression();
                        if (baseExpr instanceof LanguageIdentifierNode &&
                                ((LanguageIdentifierNode)baseExpr).getKind() == LanguageIdentifierKind.SUPER)
                        {
                            // If we're a super expression, adjust the namespace in case it's the protected namespace
                            IDefinition baseType = baseExpr.resolveType(project);
                            Set<INamespaceDefinition> nsset = ImmutableSet.of((INamespaceDefinition)ns);
                            nsset = scope.adjustNamespaceSetForSuper(baseType, nsset);
                            // We only started with 1 namespace, so we know that's how many we have
                            ns = (NamespaceDefinition)nsset.iterator().next();
                        }
                    }
                    // If the qualifier is the any namespace, then we want a null nsset
                    // instead of a nsset of length 1, with a null namespace in it.
                    if( ns == NamespaceDefinition.getAnyNamespaceReference() )
                        namespaceSet = null;
                    else
                        namespaceSet = new Nsset(ns.getAETNamespace());
                }
                else
                {
                    // qualifier resolve to 1+ namespaces, so emit a multiname
                    Set<INamespaceDefinition> nsset = qual.getNamespaceSet();
                    nameKind = isAttributeIdentifier() ? CONSTANT_MultinameA : CONSTANT_Multiname;

                    namespaceSet = SemanticUtils.convertSetINamespaceToNsset(nsset);
                }
            }
            else
            {
                namespaceSet = null;
                nameKind = isAttributeIdentifier() ? CONSTANT_RTQnameA : CONSTANT_RTQname;
            }

            return new Name(nameKind, namespaceSet, getName());
        }

        Name name = null;

        if (isMemberRef())
        {
            ExpressionNodeBase baseExpr = getBaseExpression();
            if (baseExpr != null)
            {
                // Handle the case where we look like a member expression, but the base expression is really
                // a reference to a package.  For example 'a.b.c.Foo' where a.b.c is a known package name.
                // This needs to generate a QName with a.b.c as the qualifier.
                if (baseIsPackage())
                {
                    String packageName = baseExpr.computeSimpleReference();
                    Workspace workspace = (Workspace)project.getWorkspace();
                    INamespaceReference qualifier = workspace.getPackageNamespaceDefinitionCache().get(packageName, false);

                    return new Name(isAttributeIdentifier() ? CONSTANT_QnameA : CONSTANT_Qname,
                            new Nsset(qualifier.resolveAETNamespace(project)), getName());
                }

                Set<INamespaceDefinition> namespaceSet = null;
                IDefinition baseType = baseExpr.resolveType(project);

                // If our base type is an interface,  then we need to use the special
                // interface namespace set (the namespace of the interface, plus the namespaces for all the interfaces
                // it extends)
                if (baseType instanceof InterfaceDefinition)
                {
                    namespaceSet = ((InterfaceDefinition)baseType).getInterfaceNamespaceSet(project);
                }
                else if (baseExpr instanceof LanguageIdentifierNode &&
                         ((LanguageIdentifierNode)baseExpr).getKind() == LanguageIdentifierKind.SUPER)
                {
                    namespaceSet = scope.getNamespaceSetForSuper(project, baseType);
                }

                if (namespaceSet != null)
                    return makeName(namespaceSet, getName(), isAttributeIdentifier());
            }
        }

        if (isNameNode())
        {
            BaseDefinitionNode defNode = getParentAsDefinition();
            name = defNode.getDefinition().getMName(project);
        }
        else if (scope != null)
        {

            Set<INamespaceDefinition> namespaceSet = null;
            if (isMemberRef())
            {
                // Member refs just use the open namespace set
                namespaceSet = scope.getNamespaceSet(project);
            }
            else
            {
                // lexical refs may be influenced by the imports
                namespaceSet = scope.getNamespaceSetForName(project, getName());
            }

            name = makeName(namespaceSet, getName(), isAttributeIdentifier());
        }
View Full Code Here

            // Get the class this definition is in
            IClassDefinition containingClass = (IClassDefinition)this.getAncestorOfType(IClassDefinition.class);

            // Grab the scope the fromNode uses to resolve itself, and walk
            // up the containing scopes looking for an instance scope
            ASScope fromScope = fromNode.getASScope();
            while( fromScope != null )
            {
                if( fromScope instanceof ScopeView )
                {
                    // return true if we hit an instance scope, and it's for the same
                    // class as this definition is in
                    return ((ScopeView)fromScope).isInstanceScope()
                            && fromScope.getDefinition() == containingClass;
                }
                fromScope = fromScope.getContainingScope();
            }
        }
        return false;
    }
View Full Code Here

TOP

Related Classes of org.apache.flex.compiler.internal.scopes.ASScope

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.