Skip to content

Commit

Permalink
Remove Guava usage, and clean up processor (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
niloc132 authored Jul 15, 2021
1 parent ddbb670 commit 99d2afb
Showing 1 changed file with 10 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
import static java.util.stream.Collectors.toSet;

import com.google.auto.service.AutoService;
import com.google.common.base.Stopwatch;
import com.google.common.primitives.Primitives;
import com.squareup.javapoet.*;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.ParameterSpec;
import com.squareup.javapoet.TypeSpec;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
Expand All @@ -33,7 +36,6 @@
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;
import javax.tools.Diagnostic;
import javax.tools.Diagnostic.Kind;
import org.gwtproject.safecss.shared.SafeStyles;
Expand All @@ -45,9 +47,7 @@ public class SafeHtmlProcessor extends AbstractProcessor {

private Messager messager;
private Filer filer;
private Types types;
private Elements elements;
private Stopwatch stopwatch;

@Override
public Set<String> getSupportedAnnotationTypes() {
Expand All @@ -65,22 +65,14 @@ public synchronized void init(ProcessingEnvironment processingEnv) {

this.messager = processingEnv.getMessager();
this.filer = processingEnv.getFiler();
this.types = processingEnv.getTypeUtils();
this.elements = processingEnv.getElementUtils();

this.createMessage(Kind.NOTE, "GWT-SafeHTML-Processor (version: HEAD-SNAPSHOT) started ...");

this.stopwatch = Stopwatch.createStarted();
this.createMessage(Kind.NOTE, "GWT-SafeHTML-Processor started ...");
}

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver()) {
this.createMessage(
Kind.NOTE,
"GWT-editor-Processor finished ... processing takes: "
+ this.stopwatch.stop().toString());
} else {
if (!roundEnv.processingOver()) {
if (annotations.size() > 0) {
T types = new T();
Set<TypeElement> templateTypes =
Expand Down Expand Up @@ -143,7 +135,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
continue;
}
try {
templateTypeSpec.addMethod(this.generateMethod(templateType, template, method));
templateTypeSpec.addMethod(this.generateMethod(template, method));
} catch (SafeHtmlProcessorException e) {
this.createMessage(
Kind.ERROR,
Expand Down Expand Up @@ -186,8 +178,7 @@ private AnnotationMirror getAnnotationWithName(ExecutableElement elt, String nam
.orElse(null);
}

private MethodSpec generateMethod(
TypeElement templateType, AnnotationMirror template, ExecutableElement method)
private MethodSpec generateMethod(AnnotationMirror template, ExecutableElement method)
throws SafeHtmlProcessorException {
final String templateString = getTemplateString(template);
MethodSpec.Builder templateMethod =
Expand Down Expand Up @@ -623,7 +614,7 @@ private void emitAttributeContextParameterExpression(
/**
* Escapes string content to be a valid string literal.
*
* @param unescaped
* @param unescaped the string to escape
* @return an escaped version of <code>unescaped</code>, suitable for being enclosed in double
* quotes in Java source
*/
Expand Down Expand Up @@ -684,7 +675,6 @@ private void createMessage(Kind kind, String message) {
private void createMessage(Kind kind, String message, ExecutableElement method) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
String messageValue = message;
if (method != null) {
message = message + " --> " + method.toString();
}
Expand All @@ -693,41 +683,7 @@ private void createMessage(Kind kind, String message, ExecutableElement method)
this.messager.printMessage(kind, sw.toString());
}

private String[] getParamTypes(ExecutableElement method) {
String[] params = new String[method.getParameters().size()];
int i = 0;
for (VariableElement variableElement : method.getParameters()) {
params[i++] = variableElement.asType().toString();
}
return params;
}

/**
* Convenience method to use TreeLogger error pattern.
*
* @param msg msg
* @param element element causing error
* @return the exception to throw
*/
private SafeHtmlProcessorException error(String msg, Throwable cause, Element element) {
messager.printMessage(Diagnostic.Kind.ERROR, msg + ": " + cause.getMessage(), element);
return new SafeHtmlProcessorException();
}

/**
* Convenience method to use TreeLogger error pattern.
*
* @param e throwable
* @param element element causing error
* @return th exception to throw
*/
private SafeHtmlProcessorException error(Throwable e, Element element) {
messager.printMessage(Diagnostic.Kind.ERROR, e.getMessage() + ": " + e.getMessage(), element);
return new SafeHtmlProcessorException();
}

private class T {

DeclaredType jlObject =
(DeclaredType)
processingEnv
Expand Down

0 comments on commit 99d2afb

Please sign in to comment.