javafx: inplace rename for custom components called by qualified name fixed (IDEA-101227)

This commit is contained in:
anna
2013-04-01 13:50:22 +02:00
parent c05c67943d
commit 6784ba1d3d
2 changed files with 27 additions and 2 deletions

View File

@@ -20,7 +20,9 @@ import com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase;
import com.intellij.openapi.application.PluginPathManager;
import com.intellij.psi.PsiElement;
import com.intellij.refactoring.rename.RenameProcessor;
import com.intellij.refactoring.rename.inplace.MemberInplaceRenameHandler;
import com.intellij.testFramework.PsiTestUtil;
import com.intellij.testFramework.fixtures.CodeInsightTestUtil;
import org.jetbrains.annotations.NotNull;
public class JavaFXRenameTest extends DaemonAnalyzerTestCase {
@@ -47,15 +49,23 @@ public class JavaFXRenameTest extends DaemonAnalyzerTestCase {
}
public void testCustomComponentTag() throws Exception {
doTest("Foo");
doTest("Foo", true);
}
private void doTest(final String newName) throws Exception {
doTest(newName, false);
}
private void doTest(final String newName, boolean inline) throws Exception {
configureByFiles(null, getTestName(true) + ".fxml", getTestName(false) + ".java");
PsiElement element = TargetElementUtilBase
.findTargetElement(myEditor, TargetElementUtilBase.ELEMENT_NAME_ACCEPTED | TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED);
assertNotNull(element);
new RenameProcessor(getProject(), element, newName, true, true).run();
if (inline) {
CodeInsightTestUtil.doInlineRename(new MemberInplaceRenameHandler(), newName, getEditor(), element);
} else {
new RenameProcessor(getProject(), element, newName, true, true).run();
}
checkResultByFile(getTestName(true) + "_after.fxml");
}

View File

@@ -8,6 +8,7 @@ import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.codeInsight.quickfix.UnresolvedReferenceQuickFixProvider;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
@@ -35,6 +36,20 @@ public class JavaFxTagNameReference extends TagNameReference{
super(element, startTagFlag);
}
@Override
public TextRange getRangeInElement() {
final TextRange rangeInElement = super.getRangeInElement();
final XmlTag tagElement = getTagElement();
if (tagElement != null) {
final String tagElementName = tagElement.getName();
final int dotIdx = tagElementName.indexOf(".");
if (dotIdx > -1 && dotIdx + 2 < rangeInElement.getEndOffset()) {
return new TextRange(rangeInElement.getStartOffset() + dotIdx + 1, rangeInElement.getEndOffset());
}
}
return rangeInElement;
}
@Override
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
if (element instanceof PsiClass) {