javafx: fx:reference source ref

This commit is contained in:
Anna Kozlova
2013-01-31 18:45:32 +04:00
parent e078d1b31f
commit 2c9f51fad2
5 changed files with 78 additions and 4 deletions
@@ -51,6 +51,12 @@ public class FxmlReferencesContributor extends PsiReferenceContributor {
.and(attributeValueInFxml),
new JavaFxSourceReferenceProvider());
registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withParent(XmlPatterns.xmlAttribute().withName(FxmlConstants.FX_ELEMENT_SOURCE)
.withParent(XmlPatterns.xmlTag()
.withName(FxmlConstants.FX_REFERENCE)))
.and(attributeValueInFxml),
new JavaFxComponentIdReferenceProvider());
registrar.registerReferenceProvider(XmlPatterns.xmlAttributeValue().withValue(string().startsWith("#"))
.and(attributeValueInFxml),
new JavaFxEventHandlerReferenceProvider());
@@ -0,0 +1,67 @@
/*
* 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.*;
import com.intellij.psi.xml.XmlAttribute;
import com.intellij.psi.xml.XmlAttributeValue;
import com.intellij.psi.xml.XmlTag;
import com.intellij.util.ArrayUtil;
import com.intellij.util.ProcessingContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.javaFX.fxml.FxmlConstants;
import java.util.HashMap;
import java.util.Map;
/**
* User: anna
*/
class JavaFxComponentIdReferenceProvider extends PsiReferenceProvider {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element,
@NotNull ProcessingContext context) {
final XmlAttributeValue xmlAttributeValue = (XmlAttributeValue)element;
final String referencesId = xmlAttributeValue.getValue();
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());
}
}
});
return new PsiReference[]{new PsiReferenceBase<XmlAttributeValue>(xmlAttributeValue) {
@Nullable
@Override
public PsiElement resolve() {
return fileIds.get(referencesId);
}
@NotNull
@Override
public Object[] getVariants() {
return ArrayUtil.toStringArray(fileIds.keySet());
}
}};
}
}
@@ -1,5 +1,5 @@
<?import javafx.scene.layout.GridPane?>
<GridPane xmlns:fx="http://javafx.com/fxml">
<fx:reference GridPane.halignment="CENTER" />
<fx:reference GridPane.halignment="CENTER" source="lbl"/>
<<error descr="Element fx:reference doesn't have required attribute source">fx:reference</error> GridPane.halignment="CENTER" />
<fx:reference GridPane.halignment="CENTER" source="<error descr="Cannot resolve symbol 'lbl'">lbl</error>"/>
</GridPane>
@@ -3,7 +3,7 @@
<GridPane xmlns:fx="http://javafx.com/fxml">
<ImageView>
<image>
<fx:reference source="myImage"/>
<fx:reference source="<error descr="Cannot resolve symbol 'myImage'">myImage</error>"/>
</image>
</ImageView>
<fx:include source="<error descr="Cannot resolve file 'my_button.fxml'">my_button.fxml</error>"/>
@@ -3,6 +3,7 @@ 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.codeInspection.htmlInspections.RequiredAttributesInspection;
import com.intellij.openapi.application.PluginPathManager;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiField;
@@ -24,7 +25,7 @@ public class JavaFXHighlightingTest extends DaemonAnalyzerTestCase {
@Override
protected LocalInspectionTool[] configureLocalInspectionTools() {
return new LocalInspectionTool[] {new XmlPathReferenceInspection()};
return new LocalInspectionTool[] {new XmlPathReferenceInspection(), new RequiredAttributesInspection() };
}
public void testLoginForm() throws Exception {