Lazy value contract fixed

This commit is contained in:
Roman Shevchenko
2012-11-23 17:59:25 +01:00
parent 8daf20eafa
commit edff99391d
5 changed files with 87 additions and 19 deletions
@@ -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<MultiMap<String, URL>> myGroups = new NotNullLazyValue<MultiMap<String, URL>>() {
private final ClearableLazyValue<MultiMap<String, URL>> myGroups = new ClearableLazyValue<MultiMap<String, URL>>() {
@NotNull
@Override
protected MultiMap<String, URL> compute() {
@@ -117,7 +117,6 @@ public class ArchivedTemplatesFactory extends ProjectTemplatesFactory {
@NotNull
@Override
public ProjectTemplate[] createTemplates(String group, WizardContext context) {
Collection<URL> urls = myGroups.getValue().get(group);
List<ProjectTemplate> templates = new ArrayList<ProjectTemplate>();
for (URL url : urls) {
@@ -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<Boolean> myProperSetting = new NotNullLazyValue<Boolean>() {
private final ClearableLazyValue<Boolean> myProperSetting = new ClearableLazyValue<Boolean>() {
@NotNull
@Override
protected Boolean compute() {
@@ -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<T> extends ClearableLazyValue<T> {
@NotNull
@Override
public final synchronized T getValue() {
return super.getValue();
}
@Override
public final synchronized void drop() {
super.drop();
}
}
@@ -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<T> {
private T myValue;
@NotNull
protected abstract T compute();
@NotNull
public T getValue() {
if (myValue == null) {
myValue = compute();
}
return myValue;
}
public void drop() {
myValue = null;
}
}
@@ -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<T> {
@@ -35,8 +37,4 @@ public abstract class NotNullLazyValue<T> {
}
return myValue;
}
public void drop() {
myValue = null;
}
}