javafx: fx:root only on top level check

This commit is contained in:
anna
2013-03-28 10:32:11 +01:00
parent 3afaa40f79
commit 90f21bcdac
4 changed files with 31 additions and 11 deletions

View File

@@ -299,6 +299,10 @@ public class JavaFXHighlightingTest extends AbstractJavaFXTestCase {
doTest();
}
public void testRootTagOnDifferentLevels() throws Exception {
doTest();
}
public void testIncludedForm() throws Exception {
myFixture.addFileToProject("sample.fxml", "<?import javafx.scene.layout.GridPane?>\n" +
"<fx:root type=\"javafx.scene.layout.GridPane\" xmlns:fx=\"http://javafx.com/fxml\"/>\n");

View File

@@ -46,7 +46,7 @@ public class FxmlConstants {
@NonNls public static final String STYLESHEETS = "stylesheets";
public static final List<String> FX_DEFAULT_PROPERTIES = Arrays.asList(FX_ID, FX_CONTROLLER, VALUE, FX_VALUE, FX_FACTORY, FX_CONSTANT);
public static final List<String> FX_DEFAULT_ELEMENTS = Arrays.asList(FX_INCLUDE, FX_REFERENCE, FX_COPY, FX_DEFINE, FX_SCRIPT);
public static final List<String> FX_DEFAULT_ELEMENTS = Arrays.asList(FX_INCLUDE, FX_REFERENCE, FX_COPY, FX_DEFINE, FX_SCRIPT, FX_ROOT);
public static final String FX_ELEMENT_SOURCE = "source";

View File

@@ -77,7 +77,7 @@ public class JavaFxDefaultPropertyElementDescriptor implements XmlElementDescrip
public XmlElementDescriptor getElementDescriptor(XmlTag childTag, XmlTag contextTag) {
final String name = childTag.getName();
if (FxmlConstants.FX_DEFINE.equals(myName)) {
if (FxmlConstants.FX_INCLUDE.equals(name) || FxmlConstants.FX_REFERENCE.equals(name)) {
if (FxmlConstants.FX_DEFAULT_ELEMENTS.contains(name)) {
return new JavaFxDefaultPropertyElementDescriptor(name, childTag);
}
return new JavaFxClassBackedElementDescriptor(name, childTag);
@@ -281,15 +281,21 @@ public class JavaFxDefaultPropertyElementDescriptor implements XmlElementDescrip
@Override
public void validate(@NotNull XmlTag context, @NotNull ValidationHost host) {
final XmlTag referencedTag = getReferencedTag(context);
if (referencedTag != null) {
final XmlElementDescriptor descriptor = referencedTag.getDescriptor();
if (descriptor != null) {
final PsiElement declaration = descriptor.getDeclaration();
if (declaration instanceof PsiClass) {
final String canCoerceError = JavaFxPsiUtil.isClassAcceptable(context.getParentTag(), (PsiClass)declaration);
if (canCoerceError != null) {
host.addMessage(context.getNavigationElement(), canCoerceError, ValidationHost.ErrorType.ERROR);
if (FxmlConstants.FX_ROOT.equals(context.getName())) {
if (context.getParentTag() != null) {
host.addMessage(context.getNavigationElement(), "<fx:root> is valid only as the root node of an FXML document", ValidationHost.ERROR);
}
} else {
final XmlTag referencedTag = getReferencedTag(context);
if (referencedTag != null) {
final XmlElementDescriptor descriptor = referencedTag.getDescriptor();
if (descriptor != null) {
final PsiElement declaration = descriptor.getDeclaration();
if (declaration instanceof PsiClass) {
final String canCoerceError = JavaFxPsiUtil.isClassAcceptable(context.getParentTag(), (PsiClass)declaration);
if (canCoerceError != null) {
host.addMessage(context.getNavigationElement(), canCoerceError, ValidationHost.ErrorType.ERROR);
}
}
}
}

View File

@@ -0,0 +1,10 @@
<?import javafx.scene.layout.*?>
<GridPane xmlns:fx="http://javafx.com/fxml">
<<error descr="<fx:root> is valid only as the root node of an FXML document">fx:root</error> type="javafx.scene.layout.AnchorPane"/>
<fx:define>
<<error descr="<fx:root> is valid only as the root node of an FXML document">fx:root</error> type="javafx.scene.layout.AnchorPane"/>
</fx:define>
<GridPane>
<<error descr="<fx:root> is valid only as the root node of an FXML document">fx:root</error> type="javafx.scene.layout.AnchorPane"/>
</GridPane>
</GridPane>