mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
javafx: make tag types depend on hierarchy position (IDEA-101617)
This commit is contained in:
+5
@@ -119,6 +119,11 @@ public class JavaFXHighlightingTest extends DaemonAnalyzerTestCase {
|
||||
doTestNavigation("CustomVBox", "tf", "custom/" + getTestName(true) + ".fxml", "custom/CustomVBox.java");
|
||||
}
|
||||
|
||||
public void testCustomComponent_Fields() throws Exception {
|
||||
configureByFiles(null, "custom/" + getTestName(true) + ".fxml", "custom/_CustomVBox.java");
|
||||
doDoTest(false, false);
|
||||
}
|
||||
|
||||
private void doTestNavigation(String resultClassName, String resultFieldName) throws Exception {
|
||||
doTestNavigation(resultClassName, resultFieldName, ArrayUtil.EMPTY_STRING_ARRAY);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ package org.jetbrains.plugins.javaFX.fxml;
|
||||
|
||||
import com.intellij.codeInsight.daemon.Validator;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.xml.*;
|
||||
import com.intellij.psi.xml.XmlDocument;
|
||||
import com.intellij.psi.xml.XmlFile;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.xml.XmlElementDescriptor;
|
||||
import com.intellij.xml.XmlNSDescriptor;
|
||||
@@ -25,19 +27,15 @@ public class JavaFXNSDescriptor implements XmlNSDescriptor, Validator<XmlDocumen
|
||||
|
||||
if (tag.getName().equals(FxmlConstants.FX_ROOT)) {
|
||||
return new JavaFxDefaultPropertyElementDescriptor(name, tag);
|
||||
} else if (JavaFxPsiUtil.isClassTag(name)) {
|
||||
return new JavaFxClassBackedElementDescriptor(name, tag);
|
||||
}
|
||||
else {
|
||||
final XmlTag parentTag = tag.getParentTag();
|
||||
if (parentTag != null) {
|
||||
final XmlElementDescriptor descriptor = parentTag.getDescriptor();
|
||||
if (descriptor != null) {
|
||||
return descriptor.getElementDescriptor(tag, parentTag);
|
||||
}
|
||||
final XmlTag parentTag = tag.getParentTag();
|
||||
if (parentTag != null) {
|
||||
final XmlElementDescriptor descriptor = parentTag.getDescriptor();
|
||||
if (descriptor != null) {
|
||||
return descriptor.getElementDescriptor(tag, parentTag);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return new JavaFxClassBackedElementDescriptor(name, tag);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -98,7 +98,7 @@ public class JavaFxPsiUtil {
|
||||
|
||||
PsiFile file = tag.getContainingFile();
|
||||
for (String anImport : imports) {
|
||||
if (StringUtil.endsWith(anImport, "." + name)) {
|
||||
if (StringUtil.getShortName(anImport).equals(name)) {
|
||||
psiClass = psiFacade.findClass(anImport, file.getResolveScope());
|
||||
} else if (StringUtil.endsWith(anImport, ".*")) {
|
||||
psiClass = psiFacade.findClass(StringUtil.trimEnd(anImport, "*") + name, file.getResolveScope());
|
||||
@@ -159,15 +159,6 @@ public class JavaFxPsiUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isClassTag(String name) {
|
||||
final String shortName = StringUtil.getShortName(name);
|
||||
final boolean capitalized = StringUtil.isCapitalized(name);
|
||||
if (name.equals(shortName)) {
|
||||
return capitalized;
|
||||
}
|
||||
return !capitalized;
|
||||
}
|
||||
|
||||
public static PsiMethod findPropertySetter(String attributeName, XmlTag context) {
|
||||
final String packageName = StringUtil.getPackageName(attributeName);
|
||||
if (context != null && !StringUtil.isEmptyOrSpaces(packageName)) {
|
||||
|
||||
+5
-2
@@ -19,8 +19,10 @@ import com.intellij.codeInspection.*;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
import com.intellij.xml.XmlElementDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.javaFX.fxml.JavaFxPsiUtil;
|
||||
import org.jetbrains.plugins.javaFX.fxml.descriptors.JavaFxPropertyElementDescriptor;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
@@ -35,11 +37,12 @@ public class JavaFxDefaultTagInspection extends XmlSuppressableInspectionTool{
|
||||
@Override
|
||||
public void visitXmlTag(XmlTag tag) {
|
||||
super.visitXmlTag(tag);
|
||||
final String tagName = tag.getName();
|
||||
if (!JavaFxPsiUtil.isClassTag(tagName)) {
|
||||
final XmlElementDescriptor descriptor = tag.getDescriptor();
|
||||
if (descriptor instanceof JavaFxPropertyElementDescriptor) {
|
||||
final XmlTag parentTag = tag.getParentTag();
|
||||
if (parentTag != null) {
|
||||
final String propertyName = JavaFxPsiUtil.getDefaultPropertyName(JavaFxPsiUtil.getTagClass(parentTag));
|
||||
final String tagName = tag.getName();
|
||||
if (Comparing.strEqual(tagName, propertyName)) {
|
||||
holder.registerProblem(tag.getFirstChild(),
|
||||
"Default property tag could be removed",
|
||||
|
||||
+17
-13
@@ -136,23 +136,27 @@ public class JavaFxClassBackedElementDescriptor implements XmlElementDescriptor,
|
||||
@Override
|
||||
public XmlElementDescriptor getElementDescriptor(XmlTag childTag, XmlTag contextTag) {
|
||||
final String name = childTag.getName();
|
||||
if (JavaFxPsiUtil.isClassTag(name)) {
|
||||
return new JavaFxClassBackedElementDescriptor(name, childTag);
|
||||
if (FxmlConstants.FX_DEFAULT_ELEMENTS.contains(name)) {
|
||||
return new JavaFxDefaultPropertyElementDescriptor(name, childTag);
|
||||
}
|
||||
else {
|
||||
final String shortName = StringUtil.getShortName(name);
|
||||
if (!name.equals(shortName)) { //static property
|
||||
final PsiMethod propertySetter = JavaFxPsiUtil.findPropertySetter(name, childTag);
|
||||
if (propertySetter != null) {
|
||||
return new JavaFxPropertyElementDescriptor(propertySetter.getContainingClass(), shortName, true);
|
||||
}
|
||||
final String shortName = StringUtil.getShortName(name);
|
||||
if (!name.equals(shortName)) { //static property
|
||||
final PsiMethod propertySetter = JavaFxPsiUtil.findPropertySetter(name, childTag);
|
||||
if (propertySetter != null) {
|
||||
return new JavaFxPropertyElementDescriptor(propertySetter.getContainingClass(), shortName, true);
|
||||
}
|
||||
|
||||
final Project project = childTag.getProject();
|
||||
if (JavaPsiFacade.getInstance(project).findClass(name, GlobalSearchScope.allScope(project)) == null) {
|
||||
return null;
|
||||
}
|
||||
if (FxmlConstants.FX_DEFAULT_ELEMENTS.contains(name)) {
|
||||
return new JavaFxDefaultPropertyElementDescriptor(name, childTag);
|
||||
}
|
||||
return myPsiClass != null ? new JavaFxPropertyElementDescriptor(myPsiClass, name, false) : null;
|
||||
}
|
||||
|
||||
final JavaFxPropertyElementDescriptor elementDescriptor = new JavaFxPropertyElementDescriptor(myPsiClass, name, false);
|
||||
if (myPsiClass != null && elementDescriptor.getDeclaration() != null) {
|
||||
return elementDescriptor;
|
||||
}
|
||||
return new JavaFxClassBackedElementDescriptor(name, childTag);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+10
-4
@@ -66,11 +66,17 @@ public class JavaFxDefaultPropertyElementDescriptor implements XmlElementDescrip
|
||||
@Nullable
|
||||
@Override
|
||||
public XmlElementDescriptor getElementDescriptor(XmlTag childTag, XmlTag contextTag) {
|
||||
if (myName.equals(FxmlConstants.FX_DEFINE) || myName.equals(FxmlConstants.FX_ROOT)) {
|
||||
final String name = childTag.getName();
|
||||
if (JavaFxPsiUtil.isClassTag(name)) {
|
||||
return new JavaFxClassBackedElementDescriptor(name, childTag);
|
||||
final String name = childTag.getName();
|
||||
if (myName.equals(FxmlConstants.FX_DEFINE)) {
|
||||
return new JavaFxClassBackedElementDescriptor(name, childTag);
|
||||
}
|
||||
|
||||
if (myName.equals(FxmlConstants.FX_ROOT)) {
|
||||
final JavaFxClassBackedElementDescriptor tagDescriptor = getRootTagDescriptor(contextTag);
|
||||
if (tagDescriptor != null) {
|
||||
return tagDescriptor.getElementDescriptor(childTag, contextTag);
|
||||
}
|
||||
return new JavaFxClassBackedElementDescriptor(name, childTag);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
+1
-7
@@ -89,13 +89,7 @@ public class JavaFxPropertyElementDescriptor implements XmlElementDescriptor {
|
||||
if (FxmlConstants.FX_DEFAULT_ELEMENTS.contains(name)) {
|
||||
return new JavaFxDefaultPropertyElementDescriptor(name, childTag);
|
||||
}
|
||||
if (JavaFxPsiUtil.isClassTag(name)) {
|
||||
return new JavaFxClassBackedElementDescriptor(name, childTag);
|
||||
}
|
||||
else if (myPsiClass != null) {
|
||||
return new JavaFxPropertyElementDescriptor(myPsiClass, name, name.indexOf('.') > 0);
|
||||
}
|
||||
return null;
|
||||
return new JavaFxClassBackedElementDescriptor(name, childTag);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.VBox;
|
||||
|
||||
|
||||
public class _CustomVBox extends VBox {
|
||||
@FXML
|
||||
private TextField tf;
|
||||
@FXML
|
||||
private Label lab1;
|
||||
@FXML
|
||||
void myMethod(){
|
||||
lab1.setText(tf.getText());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import _CustomVBox?>
|
||||
<GridPane xmlns:fx="http://javafx.com/fxml" >
|
||||
<_CustomVBox/>
|
||||
</GridPane>
|
||||
Reference in New Issue
Block a user