From 6761eca257d84daeb6e376f3bea90ab111efa3ba Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 4 Oct 2013 15:41:01 +0400 Subject: [PATCH] cleanup --- .../openapi/application/impl/ModalityStateEx.java | 8 +++++--- .../intellij/openapi/util/text/StringUtil.java | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/platform/core-impl/src/com/intellij/openapi/application/impl/ModalityStateEx.java b/platform/core-impl/src/com/intellij/openapi/application/impl/ModalityStateEx.java index 682475183590..e9aa375ba254 100644 --- a/platform/core-impl/src/com/intellij/openapi/application/impl/ModalityStateEx.java +++ b/platform/core-impl/src/com/intellij/openapi/application/impl/ModalityStateEx.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -20,8 +20,10 @@ import com.intellij.openapi.progress.ProgressIndicator; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import java.lang.ref.Reference; import java.lang.ref.WeakReference; import java.util.ArrayList; +import java.util.List; public class ModalityStateEx extends ModalityState { private static final WeakReference[] EMPTY_REFS_ARRAY = new WeakReference[0]; @@ -52,8 +54,8 @@ public class ModalityStateEx extends ModalityState { @NotNull ModalityStateEx appendEntity(@NotNull Object anEntity){ - ArrayList list = new ArrayList(); - for (WeakReference modalEntity : myModalEntities) { + List list = new ArrayList(myModalEntities.length+1); + for (Reference modalEntity : myModalEntities) { Object entity = modalEntity.get(); if (entity == null) continue; list.add(entity); diff --git a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java index b93b98851d02..7fcfc157409b 100644 --- a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java +++ b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java @@ -1109,9 +1109,13 @@ public class StringUtil extends StringUtilRt { }; } + /** + * @return list containing all words in {@code text}, or {@link ContainerUtil#emptyList()} if there are none. + * The word here means the maximum sub-string consisting entirely of characters which are Character.isJavaIdentifierPart(c). + */ @NotNull public static List getWordsIn(@NotNull String text) { - List result = new SmartList(); + List result = null; int start = -1; for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); @@ -1120,13 +1124,22 @@ public class StringUtil extends StringUtilRt { start = i; } if (isIdentifierPart && i == text.length() - 1 && start != -1) { + if (result == null) { + result = new SmartList(); + } result.add(text.substring(start, i + 1)); } else if (!isIdentifierPart && start != -1) { + if (result == null) { + result = new SmartList(); + } result.add(text.substring(start, i)); start = -1; } } + if (result == null) { + return ContainerUtil.emptyList(); + } return result; }