2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.jetbrains.plugins.groovy.lang.psi.impl.synthetic;
19 import com.intellij.openapi.editor.colors.TextAttributesKey;
20 import com.intellij.openapi.project.Project;
21 import com.intellij.openapi.wm.ToolWindowManager;
22 import com.intellij.psi.*;
23 import com.intellij.psi.javadoc.PsiDocComment;
24 import com.intellij.psi.search.GlobalSearchScope;
25 import com.intellij.psi.search.ProjectScope;
26 import com.intellij.psi.search.SearchScope;
27 import com.intellij.util.ui.tree.TreeUtil;
28 import com.intellij.ui.treeStructure.treetable.ListTreeTableModelOnColumns;
29 import com.intellij.ui.treeStructure.treetable.TreeTable;
30 import org.jetbrains.annotations.NonNls;
31 import org.jetbrains.annotations.NotNull;
32 import org.jetbrains.annotations.Nullable;
33 import org.jetbrains.plugins.groovy.GroovyIcons;
34 import org.jetbrains.plugins.groovy.annotator.intentions.dynamic.DynamicManager;
35 import org.jetbrains.plugins.groovy.annotator.intentions.dynamic.DynamicToolWindowWrapper;
36 import org.jetbrains.plugins.groovy.annotator.intentions.dynamic.elements.DClassElement;
37 import org.jetbrains.plugins.groovy.annotator.intentions.dynamic.elements.DPropertyElement;
38 import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
41 import javax.swing.tree.DefaultMutableTreeNode;
42 import javax.swing.tree.TreePath;
47 public class GrDynamicImplicitProperty extends GrImplicitVariableImpl implements GrDynamicImplicitElement, PsiField {
48 private final String myContainingClassName;
49 private final Project myProject;
51 public GrDynamicImplicitProperty(PsiManager manager, @NonNls String name, @NonNls String type, String containingClassName, LightModifierList modifierList) {
52 super(modifierList, manager, name, type, null);
53 myContainingClassName = containingClassName;
54 myProject = manager.getProject();
58 public PsiClass getContainingClassElement() {
59 final PsiClassType containingClassType = JavaPsiFacade.getInstance(getProject()).getElementFactory().
60 createTypeByFQClassName(myContainingClassName, ProjectScope.getAllScope(getProject()));
62 return containingClassType.resolve();
65 public String getContainingClassName() {
66 return myContainingClassName;
70 public PsiFile getContainingFile() {
71 final PsiClass psiClass = getContainingClassElement();
72 if (psiClass == null) return null;
74 return psiClass.getContainingFile();
77 public String getPresentableText() {
82 public String getLocationString() {
87 public TextAttributesKey getTextAttributesKey() {
92 public SearchScope getUseScope() {
93 return GlobalSearchScope.projectScope(myProject);
96 public void navigate(boolean requestFocus) {
97 DynamicToolWindowWrapper.getInstance(myProject).getToolWindow().activate(new Runnable() {
99 DynamicToolWindowWrapper toolWindowWrapper = DynamicToolWindowWrapper.getInstance(myProject);
100 final TreeTable treeTable = toolWindowWrapper.getTreeTable();
101 final ListTreeTableModelOnColumns model = toolWindowWrapper.getTreeTableModel();
103 Object root = model.getRoot();
105 if (root == null || !(root instanceof DefaultMutableTreeNode)) return;
107 DefaultMutableTreeNode treeRoot = ((DefaultMutableTreeNode) root);
108 final PsiClass psiClass = getContainingClassElement();
109 if (psiClass == null) return;
111 final DefaultMutableTreeNode desiredNode;
112 DPropertyElement dynamicProperty = null;
113 PsiClass trueSuper = null;
114 for (PsiClass aSuper : PsiUtil.iterateSupers(psiClass, true)) {
115 dynamicProperty = DynamicManager.getInstance(myProject).findConcreteDynamicProperty(aSuper.getQualifiedName(), getName());
117 if (dynamicProperty != null) {
123 if (trueSuper == null) return;
125 final DefaultMutableTreeNode classNode = TreeUtil.findNodeWithObject(treeRoot, new DClassElement(myProject, trueSuper.getQualifiedName()));
126 if (classNode == null) return;
128 desiredNode = TreeUtil.findNodeWithObject(classNode, dynamicProperty);
130 if (desiredNode == null) return;
131 final TreePath path = TreeUtil.getPathFromRoot(desiredNode);
133 treeTable.getTree().expandPath(path);
134 treeTable.getTree().setSelectionPath(path);
135 treeTable.getTree().fireTreeExpanded(path);
137 ToolWindowManager.getInstance(myProject).getFocusManager().requestFocus(treeTable, true);
138 treeTable.revalidate();
145 public boolean canNavigateToSource() {
149 public boolean canNavigate() {
153 public boolean isWritable() {
158 public Icon getIcon(boolean open) {
159 return GroovyIcons.PROPERTY;
162 public boolean isValid() {
166 public PsiClass getContainingClass() {
167 return getContainingClassElement();
170 public PsiDocComment getDocComment() {
174 public boolean isDeprecated() {