mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
javafx: navigate to java from ref expression if possible (IDEA-101239)
This commit is contained in:
+10
-1
@@ -68,7 +68,16 @@ class JavaFxComponentIdReferenceProvider extends PsiReferenceProvider {
|
||||
final String newId = StringUtil.getPackageName(expressionText);
|
||||
final String fieldRef = StringUtil.getShortName(expressionText);
|
||||
|
||||
final JavaFxIdReferenceBase idReferenceBase = new JavaFxIdReferenceBase(xmlAttributeValue, fileIds, newId);
|
||||
final PsiReferenceBase idReferenceBase;
|
||||
|
||||
final PsiClass controllerClass = JavaFxPsiUtil.getControllerClass(element.getContainingFile());
|
||||
final PsiField controllerField = controllerClass != null ? controllerClass.findFieldByName(newId, false) : null;
|
||||
if (controllerField == null) {
|
||||
idReferenceBase = new JavaFxIdReferenceBase(xmlAttributeValue, fileIds, newId);
|
||||
} else {
|
||||
idReferenceBase = new JavaFxFieldIdReferenceProvider.JavaFxControllerFieldRef(xmlAttributeValue, controllerField, controllerClass);
|
||||
}
|
||||
|
||||
final TextRange range = idReferenceBase.getRangeInElement();
|
||||
final int startOffset = range.getStartOffset() + 2;
|
||||
final int endOffset = startOffset + newId.length();
|
||||
|
||||
+31
-18
@@ -36,27 +36,40 @@ class JavaFxFieldIdReferenceProvider extends JavaFxControllerBasedReferenceProvi
|
||||
final XmlAttributeValue xmlAttributeValue,
|
||||
ProcessingContext context) {
|
||||
final PsiField field = aClass.findFieldByName(xmlAttributeValue.getValue(), false);
|
||||
return new PsiReference[] {new PsiReferenceBase<XmlAttributeValue>(xmlAttributeValue) {
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiElement resolve() {
|
||||
return field != null ? field : xmlAttributeValue;
|
||||
}
|
||||
return new PsiReference[] {new JavaFxControllerFieldRef(xmlAttributeValue, field, aClass)};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Object[] getVariants() {
|
||||
final List<Object> fieldsToSuggest = new ArrayList<Object>();
|
||||
final PsiField[] fields = aClass.getFields();
|
||||
for (PsiField psiField : fields) {
|
||||
if (!psiField.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
if (JavaFxPsiUtil.isVisibleInFxml(psiField)) {
|
||||
fieldsToSuggest.add(psiField);
|
||||
}
|
||||
public static class JavaFxControllerFieldRef extends PsiReferenceBase<XmlAttributeValue> {
|
||||
private final XmlAttributeValue myXmlAttributeValue;
|
||||
private final PsiField myField;
|
||||
private final PsiClass myAClass;
|
||||
|
||||
public JavaFxControllerFieldRef(XmlAttributeValue xmlAttributeValue, PsiField field, PsiClass aClass) {
|
||||
super(xmlAttributeValue);
|
||||
myXmlAttributeValue = xmlAttributeValue;
|
||||
myField = field;
|
||||
myAClass = aClass;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiElement resolve() {
|
||||
return myField != null ? myField : myXmlAttributeValue;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Object[] getVariants() {
|
||||
final List<Object> fieldsToSuggest = new ArrayList<Object>();
|
||||
final PsiField[] fields = myAClass.getFields();
|
||||
for (PsiField psiField : fields) {
|
||||
if (!psiField.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
if (JavaFxPsiUtil.isVisibleInFxml(psiField)) {
|
||||
fieldsToSuggest.add(psiField);
|
||||
}
|
||||
}
|
||||
return ArrayUtil.toObjectArray(fieldsToSuggest);
|
||||
}
|
||||
}};
|
||||
return ArrayUtil.toObjectArray(fieldsToSuggest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
class ExampleController {
|
||||
public PasswordField passwordField;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<AnchorPane id="AnchorPane" xmlns:fx="http://javafx.com/fxml"
|
||||
fx:controller="ExampleController">
|
||||
<PasswordField fx:id="pass<caret>wordField"/>
|
||||
<Label text="${passwordField.text}" GridPane.rowIndex="3"/>
|
||||
|
||||
</AnchorPane>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<AnchorPane id="AnchorPane" xmlns:fx="http://javafx.com/fxml"
|
||||
fx:controller="ExampleController">
|
||||
<PasswordField fx:id="newFieldName"/>
|
||||
<Label text="${newFieldName.text}" GridPane.rowIndex="3"/>
|
||||
|
||||
</AnchorPane>
|
||||
@@ -17,15 +17,12 @@ package org.jetbrains.plugins.javaFX.fxml;
|
||||
|
||||
import com.intellij.codeInsight.TargetElementUtilBase;
|
||||
import com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.openapi.application.PluginPathManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.refactoring.rename.RenameProcessor;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class JavaFXRenameTest extends DaemonAnalyzerTestCase {
|
||||
@Override
|
||||
protected void setUpModule() {
|
||||
@@ -37,6 +34,10 @@ public class JavaFXRenameTest extends DaemonAnalyzerTestCase {
|
||||
doTest(getTestName(false) + "1");
|
||||
}
|
||||
|
||||
public void testControllerField() throws Exception {
|
||||
doTest("newFieldName");
|
||||
}
|
||||
|
||||
private void doTest(final String newName) throws Exception {
|
||||
configureByFiles(null, getTestName(true) + ".fxml", getTestName(false) + ".java");
|
||||
PsiElement element = TargetElementUtilBase
|
||||
|
||||
Reference in New Issue
Block a user