mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
EA-69415 - CCE: FxmlReferencesContributor$MyJavaClassReferenceProvider$JavaClassReferenceWrapper.bindToElement
This commit is contained in:
+4
@@ -36,6 +36,10 @@ public class JavaFXRenameTest extends JavaFXDaemonAnalyzerTestCase {
|
||||
doTest(getTestName(false) + "1");
|
||||
}
|
||||
|
||||
public void testInRoot() throws Exception {
|
||||
doTest(getTestName(false) + "1");
|
||||
}
|
||||
|
||||
public void testControllerField() throws Exception {
|
||||
doTest("newFieldName");
|
||||
}
|
||||
|
||||
+22
-4
@@ -21,6 +21,7 @@ import com.intellij.patterns.XmlAttributeValuePattern;
|
||||
import com.intellij.patterns.XmlPatterns;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceProvider;
|
||||
import com.intellij.psi.xml.XmlAttribute;
|
||||
import com.intellij.psi.xml.XmlAttributeValue;
|
||||
import com.intellij.psi.xml.XmlProcessingInstruction;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
@@ -193,20 +194,37 @@ public class FxmlReferencesContributor extends PsiReferenceContributor {
|
||||
}
|
||||
|
||||
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
|
||||
String oldText = ((XmlTag)myPosition).getName();
|
||||
String oldText = getOldName();
|
||||
final TextRange range = getRangeInElement();
|
||||
final String newText =
|
||||
oldText.substring(0, range.getStartOffset() - 1) + newElementName + oldText.substring(range.getEndOffset() - 1);
|
||||
return ((XmlTag)myPosition).setName(newText);
|
||||
return setNewName(newText);
|
||||
}
|
||||
|
||||
public PsiElement bindToElement(@NotNull PsiElement element)
|
||||
throws IncorrectOperationException {
|
||||
String oldText = ((XmlTag)myPosition).getName();
|
||||
String oldText = getOldName();
|
||||
final TextRange range = getRangeInElement();
|
||||
final String newText = (element instanceof PsiPackage ? ((PsiPackage)element).getQualifiedName() : ((PsiClass)element).getName()) +
|
||||
oldText.substring(range.getEndOffset() - 1);
|
||||
return ((XmlTag)myPosition).setName(newText);
|
||||
return setNewName(newText);
|
||||
}
|
||||
|
||||
private PsiElement setNewName(String newText) {
|
||||
if (myPosition instanceof XmlTag) {
|
||||
return ((XmlTag)myPosition).setName(newText);
|
||||
}
|
||||
else {
|
||||
final XmlElementFactory xmlElementFactory = XmlElementFactory.getInstance(myPosition.getProject());
|
||||
final XmlAttribute xmlAttribute = xmlElementFactory.createXmlAttribute("attributeName", newText);
|
||||
final XmlAttributeValue valueElement = xmlAttribute.getValueElement();
|
||||
assert valueElement != null;
|
||||
return myPosition.replace(valueElement);
|
||||
}
|
||||
}
|
||||
|
||||
private String getOldName() {
|
||||
return myPosition instanceof XmlTag ? ((XmlTag)myPosition).getName() : ((XmlAttributeValue)myPosition).getValue();
|
||||
}
|
||||
|
||||
public boolean isReferenceTo(PsiElement element) {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
public class InRoot extends javafx.scene.layout.GridPane {}
|
||||
@@ -0,0 +1 @@
|
||||
<fx:root type="In<caret>Root" xmlns:fx="http://javafx.com/fxml"/>
|
||||
@@ -0,0 +1 @@
|
||||
<fx:root type="InRoot1" xmlns:fx="http://javafx.com/fxml"/>
|
||||
Reference in New Issue
Block a user