From 406c45f9ae531e32f0c6c9ca08863e3c9a8e9a98 Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 28 Mar 2014 17:33:55 +0100 Subject: [PATCH] some TemplateContext improvements after review --- .../NormalCompletionOrderingTest.groovy | 4 ++++ .../impl/LiveTemplateSettingsEditor.java | 2 +- .../template/impl/TemplateContext.java | 18 +++++++++++------- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy index 64dba685bddc..fa528a144f98 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionOrderingTest.groovy @@ -628,4 +628,8 @@ interface TxANotAnno {} assertPreferredItems 0, 'newLinkedSet1', 'newLinkedSet0', 'newLinkedSet2' } + public void testLocalReassignment() { + checkPreferredItems 0, 'localVar', 'localMethod' + } + } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateSettingsEditor.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateSettingsEditor.java index efc279c49c85..1988c9d1d8a4 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateSettingsEditor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateSettingsEditor.java @@ -404,7 +404,7 @@ public class LiveTemplateSettingsEditor extends JPanel { protected void onNodeStateChanged(CheckedTreeNode node) { final TemplateContextType type = (TemplateContextType)((Pair)node.getUserObject()).first; if (type != null) { - context.putValue(type, node.isChecked()); + context.setEnabled(type, node.isChecked()); } onChange.run(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateContext.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateContext.java index e632a6848d03..fe89900bfc06 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateContext.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateContext.java @@ -58,15 +58,17 @@ public class TemplateContext { } public boolean isEnabled(TemplateContextType contextType) { - Boolean storedValue = getOwnValue(contextType); - if (storedValue == null) { - TemplateContextType baseContextType = contextType.getBaseContextType(); - if (baseContextType != null && !(baseContextType instanceof EverywhereContextType)) { - return isEnabled(baseContextType); + synchronized (myContextStates) { + Boolean storedValue = getOwnValue(contextType); + if (storedValue == null) { + TemplateContextType baseContextType = contextType.getBaseContextType(); + if (baseContextType != null && !(baseContextType instanceof EverywhereContextType)) { + return isEnabled(baseContextType); + } + return false; } - return false; + return storedValue.booleanValue(); } - return storedValue.booleanValue(); } public void putValue(TemplateContextType context, boolean enabled) { @@ -92,6 +94,7 @@ public class TemplateContext { } } + // used during initialization => no sync void setDefaultContext(@NotNull TemplateContext defContext) { HashMap copy = new HashMap(myContextStates); myContextStates.clear(); @@ -99,6 +102,7 @@ public class TemplateContext { myContextStates.putAll(copy); } + // used during initialization => no sync void readTemplateContext(Element element) throws InvalidDataException { List options = element.getChildren("option"); for (Object e : options) {