diff --git a/platform/lang-api/src/com/intellij/usageView/UsageViewBundle.java b/platform/lang-api/src/com/intellij/usageView/UsageViewBundle.java index 1cb43c8b01fc..f6aa1bfc09fd 100644 --- a/platform/lang-api/src/com/intellij/usageView/UsageViewBundle.java +++ b/platform/lang-api/src/com/intellij/usageView/UsageViewBundle.java @@ -16,33 +16,21 @@ package com.intellij.usageView; -import com.intellij.CommonBundle; +import com.intellij.DynamicBundle; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.PropertyKey; -import java.lang.ref.Reference; -import java.lang.ref.SoftReference; -import java.util.ResourceBundle; - -/** - * @author yole - */ -public class UsageViewBundle { - - public static String message(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, @NotNull Object... params) { - return CommonBundle.message(getBundle(), key, params); - } - - private static Reference ourBundle; +public class UsageViewBundle extends DynamicBundle { @NonNls private static final String BUNDLE = "messages.UsageView"; - private UsageViewBundle() { - } + private static final UsageViewBundle INSTANCE = new UsageViewBundle(); - @SuppressWarnings({"AutoBoxing"}) - public static String getUsagesString(int usagesCount, int filesCount) { - return " (" + message("occurence.info.usage", usagesCount, filesCount) + ")"; + private UsageViewBundle() { super(BUNDLE); } + + @NotNull + public static String message(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, @NotNull Object... params) { + return INSTANCE.getMessage(key, params); } @SuppressWarnings({"AutoBoxing"}) @@ -54,13 +42,4 @@ public class UsageViewBundle { public static String getReferencesString(int usagesCount, int filesCount) { return " (" + message("occurence.info.reference", usagesCount, filesCount) + ")"; } - - public static ResourceBundle getBundle() { - ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); - if (bundle == null) { - bundle = ResourceBundle.getBundle(BUNDLE); - ourBundle = new SoftReference<>(bundle); - } - return bundle; - } -} +} \ No newline at end of file diff --git a/plugins/git4idea/src/git4idea/i18n/GitBundle.java b/plugins/git4idea/src/git4idea/i18n/GitBundle.java index d0fb0fcf795f..604836b3b5a6 100644 --- a/plugins/git4idea/src/git4idea/i18n/GitBundle.java +++ b/plugins/git4idea/src/git4idea/i18n/GitBundle.java @@ -14,54 +14,25 @@ * limitations under the License. */ package git4idea.i18n; -/* - * 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. - * - * Author: Anatol Pomazu - */ -import com.intellij.CommonBundle; +import com.intellij.DynamicBundle; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.PropertyKey; -import java.lang.ref.Reference; -import java.lang.ref.SoftReference; -import java.util.ResourceBundle; +public class GitBundle extends DynamicBundle { + @NonNls private static final String BUNDLE = "git4idea.i18n.GitBundle"; + private static final GitBundle INSTANCE = new GitBundle(); -/** - * Git4Idea package I18N localization bundle helper - */ -public class GitBundle { + private GitBundle() { super(BUNDLE); } + @NotNull public static String message(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, @NotNull Object... params) { - return CommonBundle.message(getBundle(), key, params); + return INSTANCE.getMessage(key, params); } - private static Reference ourBundle; - @NonNls - private static final String BUNDLE = "git4idea.i18n.GitBundle"; - - private GitBundle() { + @NotNull + public static String getString(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key) { + return message(key); } - - private static ResourceBundle getBundle() { - ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); - if (bundle == null) { - bundle = ResourceBundle.getBundle(BUNDLE); - ourBundle = new SoftReference<>(bundle); - } - return bundle; - } - - public static String getString(@PropertyKey(resourceBundle = BUNDLE) final String key) { - return getBundle().getString(key); - } -} +} \ No newline at end of file diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/HgVcsMessages.java b/plugins/hg4idea/src/org/zmlx/hg4idea/HgVcsMessages.java index 20e4daf13a6c..f91b430411a5 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/HgVcsMessages.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/HgVcsMessages.java @@ -12,34 +12,19 @@ // limitations under the License. package org.zmlx.hg4idea; +import com.intellij.DynamicBundle; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.PropertyKey; -import java.util.ResourceBundle; -import java.lang.ref.Reference; -import java.lang.ref.SoftReference; +public class HgVcsMessages extends DynamicBundle { + @NonNls private static final String BUNDLE = "org.zmlx.hg4idea.HgVcsMessages"; + private static final HgVcsMessages INSTANCE = new HgVcsMessages(); -import com.intellij.CommonBundle; + private HgVcsMessages() { super(BUNDLE); } -public final class HgVcsMessages { - - public static String message(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, @NotNull @Nullable Object... params) { - return CommonBundle.message(getBundle(), key, params); + @NotNull + public static String message(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, @NotNull Object... params) { + return INSTANCE.getMessage(key, params); } - - private static Reference ourBundle; - private static final String BUNDLE = "org.zmlx.hg4idea.HgVcsMessages"; - - private HgVcsMessages() { - } - - private static ResourceBundle getBundle() { - ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); - if (bundle == null) { - bundle = ResourceBundle.getBundle(BUNDLE); - ourBundle = new SoftReference<>(bundle); - } - return bundle; - } -} +} \ No newline at end of file diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnBundle.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnBundle.java index 9bc9da3ea3ff..4afb09710660 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnBundle.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnBundle.java @@ -15,37 +15,25 @@ */ package org.jetbrains.idea.svn; -import com.intellij.CommonBundle; +import com.intellij.DynamicBundle; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.PropertyKey; -import java.lang.ref.Reference; -import java.lang.ref.SoftReference; -import java.util.ResourceBundle; - -public class SvnBundle { - - public static String message(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, @NotNull Object... params) { - return CommonBundle.message(getBundle(), key, params); - } - - private static Reference ourBundle; +public class SvnBundle extends DynamicBundle { @NonNls private static final String BUNDLE = "org.jetbrains.idea.svn.SvnBundle"; - private SvnBundle() { + private static final SvnBundle INSTANCE = new SvnBundle(); + + private SvnBundle() { super(BUNDLE); } + + @NotNull + public static String message(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, @NotNull Object... params) { + return INSTANCE.getMessage(key, params); } - public static String getString(@PropertyKey(resourceBundle = BUNDLE) String key) { - return getBundle().getString(key); - } - - private static ResourceBundle getBundle() { - ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); - if (bundle == null) { - bundle = ResourceBundle.getBundle(BUNDLE); - ourBundle = new SoftReference<>(bundle); - } - return bundle; + @NotNull + public static String getString(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key) { + return message(key); } } diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnFileSystemListener.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnFileSystemListener.java index 6ecfe6cb4bd8..e10213c9a268 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnFileSystemListener.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/SvnFileSystemListener.java @@ -794,10 +794,10 @@ public class SvnFileSystemListener implements LocalFileOperationsHandler, Dispos else { final String singleFilePrompt; if (addedVFiles.size() == 1 && addedVFiles.get(0).isDirectory()) { - singleFilePrompt = SvnBundle.getString("confirmation.text.add.dir"); + singleFilePrompt = SvnBundle.message("confirmation.text.add.dir"); } else { - singleFilePrompt = SvnBundle.getString("confirmation.text.add.file"); + singleFilePrompt = SvnBundle.message("confirmation.text.add.file"); } filesToProcess = vcsHelper.selectFilesToProcess(addedVFiles, SvnBundle.message("confirmation.title.add.multiple.files"), null, @@ -915,11 +915,11 @@ public class SvnFileSystemListener implements LocalFileOperationsHandler, Dispos final String singleFilePrompt; if (deletedFiles.size() == 1 && deletedFiles.get(0).getFirst().isDirectory()) { singleFilePrompt = deletedFiles.get(0).getSecond().isOrGreater(WorkingCopyFormat.ONE_DOT_SEVEN) ? - SvnBundle.getString("confirmation.text.delete.dir.17") : - SvnBundle.getString("confirmation.text.delete.dir"); + SvnBundle.message("confirmation.text.delete.dir.17") : + SvnBundle.message("confirmation.text.delete.dir"); } else { - singleFilePrompt = SvnBundle.getString("confirmation.text.delete.file"); + singleFilePrompt = SvnBundle.message("confirmation.text.delete.file"); } Collection files = vcsHelper .selectFilePathsToProcess(map(deletedFiles, Functions.pairFirst()), SvnBundle.message("confirmation.title.delete.multiple.files"), diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/difftool/SvnChangeDiffViewerProvider.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/difftool/SvnChangeDiffViewerProvider.java index 3a2cbfa5d67b..34f663a46ecc 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/difftool/SvnChangeDiffViewerProvider.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/difftool/SvnChangeDiffViewerProvider.java @@ -61,18 +61,18 @@ public class SvnChangeDiffViewerProvider implements ChangeDiffViewerWrapperProvi throws DiffRequestProducerException { try { Change propertiesChange = getSvnChangeLayer(change); - if (propertiesChange == null) throw new DiffRequestProducerException(SvnBundle.getString("diff.cant.get.properties.changes")); + if (propertiesChange == null) throw new DiffRequestProducerException(SvnBundle.message("diff.cant.get.properties.changes")); ContentRevision bRevRaw = propertiesChange.getBeforeRevision(); ContentRevision aRevRaw = propertiesChange.getAfterRevision(); if (bRevRaw != null && !(bRevRaw instanceof PropertyRevision)) { LOG.warn("Before change is not PropertyRevision"); - throw new DiffRequestProducerException(SvnBundle.getString("diff.cant.get.properties.changes")); + throw new DiffRequestProducerException(SvnBundle.message("diff.cant.get.properties.changes")); } if (aRevRaw != null && !(aRevRaw instanceof PropertyRevision)) { LOG.warn("After change is not PropertyRevision"); - throw new DiffRequestProducerException(SvnBundle.getString("diff.cant.get.properties.changes")); + throw new DiffRequestProducerException(SvnBundle.message("diff.cant.get.properties.changes")); } PropertyRevision bRev = (PropertyRevision)bRevRaw; @@ -84,7 +84,7 @@ public class SvnChangeDiffViewerProvider implements ChangeDiffViewerWrapperProvi indicator.checkCanceled(); List aContent = aRev != null ? aRev.getProperties() : null; - if (aRev == null && bRev == null) throw new DiffRequestProducerException(SvnBundle.getString("diff.cant.get.properties.changes")); + if (aRev == null && bRev == null) throw new DiffRequestProducerException(SvnBundle.message("diff.cant.get.properties.changes")); ContentRevision bRevMain = change.getBeforeRevision(); ContentRevision aRevMain = change.getAfterRevision(); diff --git a/xml/dom-openapi/src/com/intellij/util/xml/DomBundle.java b/xml/dom-openapi/src/com/intellij/util/xml/DomBundle.java index bd00ef968dba..09f2df3f62db 100644 --- a/xml/dom-openapi/src/com/intellij/util/xml/DomBundle.java +++ b/xml/dom-openapi/src/com/intellij/util/xml/DomBundle.java @@ -16,36 +16,19 @@ package com.intellij.util.xml; -import com.intellij.CommonBundle; +import com.intellij.DynamicBundle; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.PropertyKey; -import java.lang.ref.Reference; -import java.lang.ref.SoftReference; -import java.util.ResourceBundle; +public class DomBundle extends DynamicBundle { + @NonNls private static final String BUNDLE = "messages.DomBundle"; + private static final DomBundle INSTANCE = new DomBundle(); -/** - * @author Dmitry Avdeev - */ -public class DomBundle { + private DomBundle() { super(BUNDLE); } - public static String message(@NotNull @PropertyKey(resourceBundle = "messages.DomBundle") String key, @NotNull Object... params) { - return CommonBundle.message(getBundle(), key, params); + @NotNull + public static String message(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, @NotNull Object... params) { + return INSTANCE.getMessage(key, params); } - - private static Reference ourBundle; - @NonNls protected static final String PATH_TO_BUNDLE = "messages.DomBundle"; - - private DomBundle() { - } - - private static ResourceBundle getBundle() { - ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); - if (bundle == null) { - bundle = ResourceBundle.getBundle(PATH_TO_BUNDLE); - ourBundle = new SoftReference<>(bundle); - } - return bundle; - } -} +} \ No newline at end of file diff --git a/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/CreateXmlElementIntentionAction.java b/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/CreateXmlElementIntentionAction.java index 62648ceeb769..df33313c372e 100644 --- a/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/CreateXmlElementIntentionAction.java +++ b/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/CreateXmlElementIntentionAction.java @@ -42,7 +42,7 @@ class CreateXmlElementIntentionAction implements IntentionAction { private final String myDeclarationTagName; CreateXmlElementIntentionAction( - @PropertyKey(resourceBundle = XmlBundle.PATH_TO_BUNDLE) String messageKey, + @PropertyKey(resourceBundle = XmlBundle.BUNDLE) String messageKey, @NonNls @NotNull String declarationTagName, TypeOrElementOrAttributeReference ref) { diff --git a/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/SchemaReferenceQuickFixProvider.java b/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/SchemaReferenceQuickFixProvider.java index b975a5b3fb7b..faccc173e002 100644 --- a/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/SchemaReferenceQuickFixProvider.java +++ b/xml/impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/SchemaReferenceQuickFixProvider.java @@ -37,7 +37,7 @@ public class SchemaReferenceQuickFixProvider extends UnresolvedReferenceQuickFix ); } else if (ref.getType() != null) { - @PropertyKey(resourceBundle = XmlBundle.PATH_TO_BUNDLE) String key = null; + @PropertyKey(resourceBundle = XmlBundle.BUNDLE) String key = null; @NonNls String declarationTagName = null; if (ref.getType() == TypeOrElementOrAttributeReference.ReferenceType.ElementReference) { diff --git a/xml/impl/src/com/intellij/xml/util/AddDtdDeclarationFix.java b/xml/impl/src/com/intellij/xml/util/AddDtdDeclarationFix.java index a8562811681a..9b1d5fb3d948 100644 --- a/xml/impl/src/com/intellij/xml/util/AddDtdDeclarationFix.java +++ b/xml/impl/src/com/intellij/xml/util/AddDtdDeclarationFix.java @@ -40,7 +40,7 @@ public class AddDtdDeclarationFix implements LocalQuickFix { private final String myReference; public AddDtdDeclarationFix( - @PropertyKey(resourceBundle = XmlBundle.PATH_TO_BUNDLE) String messageKey, + @PropertyKey(resourceBundle = XmlBundle.BUNDLE) String messageKey, @NotNull String elementDeclarationName, @NotNull PsiReference reference) { myMessageKey = messageKey; diff --git a/xml/xml-psi-api/src/com/intellij/xml/XmlBundle.java b/xml/xml-psi-api/src/com/intellij/xml/XmlBundle.java index 8336e33353b1..d452f5bc83a8 100644 --- a/xml/xml-psi-api/src/com/intellij/xml/XmlBundle.java +++ b/xml/xml-psi-api/src/com/intellij/xml/XmlBundle.java @@ -1,36 +1,19 @@ // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.xml; -import com.intellij.CommonBundle; +import com.intellij.DynamicBundle; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.PropertyKey; -import java.lang.ref.Reference; -import java.lang.ref.SoftReference; -import java.util.ResourceBundle; +public class XmlBundle extends DynamicBundle { + @NonNls public static final String BUNDLE = "messages.XmlBundle"; + private static final XmlBundle INSTANCE = new XmlBundle(); + + private XmlBundle() { super(BUNDLE); } -/** - * @author lesya - */ -public class XmlBundle { @NotNull - public static String message(@NotNull @PropertyKey(resourceBundle = PATH_TO_BUNDLE) String key, @NotNull Object... params) { - return CommonBundle.message(getBundle(), key, params); + public static String message(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, @NotNull Object... params) { + return INSTANCE.getMessage(key, params); } - - private static Reference ourBundle; - @NonNls public static final String PATH_TO_BUNDLE = "messages.XmlBundle"; - - private XmlBundle() { - } - - private static ResourceBundle getBundle() { - ResourceBundle bundle = com.intellij.reference.SoftReference.dereference(ourBundle); - if (bundle == null) { - bundle = ResourceBundle.getBundle(PATH_TO_BUNDLE); - ourBundle = new SoftReference<>(bundle); - } - return bundle; - } -} +} \ No newline at end of file