mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Javafx: Support resolution of resource keys (IDEA-100213)
This commit is contained in:
+3
-1
@@ -490,7 +490,9 @@ public class JavaFXHighlightingTest extends AbstractJavaFXTestCase {
|
||||
myFixture.testHighlighting(true, true, true, superclass + ".java");
|
||||
}
|
||||
|
||||
public void testResourceIdInFxAttribute() throws Exception {
|
||||
public void testResourceKeyInAttribute() throws Exception {
|
||||
myFixture.addFileToProject("messages.properties", "string.key=My text\n" +
|
||||
"double.key=123.456\n");
|
||||
doTest();
|
||||
}
|
||||
|
||||
|
||||
+7
@@ -219,6 +219,13 @@ public class JavaFXRenameTest extends AbstractJavaFXRenameTest {
|
||||
doTestProperty("newName", "model.Data", false);
|
||||
}
|
||||
|
||||
public void testResourceProperty() {
|
||||
myFixture.configureByFiles(getTestName(true) + ".fxml", getTestName(true) + ".properties");
|
||||
myFixture.renameElementAtCaret("new.name");
|
||||
myFixture.checkResultByFile(getTestName(true) + "_after.fxml");
|
||||
myFixture.checkResultByFile(getTestName(true) + ".properties", getTestName(true) + "_after.properties", false);
|
||||
}
|
||||
|
||||
public void doTestProperty(String name, boolean isBoolean) throws Exception {
|
||||
doTestProperty(name, null, isBoolean);
|
||||
}
|
||||
|
||||
+15
@@ -330,6 +330,21 @@ public class JavaFxCompletionTest extends LightFixtureCompletionTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testResourceProperty() {
|
||||
myFixture.addFileToProject("messages.properties", "double.key=123.456\n" +
|
||||
"string.key=Some text\n");
|
||||
configureAndComplete();
|
||||
assertSameElements(myFixture.getLookupElementStrings(), "double.key", "string.key");
|
||||
}
|
||||
|
||||
|
||||
public void testResourcePropertyManyFiles() {
|
||||
myFixture.addFileToProject("messages1.properties", "double.key=123.456\n");
|
||||
myFixture.addFileToProject("messages2.properties", "string.key=Some text\n");
|
||||
configureAndComplete();
|
||||
assertSameElements(myFixture.getLookupElementStrings(), "double.key", "string.key");
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
doTest(null);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
<orderEntry type="module" module-name="common-javaFX-plugin" />
|
||||
<orderEntry type="module" module-name="manifest" />
|
||||
<orderEntry type="module" module-name="idea-ui" />
|
||||
<orderEntry type="module" module-name="properties" />
|
||||
<orderEntry type="library" name="SceneBuilderKit" level="project" />
|
||||
<orderEntry type="module" module-name="testFramework-java" scope="TEST" />
|
||||
</component>
|
||||
|
||||
+6
@@ -114,6 +114,12 @@ public class FxmlReferencesContributor extends PsiReferenceContributor {
|
||||
.and(attributeValueInFxml),
|
||||
new JavaFxLocationReferenceProvider(false, "css"));
|
||||
|
||||
registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withValue(string().startsWith("%"))
|
||||
.withParent(XmlPatterns.xmlAttribute().andNot(
|
||||
XmlPatterns.xmlAttribute().withName(
|
||||
FxmlConstants.FX_VALUE, FxmlConstants.FX_CONSTANT, FxmlConstants.FX_FACTORY)))
|
||||
.and(attributeValueInFxml), new JavaFxResourcePropertyReferenceProvider());
|
||||
|
||||
registrar.registerReferenceProvider(PlatformPatterns.psiElement(XmlProcessingInstruction.class).inVirtualFile(virtualFile().withExtension(JavaFxFileTypeFactory.FXML_EXTENSION)),
|
||||
new ImportReferenceProvider());
|
||||
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package org.jetbrains.plugins.javaFX.fxml.refs;
|
||||
|
||||
import com.intellij.lang.properties.references.PropertyReference;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.PsiReferenceProvider;
|
||||
import com.intellij.psi.xml.XmlAttributeValue;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Pavel.Dolgov
|
||||
*/
|
||||
class JavaFxResourcePropertyReferenceProvider extends PsiReferenceProvider {
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
|
||||
if (element instanceof XmlAttributeValue) {
|
||||
final String value = ((XmlAttributeValue)element).getValue();
|
||||
if (value != null && value.startsWith("%") && value.length() > 1) {
|
||||
return new PsiReference[]{new JavaFxResourcePropertyReference(value.substring(1), (XmlAttributeValue)element)};
|
||||
}
|
||||
}
|
||||
return PsiReference.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
static class JavaFxResourcePropertyReference extends PropertyReference {
|
||||
public JavaFxResourcePropertyReference(@NotNull String key, @NotNull XmlAttributeValue element) {
|
||||
super(key, element, null, false, new TextRange(2, key.length() + 2)); // "%key" - shift by 2 because the quote also counts
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<VBox xmlns:fx="http://javafx.com/fxml">
|
||||
<Label text="%<caret>"/>
|
||||
</VBox>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<VBox xmlns:fx="http://javafx.com/fxml">
|
||||
<Label text="%<caret>"/>
|
||||
</VBox>
|
||||
+1
-1
@@ -8,5 +8,5 @@
|
||||
<Double fx:id="d" fx:value=<error descr="Invalid value: unable to coerce to java.lang.Double">"%double.key"</error>/>
|
||||
<String fx:id="s" fx:value="%string.key"/>
|
||||
</fx:define>
|
||||
<Label text="%string.key" maxWidth="%double.key"/>
|
||||
<Label text="%string.key" maxWidth="%double.key" maxHeight="%<error descr="Cannot resolve property key">missing.key</error>"/>
|
||||
</VBox>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<VBox xmlns:fx="http://javafx.com/fxml">
|
||||
<Label text="%st<caret>ring.key"/>
|
||||
</VBox>
|
||||
@@ -0,0 +1 @@
|
||||
string.key=My text
|
||||
@@ -0,0 +1,5 @@
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<VBox xmlns:fx="http://javafx.com/fxml">
|
||||
<Label text="%new.name"/>
|
||||
</VBox>
|
||||
@@ -0,0 +1 @@
|
||||
new.name=My text
|
||||
Reference in New Issue
Block a user