mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
javafx: variables resolve (IDEA-100318)
This commit is contained in:
+3
@@ -74,6 +74,9 @@ public class FxmlReferencesContributor extends PsiReferenceContributor {
|
||||
registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withValue(string().startsWith("@")).and(attributeValueInFxml),
|
||||
new JavaFxLocationReferenceProvider());
|
||||
|
||||
registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withValue(string().startsWith("$")).and(attributeValueInFxml),
|
||||
new JavaFxComponentIdReferenceProvider());
|
||||
|
||||
registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName("url")).and(attributeValueInFxml),
|
||||
new JavaFxLocationReferenceProvider());
|
||||
|
||||
|
||||
+17
-4
@@ -15,7 +15,9 @@
|
||||
*/
|
||||
package org.jetbrains.plugins.javaFX.fxml.refs;
|
||||
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.xml.XmlAttribute;
|
||||
import com.intellij.psi.xml.XmlAttributeValue;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
@@ -37,20 +39,31 @@ class JavaFxComponentIdReferenceProvider extends PsiReferenceProvider {
|
||||
public PsiReference[] getReferencesByElement(@NotNull PsiElement element,
|
||||
@NotNull ProcessingContext context) {
|
||||
final XmlAttributeValue xmlAttributeValue = (XmlAttributeValue)element;
|
||||
final String referencesId = xmlAttributeValue.getValue();
|
||||
final XmlTag currentTag = PsiTreeUtil.getParentOfType(xmlAttributeValue, XmlTag.class);
|
||||
final String value = xmlAttributeValue.getValue();
|
||||
final boolean startsWithDollar = value.startsWith("$");
|
||||
final String referencesId = startsWithDollar ? value.substring(1) : value;
|
||||
final Map<String, XmlAttributeValue> fileIds = new HashMap<String, XmlAttributeValue>();
|
||||
xmlAttributeValue.getContainingFile().accept(new XmlRecursiveElementVisitor() {
|
||||
@Override
|
||||
public void visitXmlTag(XmlTag tag) {
|
||||
super.visitXmlTag(tag);
|
||||
final XmlAttribute attribute = tag.getAttribute(FxmlConstants.FX_ID);
|
||||
if (attribute != null) {
|
||||
fileIds.put(attribute.getValue(), attribute.getValueElement());
|
||||
if (currentTag != tag) {
|
||||
final XmlAttribute attribute = tag.getAttribute(FxmlConstants.FX_ID);
|
||||
if (attribute != null) {
|
||||
fileIds.put(attribute.getValue(), attribute.getValueElement());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return new PsiReference[]{new PsiReferenceBase<XmlAttributeValue>(xmlAttributeValue) {
|
||||
@Override
|
||||
public TextRange getRangeInElement() {
|
||||
final TextRange rangeInElement = super.getRangeInElement();
|
||||
return startsWithDollar ? new TextRange(rangeInElement.getStartOffset() + 1, rangeInElement.getEndOffset()) : rangeInElement;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiElement resolve() {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<?import javafx.scene.layout.GridPane?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Tooltip?>
|
||||
<GridPane fx:controller="sample.Controller" xmlns:fx="http://javafx.com/fxml">
|
||||
<fx:define>
|
||||
<Tooltip text="tooltip" fx:id="t"/>
|
||||
</fx:define>
|
||||
|
||||
<Button onAction="#sayHello" text="Hello" fx:id="b1" tooltip="$<caret>" />
|
||||
</GridPane>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?import javafx.scene.layout.GridPane?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Tooltip?>
|
||||
<GridPane fx:controller="sample.Controller" xmlns:fx="http://javafx.com/fxml">
|
||||
<fx:define>
|
||||
<Tooltip text="tooltip" fx:id="t"/>
|
||||
</fx:define>
|
||||
|
||||
<Button onAction="#sayHello" text="Hello" fx:id="b1" tooltip="$t" />
|
||||
</GridPane>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?import javafx.scene.layout.GridPane?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Tooltip?>
|
||||
<GridPane xmlns:fx="http://javafx.com/fxml">
|
||||
<fx:define>
|
||||
<Tooltip text="tooltip" fx:id="mytt"/>
|
||||
</fx:define>
|
||||
|
||||
<Button text="Hello" fx:id="b1" tooltip="$mytt" />
|
||||
</GridPane>
|
||||
@@ -122,6 +122,10 @@ public class JavaFXHighlightingTest extends DaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testVariables() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDefineAttributes() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@@ -89,6 +89,10 @@ public class JavaFxCompletionTest extends CompletionTestCase {
|
||||
doTest("observableArrayList");
|
||||
}
|
||||
|
||||
public void testVariableCompletion() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
doTest(null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user