ItemPresentationProvider extension point; decouple Java PSI from *PresentationUtil
authorDmitry Jemerov <yole@jetbrains.com>
Fri, 23 Sep 2011 10:30:39 +0000 (12:30 +0200)
committerDmitry Jemerov <yole@jetbrains.com>
Fri, 23 Sep 2011 12:26:56 +0000 (14:26 +0200)
21 files changed:
java/java-impl/src/com/intellij/psi/impl/compiled/ClsClassImpl.java
java/java-impl/src/com/intellij/psi/impl/compiled/ClsFieldImpl.java
java/java-impl/src/com/intellij/psi/impl/compiled/ClsMethodImpl.java
java/java-impl/src/com/intellij/psi/impl/light/LightMethod.java
java/java-impl/src/com/intellij/psi/impl/light/LightMethodBuilder.java
java/java-impl/src/com/intellij/psi/impl/source/PsiClassImpl.java
java/java-impl/src/com/intellij/psi/impl/source/PsiEnumConstantImpl.java
java/java-impl/src/com/intellij/psi/impl/source/PsiFieldImpl.java
java/java-impl/src/com/intellij/psi/impl/source/PsiMethodImpl.java
java/java-impl/src/com/intellij/psi/impl/source/PsiParameterImpl.java
java/java-impl/src/com/intellij/psi/impl/source/tree/java/PsiLocalVariableImpl.java
java/java-impl/src/com/intellij/psi/presentation/java/ClassPresentationProvider.java [new file with mode: 0644]
java/java-impl/src/com/intellij/psi/presentation/java/ClassPresentationUtil.java
java/java-impl/src/com/intellij/psi/presentation/java/FieldPresentationProvider.java [new file with mode: 0644]
java/java-impl/src/com/intellij/psi/presentation/java/JavaPresentationUtil.java
java/java-impl/src/com/intellij/psi/presentation/java/MethodPresentationProvider.java [new file with mode: 0644]
java/java-impl/src/com/intellij/psi/presentation/java/VariablePresentationProvider.java [new file with mode: 0644]
platform/core-api/src/com/intellij/navigation/ItemPresentationProvider.java [new file with mode: 0644]
platform/core-api/src/com/intellij/navigation/ItemPresentationProviders.java [new file with mode: 0644]
platform/platform-resources/src/META-INF/PlatformExtensionPoints.xml
resources/src/META-INF/IdeaPlugin.xml

index df8d97f74188542e34e0243eaed07840e1fe4c54..84e2f2b7a52b47fe3a3ba1f660516a06a6222df5 100644 (file)
@@ -16,6 +16,7 @@
 package com.intellij.psi.impl.compiled;
 
 import com.intellij.navigation.ItemPresentation;
+import com.intellij.navigation.ItemPresentationProviders;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.ui.Queryable;
 import com.intellij.openapi.util.Pair;
@@ -33,7 +34,6 @@ import com.intellij.psi.impl.source.PsiClassImpl;
 import com.intellij.psi.impl.source.SourceTreeToPsiMap;
 import com.intellij.psi.impl.source.tree.TreeElement;
 import com.intellij.psi.javadoc.PsiDocComment;
-import com.intellij.psi.presentation.java.ClassPresentationUtil;
 import com.intellij.psi.scope.PsiScopeProcessor;
 import com.intellij.psi.search.SearchScope;
 import com.intellij.util.IncorrectOperationException;
@@ -524,7 +524,7 @@ public class ClsClassImpl extends ClsRepositoryPsiElement<PsiClassStub<?>> imple
   }
 
   public ItemPresentation getPresentation() {
-    return ClassPresentationUtil.getPresentation(this);
+    return ItemPresentationProviders.getItemPresentation(this);
   }
 
   public Icon getElementIcon(final int flags) {
index 5a773f2d375a8b901b56cd22b20fb4ef13abee7b..77d42e8da6c6bbc0ee73c3932d7a0e9848b6c6d6 100644 (file)
@@ -16,6 +16,7 @@
 package com.intellij.psi.impl.compiled;
 
 import com.intellij.navigation.ItemPresentation;
+import com.intellij.navigation.ItemPresentationProviders;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.util.Comparing;
 import com.intellij.psi.*;
@@ -26,7 +27,6 @@ import com.intellij.psi.impl.java.stubs.PsiFieldStub;
 import com.intellij.psi.impl.source.SourceTreeToPsiMap;
 import com.intellij.psi.impl.source.tree.TreeElement;
 import com.intellij.psi.javadoc.PsiDocComment;
-import com.intellij.psi.presentation.java.JavaPresentationUtil;
 import com.intellij.psi.search.SearchScope;
 import com.intellij.ui.RowIcon;
 import com.intellij.util.IncorrectOperationException;
@@ -233,8 +233,9 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement<PsiFieldStub> implemen
   }
 
   public ItemPresentation getPresentation() {
-    return JavaPresentationUtil.getFieldPresentation(this);
+    return ItemPresentationProviders.getItemPresentation(this);
   }
+
   public void setInitializer(PsiExpression initializer) throws IncorrectOperationException {
     throw new IncorrectOperationException();
   }
index a01928690547b498e2e26b2e918d5c46581bd275..4102a218231228a77888f3442e491f66c0ee975f 100644 (file)
@@ -16,6 +16,7 @@
 package com.intellij.psi.impl.compiled;
 
 import com.intellij.navigation.ItemPresentation;
+import com.intellij.navigation.ItemPresentationProviders;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.psi.*;
@@ -29,7 +30,6 @@ import com.intellij.psi.impl.java.stubs.PsiMethodStub;
 import com.intellij.psi.impl.source.SourceTreeToPsiMap;
 import com.intellij.psi.impl.source.tree.TreeElement;
 import com.intellij.psi.javadoc.PsiDocComment;
-import com.intellij.psi.presentation.java.JavaPresentationUtil;
 import com.intellij.psi.scope.PsiScopeProcessor;
 import com.intellij.psi.scope.util.PsiScopesUtil;
 import com.intellij.psi.search.SearchScope;
@@ -366,7 +366,7 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement<PsiMethodStub> implem
   }
 
   public ItemPresentation getPresentation() {
-    return JavaPresentationUtil.getMethodPresentation(this);
+    return ItemPresentationProviders.getItemPresentation(this);
   }
 
   public Icon getElementIcon(final int flags) {
index 7ab499b357bb053d401c24208553b6bdabaf3872..7d952f0de88426e5a389049e5c8e39fe2073fb9b 100644 (file)
@@ -17,12 +17,12 @@ package com.intellij.psi.impl.light;
 
 import com.intellij.lang.java.JavaLanguage;
 import com.intellij.navigation.ItemPresentation;
+import com.intellij.navigation.ItemPresentationProviders;
 import com.intellij.psi.*;
 import com.intellij.psi.impl.ElementPresentationUtil;
 import com.intellij.psi.impl.PsiClassImplUtil;
 import com.intellij.psi.impl.PsiImplUtil;
 import com.intellij.psi.javadoc.PsiDocComment;
-import com.intellij.psi.presentation.java.JavaPresentationUtil;
 import com.intellij.psi.search.SearchScope;
 import com.intellij.psi.util.MethodSignature;
 import com.intellij.psi.util.MethodSignatureBackedByPsiMethod;
@@ -53,7 +53,7 @@ public class LightMethod extends LightElement implements PsiMethod {
 
   @Override
   public ItemPresentation getPresentation() {
-    return JavaPresentationUtil.getMethodPresentation(this);
+    return ItemPresentationProviders.getItemPresentation(this);
   }
 
   public boolean hasTypeParameters() {
index cc29050597e016f7a71336b48c66a716b568256b..c6bea194feed0ece846ff229b9777f4f4b4941fd 100644 (file)
@@ -18,6 +18,7 @@ package com.intellij.psi.impl.light;
 import com.intellij.lang.Language;
 import com.intellij.lang.StdLanguages;
 import com.intellij.navigation.ItemPresentation;
+import com.intellij.navigation.ItemPresentationProviders;
 import com.intellij.openapi.util.Computable;
 import com.intellij.psi.*;
 import com.intellij.psi.impl.ElementPresentationUtil;
@@ -88,7 +89,7 @@ public class LightMethodBuilder extends LightElement implements PsiMethod {
 
   @Override
   public ItemPresentation getPresentation() {
-    return JavaPresentationUtil.getMethodPresentation(this);
+    return ItemPresentationProviders.getItemPresentation(this);
   }
 
   public boolean hasTypeParameters() {
index 733cc8d5259cbb2b4f5a0c3eb323e7f487845915..d6408990fa13492906b601d7f7c8a279f918b926 100644 (file)
@@ -18,6 +18,7 @@ package com.intellij.psi.impl.source;
 import com.intellij.extapi.psi.StubBasedPsiElementBase;
 import com.intellij.lang.ASTNode;
 import com.intellij.navigation.ItemPresentation;
+import com.intellij.navigation.ItemPresentationProviders;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.ui.Queryable;
 import com.intellij.openapi.util.Pair;
@@ -30,7 +31,6 @@ import com.intellij.psi.impl.source.tree.ChildRole;
 import com.intellij.psi.impl.source.tree.CompositeElement;
 import com.intellij.psi.impl.source.tree.SharedImplUtil;
 import com.intellij.psi.javadoc.PsiDocComment;
-import com.intellij.psi.presentation.java.ClassPresentationUtil;
 import com.intellij.psi.scope.ElementClassHint;
 import com.intellij.psi.scope.NameHint;
 import com.intellij.psi.scope.PsiScopeProcessor;
@@ -576,7 +576,7 @@ public class PsiClassImpl extends JavaStubPsiElement<PsiClassStub<?>> implements
   }
 
   public ItemPresentation getPresentation() {
-    return ClassPresentationUtil.getPresentation(this);
+    return ItemPresentationProviders.getItemPresentation(this);
   }
 
   public Icon getElementIcon(final int flags) {
index 31b01974b3e2386ab09fff0dc34486aac1d19fae..317e4872621fd13910ca3c5d9ed7ef4902c82d41 100644 (file)
@@ -17,6 +17,7 @@ package com.intellij.psi.impl.source;
 
 import com.intellij.lang.ASTNode;
 import com.intellij.navigation.ItemPresentation;
+import com.intellij.navigation.ItemPresentationProviders;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.util.TextRange;
 import com.intellij.psi.*;
@@ -27,7 +28,6 @@ import com.intellij.psi.impl.java.stubs.JavaStubElementTypes;
 import com.intellij.psi.impl.java.stubs.PsiFieldStub;
 import com.intellij.psi.impl.source.tree.ChildRole;
 import com.intellij.psi.javadoc.PsiDocComment;
-import com.intellij.psi.presentation.java.JavaPresentationUtil;
 import com.intellij.psi.scope.PsiScopeProcessor;
 import com.intellij.ui.RowIcon;
 import com.intellij.util.ArrayUtil;
@@ -266,8 +266,9 @@ public class PsiEnumConstantImpl extends JavaStubPsiElement<PsiFieldStub> implem
   }
 
   public ItemPresentation getPresentation() {
-    return JavaPresentationUtil.getFieldPresentation(this);
+    return ItemPresentationProviders.getItemPresentation(this);
   }
+
   public void setInitializer(PsiExpression initializer) throws IncorrectOperationException {
     throw new IncorrectOperationException();
   }
index b930eb9c637d3c5e9b9a7f72491176d9c15cb537..73f272380c104f17cd04751e103ca594a4d2080d 100644 (file)
@@ -17,6 +17,7 @@ package com.intellij.psi.impl.source;
 
 import com.intellij.lang.ASTNode;
 import com.intellij.navigation.ItemPresentation;
+import com.intellij.navigation.ItemPresentationProviders;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.ui.Queryable;
 import com.intellij.psi.*;
@@ -28,7 +29,6 @@ import com.intellij.psi.impl.source.codeStyle.CodeEditUtil;
 import com.intellij.psi.impl.source.resolve.JavaResolveCache;
 import com.intellij.psi.impl.source.tree.*;
 import com.intellij.psi.javadoc.PsiDocComment;
-import com.intellij.psi.presentation.java.JavaPresentationUtil;
 import com.intellij.psi.scope.PsiScopeProcessor;
 import com.intellij.psi.search.SearchScope;
 import com.intellij.psi.stubs.IStubElementType;
@@ -412,7 +412,7 @@ public class PsiFieldImpl extends JavaStubPsiElement<PsiFieldStub> implements Ps
   }
 
   public ItemPresentation getPresentation() {
-    return JavaPresentationUtil.getFieldPresentation(this);
+    return ItemPresentationProviders.getItemPresentation(this);
   }
 
   public void setInitializer(PsiExpression initializer) throws IncorrectOperationException {
index 5ef7807ae3d69b13fb3c8f034ac934c032ea5452..fbf97580c84c444510131117b3955d21419cfa39 100644 (file)
@@ -17,6 +17,7 @@ package com.intellij.psi.impl.source;
 
 import com.intellij.lang.ASTNode;
 import com.intellij.navigation.ItemPresentation;
+import com.intellij.navigation.ItemPresentationProviders;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.ui.Queryable;
@@ -34,7 +35,6 @@ import com.intellij.psi.impl.source.tree.CompositeElement;
 import com.intellij.psi.impl.source.tree.JavaElementType;
 import com.intellij.psi.impl.source.tree.JavaSharedImplUtil;
 import com.intellij.psi.javadoc.PsiDocComment;
-import com.intellij.psi.presentation.java.JavaPresentationUtil;
 import com.intellij.psi.scope.PsiScopeProcessor;
 import com.intellij.psi.search.SearchScope;
 import com.intellij.psi.stubs.IStubElementType;
@@ -320,7 +320,7 @@ public class PsiMethodImpl extends JavaStubPsiElement<PsiMethodStub> implements
   }
 
   public ItemPresentation getPresentation() {
-    return JavaPresentationUtil.getMethodPresentation(this);
+    return ItemPresentationProviders.getItemPresentation(this);
   }
 
   public Icon getElementIcon(final int flags) {
index 243c50633df10aab4c755d5c343ea0e167d08110..b4a11ac732b007e319596ed929341ebef1c55788 100644 (file)
@@ -17,6 +17,7 @@ package com.intellij.psi.impl.source;
 
 import com.intellij.lang.ASTNode;
 import com.intellij.navigation.ItemPresentation;
+import com.intellij.navigation.ItemPresentationProviders;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.psi.*;
 import com.intellij.psi.impl.CheckUtil;
@@ -28,7 +29,6 @@ import com.intellij.psi.impl.java.stubs.PsiParameterStub;
 import com.intellij.psi.impl.source.tree.ChildRole;
 import com.intellij.psi.impl.source.tree.CompositeElement;
 import com.intellij.psi.impl.source.tree.JavaSharedImplUtil;
-import com.intellij.psi.presentation.java.JavaPresentationUtil;
 import com.intellij.psi.search.LocalSearchScope;
 import com.intellij.psi.search.SearchScope;
 import com.intellij.ui.RowIcon;
@@ -224,7 +224,7 @@ public class PsiParameterImpl extends JavaStubPsiElement<PsiParameterStub> imple
   }
 
   public ItemPresentation getPresentation() {
-    return JavaPresentationUtil.getVariablePresentation(this);
+    return ItemPresentationProviders.getItemPresentation(this);
   }
 
   public Icon getElementIcon(final int flags) {
index 1616b187cdb67d21280de8c58228fd6cc8e89ac4..320f0b8cebee5e9cd7c56090a1891461be5c9562 100644 (file)
@@ -17,6 +17,7 @@ package com.intellij.psi.impl.source.tree.java;
 
 import com.intellij.lang.ASTNode;
 import com.intellij.navigation.ItemPresentation;
+import com.intellij.navigation.ItemPresentationProviders;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.psi.*;
 import com.intellij.psi.impl.*;
@@ -283,7 +284,7 @@ public class PsiLocalVariableImpl extends CompositePsiElement implements PsiLoca
   }
 
   public ItemPresentation getPresentation() {
-    return JavaPresentationUtil.getVariablePresentation(this);
+    return ItemPresentationProviders.getItemPresentation(this);
   }
 
   public String toString() {
diff --git a/java/java-impl/src/com/intellij/psi/presentation/java/ClassPresentationProvider.java b/java/java-impl/src/com/intellij/psi/presentation/java/ClassPresentationProvider.java
new file mode 100644 (file)
index 0000000..4912425
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2000-2011 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.psi.presentation.java;
+
+import com.intellij.navigation.ColoredItemPresentation;
+import com.intellij.navigation.ItemPresentation;
+import com.intellij.navigation.ItemPresentationProvider;
+import com.intellij.openapi.editor.colors.CodeInsightColors;
+import com.intellij.openapi.editor.colors.TextAttributesKey;
+import com.intellij.openapi.util.Iconable;
+import com.intellij.psi.PsiClass;
+import com.intellij.psi.PsiClassOwner;
+import com.intellij.psi.PsiFile;
+
+import javax.swing.*;
+
+/**
+ * @author yole
+ */
+public class ClassPresentationProvider implements ItemPresentationProvider<PsiClass> {
+  @Override
+  public ItemPresentation getPresentation(final PsiClass psiClass) {
+    return new ColoredItemPresentation() {
+      public String getPresentableText() {
+        return ClassPresentationUtil.getNameForClass(psiClass, false);
+      }
+
+      public String getLocationString() {
+        PsiFile file = psiClass.getContainingFile();
+        if (file instanceof PsiClassOwner) {
+          PsiClassOwner classOwner = (PsiClassOwner)file;
+          String packageName = classOwner.getPackageName();
+          if (packageName.length() == 0) return null;
+          return "(" + packageName + ")";
+        }
+        return null;
+      }
+
+      @Override
+      public TextAttributesKey getTextAttributesKey() {
+        if (psiClass.isDeprecated()) {
+          return CodeInsightColors.DEPRECATED_ATTRIBUTES;
+        }
+        return null;
+      }
+
+      public Icon getIcon(boolean open) {
+        return psiClass.getIcon(Iconable.ICON_FLAG_VISIBILITY | Iconable.ICON_FLAG_READ_STATUS);
+      }
+    };
+  }
+}
index 72269b5e3e461cce29197443dbecdf57c091e63e..2a13a0e98bb9c1ecd0c400185daae4c918cecaf4 100644 (file)
  */
 package com.intellij.psi.presentation.java;
 
-import com.intellij.navigation.ColoredItemPresentation;
-import com.intellij.openapi.editor.colors.CodeInsightColors;
-import com.intellij.openapi.editor.colors.TextAttributesKey;
-import com.intellij.openapi.util.Iconable;
 import com.intellij.psi.*;
 import com.intellij.psi.util.PsiTreeUtil;
 import org.jetbrains.annotations.NotNull;
 
-import javax.swing.*;
-
 public class ClassPresentationUtil {
   private ClassPresentationUtil() {
   }
@@ -78,36 +72,4 @@ public class ClassPresentationUtil {
       parent = parent.getParent();
     }
   }
-
-  @NotNull
-  public static ColoredItemPresentation getPresentation(@NotNull final PsiClass psiClass) {
-    return new ColoredItemPresentation() {
-      public String getPresentableText() {
-        return getNameForClass(psiClass, false);
-      }
-
-      public String getLocationString() {
-        PsiFile file = psiClass.getContainingFile();
-        if (file instanceof PsiClassOwner) {
-          PsiClassOwner classOwner = (PsiClassOwner)file;
-          String packageName = classOwner.getPackageName();
-          if (packageName.length() == 0) return null;
-          return "(" + packageName + ")";
-        }
-        return null;
-      }
-
-      @Override
-      public TextAttributesKey getTextAttributesKey() {
-        if (psiClass.isDeprecated()) {
-          return CodeInsightColors.DEPRECATED_ATTRIBUTES;
-        }
-        return null;
-      }
-
-      public Icon getIcon(boolean open) {
-        return psiClass.getIcon(Iconable.ICON_FLAG_VISIBILITY | Iconable.ICON_FLAG_READ_STATUS);
-      }
-    };
-  }
 }
diff --git a/java/java-impl/src/com/intellij/psi/presentation/java/FieldPresentationProvider.java b/java/java-impl/src/com/intellij/psi/presentation/java/FieldPresentationProvider.java
new file mode 100644 (file)
index 0000000..3b3d6ed
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2000-2011 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.psi.presentation.java;
+
+import com.intellij.navigation.ItemPresentation;
+import com.intellij.navigation.ItemPresentationProvider;
+import com.intellij.psi.PsiField;
+
+/**
+ * @author yole
+ */
+public class FieldPresentationProvider implements ItemPresentationProvider<PsiField> {
+  @Override
+  public ItemPresentation getPresentation(PsiField item) {
+    return JavaPresentationUtil.getFieldPresentation(item);
+  }
+}
index 9f4b05f9369fe37f91fdda9da54fd21b1c380351..c30f90ce93d3b46eddc1c666abe9fd041b3b9797 100644 (file)
@@ -83,22 +83,6 @@ public class JavaPresentationUtil {
     };
   }
 
-  public static ItemPresentation getVariablePresentation(final PsiVariable variable) {
-    return new ItemPresentation() {
-      public String getPresentableText() {
-        return PsiFormatUtil.formatVariable(variable, PsiFormatUtil.SHOW_TYPE, PsiSubstitutor.EMPTY);
-      }
-
-      public String getLocationString() {
-        return "";
-      }
-
-      public Icon getIcon(boolean open) {
-        return variable.getIcon(Iconable.ICON_FLAG_OPEN);
-      }
-    };
-  }
-
   @Nullable
   private static String getJavaSymbolContainerText(final PsiElement element) {
     final String result;
diff --git a/java/java-impl/src/com/intellij/psi/presentation/java/MethodPresentationProvider.java b/java/java-impl/src/com/intellij/psi/presentation/java/MethodPresentationProvider.java
new file mode 100644 (file)
index 0000000..91ee8d6
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2000-2011 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.psi.presentation.java;
+
+import com.intellij.navigation.ItemPresentation;
+import com.intellij.navigation.ItemPresentationProvider;
+import com.intellij.psi.PsiMethod;
+
+/**
+ * @author yole
+ */
+public class MethodPresentationProvider implements ItemPresentationProvider<PsiMethod> {
+  @Override
+  public ItemPresentation getPresentation(PsiMethod item) {
+    return JavaPresentationUtil.getMethodPresentation(item);
+  }
+}
diff --git a/java/java-impl/src/com/intellij/psi/presentation/java/VariablePresentationProvider.java b/java/java-impl/src/com/intellij/psi/presentation/java/VariablePresentationProvider.java
new file mode 100644 (file)
index 0000000..9c1fd4f
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2000-2011 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.psi.presentation.java;
+
+import com.intellij.navigation.ItemPresentation;
+import com.intellij.navigation.ItemPresentationProvider;
+import com.intellij.navigation.NavigationItem;
+import com.intellij.openapi.util.Iconable;
+import com.intellij.psi.PsiSubstitutor;
+import com.intellij.psi.PsiVariable;
+import com.intellij.psi.util.PsiFormatUtil;
+import com.intellij.psi.util.PsiFormatUtilBase;
+
+import javax.swing.*;
+
+/**
+ * @author yole
+ */
+public class VariablePresentationProvider<T extends PsiVariable & NavigationItem> implements ItemPresentationProvider<T> {
+  @Override
+  public ItemPresentation getPresentation(final T variable) {
+    return new ItemPresentation() {
+      public String getPresentableText() {
+        return PsiFormatUtil.formatVariable(variable, PsiFormatUtilBase.SHOW_TYPE, PsiSubstitutor.EMPTY);
+      }
+
+      public String getLocationString() {
+        return "";
+      }
+
+      public Icon getIcon(boolean open) {
+        return variable.getIcon(Iconable.ICON_FLAG_OPEN);
+      }
+    };
+  }
+}
diff --git a/platform/core-api/src/com/intellij/navigation/ItemPresentationProvider.java b/platform/core-api/src/com/intellij/navigation/ItemPresentationProvider.java
new file mode 100644 (file)
index 0000000..44e4dbd
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2000-2011 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.navigation;
+
+/**
+ * @author yole
+ */
+public interface ItemPresentationProvider<T extends NavigationItem> {
+  ItemPresentation getPresentation(T item);
+}
diff --git a/platform/core-api/src/com/intellij/navigation/ItemPresentationProviders.java b/platform/core-api/src/com/intellij/navigation/ItemPresentationProviders.java
new file mode 100644 (file)
index 0000000..bab05b1
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2000-2011 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.navigation;
+
+import com.intellij.openapi.util.ClassExtension;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * @author yole
+ */
+public class ItemPresentationProviders extends ClassExtension<ItemPresentationProvider> {
+  public static final ItemPresentationProviders INSTANCE = new ItemPresentationProviders();
+
+  private ItemPresentationProviders() {
+    super("com.intellij.itemPresentationProvider");
+  }
+
+  public static <T extends NavigationItem> ItemPresentationProvider<T> getItemPresentationProvider(@NotNull T element) {
+    return INSTANCE.forClass(element.getClass());
+  }
+
+  public static ItemPresentation getItemPresentation(NavigationItem element) {
+    return getItemPresentationProvider(element).getPresentation(element);
+  }
+}
index 49801499e8846f1c95c972919622cddb4703ad3f..1c70e5a5ce71b6b26db0f6be00470e47b47c7be6 100644 (file)
   <extensionPoint name="fileDocumentManagerListener" interface="com.intellij.openapi.fileEditor.FileDocumentManagerListener"/>
   <extensionPoint name="exceptionFilter" interface="com.intellij.execution.filters.ExceptionFilterFactory"/>
   <extensionPoint name="fileDocumentSynchronizationVetoer" interface="com.intellij.openapi.fileEditor.FileDocumentSynchronizationVetoer"/>
+
+  <extensionPoint name="itemPresentationProvider" beanClass="com.intellij.openapi.util.ClassExtensionPoint"/>
 </extensionPoints>
index 37f390470683807eccd265c6a2f9509d8b0c5ab4..44b5c09d05b927aa51be7f33fb36f1629e83de0d 100644 (file)
     <programRunner id="defaultDebugRunner" implementation="com.intellij.debugger.impl.GenericDebuggerRunner" order="last"/>
 
     <generation.topLevelFactory language="JAVA" implementationClass="com.intellij.psi.impl.JavaFactoryProvider"/>
+
+    <itemPresentationProvider forClass="com.intellij.psi.PsiClass"
+                              implementationClass="com.intellij.psi.presentation.java.ClassPresentationProvider"/>
+    <itemPresentationProvider forClass="com.intellij.psi.PsiMethod"
+                              implementationClass="com.intellij.psi.presentation.java.MethodPresentationProvider"/>
+    <itemPresentationProvider forClass="com.intellij.psi.PsiField"
+                              implementationClass="com.intellij.psi.presentation.java.FieldPresentationProvider"/>
+    <itemPresentationProvider forClass="com.intellij.psi.PsiLocalVariable"
+                              implementationClass="com.intellij.psi.presentation.java.VariablePresentationProvider"/>
+    <itemPresentationProvider forClass="com.intellij.psi.PsiParameter"
+                              implementationClass="com.intellij.psi.presentation.java.VariablePresentationProvider"/>
   </extensions>
 
 </idea-plugin>