Package org.apache.flex.compiler.internal.tree.as

Examples of org.apache.flex.compiler.internal.tree.as.ClassNode


        importNode = ImportNode.buildImportNode("flash.utils.ByteArray");
        packageContents.addItem(importNode);

        // generate the byte array class
        String byteArrayClassName = data.getQName() + byteArrayNamePostfix;
        ClassNode classNodeByteArray = new ClassNode(new IdentifierNode(byteArrayClassName));
        classNodeByteArray.setBaseClass(new IdentifierNode("ByteArrayAsset"));
        classNodeByteArray.setNamespace(new NamespaceIdentifierNode(INamespaceConstants.public_));
        packageContents.addItem(classNodeByteArray);

        // generate the movie class
        String movieClassName = data.getQName();
        ClassNode classNodeMovie = new ClassNode(new IdentifierNode(movieClassName));
        classNodeMovie.setBaseClass(new IdentifierNode(getBaseClassName()));
        classNodeMovie.setNamespace(new NamespaceIdentifierNode(INamespaceConstants.public_));
        packageContents.addItem(classNodeMovie);
        ScopedBlockNode classNodeMovieContents = classNodeMovie.getScopedNode();

        // generate: private static var bytes:ByteArray = null;
        VariableNode variableNodeBytes = new VariableNode(new IdentifierNode("bytes"));
        variableNodeBytes.setNamespace(new NamespaceIdentifierNode(INamespaceConstants.private_));
        variableNodeBytes.addModifier(new ModifierNode(IASKeywordConstants.STATIC));
        variableNodeBytes.setType(null, new IdentifierNode("ByteArray"));
        ASToken assignToken = new ASToken(ASTokenTypes.TOKEN_OPERATOR_ASSIGNMENT, -1, -1, -1, -1, "=");
        ASToken nullToken = new ASToken(ASTokenTypes.TOKEN_KEYWORD_NULL, -1, -1, -1, -1, IASKeywordConstants.NULL);
        LiteralNode nullNode = new LiteralNode(LiteralType.NULL, nullToken);
        variableNodeBytes.setAssignedValue(assignToken, nullNode);
        classNodeMovieContents.addItem(variableNodeBytes);

        // build the constructor
        IdentifierNode constructorNameNode = new IdentifierNode(movieClassName);
        constructorNameNode.setReferenceValue(classNodeMovie.getDefinition());
        FunctionNode constructorNode = new FunctionNode(null, constructorNameNode);
        constructorNode.setNamespace(new NamespaceIdentifierNode(INamespaceConstants.public_));
        ScopedBlockNode constructorContents = constructorNode.getScopedNode();

        // generate: super();
View Full Code Here


    {
        ITypeNode typeNode = this.getNode();
        IASNode site = typeNode;
        if (typeNode instanceof ClassNode)
        {
            ClassNode clsNode = (ClassNode)typeNode;
            IExpressionNode interfs[] = clsNode.getImplementedInterfaceNodes();
            site = interfs[i];
        }
        return site;
    }
View Full Code Here

        {
            IRequest<ISyntaxTreeRequestResult, ICompilationUnit> syntaxTreeRequest = this.syntaxTreeRequest.get();
           
            boolean isBindable = false;
            PackageNode pkg = null;
            ClassNode classNode = null;
            IMetaInfo[] metaInfos = null;
            final FileNode ast = createFileNode(getRootFileSpecification());
            if (this.getProject() instanceof FlexProject)
            {
                IASNode child = ast.getChild(0);
                if (child instanceof PackageNode)
                {
                    pkg = (PackageNode)child;
                    IDefinitionNode[] memberNodes = pkg.getAllMemberDefinitionNodes();
                    if (memberNodes.length > 0 && memberNodes[0] instanceof ClassNode)
                    {
                        classNode = (ClassNode)memberNodes[0];
                        memberNodes = classNode.getAllMemberNodes();
                        metaInfos = pkg.getMetaInfos();
                        for (IMetaInfo metaInfo : metaInfos)
                        {
                            String name = metaInfo.getTagName();
                            if (name.equals("Bindable"))
                            {
                                isBindable = true;
                                break;
                            }
                        }
                    }
                    if (!isBindable)
                    {
                        for (IDefinitionNode memberNode : memberNodes)
                        {
                            if (memberNode instanceof BaseDefinitionNode)
                            {
                                BaseDefinitionNode bdn = (BaseDefinitionNode)memberNode;
                                metaInfos = bdn.getMetaInfos();
                                for (IMetaInfo metaInfo : metaInfos)
                                {
                                    String name = metaInfo.getTagName();
                                    if (name.equals("Bindable"))
                                    {
                                        isBindable = true;
                                        break;
                                    }
                                }
                                if (isBindable)
                                    break;
                            }
                        }
                    }
                    if (isBindable)
                    {
                        IExpressionNode baseNode = classNode.getBaseClassNode();
                        Collection<IImportNode> importNodes = new ArrayList<IImportNode>();
                        ast.getAllImportNodes(importNodes);
                        if (baseNode == null)
                        {
                            // bindable class extends Object, must switch to
                            // extend EventDispatcher
                            IdentifierNode baseClassNode = new IdentifierNode("EventDispatcher");
                            baseClassNode.setParent(classNode);
                            classNode.setBaseClass(baseClassNode);
                            IdentifierNode flash = new IdentifierNode("flash");
                            IdentifierNode events = new IdentifierNode("events");
                            FullNameNode flashDotEvents = new FullNameNode(flash,
                                    new ASToken(ASToken.TOKEN_OPERATOR_MEMBER_ACCESS, 0, 0, 0, 0, "."), events);
                            FullNameNode fullNameNode = new FullNameNode(flashDotEvents,
View Full Code Here

     * @param node node to search for class node
     * @return root class name
     */
    private ClassNode findFirstClassNode(IASNode node)
    {
        ClassNode classNode = null;
        if (node instanceof ClassNode)
        {
            classNode = (ClassNode)node;
        }
        else
View Full Code Here

     * @return root class name
     */
    public String getRootClassName() throws InterruptedException
    {
        final IASNode fileNode = getSyntaxTreeRequest().get().getAST();
        final ClassNode classNode = findFirstClassNode(fileNode);
        final String rootClassName = classNode.getName();
        return rootClassName;
    }
View Full Code Here

    {
        //  This occurs in some error cases.
        if ( iNode == null )
            return;

        ClassNode enclosing_class = (ClassNode) iNode.getAncestorOfType(ClassNode.class);

        if ( enclosing_class != null )
        {
            IClassDefinition super_def = enclosing_class.getDefinition().resolveBaseClass(project);
            if (super_def != null)
            {
                IFunctionDefinition ctor = super_def.getConstructor();

                if (ctor instanceof FunctionDefinition)
View Full Code Here

        ScopedBlockNode contents = packageNode.getScopedNode();
        ImportNode importNode = ImportNode.buildImportNode(getBaseClassQName());
        contents.addItem(importNode);

        ClassNode classNode = new ClassNode(new IdentifierNode(data.getQName()));
        classNode.setBaseClass(new IdentifierNode(getBaseClassName()));
        classNode.setNamespace(new NamespaceIdentifierNode(INamespaceConstants.public_));
        contents.addItem(classNode);

        fileNode.runPostProcess(EnumSet.of(PostProcessStep.POPULATE_SCOPE));

        return fileNode;
View Full Code Here

        PackageNode packageNode = new PackageNode(new IdentifierNode(""), null);
        fileNode.addItem(packageNode);

        ScopedBlockNode contents = packageNode.getScopedNode();

        ClassNode classNode = new ClassNode(new IdentifierNode(data.getQName()));
        classNode.setNamespace(new NamespaceIdentifierNode(INamespaceConstants.public_));
        contents.addItem(classNode);

        // generate: public static var data:XML = ${XML_DATA};
        VariableNode variableNodeData = new VariableNode(new IdentifierNode("data"));
        variableNodeData.setNamespace(new NamespaceIdentifierNode(INamespaceConstants.public_));
        variableNodeData.addModifier(new ModifierNode(IASKeywordConstants.STATIC));
        variableNodeData.setType(null, new IdentifierNode("XML"));
        ASToken assignToken = new ASToken(ASTokenTypes.TOKEN_OPERATOR_ASSIGNMENT, -1, -1, -1, -1, "=");
        String xmlContents = getXMLString(problems);
        LiteralNode xmlData = new LiteralNode(LiteralType.STRING, xmlContents);
        variableNodeData.setAssignedValue(assignToken, xmlData);
        classNode.getScopedNode().addItem(variableNodeData);

        fileNode.runPostProcess(EnumSet.of(PostProcessStep.POPULATE_SCOPE));

        return fileNode;
    }
View Full Code Here

        importNode = ImportNode.buildImportNode("flash.display.Shader");
        packageContents.addItem(importNode);

        // generate the byte array class name
        String byteArrayClassName = data.getQName() + byteArrayNamePostfix;
        ClassNode classNodeByteArray = new ClassNode(new IdentifierNode(byteArrayClassName));
        classNodeByteArray.setBaseClass(new IdentifierNode(getBaseClassName()));
        classNodeByteArray.setNamespace(new NamespaceIdentifierNode(INamespaceConstants.public_));
        packageContents.addItem(classNodeByteArray);

        // generate the pbj class name
        String pbjClassName = data.getQName();
        ClassNode classNodePbj = new ClassNode(new IdentifierNode(pbjClassName));
        classNodePbj.setBaseClass(new IdentifierNode("Shader"));
        classNodePbj.addInterface(new IdentifierNode("IFlexAsset"));
        classNodePbj.setNamespace(new NamespaceIdentifierNode(INamespaceConstants.public_));
        packageContents.addItem(classNodePbj);

        // build the constructor
        IdentifierNode constructorNameNode = new IdentifierNode(pbjClassName);
        constructorNameNode.setReferenceValue(classNodePbj.getDefinition());
        FunctionNode constructorNode = new FunctionNode(null, constructorNameNode);
        constructorNode.setNamespace(new NamespaceIdentifierNode(INamespaceConstants.public_));
        ScopedBlockNode constructorContents = constructorNode.getScopedNode();

        // generate: super();
        FunctionCallNode superCall = new FunctionCallNode(LanguageIdentifierNode.buildSuper());
        constructorContents.addItem(superCall);

        // generate: byteCode = new EmbedTest_sphereClassByteArray();
        ASToken newToken = new ASToken(ASTokenTypes.TOKEN_KEYWORD_NEW, -1, -1, -1, -1, IASKeywordConstants.NEW);
        FunctionCallNode newCall = new FunctionCallNode(newToken, new IdentifierNode(byteArrayClassName));
        ASToken assignToken = new ASToken(ASTokenTypes.TOKEN_OPERATOR_ASSIGNMENT, -1, -1, -1, -1, "=");
        BinaryOperatorNodeBase assignment = BinaryOperatorNodeBase.create(assignToken, new IdentifierNode("byteCode"), newCall);
        constructorContents.addItem(assignment);

        classNodePbj.getScopedNode().addItem(constructorNode);

        fileNode.runPostProcess(EnumSet.of(PostProcessStep.POPULATE_SCOPE));

        return fileNode;
    }
View Full Code Here

TOP

Related Classes of org.apache.flex.compiler.internal.tree.as.ClassNode

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.