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

hee9841 / excel-module / #18

08 Apr 2025 11:10AM UTC coverage: 82.835% (-0.3%) from 83.096%
#18

push

github

web-flow
Fix: 에러 메세지 수정(STY_CU_003_B, STG_CT_001_B,STG_ID_002_B 테스트 사항) (#46)

* Fix: 에러 메세지 수정(STY_CU_003_B, STG_CT_001_B,STG_ID_002_B 테스트 사항)

* Style: comment, 및 포멧 수정

1 of 1 new or added line in 1 file covered. (100.0%)

32 existing lines in 2 files now uncovered.

526 of 635 relevant lines covered (82.83%)

0.83 hits per line

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

0.0
/src/main/java/io/github/hee9841/excel/annotation/processor/ExcelAnnotationProcessor.java
1
package io.github.hee9841.excel.annotation.processor;
2

3
import io.github.hee9841.excel.annotation.Excel;
4
import java.util.Set;
5
import javax.annotation.processing.AbstractProcessor;
6
import javax.annotation.processing.Messager;
7
import javax.annotation.processing.ProcessingEnvironment;
8
import javax.annotation.processing.RoundEnvironment;
9
import javax.annotation.processing.SupportedAnnotationTypes;
10
import javax.lang.model.SourceVersion;
11
import javax.lang.model.element.Element;
12
import javax.lang.model.element.ElementKind;
13
import javax.lang.model.element.Modifier;
14
import javax.lang.model.element.TypeElement;
15
import javax.tools.Diagnostic;
16

17
/**
18
 * Annotation processor for handling {@code @Excel} annotations.
19
 * This processor validates classes annotated with {@code @Excel} to ensure they meet
20
 * the required criteria for Excel processing.
21
 *
22
 * <p>Supported criteria:
23
 * <ul>
24
 *     <li>Can be applied to regular classes or record classes</li>
25
 *     <li>Target class must not be abstract</li>
26
 * </ul>
27
 */
28
@SupportedAnnotationTypes("io.github.hee9841.excel.annotation.Excel")
UNCOV
29
public class ExcelAnnotationProcessor extends AbstractProcessor {
×
30

31
    private Messager messager;
32

33
    @Override
34
    public synchronized void init(ProcessingEnvironment processingEnv) {
UNCOV
35
        super.init(processingEnv);
×
UNCOV
36
        messager = processingEnv.getMessager();
×
UNCOV
37
    }
×
38

39
    @Override
40
    public SourceVersion getSupportedSourceVersion() {
41
        return SourceVersion.latestSupported();
×
42
    }
43

44
    @Override
45
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
46
        boolean hasError = false;
×
47

48
        for (Element element : roundEnv.getElementsAnnotatedWith(Excel.class)) {
×
49
            if (!isValidExcelClass(element)) {
×
50
                hasError = true;
×
51
            }
52
        }
×
53

54
        return !hasError;
×
55
    }
56

57
    /**
58
     * Validates if the element annotated with {@code @Excel} meets the required criteria.
59
     * The following conditions are checked:
60
     * <ul>
61
     *     <li>Element must be either a regular class or a record class</li>
62
     *     <li>If it's a regular class, it must not be abstract</li>
63
     * </ul>
64
     *
65
     * @param element the element to validate, typically a class or record annotated with
66
     *                {@code @Excel}
67
     * @return true if the element meets all validation criteria, false if any validation fails
68
     * (error messages will be reported via {@link #error(Element, String, Object...)})
69
     * @see Excel
70
     */
71
    private boolean isValidExcelClass(Element element) {
72

73
        // Check for record class in Java 14 and above
74
        if (element.getKind().name().equals("RECORD")) {
×
UNCOV
75
            return true;
×
76
        }
77

78
        if (element.getKind() != ElementKind.CLASS) {
×
UNCOV
79
            error(element,
×
80
                "@%s can only be applied to classes or record classes",
UNCOV
81
                Excel.class.getSimpleName()
×
82
            );
UNCOV
83
            return false;
×
84
        }
85

UNCOV
86
        TypeElement typeElement = (TypeElement) element;
×
87

88
        // The class must not be an abstract class.
89
        if (typeElement.getModifiers().contains(Modifier.ABSTRACT)) {
×
UNCOV
90
            error(element,
×
91
                "The class %s is abstract. You can't annotate abstract classes with @%s",
UNCOV
92
                typeElement.getQualifiedName().toString(), Excel.class.getSimpleName());
×
93

UNCOV
94
            return false;
×
95
        }
96

UNCOV
97
        return true;
×
98
    }
99

100
    /**
101
     * Reports an error for the given element.
102
     *
103
     * @param e    the element for which to report the error
104
     * @param msg  the error message with format specifiers
105
     * @param args arguments referenced by the format specifiers in the message
106
     */
107
    private void error(Element e, String msg, Object... args) {
UNCOV
108
        messager.printMessage(
×
109
            Diagnostic.Kind.ERROR,
UNCOV
110
            String.format(msg, args),
×
111
            e);
UNCOV
112
    }
×
113
}
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