mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
javafx: use FileReferenceSet for location, source refs
This commit is contained in:
+6
@@ -45,6 +45,12 @@ public class FxmlReferencesContributor extends PsiReferenceContributor {
|
||||
.and(attributeValueInFxml),
|
||||
new JavaFxFieldIdReferenceProvider());
|
||||
|
||||
registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.FX_ELEMENT_SOURCE)
|
||||
.withParent(XmlPatterns.xmlTag()
|
||||
.withName(FxmlConstants.FX_INCLUDE)))
|
||||
.and(attributeValueInFxml),
|
||||
new JavaFxSourceReferenceProvider());
|
||||
|
||||
registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withValue(string().startsWith("#"))
|
||||
.and(attributeValueInFxml),
|
||||
new JavaFxEventHandlerReferenceProvider());
|
||||
|
||||
+5
-38
@@ -15,19 +15,13 @@
|
||||
*/
|
||||
package org.jetbrains.plugins.javaFX.fxml.refs;
|
||||
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.PsiReferenceProvider;
|
||||
import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet;
|
||||
import com.intellij.psi.xml.XmlAttributeValue;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
@@ -39,34 +33,7 @@ class JavaFxLocationReferenceProvider extends PsiReferenceProvider {
|
||||
@NotNull ProcessingContext context) {
|
||||
final String value = ((XmlAttributeValue)element).getValue();
|
||||
final String relativePathToResource = value.substring(1);
|
||||
|
||||
final VirtualFile virtualFile = element.getContainingFile().getOriginalFile().getVirtualFile();
|
||||
if (virtualFile != null) {
|
||||
final VirtualFile parent = virtualFile.getParent();
|
||||
final VirtualFile resourceFile = parent != null ? parent.findFileByRelativePath(relativePathToResource) : null;
|
||||
final PsiReferenceBase.Immediate<XmlAttributeValue> ref =
|
||||
new PsiReferenceBase.Immediate<XmlAttributeValue>((XmlAttributeValue)element, resourceFile != null ? element.getManager().findFile(resourceFile) : null) {
|
||||
@NotNull
|
||||
@Override
|
||||
public Object[] getVariants() {
|
||||
if (parent != null) { //todo multilevel completion, filter by resources
|
||||
final PsiDirectory psiDirectory = element.getManager().findDirectory(parent);
|
||||
if (psiDirectory != null) {
|
||||
final PsiElement[] children = psiDirectory.getChildren();
|
||||
final List<String> paths = new ArrayList<String>();
|
||||
for (PsiElement child : children) {
|
||||
if (child instanceof PsiFileSystemItem) {
|
||||
paths.add("@" + ((PsiFileSystemItem)child).getName());
|
||||
}
|
||||
}
|
||||
return ArrayUtil.toStringArray(paths);
|
||||
}
|
||||
}
|
||||
return super.getVariants();
|
||||
}
|
||||
};
|
||||
return new PsiReference[]{ref};
|
||||
}
|
||||
return PsiReference.EMPTY_ARRAY;
|
||||
final FileReferenceSet set = new FileReferenceSet(relativePathToResource, element, 2, null, true);
|
||||
return set.getAllReferences();
|
||||
}
|
||||
}
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.plugins.javaFX.fxml.refs;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.PsiReferenceProvider;
|
||||
import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet;
|
||||
import com.intellij.psi.xml.XmlAttributeValue;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
*/
|
||||
class JavaFxSourceReferenceProvider extends PsiReferenceProvider {
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiReference[] getReferencesByElement(@NotNull final PsiElement element,
|
||||
@NotNull ProcessingContext context) {
|
||||
final FileReferenceSet set = new FileReferenceSet(((XmlAttributeValue)element).getValue(), element, 1, null, true);
|
||||
return set.getAllReferences();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Button/>
|
||||
@@ -12,7 +12,7 @@
|
||||
</ImageView>
|
||||
<ImageView>
|
||||
<image>
|
||||
<Image url="<error descr="Cannot resolve symbol '@unknownIcon.png'">@unknownIcon.png</error>"/>
|
||||
<Image url="@<error descr="Cannot resolve file 'unknownIcon.png'">unknownIcon.png</error>"/>
|
||||
</image>
|
||||
</ImageView>
|
||||
</children>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
|
||||
<AnchorPane xmlns:fx="http://javafx.com/fxml">
|
||||
<children>
|
||||
<fx:include source="btn.fxml"/>
|
||||
<fx:include source="<error descr="Cannot resolve file 'btn1.fxml'">btn1.fxml</error>"/>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
@@ -6,5 +6,5 @@
|
||||
<fx:reference source="myImage"/>
|
||||
</image>
|
||||
</ImageView>
|
||||
<fx:include source="my_button.fxml"/>
|
||||
<fx:include source="<error descr="Cannot resolve file 'my_button.fxml'">my_button.fxml</error>"/>
|
||||
</GridPane>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.jetbrains.plugins.javaFX.fxml;
|
||||
|
||||
import com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.XmlPathReferenceInspection;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.openapi.application.PluginPathManager;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiField;
|
||||
@@ -20,6 +22,11 @@ public class JavaFXHighlightingTest extends DaemonAnalyzerTestCase {
|
||||
PsiTestUtil.addLibrary(getModule(), "javafx", PluginPathManager.getPluginHomePath("javaFX") + "/testData", "jfxrt.jar");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LocalInspectionTool[] configureLocalInspectionTools() {
|
||||
return new LocalInspectionTool[] {new XmlPathReferenceInspection()};
|
||||
}
|
||||
|
||||
public void testLoginForm() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
@@ -118,6 +125,11 @@ public class JavaFXHighlightingTest extends DaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testIncludeBtn() throws Exception {
|
||||
configureByFiles(null, getTestName(true) + ".fxml", "btn.fxml");
|
||||
doDoTest(false, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
|
||||
Reference in New Issue
Block a user