mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 21:11:28 +07:00
javafx: fx:root only on top level check
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user