summaryrefslogtreecommitdiff
path: root/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/replace/impl/ReplacementContext.java
diff options
context:
space:
mode:
Diffstat (limited to 'platform/structuralsearch/source/com/intellij/structuralsearch/plugin/replace/impl/ReplacementContext.java')
-rw-r--r--platform/structuralsearch/source/com/intellij/structuralsearch/plugin/replace/impl/ReplacementContext.java57
1 files changed, 57 insertions, 0 deletions
diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/replace/impl/ReplacementContext.java b/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/replace/impl/ReplacementContext.java
new file mode 100644
index 000000000000..c77d0b7ce1f1
--- /dev/null
+++ b/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/replace/impl/ReplacementContext.java
@@ -0,0 +1,57 @@
+package com.intellij.structuralsearch.plugin.replace.impl;
+
+import com.intellij.openapi.project.Project;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiNamedElement;
+import com.intellij.structuralsearch.MatchResult;
+import com.intellij.structuralsearch.StructuralSearchUtil;
+import com.intellij.structuralsearch.plugin.replace.ReplaceOptions;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: Maxim.Mossienko
+ * Date: 27.09.2005
+ * Time: 14:27:20
+ * To change this template use File | Settings | File Templates.
+ */
+public class ReplacementContext {
+ ReplacementInfoImpl replacementInfo;
+ ReplaceOptions options;
+ Project project;
+
+ public ReplaceOptions getOptions() {
+ return options;
+ }
+
+ public Project getProject() {
+ return project;
+ }
+
+ ReplacementContext(ReplaceOptions _options, Project _project) {
+ options = _options;
+ project = _project;
+ }
+
+ public Map<String, String> getNewName2PatternNameMap() {
+ Map<String, String> newNameToSearchPatternNameMap = new HashMap<String, String>(1);
+ final Map<String, MatchResult> variableMap = replacementInfo.getVariableMap();
+
+ if (variableMap != null) {
+ for (String s : variableMap.keySet()) {
+ final MatchResult matchResult = replacementInfo.getVariableMap().get(s);
+ PsiElement match = matchResult.getMatchRef() != null ? matchResult.getMatch() : null;
+ if (StructuralSearchUtil.isIdentifier(match)) match = match.getParent();
+
+ if (match instanceof PsiNamedElement) {
+ final String name = ((PsiNamedElement)match).getName();
+
+ newNameToSearchPatternNameMap.put(name, s);
+ }
+ }
+ }
+ return newNameToSearchPatternNameMap;
+ }
+}