use of com.intellij.psi.xml.XmlAttributeValue in project android by JetBrains.
the class ResourceFoldingBuilder method buildFoldRegions.
@Override
@NotNull
public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement element, @NotNull Document document, boolean quick) {
if (!(element instanceof PsiJavaFile || element instanceof XmlFile) || quick && !UNIT_TEST_MODE || !isFoldingEnabled()) {
return FoldingDescriptor.EMPTY;
}
final List<FoldingDescriptor> result = new ArrayList<FoldingDescriptor>();
if (element instanceof PsiJavaFile) {
final PsiJavaFile file = (PsiJavaFile) element;
file.accept(new JavaRecursiveElementWalkingVisitor() {
@Override
public void visitReferenceExpression(PsiReferenceExpression expression) {
InlinedResource inlinedResource = findJavaExpressionReference(expression);
if (inlinedResource != NONE) {
result.add(inlinedResource.getDescriptor());
}
super.visitReferenceExpression(expression);
}
});
} else {
final XmlFile file = (XmlFile) element;
file.accept(new XmlRecursiveElementVisitor() {
@Override
public void visitXmlAttributeValue(XmlAttributeValue value) {
InlinedResource inlinedResource = findXmlValueReference(value);
if (inlinedResource != NONE) {
FoldingDescriptor descriptor = inlinedResource.getDescriptor();
if (descriptor != null) {
result.add(descriptor);
}
}
super.visitXmlAttributeValue(value);
}
});
}
return result.toArray(new FoldingDescriptor[result.size()]);
}
use of com.intellij.psi.xml.XmlAttributeValue in project android by JetBrains.
the class AndroidValueResourcesTest method testNavigationInPlatformXml2_NavigateFromNameAttr.
public void testNavigationInPlatformXml2_NavigateFromNameAttr() throws Exception {
VirtualFile themes_holo = LocalFileSystem.getInstance().findFileByPath(TestUtils.getPlatformFile("data/res/values/themes_holo.xml").toString());
assertNotNull(themes_holo);
VirtualFile themes = LocalFileSystem.getInstance().findFileByPath(TestUtils.getPlatformFile("data/res/values/themes.xml").toString());
assertNotNull(themes);
// In themes_holo.xml: point to value of "Theme" in the name attribute on line:
// <style name="Theme.Holo.NoActionBar">
// Goto action should navigate to "Theme" in themes.xml, on line: "<style name="Theme">"
myFixture.configureFromExistingVirtualFile(themes_holo);
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(776, 19));
PsiElement[] targets = GotoDeclarationAction.findAllTargetElements(myFixture.getProject(), myFixture.getEditor(), myFixture.getCaretOffset());
assertNotNull(targets);
assertEquals(1, targets.length);
PsiElement targetElement = LazyValueResourceElementWrapper.computeLazyElement(targets[0]);
assertInstanceOf(targetElement, XmlAttributeValue.class);
XmlAttributeValue targetAttrValue = (XmlAttributeValue) targetElement;
assertEquals("Theme", targetAttrValue.getValue());
assertEquals("name", ((XmlAttribute) targetAttrValue.getParent()).getName());
assertEquals("style", ((XmlTag) targetAttrValue.getParent().getParent()).getName());
assertEquals(themes, targetElement.getContainingFile().getVirtualFile());
}
use of com.intellij.psi.xml.XmlAttributeValue in project android by JetBrains.
the class AndroidValueResourcesTest method testNavigationInPlatformXml1_NavigateFromParentAttr.
public void testNavigationInPlatformXml1_NavigateFromParentAttr() throws Exception {
VirtualFile themes_holo = LocalFileSystem.getInstance().findFileByPath(TestUtils.getPlatformFile("data/res/values/themes_holo.xml").toString());
assertNotNull(themes_holo);
VirtualFile themes = LocalFileSystem.getInstance().findFileByPath(TestUtils.getPlatformFile("data/res/values/themes.xml").toString());
assertNotNull(themes);
// In themes_holo.xml: point to value of "Theme" in the parent attribute on line:
// <style name="Theme.Holo.Light" parent="Theme.Light">
// Goto action should navigate to "Theme" in themes.xml, on line: "<style name="Theme">"
myFixture.configureFromExistingVirtualFile(themes_holo);
myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(406, 45));
PsiElement[] targets = GotoDeclarationAction.findAllTargetElements(myFixture.getProject(), myFixture.getEditor(), myFixture.getCaretOffset());
assertNotNull(targets);
assertEquals(1, targets.length);
PsiElement targetElement = LazyValueResourceElementWrapper.computeLazyElement(targets[0]);
assertInstanceOf(targetElement, XmlAttributeValue.class);
XmlAttributeValue targetAttrValue = (XmlAttributeValue) targetElement;
assertEquals("Theme", targetAttrValue.getValue());
assertEquals("name", ((XmlAttribute) targetAttrValue.getParent()).getName());
assertEquals("style", ((XmlTag) targetAttrValue.getParent().getParent()).getName());
assertEquals(themes, targetElement.getContainingFile().getVirtualFile());
}
use of com.intellij.psi.xml.XmlAttributeValue in project intellij-plugins by JetBrains.
the class FlexMxmlColorAnnotator method annotate.
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
if (!(element instanceof XmlAttribute) || !JavaScriptSupportLoader.isFlexMxmFile(element.getContainingFile())) {
return;
}
if (!LineMarkerSettings.getSettings().isEnabled(new ColorLineMarkerProvider())) {
return;
}
XmlAttribute attribute = (XmlAttribute) element;
XmlAttributeDescriptor descriptor = attribute.getDescriptor();
if (!(descriptor instanceof AnnotationBackedDescriptorImpl)) {
return;
}
AnnotationBackedDescriptorImpl annotationBackedDescriptor = (AnnotationBackedDescriptorImpl) descriptor;
String format = annotationBackedDescriptor.getFormat();
if (!FlexCssPropertyDescriptor.COLOR_FORMAT.equals(format)) {
return;
}
final String value = attribute.getValue();
if (value == null || value.length() == 0) {
return;
}
if (!JSCommonTypeNames.ARRAY_CLASS_NAME.equals(annotationBackedDescriptor.getType())) {
XmlAttributeValue valueElement = attribute.getValueElement();
if (valueElement != null) {
Annotation annotation = holder.createInfoAnnotation(valueElement, null);
annotation.setGutterIconRenderer(new MyRenderer(value, attribute));
}
}
}
use of com.intellij.psi.xml.XmlAttributeValue in project intellij-plugins by JetBrains.
the class DartPackagePathReferenceProvider method getReferencesByElement.
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext context) {
if (!(psiElement instanceof XmlAttributeValue) || !HtmlUtil.isHtmlFile(psiElement.getContainingFile()))
return PsiReference.EMPTY_ARRAY;
final PsiElement parent = psiElement.getParent();
if (!(parent instanceof XmlAttribute))
return PsiReference.EMPTY_ARRAY;
final XmlTag tag = ((XmlAttribute) parent).getParent();
if (tag == null)
return PsiReference.EMPTY_ARRAY;
final VirtualFile file = DartResolveUtil.getRealVirtualFile(psiElement.getContainingFile());
if (file == null)
return PsiReference.EMPTY_ARRAY;
if (!canContainDartPackageReference(tag.getName(), ((XmlAttribute) parent).getName()))
return PsiReference.EMPTY_ARRAY;
if (PubspecYamlUtil.findPubspecYamlFile(psiElement.getProject(), file) == null)
return PsiReference.EMPTY_ARRAY;
return getDartPackageReferences(psiElement, DartUrlResolver.getInstance(psiElement.getProject(), file));
}
Aggregations