1818import static java .util .stream .Collectors .toSet ;
1919
2020import com .google .auto .service .AutoService ;
21- import com .google .common .base .Stopwatch ;
2221import com .google .common .primitives .Primitives ;
23- import com .squareup .javapoet .*;
22+ import com .squareup .javapoet .ClassName ;
23+ import com .squareup .javapoet .JavaFile ;
24+ import com .squareup .javapoet .MethodSpec ;
25+ import com .squareup .javapoet .ParameterSpec ;
26+ import com .squareup .javapoet .TypeSpec ;
2427import java .io .IOException ;
2528import java .io .PrintWriter ;
2629import java .io .StringWriter ;
3336import javax .lang .model .type .DeclaredType ;
3437import javax .lang .model .type .TypeMirror ;
3538import javax .lang .model .util .Elements ;
36- import javax .lang .model .util .Types ;
3739import javax .tools .Diagnostic ;
3840import javax .tools .Diagnostic .Kind ;
3941import org .gwtproject .safecss .shared .SafeStyles ;
@@ -45,9 +47,7 @@ public class SafeHtmlProcessor extends AbstractProcessor {
4547
4648 private Messager messager ;
4749 private Filer filer ;
48- private Types types ;
4950 private Elements elements ;
50- private Stopwatch stopwatch ;
5151
5252 @ Override
5353 public Set <String > getSupportedAnnotationTypes () {
@@ -65,22 +65,14 @@ public synchronized void init(ProcessingEnvironment processingEnv) {
6565
6666 this .messager = processingEnv .getMessager ();
6767 this .filer = processingEnv .getFiler ();
68- this .types = processingEnv .getTypeUtils ();
6968 this .elements = processingEnv .getElementUtils ();
7069
71- this .createMessage (Kind .NOTE , "GWT-SafeHTML-Processor (version: HEAD-SNAPSHOT) started ..." );
72-
73- this .stopwatch = Stopwatch .createStarted ();
70+ this .createMessage (Kind .NOTE , "GWT-SafeHTML-Processor started ..." );
7471 }
7572
7673 @ Override
7774 public boolean process (Set <? extends TypeElement > annotations , RoundEnvironment roundEnv ) {
78- if (roundEnv .processingOver ()) {
79- this .createMessage (
80- Kind .NOTE ,
81- "GWT-editor-Processor finished ... processing takes: "
82- + this .stopwatch .stop ().toString ());
83- } else {
75+ if (!roundEnv .processingOver ()) {
8476 if (annotations .size () > 0 ) {
8577 T types = new T ();
8678 Set <TypeElement > templateTypes =
@@ -143,7 +135,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
143135 continue ;
144136 }
145137 try {
146- templateTypeSpec .addMethod (this .generateMethod (templateType , template , method ));
138+ templateTypeSpec .addMethod (this .generateMethod (template , method ));
147139 } catch (SafeHtmlProcessorException e ) {
148140 this .createMessage (
149141 Kind .ERROR ,
@@ -186,8 +178,7 @@ private AnnotationMirror getAnnotationWithName(ExecutableElement elt, String nam
186178 .orElse (null );
187179 }
188180
189- private MethodSpec generateMethod (
190- TypeElement templateType , AnnotationMirror template , ExecutableElement method )
181+ private MethodSpec generateMethod (AnnotationMirror template , ExecutableElement method )
191182 throws SafeHtmlProcessorException {
192183 final String templateString = getTemplateString (template );
193184 MethodSpec .Builder templateMethod =
@@ -623,7 +614,7 @@ private void emitAttributeContextParameterExpression(
623614 /**
624615 * Escapes string content to be a valid string literal.
625616 *
626- * @param unescaped
617+ * @param unescaped the string to escape
627618 * @return an escaped version of <code>unescaped</code>, suitable for being enclosed in double
628619 * quotes in Java source
629620 */
@@ -684,7 +675,6 @@ private void createMessage(Kind kind, String message) {
684675 private void createMessage (Kind kind , String message , ExecutableElement method ) {
685676 StringWriter sw = new StringWriter ();
686677 PrintWriter pw = new PrintWriter (sw );
687- String messageValue = message ;
688678 if (method != null ) {
689679 message = message + " --> " + method .toString ();
690680 }
@@ -693,41 +683,7 @@ private void createMessage(Kind kind, String message, ExecutableElement method)
693683 this .messager .printMessage (kind , sw .toString ());
694684 }
695685
696- private String [] getParamTypes (ExecutableElement method ) {
697- String [] params = new String [method .getParameters ().size ()];
698- int i = 0 ;
699- for (VariableElement variableElement : method .getParameters ()) {
700- params [i ++] = variableElement .asType ().toString ();
701- }
702- return params ;
703- }
704-
705- /**
706- * Convenience method to use TreeLogger error pattern.
707- *
708- * @param msg msg
709- * @param element element causing error
710- * @return the exception to throw
711- */
712- private SafeHtmlProcessorException error (String msg , Throwable cause , Element element ) {
713- messager .printMessage (Diagnostic .Kind .ERROR , msg + ": " + cause .getMessage (), element );
714- return new SafeHtmlProcessorException ();
715- }
716-
717- /**
718- * Convenience method to use TreeLogger error pattern.
719- *
720- * @param e throwable
721- * @param element element causing error
722- * @return th exception to throw
723- */
724- private SafeHtmlProcessorException error (Throwable e , Element element ) {
725- messager .printMessage (Diagnostic .Kind .ERROR , e .getMessage () + ": " + e .getMessage (), element );
726- return new SafeHtmlProcessorException ();
727- }
728-
729686 private class T {
730-
731687 DeclaredType jlObject =
732688 (DeclaredType )
733689 processingEnv
0 commit comments