javafx: completion/import inside object property element

(cherry picked from commit 730836594f9e5594af0fcf42f5168d27e33c1970)
This commit is contained in:
anna
2013-03-21 10:40:34 +01:00
parent b99c21d6cf
commit 711cf3de78
10 changed files with 59 additions and 6 deletions
@@ -41,6 +41,13 @@ public class JavaFXImportTest extends DaemonAnalyzerTestCase {
checkResultByFile(getTestName(true) + "_after.fxml");
}
public void testInsets() throws Exception {
configureByFiles(null, getTestName(true) + ".fxml", getTestName(false) + ".java");
final List<HighlightInfo> infos = doHighlighting();
findAndInvokeIntentionAction(infos, "Import Class", getEditor(), getFile());
checkResultByFile(getTestName(true) + "_after.fxml");
}
private void doTest() throws Exception {
configureByFiles(null, getTestName(true) + ".fxml");
final List<HighlightInfo> infos = doHighlighting();
@@ -121,6 +121,10 @@ public class JavaFxCompletionTest extends CompletionTestCase {
doTest("children");
}
public void testClassInsideObjectProperty() throws Exception {
doTest("Insets");
}
public void testReadOnly() throws Exception {
configureByFile(getTestName(true) + ".fxml");
assertTrue(myItems.length > 0);
@@ -356,13 +356,14 @@ public class JavaFxPsiUtil {
@Nullable
public static PsiType getPropertyType(final PsiType type, final Project project) {
final PsiClass psiClass = PsiUtil.resolveClassInType(type);
final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(type);
final PsiClass psiClass = resolveResult.getElement();
if (psiClass != null) {
final PsiClass propertyClass = JavaPsiFacade.getInstance(project).findClass(JavaFxCommonClassNames.JAVAFX_BEANS_PROPERTY,
GlobalSearchScope.allScope(project));
if (propertyClass != null) {
final PsiSubstitutor substitutor =
TypeConversionUtil.getClassSubstitutor(propertyClass, psiClass, PsiSubstitutor.EMPTY);
TypeConversionUtil.getClassSubstitutor(propertyClass, psiClass, resolveResult.getSubstitutor());
if (substitutor != null) {
return substitutor.substitute(propertyClass.getTypeParameters()[0]);
}
@@ -463,7 +464,10 @@ public class JavaFxPsiUtil {
}
private static String canCoerce(PsiClass aClass, PsiType type) {
final PsiType collectionItemType = GenericsHighlightUtil.getCollectionItemType(type, aClass.getResolveScope());
PsiType collectionItemType = GenericsHighlightUtil.getCollectionItemType(type, aClass.getResolveScope());
if (collectionItemType == null && InheritanceUtil.isInheritor(type, JavaFxCommonClassNames.JAVAFX_BEANS_PROPERTY)) {
collectionItemType = getPropertyType(type, aClass.getProject());
}
if (collectionItemType != null && PsiPrimitiveType.getUnboxedType(collectionItemType) == null) {
final PsiClass baseClass = PsiUtil.resolveClassInType(collectionItemType);
if (baseClass != null) {
@@ -71,7 +71,7 @@ public class JavaFxClassBackedElementDescriptor implements XmlElementDescriptor,
final PsiType returnType = JavaFxPsiUtil.getDefaultPropertyExpectedType(myPsiClass);
if (returnType != null) {
JavaFxPropertyElementDescriptor.collectDescriptorsByCollection(returnType, myPsiClass.getResolveScope(), children);
JavaFxPropertyElementDescriptor.collectDescriptorsByCollection(returnType, myPsiClass.getResolveScope(), children, myPsiClass.getProject());
}
for (String name : FxmlConstants.FX_DEFAULT_ELEMENTS) {
@@ -1,6 +1,7 @@
package org.jetbrains.plugins.javaFX.fxml.descriptors;
import com.intellij.codeInsight.daemon.impl.analysis.GenericsHighlightUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
@@ -19,6 +20,7 @@ import com.intellij.xml.impl.schema.AnyXmlAttributeDescriptor;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.javaFX.fxml.FxmlConstants;
import org.jetbrains.plugins.javaFX.fxml.JavaFxCommonClassNames;
import org.jetbrains.plugins.javaFX.fxml.JavaFxPsiUtil;
import java.util.ArrayList;
@@ -55,7 +57,7 @@ public class JavaFxPropertyElementDescriptor implements XmlElementDescriptor {
if (declaration instanceof PsiField) {
final PsiType psiType = ((PsiField)declaration).getType();
final ArrayList<XmlElementDescriptor> descriptors = new ArrayList<XmlElementDescriptor>();
collectDescriptorsByCollection(psiType, declaration.getResolveScope(), descriptors);
collectDescriptorsByCollection(psiType, declaration.getResolveScope(), descriptors, declaration.getProject());
for (String name : FxmlConstants.FX_DEFAULT_ELEMENTS) {
descriptors.add(new JavaFxDefaultPropertyElementDescriptor(name, null));
}
@@ -66,7 +68,8 @@ public class JavaFxPropertyElementDescriptor implements XmlElementDescriptor {
public static void collectDescriptorsByCollection(PsiType psiType,
GlobalSearchScope resolveScope,
final List<XmlElementDescriptor> descriptors) {
final List<XmlElementDescriptor> descriptors,
final Project project) {
final PsiType collectionItemType = GenericsHighlightUtil.getCollectionItemType(psiType, resolveScope);
if (collectionItemType != null) {
final PsiClass aClass = PsiUtil.resolveClassInType(collectionItemType);
@@ -79,6 +82,12 @@ public class JavaFxPropertyElementDescriptor implements XmlElementDescriptor {
}
});
}
} else if (InheritanceUtil.isInheritor(psiType, JavaFxCommonClassNames.JAVAFX_BEANS_PROPERTY)) {
final PsiType propertyType = JavaFxPsiUtil.getPropertyType(psiType, project);
final PsiClass aClass = PsiUtil.resolveClassInType(propertyType);
if (aClass != null) {
descriptors.add(new JavaFxClassBackedElementDescriptor(aClass.getName(), aClass));
}
}
}
@@ -0,0 +1,7 @@
<?import javafx.scene.layout.GridPane?>
<GridPane xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
<padding>
<<caret>
</padding>
</GridPane>
@@ -0,0 +1,8 @@
<?import javafx.scene.layout.GridPane?>
<?import javafx.geometry.Insets?>
<GridPane xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
<padding>
<Insets
</padding>
</GridPane>
@@ -0,0 +1 @@
public class Insets {}
@@ -0,0 +1,6 @@
<?import javafx.scene.layout.GridPane?>
<GridPane xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
<padding>
<In<caret>sets/>
</padding>
</GridPane>
@@ -0,0 +1,7 @@
<?import javafx.scene.layout.GridPane?>
<?import javafx.geometry.Insets?>
<GridPane xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
<padding>
<Insets/>
</padding>
</GridPane>