mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
javafx: check isAssignable for tags
This commit is contained in:
+6
-1
@@ -845,6 +845,11 @@ public class GenericsHighlightUtil {
|
||||
public static PsiType getCollectionItemType(@NotNull PsiExpression expression) {
|
||||
final PsiType type = expression.getType();
|
||||
if (type == null) return null;
|
||||
return getCollectionItemType(type, expression.getResolveScope());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiType getCollectionItemType(final PsiType type, final GlobalSearchScope scope) {
|
||||
if (type instanceof PsiArrayType) {
|
||||
return ((PsiArrayType)type).getComponentType();
|
||||
}
|
||||
@@ -857,7 +862,7 @@ public class GenericsHighlightUtil {
|
||||
PsiSubstitutor substitutor = resolveResult.getSubstitutor();
|
||||
JavaPsiFacade facade = JavaPsiFacade.getInstance(manager.getProject());
|
||||
if (qName != null) {
|
||||
PsiClass myClass = facade.findClass(qName, expression.getResolveScope());
|
||||
PsiClass myClass = facade.findClass(qName, scope);
|
||||
if (myClass != null && myClass != aClass) {
|
||||
//different JDKs
|
||||
PsiTypeParameter thisTypeParameter = getIterableTypeParameter(facade, myClass);
|
||||
|
||||
+32
-1
@@ -1,11 +1,15 @@
|
||||
package org.jetbrains.plugins.javaFX.fxml;
|
||||
|
||||
import com.intellij.codeInsight.daemon.Validator;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.GenericsHighlightUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.xml.XmlAttributeImpl;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.xml.XmlAttribute;
|
||||
import com.intellij.psi.xml.XmlFile;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
@@ -168,11 +172,38 @@ public class JavaFxClassBackedElementDescriptor implements XmlElementDescriptor,
|
||||
|
||||
@Override
|
||||
public void validate(@NotNull XmlTag context, @NotNull ValidationHost host) {
|
||||
if (context.getParentTag() != null) {
|
||||
final XmlTag parentTag = context.getParentTag();
|
||||
if (parentTag != null) {
|
||||
final XmlAttribute attribute = context.getAttribute(FxmlConstants.FX_CONTROLLER);
|
||||
if (attribute != null) {
|
||||
host.addMessage(((XmlAttributeImpl)attribute).getNameElement(), "fx:controller can only be applied to root element", ValidationHost.ErrorType.ERROR); //todo add delete/move to upper tag fix
|
||||
}
|
||||
validateTagAccordingToFieldType(context, parentTag, host);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateTagAccordingToFieldType(XmlTag context, XmlTag parentTag, ValidationHost host) {
|
||||
if (myPsiClass != null && myPsiClass.isValid()) {
|
||||
final XmlElementDescriptor descriptor = parentTag.getDescriptor();
|
||||
if (descriptor instanceof JavaFxListPropertyElementDescriptor) {
|
||||
final PsiElement declaration = descriptor.getDeclaration();
|
||||
if (declaration instanceof PsiField) {
|
||||
final PsiType type = ((PsiField)declaration).getType();
|
||||
final PsiType collectionItemType = GenericsHighlightUtil.getCollectionItemType(type, myPsiClass.getResolveScope());
|
||||
if (collectionItemType != null && PsiPrimitiveType.getUnboxedType(collectionItemType) == null) {
|
||||
final PsiClass baseClass = PsiUtil.resolveClassInType(collectionItemType);
|
||||
if (baseClass != null) {
|
||||
final String qualifiedName = baseClass.getQualifiedName();
|
||||
if (qualifiedName != null && !Comparing.strEqual(qualifiedName, CommonClassNames.JAVA_LANG_STRING)) {
|
||||
if (!InheritanceUtil.isInheritor(myPsiClass, qualifiedName)) {
|
||||
host.addMessage(context.getNavigationElement(),
|
||||
"Unable to coerce " + HighlightUtil.formatClass(myPsiClass)+ " to " + qualifiedName, ValidationHost.ErrorType.ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import java.util.*?>
|
||||
<?import java.net.*?>
|
||||
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" unknownAttr="val" xmlns:fx="http://javafx.com/fxml">
|
||||
<children>
|
||||
<<error descr="Unable to coerce java.util.ArrayList to javafx.scene.Node">ArrayList</error>/>
|
||||
</children>
|
||||
<stylesheets>
|
||||
<URL value="test.css" />
|
||||
</stylesheets>
|
||||
</AnchorPane>
|
||||
Binary file not shown.
@@ -28,6 +28,10 @@ public class JavaFXHighlightingTest extends DaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testCoercedTypes() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
doTest(false, false, getTestName(true) + ".fxml");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user