Javafx: Don't show private methods as unresolved, show them as not accessible from FXML (IDEA-153671)

This commit is contained in:
Pavel Dolgov
2016-04-01 17:28:43 +03:00
parent 4f40cd3a92
commit 0f7e621918
5 changed files with 20 additions and 4 deletions
@@ -366,6 +366,10 @@ public class JavaFXHighlightingTest extends AbstractJavaFXTestCase {
doTest();
}
public void testPrivateControllerMethod() throws Exception {
doTest(getTestName(false) + ".java");
}
public void testPropertyTagCompatibleClass() throws Exception {
doTest();
}
@@ -58,16 +58,16 @@ public class JavaFxEventHandlerReference extends PsiReferenceBase<XmlAttributeVa
if (myController == null) return EMPTY_ARRAY;
final List<PsiMethod> availableHandlers = new ArrayList<PsiMethod>();
for (PsiMethod psiMethod : myController.getMethods()) {
if (isHandlerMethod(psiMethod)) {
if (isHandlerMethod(psiMethod, true)) {
availableHandlers.add(psiMethod);
}
}
return availableHandlers.isEmpty() ? EMPTY_ARRAY : ArrayUtil.toObjectArray(availableHandlers);
}
public static boolean isHandlerMethod(PsiMethod psiMethod) {
public static boolean isHandlerMethod(PsiMethod psiMethod, boolean isVisibleInFxml) {
if (!psiMethod.hasModifierProperty(PsiModifier.STATIC) &&
JavaFxPsiUtil.isVisibleInFxml(psiMethod)) {
(!isVisibleInFxml || JavaFxPsiUtil.isVisibleInFxml(psiMethod))) {
final PsiParameter[] parameters = psiMethod.getParameterList().getParameters();
if (parameters.length == 1) {
final PsiType parameterType = parameters[0].getType();
@@ -51,7 +51,7 @@ class JavaFxEventHandlerReferenceProvider extends JavaFxControllerBasedReference
final PsiMethod[] methods = controllerClass.findMethodsByName(eventHandlerName, true);
final PsiReference[] references = Arrays.stream(methods)
.filter(JavaFxEventHandlerReference::isHandlerMethod)
.filter(psiMethod -> JavaFxEventHandlerReference.isHandlerMethod(psiMethod, false))
.map(handlerMethod -> new JavaFxEventHandlerReference(xmlAttributeValue, handlerMethod, controllerClass))
.toArray(PsiReference.ARRAY_FACTORY::create);
@@ -0,0 +1,7 @@
import javafx.scene.control.SortEvent;
import javafx.scene.control.TableView;
public class PrivateControllerMethod {
private void onSort(SortEvent<TableView> tableViewSortEvent) {
}
}
@@ -0,0 +1,5 @@
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.VBox?>
<VBox xmlns:fx="http://javafx.com/fxml" fx:controller="PrivateControllerMethod">
<TableView onSort=<error descr="'onSort(SortEvent<TableView>)' should be public or annotated with @FXML">"#onSort"</error>/>
</VBox>