use of com.intellij.psi.xml.XmlAttribute in project intellij-plugins by JetBrains.
the class TilesOgnlInjector method getLanguagesToInject.
@Override
public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) {
final PsiFile containingFile = context.getContainingFile();
if (!JamCommonUtil.isPlainXmlFile(containingFile)) {
return;
}
assert context instanceof XmlAttributeValue;
if (!((XmlAttributeValue) context).getValue().startsWith(OGNL_PREFIX)) {
return;
}
PsiElement parent = context.getParent();
if (parent instanceof XmlAttribute) {
String name = ((XmlAttribute) parent).getLocalName();
if ("expression".equals(name) || "templateExpression".equals(name)) {
DomElement domElement = DomManager.getDomManager(context.getProject()).getDomElement((XmlTag) parent.getParent());
if (domElement instanceof Put || domElement instanceof Add || domElement instanceof Definition) {
final TextRange attributeTextRange = ElementManipulators.getValueTextRange(context);
final TextRange ognlTextRange = TextRange.from(attributeTextRange.getStartOffset() + OGNL_PREFIX.length(), attributeTextRange.getLength() - OGNL_PREFIX.length());
registrar.startInjecting(OgnlLanguage.INSTANCE).addPlace(OgnlLanguage.EXPRESSION_PREFIX, OgnlLanguage.EXPRESSION_SUFFIX, (PsiLanguageInjectionHost) context, ognlTextRange).doneInjecting();
}
}
}
}
use of com.intellij.psi.xml.XmlAttribute in project intellij-plugins by JetBrains.
the class DartPackagePathReferenceProvider method getFilter.
public static ElementFilter getFilter() {
return new ElementFilter() {
@Override
public boolean isAcceptable(Object _element, PsiElement context) {
if (!(_element instanceof PsiElement))
return false;
final PsiElement element = (PsiElement) _element;
final PsiElement parentElement = element.getParent();
final PsiFile file = element.getContainingFile().getOriginalFile();
final VirtualFile vFile = file.getVirtualFile();
return vFile != null && HtmlUtil.hasHtml(file) && parentElement instanceof XmlAttribute && canContainDartPackageReference(((XmlAttribute) parentElement).getParent().getLocalName(), ((XmlAttribute) parentElement).getName()) && PubspecYamlUtil.findPubspecYamlFile(element.getProject(), vFile) != null;
}
@Override
public boolean isClassAcceptable(Class hintClass) {
return true;
}
};
}
use of com.intellij.psi.xml.XmlAttribute in project intellij-plugins by JetBrains.
the class FlexXmlBackedMembersIndex method getItemsByName.
public static Collection<NavigationItem> getItemsByName(final String name, Project project) {
Collection<VirtualFile> files = FileBasedIndex.getInstance().getContainingFiles(NAME, name, GlobalSearchScope.projectScope(project));
final Collection<NavigationItem> result = new ArrayList<>();
for (VirtualFile vFile : files) {
PsiFile file = PsiManager.getInstance(project).findFile(vFile);
if (!(file instanceof XmlFile)) {
continue;
}
process((XmlFile) file, element -> {
if (name.equals(getName(element))) {
if (element instanceof JSNamedElement) {
result.add((JSNamedElement) element);
} else {
XmlAttribute id = ((XmlTag) element).getAttribute("id");
if (id != null) {
XmlAttributeValue valueElement = id.getValueElement();
PsiElement[] children;
if (valueElement != null && (children = valueElement.getChildren()).length == 3) {
result.add(new TagNavigationItem(children[1], name));
}
}
}
}
}, true);
}
return result;
}
use of com.intellij.psi.xml.XmlAttribute in project intellij-plugins by JetBrains.
the class MxmlJSClass method addToImplementsList.
@Override
public void addToImplementsList(String refText) {
XmlAttribute attribute = getParent().getAttribute(IMPLEMENTS_ATTRIBUTE);
if (attribute == null) {
getParent().setAttribute(IMPLEMENTS_ATTRIBUTE, refText);
} else {
attribute.setValue(attribute.getValue() + ", " + refText);
}
myImplementsList = null;
}
use of com.intellij.psi.xml.XmlAttribute in project intellij-plugins by JetBrains.
the class MxmlJSClass method removeFromImplementsList.
@Override
public void removeFromImplementsList(String refText) {
String[] refs = getImplementsList().getReferenceTexts();
LOG.assertTrue(ArrayUtil.contains(refText, refs));
XmlAttribute attribute = getParent().getAttribute(IMPLEMENTS_ATTRIBUTE);
if (refs.length == 1) {
attribute.delete();
} else {
String[] newRefs = ArrayUtil.remove(refs, refText);
attribute.setValue(StringUtil.join(newRefs, ", "));
}
myImplementsList = null;
}
Aggregations