Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extensible refactorer #21

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import org.eclipse.search.ui.NewSearchUI;
import org.python.pydev.editor.actions.refactoring.PyRefactorAction;
import org.python.pydev.editor.refactoring.AbstractPyRefactoring;
import org.python.pydev.editor.refactoring.IPyRefactoring2;
import org.python.pydev.editor.refactoring.RefactoringRequest;

import com.python.pydev.refactoring.IPyRefactoring2;
import com.python.pydev.refactoring.search.FindOccurrencesSearchQuery;

public class PyFindAllOccurrences extends PyRefactorAction{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@
import org.python.pydev.editor.codecompletion.revisited.visitors.AssignDefinition;
import org.python.pydev.editor.model.ItemPointer;
import org.python.pydev.editor.refactoring.AbstractPyRefactoring;
import org.python.pydev.editor.refactoring.HierarchyNodeModel;
import org.python.pydev.editor.refactoring.IPyRefactoring2;
import org.python.pydev.editor.refactoring.RefactoringRequest;
import org.python.pydev.editor.refactoring.TooManyMatchesException;
import org.python.pydev.parser.visitors.scope.ASTEntry;

import com.python.pydev.refactoring.IPyRefactoring2;
import com.python.pydev.refactoring.wizards.rename.PyRenameEntryPoint;
import com.python.pydev.refactoring.wizards.rename.PyRenameRefactoringWizard;
import com.python.pydev.ui.hierarchy.HierarchyNodeModel;

/**
* This is the entry point for any refactoring that we implement.
*
* @author Fabio
*/
public class Refactorer extends AbstractPyRefactoring implements IPyRefactoring2{
public class Refactorer extends AbstractPyRefactoring implements IPyRefactoring2 {

public String getName() {
return "PyDev Extensions Refactorer";
Expand Down Expand Up @@ -74,6 +74,7 @@ public ItemPointer[] findDefinition(RefactoringRequest request) throws TooManyMa


// --------------------------------------------------------- IPyRefactoring2
@Override
public boolean areAllInSameClassHierarchy(List<AssignDefinition> defs) {
return new RefactorerFinds(this).areAllInSameClassHierarchy(defs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.python.pydev.editor.codecompletion.revisited.visitors.AssignDefinition;
import org.python.pydev.editor.codecompletion.revisited.visitors.Definition;
import org.python.pydev.editor.model.ItemPointer;
import org.python.pydev.editor.refactoring.HierarchyNodeModel;
import org.python.pydev.editor.refactoring.PyRefactoringFindDefinition;
import org.python.pydev.editor.refactoring.RefactoringRequest;
import org.python.pydev.parser.jython.ast.ClassDef;
Expand All @@ -45,7 +46,6 @@

import com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo;
import com.python.pydev.analysis.additionalinfo.AdditionalProjectInterpreterInfo;
import com.python.pydev.ui.hierarchy.HierarchyNodeModel;

public class RefactorerFinds {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import org.python.pydev.core.docutils.PySelection;
import org.python.pydev.core.docutils.StringUtils;
import org.python.pydev.core.log.Log;
import org.python.pydev.editor.refactoring.IPyRefactoring2;
import org.python.pydev.editor.refactoring.RefactoringRequest;
import org.python.pydev.editorinput.PySourceLocatorBase;
import org.python.pydev.parser.visitors.scope.ASTEntry;

import com.python.pydev.refactoring.IPyRefactoring2;
import com.python.pydev.refactoring.actions.PyFindAllOccurrences;
import com.python.pydev.refactoring.refactorer.search.AbstractPythonSearchQuery;
import com.python.pydev.refactoring.wizards.rename.AbstractRenameRefactorProcess;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import org.python.pydev.editor.codecompletion.revisited.ProjectModulesManager;
import org.python.pydev.editor.codecompletion.revisited.modules.CompiledModule;
import org.python.pydev.editor.codecompletion.revisited.modules.SourceModule;
import org.python.pydev.editor.refactoring.HierarchyNodeModel;
import org.python.pydev.editor.refactoring.RefactoringRequest;
import org.python.pydev.parser.jython.SimpleNode;
import org.python.pydev.plugin.nature.PythonNature;

import com.python.pydev.analysis.additionalinfo.AdditionalInfoTestsBase;
import com.python.pydev.ui.hierarchy.HierarchyNodeModel;

public class ClassHierarchySearchTest extends AdditionalInfoTestsBase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
*/
package com.python.pydev.actions;

import org.python.pydev.editor.refactoring.HierarchyNodeModel;
import org.python.pydev.parser.jython.SimpleNode;
import org.python.pydev.parser.jython.ast.ClassDef;
import org.python.pydev.parser.visitors.NodeUtils;
import org.python.pydev.parser.visitors.scope.ASTEntry;

import com.python.pydev.ui.hierarchy.HierarchyNodeModel;

/**
* @author fabioz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
import org.python.pydev.editor.model.ItemPointer;
import org.python.pydev.editor.model.Location;
import org.python.pydev.editor.refactoring.AbstractPyRefactoring;
import org.python.pydev.editor.refactoring.HierarchyNodeModel;
import org.python.pydev.editor.refactoring.IPyRefactoring;
import org.python.pydev.editor.refactoring.IPyRefactoring2;
import org.python.pydev.editor.refactoring.RefactoringRequest;
import org.python.pydev.parser.jython.SimpleNode;
import org.python.pydev.parser.jython.ast.ClassDef;
Expand All @@ -55,8 +57,6 @@
import org.python.pydev.parser.visitors.scope.DefinitionsASTIteratorVisitor;
import org.python.pydev.ui.dialogs.TreeSelectionDialog;

import com.python.pydev.refactoring.IPyRefactoring2;
import com.python.pydev.ui.hierarchy.HierarchyNodeModel;
import com.python.pydev.ui.hierarchy.TreeNode;
import com.python.pydev.ui.hierarchy.TreeNodeContentProvider;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
import org.python.pydev.editor.actions.PyAction;
import org.python.pydev.editor.actions.refactoring.PyRefactorAction;
import org.python.pydev.editor.refactoring.AbstractPyRefactoring;
import org.python.pydev.editor.refactoring.HierarchyNodeModel;
import org.python.pydev.editor.refactoring.IPyRefactoring;
import org.python.pydev.editor.refactoring.IPyRefactoring2;
import org.python.pydev.editor.refactoring.RefactoringRequest;

import com.python.pydev.refactoring.IPyRefactoring2;
import com.python.pydev.ui.hierarchy.HierarchyNodeModel;
import com.python.pydev.ui.hierarchy.PyHierarchyView;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.python.pydev.core.IModule;
import org.python.pydev.editor.actions.PyOpenAction;
import org.python.pydev.editor.model.ItemPointer;
import org.python.pydev.editor.refactoring.HierarchyNodeModel;
import org.python.pydev.parser.jython.SimpleNode;
import org.python.pydev.parser.jython.ast.ClassDef;
import org.python.pydev.parser.jython.ast.FunctionDef;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.eclipse.ui.IActionBars;
import org.python.pydev.core.ExtensionHelper;
import org.python.pydev.core.callbacks.ICallbackWithListeners;
import org.python.pydev.editor.refactoring.HierarchyNodeModel;
import org.python.pydev.ui.IViewCreatedObserver;
import org.python.pydev.ui.IViewWithControls;
import org.python.pydev.ui.ViewPartWithOrientation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.eclipse.jface.viewers.StyledString.Styler;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.graphics.Image;
import org.python.pydev.editor.refactoring.HierarchyNodeModel;


public class TreeNodeContentProvider implements ITreeContentProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
import org.python.pydev.core.MisconfigurationException;
import org.python.pydev.editor.codecompletion.revisited.modules.AbstractModule;
import org.python.pydev.editor.codecompletion.revisited.modules.SourceModule;
import org.python.pydev.editor.refactoring.HierarchyNodeModel;
import org.python.pydev.parser.jython.SimpleNode;
import org.python.pydev.parser.jython.ast.ClassDef;
import org.python.pydev.parser.jython.ast.Module;
import org.python.pydev.ui.SWTTest;

import com.python.pydev.actions.PyOutlineSelectionDialog;
import com.python.pydev.ui.hierarchy.HierarchyNodeModel;

public class PyOutlineSelectionDialogTest extends SWTTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.python.pydev.core.TestDependent;
import org.python.pydev.editor.refactoring.HierarchyNodeModel;
import org.python.pydev.plugin.PydevPlugin;
import org.python.pydev.ui.BundleInfoStub;

Expand Down
20 changes: 10 additions & 10 deletions plugins/org.python.pydev.core/.classpath
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="lib" path="lib/jpathwatch-0-94.jar"/>
<classpathentry exported="true" kind="lib" path="commons-codec.jar"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="tests"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="lib" path="lib/jpathwatch-0-94.jar"/>
<classpathentry exported="true" kind="lib" path="commons-codec.jar"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="tests"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class ExtensionHelper {
public static final String PYDEV_SIMPLE_ASSIST = "org.python.pydev.pydev_simpleassist";
public static final String PYDEV_ORGANIZE_IMPORTS = "org.python.pydev.pydev_organize_imports";
public static final String PYDEV_REFACTORING = "org.python.pydev.pydev_refactoring";
public static final String PYDEV_USER_REFACTORING = "org.python.pydev.pydev_user_refactoring";
public static final String PYDEV_QUICK_OUTLINE = "org.python.pydev.pydev_quick_outline";
public static final String PYDEV_PYEDIT_LISTENER = "org.python.pydev.pydev_pyedit_listener";
public static final String PYDEV_PREFERENCES_PROVIDER = "org.python.pydev.pydev_preferences_provider";
Expand Down Expand Up @@ -81,50 +82,44 @@ public static IExtension[] getExtensions(String type) {
return extensions;
}

@SuppressWarnings("unchecked")
/**
* @param type the name of the extension
* @return the participant for the given extension type, or null if none
* is registered.
*/
public static Object getParticipant(String type) {
//only one participant may be used for this
List<Object> participants = getParticipants(type);
if(participants.size() == 1){
return participants.get(0);
}

if(participants.size() == 0){
if (participants.isEmpty()){
return null;
}

if(participants.size() > 1){
if (participants.size() > 1) {
// only one participant may be used for this
throw new RuntimeException("More than one participant is registered for type:"+type);
}

throw new RuntimeException("Should never get here!");

return participants.get(participants.size() - 1);
}

/**
* @param type the extension we want to get
* @return a list of classes created from those extensions
*/
@SuppressWarnings("unchecked")
public static List getParticipants(String type) {
if(testingParticipants != null){
List<Object> list = testingParticipants.get(type);
if(list == null){
list = new ArrayList();
List<Object> list = null;
if (testingParticipants != null) {
list = testingParticipants.get(type);
if (list == null) {
list = new ArrayList<Object>();
}
return list;
return list;
}

ArrayList list = new ArrayList();
IExtension[] extensions = getExtensions(type);

list = new ArrayList<Object>();
// For each extension ...
for (int i = 0; i < extensions.length; i++) {
IExtension extension = extensions[i];
IConfigurationElement[] elements = extension.getConfigurationElements();
for (IExtension extension : getExtensions(type)) {
IConfigurationElement[] elements = extension
.getConfigurationElements();
// For each member of the extension ...
for (int j = 0; j < elements.length; j++) {
IConfigurationElement element = elements[j];

for (IConfigurationElement element : elements) {
try {
list.add(element.createExecutableExtension("class"));
} catch (Exception e) {
Expand All @@ -134,6 +129,4 @@ public static List getParticipants(String type) {
}
return list;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import org.python.pydev.core.docutils.StringUtils;

public class TestCaseUtils extends TestCase{
public abstract class TestCaseUtils extends TestCase{

public static final boolean DEBUG = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.net.URI;
import java.util.Map;

import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
Expand All @@ -29,6 +30,10 @@ public void build(int kind, String builderName, Map args, IProgressMonitor monit
public void build(int kind, IProgressMonitor monitor) throws CoreException {
throw new RuntimeException("Not implemented");
}

public void build(IBuildConfiguration config, int kind, IProgressMonitor monitor) throws CoreException {
throw new RuntimeException("Not implemented");
}

public void close(IProgressMonitor monitor) throws CoreException {
throw new RuntimeException("Not implemented");
Expand All @@ -49,6 +54,18 @@ public void create(IProjectDescription description, int updateFlags, IProgressMo
public void delete(boolean deleteContent, boolean force, IProgressMonitor monitor) throws CoreException {
throw new RuntimeException("Not implemented");
}

public IBuildConfiguration getActiveBuildConfig() throws CoreException {
throw new RuntimeException("Not implemented");
}

public IBuildConfiguration getBuildConfig(String configName) throws CoreException {
throw new RuntimeException("Not implemented");
}

public IBuildConfiguration[] getBuildConfigs() throws CoreException {
throw new RuntimeException("Not implemented");
}

public IContentTypeMatcher getContentTypeMatcher() throws CoreException {
throw new RuntimeException("Not implemented");
Expand Down Expand Up @@ -85,6 +102,14 @@ public IProject[] getReferencedProjects() throws CoreException {
public IProject[] getReferencingProjects() {
throw new RuntimeException("Not implemented");
}

public IBuildConfiguration[] getReferencedBuildConfigs(String configName, boolean includeMissing) throws CoreException {
throw new RuntimeException("Not implemented");
}

public boolean hasBuildConfig(String configName) throws CoreException {
throw new RuntimeException("Not implemented");
}

public boolean hasNature(String natureId) throws CoreException {
throw new RuntimeException("Not implemented");
Expand Down
1 change: 1 addition & 0 deletions plugins/org.python.pydev/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,7 @@
<extension-point id="pydev_manager_observer" name="PyDev code completion manager observer" schema="schema/pydev_manager_observer.exsd"/>
<extension-point id="pydev_hover" name="PyDev hover" schema="schema/pydev_hover.exsd"/>
<extension-point id="pydev_interpreter_info_builder" name="PyDev interpreter info builder" schema="schema/pydev_interpreter_info_builder.exsd"/>
<extension-point id="pydev_user_refactoring" name="PyDev User Refactoring" schema="schema/pydev_user_refactoring.exsd"/>
<!-- wizards -->
<extension point="org.eclipse.ui.newWizards">
<category
Expand Down
Loading