mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-114874 Live templates: don't allow editing $END$ and $SELECTION$ variables
remove special SELECTION var treatment, allow it to be non-var
This commit is contained in:
+10
-19
@@ -481,7 +481,7 @@ public class LiveTemplateSettingsEditor extends JPanel {
|
||||
}
|
||||
|
||||
private void validateEditVariablesButton() {
|
||||
myEditVariablesButton.setEnabled(!parseVariables(myTemplateEditor.getDocument().getCharsSequence()).isEmpty());
|
||||
myEditVariablesButton.setEnabled(!parseVariables().isEmpty());
|
||||
}
|
||||
|
||||
void resetUi() {
|
||||
@@ -552,20 +552,11 @@ public class LiveTemplateSettingsEditor extends JPanel {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
ArrayList<Variable> parsedVariables = parseVariables(myTemplateEditor.getDocument().getCharsSequence());
|
||||
|
||||
Map<String,String> newVariableNames = new HashMap<String, String>();
|
||||
for (Object parsedVariable : parsedVariables) {
|
||||
Variable newVariable = (Variable)parsedVariable;
|
||||
String name = newVariable.getName();
|
||||
newVariableNames.put(name, name);
|
||||
}
|
||||
Map<String,Variable> newVariableNames = parseVariables();
|
||||
|
||||
int oldVariableNumber = 0;
|
||||
for(int i = 0; i < parsedVariables.size(); i++){
|
||||
Variable variable = parsedVariables.get(i);
|
||||
if(oldVariableNames.contains(variable.getName())) {
|
||||
for (Map.Entry<String, Variable> entry : newVariableNames.entrySet()) {
|
||||
if(oldVariableNames.contains(entry.getKey())) {
|
||||
Variable oldVariable = null;
|
||||
for(;oldVariableNumber<oldVariables.size(); oldVariableNumber++) {
|
||||
oldVariable = oldVariables.get(oldVariableNumber);
|
||||
@@ -576,12 +567,12 @@ public class LiveTemplateSettingsEditor extends JPanel {
|
||||
}
|
||||
oldVariableNumber++;
|
||||
if(oldVariable != null) {
|
||||
parsedVariables.set(i, oldVariable);
|
||||
entry.setValue(oldVariable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return parsedVariables;
|
||||
return new ArrayList<Variable>(newVariableNames.values());
|
||||
}
|
||||
|
||||
private List<Variable> getCurrentVariables() {
|
||||
@@ -623,10 +614,10 @@ public class LiveTemplateSettingsEditor extends JPanel {
|
||||
}, modalityState);
|
||||
}
|
||||
|
||||
private static ArrayList<Variable> parseVariables(CharSequence text) {
|
||||
ArrayList<Variable> variables = new ArrayList<Variable>();
|
||||
TemplateImplUtil.parseVariables(text, variables, TemplateImpl.INTERNAL_VARS_SET);
|
||||
return variables;
|
||||
private Map<String, Variable> parseVariables() {
|
||||
Map<String,Variable> map = TemplateImplUtil.parseVariables(myTemplateEditor.getDocument().getCharsSequence());
|
||||
map.keySet().removeAll(TemplateImpl.INTERNAL_VARS_SET);
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -409,8 +409,8 @@ public class TemplateImpl extends Template implements SchemeElement {
|
||||
}
|
||||
|
||||
public boolean isSelectionTemplate() {
|
||||
for (Variable v : myVariables) {
|
||||
if (v.getName().equals(SELECTION)) return true;
|
||||
for (Segment v : mySegments) {
|
||||
if (v.name.equals(SELECTION)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
+6
-23
@@ -18,20 +18,16 @@ package com.intellij.codeInsight.template.impl;
|
||||
|
||||
import com.intellij.codeInsight.template.Expression;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.containers.hash.LinkedHashMap;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Maxim.Mossienko
|
||||
*/
|
||||
public class TemplateImplUtil {
|
||||
private TemplateImplUtil() {
|
||||
}
|
||||
|
||||
public static void parseVariables(CharSequence text, ArrayList<Variable> variables, @Nullable Set<String> predefinedVars) {
|
||||
public static LinkedHashMap<String, Variable> parseVariables(CharSequence text) {
|
||||
LinkedHashMap<String, Variable> variables = new LinkedHashMap<String, Variable>();
|
||||
TemplateTextLexer lexer = new TemplateTextLexer();
|
||||
lexer.start(text);
|
||||
|
||||
@@ -43,26 +39,13 @@ public class TemplateImplUtil {
|
||||
String token = text.subSequence(start, end).toString();
|
||||
if (tokenType == TemplateTokenType.VARIABLE){
|
||||
String name = token.substring(1, token.length() - 1);
|
||||
boolean isFound = false;
|
||||
|
||||
if (predefinedVars!=null && predefinedVars.contains(name) && !name.equals(TemplateImpl.SELECTION)){
|
||||
isFound = true;
|
||||
}
|
||||
else{
|
||||
for (Variable variable : variables) {
|
||||
if (variable.getName().equals(name)) {
|
||||
isFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isFound){
|
||||
variables.add(new Variable(name, "", "", true));
|
||||
if (!variables.containsKey(name)){
|
||||
variables.put(name, new Variable(name, "", "", true));
|
||||
}
|
||||
}
|
||||
lexer.advance();
|
||||
}
|
||||
return variables;
|
||||
}
|
||||
|
||||
public static Expression parseTemplate(@NonNls String text) {
|
||||
|
||||
Reference in New Issue
Block a user