Extract method

This commit is contained in:
Alexander Zolotov
2015-10-05 15:15:10 +03:00
parent a13eefb799
commit bd644927b7
2 changed files with 9 additions and 5 deletions
@@ -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);
@@ -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);
}
}