use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class OverriddenDefineRenderer method getClickAction.
@Override
@Nullable
public AnAction getClickAction() {
return new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
final PsiElement element = myDefine.getPsiElement();
if (element == null || !element.isValid())
return;
final PsiElementProcessor.CollectElements<XmlFile> collector = new PsiElementProcessor.CollectElements<>();
final XmlFile localFile = (XmlFile) element.getContainingFile();
RelaxIncludeIndex.processBackwardDependencies(localFile, collector);
final Collection<XmlFile> files = collector.getCollection();
final List<Define> result = new SmartList<>();
final OverriddenDefineSearcher searcher = new OverriddenDefineSearcher(myDefine, localFile, result);
for (XmlFile file : files) {
final Grammar grammar = GrammarFactory.getGrammar(file);
if (grammar == null)
continue;
grammar.acceptChildren(searcher);
}
if (result.size() > 0) {
OverridingDefineRenderer.doClickAction(e, result, "Go to overriding define(s)");
}
}
};
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class NoNamespaceSchemaProvider method getSchema.
@Override
@Nullable
public XmlFile getSchema(@NotNull @NonNls String url, @Nullable Module module, @NotNull PsiFile baseFile) {
if ("".equals(url)) {
final Project project = baseFile.getProject();
final VirtualFile file = NoNamespaceConfig.getInstance(project).getMappedFile(baseFile);
if (file == null)
return null;
final PsiFile f = PsiManager.getInstance(project).findFile(file);
if (f instanceof XmlFile) {
return (XmlFile) f;
}
}
return null;
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class ResolvingVisitor method processInclude.
private void processInclude(XmlFile xmlFile, XmlAttribute attribute) {
final Set<XmlFile> set = myProcessingContext.get(VISITED_KEY);
if (set.contains(xmlFile)) {
return;
}
set.add(xmlFile);
final XmlDocument document = xmlFile.getDocument();
if (document == null)
return;
final XmlTag rootTag = document.getRootTag();
if (rootTag == null)
return;
rootTag.processElements(this, attribute);
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class XsltExtractFunctionAction method extractImpl.
protected boolean extractImpl(XPathExpression expression, Set<XPathExpression> matchingExpressions, List<XmlTag> otherMatches, RefactoringOptions dlg) {
final XmlAttribute attribute = PsiTreeUtil.getContextOfType(expression, XmlAttribute.class, true);
assert attribute != null;
try {
final String name = dlg.getName();
final XmlTag rootTag = ((XmlFile) attribute.getParent().getContainingFile()).getRootTag();
final XmlTag[] templates = rootTag.findSubTags("template", XsltSupport.XSLT_NS);
final XmlTag insertionPoint = templates.length > 0 ? templates[0] : rootTag.getSubTags()[0];
final XmlTag parentTag = insertionPoint.getParentTag();
assert parentTag != null : "Could not locate position to create function at";
final XmlTag xmlTag = parentTag.createChildTag("function", XsltSupport.XSLT_NS, null, false);
xmlTag.setAttribute("name", name);
final XPathType type = ExpectedTypeUtil.mapType(expression, expression.getType());
xmlTag.setAttribute("as", prefixedName(type, insertionPoint));
final StringBuilder argList = new StringBuilder();
final List<XPathVariableReference> references = RefactoringUtil.collectVariableReferences(expression);
for (XPathVariableReference reference : references) {
final XPathVariable variable = reference.resolve();
if (variable instanceof XsltVariable) {
// don't pass through global parameters and variables
if (XsltCodeInsightUtil.getTemplateTag(variable, false) != null) {
final XmlTag param = parentTag.createChildTag("param", XsltSupport.XSLT_NS, null, false);
param.setAttribute("name", variable.getName());
if (!variable.getType().isAbstract()) {
param.setAttribute("as", prefixedName(ExpectedTypeUtil.mapType(expression, variable.getType()), parentTag));
}
RefactoringUtil.addParameter(xmlTag, param);
if (argList.length() > 0) {
argList.append(", ");
}
argList.append("$").append(variable.getName());
}
}
}
final XmlTag seqTag = parentTag.createChildTag("sequence", XsltSupport.XSLT_NS, null, false);
seqTag.setAttribute("select", expression.getText());
xmlTag.add(seqTag);
// TODO: revisit the formatting
final PsiElement element = parentTag.addBefore(xmlTag, insertionPoint);
final ASTNode node1 = parentTag.getNode();
assert node1 != null;
final ASTNode node2 = element.getNode();
assert node2 != null;
CodeStyleManager.getInstance(xmlTag.getManager().getProject()).reformatNewlyAddedElement(node1, node2);
final XPathExpression var = XPathChangeUtil.createExpression(expression, name + "(" + argList + ")");
expression.replace(var);
return true;
} catch (IncorrectOperationException e) {
Logger.getInstance(getClass().getName()).error(e);
return false;
}
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class XsltImplicitUsagesProvider method isImplicitUsage.
public boolean isImplicitUsage(PsiElement element) {
if (!(element instanceof XmlAttribute)) {
return false;
}
final XmlAttribute attr = (XmlAttribute) element;
if (!attr.isNamespaceDeclaration()) {
return false;
}
final PsiFile file = attr.getContainingFile();
if (!(file instanceof XmlFile)) {
return false;
}
// ContextProvider.hasXPathInjections() is an optimization that avoids to run the references search on totally XPath-free XML files
if (!ContextProvider.hasXPathInjections((XmlFile) file) && !XsltSupport.isXsltFile(file)) {
return false;
}
// This need to catch both prefix references from injected XPathFiles and prefixes from mode declarations/references:
// <xsl:template match="*" mode="prefix:name" />
// BTW: Almost the same logic applies to other XML dialects (RELAX-NG).
// Pull this class into the platform?
final String prefix = attr.getLocalName();
final SchemaPrefix target = new SchemaPrefix(attr, TextRange.from("xmlns:".length(), prefix.length()), prefix);
final Query<PsiReference> q = ReferencesSearch.search(target, new LocalSearchScope(attr.getParent()));
return !q.forEach(psiReference -> {
if (psiReference.getElement() == attr) {
return true;
}
return false;
});
}
Aggregations