• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

torand / openapi2java / 18202480060

02 Oct 2025 06:44PM UTC coverage: 81.561% (-0.8%) from 82.388%
18202480060

push

github

web-flow
Merge pull request #48 from torand/refactor-info-classes

Refactor info classes

507 of 736 branches covered (68.89%)

Branch coverage included in aggregate %.

825 of 934 new or added lines in 38 files covered. (88.33%)

11 existing lines in 7 files now uncovered.

1541 of 1775 relevant lines covered (86.82%)

5.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.3
/src/main/java/io/github/torand/openapi2java/model/MethodInfo.java
1
/*
2
 * Copyright (c) 2024-2025 Tore Eide Andersen
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package io.github.torand.openapi2java.model;
17

18
import java.util.*;
19

20
import static java.util.Collections.emptyList;
21
import static java.util.Objects.nonNull;
22

23
/**
24
 * Describes a method.
25
 * @param name the method name.
26
 * @param parameters the method parameters.
27
 * @param returnType the method return type.
28
 * @param deprecationMessage the deprecation message, if any.
29
 * @param annotations the annotations decorating this method.
30
 */
31
public record MethodInfo (
18✔
32
    String name,
33
    List<MethodParamInfo> parameters,
34
    String returnType,
35
    String deprecationMessage,
36
    List<AnnotationInfo> annotations
37
) implements EntityInfo {
38

39
    /**
40
     * Constructs a {@link MethodInfo} object.
41
     * @param name the method name.
42
     */
43
    public MethodInfo(String name) {
44
        this(name, emptyList(), null, null, emptyList());
7✔
45
    }
1✔
46

47
    /**
48
     * Returns a new {@link MethodInfo} object with specified parameters added.
49
     * @param params the parameters to add.
50
     * @return the new and updated {@link MethodInfo} object.
51
     */
52
    public MethodInfo withAddedParameters(Collection<MethodParamInfo> params) {
53
        List<MethodParamInfo> newParameters = new LinkedList<>(parameters);
6✔
54
        newParameters.addAll(params);
4✔
55
        return new MethodInfo(name, newParameters, returnType, deprecationMessage, annotations);
13✔
56
    }
57

58
    /**
59
     * Returns a new {@link MethodInfo} object with specified return type.
60
     * @param returnType the return type.
61
     * @return the new and updated {@link MethodInfo} object.
62
     */
63
    public MethodInfo withReturnType(String returnType) {
64
        return new MethodInfo(name, parameters, returnType, deprecationMessage, annotations);
13✔
65
    }
66

67
    /**
68
     * Returns a new {@link MethodInfo} object with specified deprecation message.
69
     * @param deprecationMessage the deprecation message.
70
     * @return the new and updated {@link MethodInfo} object.
71
     */
72
    public MethodInfo withDeprecationMessage(String deprecationMessage) {
NEW
73
        return new MethodInfo(name, parameters, returnType, deprecationMessage, annotations);
×
74
    }
75

76
    /**
77
     * Returns a new {@link MethodInfo} object with specified annotation added.
78
     * @param annotation the annotation to add.
79
     * @return the new and updated {@link MethodInfo} object.
80
     */
81
    public MethodInfo withAddedAnnotation(AnnotationInfo annotation) {
82
        List<AnnotationInfo> newAnnotations = new LinkedList<>(this.annotations);
6✔
83
        newAnnotations.add(annotation);
4✔
84
        return new MethodInfo(name, parameters, returnType, deprecationMessage, newAnnotations);
13✔
85
    }
86

87
    /**
88
     * Returns a new {@link MethodInfo} object with specified annotations added.
89
     * @param annotations the annotations to add.
90
     * @return the new and updated {@link MethodInfo} object.
91
     */
92
    public MethodInfo withAddedAnnotations(Collection<AnnotationInfo> annotations) {
93
        MethodInfo merged = this;
2✔
94
        for (AnnotationInfo annotation : annotations) {
10✔
95
            merged = merged.withAddedAnnotation(annotation);
4✔
96
        }
1✔
97
        return merged;
2✔
98
    }
99

100
    /**
101
     * Indicates whether the method is deprecated.
102
     * @return true if method is deprecated; else false.
103
     */
104
    public boolean isDeprecated() {
105
        return nonNull(deprecationMessage);
4✔
106
    }
107

108
    @Override
109
    public Set<String> aggregatedNormalImports() {
110
        Set<String> aggregated = new TreeSet<>();
4✔
111
        parameters.stream().map(p -> p.aggregatedNormalImports()).forEach(aggregated::addAll);
14✔
112
        annotations.stream().map(a -> a.imports().normalImports()).forEach(aggregated::addAll);
15✔
113
        return aggregated;
2✔
114
    }
115

116
    @Override
117
    public Set<String> aggregatedStaticImports() {
118
        Set<String> aggregated = new TreeSet<>();
4✔
119
        parameters.stream().map(p -> p.aggregatedStaticImports()).forEach(aggregated::addAll);
14✔
120
        annotations.stream().map(a -> a.imports().staticImports()).forEach(aggregated::addAll);
15✔
121
        return aggregated;
2✔
122
    }
123
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc