javafx: retrieve factory method return type to check for coercing

This commit is contained in:
anna
2013-07-15 13:41:54 +02:00
parent 5feaa9f7af
commit 478c282e65
4 changed files with 35 additions and 2 deletions
@@ -44,6 +44,10 @@ public class JavaFxCoercingTest extends AbstractJavaFXTestCase {
doTest();
}
public void testFactoryCoercing() throws Exception {
doTest();
}
private void doTest() throws Exception {
myFixture.testHighlighting(false, false, false, getTestName(true) + ".fxml");
}
@@ -11,6 +11,7 @@ import com.intellij.psi.impl.source.xml.XmlAttributeImpl;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.*;
import com.intellij.psi.xml.XmlAttribute;
import com.intellij.psi.xml.XmlAttributeValue;
import com.intellij.psi.xml.XmlTag;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Function;
@@ -377,6 +378,20 @@ public class JavaFxClassBackedElementDescriptor implements XmlElementDescriptor,
if (constField != null) {
aClass = PsiUtil.resolveClassInType(constField.getType());
}
} else {
final XmlAttribute factoryAttr = context.getAttribute(FxmlConstants.FX_FACTORY);
if (factoryAttr != null) {
final XmlAttributeValue valueElement = factoryAttr.getValueElement();
if (valueElement != null) {
final PsiReference reference = valueElement.getReference();
final PsiElement staticFactoryMethod = reference != null ? reference.resolve() : null;
if (staticFactoryMethod instanceof PsiMethod &&
((PsiMethod)staticFactoryMethod).getParameterList().getParametersCount() == 0 &&
((PsiMethod)staticFactoryMethod).hasModifierProperty(PsiModifier.STATIC)) {
aClass = PsiUtil.resolveClassInType(((PsiMethod)staticFactoryMethod).getReturnType());
}
}
}
}
final String canCoerceError = JavaFxPsiUtil.isClassAcceptable(parentTag, aClass);
if (canCoerceError != null) {
@@ -0,0 +1,14 @@
<?import javafx.collections.FXCollections?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.layout.GridPane?>
<?import java.lang.String?>
<GridPane xmlns:fx="http://javafx.com/fxml">
<ComboBox>
<items>
<FXCollections fx:factory="observableArrayList">
<String fx:value="1" />
<String fx:value="2" />
</FXCollections>
</items>
</ComboBox>
</GridPane>
@@ -10,9 +10,9 @@
<String fx:value="C"/>
</FXCollections>
</fx:define>
<<error descr="Unable to coerce javafx.collections.FXCollections to javafx.scene.Node">FXCollections</error> fx:factory="observableArrayList">
<<error descr="Unable to coerce javafx.collections.ObservableList to javafx.scene.Node">FXCollections</error> fx:factory="observableArrayList">
<String fx:value="A"/>
<String fx:value="B"/>
<String fx:value="C"/>
</<error descr="Unable to coerce javafx.collections.FXCollections to javafx.scene.Node">FXCollections</error>>
</<error descr="Unable to coerce javafx.collections.ObservableList to javafx.scene.Node">FXCollections</error>>
</fx:root>