Javafx: In quickfix that creates FXML event handler don't specify unresolved genetic parameters in argument type. Tests added (IDEA-153589)

This commit is contained in:
Pavel Dolgov
2016-03-31 18:02:08 +03:00
parent 83f8b9a0a6
commit 7959524d1b
8 changed files with 55 additions and 5 deletions
@@ -68,6 +68,14 @@ public class JavaFxEventHandlerInspectionTest extends AbstractJavaFXTestCase {
doQuickfixTest("Create method 'void onSort(SortEvent)'");
}
public void testQuickfixNoField() throws Exception {
doQuickfixTest("Create method 'void onSort(SortEvent)'");
}
public void testQuickfixNoFieldNested() throws Exception {
doQuickfixTest("Create method 'void onColumnEditStart(CellEditEvent)'");
}
public void testQuickfixSuper() throws Exception {
doQuickfixTest("Create method 'void click(MouseEvent)'");
}
@@ -556,12 +556,14 @@ public class JavaFxPsiUtil {
return canCoerceImpl(targetType, fromClass, context, messageConsumer);
}
/**
* Similar to {@link GenericsUtil#getVariableTypeByExpressionType(PsiType)} and {@link TypeConversionUtil#erasure(PsiType)}
*/
@Nullable
private static PsiType eraseFreeTypeParameters(@Nullable PsiType psiType, PsiMember member) {
private static PsiType eraseFreeTypeParameters(@Nullable PsiType psiType, @NotNull PsiMember member) {
final PsiClass containingClass = member.getContainingClass();
return eraseFreeTypeParameters(psiType, containingClass);
}
@Nullable
private static PsiType eraseFreeTypeParameters(@Nullable PsiType psiType, @Nullable PsiClass containingClass) {
if (containingClass == null) return null;
return JavaPsiFacade.getElementFactory(containingClass.getProject()).createRawSubstitutor(containingClass).substitute(psiType);
}
@@ -975,7 +977,9 @@ public class JavaFxPsiUtil {
final PsiType handlerType = tagClassSubstitutor != null ?
tagClassSubstitutor.substitute(eventHandlerPropertyType) : eventHandlerPropertyType;
return substituteEventType(handlerType, xmlAttribute.getProject());
final PsiClassType eventType = substituteEventType(handlerType, xmlAttribute.getProject());
final PsiType erasedType = eraseFreeTypeParameters(eventType, tagClass);
return erasedType instanceof PsiClassType ? (PsiClassType)erasedType : null;
}
}
}
@@ -0,0 +1,2 @@
public class QuickfixNoField {
}
@@ -0,0 +1,4 @@
import javafx.scene.control.TableColumn.CellEditEvent;
public class QuickfixNoFieldNested {
}
@@ -0,0 +1,7 @@
import javafx.scene.control.TableColumn.CellEditEvent;
public class QuickfixNoFieldNested {
public void onColumnEditStart(CellEditEvent cellEditEvent) {
}
}
@@ -0,0 +1,8 @@
import javafx.scene.control.SortEvent;
import javafx.scene.control.TableView;
public class QuickfixNoField {
public void onSort(SortEvent<TableView> tableViewSortEvent) {
}
}
@@ -0,0 +1,6 @@
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.VBox?>
<VBox xmlns:fx="http://javafx.com/fxml" fx:controller="QuickfixNoField">
<TableView onSort="#on<caret>Sort">
</TableView>
</VBox>
@@ -0,0 +1,11 @@
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.VBox?>
<VBox xmlns:fx="http://javafx.com/fxml" fx:controller="QuickfixNoFieldNested">
<TableView>
<columns>
<TableColumn onEditStart="#<caret>onColumnEditStart">
</TableColumn>
</columns>
</TableView>
</VBox>