when a reference needs no binding, its end offset was calculated incorrectly (EA-44764)

This commit is contained in:
peter
2013-03-18 19:07:55 +01:00
parent d3f0482f6f
commit ef63223676
3 changed files with 79 additions and 16 deletions
@@ -654,11 +654,11 @@ public class JavaCompletionUtil {
assert document != null;
document.replaceString(startOffset, endOffset, name);
final RangeMarker toDelete = insertTemporary(startOffset + name.length(), document, " ");
int newEndOffset = startOffset + name.length();
final RangeMarker toDelete = insertTemporary(newEndOffset, document, " ");
documentManager.commitAllDocuments();
int newEndOffset = endOffset;
PsiElement element = file.findElementAt(startOffset);
if (element instanceof PsiIdentifier) {
PsiElement parent = element.getParent();
@@ -0,0 +1,77 @@
package com.intellij.codeInsight.daemon.quickFix
import com.intellij.codeInsight.lookup.LookupManager
import com.intellij.codeInsight.template.TemplateManager
import com.intellij.codeInsight.template.impl.TemplateManagerImpl
import com.intellij.ide.DataManager
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.actionSystem.IdeActions
import com.intellij.openapi.editor.actionSystem.EditorActionManager
/**
* @author ven
*/
public class CreateMethodFromUsageTest extends LightQuickFixTestCase {
public void test() throws Exception { doAllTests(); }
public void testTemplateAssertions() throws Exception {
configureFromFileText "a.java", """
class SomeOuterClassWithLongName {
void foo(PropertyDescriptorWithVeryLongName.Group group, PropertyDescriptorWithVeryLongName.Group child) {
group.add<caret>SubGroup(child);
}
static class PropertyDescriptorWithVeryLongName {
static class Group {
}
}
}
"""
((TemplateManagerImpl)TemplateManager.getInstance(getProject())).setTemplateTesting(true);
doAction("Create Method 'addSubGroup'")
def state = TemplateManagerImpl.getTemplateState(getEditor())
//skip void return type
state.nextTab()
// parameter type
assert LookupManager.getActiveLookup(editor)?.currentItem?.lookupString?.endsWith('Group')
EditorActionManager actionManager = EditorActionManager.getInstance();
final DataContext dataContext = DataManager.getInstance().getDataContext();
actionManager.getActionHandler(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM).execute(getEditor(), dataContext);
// parameter name, skip it
assert LookupManager.getActiveLookup(editor)?.currentItem?.lookupString == 'child'
state.nextTab()
assert state.finished
checkResultByText """
class SomeOuterClassWithLongName {
void foo(PropertyDescriptorWithVeryLongName.Group group, PropertyDescriptorWithVeryLongName.Group child) {
group.addSubGroup(child);
}
static class PropertyDescriptorWithVeryLongName {
static class Group {
public void addSubGroup(Group child) {
<selection>//To change body of created methods use File | Settings | File Templates.</selection>
}
}
}
}
"""
}
@Override
protected void tearDown() throws Exception {
((TemplateManagerImpl)TemplateManager.getInstance(getProject())).setTemplateTesting(true);
super.tearDown()
}
@Override
protected String getBasePath() {
return "/codeInsight/daemonCodeAnalyzer/quickFix/createMethodFromUsage";
}
}
@@ -1,14 +0,0 @@
package com.intellij.codeInsight.daemon.quickFix;
/**
* @author ven
*/
public class CreateMethodFromUsageTest extends LightQuickFixTestCase {
public void test() throws Exception { doAllTests(); }
@Override
protected String getBasePath() {
return "/codeInsight/daemonCodeAnalyzer/quickFix/createMethodFromUsage";
}
}