mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
javafx: controller navigation with <fx:root> available (IDEA-102036)
This commit is contained in:
+4
@@ -127,6 +127,10 @@ public class JavaFXHighlightingTest extends DaemonAnalyzerTestCase {
|
||||
doDoTest(false, false);
|
||||
}
|
||||
|
||||
public void testInjectedController() throws Exception {
|
||||
doTestNavigation("MyController", "label", "injected/" + getTestName(true) + ".fxml", "injected/FooVBox.java", "injected/MyController.java");
|
||||
}
|
||||
|
||||
private void doTestNavigation(String resultClassName, String resultFieldName) throws Exception {
|
||||
doTestNavigation(resultClassName, resultFieldName, ArrayUtil.EMPTY_STRING_ARRAY);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.plugins.javaFX.fxml;
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.xml.XMLLanguage;
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Key;
|
||||
@@ -211,19 +212,34 @@ public class JavaFxPsiUtil {
|
||||
final Project project = containingFile.getProject();
|
||||
if (rootTag != null) {
|
||||
XmlAttribute attribute = rootTag.getAttribute(FxmlConstants.FX_CONTROLLER);
|
||||
if (attribute == null && FxmlConstants.FX_ROOT.equals(rootTag.getName())) {
|
||||
attribute = rootTag.getAttribute(FxmlConstants.TYPE);
|
||||
}
|
||||
if (attribute != null) {
|
||||
final String attributeValue = attribute.getValue();
|
||||
if (!StringUtil.isEmptyOrSpaces(attributeValue)) {
|
||||
return JavaPsiFacade.getInstance(project).findClass(attributeValue, containingFile.getResolveScope());
|
||||
final PsiClass controllerClass = findControllerClass(containingFile, project, attribute);
|
||||
if (controllerClass != null) {
|
||||
return controllerClass;
|
||||
}
|
||||
}
|
||||
}
|
||||
CachedValuesManager manager = CachedValuesManager.getManager(containingFile.getProject());
|
||||
return manager.getCachedValue(containingFile, INJECTED_CONTROLLER,
|
||||
new JavaFxControllerCachedValueProvider(containingFile.getProject(), containingFile), true);
|
||||
final CachedValuesManager manager = CachedValuesManager.getManager(containingFile.getProject());
|
||||
final PsiClass injectedControllerClass = manager.getCachedValue(containingFile, INJECTED_CONTROLLER,
|
||||
new JavaFxControllerCachedValueProvider(containingFile.getProject(), containingFile), true);
|
||||
if (injectedControllerClass != null) {
|
||||
return injectedControllerClass;
|
||||
}
|
||||
|
||||
if (rootTag != null && FxmlConstants.FX_ROOT.equals(rootTag.getName())) {
|
||||
final XmlAttribute rootTypeAttr = rootTag.getAttribute(FxmlConstants.TYPE);
|
||||
if (rootTypeAttr != null) {
|
||||
return findControllerClass(containingFile, project, rootTypeAttr);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static PsiClass findControllerClass(PsiFile containingFile, Project project, XmlAttribute attribute) {
|
||||
final String attributeValue = attribute.getValue();
|
||||
if (!StringUtil.isEmptyOrSpaces(attributeValue)) {
|
||||
return JavaPsiFacade.getInstance(project).findClass(attributeValue, containingFile.getResolveScope());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -426,7 +442,9 @@ public class JavaFxPsiUtil {
|
||||
return methodCallExpression.resolveMethod() == injectControllerMethods[0];
|
||||
}
|
||||
};
|
||||
ReferencesSearch.search(myContainingFile).forEach(new Processor<PsiReference>() {
|
||||
final GlobalSearchScope globalSearchScope = GlobalSearchScope
|
||||
.notScope(GlobalSearchScope.getScopeRestrictedByFileTypes(myContainingFile.getResolveScope(), StdFileTypes.XML));
|
||||
ReferencesSearch.search(myContainingFile, globalSearchScope).forEach(new Processor<PsiReference>() {
|
||||
@Override
|
||||
public boolean process(PsiReference reference) {
|
||||
final PsiElement element = reference.getElement();
|
||||
@@ -436,7 +454,7 @@ public class JavaFxPsiUtil {
|
||||
final PsiType type = expression.getType();
|
||||
if (type != null && type.equalsToText(JavaFxCommonClassNames.JAVAFX_FXML_FXMLLOADER)) {
|
||||
final PsiElement parent = expression.getParent();
|
||||
if (parent instanceof PsiVariable) {
|
||||
if (parent instanceof PsiLocalVariable) {
|
||||
ReferencesSearch.search(parent).forEach(processor);
|
||||
final PsiClass controller = processor.getInjectedController();
|
||||
if (controller != null) {
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.layout.VBox;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class FooVBox extends VBox{
|
||||
private void loaderCreation() {
|
||||
MyController controller = new MyController();
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("injectedController.fxml"));
|
||||
fxmlLoader.setRoot(this);
|
||||
fxmlLoader.setController(controller);
|
||||
|
||||
try {
|
||||
fxmlLoader.load();
|
||||
} catch (IOException exception) {
|
||||
throw new RuntimeException(exception);
|
||||
}
|
||||
}
|
||||
public FooVBox() {
|
||||
loaderCreation();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import javafx.scene.control.Label;
|
||||
|
||||
public class MyController {
|
||||
public Label label;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<fx:root type="javafx.scene.layout.VBox" xmlns:fx="http://javafx.com/fxml">
|
||||
<Label fx:id="la<caret>bel" />
|
||||
</fx:root>
|
||||
Reference in New Issue
Block a user