Source:
public static boolean isApplicable(TypeElement type, Messager messager) { @SuppressWarnings("UnstableApiUsage") boolean generateExternalAdapter = MoreElements.isAnnotationPresent(type, GenerateTypeAdapter.class); if (generateExternalAdapter) { return true; } TypeName typeName = TypeName.get(type.asType()); ParameterizedTypeName typeAdapterType = ParameterizedTypeName.get( ClassName.get(TypeAdapter.class), typeName); TypeName returnedTypeAdapter = null; for (ExecutableElement method : ElementFilter.methodsIn(type.getEnclosedElements())) { if (method.getModifiers().contains(STATIC) && !method.getModifiers().contains(PRIVATE)) { TypeMirror rType = method.getReturnType(); TypeName returnType = TypeName.get(rType); if (returnType.equals(typeAdapterType)) { return true; } if (returnType.equals(typeAdapterType.rawType) || (returnType instanceof ParameterizedTypeName && ((ParameterizedTypeName) returnType).rawType.equals(typeAdapterType.rawType))) { returnedTypeAdapter = returnType; } } } if (returnedTypeAdapter == null) { return false; } if (returnedTypeAdapter instanceof ParameterizedTypeName) { ParameterizedTypeName paramReturnType = (ParameterizedTypeName) returnedTypeAdapter; TypeName argument = paramReturnType.typeArguments.get(0); if (typeName instanceof ParameterizedTypeName) { ParameterizedTypeName pTypeName = (ParameterizedTypeName) typeName; return pTypeName.rawType.equals(argument); } else { messager.printMessage(Diagnostic.Kind.WARNING, String.format("Found static method returning TypeAdapter<%s> on %s class. " + "Skipping GsonTypeAdapter generation.", argument, type)); } } else { messager.printMessage(Diagnostic.Kind.WARNING, "Found static method returning " + "TypeAdapter with no type arguments, skipping GsonTypeAdapter generation."); } return false; }

Target:
public static boolean isApplicable(TypeElement type, Messager messager) { if (MoreElements.isAnnotationPresent(type, GenerateTypeAdapter.class)) { return true; } TypeName typeName = TypeName.get(type.asType()); ParameterizedTypeName typeAdapterType = ParameterizedTypeName.get( ClassName.get(TypeAdapter.class), typeName); TypeName returnedTypeAdapter = null; for (ExecutableElement method : ElementFilter.methodsIn(type.getEnclosedElements())) { if (method.getModifiers().contains(STATIC) && !method.getModifiers().contains(PRIVATE)) { TypeMirror rType = method.getReturnType(); TypeName returnType = TypeName.get(rType); if (returnType.equals(typeAdapterType)) { return true; } if (returnType.equals(typeAdapterType.rawType) || (returnType instanceof ParameterizedTypeName && ((ParameterizedTypeName) returnType).rawType.equals(typeAdapterType.rawType))) { returnedTypeAdapter = returnType; } } } if (returnedTypeAdapter == null) { return false; } if (returnedTypeAdapter instanceof ParameterizedTypeName) { ParameterizedTypeName paramReturnType = (ParameterizedTypeName) returnedTypeAdapter; TypeName argument = paramReturnType.typeArguments.get(0); if (typeName instanceof ParameterizedTypeName) { ParameterizedTypeName pTypeName = (ParameterizedTypeName) typeName; return pTypeName.rawType.equals(argument); } else { messager.printMessage(Diagnostic.Kind.WARNING, String.format("Found static method returning TypeAdapter<%s> on %s class. " + "Skipping GsonTypeAdapter generation.", argument, type)); } } else { messager.printMessage(Diagnostic.Kind.WARNING, "Found static method returning " + "TypeAdapter with no type arguments, skipping GsonTypeAdapter generation."); } return false; }