use of org.python.pydev.ast.refactoring.HierarchyNodeModel in project Pydev by fabioz.
the class ClassHierarchySearchTest method testFindHierarchy3.
public void testFindHierarchy3() {
String str = "" + "import pickle \n" + "class Bar:\n" + " pass \n" + "class Foo(Bar, pickle.Pickler):\n" + " pass \n" + "\n" + "";
final int line = 3;
final int col = 9;
RefactoringRequest request = setUpFooModule(line, col, str);
HierarchyNodeModel node = refactorer.findClassHierarchy(request, false);
assertEquals("Foo", node.name);
assertTrue(node.moduleName.startsWith("foo"));
assertIsIn("Bar", node.moduleName, node.parents);
assertIsIn("Pickler", "pickle", node.parents);
}
use of org.python.pydev.ast.refactoring.HierarchyNodeModel in project Pydev by fabioz.
the class ClassHierarchySearchTest method testFindHierarchy6.
public void testFindHierarchy6() {
String str = "" + "class Root(object):\n" + " pass\n" + "class Mid1(Root):\n" + " pass\n" + "class Mid2(Root):\n" + " pass\n" + "class Leaf(Mid1, Mid2):\n" + " pass\n" + "import pickle\n" + "class Bla(Leaf, Foo):\n" + " pass\n" + "class Foo:\n" + " pass\n" + "";
final int line = 9;
final int col = 8;
RefactoringRequest request = setUpFooModule(line, col, str);
HierarchyNodeModel node = refactorer.findClassHierarchy(request, false);
assertEquals("Bla", node.name);
assertTrue(node.moduleName.startsWith("foo"));
HierarchyNodeModel foo = assertIsIn("Foo", node.moduleName, node.parents);
assertEquals(0, foo.parents.size());
}
use of org.python.pydev.ast.refactoring.HierarchyNodeModel in project Pydev by fabioz.
the class RefactorerFinds method findClassHierarchy.
/**
* @return the hierarchy model, having the returned node as our 'point of interest'.
*/
public HierarchyNodeModel findClassHierarchy(RefactoringRequest request, boolean findOnlyParents) {
try {
request.getMonitor().beginTask("Find class hierarchy", 100);
ItemPointer[] pointers;
try {
request.pushMonitor(new SubProgressMonitor(request.getMonitor(), 5));
request.setAdditionalInfo(RefactoringRequest.FIND_DEFINITION_IN_ADDITIONAL_INFO, false);
pointers = this.refactorer.findDefinition(request);
} finally {
request.popMonitor().done();
}
if (pointers.length == 1) {
// ok, this is the default one.
Definition d = pointers[0].definition;
HierarchyNodeModel model;
try {
request.pushMonitor(new SubProgressMonitor(request.getMonitor(), 5));
model = createHierarhyNodeFromClassDef(d);
} finally {
request.popMonitor().done();
}
if (model == null) {
return null;
}
HashMap<HierarchyNodeModel, HierarchyNodeModel> allFound = new HashMap<HierarchyNodeModel, HierarchyNodeModel>();
allFound.put(model, model);
try {
request.pushMonitor(new SubProgressMonitor(request.getMonitor(), 10));
findParents(request.nature, d, model, allFound, request);
} finally {
request.popMonitor().done();
}
if (!findOnlyParents) {
try {
request.pushMonitor(new SubProgressMonitor(request.getMonitor(), 80));
findChildren(request, model, allFound);
} finally {
request.popMonitor().done();
}
}
return model;
}
} catch (OperationCanceledException e) {
// ignore
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
request.getMonitor().done();
}
return null;
}
use of org.python.pydev.ast.refactoring.HierarchyNodeModel in project Pydev by fabioz.
the class RefactorerFinds method findChildren.
private void findChildren(RefactoringRequest request, HierarchyNodeModel initialModel, HashMap<HierarchyNodeModel, HierarchyNodeModel> allFound) {
try {
request.getMonitor().beginTask("Find children", 100);
// and now the children...
List<AbstractAdditionalDependencyInfo> infoForProject;
try {
infoForProject = AdditionalProjectInterpreterInfo.getAdditionalInfoForProjectAndReferencing(request.nature);
} catch (MisconfigurationException e) {
Log.log(e);
return;
}
HashSet<HierarchyNodeModel> foundOnRound = new HashSet<HierarchyNodeModel>();
foundOnRound.add(initialModel);
int totalWork = 1000;
while (foundOnRound.size() > 0) {
HashSet<HierarchyNodeModel> nextRound = new HashSet<HierarchyNodeModel>(foundOnRound);
foundOnRound.clear();
for (HierarchyNodeModel toFindOnRound : nextRound) {
HashSet<SourceModule> modulesToAnalyze;
int work = totalWork / 250;
if (work <= 0) {
work = 1;
totalWork = 0;
}
totalWork -= work;
try {
request.pushMonitor(new SubProgressMonitor(request.getMonitor(), work));
modulesToAnalyze = findLikelyModulesWithChildren(request, toFindOnRound, infoForProject);
} finally {
request.popMonitor().done();
}
request.communicateWork("Likely modules with matches:" + modulesToAnalyze.size());
findChildrenOnModules(request, allFound, foundOnRound, toFindOnRound, modulesToAnalyze);
}
}
} finally {
request.getMonitor().done();
}
}
use of org.python.pydev.ast.refactoring.HierarchyNodeModel in project Pydev by fabioz.
the class HierarchyViewerTest method open.
public static Shell open(Display display) {
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
HierarchyViewer viewer = new HierarchyViewer();
viewer.createPartControl(shell);
HierarchyNodeModel curr = new HierarchyNodeModel("curr");
final HierarchyNodeModel par1pac1 = new HierarchyNodeModel("par1", "package1", null);
final HierarchyNodeModel par1 = new HierarchyNodeModel("par1", "pack2", null);
final HierarchyNodeModel super1 = new HierarchyNodeModel("super1", "pack3", null);
final HierarchyNodeModel super2 = new HierarchyNodeModel("super2", "pack3", null);
final HierarchyNodeModel par2 = new HierarchyNodeModel("par2", "pack3", null);
final HierarchyNodeModel par3 = new HierarchyNodeModel("par3", "pack3", null);
super1.parents.add(super2);
super2.parents.add(par1pac1);
par1.parents.add(super1);
par1.parents.add(super2);
par2.parents.add(super1);
par3.parents.add(super2);
curr.parents.add(par1);
curr.parents.add(par2);
curr.parents.add(par3);
curr.parents.add(new HierarchyNodeModel("par4"));
final HierarchyNodeModel c1 = new HierarchyNodeModel("child1", "pack3", null);
curr.children.add(c1);
curr.children.add(new HierarchyNodeModel("child2", "pack3", null));
final HierarchyNodeModel c3 = new HierarchyNodeModel("child3", "pack3", null);
// does not show (we go straight to the top or to the bottom)
c3.parents.add(par3);
curr.children.add(c3);
c1.children.add(new HierarchyNodeModel("sub1", "pack3", null));
viewer.setHierarchy(curr);
shell.open();
return shell;
}
Aggregations