diff --git a/java/idea-ui/src/com/intellij/platform/templates/ArchivedTemplatesFactory.java b/java/idea-ui/src/com/intellij/platform/templates/ArchivedTemplatesFactory.java index 9ff36f242f15..dfc8a1faa4b6 100644 --- a/java/idea-ui/src/com/intellij/platform/templates/ArchivedTemplatesFactory.java +++ b/java/idea-ui/src/com/intellij/platform/templates/ArchivedTemplatesFactory.java @@ -21,7 +21,7 @@ import com.intellij.ide.plugins.PluginManager; import com.intellij.ide.util.projectWizard.WizardContext; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.util.NotNullLazyValue; +import com.intellij.openapi.util.ClearableLazyValue; import com.intellij.platform.ProjectTemplate; import com.intellij.platform.ProjectTemplatesFactory; import com.intellij.util.ArrayUtil; @@ -37,13 +37,13 @@ import java.util.*; /** * @author Dmitry Avdeev - * Date: 10/1/12 + * @since 10/1/12 */ public class ArchivedTemplatesFactory extends ProjectTemplatesFactory { private static final String ZIP = ".zip"; - private final NotNullLazyValue> myGroups = new NotNullLazyValue>() { + private final ClearableLazyValue> myGroups = new ClearableLazyValue>() { @NotNull @Override protected MultiMap compute() { @@ -117,7 +117,6 @@ public class ArchivedTemplatesFactory extends ProjectTemplatesFactory { @NotNull @Override public ProjectTemplate[] createTemplates(String group, WizardContext context) { - Collection urls = myGroups.getValue().get(group); List templates = new ArrayList(); for (URL url : urls) { diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/InspectionConfigTreeNode.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/InspectionConfigTreeNode.java index 54071fc0b667..2fa06be73ab5 100644 --- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/InspectionConfigTreeNode.java +++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/InspectionConfigTreeNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -13,26 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -/* - * User: anna - * Date: 14-May-2009 - */ package com.intellij.profile.codeInspection.ui; import com.intellij.codeInspection.ex.Descriptor; import com.intellij.codeInspection.ex.ScopeToolState; -import com.intellij.openapi.util.NotNullLazyValue; +import com.intellij.openapi.util.ClearableLazyValue; import com.intellij.psi.search.scope.packageSet.NamedScope; import com.intellij.ui.CheckedTreeNode; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +/** + * @author anna + * @since 14-May-2009 + */ public class InspectionConfigTreeNode extends CheckedTreeNode { private ScopeToolState myState; private boolean myByDefault; private boolean myInspectionNode; - private final NotNullLazyValue myProperSetting = new NotNullLazyValue() { + private final ClearableLazyValue myProperSetting = new ClearableLazyValue() { @NotNull @Override protected Boolean compute() { diff --git a/platform/util/src/com/intellij/openapi/util/AtomicClearableLazyValue.java b/platform/util/src/com/intellij/openapi/util/AtomicClearableLazyValue.java new file mode 100644 index 000000000000..b939df370f5f --- /dev/null +++ b/platform/util/src/com/intellij/openapi/util/AtomicClearableLazyValue.java @@ -0,0 +1,31 @@ +/* + * 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.openapi.util; + +import org.jetbrains.annotations.NotNull; + +public abstract class AtomicClearableLazyValue extends ClearableLazyValue { + @NotNull + @Override + public final synchronized T getValue() { + return super.getValue(); + } + + @Override + public final synchronized void drop() { + super.drop(); + } +} diff --git a/platform/util/src/com/intellij/openapi/util/ClearableLazyValue.java b/platform/util/src/com/intellij/openapi/util/ClearableLazyValue.java new file mode 100644 index 000000000000..e58acb3be79a --- /dev/null +++ b/platform/util/src/com/intellij/openapi/util/ClearableLazyValue.java @@ -0,0 +1,41 @@ +/* + * 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.openapi.util; + +import org.jetbrains.annotations.NotNull; + +/** + * Lazy value with ability to reset (and recompute) the value. + * Thread-safe version: {@link AtomicClearableLazyValue}. + */ +public abstract class ClearableLazyValue { + private T myValue; + + @NotNull + protected abstract T compute(); + + @NotNull + public T getValue() { + if (myValue == null) { + myValue = compute(); + } + return myValue; + } + + public void drop() { + myValue = null; + } +} diff --git a/platform/util/src/com/intellij/openapi/util/NotNullLazyValue.java b/platform/util/src/com/intellij/openapi/util/NotNullLazyValue.java index ea51d5f5ddc0..4768ac666a35 100644 --- a/platform/util/src/com/intellij/openapi/util/NotNullLazyValue.java +++ b/platform/util/src/com/intellij/openapi/util/NotNullLazyValue.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * 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. @@ -13,13 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.openapi.util; import org.jetbrains.annotations.NotNull; /** - * Thread-safe version: {@link com.intellij.openapi.util.AtomicNotNullLazyValue}. + * Compute-once keep-forever lazy value. + * Thread-safe version: {@link AtomicNotNullLazyValue}. + * Clearable version: {@link ClearableLazyValue}. + * * @author peter */ public abstract class NotNullLazyValue { @@ -35,8 +37,4 @@ public abstract class NotNullLazyValue { } return myValue; } - - public void drop() { - myValue = null; - } } \ No newline at end of file