From 0bf51eaa4e18cbc9ebd197c67890735aa531eefc Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Tue, 22 Mar 2011 18:03:51 +0300 Subject: [PATCH] multiple presentations support --- .../intellij/ide/TypePresentationService.java | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/platform/lang-api/src/com/intellij/ide/TypePresentationService.java b/platform/lang-api/src/com/intellij/ide/TypePresentationService.java index cabf6ab7ad61..4d25772a88f9 100644 --- a/platform/lang-api/src/com/intellij/ide/TypePresentationService.java +++ b/platform/lang-api/src/com/intellij/ide/TypePresentationService.java @@ -6,6 +6,7 @@ import com.intellij.ide.presentation.PresentationTemplateImpl; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.util.NullableLazyValue; import com.intellij.util.containers.ConcurrentFactoryMap; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.FactoryMap; import org.jetbrains.annotations.Nullable; @@ -22,14 +23,22 @@ public class TypePresentationService { @Nullable public Icon getTypeIcon(Class type) { - PresentationTemplate template = mySuperClasses.get(type); - return template == null ? null : template.getIcon(null, 0); + Set templates = mySuperClasses.get(type); + for (PresentationTemplate template : templates) { + Icon icon = template.getIcon(null, 0); + if (icon != null) return icon; + } + return null; } @Nullable public String getTypePresentableName(Class type) { - PresentationTemplate template = mySuperClasses.get(type); - return template == null ? null : template.getTypeName(); + Set templates = mySuperClasses.get(type); + for (PresentationTemplate template : templates) { + String typeName = template.getTypeName(); + if (typeName != null) return typeName; + } + return null; } public static TypePresentationService getService() { @@ -79,30 +88,27 @@ public class TypePresentationService { private final Map> myIcons = new HashMap>(); private final Map> myNames = new HashMap>(); @SuppressWarnings({"MismatchedQueryAndUpdateOfCollection"}) - private final FactoryMap mySuperClasses = new ConcurrentFactoryMap() { + private final FactoryMap> mySuperClasses = new ConcurrentFactoryMap>() { @Override - protected PresentationTemplate create(Class key) { - return walkSupers(key, new LinkedHashSet()); + protected Set create(Class key) { + LinkedHashSet templates = new LinkedHashSet(); + walkSupers(key, new LinkedHashSet(), templates); + return templates; } - @Nullable - private PresentationTemplate walkSupers(Class aClass, Set result) { - if (!result.add(aClass)) { - return null; + private void walkSupers(Class aClass, Set classes, Set templates) { + if (!classes.add(aClass)) { + return; } - PresentationTemplate template = createPresentationTemplate(aClass); - if (template != null) return template; + ContainerUtil.addIfNotNull(createPresentationTemplate(aClass), templates); final Class superClass = aClass.getSuperclass(); if (superClass != null) { - template = walkSupers(superClass, result); - if (template != null) return template; + walkSupers(superClass, classes, templates); } for (Class intf : aClass.getInterfaces()) { - template = walkSupers(intf, result); - if (template != null) return template; + walkSupers(intf, classes, templates); } - return null; } };