mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
javafx: refs to stylesheets (IDEA-99984)
This commit is contained in:
+2
@@ -85,6 +85,8 @@ public class FxmlReferencesContributor extends PsiReferenceContributor {
|
||||
|
||||
registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName("url")).and(attributeValueInFxml),
|
||||
new JavaFxLocationReferenceProvider());
|
||||
registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName("stylesheets")).and(attributeValueInFxml),
|
||||
new JavaFxLocationReferenceProvider(true));
|
||||
|
||||
registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlTokenType.XML_TAG_CHARACTERS).inFile(inFxmlElementPattern()), new ImportReferenceProvider());
|
||||
|
||||
|
||||
+36
-5
@@ -23,25 +23,56 @@ import com.intellij.psi.xml.XmlAttributeValue;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
*/
|
||||
class JavaFxLocationReferenceProvider extends PsiReferenceProvider {
|
||||
private boolean mySupportCommaInValue = false;
|
||||
|
||||
JavaFxLocationReferenceProvider() {
|
||||
}
|
||||
|
||||
JavaFxLocationReferenceProvider(boolean supportCommaInValue) {
|
||||
mySupportCommaInValue = supportCommaInValue;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiReference[] getReferencesByElement(@NotNull final PsiElement element,
|
||||
@NotNull ProcessingContext context) {
|
||||
final String value = ((XmlAttributeValue)element).getValue();
|
||||
final FileReferenceSet set;
|
||||
if (value.startsWith("@")) {
|
||||
set = new FileReferenceSet(value.substring(1), element, 2, null, true);
|
||||
return new FileReferenceSet(value.substring(1), element, 2, null, true).getAllReferences();
|
||||
}
|
||||
else {
|
||||
set = new FileReferenceSet(value, element, 1, null, true);
|
||||
if (value.startsWith("/")) {
|
||||
set.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, FileReferenceSet.ABSOLUTE_TOP_LEVEL);
|
||||
if (mySupportCommaInValue && value.contains(",")) {
|
||||
int startIdx = 0;
|
||||
int endIdx = 0;
|
||||
List<PsiReference> refs = new ArrayList<PsiReference>();
|
||||
while (true) {
|
||||
endIdx = value.indexOf(",", startIdx);
|
||||
Collections.addAll(refs, collectRefs(element, endIdx >= 0 ? value.substring(startIdx, endIdx) : value.substring(startIdx), startIdx + 1));
|
||||
startIdx = endIdx + 1;
|
||||
if (endIdx < 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return refs.toArray(new PsiReference[refs.size()]);
|
||||
} else {
|
||||
return collectRefs(element, value, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static PsiReference[] collectRefs(PsiElement element, String value, final int startInElement) {
|
||||
final FileReferenceSet set = new FileReferenceSet(value, element, startInElement, null, true);
|
||||
if (value.startsWith("/")) {
|
||||
set.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, FileReferenceSet.ABSOLUTE_TOP_LEVEL);
|
||||
}
|
||||
return set.getAllReferences();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<AnchorPane id="AnchorPane" xmlns:fx="http://javafx.com/fxml"
|
||||
stylesheets="<caret>" />
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<AnchorPane id="AnchorPane" xmlns:fx="http://javafx.com/fxml"
|
||||
stylesheets="mystyle.css" />
|
||||
@@ -1,6 +1,6 @@
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import java.lang.String?>
|
||||
<AnchorPane id="AnchorPane" xmlns:fx="http://javafx.com/fxml" stylesheets="mystyle.css" <error descr="Property 'backgroundFills' is read-only">backgroundFills=""</error>>
|
||||
<AnchorPane id="AnchorPane" xmlns:fx="http://javafx.com/fxml" stylesheets="<error descr="Cannot resolve file 'mystyle.css'">mystyle.css</error>" <error descr="Property 'backgroundFills' is read-only">backgroundFills=""</error>>
|
||||
<stylesheets>
|
||||
<String fx:value="mystyle.css"/>
|
||||
</stylesheets>
|
||||
|
||||
@@ -97,6 +97,10 @@ public class JavaFxCompletionTest extends CompletionTestCase {
|
||||
doTest("text");
|
||||
}
|
||||
|
||||
public void testStylesheets() throws Exception {
|
||||
doTest("mystyle.css", "mystyle.css");
|
||||
}
|
||||
|
||||
public void testReadOnly() throws Exception {
|
||||
configureByFile(getTestName(true) + ".fxml");
|
||||
assertTrue(myItems.length > 0);
|
||||
@@ -117,7 +121,17 @@ public class JavaFxCompletionTest extends CompletionTestCase {
|
||||
}
|
||||
|
||||
private void doTest(final String selection) throws Exception {
|
||||
configureByFile(getTestName(true) + ".fxml");
|
||||
doTest(selection, null);
|
||||
}
|
||||
|
||||
private void doTest(final String selection, String additionalPath) throws Exception {
|
||||
final String mainFxml = getTestName(true) + ".fxml";
|
||||
if (additionalPath != null) {
|
||||
configureByFiles(null, mainFxml, additionalPath);
|
||||
complete();
|
||||
} else {
|
||||
configureByFile(mainFxml);
|
||||
}
|
||||
assertTrue(myItems.length > 0);
|
||||
LookupElement selectionElement = null;
|
||||
for (LookupElement item : myItems) {
|
||||
|
||||
Reference in New Issue
Block a user