use of com.android.tools.idea.gradle.editor.entity.GradleEditorSourceBinding in project android by JetBrains.
the class AbstractPropertyChecker method apply.
@Nullable
public String apply(T entity) {
String actualValue = deriveActualValue(entity);
List<GradleEditorSourceBinding> actualDefinitionValueSourceBindings = deriveDefinitionValueSourceBindings(entity);
if (myExpectedValue != null) {
if (!myExpectedValue.equals(actualValue)) {
return String.format("expected value mismatch - expected: '%s', actual: '%s'", myExpectedValue, actualValue);
}
if (!myExpectedValue.isEmpty()) {
// We expect that there must be exactly one source binding which points to the target value if it's defined.
if (actualDefinitionValueSourceBindings.size() == 1 && !myExpectedValue.equals(text(actualDefinitionValueSourceBindings.get(0)))) {
return String.format("expected that definition value source binding points to the text '%s' but it points to '%s'", myExpectedValue, text(actualDefinitionValueSourceBindings.get(0)));
}
}
}
if (myExpectedDefinitionValueBindings != null) {
if (myExpectedDefinitionValueBindings.size() != actualDefinitionValueSourceBindings.size()) {
return String.format("expected %d definition value bindings (%s) but got %d (%s)", myExpectedDefinitionValueBindings.size(), myExpectedDefinitionValueBindings, actualDefinitionValueSourceBindings.size(), actualDefinitionValueSourceBindings);
}
List<String> expected = Lists.newArrayList(myExpectedDefinitionValueBindings);
for (GradleEditorSourceBinding sourceBinding : actualDefinitionValueSourceBindings) {
expected.remove(text(sourceBinding));
}
if (!expected.isEmpty()) {
return String.format("expected definition value binding(s) '%s' is not found at the target entity", expected);
}
if (myExpectedDefinitionValueBindings.size() > 1 && !Strings.isNullOrEmpty(actualValue)) {
// is changed more than once.
return String.format("expected to find an empty value for the multiple definition value bindings (%s) but it's not - '%s'", myExpectedDefinitionValueBindings, actualValue);
}
}
if (myExpectedDeclarationValue != null) {
if (!(entity instanceof GradleEntityDeclarationValueLocationAware)) {
return String.format("expected target entity to be IS-A %s but it's not", GradleEntityDeclarationValueLocationAware.class.getSimpleName());
}
if (!myExpectedDeclarationValue.equals(text(((GradleEntityDeclarationValueLocationAware) entity).getDeclarationValueLocation()))) {
return String.format("expected declaration value '%s' but it's '%s'", myExpectedDeclarationValue, text(((GradleEntityDeclarationValueLocationAware) entity).getDeclarationValueLocation()));
}
}
if (myExpectedWholeEntityText != null && !myExpectedWholeEntityText.equals(text(entity.getEntityLocation()))) {
return String.format("expected whole entity text '%s' but it is '%s'", myExpectedWholeEntityText, text(entity.getEntityLocation()));
}
return null;
}
Aggregations