SSR: show script log var name as available variable in script editor

This commit is contained in:
Bas Leijdekkers
2016-03-26 15:38:00 +01:00
parent a35b2ef2d1
commit 1e2ba40257
3 changed files with 6 additions and 2 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -25,6 +25,8 @@ import com.intellij.structuralsearch.SSRBundle;
*/
public class ScriptLog {
public static final String SCRIPT_LOG_VAR_NAME = "__log__";
private static final NotificationGroup myEventLog = NotificationGroup.logOnlyGroup(SSRBundle.message("structural.search.title"));
private final Project myProject;
@@ -84,7 +84,7 @@ public class ScriptSupport {
public String evaluate(MatchResult result, PsiElement context) {
try {
final HashMap<String, Object> variableMap = new HashMap<String, Object>();
variableMap.put("__log__", myScriptLog);
variableMap.put(ScriptLog.SCRIPT_LOG_VAR_NAME, myScriptLog);
if (result != null) {
buildVariableMap(result, variableMap);
if (context == null) {
@@ -28,6 +28,7 @@ import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiFileFactory;
import com.intellij.structuralsearch.*;
import com.intellij.structuralsearch.impl.matcher.CompiledPattern;
import com.intellij.structuralsearch.impl.matcher.predicates.ScriptLog;
import com.intellij.structuralsearch.impl.matcher.predicates.ScriptSupport;
import com.intellij.structuralsearch.plugin.replace.ReplaceOptions;
import com.intellij.structuralsearch.plugin.replace.ui.ReplaceConfiguration;
@@ -272,6 +273,7 @@ class EditVarConstraintsDialog extends DialogWrapper {
customScriptCode.getButton().addActionListener(new ActionListener() {
public void actionPerformed(@NotNull final ActionEvent e) {
final List<String> variableNames = ContainerUtil.newArrayList(myConfiguration.getMatchOptions().getVariableConstraintNames());
variableNames.add(ScriptLog.SCRIPT_LOG_VAR_NAME);
variableNames.remove(CompiledPattern.ALL_CLASS_UNMATCHED_CONTENT_VAR_ARTIFICIAL_NAME);
final EditScriptDialog dialog = new EditScriptDialog(project, customScriptCode.getChildComponent().getText(), variableNames);
dialog.show();