summaryrefslogtreecommitdiff
path: root/java/java-psi-impl/src/com/intellij/codeInsight
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2013-08-15 14:06:37 -0700
committerTor Norbye <tnorbye@google.com>2013-08-15 14:06:37 -0700
commita3c36999a717e0d9923378ca5e0ae1160118c1e6 (patch)
treeeda7fde5565d08649c0f5952e957a5ff4b2070d5 /java/java-psi-impl/src/com/intellij/codeInsight
parentd1129abbe4dc0ce9bbad9118a35a85dbebc8758f (diff)
downloadidea-a3c36999a717e0d9923378ca5e0ae1160118c1e6.tar.gz
Snapshot 13baaa319cd568c4e19b9232b24f2002f2631688 from master branch of git://git.jetbrains.org/idea/community.git
Change-Id: I2ede7fef748e781ed425346a4e03e721bf4d2610
Diffstat (limited to 'java/java-psi-impl/src/com/intellij/codeInsight')
-rw-r--r--java/java-psi-impl/src/com/intellij/codeInsight/JavaContainerProvider.java39
-rw-r--r--java/java-psi-impl/src/com/intellij/codeInsight/highlighting/JavaHighlightUsagesDescriptionProvider.java69
2 files changed, 108 insertions, 0 deletions
diff --git a/java/java-psi-impl/src/com/intellij/codeInsight/JavaContainerProvider.java b/java/java-psi-impl/src/com/intellij/codeInsight/JavaContainerProvider.java
new file mode 100644
index 000000000000..64a715e3a616
--- /dev/null
+++ b/java/java-psi-impl/src/com/intellij/codeInsight/JavaContainerProvider.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2000-2012 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.codeInsight;
+
+import com.intellij.psi.PsiClass;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiMember;
+import com.intellij.psi.PsiTypeParameter;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * @author Max Medvedev
+ */
+public class JavaContainerProvider implements ContainerProvider {
+ @Override
+ public PsiElement getContainer(@NotNull PsiElement item) {
+ if (item instanceof PsiTypeParameter) return item.getParent().getParent();
+ if (item instanceof PsiClass) {
+ final PsiClass containingClass = ((PsiClass)item).getContainingClass();
+ return containingClass != null ? containingClass : item.getContainingFile();
+ }
+ if (item instanceof PsiMember) return ((PsiMember)item).getContainingClass();
+
+ return null;
+ }
+}
diff --git a/java/java-psi-impl/src/com/intellij/codeInsight/highlighting/JavaHighlightUsagesDescriptionProvider.java b/java/java-psi-impl/src/com/intellij/codeInsight/highlighting/JavaHighlightUsagesDescriptionProvider.java
new file mode 100644
index 000000000000..b09181c1a5da
--- /dev/null
+++ b/java/java-psi-impl/src/com/intellij/codeInsight/highlighting/JavaHighlightUsagesDescriptionProvider.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2000-2009 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.codeInsight.highlighting;
+
+import com.intellij.psi.*;
+import com.intellij.psi.util.PsiFormatUtil;
+import com.intellij.lang.LangBundle;
+import com.intellij.psi.util.PsiFormatUtilBase;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * @author yole
+ */
+public class JavaHighlightUsagesDescriptionProvider implements ElementDescriptionProvider {
+ @Override
+ public String getElementDescription(@NotNull final PsiElement element, @NotNull final ElementDescriptionLocation location) {
+ if (!(location instanceof HighlightUsagesDescriptionLocation)) return null;
+
+ String elementName = null;
+ if (element instanceof PsiClass) {
+ elementName = ((PsiClass)element).getQualifiedName();
+ if (elementName == null) {
+ elementName = ((PsiClass)element).getName();
+ }
+ elementName = (((PsiClass)element).isInterface() ?
+ LangBundle.message("java.terms.interface") :
+ LangBundle.message("java.terms.class")) + " " + elementName;
+ }
+ else if (element instanceof PsiMethod) {
+ elementName = PsiFormatUtil.formatMethod((PsiMethod)element,
+ PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS |
+ PsiFormatUtilBase.SHOW_CONTAINING_CLASS,
+ PsiFormatUtilBase.SHOW_TYPE);
+ elementName = LangBundle.message("java.terms.method") + " " + elementName;
+ }
+ else if (element instanceof PsiVariable) {
+ elementName = PsiFormatUtil.formatVariable((PsiVariable)element,
+ PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_CONTAINING_CLASS,
+ PsiSubstitutor.EMPTY);
+ if (element instanceof PsiField) {
+ elementName = LangBundle.message("java.terms.field") + " " + elementName;
+ }
+ else if (element instanceof PsiParameter) {
+ elementName = LangBundle.message("java.terms.parameter") + " " + elementName;
+ }
+ else {
+ elementName = LangBundle.message("java.terms.variable") + " " + elementName;
+ }
+ }
+ else if (element instanceof PsiPackage) {
+ elementName = ((PsiPackage)element).getQualifiedName();
+ elementName = LangBundle.message("java.terms.package") + " " + elementName;
+ }
+ return elementName;
+ }
+}