use of com.intellij.psi.xml.XmlTag in project intellij-community by JetBrains.
the class XslZenCodingFilter method filterNode.
@NotNull
@Override
public GenerationNode filterNode(@NotNull final GenerationNode node) {
TemplateToken token = node.getTemplateToken();
final XmlTag tag = token != null ? token.getXmlTag() : null;
if (tag != null) {
if (token.getAttributes().containsKey(SELECT_ATTR_NAME)) {
return node;
}
ApplicationManager.getApplication().runWriteAction(() -> {
if (isOurTag(tag, node.getChildren().size() > 0)) {
XmlAttribute attribute = tag.getAttribute(SELECT_ATTR_NAME);
if (attribute != null) {
attribute.delete();
}
}
});
return node;
}
return node;
}
use of com.intellij.psi.xml.XmlTag in project intellij-community by JetBrains.
the class TemplateToken method createTemplateText.
@NotNull
private static String createTemplateText(@NotNull TemplateImpl template, @NotNull CustomTemplateCallback callback, @NotNull Map<String, String> attributes) {
XmlTag dummyRootTag = null;
String templateString = template.getString();
if (!containsAttrsVar(template)) {
PsiFile dummyFile = PsiFileFactory.getInstance(callback.getProject()).createFileFromText("dummy.html", callback.getFile().getLanguage(), templateString, false, true);
dummyRootTag = PsiTreeUtil.findChildOfType(dummyFile, XmlTag.class);
if (dummyRootTag != null && !attributes.isEmpty()) {
addMissingAttributes(dummyRootTag, attributes);
}
}
return dummyRootTag != null ? dummyRootTag.getContainingFile().getText() : templateString;
}
use of com.intellij.psi.xml.XmlTag in project intellij-community by JetBrains.
the class Html5CustomAttributeDescriptorsProvider method getAttributeDescriptors.
@Override
public XmlAttributeDescriptor[] getAttributeDescriptors(XmlTag tag) {
if (tag == null || !HtmlUtil.isHtml5Context(tag)) {
return XmlAttributeDescriptor.EMPTY;
}
final List<String> currentAttrs = new ArrayList<>();
for (XmlAttribute attribute : tag.getAttributes()) {
currentAttrs.add(attribute.getName());
}
final Project project = tag.getProject();
final Collection<String> keys = CachedValuesManager.getManager(project).getCachedValue(project, () -> {
final Collection<String> keys1 = FileBasedIndex.getInstance().getAllKeys(Html5CustomAttributesIndex.INDEX_ID, project);
final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
return CachedValueProvider.Result.<Collection<String>>create(ContainerUtil.filter(keys1, key -> !FileBasedIndex.getInstance().processValues(Html5CustomAttributesIndex.INDEX_ID, key, null, (file, value) -> false, scope)), PsiModificationTracker.MODIFICATION_COUNT);
});
if (keys.isEmpty())
return XmlAttributeDescriptor.EMPTY;
final List<XmlAttributeDescriptor> result = new ArrayList<>();
for (String key : keys) {
boolean add = true;
for (String attr : currentAttrs) {
if (attr.startsWith(key)) {
add = false;
}
}
if (add) {
result.add(new AnyXmlAttributeDescriptor(key));
}
}
return result.toArray(new XmlAttributeDescriptor[result.size()]);
}
use of com.intellij.psi.xml.XmlTag in project intellij-community by JetBrains.
the class XmlParameterInfoHandler method findElementForParameterInfo.
@Override
public XmlTag findElementForParameterInfo(@NotNull final CreateParameterInfoContext context) {
final XmlTag tag = findXmlTag(context.getFile(), context.getOffset());
final XmlElementDescriptor descriptor = tag != null ? tag.getDescriptor() : null;
if (descriptor == null) {
DaemonCodeAnalyzer.getInstance(context.getProject()).updateVisibleHighlighters(context.getEditor());
return null;
}
context.setItemsToShow(new Object[] { descriptor });
return tag;
}
use of com.intellij.psi.xml.XmlTag in project intellij-community by JetBrains.
the class FormReferenceProvider method processReferences.
private static void processReferences(final PsiPlainTextFile file, final PsiReferenceProcessor processor) {
final Project project = file.getProject();
final XmlTag rootTag = ApplicationManager.getApplication().runReadAction(new Computable<XmlTag>() {
public XmlTag compute() {
final XmlFile xmlFile = (XmlFile) PsiFileFactory.getInstance(project).createFileFromText("a.xml", XmlFileType.INSTANCE, file.getViewProvider().getContents());
return xmlFile.getRootTag();
}
});
if (rootTag == null || !Utils.FORM_NAMESPACE.equals(rootTag.getNamespace())) {
return;
}
@NonNls final String name = rootTag.getName();
if (!"form".equals(name)) {
return;
}
PsiReference classReference = null;
final XmlAttribute classToBind = rootTag.getAttribute("bind-to-class", null);
if (classToBind != null) {
// reference to class
final XmlAttributeValue valueElement = classToBind.getValueElement();
if (valueElement == null) {
return;
}
final String className = valueElement.getValue().replace('$', '.');
final PsiReference[] referencesByString = new JavaClassReferenceProvider().getReferencesByString(className, file, valueElement.getTextRange().getStartOffset() + 1);
if (referencesByString.length < 1) {
// There are no references there
return;
}
for (PsiReference aReferencesByString : referencesByString) {
processor.execute(aReferencesByString);
}
classReference = referencesByString[referencesByString.length - 1];
}
final PsiReference finalClassReference = classReference;
ApplicationManager.getApplication().runReadAction(() -> processReferences(rootTag, finalClassReference, file, processor));
}
Aggregations