From b875b325050d3d409e79d506473bdace1c88997b Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 4 Feb 2016 12:10:10 +0100 Subject: [PATCH] revert IDEA-145973 Same-named template macros for different languages --- .../codeInsight/template/MacroParserTest.java | 4 ++-- .../template/ExpressionContext.java | 7 ------ .../template/impl/MacroCallNode.java | 24 ++++++------------- .../template/impl/MacroParser.java | 2 +- .../template/impl/TemplateManagerImpl.java | 1 - .../template/impl/TemplateState.java | 16 +------------ 6 files changed, 11 insertions(+), 43 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/template/MacroParserTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/template/MacroParserTest.java index d05067b23d0c..18655337b98e 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/template/MacroParserTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/template/MacroParserTest.java @@ -19,7 +19,7 @@ public class MacroParserTest extends LightIdeaTestCase { Expression e = MacroParser.parse(" variableOfType( \"java.util.Collection\" ) "); assertTrue(e instanceof MacroCallNode); MacroCallNode n = (MacroCallNode) e; - assertTrue(n.getMacro(new TemplateContextType[0]) instanceof VariableOfTypeMacro); + assertTrue(n.getMacro() instanceof VariableOfTypeMacro); Expression[] parameters = n.getParameters(); assertEquals(1, parameters.length); assertTrue(parameters [0] instanceof ConstantNode); @@ -46,7 +46,7 @@ public class MacroParserTest extends LightIdeaTestCase { Expression e = MacroParser.parse("variableOfType(\"A\", \"B\")"); assertTrue(e instanceof MacroCallNode); MacroCallNode n = (MacroCallNode) e; - assertTrue(n.getMacro(new TemplateContextType[0]) instanceof VariableOfTypeMacro); + assertTrue(n.getMacro() instanceof VariableOfTypeMacro); Expression[] parameters = n.getParameters(); assertEquals(2, parameters.length); assertTrue(parameters [0] instanceof ConstantNode); diff --git a/platform/lang-api/src/com/intellij/codeInsight/template/ExpressionContext.java b/platform/lang-api/src/com/intellij/codeInsight/template/ExpressionContext.java index ced75119175d..b86edbedbe1f 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/template/ExpressionContext.java +++ b/platform/lang-api/src/com/intellij/codeInsight/template/ExpressionContext.java @@ -21,7 +21,6 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public interface ExpressionContext { @@ -37,11 +36,5 @@ public interface ExpressionContext { T getProperty(Key key); @Nullable PsiElement getPsiElementAtStartOffset(); - - /** - * @return all template context types matching the template invocation place - */ - @NotNull - TemplateContextType[] getCompatibleContexts(); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/MacroCallNode.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/MacroCallNode.java index b11356ad0426..945830bb1031 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/MacroCallNode.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/MacroCallNode.java @@ -21,49 +21,39 @@ import com.intellij.codeInsight.template.*; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.function.Predicate; public class MacroCallNode extends Expression { - private final List myMacros; + private final Macro myMacro; private final ArrayList myParameters = new ArrayList<>(); public MacroCallNode(@NotNull Macro macro) { - this(Collections.singletonList(macro)); - } - - public MacroCallNode(List macros) { - myMacros = macros; - assert macros.size() > 0; + myMacro = macro; } public void addParameter(Expression node) { myParameters.add(node); } - public Macro getMacro(TemplateContextType[] context) { - Predicate isAcceptableInContext = macro -> Arrays.stream(context).anyMatch(macro::isAcceptableInContext); - return myMacros.stream().filter(isAcceptableInContext).findFirst().orElse(myMacros.get(0)); + public Macro getMacro() { + return myMacro; } @Override public Result calculateResult(ExpressionContext context) { Expression[] parameters = myParameters.toArray(new Expression[myParameters.size()]); - return getMacro(context.getCompatibleContexts()).calculateResult(parameters, context); + return getMacro().calculateResult(parameters, context); } @Override public Result calculateQuickResult(ExpressionContext context) { Expression[] parameters = myParameters.toArray(new Expression[myParameters.size()]); - return getMacro(context.getCompatibleContexts()).calculateQuickResult(parameters, context); + return getMacro().calculateQuickResult(parameters, context); } @Override public LookupElement[] calculateLookupItems(ExpressionContext context) { Expression[] parameters = myParameters.toArray(new Expression[myParameters.size()]); - return getMacro(context.getCompatibleContexts()).calculateLookupItems(parameters, context); + return getMacro().calculateLookupItems(parameters, context); } public Expression[] getParameters() { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/MacroParser.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/MacroParser.java index d6f0ac72b766..c7d9e73583c0 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/MacroParser.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/MacroParser.java @@ -84,7 +84,7 @@ public class MacroParser { } advance(lexer); - MacroCallNode macroCallNode = new MacroCallNode(macros); + MacroCallNode macroCallNode = new MacroCallNode(macros.get(0)); if (lexer.getTokenType() == null) { return macroCallNode; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateManagerImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateManagerImpl.java index df19186202c9..0a50b8b6434d 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateManagerImpl.java @@ -122,7 +122,6 @@ public class TemplateManagerImpl extends TemplateManager implements Disposable { private TemplateState initTemplateState(@NotNull Editor editor) { clearTemplateState(editor); - PsiDocumentManager.getInstance(myProject).commitDocument(editor.getDocument()); TemplateState state = new TemplateState(myProject, editor); Disposer.register(this, state); editor.putUserData(TEMPLATE_STATE_KEY, state); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateState.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateState.java index c64329f0e1c4..bf2f53af6360 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateState.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateState.java @@ -99,19 +99,11 @@ public class TemplateState implements Disposable { @Nullable private PairProcessor myProcessor; private boolean mySelectionCalculated = false; private boolean myStarted; - private final TemplateContextType[] myCompatibleContexts; TemplateState(@NotNull Project project, @NotNull final Editor editor) { myProject = project; myEditor = editor; myDocument = myEditor.getDocument(); - - PsiFile file = getPsiFile(); - if (file != null) { - myCompatibleContexts = TemplateManagerImpl.getApplicableContextTypes(file, editor.getCaretModel().getOffset()).toArray(new TemplateContextType[0]); - } else { - myCompatibleContexts = new TemplateContextType[0]; - } } private void initListeners() { @@ -935,12 +927,6 @@ public class TemplateState implements Disposable { PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); return file == null ? null : file.findElementAt(offset); } - - @NotNull - @Override - public TemplateContextType[] getCompatibleContexts() { - return myCompatibleContexts; - } }; } @@ -1085,7 +1071,7 @@ public class TemplateState implements Disposable { Expression e = myTemplate.getExpressionAt(j); @NonNls String marker = "a"; if (e instanceof MacroCallNode) { - marker = ((MacroCallNode)e).getMacro(myCompatibleContexts).getDefaultValue(); + marker = ((MacroCallNode)e).getMacro().getDefaultValue(); } replaceString(marker, mySegments.getSegmentStart(i), mySegments.getSegmentEnd(i), i); indices.add(i);