Skip to content

Commit

Permalink
wip2
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Sep 21, 2024
1 parent 113af65 commit 0769038
Show file tree
Hide file tree
Showing 19 changed files with 101 additions and 123 deletions.
1 change: 1 addition & 0 deletions plugins/org.python.pydev.ast/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Export-Package: org.python.pydev.ast,
org.python.pydev.ast.adapters.context,
org.python.pydev.ast.adapters.offsetstrategy,
org.python.pydev.ast.adapters.visitors,
org.python.pydev.ast.adapters.visitors.selection,
org.python.pydev.ast.analysis,
org.python.pydev.ast.analysis.messages,
org.python.pydev.ast.builder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import org.python.pydev.ast.adapters.ModuleAdapter;
import org.python.pydev.ast.adapters.PythonModuleManager;
import org.python.pydev.ast.adapters.context.AbstractContextVisitor;
import org.python.pydev.ast.adapters.visitors.selection.SelectionException;
import org.python.pydev.ast.adapters.visitors.selection.SelectionExtenderVisitor;
import org.python.pydev.ast.adapters.visitors.selection.SelectionValidationVisitor;
import org.python.pydev.ast.codecompletion.revisited.modules.SourceModule;
import org.python.pydev.core.BaseModuleRequest;
import org.python.pydev.core.IGrammarVersionProvider;
Expand Down Expand Up @@ -109,4 +112,28 @@ public AdditionalGrammarVersionsToCheck getAdditionalGrammarVersions()
return new ModuleAdapter(pythonModuleManager, file, doc, org.python.pydev.parser.PyParser.parseSimple(doc, versionProvider), nature);
}

public static void validateSelection(ModuleAdapter scope) throws SelectionException {
SelectionValidationVisitor visitor = null;
try {
visitor = new SelectionValidationVisitor();
scope.getASTNode().accept(visitor);
} catch (SelectionException e) {
throw e;
} catch (Throwable e) {
throw new RuntimeException(e);
}
}

public static ICoreTextSelection createSelectionExtension(AbstractScopeNode<?> scope,
ICoreTextSelection selection) {
SelectionExtenderVisitor visitor = null;
try {
visitor = new SelectionExtenderVisitor(scope.getModule(), selection);
scope.getASTNode().accept(visitor);
} catch (Exception e) {
throw new RuntimeException(e);
}
return visitor.getSelection();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
*/

package org.python.pydev.refactoring.ast.visitors.selection;
package org.python.pydev.ast.adapters.visitors.selection;

import org.python.pydev.parser.jython.SimpleNode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
*/

package org.python.pydev.refactoring.ast.visitors.selection;
package org.python.pydev.ast.adapters.visitors.selection;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
*/

package org.python.pydev.refactoring.ast.visitors.selection;
package org.python.pydev.ast.adapters.visitors.selection;

import org.python.pydev.ast.codecompletion.revisited.visitors.AbstractVisitor;
import org.python.pydev.parser.jython.SimpleNode;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* Contributors:
* Fabio Zadrozny <[email protected]> - initial implementation
******************************************************************************/
/*
/*
* Copyright (C) 2006, 2007 Dennis Hunziker, Ueli Kistler
* Copyright (C) 2007 Reto Schuettel, Robin Stocker
*
* IFS Institute for Software, HSR Rapperswil, Switzerland
*
*
*/

package org.python.pydev.refactoring.coderefactoring.extractmethod;
Expand All @@ -32,9 +32,8 @@
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.python.pydev.ast.adapters.IClassDefAdapter;
import org.python.pydev.ast.adapters.ModuleAdapter;
import org.python.pydev.ast.adapters.visitors.selection.SelectionException;
import org.python.pydev.core.log.Log;
import org.python.pydev.refactoring.ast.visitors.VisitorFactory;
import org.python.pydev.refactoring.ast.visitors.selection.SelectionException;
import org.python.pydev.refactoring.core.base.AbstractPythonRefactoring;
import org.python.pydev.refactoring.core.base.RefactoringInfo;
import org.python.pydev.refactoring.core.base.RefactoringInfo.SelectionComputer;
Expand Down Expand Up @@ -70,7 +69,8 @@ public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws Core
}

try {
VisitorFactory.validateSelection(selectionComputer.selectionModuleAdapter);
org.python.pydev.ast.adapters.visitors.VisitorFactory
.validateSelection(selectionComputer.selectionModuleAdapter);
} catch (SelectionException e) {
status.addFatalError(e.getMessage());
return status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import org.python.pydev.parser.jython.ast.exprType;
import org.python.pydev.parser.jython.ast.stmtType;
import org.python.pydev.parser.jython.ast.factory.AdapterPrefs;
import org.python.pydev.refactoring.ast.visitors.VisitorFactory;
import org.python.pydev.shared_core.SharedCorePlugin;
import org.python.pydev.shared_core.string.CoreTextSelection;
import org.python.pydev.shared_core.string.ICoreTextSelection;
Expand Down Expand Up @@ -133,7 +132,8 @@ private void initInfo(ICoreTextSelection selection) {
}

try {
this.moduleAdapter = org.python.pydev.ast.adapters.visitors.VisitorFactory.createModuleAdapter(moduleManager, realFile, doc, nature,
this.moduleAdapter = org.python.pydev.ast.adapters.visitors.VisitorFactory.createModuleAdapter(
moduleManager, realFile, doc, nature,
this.versionProvider);
} catch (Throwable e) {
throw new RuntimeException(e);
Expand Down Expand Up @@ -314,7 +314,8 @@ private ModuleAdapter getParsedMultilineSelection(RefactoringInfo info, ICoreTex
source = source.replaceAll("\r", "");

try {
ModuleAdapter node = org.python.pydev.ast.adapters.visitors.VisitorFactory.createModuleAdapter(null, null, new Document(source), null,
ModuleAdapter node = org.python.pydev.ast.adapters.visitors.VisitorFactory.createModuleAdapter(null,
null, new Document(source), null,
info.getVersionProvider());
return node;
} catch (TokenMgrError e) {
Expand All @@ -335,8 +336,9 @@ public SelectionComputer getSelectionComputer(SelectionComputer.SelectionCompute

private ICoreTextSelection getExtendedSelection() {
if (getScopeAdapter() != null) {
return moduleAdapter.normalizeSelection(VisitorFactory.createSelectionExtension(
getScopeAdapter(), this.userSelection));
return moduleAdapter
.normalizeSelection(org.python.pydev.ast.adapters.visitors.VisitorFactory.createSelectionExtension(
getScopeAdapter(), this.userSelection));
}
return null;
}
Expand All @@ -351,7 +353,8 @@ private ModuleAdapter getParsedSelection(ICoreTextSelection selection) {

if (selection != null && source.length() > 0) {
try {
parsedAdapter = org.python.pydev.ast.adapters.visitors.VisitorFactory.createModuleAdapter(moduleManager, null, new Document(source), nature,
parsedAdapter = org.python.pydev.ast.adapters.visitors.VisitorFactory.createModuleAdapter(moduleManager,
null, new Document(source), nature,
this.versionProvider);
} catch (TokenMgrError e) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* Contributors:
* Fabio Zadrozny <[email protected]> - initial implementation
******************************************************************************/
/*
* Copyright (C) 2006, 2007 Dennis Hunziker, Ueli Kistler
/*
* Copyright (C) 2006, 2007 Dennis Hunziker, Ueli Kistler
*/

package org.python.pydev.refactoring.tests.adapter;
Expand All @@ -24,7 +24,6 @@
import org.python.pydev.ast.adapters.FunctionDefAdapter;
import org.python.pydev.ast.adapters.IClassDefAdapter;
import org.python.pydev.ast.adapters.ModuleAdapter;
import org.python.pydev.refactoring.ast.visitors.VisitorFactory;
import org.python.pydev.refactoring.tests.core.AbstractIOTestCase;

public class FunctionDefAdapterTestCase extends AbstractIOTestCase {
Expand All @@ -37,7 +36,8 @@ public FunctionDefAdapterTestCase(String name) {
@Override
public void runTest() throws Throwable {
StringBuffer buffer = new StringBuffer();
ModuleAdapter module = org.python.pydev.ast.adapters.visitors.VisitorFactory.createModuleAdapter(null, null, new Document(data.source),
ModuleAdapter module = org.python.pydev.ast.adapters.visitors.VisitorFactory.createModuleAdapter(null, null,
new Document(data.source),
new PythonNatureStub(), createVersionProvider());
List<IClassDefAdapter> classes = module.getClasses();
assertTrue(classes.size() > 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.python.pydev.ast.codecompletion.shell.PythonShellTest;
import org.python.pydev.core.ShellId;
import org.python.pydev.core.TestDependent;
import org.python.pydev.refactoring.ast.visitors.VisitorFactory;
import org.python.pydev.shared_core.io.FileUtils;

public class HierarchyTestCase extends CodeCompletionTestsBase {
Expand Down Expand Up @@ -84,8 +83,9 @@ public void tearDown() throws Exception {

public void testHierarchyWithBuiltins() throws Throwable {

ModuleAdapter module = org.python.pydev.ast.adapters.visitors.VisitorFactory.createModuleAdapter(new PythonModuleManager(nature), file, new Document(
FileUtils.getFileContents(file)), nature, nature);
ModuleAdapter module = org.python.pydev.ast.adapters.visitors.VisitorFactory
.createModuleAdapter(new PythonModuleManager(nature), file, new Document(
FileUtils.getFileContents(file)), nature, nature);

List<IClassDefAdapter> classes = module.getClasses();
assertEquals(1, classes.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.eclipse.jface.text.Document;
import org.python.pydev.ast.adapters.FQIdentifier;
import org.python.pydev.ast.adapters.ModuleAdapter;
import org.python.pydev.refactoring.ast.visitors.VisitorFactory;
import org.python.pydev.refactoring.tests.core.AbstractIOTestCase;

import com.thoughtworks.xstream.XStream;
Expand All @@ -47,7 +46,8 @@ public void runTest() throws Throwable {
});
xstream.alias("config", ModuleAdapterTestConfig.class);

ModuleAdapter module = org.python.pydev.ast.adapters.visitors.VisitorFactory.createModuleAdapter(null, null, new Document(data.source),
ModuleAdapter module = org.python.pydev.ast.adapters.visitors.VisitorFactory.createModuleAdapter(null, null,
new Document(data.source),
new PythonNatureStub(), createVersionProvider());
if (data.config.length() > 0) {
config = (ModuleAdapterTestConfig) xstream.fromXML(data.config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* Contributors:
* Fabio Zadrozny <[email protected]> - initial implementation
******************************************************************************/
/*
* Copyright (C) 2006, 2007 Dennis Hunziker, Ueli Kistler
/*
* Copyright (C) 2006, 2007 Dennis Hunziker, Ueli Kistler
*/

package org.python.pydev.refactoring.tests.codegenerator.generateproperties;
Expand All @@ -30,7 +30,6 @@
import org.python.pydev.ast.adapters.IClassDefAdapter;
import org.python.pydev.ast.adapters.ModuleAdapter;
import org.python.pydev.core.MisconfigurationException;
import org.python.pydev.refactoring.ast.visitors.VisitorFactory;
import org.python.pydev.refactoring.codegenerator.generateproperties.edit.DeleteMethodEdit;
import org.python.pydev.refactoring.codegenerator.generateproperties.edit.GetterMethodEdit;
import org.python.pydev.refactoring.codegenerator.generateproperties.edit.PropertyEdit;
Expand Down Expand Up @@ -90,7 +89,8 @@ private IDocument applyGenerateProperties(MockupGeneratePropertiesRequestProcess

private MockupGeneratePropertiesRequestProcessor setupRequestProcessor(MockupGeneratePropertiesConfig config)
throws Throwable {
ModuleAdapter module = org.python.pydev.ast.adapters.visitors.VisitorFactory.createModuleAdapter(null, null, new Document(data.source),
ModuleAdapter module = org.python.pydev.ast.adapters.visitors.VisitorFactory.createModuleAdapter(null, null,
new Document(data.source),
new PythonNatureStub(), createVersionProvider());
List<IClassDefAdapter> classes = module.getClasses();
assertTrue(classes.size() > 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Contributors:
* Fabio Zadrozny <[email protected]> - initial implementation
******************************************************************************/
/*
/*
* Copyright (C) 2006, 2007 Dennis Hunziker, Ueli Kistler
* Copyright (C) 2007 Reto Schuettel, Robin Stocker
*/
Expand All @@ -35,7 +35,6 @@
import org.python.pydev.core.MisconfigurationException;
import org.python.pydev.parser.jython.ParseException;
import org.python.pydev.parser.jython.ast.Module;
import org.python.pydev.refactoring.ast.visitors.VisitorFactory;
import org.python.pydev.refactoring.coderefactoring.extractmethod.edit.ExtractCallEdit;
import org.python.pydev.refactoring.coderefactoring.extractmethod.edit.ExtractMethodEdit;
import org.python.pydev.refactoring.coderefactoring.extractmethod.edit.ParameterReturnDeduce;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.python.pydev.core.IGrammarVersionProvider;
import org.python.pydev.core.IModulesManager;
import org.python.pydev.core.MisconfigurationException;
import org.python.pydev.refactoring.ast.visitors.VisitorFactory;
import org.python.pydev.shared_core.io.FileUtils;
import org.python.pydev.shared_core.string.StringUtils;

Expand Down Expand Up @@ -64,8 +63,9 @@ protected ModuleAdapter createModuleAdapterFromDataSource(String version) throws

CodeCompletionTestsBase.nature.setVersion(version, null);
}
ModuleAdapter module = org.python.pydev.ast.adapters.visitors.VisitorFactory.createModuleAdapter(pythonModuleManager, data.file, new Document(
data.source), CodeCompletionTestsBase.nature, CodeCompletionTestsBase.nature);
ModuleAdapter module = org.python.pydev.ast.adapters.visitors.VisitorFactory
.createModuleAdapter(pythonModuleManager, data.file, new Document(
data.source), CodeCompletionTestsBase.nature, CodeCompletionTestsBase.nature);
return module;
} catch (Exception e) {
throw new RuntimeException("Error handling: " + data.file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* Contributors:
* Fabio Zadrozny <[email protected]> - initial implementation
******************************************************************************/
/*
* Copyright (C) 2006, 2007 Dennis Hunziker, Ueli Kistler
/*
* Copyright (C) 2006, 2007 Dennis Hunziker, Ueli Kistler
*/

package org.python.pydev.refactoring.tests.visitors;
Expand All @@ -27,7 +27,6 @@
import org.python.pydev.ast.adapters.context.ClassDefVisitor;
import org.python.pydev.ast.adapters.context.GlobalAttributeVisitor;
import org.python.pydev.ast.adapters.context.LocalAttributeVisitor;
import org.python.pydev.refactoring.ast.visitors.VisitorFactory;
import org.python.pydev.refactoring.tests.adapter.PythonNatureStub;
import org.python.pydev.refactoring.tests.core.AbstractIOTestCase;

Expand All @@ -40,16 +39,20 @@ public AttributeVisitorTestCase(String name) {
@Override
public void runTest() throws Throwable {
StringBuffer buffer = new StringBuffer();
ModuleAdapter module = org.python.pydev.ast.adapters.visitors.VisitorFactory.createModuleAdapter(null, null, new Document(data.source),
ModuleAdapter module = org.python.pydev.ast.adapters.visitors.VisitorFactory.createModuleAdapter(null, null,
new Document(data.source),
new PythonNatureStub(), createVersionProvider());
GlobalAttributeVisitor globalVisitor = org.python.pydev.ast.adapters.visitors.VisitorFactory.createContextVisitor(GlobalAttributeVisitor.class,
module.getASTNode(), module, module);
ClassDefVisitor classVisitor = org.python.pydev.ast.adapters.visitors.VisitorFactory.createContextVisitor(ClassDefVisitor.class, module.getASTNode(),
GlobalAttributeVisitor globalVisitor = org.python.pydev.ast.adapters.visitors.VisitorFactory
.createContextVisitor(GlobalAttributeVisitor.class,
module.getASTNode(), module, module);
ClassDefVisitor classVisitor = org.python.pydev.ast.adapters.visitors.VisitorFactory.createContextVisitor(
ClassDefVisitor.class, module.getASTNode(),
module, module);
assertTrue(classVisitor.getAll().size() > 0);

ClassDefAdapter classDefAdapter = (ClassDefAdapter) classVisitor.getAll().get(0);
LocalAttributeVisitor localVisitor = org.python.pydev.ast.adapters.visitors.VisitorFactory.createContextVisitor(LocalAttributeVisitor.class,
LocalAttributeVisitor localVisitor = org.python.pydev.ast.adapters.visitors.VisitorFactory.createContextVisitor(
LocalAttributeVisitor.class,
classDefAdapter.getASTNode(), module, classDefAdapter);
printAttributes(buffer, globalVisitor);
printAttributes(buffer, localVisitor);
Expand Down
Loading

0 comments on commit 0769038

Please sign in to comment.