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

aspectran / aspectran / #4075

19 Feb 2025 12:58PM CUT coverage: 35.181% (-0.004%) from 35.185%
#4075

push

github

topframe
Update

20 of 155 new or added lines in 9 files covered. (12.9%)

5 existing lines in 3 files now uncovered.

14252 of 40510 relevant lines covered (35.18%)

0.35 hits per line

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

62.07
/core/src/main/java/com/aspectran/core/context/rule/DescriptionRule.java
1
/*
2
 * Copyright (c) 2008-2025 The Aspectran Project
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 com.aspectran.core.context.rule;
17

18
import com.aspectran.core.activity.Activity;
19
import com.aspectran.core.context.asel.token.Token;
20
import com.aspectran.core.context.asel.token.TokenParser;
21
import com.aspectran.core.context.env.Profiles;
22
import com.aspectran.core.context.rule.ability.Replicable;
23
import com.aspectran.core.context.rule.type.TextStyleType;
24
import com.aspectran.utils.StringUtils;
25
import com.aspectran.utils.ToStringBuilder;
26
import com.aspectran.utils.annotation.jsr305.NonNull;
27

28
import java.util.ArrayList;
29
import java.util.List;
30

31
/**
32
 * <p>Created: 2019/12/17</p>
33
 */
34
public class DescriptionRule implements Replicable<DescriptionRule> {
35

36
    private String profile;
37

38
    private Profiles profiles;
39

40
    private TextStyleType contentStyle;
41

42
    private String content;
43

44
    private String formattedContent;
45

46
    private List<DescriptionRule> candidates;
47

48
    public DescriptionRule() {
1✔
49
    }
1✔
50

51
    public DescriptionRule(DescriptionRule other) {
1✔
52
        if (other != null) {
1✔
53
            setProfiles(other.getProfile(), other.getProfiles());
1✔
54
            setContentStyle(other.getContentStyle());
1✔
55
            setContent(other.getContent());
1✔
56
            setFormattedContent(other.getFormattedContent());
1✔
57
            setCandidates(other.getCandidates());
1✔
58
        }
59
    }
1✔
60

61
    public String getProfile() {
62
        return profile;
1✔
63
    }
64

65
    public void setProfile(String profile) {
66
        this.profile = profile;
×
67
        this.profiles = (profile != null ? Profiles.of(profile) : null);
×
68
    }
×
69

70
    public Profiles getProfiles() {
71
        return profiles;
1✔
72
    }
73

74
    private void setProfiles(String profile, Profiles profiles) {
75
        this.profile = profile;
1✔
76
        this.profiles = profiles;
1✔
77
    }
1✔
78

79
    public TextStyleType getContentStyle() {
80
        return contentStyle;
1✔
81
    }
82

83
    public void setContentStyle(TextStyleType contentStyle) {
84
        this.contentStyle = contentStyle;
1✔
85
    }
1✔
86

87
    public String getContent() {
88
        return content;
1✔
89
    }
90

91
    public void setContent(String content) {
92
        this.content = content;
1✔
93
    }
1✔
94

95
    public String getFormattedContent() {
96
        return (formattedContent != null ? formattedContent : content);
1✔
97
    }
98

99
    public void setFormattedContent(String formattedContent) {
100
        this.formattedContent = formattedContent;
1✔
101
    }
1✔
102

103
    public List<DescriptionRule> getCandidates() {
104
        return candidates;
1✔
105
    }
106

107
    public void setCandidates(List<DescriptionRule> candidates) {
108
        this.candidates = candidates;
1✔
109
    }
1✔
110

111
    public boolean addCandidate(DescriptionRule candidate) {
112
        if (candidates == null) {
1✔
113
            candidates = new ArrayList<>();
1✔
114
        }
115
        return candidates.add(candidate);
1✔
116
    }
117

118
    @Override
119
    public DescriptionRule replicate() {
120
        DescriptionRule dr = new DescriptionRule();
×
121
        dr.setProfiles(profile, profiles);
×
122
        dr.setContentStyle(contentStyle);
×
123
        dr.setContent(content);
×
124
        return dr;
×
125
    }
126

127
    @Override
128
    public String toString() {
129
        ToStringBuilder tsb = new ToStringBuilder();
×
130
        tsb.append("profile", profile);
×
131
        tsb.append("style", contentStyle);
×
132
        tsb.append("content", content);
×
133
        return tsb.toString();
×
134
    }
135

136
    public static String render(@NonNull DescriptionRule descriptionRule, Activity activity) {
137
        String content = descriptionRule.getFormattedContent();
×
138
        if (content == null || activity == null) {
×
139
            return content;
×
140
        }
141

142
        Token[] contentTokens = TokenParser.makeTokens(content, true);
×
143
        for (Token token : contentTokens) {
×
NEW
144
            Token.resolveValueProvider(token, activity.getClassLoader());
×
145
        }
146
        return activity.getTokenEvaluator().evaluateAsString(contentTokens);
×
147
    }
148

149
    @NonNull
150
    public static DescriptionRule newInstance(String profile, String style)
151
            throws IllegalRuleException {
152
        TextStyleType contentStyle = TextStyleType.resolve(style);
1✔
153
        if (style != null && contentStyle == null) {
1✔
154
            throw new IllegalRuleException("No text style type for '" + style + "'");
×
155
        }
156

157
        DescriptionRule dr = new DescriptionRule();
1✔
158
        dr.setContentStyle(contentStyle);
1✔
159
        if (StringUtils.hasText(profile)) {
1✔
160
            dr.setProfile(profile);
×
161
        }
162
        return dr;
1✔
163
    }
164

165
}
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

© 2025 Coveralls, Inc