diff --git a/action-system/impl/com/intellij/openapi/actionSystem/impl/ActionManagerImpl.java b/action-system/impl/com/intellij/openapi/actionSystem/impl/ActionManagerImpl.java index 0bf486b1962a..313ce0eb5e5d 100644 --- a/action-system/impl/com/intellij/openapi/actionSystem/impl/ActionManagerImpl.java +++ b/action-system/impl/com/intellij/openapi/actionSystem/impl/ActionManagerImpl.java @@ -47,19 +47,19 @@ public final class ActionManagerImpl extends ActionManagerEx implements JDOMExte private static final int UPDATE_DELAY_AFTER_TYPING = 500; private final Object myLock = new Object(); - private THashMap myId2Action; - private THashMap> myPlugin2Id; - private TObjectIntHashMap myId2Index; - private THashMap myAction2Id; - private ArrayList myNotRegisteredInternalActionIds; + private final THashMap myId2Action; + private final THashMap> myPlugin2Id; + private final TObjectIntHashMap myId2Index; + private final THashMap myAction2Id; + private final ArrayList myNotRegisteredInternalActionIds; private MyTimer myTimer; private int myRegisteredActionsCount; - private ArrayList myActionListeners; + private final ArrayList myActionListeners; private AnActionListener[] myCachedActionListeners; private String myLastPreformedActionId; - private KeymapManager myKeymapManager; - private DataManager myDataManager; + private final KeymapManager myKeymapManager; + private final DataManager myDataManager; private String myPrevPerformedActionId; private long myLastTimeEditorWasTypedIn = 0; @NonNls private static final String ACTION_ELEMENT_NAME = "action"; @@ -171,11 +171,13 @@ public final class ActionManagerImpl extends ActionManagerEx implements JDOMExte } private AnAction getActionImpl(String id, boolean canReturnStub) { + synchronized (myLock) { AnAction action = (AnAction)myId2Action.get(id); if (!canReturnStub && action instanceof ActionStub) { action = convert((ActionStub)action); } return action; + } } /** @@ -183,7 +185,6 @@ public final class ActionManagerImpl extends ActionManagerEx implements JDOMExte */ @SuppressWarnings({"HardCodedStringLiteral"}) private AnAction convert(ActionStub stub) { - synchronized (myLock) { LOG.assertTrue(myAction2Id.contains(stub)); myAction2Id.remove(stub); @@ -237,7 +238,6 @@ public final class ActionManagerImpl extends ActionManagerEx implements JDOMExte myAction2Id.put(obj, stub.getId()); return (AnAction)obj; - } } public String getId(@NotNull AnAction action) { @@ -513,7 +513,7 @@ public final class ActionManagerImpl extends ActionManagerEx implements JDOMExte assertActionIsGroupOrStub(action); } - String actionName = (action instanceof ActionStub) ? ((ActionStub) action).getClassName() : action.getClass().getName(); + String actionName = action instanceof ActionStub ? ((ActionStub)action).getClassName() : action.getClass().getName(); if (!ADD_TO_GROUP_ELEMENT_NAME.equals(element.getName())) { LOG.error("unexpected name of element \"" + element.getName() + "\""); @@ -695,7 +695,7 @@ public final class ActionManagerImpl extends ActionManagerEx implements JDOMExte return action; } - public void processActionsElement(Element element, ClassLoader loader, PluginId pluginId) { + private void processActionsElement(Element element, ClassLoader loader, PluginId pluginId) { if (LOG.isDebugEnabled()) { LOG.debug("enter: processActionsNode(" + element.getName() + ")"); } diff --git a/codeInsight/impl/com/intellij/codeInsight/lookup/impl/LookupImpl.java b/codeInsight/impl/com/intellij/codeInsight/lookup/impl/LookupImpl.java index 725be34465f6..9348e3ef4abc 100644 --- a/codeInsight/impl/com/intellij/codeInsight/lookup/impl/LookupImpl.java +++ b/codeInsight/impl/com/intellij/codeInsight/lookup/impl/LookupImpl.java @@ -18,7 +18,6 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiDocumentManager; import com.intellij.ui.LightweightHint; import com.intellij.ui.ListScrollingUtil; -import com.intellij.util.containers.HashMap; import org.apache.oro.text.regex.Pattern; import org.apache.oro.text.regex.PatternMatcher; import org.apache.oro.text.regex.Perl5Matcher; @@ -55,7 +54,6 @@ public class LookupImpl extends LightweightHint implements Lookup { private DocumentListener myDocumentListener; private ArrayList myListeners = new ArrayList(); - private HashMap myUserMap = new HashMap(); private boolean myCanceled = true; private boolean myDisposed = false; @@ -502,19 +500,6 @@ public class LookupImpl extends LightweightHint implements Lookup { } } - public T getUserData(Key key){ - return (T)myUserMap.get(key); - } - - public void putUserData(Key key, T value){ - if (value != null){ - myUserMap.put(key, value); - } - else{ - myUserMap.remove(key); - } - } - static boolean isNarrowDownMode(){ return CodeInsightSettings.getInstance().NARROW_DOWN_LOOKUP_LIST; } diff --git a/codeInsight/tests/com/intellij/codeInsight/CodeInsightTestCase.java b/codeInsight/tests/com/intellij/codeInsight/CodeInsightTestCase.java index a2956151c202..3786f9eb6fe8 100644 --- a/codeInsight/tests/com/intellij/codeInsight/CodeInsightTestCase.java +++ b/codeInsight/tests/com/intellij/codeInsight/CodeInsightTestCase.java @@ -143,12 +143,14 @@ public abstract class CodeInsightTestCase extends PsiTestCase { if (projectRoot != null) { FileUtil.copyDir(projectRoot, toDirIO); VirtualFile fromDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(projectRoot); - editorInfos = copyFilesFillingEditorInfos(fromDir, toDir, ContainerUtil.map2Array(vFiles, String.class, new Function() { - public String fun(final VirtualFile s) { - return s.getPath().substring(projectRoot.getPath().length()); - } - })); - } else { + editorInfos = + copyFilesFillingEditorInfos(fromDir, toDir, ContainerUtil.map2Array(vFiles, String.class, new Function() { + public String fun(final VirtualFile s) { + return s.getPath().substring(projectRoot.getPath().length()); + } + })); + } + else { editorInfos = new LinkedHashMap(); for (final VirtualFile vFile : vFiles) { editorInfos.putAll(copyFilesFillingEditorInfos(vFile.getParent(), toDir, vFile.getName())); diff --git a/source/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java b/source/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java index a09af9517d32..da90ed978f99 100644 --- a/source/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java +++ b/source/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java @@ -50,7 +50,7 @@ public final class LocalFileSystemImpl extends LocalFileSystem implements Applic private static final Key DELETED_STATUS = Key.create("DELETED_STATUS"); private List myHandlers = new ArrayList(); - public Map myUnaccountedFiles = SystemInfo.isFileSystemCaseSensitive + public final Map myUnaccountedFiles = SystemInfo.isFileSystemCaseSensitive ? new THashMap() : new THashMap( new CaseInsensitiveStringHashingStrategy() diff --git a/source/com/intellij/psi/impl/source/javadoc/PsiDocMethodOrFieldRef.java b/source/com/intellij/psi/impl/source/javadoc/PsiDocMethodOrFieldRef.java index 025f246e2ffb..dcec5d0b2a5d 100644 --- a/source/com/intellij/psi/impl/source/javadoc/PsiDocMethodOrFieldRef.java +++ b/source/com/intellij/psi/impl/source/javadoc/PsiDocMethodOrFieldRef.java @@ -16,6 +16,7 @@ import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.TypeConversionUtil; import com.intellij.util.CharTable; import com.intellij.util.IncorrectOperationException; +import com.intellij.util.SmartList; import org.jetbrains.annotations.NonNls; import java.util.ArrayList; @@ -91,13 +92,13 @@ public class PsiDocMethodOrFieldRef extends CompositePsiElement implements PsiDo } public static PsiVariable[] getAllVariables(PsiElement scope, PsiElement place) { - final List result = new ArrayList(); + final List result = new SmartList(); PsiScopesUtil.processScope(scope, new FilterScopeProcessor(new ClassFilter(PsiVariable.class), result), PsiSubstitutor.UNKNOWN, null, place); return result.toArray(new PsiVariable[result.size()]); } public static PsiMethod[] getAllMethods(PsiElement scope, PsiElement place) { - final List result = new ArrayList(); + final List result = new SmartList(); PsiScopesUtil.processScope(scope, new FilterScopeProcessor(new ClassFilter(PsiMethod.class), result), PsiSubstitutor.UNKNOWN, null, place); return result.toArray(new PsiMethod[result.size()]); } diff --git a/source/com/intellij/psi/impl/source/tree/injected/InjectedLanguageUtil.java b/source/com/intellij/psi/impl/source/tree/injected/InjectedLanguageUtil.java index 17c0a4e9ed3c..2c7fd8235665 100644 --- a/source/com/intellij/psi/impl/source/tree/injected/InjectedLanguageUtil.java +++ b/source/com/intellij/psi/impl/source/tree/injected/InjectedLanguageUtil.java @@ -266,17 +266,17 @@ public class InjectedLanguageUtil { @Nullable public static PsiLanguageInjectionHost findInjectionHost(PsiElement element) { - if (element == null) return null; + if (element == null || element instanceof PsiFile) return null; if (element instanceof PsiLanguageInjectionHost) { return (PsiLanguageInjectionHost)element; } element = element.getParent(); - if (element == null) return null; + if (element == null || element instanceof PsiFile) return null; if (element instanceof PsiLanguageInjectionHost) { return (PsiLanguageInjectionHost)element; } element = element.getParent(); - if (element == null) return null; + if (element == null || element instanceof PsiFile) return null; if (element instanceof PsiLanguageInjectionHost) { return (PsiLanguageInjectionHost)element; } diff --git a/ui/impl/com/intellij/ui/LightweightHint.java b/ui/impl/com/intellij/ui/LightweightHint.java index 6248b6958d33..63c1b935a4d9 100644 --- a/ui/impl/com/intellij/ui/LightweightHint.java +++ b/ui/impl/com/intellij/ui/LightweightHint.java @@ -3,12 +3,10 @@ package com.intellij.ui; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.ui.popup.JBPopupFactory; -import com.intellij.openapi.util.Key; -import com.intellij.openapi.util.UserDataHolder; +import com.intellij.openapi.util.UserDataHolderBase; import com.intellij.openapi.wm.ex.LayoutFocusTraversalPolicyExt; import com.intellij.ui.awt.RelativePoint; import com.intellij.ui.popup.JBPopupImpl; -import gnu.trove.THashMap; import javax.swing.*; import javax.swing.event.EventListenerList; @@ -18,14 +16,12 @@ import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.util.EventListener; import java.util.EventObject; -import java.util.Map; -public class LightweightHint implements Hint, UserDataHolder { +public class LightweightHint extends UserDataHolderBase implements Hint { private static final Logger LOG = Logger.getInstance("#com.intellij.ui.LightweightHint"); private final JComponent myComponent; private JComponent myFocusBackComponent; - private final Map myUserMap = new THashMap(1); private final EventListenerList myListenerList = new EventListenerList(); private MyEscListener myEscListener; private JBPopup myPopup; @@ -192,20 +188,6 @@ public class LightweightHint implements Hint, UserDataHolder { return myComponent; } - @SuppressWarnings({"unchecked"}) - public T getUserData(final Key key) { - return (T)myUserMap.get(key); - } - - public void putUserData(final Key key, final T value) { - if (value != null) { - myUserMap.put(key, value); - } - else { - myUserMap.remove(key); - } - } - public final void addHintListener(final HintListener listener) { myListenerList.add(HintListener.class, listener); } @@ -220,7 +202,7 @@ public class LightweightHint implements Hint, UserDataHolder { private final class MyEscListener implements ActionListener { public final void actionPerformed(final ActionEvent e) { - LightweightHint.this.hide(); + hide(); } } } diff --git a/util/src/com/intellij/util/SmartList.java b/util/src/com/intellij/util/SmartList.java index 36546a4ad9b7..88a11f404a2d 100644 --- a/util/src/com/intellij/util/SmartList.java +++ b/util/src/com/intellij/util/SmartList.java @@ -102,7 +102,48 @@ public class SmartList extends AbstractList { else { oldValue = ((List)myElem).set(index, element); } + return oldValue; + } + public E remove(final int index) { + if (index < 0 || index >= mySize) { + throw new IndexOutOfBoundsException("index= " + index + ". Must be index > 0 && index < " + mySize); + } + ArrayList old = new ArrayList(this); + + final E oldValue; + if (mySize == 1) { + oldValue = (E)myElem; + myElem = null; + } + else if (mySize == 2) { + final Object[] array = (Object[])myElem; + oldValue = (E)array[index]; + myElem = array[1 - index]; + } + else if (mySize == 3) { + List list = (List)myElem; + oldValue = list.get(index); + Object[] array = new Object[2]; + int i0 = index==0 ? 1 : index==1 ? 0 : 0; + int i1 = index==0 ? 2 : index==1 ? 2 : 1; + array[0] = list.get(i0); + array[1] = list.get(i1); + myElem = array; + } + else { + List list = (List)myElem; + oldValue = list.remove(index); + } + mySize--; + { + List list = new ArrayList(subList(0, index)); + list.add(oldValue); + list.addAll(subList(index, mySize)); + if (!list.equals(old)) { + int i = 0; + } + } return oldValue; } }