Package org.python.pydev.parser.jython.ast

Examples of org.python.pydev.parser.jython.ast.Pass


        fixNode(node);

        node.test.accept(this);

        if (node.body == null || node.body.length == 0) {
            node.body = new stmtType[] { new Pass() };
        }

        //write the body and dedent
        for (SimpleNode n : node.body) {
            n.accept(this);
View Full Code Here


                        decorators = "@staticmethod\n";
                        break;

                    case CONSTANT:
                        String indent = targetClass.getNodeBodyIndent();
                        Pass replacePassStatement = getLastPassFromNode(targetClass.getASTNode());

                        String constant = com.aptana.shared_core.string.StringUtils.format("\n%s = ${None}${cursor}\n", actTok);
                        Tuple<Integer, String> offsetAndIndent;
                        offsetAndIndent = getLocationOffset(AbstractPyCreateAction.LOCATION_STRATEGY_FIRST_METHOD,
                                pySelection, moduleAdapter, targetClass);

                        return createProposal(pySelection, constant, offsetAndIndent, false, replacePassStatement);

                    case FIELD:

                        parametersAfterCall = checkFirst(parametersAfterCall, "self");
                        FunctionDefAdapter firstInit = targetClass.getFirstInit();
                        if (firstInit != null) {
                            FunctionDef astNode = firstInit.getASTNode();
                            replacePassStatement = getLastPassFromNode(astNode);

                            //Create the field as the last line in the __init__
                            int nodeLastLine = firstInit.getNodeLastLine() - 1;
                            indent = firstInit.getNodeBodyIndent();
                            String pattern;

                            if (replacePassStatement == null) {
                                pattern = com.aptana.shared_core.string.StringUtils.format("\nself.%s = ${None}${cursor}", actTok);
                                try {
                                    IRegion region = pySelection.getDoc().getLineInformation(nodeLastLine);
                                    int offset = region.getOffset() + region.getLength();
                                    offsetAndIndent = new Tuple<Integer, String>(offset, indent);
                                } catch (BadLocationException e) {
                                    Log.log(e);
                                    return null;
                                }

                            } else {
                                pattern = com.aptana.shared_core.string.StringUtils.format("self.%s = ${None}${cursor}", actTok);
                                offsetAndIndent = new Tuple<Integer, String>(-1, ""); //offset will be from the pass stmt
                            }
                            return createProposal(pySelection, pattern, offsetAndIndent, false, replacePassStatement);

                        } else {
                            //Create the __init__ with the field declaration!
                            body = com.aptana.shared_core.string.StringUtils.format("self.%s = ${None}${cursor}", actTok);
                            actTok = "__init__";
                            locationStrategy = AbstractPyCreateAction.LOCATION_STRATEGY_FIRST_METHOD;
                        }

                        break;
                }
            } else {
                //We should create in a class and couldn't find it!
                return null;
            }
        }

        String params = "";
        String source;
        if (parametersAfterCall != null && parametersAfterCall.size() > 0) {
            params = createParametersList(parametersAfterCall).toString();
        }

        Tuple<Integer, String> offsetAndIndent;
        Pass replacePassStatement = null;
        if (targetClass != null) {
            replacePassStatement = getLastPassFromNode(targetClass.getASTNode());
            offsetAndIndent = getLocationOffset(locationStrategy, pySelection, moduleAdapter, targetClass);

        } else {
View Full Code Here

        return createProposal(pySelection, source, offsetAndIndent, true, replacePassStatement);
    }

    private Pass getLastPassFromNode(SimpleNode astNode) {
        stmtType[] body = NodeUtils.getBody(astNode);
        Pass replacePassStatement = null;
        if (body.length > 0) {
            SimpleNode lastNode = body[body.length - 1];
            if (lastNode instanceof Pass) {
                //Remove the pass and add the statement!
                replacePassStatement = (Pass) lastNode;
View Full Code Here

        assertTrue(s.startsWith(FileUtils.BOM_UTF8));

        assertEquals("utf-8", FileUtils.getPythonFileEncoding(file));
        SimpleNode ast = parseLegalDocStr(s);
        Module m = (Module) ast;
        Pass p = (Pass) m.body[0];

        assertTrue(s.startsWith(FileUtils.BOM_UTF8));

        ast = parseLegalDocStr(s);
        m = (Module) ast;
View Full Code Here

                String s = "" +
                        "pass\n" +
                        "pass";
                Module m = (Module) parseLegalDocStr(s);
                assertEquals(2, m.body.length);
                Pass p1 = (Pass) m.body[0];
                Pass p2 = (Pass) m.body[1];
                //must intern specials in the same pass.
                assertSame(((SpecialStr) p1.specialsBefore.get(0)).str, ((SpecialStr) p2.specialsBefore.get(0)).str);
                return true;
            }
        });
View Full Code Here

    public Str createString(String string) {
        return new Str(string, Str.TripleSingle, false, false, false);
    }

    public Pass createPass() {
        return new Pass();
    }
View Full Code Here

TOP

Related Classes of org.python.pydev.parser.jython.ast.Pass

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.