Repository navigation
fix: reject unnamed method parameters #470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
AndreasIgel
merged 5 commits into
java-helpers:main
from
igel-devin-ai:devin/1796080476-issue-454-unnamed-parameters
Dec 2, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7f19c7d
fix: reject unnamed method parameters
devin-ai-integration[bot] 1ec8760
Merge remote-tracking branch 'upstream/main' into devin/1796080476-is…
devin-ai-integration[bot] cffd9ca
merge: resolve upstream parameter handling
devin-ai-integration[bot] 9b6ff96
feat: validate generation targets before backend generation
devin-ai-integration[bot] 90371c6
refactor: keep parameter validation outside roaster
devin-ai-integration[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...processor/src/main/java/org/javahelpers/codegen/processing/GenerationTargetValidator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* | ||
| * MIT License | ||
| * | ||
| * Copyright (c) 2025-2026 Andreas Igel | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in all | ||
| * copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| * SOFTWARE. | ||
| */ | ||
|
|
||
| package org.javahelpers.codegen.processing; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.javahelpers.codegen.CodeGenerationException; | ||
| import org.javahelpers.codegen.model.core.GenerationTargetClassDto; | ||
| import org.javahelpers.codegen.model.method.MethodDto; | ||
| import org.javahelpers.codegen.model.method.MethodParameterDto; | ||
| import org.javahelpers.codegen.model.type.NestedTypeDto; | ||
|
|
||
| /** Validates generation-target DTOs before a backend-specific generator is invoked. */ | ||
| public final class GenerationTargetValidator { | ||
|
|
||
| private GenerationTargetValidator() {} | ||
|
|
||
| /** | ||
| * Validates a generation target. | ||
| * | ||
| * @param target target class definition | ||
| * @throws CodeGenerationException if the target is invalid | ||
| */ | ||
| public static void validate(GenerationTargetClassDto target) throws CodeGenerationException { | ||
| for (var constructor : target.getConstructors()) { | ||
| validateParameters(target, constructor.getParameters(), "constructor"); | ||
| } | ||
| for (MethodDto method : target.getMethods()) { | ||
| validateMethod(target, method); | ||
| } | ||
| for (NestedTypeDto nestedType : target.getNestedTypes()) { | ||
| for (MethodDto method : nestedType.getMethods()) { | ||
| validateMethod(target, method); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static void validateMethod(GenerationTargetClassDto target, MethodDto method) | ||
| throws CodeGenerationException { | ||
| validateParameters(target, method.getParameters(), "method '" + method.getMethodName() + "'"); | ||
| } | ||
|
|
||
| private static void validateParameters( | ||
| GenerationTargetClassDto target, Iterable<MethodParameterDto> parameters, String owner) | ||
| throws CodeGenerationException { | ||
| for (MethodParameterDto parameter : parameters) { | ||
| if (StringUtils.isBlank(parameter.getParameterName())) { | ||
| throw new CodeGenerationException( | ||
| "Unnamed parameter in " + owner + " of " + target.getTypeName().getFullQualifiedName()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
82 changes: 82 additions & 0 deletions
82
...essor/src/test/java/org/javahelpers/codegen/processing/GenerationTargetValidatorTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /* | ||
| * MIT License | ||
| * | ||
| * Copyright (c) 2025-2026 Andreas Igel | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in all | ||
| * copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| * SOFTWARE. | ||
| */ | ||
|
|
||
| package org.javahelpers.codegen.processing; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| import org.javahelpers.codegen.CodeGenerationException; | ||
| import org.javahelpers.codegen.model.core.GenerationTargetClassDtoBuilder; | ||
| import org.javahelpers.codegen.model.method.MethodDto; | ||
| import org.javahelpers.codegen.model.method.MethodParameterDto; | ||
| import org.javahelpers.codegen.model.type.TypeName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** Tests for backend-independent generation-target validation. */ | ||
| class GenerationTargetValidatorTest { | ||
|
|
||
| /** Blank method parameter names are rejected before backend generation. */ | ||
| @Test | ||
| void blankMethodParameterFails() { | ||
| MethodDto method = new MethodDto(); | ||
| method.setMethodName("run"); | ||
| method.addParameter(unnamedParameter()); | ||
|
|
||
| CodeGenerationException thrown = | ||
| assertThrows( | ||
| CodeGenerationException.class, | ||
| () -> | ||
| GenerationTargetValidator.validate( | ||
| GenerationTargetClassDtoBuilder.create() | ||
| .typeName("com.example", "Target") | ||
| .method(method) | ||
| .build())); | ||
|
|
||
| assertEquals("Unnamed parameter in method 'run' of com.example.Target", thrown.getMessage()); | ||
| } | ||
|
|
||
| /** Blank constructor parameter names are rejected before backend generation. */ | ||
| @Test | ||
| void blankConstructorParameterFails() { | ||
| CodeGenerationException thrown = | ||
| assertThrows( | ||
| CodeGenerationException.class, | ||
| () -> | ||
| GenerationTargetValidator.validate( | ||
| GenerationTargetClassDtoBuilder.create() | ||
| .typeName("com.example", "Target") | ||
| .constructor(c -> c.parameter(unnamedParameter())) | ||
| .build())); | ||
|
|
||
| assertEquals("Unnamed parameter in constructor of com.example.Target", thrown.getMessage()); | ||
| } | ||
|
|
||
| private static MethodParameterDto unnamedParameter() { | ||
| MethodParameterDto parameter = new MethodParameterDto(); | ||
| parameter.setParameterTypeName(TypeName.of(String.class)); | ||
| parameter.setParameterName(" "); | ||
| return parameter; | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.