mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-06 10:07:41 +07:00
Javafx: In FXML completion for event handler take care of superclasses' generic parameters (IDEA-154115)
This commit is contained in:
+6
-1
@@ -218,7 +218,12 @@ public class JavaFxCompletionTest extends LightFixtureCompletionTestCase {
|
||||
}
|
||||
|
||||
public void testEventHandlerMethod() throws Exception {
|
||||
configureAndComplete("EventHandlerMethod.java", "EventHandlerMethodSuper.java");
|
||||
configureAndComplete(getTestName(false) + ".java", getTestName(false) + "Super.java");
|
||||
assertSameElements(myFixture.getLookupElementStrings(), "onMyKeyTyped", "onSuperKeyTyped");
|
||||
}
|
||||
|
||||
public void testEventHandlerMethodTypeParam() throws Exception {
|
||||
configureAndComplete(getTestName(false) + ".java", getTestName(false) + "Super.java");
|
||||
assertSameElements(myFixture.getLookupElementStrings(), "onMyKeyTyped", "onSuperKeyTyped");
|
||||
}
|
||||
|
||||
|
||||
+9
-3
@@ -21,6 +21,7 @@ import com.intellij.codeInsight.quickfix.UnresolvedReferenceQuickFixProvider;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.psi.xml.XmlAttribute;
|
||||
import com.intellij.psi.xml.XmlAttributeValue;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
@@ -58,20 +59,25 @@ public class JavaFxEventHandlerReference extends PsiReferenceBase<XmlAttributeVa
|
||||
if (myController == null) return EMPTY_ARRAY;
|
||||
final List<PsiMethod> availableHandlers = new ArrayList<PsiMethod>();
|
||||
for (PsiMethod psiMethod : myController.getAllMethods()) {
|
||||
if (isHandlerMethodSignature(psiMethod) && JavaFxPsiUtil.isVisibleInFxml(psiMethod)) {
|
||||
if (isHandlerMethodSignature(psiMethod, myController) && JavaFxPsiUtil.isVisibleInFxml(psiMethod)) {
|
||||
availableHandlers.add(psiMethod);
|
||||
}
|
||||
}
|
||||
return availableHandlers.isEmpty() ? EMPTY_ARRAY : ArrayUtil.toObjectArray(availableHandlers);
|
||||
}
|
||||
|
||||
public static boolean isHandlerMethodSignature(PsiMethod psiMethod) {
|
||||
public static boolean isHandlerMethodSignature(@NotNull PsiMethod psiMethod, @NotNull PsiClass controllerClass) {
|
||||
final PsiClass containingClass = psiMethod.getContainingClass();
|
||||
if (containingClass != null && CommonClassNames.JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName())) return false;
|
||||
if (!psiMethod.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
final PsiParameter[] parameters = psiMethod.getParameterList().getParameters();
|
||||
if (parameters.length == 1) {
|
||||
final PsiType parameterType = parameters[0].getType();
|
||||
PsiType parameterType = parameters[0].getType();
|
||||
if (containingClass != null && !controllerClass.isEquivalentTo(containingClass)) {
|
||||
final PsiSubstitutor substitutor =
|
||||
TypeConversionUtil.getSuperClassSubstitutor(containingClass, controllerClass, PsiSubstitutor.EMPTY);
|
||||
parameterType = substitutor.substitute(parameterType);
|
||||
}
|
||||
if (InheritanceUtil.isInheritor(parameterType, JavaFxCommonNames.JAVAFX_EVENT)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
+2
-2
@@ -51,8 +51,8 @@ class JavaFxEventHandlerReferenceProvider extends JavaFxControllerBasedReference
|
||||
final PsiMethod[] methods = controllerClass.findMethodsByName(eventHandlerName, true);
|
||||
|
||||
final PsiReference[] references = Arrays.stream(methods)
|
||||
.filter(JavaFxEventHandlerReference::isHandlerMethodSignature)
|
||||
.map(handlerMethod -> new JavaFxEventHandlerReference(xmlAttributeValue, handlerMethod, controllerClass))
|
||||
.filter(psiMethod -> JavaFxEventHandlerReference.isHandlerMethodSignature(psiMethod, controllerClass))
|
||||
.map(psiMethod -> new JavaFxEventHandlerReference(xmlAttributeValue, psiMethod, controllerClass))
|
||||
.toArray(PsiReference.ARRAY_FACTORY::create);
|
||||
|
||||
if (references.length == 1) {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
|
||||
public class EventHandlerMethodTypeParam extends EventHandlerMethodTypeParamSuper<KeyEvent> {
|
||||
@FXML
|
||||
private void onMyKeyTyped(KeyEvent event) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
|
||||
public class EventHandlerMethodTypeParamSuper<T> {
|
||||
@FXML
|
||||
private void onSuperKeyTyped(T event) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<VBox xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/null" fx:controller="EventHandlerMethodTypeParam">
|
||||
<TextField onKeyTyped="#<caret>"/>
|
||||
</VBox>
|
||||
Reference in New Issue
Block a user