javafx: complete default properties tag as well as its subtags if any

(cherry picked from commit 4e27e34)
This commit is contained in:
anna
2013-03-22 21:36:42 +01:00
parent 2bb6d246e0
commit f9a4b7ee47
3 changed files with 44 additions and 9 deletions
@@ -129,6 +129,18 @@ public class JavaFxCompletionTest extends LightFixtureCompletionTestCase {
doTest("top");
}
public void testPrimitiveSubtags() throws Exception {
myFixture.configureByFiles(getTestName(true) + ".fxml");
complete();
assertDoesntContain(myFixture.getLookupElementStrings(), "geomBoundsInvalid");
}
public void testDefaultPropertyWrappedField() throws Exception {
myFixture.configureByFiles(getTestName(true) + ".fxml");
complete();
assertContainsElements(myFixture.getLookupElementStrings(), "image", "Image");
}
public void testIncludedRootAttributes() throws Exception {
myFixture.addFileToProject("foo.fxml", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<?import javafx.scene.layout.*?>\n" +
@@ -69,6 +69,11 @@ public class JavaFxClassBackedElementDescriptor implements XmlElementDescriptor,
}
});
final JavaFxPropertyElementDescriptor defaultPropertyDescriptor = getDefaultPropertyDescriptor();
if (defaultPropertyDescriptor != null) {
Collections.addAll(children, defaultPropertyDescriptor.getElementsDescriptors(context));
}
collectStaticElementDescriptors(context, children);
final PsiType returnType = JavaFxPsiUtil.getDefaultPropertyExpectedType(myPsiClass);
@@ -88,6 +93,21 @@ public class JavaFxClassBackedElementDescriptor implements XmlElementDescriptor,
return XmlElementDescriptor.EMPTY_ARRAY;
}
private JavaFxPropertyElementDescriptor getDefaultPropertyDescriptor() {
final PsiAnnotation defaultProperty = AnnotationUtil
.findAnnotationInHierarchy(myPsiClass, Collections.singleton(JavaFxCommonClassNames.JAVAFX_BEANS_DEFAULT_PROPERTY));
if (defaultProperty != null) {
final PsiAnnotationMemberValue defaultPropertyAttributeValue = defaultProperty.findAttributeValue("value");
if (defaultPropertyAttributeValue instanceof PsiLiteralExpression) {
final Object value = ((PsiLiteralExpression)defaultPropertyAttributeValue).getValue();
if (value instanceof String) {
return new JavaFxPropertyElementDescriptor(myPsiClass, (String)value, false);
}
}
}
return null;
}
static void collectStaticAttributesDescriptors(@Nullable XmlTag context, List<XmlAttributeDescriptor> simpleAttrs) {
if (context == null) return;
collectParentStaticProperties(context.getParentTag(), simpleAttrs, new Function<PsiMethod, XmlAttributeDescriptor>() {
@@ -159,18 +179,17 @@ public class JavaFxClassBackedElementDescriptor implements XmlElementDescriptor,
return elementDescriptor;
}
} else {
final PsiAnnotation defaultProperty = AnnotationUtil
.findAnnotationInHierarchy(myPsiClass, Collections.singleton(JavaFxCommonClassNames.JAVAFX_BEANS_DEFAULT_PROPERTY));
if (defaultProperty != null) {
final PsiAnnotationMemberValue defaultPropertyAttributeValue = defaultProperty.findAttributeValue("value");
if (defaultPropertyAttributeValue instanceof PsiLiteralExpression) {
final Object value = ((PsiLiteralExpression)defaultPropertyAttributeValue).getValue();
if (value instanceof String && ((String)value).equalsIgnoreCase(name) && myPsiClass.findFieldByName(name, true) == null) {
elementDescriptor = null;
final JavaFxPropertyElementDescriptor defaultPropertyDescriptor = getDefaultPropertyDescriptor();
if (defaultPropertyDescriptor != null) {
final String defaultPropertyName = defaultPropertyDescriptor.getName();
if (StringUtil.equalsIgnoreCase(defaultPropertyName, name) && !StringUtil.equals(defaultPropertyName, name)) {
final XmlElementDescriptor childDescriptor = defaultPropertyDescriptor.getElementDescriptor(childTag, contextTag);
if (childDescriptor != null) {
return childDescriptor;
}
}
}
if (elementDescriptor != null && elementDescriptor.getDeclaration() != null) {
if (elementDescriptor.getDeclaration() != null) {
return elementDescriptor;
}
}
@@ -0,0 +1,4 @@
<?import javafx.scene.image.*?>
<ImageView id="lock" pickOnBounds="true">
<<caret>
</ImageView>