Skip to content

Commit

Permalink
Merge pull request #471 from maskarade/show_error_if_rxjava_suppor_co…
Browse files Browse the repository at this point in the history
…nflict

Show processing error if different rxJavaSupport databases are found
  • Loading branch information
gfx authored Nov 15, 2018
2 parents 642d55a + f7cd364 commit 0c2ed12
Showing 1 changed file with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.TypeName;

import androidx.annotation.Nullable;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Type;
Expand All @@ -47,6 +45,8 @@
import javax.lang.model.util.Types;
import javax.tools.Diagnostic;

import androidx.annotation.Nullable;

public class ProcessingContext {

public final ProcessingEnvironment processingEnv;
Expand Down Expand Up @@ -224,9 +224,27 @@ public boolean isRxJavaSupport(SchemaDefinition schema) {
if (databases.isEmpty()) {
return Database.DEFAULT_RX_JAVA_SUPPORT;
}
return databases

long targetCount = databases
.stream()
.filter((database) -> database.getSchemas().contains(schema))
.count();

long rxJavaSupportCount = databases
.stream()
.anyMatch((database) -> database.isRxJavaSupport() && database.getSchemas().contains(schema));
.filter((database) -> database.getSchemas().contains(schema) && database.isRxJavaSupport())
.count();

if (rxJavaSupportCount == 0L) {
return false;
}

if (rxJavaSupportCount < targetCount) {
addError(schema.getModelClassName().simpleName() + " is included in different RxJavaSupport databases.",
schema.getElement());
}

return true;
}

public void note(String message) {
Expand Down

0 comments on commit 0c2ed12

Please sign in to comment.