7
7
8
8
import org .bsc .processor .BaseAbstractProcessor ;
9
9
10
- import java . io . IOException ;
11
- import java . util . Set ;
12
-
13
- import javax .annotation .processing .* ;
10
+ import javax . annotation . processing . Filer ;
11
+ import javax . annotation . processing . RoundEnvironment ;
12
+ import javax . annotation . processing . SupportedAnnotationTypes ;
13
+ import javax .annotation .processing .SupportedSourceVersion ;
14
14
import javax .lang .model .SourceVersion ;
15
15
import javax .lang .model .element .Element ;
16
16
import javax .lang .model .element .ElementKind ;
17
17
import javax .lang .model .element .TypeElement ;
18
- import javax .tools .Diagnostic .Kind ;
19
18
import javax .tools .FileObject ;
20
19
import javax .tools .StandardLocation ;
20
+ import java .io .IOException ;
21
+ import java .util .Set ;
21
22
22
23
/**
23
24
*
24
25
* @author softphone
25
26
*
26
27
*
27
28
*/
28
- //@SupportedSourceVersion(SourceVersion.RELEASE_9 )
29
- @ SupportedSourceVersion (SourceVersion .RELEASE_8 )
29
+ //@SupportedSourceVersion(SourceVersion.RELEASE_8 )
30
+ @ SupportedSourceVersion (SourceVersion .RELEASE_9 )
30
31
@ SupportedAnnotationTypes ( "*" )
31
32
//@SupportedOptions( {"subfolder", "filepath", "templateUri"})
32
33
//@SupportedAnnotationTypes( {"javax.ws.rs.GET", "javax.ws.rs.PUT", "javax.ws.rs.POST", "javax.ws.rs.DELETE"})
@@ -39,50 +40,46 @@ public class TESTWikiProcessor extends BaseAbstractProcessor {
39
40
* @throws IOException
40
41
*/
41
42
protected FileObject getResourceFormClassPath (Filer filer , final String resource , final String packageName ) throws IOException {
42
- FileObject f = filer .getResource (StandardLocation .CLASS_PATH , packageName , resource );
43
+ final FileObject f = filer .getResource (StandardLocation .CLASS_PATH , packageName , resource );
43
44
44
45
//java.io.Reader r = f.openReader(true); // ignoreEncodingErrors
45
- java .io .InputStream is = f .openInputStream ();
46
+ try ( java .io .InputStream is = f .openInputStream ()) {
46
47
47
- if ( is ==null ) {
48
- warn ( String .format ("resource [%s] not found!" , resource ) );
49
- return null ;
48
+ if (is == null ) {
49
+ warn ("resource [%s] not found!" , resource );
50
+ return null ;
51
+ }
50
52
}
51
-
52
53
return f ;
53
54
}
54
55
56
+ /**
57
+ *
58
+ * @param annotations
59
+ * @param roundEnv
60
+ * @return
61
+ */
55
62
@ Override
56
63
public boolean process (Set <? extends TypeElement > annotations , RoundEnvironment roundEnv ) {
57
64
if (roundEnv .processingOver ()) return false ;
58
65
59
-
60
66
final java .util .Map <String ,String > optionMap = processingEnv .getOptions ();
61
67
62
- System .out .println ( "====> PROCESSOR RUN" );
63
- for ( java .util .Map .Entry <String ,String > k : optionMap .entrySet () )
64
- System .out .printf ( "\t [%s] = [%s]\n " , k .getKey (), k .getValue ());
65
-
68
+ info ( "====> PROCESSOR RUN" );
69
+ optionMap .entrySet ().forEach ( k -> info ( "\t [%s] = [%s]" , k .getKey (), k .getValue ()));
70
+
66
71
for ( TypeElement e : annotations ) {
67
72
68
- for (Element re : roundEnv .getElementsAnnotatedWith (e )) {
73
+ for (Element re : roundEnv .getElementsAnnotatedWith (e )) {
69
74
70
75
if ( re .getKind ()==ElementKind .METHOD ) {
71
76
72
- info ( String . format ( "[%s], Element [%s] is [%s] " , re .getEnclosingElement (), re .getKind (), re .getSimpleName ()) );
77
+ info ( "[%s], Element [%s] is [%s]" , re .getEnclosingElement (), re .getKind (), re .getSimpleName () );
73
78
74
79
}
75
80
}
76
81
}
77
82
78
- //final Filer filer = processingEnv.getFiler();
79
-
80
- //FileObject res = getOutputFile(filer, subfolder, filePath);
81
-
82
- //java.io.Writer w = res.openWriter();
83
-
84
- //w.close();
85
-
86
83
return true ;
87
84
}
88
85
0 commit comments