Search in sources :

Example 1 with MavenDomParent

use of org.jetbrains.idea.maven.dom.model.MavenDomParent 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)

Aggregations

Project (com.intellij.openapi.project.Project)1 XmlFile (com.intellij.psi.xml.XmlFile)1 XmlTag (com.intellij.psi.xml.XmlTag)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 MavenDomParent (org.jetbrains.idea.maven.dom.model.MavenDomParent)1 MavenDomProjectModel (org.jetbrains.idea.maven.dom.model.MavenDomProjectModel)1