Search in sources :

Example 1 with IGrammarVersionProvider

use of org.python.pydev.core.IGrammarVersionProvider in project Pydev by fabioz.

the class PrettyPrinterV2 method createDefaultPrefs.

public static PrettyPrinterPrefsV2 createDefaultPrefs(IGrammarVersionProvider versionProvider, IIndentPrefs indentPrefs, String endLineDelim) {
    if (versionProvider == null) {
        versionProvider = new IGrammarVersionProvider() {

            @Override
            public int getGrammarVersion() throws MisconfigurationException {
                return IGrammarVersionProvider.LATEST_GRAMMAR_PY3_VERSION;
            }

            @Override
            public AdditionalGrammarVersionsToCheck getAdditionalGrammarVersions() throws MisconfigurationException {
                return null;
            }
        };
    }
    PrettyPrinterPrefsV2 prettyPrinterPrefs = new PrettyPrinterPrefsV2(endLineDelim, indentPrefs.getIndentationString(), versionProvider);
    prettyPrinterPrefs.setSpacesAfterComma(1);
    prettyPrinterPrefs.setSpacesBeforeComment(1);
    prettyPrinterPrefs.setLinesAfterMethod(1);
    prettyPrinterPrefs.setLinesAfterClass(2);
    prettyPrinterPrefs.setLinesAfterSuite(1);
    return prettyPrinterPrefs;
}
Also used : IGrammarVersionProvider(org.python.pydev.core.IGrammarVersionProvider) MisconfigurationException(org.python.pydev.core.MisconfigurationException)

Example 2 with IGrammarVersionProvider

use of org.python.pydev.core.IGrammarVersionProvider in project Pydev by fabioz.

the class PrettyPrinterTest method testNPEError.

public void testNPEError() throws Throwable {
    final String s = "" + "def Foo(*args):\n" + "    pass\n" + "";
    IGrammarVersionProvider p = new IGrammarVersionProvider() {

        @Override
        public int getGrammarVersion() throws MisconfigurationException {
            return IGrammarVersionProvider.GRAMMAR_PYTHON_VERSION_2_7;
        }

        @Override
        public AdditionalGrammarVersionsToCheck getAdditionalGrammarVersions() throws MisconfigurationException {
            return null;
        }
    };
    Module node = (Module) parseLegalDocStr(s);
    FunctionDef funcDef = (FunctionDef) node.body[0];
    String result = PrettyPrinterV2.printArguments(p, funcDef.args);
    assertEquals("*args", result);
}
Also used : IGrammarVersionProvider(org.python.pydev.core.IGrammarVersionProvider) FunctionDef(org.python.pydev.parser.jython.ast.FunctionDef) Module(org.python.pydev.parser.jython.ast.Module)

Example 3 with IGrammarVersionProvider

use of org.python.pydev.core.IGrammarVersionProvider in project Pydev by fabioz.

the class PrettyPrinterTest method testNPEError2.

public void testNPEError2() throws Throwable {
    final String s = "" + "def Foo(*, a):\n" + "    pass\n" + "";
    IGrammarVersionProvider p = new IGrammarVersionProvider() {

        @Override
        public int getGrammarVersion() throws MisconfigurationException {
            return IGrammarVersionProvider.GRAMMAR_PYTHON_VERSION_3_5;
        }

        @Override
        public AdditionalGrammarVersionsToCheck getAdditionalGrammarVersions() throws MisconfigurationException {
            return null;
        }
    };
    setDefaultVersion(IGrammarVersionProvider.GRAMMAR_PYTHON_VERSION_3_5);
    Module node = (Module) parseLegalDocStr(s);
    FunctionDef funcDef = (FunctionDef) node.body[0];
    String result = PrettyPrinterV2.printArguments(p, funcDef.args);
    assertEquals("*, a", result);
}
Also used : IGrammarVersionProvider(org.python.pydev.core.IGrammarVersionProvider) FunctionDef(org.python.pydev.parser.jython.ast.FunctionDef) Module(org.python.pydev.parser.jython.ast.Module)

Example 4 with IGrammarVersionProvider

use of org.python.pydev.core.IGrammarVersionProvider in project Pydev by fabioz.

the class Rewriter method createSourceFromAST.

public static String createSourceFromAST(SimpleNode root, boolean ignoreComments, AdapterPrefs adapterPrefs) {
    IGrammarVersionProvider versionProvider = adapterPrefs.versionProvider;
    IIndentPrefs indentPrefs = DefaultIndentPrefs.get(adapterPrefs.projectAdaptable);
    String endLineDelim = adapterPrefs.endLineDelim;
    PrettyPrinterPrefsV2 prettyPrinterPrefs = PrettyPrinterV2.createDefaultPrefs(versionProvider, indentPrefs, endLineDelim);
    PrettyPrinterV2 printer = new PrettyPrinterV2(prettyPrinterPrefs);
    try {
        return printer.print(root);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : PrettyPrinterPrefsV2(org.python.pydev.parser.prettyprinterv2.PrettyPrinterPrefsV2) IGrammarVersionProvider(org.python.pydev.core.IGrammarVersionProvider) IIndentPrefs(org.python.pydev.core.IIndentPrefs) PrettyPrinterV2(org.python.pydev.parser.prettyprinterv2.PrettyPrinterV2)

Example 5 with IGrammarVersionProvider

use of org.python.pydev.core.IGrammarVersionProvider in project Pydev by fabioz.

the class PyAstFactoryTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    astFactory = new PyAstFactory(new AdapterPrefs("\n", new IGrammarVersionProvider() {

        @Override
        public int getGrammarVersion() throws MisconfigurationException {
            return IGrammarVersionProvider.GRAMMAR_PYTHON_VERSION_2_7;
        }

        @Override
        public AdditionalGrammarVersionsToCheck getAdditionalGrammarVersions() throws MisconfigurationException {
            return null;
        }
    }));
}
Also used : IGrammarVersionProvider(org.python.pydev.core.IGrammarVersionProvider) MisconfigurationException(org.python.pydev.core.MisconfigurationException) AdapterPrefs(org.python.pydev.parser.jython.ast.factory.AdapterPrefs) PyAstFactory(org.python.pydev.parser.jython.ast.factory.PyAstFactory)

Aggregations

IGrammarVersionProvider (org.python.pydev.core.IGrammarVersionProvider)22 MisconfigurationException (org.python.pydev.core.MisconfigurationException)9 Module (org.python.pydev.parser.jython.ast.Module)8 Document (org.eclipse.jface.text.Document)6 IDocument (org.eclipse.jface.text.IDocument)6 AdapterPrefs (org.python.pydev.parser.jython.ast.factory.AdapterPrefs)6 FunctionDef (org.python.pydev.parser.jython.ast.FunctionDef)4 RefactoringInfo (org.python.pydev.refactoring.core.base.RefactoringInfo)4 CoreTextSelection (org.python.pydev.shared_core.string.CoreTextSelection)4 ICoreTextSelection (org.python.pydev.shared_core.string.ICoreTextSelection)4 ArrayList (java.util.ArrayList)3 AbstractModule (org.python.pydev.ast.codecompletion.revisited.modules.AbstractModule)3 SourceModule (org.python.pydev.ast.codecompletion.revisited.modules.SourceModule)3 SimpleNode (org.python.pydev.parser.jython.SimpleNode)3 PyAstFactory (org.python.pydev.parser.jython.ast.factory.PyAstFactory)3 ParseOutput (org.python.pydev.shared_core.parsing.BaseParser.ParseOutput)3 File (java.io.File)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 Change (org.eclipse.ltk.core.refactoring.Change)2 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)2