Package org.apache.flex.compiler.internal.definitions

Examples of org.apache.flex.compiler.internal.definitions.ClassDefinition


        }
    }

    private void processRootTag(MXMLTreeBuilder builder, IMXMLTagData rootTag, IMXMLTextData asDoc)
    {
        ClassDefinition fileDef = fileScope.getMainClassDefinition();
        assert fileDef != null;

        IDefinition tagDef = builder.getFileScope().resolveTagToDefinition(rootTag);

        // Report a problem if the root tag doesn't map to a definition.
        if (tagDef == null)
        {
            ICompilerProblem problem = new MXMLUnresolvedTagProblem(rootTag);
            builder.addProblem(problem);
            return;
        }

        // Report a problem if that definition isn't for a class.
        if (!(tagDef instanceof IClassDefinition))
        {
            ICompilerProblem problem = new MXMLNotAClassProblem(rootTag, tagDef.getQualifiedName());
            builder.addProblem(problem);
            return;
        }

        IClassDefinition tagDefinition = (IClassDefinition)tagDef;

        // Report a problem if that class is final.
        if (tagDefinition != null && tagDefinition.isFinal())
        {
            ICompilerProblem problem = new MXMLFinalClassProblem(rootTag, tagDef.getQualifiedName());
            builder.addProblem(problem);
            return;
        }

        // Report a problem is that class's constructor has required parameters.
        IFunctionDefinition constructor = tagDefinition.getConstructor();
        if (constructor != null && constructor.hasRequiredParameters())
        {
            ICompilerProblem problem = new MXMLConstructorHasParametersProblem(rootTag, tagDef.getQualifiedName());
            builder.addProblem(problem);
            return;
        }

        documentNode = new MXMLDocumentNode(this);
        documentNode.setClassReference(project, tagDefinition);
        documentNode.setClassDefinition(fileDef);
        documentNode.initializeFromTag(builder, rootTag);
       
        if (asDoc != null)
        {
            IASDocComment asDocComment = builder.getWorkspace().getASDocDelegate().createASDocComment(asDoc, tagDefinition);
            documentNode.setASDocComment(asDocComment);
        }

        fileDef.setNode(documentNode);
        // TODO setNode() sets the nameStart and nameEnd to -1
        // Fix setNode() to set the values properly
        // From MXMLScopeBuilder - CM clients expect the name start of the root class definition to be at 0.
        if (fileDef.getNameStart() == -1 && fileDef.getNameEnd() == -1)
            fileDef.setNameLocation(0, 0);
    }
View Full Code Here


                builder.addProblem(problem);
            }

            // Find the ClassDefinition that was created for the component class.
            MXMLFileScope fileScope = builder.getFileScope();
            ClassDefinition fxComponentClassDefinition =
                    fileScope.getClassDefinitionForComponentTag(tag);

            assert fxComponentClassDefinition != null : "MXMLScopeBuilder failed to build a class for an fx:Component";

            // attach scope with the component class definition node.
            TypeScope componentClassScope = (TypeScope)fxComponentClassDefinition.getContainedScope();
            containedClassDefinitionNode.setScope(componentClassScope); // TODO Move this logic to initializeFromTag().

            // Connect node to definitions and vice versa.
            containedClassDefinitionNode.setClassReference(project, tagDefinition); // TODO Move this logic to initializeFromTag().
            containedClassDefinitionNode.setClassDefinition(fxComponentClassDefinition); // TODO Move this logic to initializeFromTag().

            int nameStart = fxComponentClassDefinition.getNameStart();
            int nameEnd = fxComponentClassDefinition.getNameEnd();
            fxComponentClassDefinition.setNode(containedClassDefinitionNode);
            // TODO The above call is setting nameStart and nameEnd to -1
            // because the MXML class definition node doesn't have a name expression node.
            // We need to reset the correct nameStart and nameEnd.
            fxComponentClassDefinition.setNameLocation(nameStart, nameEnd);

            containedClassDefinitionNode.initializeFromTag(builder, childTag);
        }
        if (!handled)
        {
View Full Code Here

            IDefinition objectDef = objectReference.resolve(flexProject);
            if ((objectDef == null) || (!(objectDef instanceof ClassDefinition)))
                return false;

            ClassDefinition objectClassDef = (ClassDefinition)objectDef;

            // Generates a Style's class
            // Generated class name will be of the form _MyApplication_Styles
            // Eg:
            // public class _MyApplication_Styles
View Full Code Here

            return true;
        }
       
        private boolean computeGenerateSystemManagerAndFlexInit()
        {
            ClassDefinition rootClassDef = (ClassDefinition)mainApplicationClassDefinition;
            ClassDefinition rootFactoryClass = rootClassDef.resolveInheritedFactoryClass(flexProject);
            generateSystemManagerAndFlexInit =
                (rootFactoryClass != null) && (!rootClassDef.hasOwnFactoryClass(flexProject.getWorkspace()));

            return generateSystemManagerAndFlexInit;
        }
View Full Code Here

            return generateSystemManagerAndFlexInit;
        }
       
        public boolean isFlexInfo(ClassDefinition rootClassDef)
        {
            ClassDefinition superClass = (ClassDefinition)rootClassDef.resolveBaseClass(flexProject);
            String impls[] = superClass.getImplementedInterfacesAsDisplayStrings();
            for (String impl : impls)
            {
                if (impl.contains(".IFlexInfo"))
                {
                    return true;
View Full Code Here

            if (rootNode != null)
                return rootNode;

            ASProjectScope projectScope = flexProject.getScope();
           
            ClassDefinition mainClassDef = (ClassDefinition) mainApplicationClassDefinition;
            if (mainClassDef.hasOwnFactoryClass(flexProject.getWorkspace()))
                return null;

            ICompilationUnit mainUnit = projectScope.getCompilationUnitForDefinition(mainClassDef);
            IRequest<ISyntaxTreeRequestResult, ICompilationUnit> request = mainUnit.getSyntaxTreeRequest();
            ISyntaxTreeRequestResult result = request.get();
View Full Code Here

            Name stylesClassName = new Name(getStylesClassName());

            IDefinition objectDef = objectReference.resolve(flexProject);
            if ((objectDef == null) || (!(objectDef instanceof ClassDefinition)))
                return false;
            ClassDefinition objectClassDef = (ClassDefinition)objectDef;
           
           
            // Generate code for the constructor:
            // public function ClassName()
            // {
            //    super();
            // }
            InstructionList classITraitsInit = new InstructionList();
            classITraitsInit.addInstruction(ABCConstants.OP_getlocal0);
            classITraitsInit.addInstruction(ABCConstants.OP_constructsuper, 0);
            classITraitsInit.addInstruction(ABCConstants.OP_returnvoid);
            ClassGeneratorHelper classGen = new ClassGeneratorHelper(flexProject, emitter, flexInitClassName,
                    objectClassDef, Collections.<Name>emptyList(), classITraitsInit);
           
            // Generate code for the static init method:
            // public static function init(mf : IFlexModuleFactory) : void
            // {
            //    new ChildManager(mf);
            //    var local2 : * = new StyleManagerImpl(mf);
            //
            //    // For each effect declared in the application:
            //    EffectManager.mx_internal::registerEffectTrigger(<effectName>, <eventName>);
            //
            //    // For each remote class alias declared in the application
            //    try
            //    {
            //        if (flash.net.getClassByAlias(<remote class alias>) != <class>)
            //        {
            //            flash.net.registerClassAlias(<remote class alias>, <class>);
            //        }
            //    }
            //    catch (e:Error)
            //    {
            //        flash.net.registerClassAlias(<remote class alias>, <class>);
            //    }
            //
            //    var local3 : * = [<names of all inheriting styles declared in the application>];
            //
            //    for each (var local0 : * in local3)
            //    {
            //        local2.registerInheritingStyle(local0);  // local2 is the style manager.
            //    }
            // }
            if (isAppFlexInfo)
            {
                MethodInfo initMethodInfo = new MethodInfo();
                initMethodInfo.setMethodName("FlexInit init method");
                initMethodInfo.setParamTypes(new Vector<Name>(Collections.singleton(new Name("Object"))));
                initMethodInfo.setReturnType(new Name(IASLanguageConstants.void_));
                IMethodVisitor initMethodVisitor = emitter.visitMethod(initMethodInfo);
                initMethodVisitor.visit();
                MethodBodyInfo initMethodBodyInfo = new MethodBodyInfo();
                initMethodBodyInfo.setMethodInfo(initMethodInfo);
                IMethodBodyVisitor initMethodBodyVisitor = initMethodVisitor.visitBody(initMethodBodyInfo);
                initMethodBodyVisitor.visit();
               
                // local0 = temp
                // local1 = module factory argument
                // local2 = style manager
                // local3 = inherited styles array
                InstructionList initMethod = new InstructionList();
                initMethod.addInstruction(ABCConstants.OP_returnvoid);
               
                initMethodBodyVisitor.visitInstructionList(initMethod);
                initMethodBodyVisitor.visitEnd();
                initMethodVisitor.visitEnd();
               
                ITraitVisitor initMethodTraitVisitor =
                    classGen.getCTraitsVisitor().visitMethodTrait(ABCConstants.TRAIT_Method, new Name("init"), 0, initMethodInfo);
                initMethodTraitVisitor.visitStart();
                initMethodTraitVisitor.visitEnd();

                codegenInfoMethod(classGen,
                        flexProject.getCompatibilityVersion(),
                        getMainClassQName(),
                        getPreloaderClassReference(),
                        getRuntimeDPIProviderClassReference(),
                        splashScreenImage,
                        getRootNode(),
                        getTargetAttributes(),
                        flexProject.getLocales(),
                        frame1Info,
                        accessibleClassNames,
                        getFlexInitClassName(),
                        getStylesClassName(),
                        targetSettings.getRuntimeSharedLibraries(),
                        rslInfo,
                        problems,
                        isAppFlexInfo);
               
            }
            else
            {
                MethodInfo initMethodInfo = new MethodInfo();
                initMethodInfo.setMethodName("FlexInit init method");
                initMethodInfo.setParamTypes(new Vector<Name>(Collections.singleton(iModuleFactoryReference.getMName())));
                initMethodInfo.setReturnType(new Name(IASLanguageConstants.void_));
                IMethodVisitor initMethodVisitor = emitter.visitMethod(initMethodInfo);
                initMethodVisitor.visit();
                MethodBodyInfo initMethodBodyInfo = new MethodBodyInfo();
                initMethodBodyInfo.setMethodInfo(initMethodInfo);
                IMethodBodyVisitor initMethodBodyVisitor = initMethodVisitor.visitBody(initMethodBodyInfo);
                initMethodBodyVisitor.visit();
               
                // local0 = temp
                // local1 = module factory argument
                // local2 = style manager
                // local3 = inherited styles array
                InstructionList initMethod = new InstructionList();
               
                // Since we don't need "this", we can kill local0, we'll use it later for something else.
                initMethod.addInstruction(ABCConstants.OP_kill, 0);
                initMethod.addInstruction(ABCConstants.OP_finddef, childManagerReference.getMName());
                initMethod.addInstruction(ABCConstants.OP_getlocal1);
                initMethod.addInstruction(ABCConstants.OP_constructprop, new Object[] { childManagerReference.getMName(), 1 });
                initMethod.addInstruction(ABCConstants.OP_pop);
                initMethod.addInstruction(ABCConstants.OP_finddef, styleManagerImplReference.getMName());
                initMethod.addInstruction(ABCConstants.OP_getlocal1);
                initMethod.addInstruction(ABCConstants.OP_constructprop, new Object[] { styleManagerImplReference.getMName(), 1 });
                initMethod.addInstruction(ABCConstants.OP_setlocal2);
               
                Map<String, String> effectNameToTriggerMap = new TreeMap<String, String>();
                Map<String, Boolean> inheritingStyleMap = new TreeMap<String, Boolean>();
                Map<ClassDefinition, String> remoteClassAliasMap =
                    new TreeMap<ClassDefinition, String>(new Comparator<ClassDefinition>()
                    {
                        @Override
                        public int compare(ClassDefinition o1, ClassDefinition o2)
                        {
                            return o1.getQualifiedName().compareTo(o2.getQualifiedName());
                        }
                    })
                    {
                        private static final long serialVersionUID = 1L;
   
                        /**
                         *  Override so warning messages can be logged.
                         */
                        @Override
                        public String put(ClassDefinition key, String value)
                        {
                            // check for duplicate values and log a warning if any remote
                            // classes try to use the same alias.
                            if (containsValue(value))
                            {
                               for (Map.Entry<ClassDefinition,String> entry  : entrySet())
                               {
                                   if (value != null && value.equals(entry.getValue()))
                                   {
                                       problems.add(new ClassesMappedToSameRemoteAliasProblem(key.getQualifiedName(),
                                               entry.getKey().getQualifiedName(), value));
                                       break;
                                   }
                               }
                            }
                            return super.put(key, value);
                        }
                    };
                   
                for (ICompilationUnit cu : emittedCompilationUnits)
                {
                    Collection<IDefinition> visibleDefs = cu.getFileScopeRequest().get().getExternallyVisibleDefinitions();
                    for (IDefinition visibleDef : visibleDefs)
                    {
                        if (visibleDef instanceof ClassDefinition)
                        {
                            ClassDefinition visibleClass = (ClassDefinition) visibleDef;
                            IEffectDefinition[] effectDefinitions = visibleClass.getEffectDefinitions(flexProject.getWorkspace());
                            for (IEffectDefinition effectDefinition : effectDefinitions)
                            {
                                // TODO create compiler problem if effect already has a trigger.
                                effectNameToTriggerMap.put(effectDefinition.getBaseName(), effectDefinition.getEvent());
                            }
                           
                            IStyleDefinition[] styleDefinitions = visibleClass.getStyleDefinitions(flexProject.getWorkspace());
                            for (IStyleDefinition styleDefinition : styleDefinitions)
                            {
                                boolean isInheriting = styleDefinition.isInheriting();
                                // TODO create compiler problem if style definitions conflict
                                inheritingStyleMap.put(styleDefinition.getBaseName(), isInheriting);
                            }
                           
                            String remoteClassAlias = visibleClass.getRemoteClassAlias();
                            if (remoteClassAlias != null)
                                remoteClassAliasMap.put(visibleClass, remoteClassAlias);
                        }
                    }
                }
View Full Code Here

        IDefinition parent = def.getParent();

        if ( namespace != null && parent instanceof ClassDefinition )
        {
            // Iterate over the superclasses of this method's class.
            ClassDefinition cls  = (ClassDefinition)parent;
            ClassDefinition base = (ClassDefinition)cls.resolveBaseClass(project);

            if (base != null)
            {
                // Adjust the namespace if this is the protected namespace
                INamespaceDefinition protectedNS = cls.getProtectedNamespaceReference().resolveNamespaceReference(project);
                if (namespace.equals(protectedNS))
                    namespace = base.getProtectedNamespaceReference().resolveNamespaceReference(project);
            }
        }

        return namespace;
    }
View Full Code Here

     */
    public static ASScope getClassScope(IASNode iNode, ICompilerProject project)
    {
        if ( isInInstanceFunction(iNode, project) || isInStaticClassFunction(iNode, project) )
        {
            ClassDefinition class_def = (ClassDefinition) getEnclosingFunctionDefinition(iNode, project).getAncestorOfType(ClassDefinition.class);
            if ( class_def != null )
                return class_def.getContainedScope();
        }

        return null;
    }
View Full Code Here

                    IDefinition d = instanceNode.resolveID();
                    // Only create reference var if it isn't already declared on base class
                    // Look for a property with the same name as this function in the base class
                    // the lookup will search up the inheritance chain, so we don't have to worry about
                    // walking up the inheritance chain here.
                    ClassDefinition base = (ClassDefinition)classDefinition.resolveBaseClass(getProject());

                    if (base != null)
                    {
                        IDefinition baseDef = base.getContainedScope().getQualifiedPropertyFromDef(
                            getProject(), base, d.getBaseName(), NamespaceDefinition.getPublicNamespaceDefinition(), false);
                        if (baseDef == null)
                            addBindableVariableTrait(idName, instanceClassName, d);
                        //else
                        //    System.out.println("not adding bindable variable trait for " + d.getBaseName() + " in " + instanceClassName);
View Full Code Here

TOP

Related Classes of org.apache.flex.compiler.internal.definitions.ClassDefinition

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.