Search in sources :

Example 1 with DMethodElement

use of org.jetbrains.plugins.groovy.annotator.intentions.dynamic.elements.DMethodElement in project intellij-community by JetBrains.

the class GrDynamicImplicitMethod method navigate.

@Override
public void navigate(boolean requestFocus) {
    DynamicToolWindowWrapper.getInstance(getProject()).getToolWindow().activate(() -> {
        DynamicToolWindowWrapper toolWindowWrapper = DynamicToolWindowWrapper.getInstance(getProject());
        final TreeTable treeTable = toolWindowWrapper.getTreeTable();
        final ListTreeTableModelOnColumns model = toolWindowWrapper.getTreeTableModel();
        Object root = model.getRoot();
        if (root == null || !(root instanceof DefaultMutableTreeNode))
            return;
        DefaultMutableTreeNode treeRoot = ((DefaultMutableTreeNode) root);
        DefaultMutableTreeNode desiredNode;
        JavaPsiFacade facade = JavaPsiFacade.getInstance(getProject());
        final PsiClassType fqClassName = facade.getElementFactory().createTypeByFQClassName(myContainingClassName, ProjectScope.getAllScope(getProject()));
        final PsiClass psiClass = fqClassName.resolve();
        if (psiClass == null)
            return;
        PsiClass trueClass = null;
        DMethodElement methodElement = null;
        final GrParameter[] parameters = getParameters();
        List<String> parameterTypes = new ArrayList<>();
        for (GrParameter parameter : parameters) {
            final String type = parameter.getType().getCanonicalText();
            parameterTypes.add(type);
        }
        for (PsiClass aSuper : PsiUtil.iterateSupers(psiClass, true)) {
            methodElement = DynamicManager.getInstance(getProject()).findConcreteDynamicMethod(aSuper.getQualifiedName(), getName(), ArrayUtil.toStringArray(parameterTypes));
            if (methodElement != null) {
                trueClass = aSuper;
                break;
            }
        }
        if (trueClass == null)
            return;
        final DefaultMutableTreeNode classNode = TreeUtil.findNodeWithObject(treeRoot, new DClassElement(getProject(), trueClass.getQualifiedName()));
        if (classNode == null)
            return;
        desiredNode = TreeUtil.findNodeWithObject(classNode, methodElement);
        if (desiredNode == null)
            return;
        final TreePath path = TreeUtil.getPathFromRoot(desiredNode);
        treeTable.getTree().expandPath(path);
        treeTable.getTree().setSelectionPath(path);
        treeTable.getTree().fireTreeExpanded(path);
        //        ToolWindowManager.getInstance(myProject).getFocusManager().requestFocus(treeTable, true);
        treeTable.revalidate();
        treeTable.repaint();
    }, true);
}
Also used : ListTreeTableModelOnColumns(com.intellij.ui.treeStructure.treetable.ListTreeTableModelOnColumns) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeTable(com.intellij.ui.treeStructure.treetable.TreeTable) ArrayList(java.util.ArrayList) DMethodElement(org.jetbrains.plugins.groovy.annotator.intentions.dynamic.elements.DMethodElement) GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter) DClassElement(org.jetbrains.plugins.groovy.annotator.intentions.dynamic.elements.DClassElement) TreePath(javax.swing.tree.TreePath)

Aggregations

ListTreeTableModelOnColumns (com.intellij.ui.treeStructure.treetable.ListTreeTableModelOnColumns)1 TreeTable (com.intellij.ui.treeStructure.treetable.TreeTable)1 ArrayList (java.util.ArrayList)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 TreePath (javax.swing.tree.TreePath)1 DClassElement (org.jetbrains.plugins.groovy.annotator.intentions.dynamic.elements.DClassElement)1 DMethodElement (org.jetbrains.plugins.groovy.annotator.intentions.dynamic.elements.DMethodElement)1 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)1