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 ede5a99859e81a864cc3026399dd8971fe74a767
Author: Lukasz Lenart <[email protected]>
AuthorDate: Wed Nov 11 19:28:10 2026 +0100

    feat: check package and action extension tokens
    
    Highlight an extension that starts with a dot, contains a slash, or 
contains whitespace.
    
    Co-authored-by: Cursor <[email protected]>
---
 .../intellij/struts2/dom/struts/action/Action.java |  4 ++
 .../strutspackage/ExtensionListConverter.java      | 78 ++++++++++++++++++++++
 .../dom/struts/strutspackage/StrutsPackage.java    |  3 +
 .../struts2/dom/struts/StrutsHighlightingTest.java |  4 ++
 .../strutsXml/highlighting/struts-extension.xml    | 31 +++++++++
 5 files changed, 120 insertions(+)

diff --git a/src/main/java/com/intellij/struts2/dom/struts/action/Action.java 
b/src/main/java/com/intellij/struts2/dom/struts/action/Action.java
index d57670a..b5f5488 100644
--- a/src/main/java/com/intellij/struts2/dom/struts/action/Action.java
+++ b/src/main/java/com/intellij/struts2/dom/struts/action/Action.java
@@ -20,6 +20,7 @@ import com.intellij.psi.PsiClass;
 import com.intellij.psi.PsiMethod;
 import com.intellij.struts2.dom.ExtendableClassConverter;
 import com.intellij.struts2.dom.params.ParamsElement;
+import com.intellij.struts2.dom.struts.strutspackage.ExtensionListConverter;
 import com.intellij.struts2.dom.struts.strutspackage.InterceptorRef;
 import com.intellij.struts2.dom.struts.strutspackage.StrutsPackage;
 import com.intellij.util.xml.*;
@@ -66,6 +67,9 @@ public interface Action extends ParamsElement {
   @Convert(HttpMethodConverter.class)
   GenericAttributeValue<String> getHttpMethod();
 
+  @Convert(ExtensionListConverter.class)
+  GenericAttributeValue<String> getExtension();
+
 
   // --------------------
   @SubTagList("result")
diff --git 
a/src/main/java/com/intellij/struts2/dom/struts/strutspackage/ExtensionListConverter.java
 
b/src/main/java/com/intellij/struts2/dom/struts/strutspackage/ExtensionListConverter.java
new file mode 100644
index 0000000..58d316b
--- /dev/null
+++ 
b/src/main/java/com/intellij/struts2/dom/struts/strutspackage/ExtensionListConverter.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2026 The authors
+ * Licensed 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.
+ */
+package com.intellij.struts2.dom.struts.strutspackage;
+
+import com.intellij.psi.PsiElement;
+import com.intellij.util.ArrayUtilRt;
+import com.intellij.util.xml.ConvertContext;
+import com.intellij.util.xml.DomUtil;
+import com.intellij.util.xml.GenericDomValue;
+import com.intellij.util.xml.converters.DelimitedListConverter;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.List;
+
+public class ExtensionListConverter extends DelimitedListConverter<String> {
+
+  public ExtensionListConverter() {
+    super(",");
+  }
+
+  static boolean isLegal(@NotNull String token) {
+    return !token.startsWith(".") && !token.contains("/") && 
!containsWhitespace(token);
+  }
+
+  private static boolean containsWhitespace(String token) {
+    for (int i = 0; i < token.length(); i++) {
+      if (Character.isWhitespace(token.charAt(i))) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  @Override
+  protected String convertString(@Nullable String token, ConvertContext 
context) {
+    if (token == null || token.isEmpty() || isLegal(token)) {
+      return token;
+    }
+    return null;
+  }
+
+  @Override
+  protected String toString(@Nullable String token) {
+    return token;
+  }
+
+  @Override
+  protected Object[] getReferenceVariants(ConvertContext context,
+                                          GenericDomValue<? extends 
List<String>> value) {
+    return ArrayUtilRt.EMPTY_OBJECT_ARRAY;
+  }
+
+  @Override
+  protected PsiElement resolveReference(@Nullable String token, ConvertContext 
context) {
+    if (token != null && (token.isEmpty() || isLegal(token))) {
+      return DomUtil.getValueElement((GenericDomValue<?>) 
context.getInvocationElement());
+    }
+    return null;
+  }
+
+  @Override
+  protected String getUnresolvedMessage(String token) {
+    return "Invalid extension '" + token + "'";
+  }
+}
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 bdb6c9e..67f24ef 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
@@ -57,6 +57,9 @@ public interface StrutsPackage extends CommonDomModelElement {
 
   GenericAttributeValue<Boolean> getStrictMethodInvocation();
 
+  @Convert(ExtensionListConverter.class)
+  GenericAttributeValue<String> getExtension();
+
   // externalReferenceResolver - deprecated
 
   /**
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 6e43b4e..7ac74f2 100644
--- a/src/test/java/com/intellij/struts2/dom/struts/StrutsHighlightingTest.java
+++ b/src/test/java/com/intellij/struts2/dom/struts/StrutsHighlightingTest.java
@@ -98,4 +98,8 @@ public class StrutsHighlightingTest extends 
StrutsLightHighlightingTestCase {
     performHighlightingTest("struts-http-method.xml");
   }
 
+  public void testExtensionTokens() {
+    performHighlightingTest("struts-extension.xml");
+  }
+
 }
diff --git a/src/test/testData/strutsXml/highlighting/struts-extension.xml 
b/src/test/testData/strutsXml/highlighting/struts-extension.xml
new file mode 100644
index 0000000..310c80f
--- /dev/null
+++ b/src/test/testData/strutsXml/highlighting/struts-extension.xml
@@ -0,0 +1,31 @@
+<?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="web" extension="action,<error descr="Invalid extension 
'.do'">.do</error>,<error descr="Invalid extension 'a/b'">a/b</error>,<error 
descr="Invalid extension 'x y'">x y</error>,">
+    <action name="plain" extension=","/>
+  </package>
+</struts>

Reply via email to