Skip to content

Commit

Permalink
Cleanup a bunch of errors/warnings including java7/java8 style.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjudd committed Nov 19, 2017
1 parent 9c82c42 commit b227776
Show file tree
Hide file tree
Showing 311 changed files with 1,717 additions and 1,421 deletions.
8 changes: 4 additions & 4 deletions annotation/compiler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ dependencies {
// from https://code.google.com/archive/p/jarjar/downloads
jarjar files('libs/jarjar-1.4.jar')

compileOnly 'com.squareup:javapoet:1.9.0'
compileOnly 'com.google.auto.service:auto-service:1.0-rc3'
compileOnly 'com.google.code.findbugs:jsr305:3.0.1'
compileOnly "com.squareup:javapoet:${JAVAPOET_VERSION}"
compileOnly "com.google.auto.service:auto-service:${AUTO_SERVICE_VERSION}"
compileOnly "com.google.code.findbugs:jsr305:${JSR_305_VERSION}"
compile project(':annotation')
// This is to support com.sun.tootls.javac.util.List, currently used in RootModuleGenerator.
// This is to support com.sun.tools.javac.util.List, currently used in RootModuleGenerator.
compile files(Jvm.current().getToolsJar())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ private void writeRequestBuilder(String packageName, TypeSpec requestBuilder) {
}

private static final class FoundIndexedClassNames {
final Set<String> glideModules;
final Set<String> extensions;
private final Set<String> glideModules;
private final Set<String> extensions;

private FoundIndexedClassNames(Set<String> glideModules, Set<String> extensions) {
this.glideModules = glideModules;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class ExtensionProcessor {
extensionValidator = new GlideExtensionValidator(processingEnvironment, processorUtil);
}

boolean processExtensions(Set<? extends TypeElement> set, RoundEnvironment env) {
boolean processExtensions(RoundEnvironment env) {
List<TypeElement> elements = processorUtil.getElementsFor(GlideExtension.class, env);
processorUtil.debugLog("Processing types : " + elements);
for (TypeElement typeElement : elements) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public final class GlideAnnotationProcessor extends AbstractProcessor {
private AppModuleProcessor appModuleProcessor;
private boolean isGeneratedAppGlideModuleWritten;
private ExtensionProcessor extensionProcessor;
private boolean isGeneratedAppGlideModulePending;

@Override
public synchronized void init(ProcessingEnvironment processingEnvironment) {
Expand Down Expand Up @@ -117,15 +116,14 @@ public boolean process(Set<? extends TypeElement> set, RoundEnvironment env) {
// return false;
// }
processorUtil.process();
boolean newModulesWritten = libraryModuleProcessor.processModules(set, env);
boolean newExtensionWritten = extensionProcessor.processExtensions(set, env);
boolean newModulesWritten = libraryModuleProcessor.processModules(env);
boolean newExtensionWritten = extensionProcessor.processExtensions(env);
appModuleProcessor.processModules(set, env);

if (newExtensionWritten || newModulesWritten) {
if (isGeneratedAppGlideModuleWritten) {
throw new IllegalStateException("Cannot process annotations after writing AppGlideModule");
}
isGeneratedAppGlideModulePending = true;
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,7 @@ private boolean typeMatchesExpected(
}
TypeMirror argument = typeArguments.get(0);
String expected = getGlideTypeValue(executableElement);
if (!argument.toString().equals(expected)) {
return false;
}
return true;
return argument.toString().equals(expected);
}

private boolean isRequestBuilder(TypeMirror typeMirror) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,20 @@ public ParameterSpec apply(VariableElement input) {
builder.returns(ClassName.get(element));
}

String code = returnsValue ? "return " : "";
code += "$T.$N(";
StringBuilder code = new StringBuilder(returnsValue ? "return " : "");
code.append("$T.$N(");
List<Object> args = new ArrayList<>();
args.add(ClassName.get(glideType));
args.add(methodToOverride.getSimpleName());
if (!parameters.isEmpty()) {
for (VariableElement param : parameters) {
code += "$L, ";
code.append("$L, ");
args.add(param.getSimpleName());
}
code = code.substring(0, code.length() - 2);
code = new StringBuilder(code.substring(0, code.length() - 2));
}
code += ")";
builder.addStatement(code, args.toArray(new Object[0]));
code.append(")");
builder.addStatement(code.toString(), args.toArray(new Object[0]));
return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,15 @@ private static TypeSpec generate(List<TypeElement> libraryModules,
annotationBuilder.addMember(value, "$S", ClassName.get(childModule).toString());
}

String indexerName = INDEXER_NAME_PREFIX + annotation.getSimpleName() + "_";
StringBuilder indexerName = new StringBuilder(
INDEXER_NAME_PREFIX + annotation.getSimpleName() + "_");
for (TypeElement element : libraryModules) {
indexerName += element.getQualifiedName().toString().replace(".", "_");
indexerName += "_";
indexerName.append(element.getQualifiedName().toString().replace(".", "_"));
indexerName.append("_");
}
indexerName = indexerName.substring(0, indexerName.length() - 1);
indexerName = new StringBuilder(indexerName.substring(0, indexerName.length() - 1));

return TypeSpec.classBuilder(indexerName)
return TypeSpec.classBuilder(indexerName.toString())
.addAnnotation(annotationBuilder.build())
.addModifiers(Modifier.PUBLIC)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* {@code LibraryGlideModule}s.
*/
final class LibraryModuleProcessor {
private ProcessorUtil processorUtil;
private IndexerGenerator indexerGenerator;
private final ProcessorUtil processorUtil;
private final IndexerGenerator indexerGenerator;

LibraryModuleProcessor(ProcessorUtil processorUtil, IndexerGenerator indexerGenerator) {
this.processorUtil = processorUtil;
this.indexerGenerator = indexerGenerator;
}

boolean processModules(Set<? extends TypeElement> set, RoundEnvironment env) {
boolean processModules(RoundEnvironment env) {
// Order matters here, if we find an Indexer below, we return before writing the root module.
// If we fail to add to appModules before then, we might accidentally skip a valid RootModule.
List<TypeElement> libraryGlideModules = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,20 +202,20 @@ public Object apply(ParameterSpec input) {
private CodeBlock generateSeeMethodJavadocInternal(
TypeName nameOfClassContainingMethod, String methodName,
List<Object> safeParameterNames) {
String javadocString = "@see $T#$L(";
StringBuilder javadocString = new StringBuilder("@see $T#$L(");
List<Object> javadocArgs = new ArrayList<>();
javadocArgs.add(nameOfClassContainingMethod);
javadocArgs.add(methodName);

for (Object param : safeParameterNames) {
javadocString += "$T, ";
javadocString.append("$T, ");
javadocArgs.add(param);
}
if (javadocArgs.size() > 2) {
javadocString = javadocString.substring(0, javadocString.length() - 2);
javadocString = new StringBuilder(javadocString.substring(0, javadocString.length() - 2));
}
javadocString += ")\n";
return CodeBlock.of(javadocString, javadocArgs.toArray(new Object[0]));
javadocString.append(")\n");
return CodeBlock.of(javadocString.toString(), javadocArgs.toArray(new Object[0]));
}

/**
Expand Down Expand Up @@ -255,7 +255,6 @@ static CodeBlock generateCastingSuperCall(TypeName toReturn, ExecutableElement m
.add(
FluentIterable.from(method.getParameters())
.transform(new Function<VariableElement, String>() {
@Nullable
@Override
public String apply(VariableElement input) {
return input.getSimpleName().toString();
Expand Down Expand Up @@ -436,10 +435,7 @@ public boolean apply(@Nullable Element input) {
return false;
}
ExecutableElement method = (ExecutableElement) input;
if (returnType == null) {
return true;
}
return isReturnValueTypeMatching(method, returnType);
return returnType == null || isReturnValueTypeMatching(method, returnType);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -262,13 +263,14 @@ private List<MethodAndStaticVar> generateMethodsForRequestOptionsExtensionNew(

List<Object> methodArgs = new ArrayList<>();
methodArgs.add(element.getSimpleName().toString());
String methodLiterals = "";
StringBuilder methodLiterals = new StringBuilder();
if (!parameters.isEmpty()) {
for (VariableElement variable : parameters) {
methodLiterals += "$L, ";
methodLiterals.append("$L, ");
methodArgs.add(variable.getSimpleName().toString());
}
methodLiterals = methodLiterals.substring(0, methodLiterals.length() - 2);
methodLiterals = new StringBuilder(
methodLiterals.substring(0, methodLiterals.length() - 2));
}
extensionRequestOptionsArgument = CodeBlock.builder()
.add(
Expand All @@ -280,20 +282,20 @@ private List<MethodAndStaticVar> generateMethodsForRequestOptionsExtensionNew(
}

List<Object> args = new ArrayList<>();
String code = "return ($T) $T.$L($L, ";
StringBuilder code = new StringBuilder("return ($T) $T.$L($L, ");
args.add(glideOptionsName);
args.add(ClassName.get(element.getEnclosingElement().asType()));
args.add(element.getSimpleName().toString());
args.add(extensionRequestOptionsArgument);
if (!parameters.isEmpty()) {
for (VariableElement variable : parameters) {
code += "$L, ";
code.append("$L, ");
args.add(variable.getSimpleName().toString());
}
}
code = code.substring(0, code.length() - 2);
code += ")";
builder.addStatement(code, args.toArray(new Object[0]));
code = new StringBuilder(code.substring(0, code.length() - 2));
code.append(")");
builder.addStatement(code.toString(), args.toArray(new Object[0]));
builder.addAnnotation(AnnotationSpec.builder(CHECK_RESULT_CLASS_NAME).build());

List<MethodAndStaticVar> result = new ArrayList<>();
Expand Down Expand Up @@ -326,13 +328,13 @@ private List<MethodAndStaticVar> generateMethodsForRequestOptionsExtensionDeprec
// IE centerCrop(context) creates methodLiterals="%L" and methodArgs=[centerCrop, context].
List<Object> methodArgs = new ArrayList<>();
methodArgs.add(element.getSimpleName().toString());
String methodLiterals = "";
StringBuilder methodLiterals = new StringBuilder();
if (!parameters.isEmpty()) {
for (VariableElement variable : parameters) {
methodLiterals += "$L, ";
methodLiterals.append("$L, ");
methodArgs.add(variable.getSimpleName().toString());
}
methodLiterals = methodLiterals.substring(0, methodLiterals.length() - 2);
methodLiterals = new StringBuilder(methodLiterals.substring(0, methodLiterals.length() - 2));
}

builder.beginControlFlow("if (isAutoCloneEnabled())")
Expand All @@ -352,19 +354,19 @@ private List<MethodAndStaticVar> generateMethodsForRequestOptionsExtensionDeprec

// Adds: <AnnotatedClass>.<thisMethodName>(RequestOptions<?>, <arg1>, <arg2>, <argN>);
List<Object> args = new ArrayList<>();
String code = "$T.$L($L, ";
StringBuilder code = new StringBuilder("$T.$L($L, ");
args.add(ClassName.get(element.getEnclosingElement().asType()));
args.add(element.getSimpleName().toString());
args.add("this");
if (!parameters.isEmpty()) {
for (VariableElement variable : parameters) {
code += "$L, ";
code.append("$L, ");
args.add(variable.getSimpleName().toString());
}
}
code = code.substring(0, code.length() - 2);
code += ")";
builder.addStatement(code, args.toArray(new Object[0]));
code = new StringBuilder(code.substring(0, code.length() - 2));
code.append(")");
builder.addStatement(code.toString(), args.toArray(new Object[0]));

builder.addStatement("return this");
builder.addAnnotation(AnnotationSpec.builder(CHECK_RESULT_CLASS_NAME).build());
Expand Down Expand Up @@ -439,21 +441,21 @@ private MethodAndStaticVar generateStaticMethodEquivalentForRequestOptionsStatic
.returns(glideOptionsName);

List<? extends VariableElement> parameters = staticMethod.getParameters();
String createNewOptionAndCall = "new $T().$N(";
StringBuilder createNewOptionAndCall = new StringBuilder("new $T().$N(");
if (!parameters.isEmpty()) {
methodSpecBuilder.addParameters(ProcessorUtil.getParameters(staticMethod));
for (VariableElement parameter : parameters) {
createNewOptionAndCall += parameter.getSimpleName().toString();
createNewOptionAndCall.append(parameter.getSimpleName().toString());
// use the Application Context to avoid memory leaks.
if (memoize && isAndroidContext(parameter)) {
createNewOptionAndCall += ".getApplicationContext()";
createNewOptionAndCall.append(".getApplicationContext()");
}
createNewOptionAndCall += ", ";
createNewOptionAndCall.append(", ");
}
createNewOptionAndCall =
createNewOptionAndCall.substring(0, createNewOptionAndCall.length() - 2);
createNewOptionAndCall = new StringBuilder(
createNewOptionAndCall.substring(0, createNewOptionAndCall.length() - 2));
}
createNewOptionAndCall += ")";
createNewOptionAndCall.append(")");

FieldSpec requiredStaticField = null;
if (memoize) {
Expand Down Expand Up @@ -517,6 +519,8 @@ private MethodAndStaticVar generateStaticMethodEquivalentForExtensionMethod(
}
boolean memoize = memoizeStaticMethodFromAnnotation(instanceMethod);

//noinspection ResultOfMethodCallIgnored
Preconditions.checkNotNull(staticMethodName);
MethodSpec.Builder methodSpecBuilder = MethodSpec.methodBuilder(staticMethodName)
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.addJavadoc(processorUtil.generateSeeMethodJavadoc(instanceMethod))
Expand All @@ -535,21 +539,21 @@ private MethodAndStaticVar generateStaticMethodEquivalentForExtensionMethod(
// Remove is not supported.
parameters = parameters.subList(1, parameters.size());

String createNewOptionAndCall = "new $T().$L(";
StringBuilder createNewOptionAndCall = new StringBuilder("new $T().$L(");
if (!parameters.isEmpty()) {
methodSpecBuilder.addParameters(ProcessorUtil.getParameters(parameters));
for (VariableElement parameter : parameters) {
createNewOptionAndCall += parameter.getSimpleName().toString();
createNewOptionAndCall.append(parameter.getSimpleName().toString());
// use the Application Context to avoid memory leaks.
if (memoize && isAndroidContext(parameter)) {
createNewOptionAndCall += ".getApplicationContext()";
createNewOptionAndCall.append(".getApplicationContext()");
}
createNewOptionAndCall += ", ";
createNewOptionAndCall.append(", ");
}
createNewOptionAndCall =
createNewOptionAndCall.substring(0, createNewOptionAndCall.length() - 2);
createNewOptionAndCall = new StringBuilder(
createNewOptionAndCall.substring(0, createNewOptionAndCall.length() - 2));
}
createNewOptionAndCall += ")";
createNewOptionAndCall.append(")");

FieldSpec requiredStaticField = null;
if (memoize) {
Expand Down
8 changes: 4 additions & 4 deletions annotation/compiler/test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ dependencies {
// build.gradle file.
testImplementation project(':glide')
testImplementation project(':annotation:compiler')
testImplementation 'com.squareup:javapoet:1.9.0'
testImplementation 'com.google.auto.service:auto-service:1.0-rc3'
testImplementation 'com.google.code.findbugs:jsr305:3.0.1'
testImplementation 'com.google.testing.compile:compile-testing:0.10'
testImplementation "com.squareup:javapoet:${JAVAPOET_VERSION}"
testImplementation "com.google.auto.service:auto-service:${AUTO_SERVICE_VERSION}"
testImplementation "com.google.code.findbugs:jsr305:${JSR_305_VERSION}"
testImplementation 'com.google.testing.compile:compile-testing:0.12'
// Use a stupidly old version of the Android classes jar. This works because we just need to get
// our generated classes to compile and our generated classes tend to use simple and stable
// Android APIs. If that changes, we'll need to find an alternative.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@SuppressWarnings("ResultOfMethodCallIgnored")
@RunWith(JUnit4.class)
public class InvalidGlideExtensionTest {
@Rule public ExpectedException expectedException = ExpectedException.none();
@Rule public final ExpectedException expectedException = ExpectedException.none();

@Test
public void compilation_withPublicConstructor_fails() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@SuppressWarnings("ResultOfMethodCallIgnored")
@RunWith(JUnit4.class)
public class InvalidGlideOptionsExtensionTest {
@Rule public ExpectedException expectedException = ExpectedException.none();
@Rule public final ExpectedException expectedException = ExpectedException.none();

@Test
public void compilation_withAnnotatedNonStaticMethod_fails() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@SuppressWarnings("ResultOfMethodCallIgnored")
@RunWith(JUnit4.class)
public class InvalidGlideTypeExtensionTest {
@Rule public ExpectedException expectedException = ExpectedException.none();
@Rule public final ExpectedException expectedException = ExpectedException.none();

@Test
public void compilation_withAnnotatedNonStaticMethod_fails() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
@RunWith(JUnit4.class)
public class MultipleAppGlideModuleTest {
@Rule public ExpectedException expectedException = ExpectedException.none();
@Rule public final ExpectedException expectedException = ExpectedException.none();
private static final String FIRST_MODULE = "EmptyAppModule1.java";
private static final String SECOND_MODULE = "EmptyAppModule2.java";

Expand Down
Loading

0 comments on commit b227776

Please sign in to comment.