This repository has been archived by the owner on Nov 17, 2017. It is now read-only.
/
CdkProcessorImpl.java
125 lines (102 loc) · 3.55 KB
/
CdkProcessorImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* $Id$
*
* License Agreement.
*
* Rich Faces - Natural Ajax for Java Server Faces (JSF)
*
* Copyright (C) 2007 Exadel, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.richfaces.cdk.apt;
import java.util.Collections;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;
import org.richfaces.cdk.Logger;
import org.richfaces.cdk.TimeMeasure;
import com.google.inject.Inject;
/**
* <p class="changed_added_4_0">
* Base class for all CDK Annotation processors. That class provides access to current CDK context and utility methods for Java
* source models.
* </p>
*
* @author asmirnov@exadel.com
*
*/
public class CdkProcessorImpl extends AbstractProcessor implements CdkProcessor {
private static final Set<String> PROCESSED_ANNOTATION = Collections.singleton("*");
@Inject
private SourceUtilsProvider sourceUtilsProducer;
@Inject
private LibraryCompiler compiler;
@Inject
private LibraryGenerator generator;
@Inject
private Logger log;
private boolean firstRound = true;
private TimeMeasure time;
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
sourceUtilsProducer.setProcessingEnv(processingEnv);
}
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (time == null) {
time = new TimeMeasure("java source processing", log).info(true);
}
if (!roundEnv.processingOver()) {
if (firstRound) {
firstRound = false;
compiler.beforeJavaSourceProcessing();
time.start();
}
compiler.processJavaSource(processingEnv, roundEnv);
} else {
time.stop();
compiler.afterJavaSourceProcessing();
continueAfterJavaSourceProcessing();
}
return false;
}
@Override
public void continueAfterJavaSourceProcessing() {
time = new TimeMeasure("non-java source processing", log).info(true).start();
compiler.processNonJavaSources();
time.stop();
time = new TimeMeasure("library verification", log).info(true).start();
compiler.verify();
time.stop();
if (0 == log.getErrorCount()) {
time = new TimeMeasure("library generation", log).info(true).start();
generator.generate();
time.stop();
}
}
@Override
public Set<String> getSupportedAnnotationTypes() {
return PROCESSED_ANNOTATION;
}
@Override
public SourceVersion getSupportedSourceVersion() {
// CDK supports Java 5 or 6 source code.
return SourceVersion.RELEASE_6;
}
}