javafx: default tags inside list (IDEA-100089)

This commit is contained in:
Anna Kozlova
2013-01-30 18:03:15 +04:00
parent 7bff02a4e4
commit f82db143ed
4 changed files with 31 additions and 5 deletions
@@ -85,7 +85,7 @@ public class JavaFxClassBackedElementDescriptor implements XmlElementDescriptor,
final PsiMethod getter = findPropertyGetter(propertyName, myPsiClass);
if (getter != null) {
final PsiType returnType = getter.getReturnType();
children.addAll(JavaFxPropertyElementDescriptor.collectDescriptorsByCollection(returnType, myPsiClass.getResolveScope()));
JavaFxPropertyElementDescriptor.collectDescriptorsByCollection(returnType, myPsiClass.getResolveScope(), children);
}
}
}
@@ -19,6 +19,7 @@ import com.intellij.xml.XmlElementsGroup;
import com.intellij.xml.XmlNSDescriptor;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.javaFX.fxml.FxmlConstants;
import java.util.ArrayList;
import java.util.List;
@@ -53,14 +54,19 @@ public class JavaFxPropertyElementDescriptor implements XmlElementDescriptor {
final PsiElement declaration = getDeclaration();
if (declaration instanceof PsiField) {
final PsiType psiType = ((PsiField)declaration).getType();
final List<XmlElementDescriptor> descriptors = collectDescriptorsByCollection(psiType, declaration.getResolveScope());
final ArrayList<XmlElementDescriptor> descriptors = new ArrayList<XmlElementDescriptor>();
collectDescriptorsByCollection(psiType, declaration.getResolveScope(), descriptors);
for (String name : FxmlConstants.FX_DEFAULT_ELEMENTS) {
descriptors.add(new JavaFxDefaultPropertyElementDescriptor(name, null));
}
if (!descriptors.isEmpty()) return descriptors.toArray(new XmlElementDescriptor[descriptors.size()]);
}
return XmlElementDescriptor.EMPTY_ARRAY;
}
public static List<XmlElementDescriptor> collectDescriptorsByCollection(PsiType psiType, GlobalSearchScope resolveScope) {
final List<XmlElementDescriptor> descriptors = new ArrayList<XmlElementDescriptor>();
public static void collectDescriptorsByCollection(PsiType psiType,
GlobalSearchScope resolveScope,
final List<XmlElementDescriptor> descriptors) {
final PsiType collectionItemType = GenericsHighlightUtil.getCollectionItemType(psiType, resolveScope);
if (collectionItemType != null) {
final PsiClass aClass = PsiUtil.resolveClassInType(collectionItemType);
@@ -74,13 +80,15 @@ public class JavaFxPropertyElementDescriptor implements XmlElementDescriptor {
});
}
}
return descriptors;
}
@Nullable
@Override
public XmlElementDescriptor getElementDescriptor(XmlTag childTag, XmlTag contextTag) {
final String name = childTag.getName();
if (FxmlConstants.FX_DEFAULT_ELEMENTS.contains(name)) {
return new JavaFxDefaultPropertyElementDescriptor(name, childTag);
}
if (JavaFxClassBackedElementDescriptor.isClassTag(name)) {
return new JavaFxClassBackedElementDescriptor(name, childTag);
}
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.control.Label?>
<GridPane fx:id="gp"
xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
<children>
<fx:script>
</fx:script>
<fx:<error descr="Cannot resolve symbol 'fx:id'">id</error>/>
<Label fx:id="label" GridPane.rowIndex="1" <error descr="Attribute fx:script is not allowed here">fx:script</error>=""/>
</children>
</GridPane>
@@ -46,6 +46,10 @@ public class JavaFXHighlightingTest extends DaemonAnalyzerTestCase {
doTest();
}
public void testDefaultTagInList() throws Exception {
doTest();
}
public void testUnresolvedImport() throws Exception {
doTest();
}