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;
}
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);
}
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);
}
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);
}
}
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;
}
}));
}
Aggregations