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 0c0a4bbc44f29ef9043fb3a4dd13d76b46b7e688 Author: Lukasz Lenart <[email protected]> AuthorDate: Wed Nov 11 19:20:40 2026 +0100 feat: complete and check action http-method Accept the nine HTTP methods in any case and highlight any other token. Co-authored-by: Cursor <[email protected]> --- .../intellij/struts2/dom/struts/action/Action.java | 4 ++ .../dom/struts/action/HttpMethodConverter.java | 67 ++++++++++++++++++++++ .../struts2/dom/struts/StrutsCompletionTest.java | 7 ++- .../struts2/dom/struts/StrutsHighlightingTest.java | 4 ++ .../struts-completionvariants-http-method.xml | 31 ++++++++++ .../strutsXml/highlighting/struts-http-method.xml | 31 ++++++++++ 6 files changed, 143 insertions(+), 1 deletion(-) 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 565be33..d57670a 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 @@ -62,6 +62,10 @@ public interface Action extends ParamsElement { @Convert(ActionMethodConverter.class) GenericAttributeValue<PsiMethod> getMethod(); + @Attribute("http-method") + @Convert(HttpMethodConverter.class) + GenericAttributeValue<String> getHttpMethod(); + // -------------------- @SubTagList("result") diff --git a/src/main/java/com/intellij/struts2/dom/struts/action/HttpMethodConverter.java b/src/main/java/com/intellij/struts2/dom/struts/action/HttpMethodConverter.java new file mode 100644 index 0000000..ab96878 --- /dev/null +++ b/src/main/java/com/intellij/struts2/dom/struts/action/HttpMethodConverter.java @@ -0,0 +1,67 @@ +/* + * 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.action; + +import com.intellij.psi.PsiElement; +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.Nullable; + +import java.util.List; +import java.util.Locale; + +public class HttpMethodConverter extends DelimitedListConverter<String> { + + static final List<String> HTTP_METHODS = List.of( + "GET", "HEAD", "POST", "PUT", "DELETE", "TRACE", "OPTIONS", "CONNECT", "PATCH"); + + public HttpMethodConverter() { + super(","); + } + + @Override + protected String convertString(@Nullable String token, ConvertContext context) { + if (token != null && HTTP_METHODS.contains(token.toUpperCase(Locale.ROOT))) { + 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 HTTP_METHODS.toArray(); + } + + @Override + protected PsiElement resolveReference(@Nullable String token, ConvertContext context) { + if (token != null && HTTP_METHODS.contains(token.toUpperCase(Locale.ROOT))) { + return DomUtil.getValueElement((GenericDomValue<?>) context.getInvocationElement()); + } + return null; + } + + @Override + protected String getUnresolvedMessage(String token) { + return "Cannot resolve http-method '" + token + "'"; + } +} diff --git a/src/test/java/com/intellij/struts2/dom/struts/StrutsCompletionTest.java b/src/test/java/com/intellij/struts2/dom/struts/StrutsCompletionTest.java index 028d1a7..c8ee85a 100644 --- a/src/test/java/com/intellij/struts2/dom/struts/StrutsCompletionTest.java +++ b/src/test/java/com/intellij/struts2/dom/struts/StrutsCompletionTest.java @@ -121,4 +121,9 @@ public class StrutsCompletionTest extends StrutsLightHighlightingTestCase { performCompletionVariantTest("struts-completionvariants-scoped-constant-theme-value.xml", "ajax", "css_xhtml", "html5", "simple", "xhtml"); } -} \ No newline at end of file + + public void testCompletionVariantsHttpMethod() { + performCompletionVariantTest("struts-completionvariants-http-method.xml", + "CONNECT", "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT", "TRACE"); + } +} 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 5563dd0..6e43b4e 100644 --- a/src/test/java/com/intellij/struts2/dom/struts/StrutsHighlightingTest.java +++ b/src/test/java/com/intellij/struts2/dom/struts/StrutsHighlightingTest.java @@ -94,4 +94,8 @@ public class StrutsHighlightingTest extends StrutsLightHighlightingTestCase { performHighlightingTest("struts-scoped-constant.xml"); } + public void testHttpMethod() { + performHighlightingTest("struts-http-method.xml"); + } + } diff --git a/src/test/testData/strutsXml/completion/struts-completionvariants-http-method.xml b/src/test/testData/strutsXml/completion/struts-completionvariants-http-method.xml new file mode 100644 index 0000000..acf6efe --- /dev/null +++ b/src/test/testData/strutsXml/completion/struts-completionvariants-http-method.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"> + <action name="save" http-method="<caret>"/> + </package> +</struts> diff --git a/src/test/testData/strutsXml/highlighting/struts-http-method.xml b/src/test/testData/strutsXml/highlighting/struts-http-method.xml new file mode 100644 index 0000000..7ac0959 --- /dev/null +++ b/src/test/testData/strutsXml/highlighting/struts-http-method.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"> + <action name="save" http-method="post,<error descr="Cannot resolve http-method 'FOO'">FOO</error>"/> + </package> +</struts>
