Package org.apache.flex.compiler.internal.abc

Examples of org.apache.flex.compiler.internal.abc.ClassGeneratorHelper


            final InstructionList cinit = cssCodeGenResult.getClassInitializationInstructions();
            assert cinit.canFallThrough() : "CSSReducer should not append 'returnvoid' to the initialization instructions.";
            cinit.addInstruction(ABCConstants.OP_returnvoid);

            ClassGeneratorHelper classGenerator = new ClassGeneratorHelper(
                        flexProject,
                        emitter,
                        stylesClassName,
                        objectClassDef,
                        Collections.<Name> emptyList(),
                        Collections.<Name> emptyList(),
                        ClassGeneratorHelper.returnVoid(),
                        cinit,
                        false);
            cssCodeGenResult.visitClassTraits(classGenerator.getCTraitsVisitor());

            classGenerator.finishScript();

            DoABCTag tag = new DoABCTag();
            tag.setABCData(emitter.emit());
            tag.setName("defaults.css and theme CSS data");
            frame.addTag(tag);
View Full Code Here


                     flexProject.getWorkspace(), className);

            ABCEmitter emitter = new ABCEmitter();
            emitter.visit(ABCConstants.VERSION_ABC_MAJOR_FP10, ABCConstants.VERSION_ABC_MINOR_FP10);

            ClassGeneratorHelper classGen = new ClassGeneratorHelper(flexProject, emitter,
                     mainClassRef.getMName(),
                     (ClassDefinition)flexProject.getBuiltinType(BuiltinType.OBJECT),
                     ClassGeneratorHelper.returnVoid());

            //Create method body for compiledLocales getter
            InstructionList localesInstructionList = new InstructionList();

            for (String locale : locales)
            {
                localesInstructionList.addInstruction(ABCConstants.OP_pushstring, locale);
            }

            localesInstructionList.addInstruction(ABCConstants.OP_newarray, locales.size());
            localesInstructionList.addInstruction(ABCConstants.OP_returnvalue);

            classGen.addCTraitsGetter(new Name("compiledLocales"),
                    new Name(IASLanguageConstants.Array), localesInstructionList);

            //Create method body for compiledLocales getter
            InstructionList bundlesInstructionList = new InstructionList();

            for (String bundleName : frame1Info.compiledResourceBundleNames)
            {
                bundlesInstructionList.addInstruction(ABCConstants.OP_pushstring, bundleName);
            }

            bundlesInstructionList.addInstruction(ABCConstants.OP_newarray, frame1Info.compiledResourceBundleNames.size());
            bundlesInstructionList.addInstruction(ABCConstants.OP_returnvalue);

            classGen.addCTraitsGetter(new Name("compiledResourceBundleNames"),
                    new Name(IASLanguageConstants.Array), bundlesInstructionList);      
           
            //Generate script      
            classGen.finishScript();
           
            DoABCTag doABC = new DoABCTag();
            try
            {
                doABC.setABCData(emitter.emit());
View Full Code Here

            // }
            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);
                        }
                    }
                }
               
                // register effects
                if (!effectNameToTriggerMap.isEmpty())
                {
                    IDefinition mxInternalDef = mxInternalReference.resolve(flexProject);
                    if (!(mxInternalDef instanceof NamespaceDefinition))
                        return false;
                   
                   
                    IResolvedQualifiersReference registerEffectTriggerRef =
                        ReferenceFactory.resolvedQualifierQualifiedReference(flexProject.getWorkspace(), (INamespaceDefinition)mxInternalDef,
                                "registerEffectTrigger");
                    Name registerEffectTriggerName = registerEffectTriggerRef.getMName();
                   
                    initMethod.addInstruction(ABCConstants.OP_getlex, effectManagerReference.getMName());
                   
                    for (Map.Entry<String, String> effectEntry : effectNameToTriggerMap.entrySet())
                    {
                        initMethod.addInstruction(ABCConstants.OP_dup)// copy the effectManager class closure
                        initMethod.addInstruction(ABCConstants.OP_pushstring, effectEntry.getKey());
                        initMethod.addInstruction(ABCConstants.OP_pushstring, effectEntry.getValue());
                        initMethod.addInstruction(ABCConstants.OP_callpropvoid, new Object[] { registerEffectTriggerName, 2 });
                    }
                    initMethod.addInstruction(ABCConstants.OP_pop);
                   
                }
               
                // Initialize AccessibilityClasses. Below is example code. Each
                // accessibility class found by the compiler will have its
                // enableAccessibility() method called.
                //
                // if (Capabilities.hasAccessibility) {
                //    spark.accessibility.TextBaseAccImpl.enableAccessibility();
                //    mx.accessibility.UIComponentAccProps.enableAccessibility();
                //    spark.accessibility.ButtonBaseAccImpl.enableAccessibility();
                // }
                if (targetSettings.isAccessible())
                {
                    Name capabilitiesSlotName = capabilitiesReference.getMName();
                    initMethod.addInstruction(ABCConstants.OP_findpropstrict, capabilitiesSlotName);
                    initMethod.addInstruction(ABCConstants.OP_getproperty, capabilitiesSlotName);
                    initMethod.addInstruction(ABCConstants.OP_getproperty, new Name("hasAccessibility"));
                    Label accessibilityEnd = new Label();
                    initMethod.addInstruction(ABCConstants.OP_iffalse, accessibilityEnd);
   
                    IResolvedQualifiersReference enableAccessibilityReference = ReferenceFactory.packageQualifiedReference(flexProject.getWorkspace(),
                            "enableAccessibility");           
                    Name enableAccessibilityName = enableAccessibilityReference.getMName();
                    Object[] enableAccessibilityCallPropOperands = new Object[] { enableAccessibilityName, 0 };
                    for (String accessibilityClassName : accessibleClassNames)
                    {
                        IResolvedQualifiersReference ref = ReferenceFactory.packageQualifiedReference(flexProject.getWorkspace(),
                                accessibilityClassName);
                        Name accName = ref.getMName();
                        initMethod.addInstruction(ABCConstants.OP_getlex, accName);
                        initMethod.addInstruction(ABCConstants.OP_callproperty, enableAccessibilityCallPropOperands);
                        initMethod.addInstruction(ABCConstants.OP_pop);
                    }
   
                    initMethod.labelNext(accessibilityEnd);
                }
               
                // register class aliases
                if (!remoteClassAliasMap.isEmpty())
                {
                    Name getClassByAliasName = getClassByAliasReference.getMName();
                    Name registerClassAliasName = registerClassAliasReference.getMName();
                    Object[] getClassByAliasCallPropOperands = new Object[] { getClassByAliasName, 1 };
                    Object [] registerClassAliasCallPropOperands = new Object[] { registerClassAliasName, 2 };
                    for (Map.Entry<ClassDefinition, String> classAliasEntry : remoteClassAliasMap.entrySet())
                    {
                        Label tryLabel = new Label();
                        initMethod.labelNext(tryLabel);
                        initMethod.addInstruction(ABCConstants.OP_finddef, getClassByAliasName);
                        initMethod.addInstruction(ABCConstants.OP_pushstring, classAliasEntry.getValue());
                        initMethod.addInstruction(ABCConstants.OP_callproperty, getClassByAliasCallPropOperands);
                        Name classMName = classAliasEntry.getKey().getMName(flexProject);
                        initMethod.addInstruction(ABCConstants.OP_getlex, classMName);
                        Label endTryLabel = new Label();
                        initMethod.addInstruction(ABCConstants.OP_ifeq, endTryLabel);
                        initMethod.addInstruction(ABCConstants.OP_finddef, registerClassAliasName);
                        initMethod.addInstruction(ABCConstants.OP_pushstring, classAliasEntry.getValue());
                        initMethod.addInstruction(ABCConstants.OP_getlex, classMName);
                        initMethod.addInstruction(ABCConstants.OP_callpropvoid, registerClassAliasCallPropOperands);
                        initMethod.labelNext(endTryLabel);
                        Label afterCatch = new Label();
                        initMethod.addInstruction(ABCConstants.OP_jump, afterCatch);
                        Label catchLabel = new Label();
                        initMethod.labelNext(catchLabel);
                        initMethod.addInstruction(ABCConstants.OP_pop);
                        initMethod.addInstruction(ABCConstants.OP_finddef, registerClassAliasName);
                        initMethod.addInstruction(ABCConstants.OP_pushstring, classAliasEntry.getValue());
                        initMethod.addInstruction(ABCConstants.OP_getlex, classMName);
                        initMethod.addInstruction(ABCConstants.OP_callpropvoid, registerClassAliasCallPropOperands);
                        initMethod.labelNext(afterCatch);
                        initMethodBodyVisitor.visitException(tryLabel, endTryLabel, catchLabel,
                                new Name(IASLanguageConstants.Error), null);
                    }
                }
               
                // register inheriting styles
                if (!inheritingStyleMap.isEmpty())
                {
                    initMethod.addInstruction(ABCConstants.OP_getlex, stylesClassName);
                    int count = 0;
                    for (Map.Entry<String, Boolean> styleEntry : inheritingStyleMap.entrySet())
                    {
                        if (styleEntry.getValue().booleanValue())
                        {
                            ++count;
                            initMethod.addInstruction(ABCConstants.OP_pushstring, styleEntry.getKey());
                        }
                    }
                   
                    initMethod.addInstruction(ABCConstants.OP_newarray, count);
                    initMethod.addInstruction(ABCConstants.OP_setproperty, new Name("inheritingStyles"));
   
                }
   
                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();
            }
            classGen.finishScript();
           
            DoABCTag doABC = new DoABCTag();
            try
            {
                doABC.setABCData(emitter.emit());
View Full Code Here

                classITraitsInit.addInstruction(ABCConstants.OP_setproperty, new Name("compatibilityVersionString"));
            }
            classITraitsInit.addInstruction(ABCConstants.OP_getlocal0);
            classITraitsInit.addInstruction(ABCConstants.OP_constructsuper, 0);
            classITraitsInit.addInstruction(ABCConstants.OP_returnvoid);
            ClassGeneratorHelper classGen = new ClassGeneratorHelper(flexProject, emitter, generatedSystemManagerName, systemManagerClass, implementedInterfaces, classITraitsInit);

            final FlexRSLInfo rslInfo = getRSLInfo();
           
            final FlexSplashScreenImage splashScreenImage = getSplashScreenImage();
           
            // Codegen various methods
            codegenCallInContextMethod(classGen, true);
            codegenCreateMethod(classGen, ((DefinitionBase)mainApplicationClassDefinition).getMName(flexProject));
            codegenInfoMethod(classGen,
                    flexProject.getCompatibilityVersion(),
                    getMainClassQName(),
                    getPreloaderClassReference(),
                    getRuntimeDPIProviderClassReference(),
                    splashScreenImage,
                    getRootNode(),
                    getTargetAttributes(),
                    flexProject.getLocales(),
                    frame1Info,
                    accessibleClassNames,
                    getFlexInitClassName(),
                    getStylesClassName(),
                    targetSettings.getRuntimeSharedLibraries(),
                    rslInfo,
                    problemCollection,
                    false);
           
            classGen.finishScript();

            DoABCTag doABC = new DoABCTag();
            try
            {
                doABC.setABCData(emitter.emit());
View Full Code Here

               
                constructorInstructionList.addInstruction(ABCConstants.OP_newarray, resourceBundleCount);
                constructorInstructionList.addInstruction(ABCConstants.OP_constructsuper, 1);
                constructorInstructionList.addInstruction(ABCConstants.OP_returnvoid);
               
                ClassGeneratorHelper classGen = new ClassGeneratorHelper(flexProject, emitter,
                        new Name(qname),
                        (ClassDefinition)resourceModuleBaseRef.resolve(flexProject),
                        Collections.<Name> emptyList(),
                        constructorInstructionList);

                classGen.finishScript();
                generatedBytes = emitter.emit();
            }
            catch (Throwable ex)
            {
                problems.add(new InternalCompilerProblem(ex));
View Full Code Here

                                         final Name mainClassName)
    {
        final IDefinition styleModuleBaseDefinition = project.resolveQNameToDefinition("StyleModuleBase");
        if (styleModuleBaseDefinition instanceof ClassDefinition)
        {
            final ClassGeneratorHelper helper = new ClassGeneratorHelper(
                    project,
                    emitter,
                    mainClassName,
                    (ClassDefinition)styleModuleBaseDefinition,
                    ClassGeneratorHelper.returnVoid());
            helper.finishScript();
        }
        else
        {
            throw new IllegalStateException("Unable to resolve 'StyleModuleBase' for CSS module.");
        }
View Full Code Here

        final CSSEmitter cssEmitter = new CSSEmitter(reducer);
        cssEmitter.burm(cssDocument);
       
        final InstructionList cinit = reducer.getClassInitializationInstructions();
        cinit.addInstruction(ABCConstants.OP_returnvoid);
        final ClassGeneratorHelper helper = new ClassGeneratorHelper(
                project,
                abcEmitter,
                stylesDataClassName,
                (ClassDefinition)project.resolveQNameToDefinition(IASLanguageConstants.Object),
                Collections.<Name>emptyList(),
                Collections.<Name>emptyList(),
                ClassGeneratorHelper.returnVoid(),
                cinit,
                false);
        reducer.visitClassTraits(helper.getCTraitsVisitor());
        helper.finishScript();
    }
View Full Code Here

       
        IResolvedQualifiersReference mainClassRef = ReferenceFactory.packageQualifiedReference(
                project.getWorkspace(), qualifiedClassName);
       
        ClassGeneratorHelper classGen = new ClassGeneratorHelper(project, emitter,
                mainClassRef.getMName(),
                (ClassDefinition)resourceBundleReference.resolve(project),
                Collections.<Name> emptyList(), Collections.<Name> emptyList(),
                constructorInstructionList, true);

        //Create method body for getContents
        InstructionList bodyInstructionList = new InstructionList();
        bodyInstructionList.addInstruction(ABCConstants.OP_getlocal0);
        bodyInstructionList.addInstruction(ABCConstants.OP_pushscope);

        //Create key value pair entries "key":"value"
        int entryCount = 0;
        for (int i = 0; i < fileNode.getChildCount(); i++)
        {
            IASNode node = fileNode.getChild(i);
            if (node instanceof ResourceBundleEntryNode)
            {
                entryCount++;
                ResourceBundleEntryNode entryNode = (ResourceBundleEntryNode)node;

                //push key
                bodyInstructionList.addInstruction(ABCConstants.OP_pushstring, entryNode.getKeyNode().getValue());

                //push value
                ExpressionNodeBase valueNode = entryNode.getValueNode();
                switch (valueNode.getNodeID())
                {

                    case LiteralStringID:
                        bodyInstructionList.addInstruction(ABCConstants.OP_pushstring,
                                ((LiteralNode)valueNode).getValue());
                        break;

                    case ClassReferenceID:
                        ClassReferenceNode crn = (ClassReferenceNode)valueNode;
                        if (crn.getName() != null)
                        {

                            IResolvedQualifiersReference refClass = ReferenceFactory.packageQualifiedReference(project.getWorkspace(), crn.getName());

                            if (refClass.resolve(project, crn.getASScope(), DependencyType.EXPRESSION, true) == null)
                            {
                                ICompilerProblem problem = new UnresolvedClassReferenceProblem(crn, crn.getName());
                                problems.add(problem);
                            }
                        }
                        String className = crn.getName();
                        if(className == null)
                        {
                            bodyInstructionList.addInstruction(ABCConstants.OP_pushnull);
                        }
                        else
                        {
                            IResolvedQualifiersReference classRef = ReferenceFactory.packageQualifiedReference(
                                    project.getWorkspace(), className);

                            bodyInstructionList.addInstruction(ABCConstants.OP_getlex, classRef.getMName());
                        }
                       
                        break;

                    case EmbedID:
                        EmbedNode embedNode = (EmbedNode)valueNode;
                        try
                        {
                            String name = embedNode.getName(project, problems);
                            IResolvedQualifiersReference embedClassRef = ReferenceFactory.packageQualifiedReference(
                                    project.getWorkspace(), name);
                            bodyInstructionList.addInstruction(ABCConstants.OP_getlex, embedClassRef.getMName());
                        }
                        catch (InterruptedException ex)
                        {
                            problems.add(new CodegenInternalProblem(embedNode, ex));
                        }
                        break;

                    default:
                        //This shouldn't happen. Should we handle this case by collecting a problem?
                }
            }
        }

        bodyInstructionList.addInstruction(ABCConstants.OP_newobject, entryCount);
        bodyInstructionList.addInstruction(ABCConstants.OP_returnvalue);

        Name getContentsMethodName = new Name(ABCConstants.CONSTANT_Qname,
                new Nsset(classGen.getProtectedNamespace()), "getContent");

        //Create getContents method
        classGen.addITraitsMethod(getContentsMethodName, Collections.<Name> emptyList(),
                new Name(IASLanguageConstants.Object), Collections.<Object> emptyList(),
                false, false, true, bodyInstructionList);

        classGen.finishScript();
    }
View Full Code Here

            // }
            InstructionList classITraitsInit = new InstructionList();
            classITraitsInit.addInstruction(ABCConstants.OP_getlocal0);
            classITraitsInit.addInstruction(ABCConstants.OP_constructsuper, 0);
            classITraitsInit.addInstruction(ABCConstants.OP_returnvoid);
            ClassGeneratorHelper classGen = new ClassGeneratorHelper(project,
                    emitter,
                    generatedRootName,
                    (ClassDefinition)moduleFactoryInfo.moduleFactoryBaseClass,
                    Collections.<Name>emptyList(),
                    classITraitsInit);
            IResolvedQualifiersReference objectReference =
                ReferenceFactory.packageQualifiedReference(project.getWorkspace(),
                    IASLanguageConstants.Object);
           
            // Codegen various methods
            // TODO: Determine whether a override is needed or not depending on the
            // methods in the base class. Same deal for the Create and Info Methods.
            codegenCallInContextMethod(classGen, true);

            final FlexLibraryFrame1Info frame1Info =
                new FlexLibraryFrame1Info(flexProject, emittedCompilationUnits);
           
            // Override the create() and info() methods if we have embedded fonts.
            if (!frame1Info.embeddedFonts.isEmpty())
            {
                codegenCreateMethod(classGen, objectReference.getMName());
                codegenInfoMethod(classGen,
                        IASLanguageConstants.Object,
                        frame1Info,
                        accessibleClassNames,
                        problemCollection);           
            }
           
            classGen.finishScript();

            DoABCTag doABC = new DoABCTag();
            try
            {
                doABC.setABCData(emitter.emit());
View Full Code Here

        TypeDefinitionBase numberDef = (TypeDefinitionBase)project.getBuiltinType(BuiltinType.NUMBER);
        Name numberName = numberDef.getMName(project);

        // add all the member variables to the class
        ClassGeneratorHelper classGen = new ClassGeneratorHelper(project, emitter, className, baseClassDef, implementedInterfaces, classITraitsInit);

        // generate:
        // public function get borderMetrics():EdgeMetrics
        // {
        //     if (scale9Grid == null)
        //     {
        //         return EdgeMetrics.EMPTY;
        //     }
        //     else
        //     {
        //         return new EdgeMetrics(scale9Grid.left,
        //                                scale9Grid.top,
        //                                Math.ceil(measuredWidth - scale9Grid.right),
        //                                Math.ceil(measuredHeight - scale9Grid.bottom));
        //     }
        // }
        if (skinClassInfo.needsIBorder && skinClassInfo.needsBorderMetrics)
        {
            InstructionList body = new InstructionList();
            Name scale9Grid = new Name("scale9Grid");
            body.addInstruction(ABCConstants.OP_getlocal0);
            body.addInstruction(ABCConstants.OP_getproperty, scale9Grid);

            Label trueLabel = new Label();
            body.addInstruction(ABCConstants.OP_iftrue, trueLabel);

            Name edgeMetrics = ReferenceFactory.packageQualifiedReference(workspace, CORE_PACKAGE + ".EdgeMetrics").getMName();
            body.addInstruction(ABCConstants.OP_getlex, edgeMetrics);
            body.addInstruction(ABCConstants.OP_getproperty, new Name("EMPTY"));
            body.addInstruction(ABCConstants.OP_returnvalue);

            body.labelNext(trueLabel);
            body.addInstruction(ABCConstants.OP_findpropstrict, edgeMetrics);
           
            body.addInstruction(ABCConstants.OP_getlocal0);
            body.addInstruction(ABCConstants.OP_getproperty, scale9Grid);
            body.addInstruction(ABCConstants.OP_getproperty, new Name("left"));

            body.addInstruction(ABCConstants.OP_getlocal0);
            body.addInstruction(ABCConstants.OP_getproperty, scale9Grid);
            body.addInstruction(ABCConstants.OP_getproperty, new Name("top"));

            Name math = new Name("Math");
            body.addInstruction(ABCConstants.OP_getlex, math);
            body.addInstruction(ABCConstants.OP_getlocal0);

            body.addInstruction(ABCConstants.OP_getproperty, new Name("measuredWidth"));
            body.addInstruction(ABCConstants.OP_getlocal0);
            body.addInstruction(ABCConstants.OP_getproperty, scale9Grid);
            body.addInstruction(ABCConstants.OP_getproperty, new Name("right"));
            body.addInstruction(ABCConstants.OP_subtract);

            Object[] ceil = new Object[] {new Name("ceil"), 1};
            body.addInstruction(ABCConstants.OP_callproperty, ceil);
            body.addInstruction(ABCConstants.OP_getlex, math);
            body.addInstruction(ABCConstants.OP_getlocal0);

            body.addInstruction(ABCConstants.OP_getproperty, new Name("measuredHeight"));
            body.addInstruction(ABCConstants.OP_getlocal0);
            body.addInstruction(ABCConstants.OP_getproperty, scale9Grid);
            body.addInstruction(ABCConstants.OP_getproperty, new Name("bottom"));
            body.addInstruction(ABCConstants.OP_subtract);

            body.addInstruction(ABCConstants.OP_callproperty, ceil);
            body.addInstruction(ABCConstants.OP_constructprop, new Object[] {edgeMetrics, 4});
            body.addInstruction(ABCConstants.OP_returnvalue);

            classGen.addITraitsGetter(new Name("borderMetrics"), edgeMetrics, body);
        }

        if (skinClassInfo.needsIFlexDisplayObject)
        {
            // generate:
            // public function get measuredWidth():Number
            // {
            //     return _measuredWidth;
            // }
            if (skinClassInfo.needsMeasuredWidth)
            {
                InstructionList body = new InstructionList();
                body.addInstruction(ABCConstants.OP_getlocal0);
                body.addInstruction(ABCConstants.OP_getproperty, _measuredWidth);
                body.addInstruction(ABCConstants.OP_returnvalue);

                classGen.addMemberVariable(_measuredWidth, numberName);
                classGen.addITraitsGetter(new Name("measuredWidth"), numberName, body);
            }

            // generate:
            // public function get measuredHeight():Number
            // {
            //     return _measuredHeight;
            // }
            if (skinClassInfo.needsMeasuredHeight)
            {
                InstructionList body = new InstructionList();
                body.addInstruction(ABCConstants.OP_getlocal0);
                body.addInstruction(ABCConstants.OP_getproperty, _measuredHeight);
                body.addInstruction(ABCConstants.OP_returnvalue);

                classGen.addMemberVariable(_measuredHeight, numberName);
                classGen.addITraitsGetter(new Name("measuredHeight"), numberName, body);
            }

            // generate:
            // public function move(x:Number, y:Number):void
            // {
            //     this.x = x;
            //     this.y = y;
            // }
            if (skinClassInfo.needsMove)
            {
                InstructionList body = new InstructionList();

                body.addInstruction(ABCConstants.OP_getlocal0);
                body.addInstruction(ABCConstants.OP_getlocal1);
                body.addInstruction(ABCConstants.OP_setproperty, new Name("x"));

                body.addInstruction(ABCConstants.OP_getlocal0);
                body.addInstruction(ABCConstants.OP_getlocal2);
                body.addInstruction(ABCConstants.OP_setproperty, new Name("y"));

                body.addInstruction(ABCConstants.OP_returnvoid);

                Collection<Name> paramTypes = new ImmutableList.Builder<Name>()
                .add(numberName)
                .add(numberName)
                .build();

                classGen.addITraitsMethod(new Name("move"), paramTypes, new Name("void"), Collections.<Object>emptyList(), false, false, false, body);
            }

            // generate:
            // public function setActualSize(newWidth:Number, newHeight:Number):void
            // {
            //     if (width != newWidth)
            //     {
            //         width = newWidth;
            //     }
            //     if (height != newHeight)
            //     {
            //         height = newHeight;
            //     }
            // }
            if (skinClassInfo.needsSetActualSize)
            {
                InstructionList body = new InstructionList();

                Name width = new Name("width");
                body.addInstruction(ABCConstants.OP_getlocal0);
                body.addInstruction(ABCConstants.OP_getproperty, width);
                body.addInstruction(ABCConstants.OP_getlocal1);

                Label trueLabel = new Label();
                body.addInstruction(ABCConstants.OP_ifeq, trueLabel);

                body.addInstruction(ABCConstants.OP_findproperty, width);
                body.addInstruction(ABCConstants.OP_getlocal1);
                body.addInstruction(ABCConstants.OP_setproperty, width);

                body.labelNext(trueLabel);

                Name height = new Name("height");
                body.addInstruction(ABCConstants.OP_getlocal0);
                body.addInstruction(ABCConstants.OP_getproperty, height);
                body.addInstruction(ABCConstants.OP_getlocal2);

                trueLabel = new Label();
                body.addInstruction(ABCConstants.OP_ifeq, trueLabel);

                body.addInstruction(ABCConstants.OP_findproperty, height);
                body.addInstruction(ABCConstants.OP_getlocal2);
                body.addInstruction(ABCConstants.OP_setproperty, height);

                body.labelNext(trueLabel);

                body.addInstruction(ABCConstants.OP_returnvoid);

                Collection<Name> paramTypes = new ImmutableList.Builder<Name>()
                .add(numberName)
                .add(numberName)
                .build();

                classGen.addITraitsMethod(new Name("setActualSize"), paramTypes, new Name("void"), Collections.<Object>emptyList(), false, false, false, body);
            }
        }

        // generate:
        // override public function toString():String
        // {
        //     return NameUtil.displayObjectToString(this);
        // }
        if (!skinClassInfo.flexMovieClipOrSprite)
        {
            InstructionList body = new InstructionList();
            body.addInstruction(ABCConstants.OP_getlocal0);
            body.addInstruction(ABCConstants.OP_pushscope);

            Name nameUtil = ReferenceFactory.packageQualifiedReference(workspace, UTILS_PACKAGE + ".NameUtil").getMName();
            body.addInstruction(ABCConstants.OP_getlex, nameUtil);
            body.addInstruction(ABCConstants.OP_getlocal0);

            Object[] displayObjectToString = new Object[] { new Name("displayObjectToString"), 1 };
            body.addInstruction(ABCConstants.OP_callproperty, displayObjectToString);
            body.addInstruction(ABCConstants.OP_returnvalue);

            TypeDefinitionBase stringDef = (TypeDefinitionBase)project.getBuiltinType(BuiltinType.STRING);
            Name stringName = stringDef.getMName(project);
            classGen.addITraitsMethod(new Name("toString"), Collections.<Name>emptyList(), stringName, Collections.<Object>emptyList(), false, false, true, body);
        }

        classGen.finishScript();

        try
        {
            return emitter.emit();
        }
View Full Code Here

TOP

Related Classes of org.apache.flex.compiler.internal.abc.ClassGeneratorHelper

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.