use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class XsltNamespaceContext method getUnresolvedNamespaceFixesStatic.
public static IntentionAction[] getUnresolvedNamespaceFixesStatic(PsiReference reference, String localName) {
final XmlElementFactory factory = XmlElementFactory.getInstance(reference.getElement().getProject());
final XmlTag tag = factory.createTagFromText("<" + reference.getCanonicalText() + ":" + localName + " />", XMLLanguage.INSTANCE);
final XmlFile xmlFile = PsiTreeUtil.getContextOfType(reference.getElement(), XmlFile.class, true);
return new IntentionAction[] { new MyCreateNSDeclarationAction(tag, reference.getCanonicalText(), xmlFile) };
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class XsltVariableContext method resolveInner.
@Nullable
private XPathVariable resolveInner(XPathVariableReference reference) {
final XmlTag context = getContextTagImpl(reference);
final VariableResolveProcessor processor = new VariableResolveProcessor(reference.getReferencedName(), context);
final XPathVariable variable = (XPathVariable) ResolveUtil.treeWalkUp(processor, context);
if (variable != null) {
return variable;
}
if (!processForwardGlobals(context, processor)) {
final XmlFile file = PsiTreeUtil.getParentOfType(context, XmlFile.class, true);
if (file != null) {
XsltIncludeIndex.processBackwardDependencies(file, xmlFile -> {
processor.processExternalFile(xmlFile, context);
return processor.shouldContinue();
});
}
}
return (XPathVariable) processor.getResult();
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class XsltParameterImpl method getLocalUseScope.
@NotNull
@Override
public SearchScope getLocalUseScope() {
final XmlTag tag = getTag();
if (!tag.isValid()) {
return getDefaultUseScope();
}
final XsltTemplate template = getTemplate();
if (template == null) {
return getDefaultUseScope();
}
if (template.getName() == null) {
return getDefaultUseScope();
}
final XmlFile file = (XmlFile) tag.getContainingFile();
if (!XsltIncludeIndex.processBackwardDependencies(file, new CommonProcessors.FindFirstProcessor<>())) {
// processor found something
return getDefaultUseScope();
}
return new LocalSearchScope(file);
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class EmmetPreviewUtil method calculateTemplateText.
@Nullable
public static String calculateTemplateText(@NotNull Editor editor, @NotNull PsiFile file, boolean expandPrimitiveAbbreviations) {
if (file instanceof XmlFile) {
PsiDocumentManager.getInstance(file.getProject()).commitDocument(editor.getDocument());
CollectCustomTemplateCallback callback = new CollectCustomTemplateCallback(editor, file);
PsiElement context = callback.getContext();
ZenCodingGenerator generator = ZenCodingTemplate.findApplicableDefaultGenerator(context, false);
if (generator != null && generator instanceof XmlZenCodingGenerator) {
final String templatePrefix = new ZenCodingTemplate().computeTemplateKeyWithoutContextChecking(callback);
if (templatePrefix != null) {
try {
ZenCodingTemplate.expand(templatePrefix, callback, generator, Collections.<ZenCodingFilter>emptyList(), expandPrimitiveAbbreviations, 0);
TemplateImpl template = callback.getGeneratedTemplate();
String templateText = template != null ? template.getTemplateText() : null;
if (!StringUtil.isEmpty(templateText)) {
return template.isToReformat() ? reformatTemplateText(file, templateText) : templateText;
}
} catch (EmmetException e) {
return e.getMessage();
}
}
}
}
return null;
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class EmmetUpdateTagAction method processTags.
private static void processTags(@NotNull Project project, @Nullable String templateText, @NotNull PairProcessor<XmlTag, Boolean> processor) {
if (StringUtil.isNotEmpty(templateText)) {
final PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(project);
XmlFile xmlFile = (XmlFile) psiFileFactory.createFileFromText("dummy.xml", StdFileTypes.HTML, templateText);
XmlTag tag = xmlFile.getRootTag();
boolean firstTag = true;
while (tag != null) {
processor.process(tag, firstTag);
firstTag = false;
tag = PsiTreeUtil.getNextSiblingOfType(tag, XmlTag.class);
}
}
}
Aggregations