Search in sources :

Example 1 with Scopes

use of org.python.pydev.shared_core.parsing.Scopes in project Pydev by fabioz.

the class ScopesParser method createScopes.

@Override
public Scopes createScopes(IDocument doc) {
    this.scopes = new Scopes();
    this.doc = doc;
    this.lineOffsetToIndent = new TreeMap<Integer, Integer>();
    try {
        TabNannyDocIterator nannyDocIterator = new TabNannyDocIterator(doc, true, false);
        while (nannyDocIterator.hasNext()) {
            IndentInfo next = nannyDocIterator.next();
            this.lineOffsetToIndent.put(next.startOffset, next.indent.length());
        }
    } catch (BadLocationException e1) {
        throw new RuntimeException(e1);
    }
    try {
        return this.createScopes();
    } catch (SyntaxErrorException e) {
        throw new RuntimeException(e);
    }
}
Also used : IndentInfo(org.python.pydev.core.docutils.TabNannyDocIterator.IndentInfo) TabNannyDocIterator(org.python.pydev.core.docutils.TabNannyDocIterator) Scopes(org.python.pydev.shared_core.parsing.Scopes) SyntaxErrorException(org.python.pydev.core.docutils.SyntaxErrorException) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 2 with Scopes

use of org.python.pydev.shared_core.parsing.Scopes in project Pydev by fabioz.

the class ScopesParserTest method testScopes2.

public void testScopes2() throws Exception {
    Document doc = new Document("a().o");
    Scopes scopes = new ScopesParser().createScopes(doc);
    assertEquals(new Region(0, 5), scopes.getScopeForSelection(2, 0));
}
Also used : Scopes(org.python.pydev.shared_core.parsing.Scopes) Region(org.eclipse.jface.text.Region) Document(org.eclipse.jface.text.Document)

Example 3 with Scopes

use of org.python.pydev.shared_core.parsing.Scopes in project Pydev by fabioz.

the class ScopesParserTest method testScopes4.

public void testScopes4() throws Exception {
    Document doc = new Document("(1\n" + "\n" + "class Bar(object):\n" + "    call" + "");
    Scopes scopes = new ScopesParser().createScopes(doc);
    assertEquals("" + "[1 (1\n" + "\n" + "[3 class Bar([2 object 2]):\n" + "    [4 call 3] 4] 1]" + "", scopes.debugString(doc).toString());
}
Also used : Scopes(org.python.pydev.shared_core.parsing.Scopes) Document(org.eclipse.jface.text.Document)

Example 4 with Scopes

use of org.python.pydev.shared_core.parsing.Scopes in project Pydev by fabioz.

the class ScopesParserTest method testScopes.

public void testScopes() throws Exception {
    Document doc = new Document("" + "#comment\n" + "class Foo(object):\n" + "    def method(self, a=(10,20)):\n" + "        '''\n" + "    multi string\n" + "        '''\n");
    Scopes scopes = new ScopesParser().createScopes(doc);
    assertEquals("" + "[1 [2 #comment 2]\n" + "[4 class Foo([3 object 3]):\n" + "    [5 [8 def method([6 self, a=([7 10,20 7]) 6]):\n" + "        [9 [10 '''\n" + "    multi string\n" + "        ''' 10]\n" + " 4] 5] 8] 9] 1]" + "", scopes.debugString(doc).toString());
}
Also used : Scopes(org.python.pydev.shared_core.parsing.Scopes) Document(org.eclipse.jface.text.Document)

Example 5 with Scopes

use of org.python.pydev.shared_core.parsing.Scopes in project Pydev by fabioz.

the class ScopesParserTest method testScopes3.

public void testScopes3() throws Exception {
    Document doc = new Document("a(.o");
    Scopes scopes = new ScopesParser().createScopes(doc);
    assertEquals(new Region(0, 4), scopes.getScopeForSelection(2, 0));
}
Also used : Scopes(org.python.pydev.shared_core.parsing.Scopes) Region(org.eclipse.jface.text.Region) Document(org.eclipse.jface.text.Document)

Aggregations

Scopes (org.python.pydev.shared_core.parsing.Scopes)7 Document (org.eclipse.jface.text.Document)5 Region (org.eclipse.jface.text.Region)3 BadLocationException (org.eclipse.jface.text.BadLocationException)2 IRegion (org.eclipse.jface.text.IRegion)1 SyntaxErrorException (org.python.pydev.core.docutils.SyntaxErrorException)1 TabNannyDocIterator (org.python.pydev.core.docutils.TabNannyDocIterator)1 IndentInfo (org.python.pydev.core.docutils.TabNannyDocIterator.IndentInfo)1 CoreTextSelection (org.python.pydev.shared_core.string.CoreTextSelection)1 ICoreTextSelection (org.python.pydev.shared_core.string.ICoreTextSelection)1 TextSelectionUtils (org.python.pydev.shared_core.string.TextSelectionUtils)1