use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class HtmlUnknownTargetInspection method notRemoteBase.
static boolean notRemoteBase(PsiReference reference) {
final PsiFile file = reference.getElement().getContainingFile();
final String basePath = file instanceof XmlFile ? HtmlUtil.getHrefBase((XmlFile) file) : null;
return basePath == null || !HtmlUtil.hasHtmlPrefix(basePath);
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class MavenRedundantGroupIdInspection method checkFile.
@Nullable
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
if (file instanceof XmlFile && (file.isPhysical() || ApplicationManager.getApplication().isUnitTestMode())) {
DomFileElement<MavenDomProjectModel> model = DomManager.getDomManager(file.getProject()).getFileElement((XmlFile) file, MavenDomProjectModel.class);
if (model != null) {
MavenDomProjectModel projectModel = model.getRootElement();
String groupId = projectModel.getGroupId().getStringValue();
if (groupId != null && groupId.length() > 0) {
MavenDomParent parent = projectModel.getMavenParent();
String parentGroupId = parent.getGroupId().getStringValue();
if (groupId.equals(parentGroupId)) {
XmlTag xmlTag = projectModel.getGroupId().getXmlTag();
LocalQuickFix fix = new LocalQuickFixBase("Remove unnecessary <groupId>") {
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
descriptor.getPsiElement().delete();
}
};
return new ProblemDescriptor[] { manager.createProblemDescriptor(xmlTag, "Definition of groupId is redundant, because it's inherited from the parent", fix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly) };
}
}
}
}
return null;
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class XPathAction method isEnabled.
protected boolean isEnabled(AnActionEvent event, boolean checkAvailable) {
final Project project = event.getProject();
if (project == null) {
// no active project
return false;
}
Editor editor = CommonDataKeys.EDITOR.getData(event.getDataContext());
if (editor == null) {
FileEditorManager fem = FileEditorManager.getInstance(project);
editor = fem.getSelectedTextEditor();
}
if (editor == null) {
return false;
}
// do we have an xml file?
final PsiDocumentManager cem = PsiDocumentManager.getInstance(project);
final PsiFile psiFile = cem.getPsiFile(editor.getDocument());
// this is also true for DTD documents...
if (!(psiFile instanceof XmlFile) || psiFile.getLanguage() == StdFileTypes.DTD.getLanguage()) {
return false;
}
return !checkAvailable || isEnabledAt((XmlFile) psiFile, editor.getCaretModel().getOffset());
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class XPathEvalAction method execute.
private void execute(Editor editor) {
final Project project = editor.getProject();
final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (psiFile == null) {
return;
}
InputExpressionDialog.Context input;
XmlElement contextNode = null;
final Config cfg = XPathAppComponent.getInstance().getConfig();
do {
RangeHighlighter contextHighlighter = null;
if (cfg.isUseContextAtCursor()) {
// find out current context node
contextNode = MyPsiUtil.findContextNode(psiFile, editor);
if (contextNode != null) {
contextHighlighter = HighlighterUtil.highlightNode(editor, contextNode, cfg.getContextAttributes(), cfg);
}
}
if (contextNode == null) {
// in XPath data model, / is the document itself, including comments, PIs and the root element
contextNode = ((XmlFile) psiFile).getDocument();
if (contextNode == null) {
FileViewProvider fileViewProvider = psiFile.getViewProvider();
if (fileViewProvider instanceof TemplateLanguageFileViewProvider) {
Language dataLanguage = ((TemplateLanguageFileViewProvider) fileViewProvider).getTemplateDataLanguage();
PsiFile templateDataFile = fileViewProvider.getPsi(dataLanguage);
if (templateDataFile instanceof XmlFile)
contextNode = ((XmlFile) templateDataFile).getDocument();
}
}
}
input = inputXPathExpression(project, contextNode);
if (contextHighlighter != null) {
contextHighlighter.dispose();
}
if (input == null) {
return;
}
HighlighterUtil.clearHighlighters(editor);
} while (contextNode != null && evaluateExpression(input, contextNode, editor, cfg));
}
use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.
the class XsltDeclarationInspection method buildVisitor.
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
if (!(holder.getFile() instanceof XmlFile))
return PsiElementVisitor.EMPTY_VISITOR;
return new XmlElementVisitor() {
@Override
public void visitXmlTag(final XmlTag tag) {
final XmlAttribute nameAttr = tag.getAttribute("name", null);
if (nameAttr == null || PsiTreeUtil.hasErrorElements(nameAttr))
return;
if (XsltSupport.isVariableOrParam(tag)) {
final XsltNamedElement instance = getXsltElementFactory().wrapElement(tag, XsltNamedElement.class);
checkDeclaration(instance, nameAttr.getValue(), holder);
} else if (XsltSupport.isTemplate(tag)) {
final XsltTemplate tmpl = getXsltElementFactory().wrapElement(tag, XsltTemplate.class);
checkDeclaration(tmpl, nameAttr.getValue(), holder);
}
}
private void checkDeclaration(final XsltNamedElement element, final String name, ProblemsHolder holder) {
final XmlTag tag = element.getTag();
final PsiElement token = element.getNameIdentifier();
if (name == null || name.length() == 0) {
if (token != null) {
holder.registerProblem(token, "Empty name not permitted");
} else {
final XmlAttribute attribute = element.getNameAttribute();
if (attribute != null) {
final XmlAttributeValue e = attribute.getValueElement();
if (e != null) {
holder.registerProblem(e, "Empty name not permitted");
}
}
}
} else if (!isLegalName(name, holder.getManager().getProject())) {
assert token != null;
holder.registerProblem(token, "Illegal name");
} else {
assert token != null;
final XmlFile file = (XmlFile) tag.getContainingFile();
final XmlTag duplicatedSymbol = DeclarationChecker.getInstance(file).getDuplicatedSymbol(tag);
if (duplicatedSymbol != null) {
if (duplicatedSymbol.getContainingFile() == file) {
holder.registerProblem(token, "Duplicate declaration");
} else {
holder.registerProblem(token, "Duplicates declaration from '" + duplicatedSymbol.getContainingFile().getName() + "'");
}
}
}
}
private boolean isLegalName(String value, Project project) {
return getNamesValidator().isIdentifier(value, project);
}
};
}
Aggregations