Search in sources :

Example 1 with PrettyPrinterPrefsV2

use of org.python.pydev.parser.prettyprinterv2.PrettyPrinterPrefsV2 in project Pydev by fabioz.

the class NodeUtils method printAst.

/**
 * Copied from {@link PyTextHover} when that class was deprecated.
 */
public static String printAst(IPyEdit edit, SimpleNode astToPrint) {
    String str = null;
    if (astToPrint != null) {
        IIndentPrefs indentPrefs;
        if (edit != null) {
            indentPrefs = edit.getIndentPrefs();
        } else {
            indentPrefs = DefaultIndentPrefs.get(null);
        }
        Str docStr = getNodeDocStringNode(astToPrint);
        if (docStr != null) {
            docStr.s = PyStringUtils.fixWhitespaceColumnsToLeftFromDocstring(docStr.s, indentPrefs.getIndentationString());
        }
        PrettyPrinterPrefsV2 prefsV2 = PrettyPrinterV2.createDefaultPrefs(edit, indentPrefs, LINE_DELIM);
        PrettyPrinterV2 prettyPrinterV2 = new PrettyPrinterV2(prefsV2);
        try {
            str = prettyPrinterV2.print(astToPrint);
        } catch (IOException e) {
            Log.log(e);
        }
    }
    return str;
}
Also used : Str(org.python.pydev.parser.jython.ast.Str) ISpecialStr(org.python.pydev.parser.jython.ISpecialStr) PrettyPrinterPrefsV2(org.python.pydev.parser.prettyprinterv2.PrettyPrinterPrefsV2) IIndentPrefs(org.python.pydev.core.IIndentPrefs) PrettyPrinterV2(org.python.pydev.parser.prettyprinterv2.PrettyPrinterV2) IOException(java.io.IOException)

Example 2 with PrettyPrinterPrefsV2

use of org.python.pydev.parser.prettyprinterv2.PrettyPrinterPrefsV2 in project Pydev by fabioz.

the class AbstractPrettyPrinterTestBase method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    prefs = new PrettyPrinterPrefsV2("\n", "    ", versionProvider);
}
Also used : PrettyPrinterPrefsV2(org.python.pydev.parser.prettyprinterv2.PrettyPrinterPrefsV2)

Example 3 with PrettyPrinterPrefsV2

use of org.python.pydev.parser.prettyprinterv2.PrettyPrinterPrefsV2 in project Pydev by fabioz.

the class PrettyPrinterLibTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    prefs = new PrettyPrinterPrefsV2("\n", "    ", versionProvider);
    setDefaultVersion(IGrammarVersionProvider.GRAMMAR_PYTHON_VERSION_2_7);
}
Also used : PrettyPrinterPrefsV2(org.python.pydev.parser.prettyprinterv2.PrettyPrinterPrefsV2)

Example 4 with PrettyPrinterPrefsV2

use of org.python.pydev.parser.prettyprinterv2.PrettyPrinterPrefsV2 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 PrettyPrinterPrefsV2

use of org.python.pydev.parser.prettyprinterv2.PrettyPrinterPrefsV2 in project Pydev by fabioz.

the class NodeUtils method printAst.

public static String printAst(IIndentPrefs indentPrefs, IGrammarVersionProvider versionProvider, SimpleNode astToPrint, String lineDelimiter) {
    String str = null;
    if (astToPrint != null) {
        PrettyPrinterPrefsV2 prefsV2 = PrettyPrinterV2.createDefaultPrefs(versionProvider, indentPrefs, lineDelimiter);
        PrettyPrinterV2 prettyPrinterV2 = new PrettyPrinterV2(prefsV2);
        try {
            str = prettyPrinterV2.print(astToPrint);
        } catch (IOException e) {
            Log.log(e);
        }
    }
    return str;
}
Also used : PrettyPrinterPrefsV2(org.python.pydev.parser.prettyprinterv2.PrettyPrinterPrefsV2) PrettyPrinterV2(org.python.pydev.parser.prettyprinterv2.PrettyPrinterV2) IOException(java.io.IOException)

Aggregations

PrettyPrinterPrefsV2 (org.python.pydev.parser.prettyprinterv2.PrettyPrinterPrefsV2)8 PrettyPrinterV2 (org.python.pydev.parser.prettyprinterv2.PrettyPrinterV2)4 IGrammarVersionProvider (org.python.pydev.core.IGrammarVersionProvider)3 IOException (java.io.IOException)2 IIndentPrefs (org.python.pydev.core.IIndentPrefs)2 ISpecialStr (org.python.pydev.parser.jython.ISpecialStr)1 Module (org.python.pydev.parser.jython.ast.Module)1 Str (org.python.pydev.parser.jython.ast.Str)1 IPrettyPrinterPrefs (org.python.pydev.parser.prettyprinterv2.IPrettyPrinterPrefs)1