From f4196bbc77b59d2e34c0ff3707177434d0bfae6b Mon Sep 17 00:00:00 2001 From: Fabio Zadrozny Date: Sat, 21 Sep 2024 13:13:24 -0300 Subject: [PATCH] wip --- .../rename/MatchImportsVisitorTest.java | 6 +-- .../ast/adapters/FunctionArgAdapter.java | 1 + .../ast/adapters/visitors/VisitorFactory.java | 51 ++----------------- .../revisited/AbstractASTManager.java | 2 +- .../revisited/ModulesManager.java | 2 +- .../revisited/SystemModulesManager.java | 2 +- .../revisited/modules/AbstractModule.java | 4 +- .../src/org/python/pydev/parser/PyParser.java | 35 +++++++++++-- .../parser/prettyprinterv2/Formatter.java | 2 +- .../parser/prettyprinterv2}/Rewriter.java | 7 ++- .../pydev/parser/visitors/NodeUtils.java | 2 +- .../org/python/pydev/parser/PyParserTest.java | 2 +- .../python/pydev/parser/PyParserTestBase.java | 4 +- .../pydev/parser/PyParserWithoutTree.java | 4 +- .../scope/CodeFoldingVisitorTest.java | 22 ++++---- .../visitors/scope/EasyASTIteratorTest.java | 12 ++--- .../ch/hsr/ukistler/astgraph/ASTGraph.java | 2 +- .../ast/visitors/VisitorFactory.java | 2 +- .../core/base/RefactoringInfo.java | 2 +- .../core/edit/AbstractReplaceEdit.java | 2 +- .../core/edit/AbstractTextEdit.java | 2 +- .../extractmethod/ExtractMethodTestCase.java | 2 +- .../tests/core/AbstractRewriterTestCase.java | 2 +- .../visitors/SelectionExtensionTestCase.java | 2 +- .../src/org/python/pydev/editor/PyEdit.java | 2 +- .../codefolding/CodeFoldingSetterTest.java | 2 +- .../python/pydev/parser/GenCythonAstTest.java | 2 +- .../pydev/parser/PyParserCythonTest.java | 2 +- .../codecompletion/revisited/ModuleTest.java | 6 +-- 29 files changed, 87 insertions(+), 101 deletions(-) rename plugins/{org.python.pydev.refactoring/src/org/python/pydev/refactoring/ast/visitors/rewriter => org.python.pydev.parser/src/org/python/pydev/parser/prettyprinterv2}/Rewriter.java (88%) diff --git a/plugins/com.python.pydev.refactoring/tests/com/python/pydev/refactoring/wizards/rename/MatchImportsVisitorTest.java b/plugins/com.python.pydev.refactoring/tests/com/python/pydev/refactoring/wizards/rename/MatchImportsVisitorTest.java index 93bf284912..b44e228a24 100644 --- a/plugins/com.python.pydev.refactoring/tests/com/python/pydev/refactoring/wizards/rename/MatchImportsVisitorTest.java +++ b/plugins/com.python.pydev.refactoring/tests/com/python/pydev/refactoring/wizards/rename/MatchImportsVisitorTest.java @@ -27,7 +27,7 @@ public void testMatchImports() throws Exception { + "from a.b.c.d import *\n" //rename a.b.c with wild import + ""); IPythonNature nature = new PythonNatureStub(); - ParseOutput obj = PyParser.reparseDocument(new PyParser.ParserInfo(doc, nature)); + ParseOutput obj = PyParser.parseFull(new PyParser.ParserInfo(doc, nature)); SourceModule module = (SourceModule) AbstractModule.createModule((SimpleNode) obj.ast, null, "z", null); MatchImportsVisitor visitor = new MatchImportsVisitor(nature, "a.b.c", module, null); @@ -44,7 +44,7 @@ public void testMatchImports2() throws Exception { + "import a.b\n" + ""); IPythonNature nature = new PythonNatureStub(); - ParseOutput obj = PyParser.reparseDocument(new PyParser.ParserInfo(doc, nature)); + ParseOutput obj = PyParser.parseFull(new PyParser.ParserInfo(doc, nature)); SourceModule module = (SourceModule) AbstractModule.createModule((SimpleNode) obj.ast, null, "z", null); MatchImportsVisitor visitor = new MatchImportsVisitor(nature, "a.b.c", module, null); @@ -68,7 +68,7 @@ public int getGrammarVersion() { return IPythonNature.GRAMMAR_PYTHON_VERSION_3_5; } }; - ParseOutput obj = PyParser.reparseDocument(new PyParser.ParserInfo(doc, nature)); + ParseOutput obj = PyParser.parseFull(new PyParser.ParserInfo(doc, nature)); SourceModule module = (SourceModule) AbstractModule.createModule((SimpleNode) obj.ast, null, "a.g", null); MatchImportsVisitor visitor = new MatchImportsVisitor(nature, "a.b.c", module, null); diff --git a/plugins/org.python.pydev.ast/src/org/python/pydev/ast/adapters/FunctionArgAdapter.java b/plugins/org.python.pydev.ast/src/org/python/pydev/ast/adapters/FunctionArgAdapter.java index c71b1884b4..c1125d54f4 100644 --- a/plugins/org.python.pydev.ast/src/org/python/pydev/ast/adapters/FunctionArgAdapter.java +++ b/plugins/org.python.pydev.ast/src/org/python/pydev/ast/adapters/FunctionArgAdapter.java @@ -31,6 +31,7 @@ import org.python.pydev.parser.jython.ast.argumentsType; import org.python.pydev.parser.jython.ast.exprType; import org.python.pydev.parser.jython.ast.factory.AdapterPrefs; +import org.python.pydev.parser.prettyprinterv2.Rewriter; import org.python.pydev.shared_core.string.StringUtils; public class FunctionArgAdapter extends AbstractNodeAdapter { diff --git a/plugins/org.python.pydev.ast/src/org/python/pydev/ast/adapters/visitors/VisitorFactory.java b/plugins/org.python.pydev.ast/src/org/python/pydev/ast/adapters/visitors/VisitorFactory.java index 1e19b79268..0d93730419 100644 --- a/plugins/org.python.pydev.ast/src/org/python/pydev/ast/adapters/visitors/VisitorFactory.java +++ b/plugins/org.python.pydev.ast/src/org/python/pydev/ast/adapters/visitors/VisitorFactory.java @@ -1,25 +1,19 @@ package org.python.pydev.ast.adapters.visitors; -import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IDocument; import org.python.pydev.ast.adapters.AbstractNodeAdapter; import org.python.pydev.ast.adapters.AbstractScopeNode; import org.python.pydev.ast.adapters.ModuleAdapter; import org.python.pydev.ast.adapters.context.AbstractContextVisitor; -import org.python.pydev.core.IGrammarVersionProvider; -import org.python.pydev.core.MisconfigurationException; -import org.python.pydev.parser.PyParser; -import org.python.pydev.parser.PyParser.ParserInfo; -import org.python.pydev.parser.jython.ParseException; import org.python.pydev.parser.jython.SimpleNode; -import org.python.pydev.parser.jython.TokenMgrError; -import org.python.pydev.parser.jython.ast.Module; import org.python.pydev.parser.jython.ast.VisitorIF; import org.python.pydev.parser.jython.ast.exprType; -import org.python.pydev.shared_core.parsing.BaseParser.ParseOutput; import org.python.pydev.shared_core.string.ICoreTextSelection; -public class VisitorFactory { +public final class VisitorFactory { + + private VisitorFactory() { + } /** * Unchecked (because if doing Class.cast, it does not work in java 1.4) @@ -62,41 +56,4 @@ public static T createVisitor(Class visitorClass, Simpl return visitor; } - public static T createVisitor(Class visitorClass, String source, - IGrammarVersionProvider versionProvider) throws Throwable { - return createVisitor(visitorClass, VisitorFactory.getRootNodeFromString(source, versionProvider)); - } - - public static Module getRootNode(IDocument doc, IGrammarVersionProvider versionProvider) throws ParseException, - MisconfigurationException { - ParseOutput objects = PyParser.reparseDocument(new PyParser.ParserInfo(doc, versionProvider)); - Throwable exception = objects.error; - - if (exception != null) { - /* We try to get rid of the 'Throwable' exception, if possible */ - if (exception instanceof ParseException) { - throw (ParseException) exception; - } else if (exception instanceof TokenMgrError) { - /* Error from Lexer */ - throw new ParseException(exception.toString()); - } else { - throw new RuntimeException(exception); - } - } - - if (objects.error != null) { - throw new RuntimeException(objects.error); - } - return (Module) objects.ast; - } - - public static IDocument getDocumentFromString(String source) { - return new Document(source); - } - - public static SimpleNode getRootNodeFromString(String source, IGrammarVersionProvider versionProvider) - throws ParseException, MisconfigurationException { - return getRootNode(getDocumentFromString(source), versionProvider); - } - } diff --git a/plugins/org.python.pydev.ast/src/org/python/pydev/ast/codecompletion/revisited/AbstractASTManager.java b/plugins/org.python.pydev.ast/src/org/python/pydev/ast/codecompletion/revisited/AbstractASTManager.java index ad64de224e..d80fb7b528 100644 --- a/plugins/org.python.pydev.ast/src/org/python/pydev/ast/codecompletion/revisited/AbstractASTManager.java +++ b/plugins/org.python.pydev.ast/src/org/python/pydev/ast/codecompletion/revisited/AbstractASTManager.java @@ -558,7 +558,7 @@ public TokensList getCompletionsForToken(IDocument doc, ICompletionState state) TokensList completionsForModule; try { ParseOutput obj = PyParser - .reparseDocument(new PyParser.ParserInfo(doc, state.getNature())); + .parseFull(new PyParser.ParserInfo(doc, state.getNature())); SimpleNode n = (SimpleNode) obj.ast; IModule module = AbstractModule.createModule(n, state.getNature()); diff --git a/plugins/org.python.pydev.ast/src/org/python/pydev/ast/codecompletion/revisited/ModulesManager.java b/plugins/org.python.pydev.ast/src/org/python/pydev/ast/codecompletion/revisited/ModulesManager.java index fbca807caa..e0e0684f28 100644 --- a/plugins/org.python.pydev.ast/src/org/python/pydev/ast/codecompletion/revisited/ModulesManager.java +++ b/plugins/org.python.pydev.ast/src/org/python/pydev/ast/codecompletion/revisited/ModulesManager.java @@ -1169,7 +1169,7 @@ public AdditionalGrammarVersionsToCheck getAdditionalGrammarVersions() return null; } }; - ParseOutput obj = PyParser.reparseDocument(new PyParser.ParserInfo(doc, provider, + ParseOutput obj = PyParser.parseFull(new PyParser.ParserInfo(doc, provider, "_django_manager_body", managerBody)); Module ast2 = (Module) obj.ast; newBody = ast2.body; diff --git a/plugins/org.python.pydev.ast/src/org/python/pydev/ast/codecompletion/revisited/SystemModulesManager.java b/plugins/org.python.pydev.ast/src/org/python/pydev/ast/codecompletion/revisited/SystemModulesManager.java index b8925c1b79..00cefec81f 100644 --- a/plugins/org.python.pydev.ast/src/org/python/pydev/ast/codecompletion/revisited/SystemModulesManager.java +++ b/plugins/org.python.pydev.ast/src/org/python/pydev/ast/codecompletion/revisited/SystemModulesManager.java @@ -295,7 +295,7 @@ public AdditionalGrammarVersionsToCheck getAdditionalGrammarVersions() return null; } }; - ParseOutput obj = PyParser.reparseDocument(new PyParser.ParserInfo(doc, provider, + ParseOutput obj = PyParser.parseFull(new PyParser.ParserInfo(doc, provider, finalName, predefinedModule)); if (obj.error != null) { if (lastModified == null) { diff --git a/plugins/org.python.pydev.ast/src/org/python/pydev/ast/codecompletion/revisited/modules/AbstractModule.java b/plugins/org.python.pydev.ast/src/org/python/pydev/ast/codecompletion/revisited/modules/AbstractModule.java index 907a1fa26a..b543616478 100644 --- a/plugins/org.python.pydev.ast/src/org/python/pydev/ast/codecompletion/revisited/modules/AbstractModule.java +++ b/plugins/org.python.pydev.ast/src/org/python/pydev/ast/codecompletion/revisited/modules/AbstractModule.java @@ -330,12 +330,12 @@ public static SourceModule createModuleFromDoc(String name, File f, IDocument do if (f != null) { if (!checkForPath || PythonPathHelper.isValidSourceFile(f.getName())) { - ParseOutput obj = PyParser.reparseDocument(new PyParser.ParserInfo(doc, grammarVersionProvider, name, + ParseOutput obj = PyParser.parseFull(new PyParser.ParserInfo(doc, grammarVersionProvider, name, f)); return new SourceModule(name, f, (SimpleNode) obj.ast, obj.error, nature); } } else { - ParseOutput obj = PyParser.reparseDocument(new PyParser.ParserInfo(doc, grammarVersionProvider, name, f)); + ParseOutput obj = PyParser.parseFull(new PyParser.ParserInfo(doc, grammarVersionProvider, name, f)); return new SourceModule(name, f, (SimpleNode) obj.ast, obj.error, nature); } return null; diff --git a/plugins/org.python.pydev.parser/src/org/python/pydev/parser/PyParser.java b/plugins/org.python.pydev.parser/src/org/python/pydev/parser/PyParser.java index 536ab8aa34..58b747eed1 100644 --- a/plugins/org.python.pydev.parser/src/org/python/pydev/parser/PyParser.java +++ b/plugins/org.python.pydev.parser/src/org/python/pydev/parser/PyParser.java @@ -28,6 +28,7 @@ import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocumentExtension4; import org.eclipse.jface.text.IRegion; @@ -82,7 +83,7 @@ */ @SuppressWarnings("restriction") -public class PyParser extends BaseParser implements IPyParser { +public final class PyParser extends BaseParser implements IPyParser { /** * Just for tests: show whenever we're not able to parse some file. @@ -291,7 +292,7 @@ public ParseOutput reparseDocument(Object... argsToReparse) { version = IGrammarVersionProvider.LATEST_GRAMMAR_PY3_VERSION; } long documentTime = System.currentTimeMillis(); - ParseOutput obj = reparseDocument(new ParserInfo(document, version, true, additionalGrammarsToCheck)); + ParseOutput obj = parseFull(new ParserInfo(document, version, true, additionalGrammarsToCheck)); IFile original = null; IAdaptable adaptable = null; @@ -367,6 +368,34 @@ public ParseOutput reparseDocument(Object... argsToReparse) { //static methods that can be used to get the ast (and error if any) -------------------------------------- + public static SimpleNode parseSimple(String source, IGrammarVersionProvider versionProvider) + throws ParseException, MisconfigurationException { + return parseSimple(new Document(source), versionProvider); + } + + public static Module parseSimple(IDocument doc, IGrammarVersionProvider versionProvider) throws ParseException, + MisconfigurationException { + ParseOutput objects = parseFull(new ParserInfo(doc, versionProvider)); + Throwable exception = objects.error; + + if (exception != null) { + /* We try to get rid of the 'Throwable' exception, if possible */ + if (exception instanceof ParseException) { + throw (ParseException) exception; + } else if (exception instanceof TokenMgrError) { + /* Error from Lexer */ + throw new ParseException(exception.toString()); + } else { + throw new RuntimeException(exception); + } + } + + if (objects.error != null) { + throw new RuntimeException(objects.error); + } + return (Module) objects.ast; + } + public final static class ParserInfo implements IGrammarVersionProvider { public IDocument document; @@ -550,7 +579,7 @@ public static Tuple reparseDocumentInternal(IDocument doc, * @return a tuple with the SimpleNode root(if parsed) and the error (if any). * if we are able to recover from a reparse, we have both, the root and the error. */ - public static ParseOutput reparseDocument(ParserInfo info) { + public static ParseOutput parseFull(ParserInfo info) { if (info.grammarVersion == IPythonNature.GRAMMAR_PYTHON_VERSION_CYTHON) { return createCythonAst(info); } diff --git a/plugins/org.python.pydev.parser/src/org/python/pydev/parser/prettyprinterv2/Formatter.java b/plugins/org.python.pydev.parser/src/org/python/pydev/parser/prettyprinterv2/Formatter.java index ad6a9f8cab..b0b0418331 100644 --- a/plugins/org.python.pydev.parser/src/org/python/pydev/parser/prettyprinterv2/Formatter.java +++ b/plugins/org.python.pydev.parser/src/org/python/pydev/parser/prettyprinterv2/Formatter.java @@ -28,7 +28,7 @@ public void formatAll(IDocument doc, IPyFormatStdProvider edit, IFile f, boolean throws SyntaxErrorException { ParseOutput objects; try { - objects = PyParser.reparseDocument(new PyParser.ParserInfo(doc, edit.getPythonNature())); + objects = PyParser.parseFull(new PyParser.ParserInfo(doc, edit.getPythonNature())); } catch (MisconfigurationException e1) { Log.log(e1); return; diff --git a/plugins/org.python.pydev.refactoring/src/org/python/pydev/refactoring/ast/visitors/rewriter/Rewriter.java b/plugins/org.python.pydev.parser/src/org/python/pydev/parser/prettyprinterv2/Rewriter.java similarity index 88% rename from plugins/org.python.pydev.refactoring/src/org/python/pydev/refactoring/ast/visitors/rewriter/Rewriter.java rename to plugins/org.python.pydev.parser/src/org/python/pydev/parser/prettyprinterv2/Rewriter.java index 3b9e034506..f2aeed7cef 100644 --- a/plugins/org.python.pydev.refactoring/src/org/python/pydev/refactoring/ast/visitors/rewriter/Rewriter.java +++ b/plugins/org.python.pydev.parser/src/org/python/pydev/parser/prettyprinterv2/Rewriter.java @@ -9,15 +9,14 @@ * Contributors: * Fabio Zadrozny - initial API and implementation ******************************************************************************/ -package org.python.pydev.refactoring.ast.visitors.rewriter; +package org.python.pydev.parser.prettyprinterv2; import org.python.pydev.core.IGrammarVersionProvider; import org.python.pydev.core.IIndentPrefs; import org.python.pydev.core.autoedit.DefaultIndentPrefs; +import org.python.pydev.parser.PyParser; import org.python.pydev.parser.jython.SimpleNode; import org.python.pydev.parser.jython.ast.factory.AdapterPrefs; -import org.python.pydev.parser.prettyprinterv2.PrettyPrinterPrefsV2; -import org.python.pydev.parser.prettyprinterv2.PrettyPrinterV2; /** * This class just provides an interface for using the rewriter. @@ -26,7 +25,7 @@ public final class Rewriter { public static String reparsed(String source, AdapterPrefs adapterPrefs) { try { - SimpleNode root = org.python.pydev.ast.adapters.visitors.VisitorFactory.getRootNodeFromString(source, + SimpleNode root = PyParser.parseSimple(source, adapterPrefs.versionProvider); return createSourceFromAST(root, adapterPrefs); } catch (Throwable e) { diff --git a/plugins/org.python.pydev.parser/src/org/python/pydev/parser/visitors/NodeUtils.java b/plugins/org.python.pydev.parser/src/org/python/pydev/parser/visitors/NodeUtils.java index b8573d3a20..50f959a2ff 100644 --- a/plugins/org.python.pydev.parser/src/org/python/pydev/parser/visitors/NodeUtils.java +++ b/plugins/org.python.pydev.parser/src/org/python/pydev/parser/visitors/NodeUtils.java @@ -2207,7 +2207,7 @@ public static exprType[] extractElts(ISimpleNode node) { public static exprType extractOptionalValueSubscript(exprType node) { if (node instanceof Str) { ParseOutput objects = PyParser - .reparseDocument(new ParserInfo(new Document(((Str) node).s), + .parseFull(new ParserInfo(new Document(((Str) node).s), IPythonNature.LATEST_GRAMMAR_PY3_VERSION, null)); if (objects.error == null && objects.ast != null && objects.ast instanceof Module && ((Module) objects.ast).body.length == 1 && ((Module) objects.ast).body[0] != null diff --git a/plugins/org.python.pydev.parser/tests/org/python/pydev/parser/PyParserTest.java b/plugins/org.python.pydev.parser/tests/org/python/pydev/parser/PyParserTest.java index a53507740e..50034e4f95 100644 --- a/plugins/org.python.pydev.parser/tests/org/python/pydev/parser/PyParserTest.java +++ b/plugins/org.python.pydev.parser/tests/org/python/pydev/parser/PyParserTest.java @@ -77,7 +77,7 @@ public void testTryReparse() throws BadLocationException { } PyParser.ParserInfo parserInfo = new PyParser.ParserInfo(doc, IPythonNature.LATEST_GRAMMAR_PY2_VERSION, null); - ParseOutput reparseDocument = PyParser.reparseDocument(parserInfo); + ParseOutput reparseDocument = PyParser.parseFull(parserInfo); assertTrue(reparseDocument.ast == null); assertTrue(reparseDocument.error != null); } diff --git a/plugins/org.python.pydev.parser/tests/org/python/pydev/parser/PyParserTestBase.java b/plugins/org.python.pydev.parser/tests/org/python/pydev/parser/PyParserTestBase.java index 21c9d45251..29d7a8482e 100644 --- a/plugins/org.python.pydev.parser/tests/org/python/pydev/parser/PyParserTestBase.java +++ b/plugins/org.python.pydev.parser/tests/org/python/pydev/parser/PyParserTestBase.java @@ -103,7 +103,7 @@ protected Throwable parseILegalDoc(IDocument doc) { protected Throwable parseILegalDoc(IDocument doc, boolean generateTree) { ParseOutput objects; try { - objects = PyParser.reparseDocument(new ParserInfo(doc, parser.getGrammarVersion(), generateTree, null)); + objects = PyParser.parseFull(new ParserInfo(doc, parser.getGrammarVersion(), generateTree, null)); } catch (MisconfigurationException e) { throw new RuntimeException(e); } @@ -162,7 +162,7 @@ protected static SimpleNode parseLegalDoc(IDocument doc, Object[] additionalErrI */ protected static SimpleNode parseLegalDoc(IDocument doc, Object[] additionalErrInfo, int grammarVersion, boolean generateTree) { - ParseOutput objects = PyParser.reparseDocument(new ParserInfo(doc, grammarVersion, + ParseOutput objects = PyParser.parseFull(new ParserInfo(doc, grammarVersion, generateTree, null)); Object err = objects.error; diff --git a/plugins/org.python.pydev.parser/tests/org/python/pydev/parser/PyParserWithoutTree.java b/plugins/org.python.pydev.parser/tests/org/python/pydev/parser/PyParserWithoutTree.java index 0f5831167b..8d2f036ed4 100644 --- a/plugins/org.python.pydev.parser/tests/org/python/pydev/parser/PyParserWithoutTree.java +++ b/plugins/org.python.pydev.parser/tests/org/python/pydev/parser/PyParserWithoutTree.java @@ -37,12 +37,12 @@ public AdditionalGrammarVersionsToCheck getAdditionalGrammarVersions() throws Mi return null; } }; - ParseOutput tuple = PyParser.reparseDocument(new PyParser.ParserInfo(new Document(contents), + ParseOutput tuple = PyParser.parseFull(new PyParser.ParserInfo(new Document(contents), grammarProvider, false)); assertTrue("Found: " + tuple.error, tuple.error instanceof ParseException); - tuple = PyParser.reparseDocument(new PyParser.ParserInfo(new Document("a = 10"), grammarProvider, false)); + tuple = PyParser.parseFull(new PyParser.ParserInfo(new Document("a = 10"), grammarProvider, false)); assertTrue("Found: " + tuple.error, tuple.error == null); } diff --git a/plugins/org.python.pydev.parser/tests/org/python/pydev/parser/visitors/scope/CodeFoldingVisitorTest.java b/plugins/org.python.pydev.parser/tests/org/python/pydev/parser/visitors/scope/CodeFoldingVisitorTest.java index ecabbf695f..a91089c42a 100644 --- a/plugins/org.python.pydev.parser/tests/org/python/pydev/parser/visitors/scope/CodeFoldingVisitorTest.java +++ b/plugins/org.python.pydev.parser/tests/org/python/pydev/parser/visitors/scope/CodeFoldingVisitorTest.java @@ -40,7 +40,7 @@ public void testIfElifElse() throws Exception { "else:\n" + " print(3)\n" + "\n"; - ParseOutput objects = PyParser.reparseDocument(new PyParser.ParserInfo(new Document(str), + ParseOutput objects = PyParser.parseFull(new PyParser.ParserInfo(new Document(str), IPythonNature.GRAMMAR_PYTHON_VERSION_3_5, null)); SimpleNode root = (SimpleNode) objects.ast; root.accept(visitor); @@ -66,7 +66,7 @@ public void testIf() throws Exception { " else:\n" + " print(4)\n" + ""; - ParseOutput objects = PyParser.reparseDocument(new PyParser.ParserInfo(new Document(str), + ParseOutput objects = PyParser.parseFull(new PyParser.ParserInfo(new Document(str), IPythonNature.GRAMMAR_PYTHON_VERSION_3_5, null)); SimpleNode root = (SimpleNode) objects.ast; root.accept(visitor); @@ -91,7 +91,7 @@ public void testWith() throws Exception { "with a:\n" + " print a\n" + ""; - ParseOutput objects = PyParser.reparseDocument(new PyParser.ParserInfo(new Document(str), + ParseOutput objects = PyParser.parseFull(new PyParser.ParserInfo(new Document(str), IPythonNature.GRAMMAR_PYTHON_VERSION_3_5, null)); SimpleNode root = (SimpleNode) objects.ast; root.accept(visitor); @@ -111,7 +111,7 @@ public void testFor() throws Exception { " print(5)\n" + "\n" + ""; - ParseOutput objects = PyParser.reparseDocument(new PyParser.ParserInfo(new Document(str), + ParseOutput objects = PyParser.parseFull(new PyParser.ParserInfo(new Document(str), IPythonNature.GRAMMAR_PYTHON_VERSION_3_5, null)); SimpleNode root = (SimpleNode) objects.ast; root.accept(visitor); @@ -127,7 +127,7 @@ public void testImport() throws Exception { "from a import b\n" + "import b\n" + ""; - ParseOutput objects = PyParser.reparseDocument(new PyParser.ParserInfo(new Document(str), + ParseOutput objects = PyParser.parseFull(new PyParser.ParserInfo(new Document(str), IPythonNature.GRAMMAR_PYTHON_VERSION_3_5, null)); SimpleNode root = (SimpleNode) objects.ast; root.accept(visitor); @@ -147,7 +147,7 @@ public void testWhile() throws Exception { " print(5)\n" + "\n" + ""; - ParseOutput objects = PyParser.reparseDocument(new PyParser.ParserInfo(new Document(str), + ParseOutput objects = PyParser.parseFull(new PyParser.ParserInfo(new Document(str), IPythonNature.GRAMMAR_PYTHON_VERSION_3_5, null)); SimpleNode root = (SimpleNode) objects.ast; root.accept(visitor); @@ -167,7 +167,7 @@ public void testTry() throws Exception { " print(5)\n" + "\n" + ""; - ParseOutput objects = PyParser.reparseDocument(new PyParser.ParserInfo(new Document(str), + ParseOutput objects = PyParser.parseFull(new PyParser.ParserInfo(new Document(str), IPythonNature.GRAMMAR_PYTHON_VERSION_3_5, null)); SimpleNode root = (SimpleNode) objects.ast; root.accept(visitor); @@ -187,7 +187,7 @@ public void testTryFinally() throws Exception { " print(5)\n" + "\n" + ""; - ParseOutput objects = PyParser.reparseDocument(new PyParser.ParserInfo(new Document(str), + ParseOutput objects = PyParser.parseFull(new PyParser.ParserInfo(new Document(str), IPythonNature.GRAMMAR_PYTHON_VERSION_3_5, null)); SimpleNode root = (SimpleNode) objects.ast; root.accept(visitor); @@ -206,7 +206,7 @@ public void testTryFinallyVersion25() throws Exception { " print(5)\n" + "\n" + ""; - ParseOutput objects = PyParser.reparseDocument(new PyParser.ParserInfo(new Document(str), + ParseOutput objects = PyParser.parseFull(new PyParser.ParserInfo(new Document(str), IPythonNature.GRAMMAR_PYTHON_VERSION_3_5, null)); SimpleNode root = (SimpleNode) objects.ast; root.accept(visitor); @@ -223,7 +223,7 @@ public void testString() throws Exception { "test\n" + "'''\n" + ""; - ParseOutput objects = PyParser.reparseDocument(new PyParser.ParserInfo(new Document(str), + ParseOutput objects = PyParser.parseFull(new PyParser.ParserInfo(new Document(str), IPythonNature.GRAMMAR_PYTHON_VERSION_3_5, null)); SimpleNode root = (SimpleNode) objects.ast; root.accept(visitor); @@ -251,7 +251,7 @@ public void testTryFinally2() throws Exception { " finally:\n" + " pass\n" + "\n"; - ParseOutput objects = PyParser.reparseDocument(new PyParser.ParserInfo(new Document(str), + ParseOutput objects = PyParser.parseFull(new PyParser.ParserInfo(new Document(str), IPythonNature.GRAMMAR_PYTHON_VERSION_3_5, null)); SimpleNode root = (SimpleNode) objects.ast; root.accept(visitor); diff --git a/plugins/org.python.pydev.parser/tests/org/python/pydev/parser/visitors/scope/EasyASTIteratorTest.java b/plugins/org.python.pydev.parser/tests/org/python/pydev/parser/visitors/scope/EasyASTIteratorTest.java index b8f3a6a02b..b94adbb859 100644 --- a/plugins/org.python.pydev.parser/tests/org/python/pydev/parser/visitors/scope/EasyASTIteratorTest.java +++ b/plugins/org.python.pydev.parser/tests/org/python/pydev/parser/visitors/scope/EasyASTIteratorTest.java @@ -79,7 +79,7 @@ public void testClassesMethods() throws Exception { + ""; - ParseOutput objects = PyParser.reparseDocument(new PyParser.ParserInfo(new Document(str), + ParseOutput objects = PyParser.parseFull(new PyParser.ParserInfo(new Document(str), IPythonNature.GRAMMAR_PYTHON_VERSION_3_5, null)); SimpleNode root = (SimpleNode) objects.ast; root.accept(visitor); @@ -108,7 +108,7 @@ public void testMultiline() throws Exception { "c \n" + "''' \n"; - ParseOutput objects = PyParser.reparseDocument(new PyParser.ParserInfo(new Document(str), + ParseOutput objects = PyParser.parseFull(new PyParser.ParserInfo(new Document(str), IPythonNature.GRAMMAR_PYTHON_VERSION_3_5, null)); SimpleNode root = (SimpleNode) objects.ast; root.accept(visitor); @@ -139,7 +139,7 @@ public void testMultiline2() throws Exception { " t2 \n" + " ''' \n"; - ParseOutput objects = PyParser.reparseDocument(new PyParser.ParserInfo(new Document(str), + ParseOutput objects = PyParser.parseFull(new PyParser.ParserInfo(new Document(str), IPythonNature.GRAMMAR_PYTHON_VERSION_3_5, null)); SimpleNode root = (SimpleNode) objects.ast; root.accept(visitor); @@ -164,7 +164,7 @@ public void testImports() throws Exception { "from test.lib import test as alias\n" + ""; - ParseOutput objects = PyParser.reparseDocument(new PyParser.ParserInfo(new Document(str), + ParseOutput objects = PyParser.parseFull(new PyParser.ParserInfo(new Document(str), IPythonNature.GRAMMAR_PYTHON_VERSION_3_5, null)); SimpleNode root = (SimpleNode) objects.ast; root.accept(visitor); @@ -186,7 +186,7 @@ public void testDecorator() throws Exception { "\n" + "\n"; - ParseOutput objects = PyParser.reparseDocument(new PyParser.ParserInfo(new Document(str), + ParseOutput objects = PyParser.parseFull(new PyParser.ParserInfo(new Document(str), IPythonNature.GRAMMAR_PYTHON_VERSION_3_5, null)); if (objects.error != null) { throw new RuntimeException(objects.error); @@ -216,7 +216,7 @@ public void testAttributes() throws Exception { " classAttr = 10\n" + "pass"; - ParseOutput objects = PyParser.reparseDocument(new PyParser.ParserInfo(new Document(str), + ParseOutput objects = PyParser.parseFull(new PyParser.ParserInfo(new Document(str), IPythonNature.GRAMMAR_PYTHON_VERSION_3_5, null)); SimpleNode root = (SimpleNode) objects.ast; root.accept(visitor); diff --git a/plugins/org.python.pydev.refactoring/contrib/ch/hsr/ukistler/astgraph/ASTGraph.java b/plugins/org.python.pydev.refactoring/contrib/ch/hsr/ukistler/astgraph/ASTGraph.java index 9bfec0e7d1..b16f5a31c5 100644 --- a/plugins/org.python.pydev.refactoring/contrib/ch/hsr/ukistler/astgraph/ASTGraph.java +++ b/plugins/org.python.pydev.refactoring/contrib/ch/hsr/ukistler/astgraph/ASTGraph.java @@ -56,7 +56,7 @@ public ParseOutput parseFile(String fileName) throws FileNotFoundException, IOEx } IDocument doc = new Document(source.toString()); - ParseOutput objects = PyParser.reparseDocument(new PyParser.ParserInfo(doc, + ParseOutput objects = PyParser.parseFull(new PyParser.ParserInfo(doc, IPythonNature.LATEST_GRAMMAR_PY3_VERSION, null)); if (objects.error != null) { throw objects.error; diff --git a/plugins/org.python.pydev.refactoring/src/org/python/pydev/refactoring/ast/visitors/VisitorFactory.java b/plugins/org.python.pydev.refactoring/src/org/python/pydev/refactoring/ast/visitors/VisitorFactory.java index a12f2b406d..4f380cf32a 100644 --- a/plugins/org.python.pydev.refactoring/src/org/python/pydev/refactoring/ast/visitors/VisitorFactory.java +++ b/plugins/org.python.pydev.refactoring/src/org/python/pydev/refactoring/ast/visitors/VisitorFactory.java @@ -108,6 +108,6 @@ public AdditionalGrammarVersionsToCheck getAdditionalGrammarVersions() } } } - return new ModuleAdapter(pythonModuleManager, file, doc, org.python.pydev.ast.adapters.visitors.VisitorFactory.getRootNode(doc, versionProvider), nature); + return new ModuleAdapter(pythonModuleManager, file, doc, org.python.pydev.parser.PyParser.parseSimple(doc, versionProvider), nature); } } diff --git a/plugins/org.python.pydev.refactoring/src/org/python/pydev/refactoring/core/base/RefactoringInfo.java b/plugins/org.python.pydev.refactoring/src/org/python/pydev/refactoring/core/base/RefactoringInfo.java index 1deb8c3a5a..aa4b773b81 100644 --- a/plugins/org.python.pydev.refactoring/src/org/python/pydev/refactoring/core/base/RefactoringInfo.java +++ b/plugins/org.python.pydev.refactoring/src/org/python/pydev/refactoring/core/base/RefactoringInfo.java @@ -281,7 +281,7 @@ private boolean isValidWhenCodeExtracted(RefactoringInfo info, ICoreTextSelectio Document temp = new Document(document.get()); temp.replace(o1.getOffset() + firstNonWhitespace, o1.getLength() - (firstNonWhitespace + lastNonWhitespace), "call()"); - Module rootNode = org.python.pydev.ast.adapters.visitors.VisitorFactory.getRootNode(temp, info.getVersionProvider()); + Module rootNode = org.python.pydev.parser.PyParser.parseSimple(temp, info.getVersionProvider()); if (rootNode != null) { return true; } diff --git a/plugins/org.python.pydev.refactoring/src/org/python/pydev/refactoring/core/edit/AbstractReplaceEdit.java b/plugins/org.python.pydev.refactoring/src/org/python/pydev/refactoring/core/edit/AbstractReplaceEdit.java index 1177bb3b5a..e09a387c5b 100644 --- a/plugins/org.python.pydev.refactoring/src/org/python/pydev/refactoring/core/edit/AbstractReplaceEdit.java +++ b/plugins/org.python.pydev.refactoring/src/org/python/pydev/refactoring/core/edit/AbstractReplaceEdit.java @@ -27,7 +27,7 @@ import org.eclipse.text.edits.ReplaceEdit; import org.eclipse.text.edits.TextEdit; import org.python.pydev.core.MisconfigurationException; -import org.python.pydev.refactoring.ast.visitors.rewriter.Rewriter; +import org.python.pydev.parser.prettyprinterv2.Rewriter; import org.python.pydev.refactoring.core.request.IRefactoringRequest; public abstract class AbstractReplaceEdit extends AbstractTextEdit { diff --git a/plugins/org.python.pydev.refactoring/src/org/python/pydev/refactoring/core/edit/AbstractTextEdit.java b/plugins/org.python.pydev.refactoring/src/org/python/pydev/refactoring/core/edit/AbstractTextEdit.java index 6740ad737a..d7dd9ba736 100644 --- a/plugins/org.python.pydev.refactoring/src/org/python/pydev/refactoring/core/edit/AbstractTextEdit.java +++ b/plugins/org.python.pydev.refactoring/src/org/python/pydev/refactoring/core/edit/AbstractTextEdit.java @@ -34,7 +34,7 @@ import org.python.pydev.parser.jython.ast.factory.NodeHelper; import org.python.pydev.parser.jython.ast.factory.PyAstFactory; import org.python.pydev.parser.prettyprinterv2.MakeAstValidForPrettyPrintingVisitor; -import org.python.pydev.refactoring.ast.visitors.rewriter.Rewriter; +import org.python.pydev.parser.prettyprinterv2.Rewriter; import org.python.pydev.refactoring.core.request.IExtractMethodRefactoringRequest; import org.python.pydev.refactoring.core.request.IRefactoringRequest; diff --git a/plugins/org.python.pydev.refactoring/tests/org/python/pydev/refactoring/tests/coderefactoring/extractmethod/ExtractMethodTestCase.java b/plugins/org.python.pydev.refactoring/tests/org/python/pydev/refactoring/tests/coderefactoring/extractmethod/ExtractMethodTestCase.java index ff3591de7a..dadf1dff1a 100644 --- a/plugins/org.python.pydev.refactoring/tests/org/python/pydev/refactoring/tests/coderefactoring/extractmethod/ExtractMethodTestCase.java +++ b/plugins/org.python.pydev.refactoring/tests/org/python/pydev/refactoring/tests/coderefactoring/extractmethod/ExtractMethodTestCase.java @@ -68,7 +68,7 @@ public void runTest() throws Throwable { IGrammarVersionProvider versionProvider = createVersionProvider(); Module astModule; try { - astModule = org.python.pydev.ast.adapters.visitors.VisitorFactory.getRootNode(doc, versionProvider); + astModule = org.python.pydev.parser.PyParser.parseSimple(doc, versionProvider); } catch (ParseException e) { throw new RuntimeException("Error parsing:\n" + data.source + "\n---\nError: " + e.getMessage(), e); } catch (Exception e1) { diff --git a/plugins/org.python.pydev.refactoring/tests/org/python/pydev/refactoring/tests/core/AbstractRewriterTestCase.java b/plugins/org.python.pydev.refactoring/tests/org/python/pydev/refactoring/tests/core/AbstractRewriterTestCase.java index d7ebf41167..c7b12e609d 100644 --- a/plugins/org.python.pydev.refactoring/tests/org/python/pydev/refactoring/tests/core/AbstractRewriterTestCase.java +++ b/plugins/org.python.pydev.refactoring/tests/org/python/pydev/refactoring/tests/core/AbstractRewriterTestCase.java @@ -24,7 +24,7 @@ import org.python.pydev.core.IGrammarVersionProvider; import org.python.pydev.core.MisconfigurationException; import org.python.pydev.parser.jython.ast.factory.AdapterPrefs; -import org.python.pydev.refactoring.ast.visitors.rewriter.Rewriter; +import org.python.pydev.parser.prettyprinterv2.Rewriter; public abstract class AbstractRewriterTestCase extends AbstractIOTestCase { diff --git a/plugins/org.python.pydev.refactoring/tests/org/python/pydev/refactoring/tests/visitors/SelectionExtensionTestCase.java b/plugins/org.python.pydev.refactoring/tests/org/python/pydev/refactoring/tests/visitors/SelectionExtensionTestCase.java index 146b728ac4..308c8cec37 100644 --- a/plugins/org.python.pydev.refactoring/tests/org/python/pydev/refactoring/tests/visitors/SelectionExtensionTestCase.java +++ b/plugins/org.python.pydev.refactoring/tests/org/python/pydev/refactoring/tests/visitors/SelectionExtensionTestCase.java @@ -25,7 +25,7 @@ import org.eclipse.jface.text.IDocument; import org.python.pydev.core.IGrammarVersionProvider; import org.python.pydev.core.MisconfigurationException; -import org.python.pydev.refactoring.ast.visitors.rewriter.Rewriter; +import org.python.pydev.parser.prettyprinterv2.Rewriter; import org.python.pydev.refactoring.core.base.RefactoringInfo; import org.python.pydev.refactoring.core.base.RefactoringInfo.SelectionComputer; import org.python.pydev.refactoring.core.base.RefactoringInfo.SelectionComputer.SelectionComputerKind; diff --git a/plugins/org.python.pydev/src/org/python/pydev/editor/PyEdit.java b/plugins/org.python.pydev/src/org/python/pydev/editor/PyEdit.java index c5809369f1..e36899b0f4 100644 --- a/plugins/org.python.pydev/src/org/python/pydev/editor/PyEdit.java +++ b/plugins/org.python.pydev/src/org/python/pydev/editor/PyEdit.java @@ -965,7 +965,7 @@ protected BaseParserManager getParserManager() { * Note: This function will actually do a parse operation when called (so, it should be called with care). */ public boolean hasSyntaxError(IDocument doc) throws MisconfigurationException { - ParseOutput reparse = PyParser.reparseDocument(new PyParser.ParserInfo(doc, this, false)); + ParseOutput reparse = PyParser.parseFull(new PyParser.ParserInfo(doc, this, false)); if (reparse.error != null) { this.getStatusLineManager().setErrorMessage(reparse.error.getMessage()); return true; diff --git a/plugins/org.python.pydev/tests/org/python/pydev/editor/codefolding/CodeFoldingSetterTest.java b/plugins/org.python.pydev/tests/org/python/pydev/editor/codefolding/CodeFoldingSetterTest.java index 239e6c2d47..42f6d301f8 100644 --- a/plugins/org.python.pydev/tests/org/python/pydev/editor/codefolding/CodeFoldingSetterTest.java +++ b/plugins/org.python.pydev/tests/org/python/pydev/editor/codefolding/CodeFoldingSetterTest.java @@ -366,7 +366,7 @@ private List getMarks(Document doc) { } private List getMarks(Document doc, int grammarVersion) { - ParseOutput r = PyParser.reparseDocument(new PyParser.ParserInfo(doc, grammarVersion, null)); + ParseOutput r = PyParser.parseFull(new PyParser.ParserInfo(doc, grammarVersion, null)); List marks = CodeFoldingSetter.getMarks(doc, (SimpleNode) r.ast, true, null); if (DEBUG) { for (FoldingEntry entry : marks) { diff --git a/plugins/org.python.pydev/tests/org/python/pydev/parser/GenCythonAstTest.java b/plugins/org.python.pydev/tests/org/python/pydev/parser/GenCythonAstTest.java index faa9cb33c6..d6ab575580 100644 --- a/plugins/org.python.pydev/tests/org/python/pydev/parser/GenCythonAstTest.java +++ b/plugins/org.python.pydev/tests/org/python/pydev/parser/GenCythonAstTest.java @@ -297,7 +297,7 @@ public ParseOutput compareCase(String expected, String cython, LineColComparator ParseOutput cythonParseOutput = new GenCythonAstImpl(parserInfoCython).genCythonAst(); ParserInfo parserInfoInternal = new ParserInfo(new Document(expected), grammarVersionProvider); - ParseOutput parseOutput = PyParser.reparseDocument(parserInfoInternal); + ParseOutput parseOutput = PyParser.parseFull(parserInfoInternal); if (cythonParseOutput.ast == null) { if (cythonParseOutput.error != null) { throw new RuntimeException(cythonParseOutput.error); diff --git a/plugins/org.python.pydev/tests/org/python/pydev/parser/PyParserCythonTest.java b/plugins/org.python.pydev/tests/org/python/pydev/parser/PyParserCythonTest.java index 8f498ecefa..fca3979fbc 100644 --- a/plugins/org.python.pydev/tests/org/python/pydev/parser/PyParserCythonTest.java +++ b/plugins/org.python.pydev/tests/org/python/pydev/parser/PyParserCythonTest.java @@ -52,7 +52,7 @@ public void testCythonParsing() throws Exception { ""; Document doc = new Document(str); ParseOutput parseOutput = PyParser - .reparseDocument(new ParserInfo(doc, IPythonNature.GRAMMAR_PYTHON_VERSION_CYTHON, + .parseFull(new ParserInfo(doc, IPythonNature.GRAMMAR_PYTHON_VERSION_CYTHON, true, null)); assertTrue(parseOutput.isCython); assertNull(parseOutput.error); diff --git a/plugins/org.python.pydev/tests_completions/org/python/pydev/ast/codecompletion/revisited/ModuleTest.java b/plugins/org.python.pydev/tests_completions/org/python/pydev/ast/codecompletion/revisited/ModuleTest.java index 34e612e497..529e78eeb0 100644 --- a/plugins/org.python.pydev/tests_completions/org/python/pydev/ast/codecompletion/revisited/ModuleTest.java +++ b/plugins/org.python.pydev/tests_completions/org/python/pydev/ast/codecompletion/revisited/ModuleTest.java @@ -49,7 +49,7 @@ public static void main(String[] args) { } public void testMod1() { - ParseOutput obj = PyParser.reparseDocument(new PyParser.ParserInfo(new Document(getDoc1()), + ParseOutput obj = PyParser.parseFull(new PyParser.ParserInfo(new Document(getDoc1()), IPythonNature.GRAMMAR_PYTHON_VERSION_3_5, null)); SimpleNode n = (SimpleNode) obj.ast; IModule module = AbstractModule.createModule(n, null); @@ -76,7 +76,7 @@ public void testMod2() { " pass\n" + "other = method\n" + ""; - ParseOutput obj = PyParser.reparseDocument(new PyParser.ParserInfo(new Document(doc), + ParseOutput obj = PyParser.parseFull(new PyParser.ParserInfo(new Document(doc), IPythonNature.GRAMMAR_PYTHON_VERSION_3_5, null)); SimpleNode n = (SimpleNode) obj.ast; IModule module = AbstractModule.createModule(n, null); @@ -101,7 +101,7 @@ public void testMod3() { " pass\n" + "other = another = method\n" + ""; - ParseOutput obj = PyParser.reparseDocument(new PyParser.ParserInfo(new Document(doc), + ParseOutput obj = PyParser.parseFull(new PyParser.ParserInfo(new Document(doc), IPythonNature.GRAMMAR_PYTHON_VERSION_3_5, null)); SimpleNode n = (SimpleNode) obj.ast; IModule module = AbstractModule.createModule(n, null);