Search in sources :

Example 21 with FunctionDef

use of org.python.pydev.parser.jython.ast.FunctionDef in project Pydev by fabioz.

the class FastDefinitionsParserTest method testDefinitionsParserLines7.

public void testDefinitionsParserLines7() {
    Module m = (Module) FastDefinitionsParser.parse("class Bar(object):\n" + "    def m2 ( \n" + "        self,\n" + "        a ) : self.a=10\n");
    assertEquals(1, m.body.length);
    ClassDef classDefBar = (ClassDef) m.body[0];
    assertEquals(1, classDefBar.beginColumn);
    assertEquals(1, classDefBar.beginLine);
    assertEquals("Bar", ((NameTok) classDefBar.name).id);
    FunctionDef defM2 = (FunctionDef) classDefBar.body[0];
    assertEquals("m2", ((NameTok) (defM2).name).id);
    assertEquals(5, defM2.beginColumn);
    assertEquals(2, defM2.beginLine);
    Assign a = (Assign) defM2.body[0];
    assertEquals("self.a", NodeUtils.getFullRepresentationString(a.targets[0]));
    assertEquals(15, a.beginColumn);
    assertEquals(4, a.beginLine);
}
Also used : ClassDef(org.python.pydev.parser.jython.ast.ClassDef) FunctionDef(org.python.pydev.parser.jython.ast.FunctionDef) Assign(org.python.pydev.parser.jython.ast.Assign) Module(org.python.pydev.parser.jython.ast.Module)

Example 22 with FunctionDef

use of org.python.pydev.parser.jython.ast.FunctionDef in project Pydev by fabioz.

the class FastDefinitionsParserTest method testAttributes3.

public void testAttributes3() {
    Module m = (Module) FastDefinitionsParser.parse("class Bar:\n" + "    def m1(self):\n" + // local scope: don't get it
    "        ATTRIBUTE = 10\n" + "\n" + "");
    assertEquals(1, m.body.length);
    ClassDef classDef = ((ClassDef) m.body[0]);
    assertEquals("Bar", ((NameTok) classDef.name).id);
    // method
    assertEquals(1, classDef.body.length);
    FunctionDef funcDef = (FunctionDef) classDef.body[0];
    assertEquals("m1", ((NameTok) funcDef.name).id);
    assertNull(funcDef.body);
}
Also used : ClassDef(org.python.pydev.parser.jython.ast.ClassDef) FunctionDef(org.python.pydev.parser.jython.ast.FunctionDef) Module(org.python.pydev.parser.jython.ast.Module)

Example 23 with FunctionDef

use of org.python.pydev.parser.jython.ast.FunctionDef in project Pydev by fabioz.

the class FastDefinitionsParserTest method testDefinitionsParserLines2.

public void testDefinitionsParserLines2() {
    Module m = (Module) FastDefinitionsParser.parse("class Bar(object):\n" + "    def ra(\n" + "\n" + "\n" + "    )\n" + "    '''some\n" + "multi\n" + "line\n" + "string\n" + "    '''\n" + "    def m2(self):pass\n" + "        #def m3(self):pass\n" + "        'string'\n");
    assertEquals(1, m.body.length);
    ClassDef classDefBar = (ClassDef) m.body[0];
    assertEquals(1, classDefBar.beginColumn);
    assertEquals(1, classDefBar.beginLine);
    assertEquals("Bar", ((NameTok) classDefBar.name).id);
    FunctionDef defRa = (FunctionDef) classDefBar.body[0];
    assertEquals("ra", ((NameTok) (defRa).name).id);
    assertEquals(5, defRa.beginColumn);
    assertEquals(2, defRa.beginLine);
    FunctionDef defM2 = (FunctionDef) classDefBar.body[1];
    assertEquals("m2", ((NameTok) (defM2).name).id);
    assertEquals(5, defM2.beginColumn);
    assertEquals(11, defM2.beginLine);
}
Also used : ClassDef(org.python.pydev.parser.jython.ast.ClassDef) FunctionDef(org.python.pydev.parser.jython.ast.FunctionDef) Module(org.python.pydev.parser.jython.ast.Module)

Example 24 with FunctionDef

use of org.python.pydev.parser.jython.ast.FunctionDef in project Pydev by fabioz.

the class FastDefinitionsParserTest method testDefinitionsParserLines3.

public void testDefinitionsParserLines3() {
    Module m = (Module) FastDefinitionsParser.parse("class Bar(object):\n" + "    def ra(\n" + "\n" + "\n" + "    )\n" + "    a = 10\n" + "    a = 10\n" + "    a = #comment 10\r\n" + "    '''some\n" + "multi\n" + "line\n" + "string\n" + "    '''\n" + "    def m2(self):pass\n" + "        #def m3(self):pass\n" + "        'string'\n");
    assertEquals(1, m.body.length);
    ClassDef classDefBar = (ClassDef) m.body[0];
    assertEquals(1, classDefBar.beginColumn);
    assertEquals(1, classDefBar.beginLine);
    assertEquals("Bar", ((NameTok) classDefBar.name).id);
    FunctionDef defRa = (FunctionDef) classDefBar.body[0];
    assertEquals("ra", ((NameTok) (defRa).name).id);
    assertEquals(5, defRa.beginColumn);
    assertEquals(2, defRa.beginLine);
    // 2 assigns
    FunctionDef defM2 = (FunctionDef) classDefBar.body[4];
    assertEquals("m2", ((NameTok) (defM2).name).id);
    assertEquals(5, defM2.beginColumn);
    assertEquals(14, defM2.beginLine);
}
Also used : ClassDef(org.python.pydev.parser.jython.ast.ClassDef) FunctionDef(org.python.pydev.parser.jython.ast.FunctionDef) Module(org.python.pydev.parser.jython.ast.Module)

Example 25 with FunctionDef

use of org.python.pydev.parser.jython.ast.FunctionDef in project Pydev by fabioz.

the class FastDefinitionsParserTest method testDefinitionsParserLines5.

public void testDefinitionsParserLines5() {
    Module m = (Module) FastDefinitionsParser.parse("class Bar(object):\n" + "    def m2(self):self.a=10\n");
    assertEquals(1, m.body.length);
    ClassDef classDefBar = (ClassDef) m.body[0];
    assertEquals(1, classDefBar.beginColumn);
    assertEquals(1, classDefBar.beginLine);
    assertEquals("Bar", ((NameTok) classDefBar.name).id);
    FunctionDef defM2 = (FunctionDef) classDefBar.body[0];
    assertEquals("m2", ((NameTok) (defM2).name).id);
    assertEquals(5, defM2.beginColumn);
    assertEquals(2, defM2.beginLine);
    Assign a = (Assign) defM2.body[0];
    assertEquals("self.a", NodeUtils.getFullRepresentationString(a.targets[0]));
    assertEquals(18, a.beginColumn);
    assertEquals(2, a.beginLine);
}
Also used : ClassDef(org.python.pydev.parser.jython.ast.ClassDef) FunctionDef(org.python.pydev.parser.jython.ast.FunctionDef) Assign(org.python.pydev.parser.jython.ast.Assign) Module(org.python.pydev.parser.jython.ast.Module)

Aggregations

FunctionDef (org.python.pydev.parser.jython.ast.FunctionDef)137 ClassDef (org.python.pydev.parser.jython.ast.ClassDef)63 Module (org.python.pydev.parser.jython.ast.Module)44 SimpleNode (org.python.pydev.parser.jython.SimpleNode)36 NameTok (org.python.pydev.parser.jython.ast.NameTok)30 ArrayList (java.util.ArrayList)27 org.python.pydev.parser.jython.ast.stmtType (org.python.pydev.parser.jython.ast.stmtType)27 org.python.pydev.parser.jython.ast.exprType (org.python.pydev.parser.jython.ast.exprType)26 Name (org.python.pydev.parser.jython.ast.Name)25 Assign (org.python.pydev.parser.jython.ast.Assign)17 org.python.pydev.parser.jython.ast.argumentsType (org.python.pydev.parser.jython.ast.argumentsType)17 Attribute (org.python.pydev.parser.jython.ast.Attribute)15 Call (org.python.pydev.parser.jython.ast.Call)14 SourceToken (org.python.pydev.ast.codecompletion.revisited.modules.SourceToken)13 Expr (org.python.pydev.parser.jython.ast.Expr)13 Return (org.python.pydev.parser.jython.ast.Return)12 AdapterPrefs (org.python.pydev.parser.jython.ast.factory.AdapterPrefs)12 PyAstFactory (org.python.pydev.parser.jython.ast.factory.PyAstFactory)12 TokensList (org.python.pydev.core.TokensList)10 Yield (org.python.pydev.parser.jython.ast.Yield)10