Merge branch 'master' of git.labs.intellij.net:idea/community cidr/100.85 idea/100.87 pycharm/100.84 pycharm/100.88 rubymine/100.86
authorMaxim.Mossienko <Maxim.Mossienko@jetbrains.com>
Fri, 17 Dec 2010 14:22:43 +0000 (17:22 +0300)
committerMaxim.Mossienko <Maxim.Mossienko@jetbrains.com>
Fri, 17 Dec 2010 14:22:43 +0000 (17:22 +0300)
platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DefaultHighlightVisitor.java
platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java
platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestUtil.java

index 1d2f5e256b313ad6ca6d14af0bc4b9041981a802..c569d0cab7f1c41ee4368c7baa39dd1a2b1e369c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2010 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.
index adb4f94525e7458a0381c15fe0096990cc703330..cd01409972b337e6c32dde0eb018ca4f3e844005 100644 (file)
@@ -111,8 +111,10 @@ public class VariableInplaceRenamer {
       return false;
     }
 
-    VirtualFile vFile = myElementToRename.getContainingFile().getVirtualFile();
-    SearchScope referencesSearchScope = vFile == null || ProjectRootManager.getInstance(myProject).getFileIndex().isInContent(vFile)
+    final FileViewProvider fileViewProvider = myElementToRename.getContainingFile().getViewProvider();
+    VirtualFile file = getTopLevelVirtualFile(fileViewProvider);
+
+    SearchScope referencesSearchScope = file == null || ProjectRootManager.getInstance(myProject).getFileIndex().isInContent(file)
       ? ProjectScope.getProjectScope(myElementToRename.getProject())
       : new LocalSearchScope(myElementToRename.getContainingFile());
 
@@ -120,9 +122,6 @@ public class VariableInplaceRenamer {
 
     addReferenceAtCaret(refs);
 
-    final FileViewProvider fileViewProvider = myElementToRename.getContainingFile().getViewProvider();
-    VirtualFile file = getTopLevelVirtualFile(fileViewProvider);
-
     for (PsiReference ref : refs) {
       final FileViewProvider usageViewProvider = ref.getElement().getContainingFile().getViewProvider();
 
index f23786a406492cfc72214974f4f58726bc0cefc1..aa0b72d4710df57939f1d8d368c28464da269cad 100644 (file)
@@ -29,6 +29,7 @@ import com.intellij.codeInsight.template.impl.TemplateManagerImpl;
 import com.intellij.codeInsight.template.impl.TemplateState;
 import com.intellij.codeInsight.template.impl.actions.ListTemplatesAction;
 import com.intellij.ide.DataManager;
+import com.intellij.injected.editor.EditorWindow;
 import com.intellij.lang.surroundWith.Surrounder;
 import com.intellij.openapi.actionSystem.AnAction;
 import com.intellij.openapi.actionSystem.DataContext;
@@ -152,27 +153,33 @@ public class CodeInsightTestUtil {
   }
 
   public static void doInlineRename(VariableInplaceRenameHandler handler, final String newName, CodeInsightTestFixture fixture) {
-    final Editor editor = fixture.getEditor();
-    PsiElement element = fixture.getElementAtCaret();
+    doInlineRename(handler, newName, fixture.getEditor(), fixture.getElementAtCaret());
+  }
+
+  public static void doInlineRename(VariableInplaceRenameHandler handler, final String newName, Editor editor, PsiElement elementAtCaret) {
     Project project = editor.getProject();
     TemplateManagerImpl templateManager = (TemplateManagerImpl)TemplateManager.getInstance(project);
     try {
       templateManager.setTemplateTesting(true);
-      VariableInplaceRenamer renamer = handler.doRename(element, editor, null);
+      VariableInplaceRenamer renamer = handler.doRename(elementAtCaret, editor, null);
+      if (editor instanceof EditorWindow) {
+        editor = ((EditorWindow)editor).getDelegate();
+      }
       TemplateState state = TemplateManagerImpl.getTemplateState(editor);
       final TextRange range = state.getCurrentVariableRange();
       assert range != null;
+      final Editor finalEditor = editor;
       new WriteCommandAction.Simple(project) {
         @Override
         protected void run() throws Throwable {
-          editor.getDocument().replaceString(range.getStartOffset(), range.getEndOffset(), newName);
+          finalEditor.getDocument().replaceString(range.getStartOffset(), range.getEndOffset(), newName);
         }
       }.execute().throwException();
       assert renamer != null;
       renamer.finish();
 
       TemplateManagerImpl.getTemplateState(editor).gotoEnd();
-      renamer.performAutomaticRename(newName, element);
+      renamer.performAutomaticRename(newName, elementAtCaret);
     }
     finally {
       templateManager.setTemplateTesting(false);