From bd644927b7d14f2a079ec3da44f73a68bcc56644 Mon Sep 17 00:00:00 2001 From: Alexander Zolotov Date: Mon, 5 Oct 2015 15:10:54 +0300 Subject: [PATCH] Extract method --- .../template/impl/EditVariableDialog.java | 2 +- .../codeInsight/template/impl/TemplateImplUtil.java | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/EditVariableDialog.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/EditVariableDialog.java index 50ca64075d5d..8cb9ab24a98b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/EditVariableDialog.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/EditVariableDialog.java @@ -259,7 +259,7 @@ class EditVariableDialog extends DialogWrapper { Variable variable = myVariables.get(row); if (col == 0) { String varName = (String) aValue; - if (TemplateImplUtil.parseVariables("$" + varName + "$").containsKey(varName)) { + if (TemplateImplUtil.isValidVariableName(varName)) { Variable newVar = new Variable(varName, variable.getExpressionString(), variable.getDefaultValueString(), variable.isAlwaysStopAt()); myVariables.set(row, newVar); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateImplUtil.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateImplUtil.java index fa429ba39911..8c9892a01ac6 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateImplUtil.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateImplUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -29,15 +29,15 @@ public class TemplateImplUtil { TemplateTextLexer lexer = new TemplateTextLexer(); lexer.start(text); - while(true){ + while (true) { IElementType tokenType = lexer.getTokenType(); if (tokenType == null) break; int start = lexer.getTokenStart(); int end = lexer.getTokenEnd(); String token = text.subSequence(start, end).toString(); - if (tokenType == TemplateTokenType.VARIABLE){ + if (tokenType == TemplateTokenType.VARIABLE) { String name = token.substring(1, token.length() - 1); - if (!variables.containsKey(name)){ + if (!variables.containsKey(name)) { variables.put(name, new Variable(name, "", "", true)); } } @@ -45,4 +45,8 @@ public class TemplateImplUtil { } return variables; } + + public static boolean isValidVariableName(String varName) { + return parseVariables("$" + varName + "$").containsKey(varName); + } }