This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch docs/struts-7-5-configuration-grammar in repository https://gitbox.apache.org/repos/asf/struts-intellij-plugin.git
commit 6bbfda18d21330aa422cfc85c8bb40e99ba3f926 Author: Lukasz Lenart <[email protected]> AuthorDate: Wed Nov 11 19:09:58 2026 +0100 feat: highlight a package that extends a final package Struts rejects that parent at startup, so the extends value is marked in the editor. Co-authored-by: Cursor <[email protected]> --- .../inspection/Struts2ModelInspectionVisitor.java | 14 ++++++++++ .../dom/struts/strutspackage/StrutsPackage.java | 2 ++ .../resources/messages/Struts2Bundle.properties | 1 + .../struts2/dom/struts/StrutsHighlightingTest.java | 6 +++- .../highlighting/struts-package-final.xml | 32 ++++++++++++++++++++++ 5 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/intellij/struts2/dom/inspection/Struts2ModelInspectionVisitor.java b/src/main/java/com/intellij/struts2/dom/inspection/Struts2ModelInspectionVisitor.java index 703f4b6..99d3e20 100644 --- a/src/main/java/com/intellij/struts2/dom/inspection/Struts2ModelInspectionVisitor.java +++ b/src/main/java/com/intellij/struts2/dom/inspection/Struts2ModelInspectionVisitor.java @@ -38,6 +38,7 @@ import com.intellij.util.xml.*; import com.intellij.util.xml.highlighting.DomElementAnnotationHolder; import java.util.Collection; +import java.util.List; import java.util.Map; /** @@ -107,6 +108,19 @@ class Struts2ModelInspectionVisitor implements DomElementVisitor { holder.createProblem(strutsPackage.getNamespace(), StrutsBundle.message("dom.highlighting.struts.package.must.start.with.slash")); } + + final List<StrutsPackage> parents = strutsPackage.getExtends().getValue(); + if (parents == null) { + return; + } + for (StrutsPackage parent : parents) { + if (parent != null && Boolean.TRUE.equals(parent.getFinal().getValue())) { + holder.createProblem(strutsPackage.getExtends(), + StrutsBundle.message("dom.highlighting.struts.package.final.parent", + parent.getName().getStringValue())); + return; + } + } } private void checkExtendableClassConverter(final GenericAttributeValue clazzAttributeValue) { diff --git a/src/main/java/com/intellij/struts2/dom/struts/strutspackage/StrutsPackage.java b/src/main/java/com/intellij/struts2/dom/struts/strutspackage/StrutsPackage.java index 307c09d..d449c21 100644 --- a/src/main/java/com/intellij/struts2/dom/struts/strutspackage/StrutsPackage.java +++ b/src/main/java/com/intellij/struts2/dom/struts/strutspackage/StrutsPackage.java @@ -49,6 +49,8 @@ public interface StrutsPackage extends CommonDomModelElement { GenericAttributeValue<Boolean> getAbstract(); + GenericAttributeValue<Boolean> getFinal(); + @Required(value = false, nonEmpty = true) @Stubbed GenericAttributeValue<String> getNamespace(); diff --git a/src/main/resources/messages/Struts2Bundle.properties b/src/main/resources/messages/Struts2Bundle.properties index 39b3afd..df7023a 100644 --- a/src/main/resources/messages/Struts2Bundle.properties +++ b/src/main/resources/messages/Struts2Bundle.properties @@ -47,6 +47,7 @@ dom.result.path.create.file=Create file ''{0}'' dom.result.path.create.file.family=Create JSP result file dom.highlighting.struts.package.must.start.with.slash=Namespace must start with '/' +dom.highlighting.struts.package.final.parent=Parent package is final and unextendable: {0} inspections.group.path.name=Struts inspections.group.display.name=Struts 2 diff --git a/src/test/java/com/intellij/struts2/dom/struts/StrutsHighlightingTest.java b/src/test/java/com/intellij/struts2/dom/struts/StrutsHighlightingTest.java index b9ea5b9..fe268d1 100644 --- a/src/test/java/com/intellij/struts2/dom/struts/StrutsHighlightingTest.java +++ b/src/test/java/com/intellij/struts2/dom/struts/StrutsHighlightingTest.java @@ -86,4 +86,8 @@ public class StrutsHighlightingTest extends StrutsLightHighlightingTestCase { performHighlightingTest("struts-dtd-https.xml"); } -} \ No newline at end of file + public void testFinalPackageParent() { + performHighlightingTest("struts-package-final.xml"); + } + +} diff --git a/src/test/testData/strutsXml/highlighting/struts-package-final.xml b/src/test/testData/strutsXml/highlighting/struts-package-final.xml new file mode 100644 index 0000000..6514812 --- /dev/null +++ b/src/test/testData/strutsXml/highlighting/struts-package-final.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + + +<!DOCTYPE struts PUBLIC + "-//Apache Software Foundation//DTD Struts Configuration 7.5//EN" + "https://struts.apache.org/dtds/struts-7.5.dtd"> + +<struts> + <package name="open"/> + <package name="locked" final="true"/> + <package name="child" extends="open"/> + <package name="blocked" extends="<error descr="Parent package is final and unextendable: locked">locked</error>"/> +</struts>
