Search in sources :

Example 1 with HierarchyNodeModel

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);
}
Also used : RefactoringRequest(org.python.pydev.ast.refactoring.RefactoringRequest) HierarchyNodeModel(org.python.pydev.ast.refactoring.HierarchyNodeModel)

Example 2 with HierarchyNodeModel

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());
}
Also used : RefactoringRequest(org.python.pydev.ast.refactoring.RefactoringRequest) HierarchyNodeModel(org.python.pydev.ast.refactoring.HierarchyNodeModel)

Example 3 with HierarchyNodeModel

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;
}
Also used : HashMap(java.util.HashMap) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) AssignDefinition(org.python.pydev.ast.codecompletion.revisited.visitors.AssignDefinition) IDefinition(org.python.pydev.core.IDefinition) Definition(org.python.pydev.ast.codecompletion.revisited.visitors.Definition) PyRefactoringFindDefinition(org.python.pydev.ast.refactoring.PyRefactoringFindDefinition) HierarchyNodeModel(org.python.pydev.ast.refactoring.HierarchyNodeModel) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) MisconfigurationException(org.python.pydev.core.MisconfigurationException) ItemPointer(org.python.pydev.ast.item_pointer.ItemPointer)

Example 4 with HierarchyNodeModel

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();
    }
}
Also used : SourceModule(org.python.pydev.ast.codecompletion.revisited.modules.SourceModule) MisconfigurationException(org.python.pydev.core.MisconfigurationException) AbstractAdditionalDependencyInfo(com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo) HierarchyNodeModel(org.python.pydev.ast.refactoring.HierarchyNodeModel) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) HashSet(java.util.HashSet)

Example 5 with HierarchyNodeModel

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;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) FillLayout(org.eclipse.swt.layout.FillLayout) HierarchyNodeModel(org.python.pydev.ast.refactoring.HierarchyNodeModel)

Aggregations

HierarchyNodeModel (org.python.pydev.ast.refactoring.HierarchyNodeModel)23 RefactoringRequest (org.python.pydev.ast.refactoring.RefactoringRequest)10 DataAndImageTreeNode (org.python.pydev.shared_core.structure.DataAndImageTreeNode)7 SourceModule (org.python.pydev.ast.codecompletion.revisited.modules.SourceModule)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)2 StyledString (org.eclipse.jface.viewers.StyledString)2 Shell (org.eclipse.swt.widgets.Shell)2 AssignDefinition (org.python.pydev.ast.codecompletion.revisited.visitors.AssignDefinition)2 Definition (org.python.pydev.ast.codecompletion.revisited.visitors.Definition)2 PyRefactoringFindDefinition (org.python.pydev.ast.refactoring.PyRefactoringFindDefinition)2 IDefinition (org.python.pydev.core.IDefinition)2 MisconfigurationException (org.python.pydev.core.MisconfigurationException)2 ASTEntry (org.python.pydev.parser.visitors.scope.ASTEntry)2 PyOutlineSelectionDialog (com.python.pydev.actions.PyOutlineSelectionDialog)1 AbstractAdditionalDependencyInfo (com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo)1 RefactorerFindReferences (com.python.pydev.analysis.refactoring.refactorer.RefactorerFindReferences)1 PyHierarchyView (com.python.pydev.ui.hierarchy.PyHierarchyView)1