Search in sources :

Example 6 with XmlFile

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);
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) PsiFile(com.intellij.psi.PsiFile)

Example 7 with XmlFile

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;
}
Also used : Project(com.intellij.openapi.project.Project) MavenDomProjectModel(org.jetbrains.idea.maven.dom.model.MavenDomProjectModel) XmlFile(com.intellij.psi.xml.XmlFile) MavenDomParent(org.jetbrains.idea.maven.dom.model.MavenDomParent) NotNull(org.jetbrains.annotations.NotNull) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with XmlFile

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());
}
Also used : Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) XmlFile(com.intellij.psi.xml.XmlFile) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) PsiDocumentManager(com.intellij.psi.PsiDocumentManager)

Example 9 with XmlFile

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));
}
Also used : Project(com.intellij.openapi.project.Project) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) FileViewProvider(com.intellij.psi.FileViewProvider) Language(com.intellij.lang.Language) XmlFile(com.intellij.psi.xml.XmlFile) XmlElement(com.intellij.psi.xml.XmlElement) PsiFile(com.intellij.psi.PsiFile) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) InputExpressionDialog(org.intellij.plugins.xpathView.ui.InputExpressionDialog)

Example 10 with XmlFile

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);
        }
    };
}
Also used : XmlElementVisitor(com.intellij.psi.XmlElementVisitor) Project(com.intellij.openapi.project.Project) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) XsltNamedElement(org.intellij.lang.xpath.xslt.psi.XsltNamedElement) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) XsltTemplate(org.intellij.lang.xpath.xslt.psi.XsltTemplate) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) ProblemsHolder(com.intellij.codeInspection.ProblemsHolder) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

XmlFile (com.intellij.psi.xml.XmlFile)409 XmlTag (com.intellij.psi.xml.XmlTag)155 PsiFile (com.intellij.psi.PsiFile)121 VirtualFile (com.intellij.openapi.vfs.VirtualFile)102 Nullable (org.jetbrains.annotations.Nullable)74 Project (com.intellij.openapi.project.Project)69 NotNull (org.jetbrains.annotations.NotNull)66 PsiElement (com.intellij.psi.PsiElement)64 XmlAttribute (com.intellij.psi.xml.XmlAttribute)39 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)34 Module (com.intellij.openapi.module.Module)34 XmlDocument (com.intellij.psi.xml.XmlDocument)32 Result (com.intellij.openapi.application.Result)28 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)23 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)22 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)21 ArrayList (java.util.ArrayList)20 Document (com.intellij.openapi.editor.Document)19 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)18 Editor (com.intellij.openapi.editor.Editor)15