Search in sources :

Example 6 with GradleEditorSourceBinding

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;
}
Also used : GradleEditorSourceBinding(com.android.tools.idea.gradle.editor.entity.GradleEditorSourceBinding) GradleEntityDeclarationValueLocationAware(com.android.tools.idea.gradle.editor.entity.GradleEntityDeclarationValueLocationAware) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GradleEditorSourceBinding (com.android.tools.idea.gradle.editor.entity.GradleEditorSourceBinding)6 Nullable (org.jetbrains.annotations.Nullable)5 RangeMarker (com.intellij.openapi.editor.RangeMarker)3 GradleEditorEntityMetaData (com.android.tools.idea.gradle.editor.metadata.GradleEditorEntityMetaData)2 StdGradleEditorEntityMetaData (com.android.tools.idea.gradle.editor.metadata.StdGradleEditorEntityMetaData)2 Document (com.intellij.openapi.editor.Document)2 ExternalDependencyGradleEditorEntity (com.android.tools.idea.gradle.editor.entity.ExternalDependencyGradleEditorEntity)1 GradleEntityDeclarationValueLocationAware (com.android.tools.idea.gradle.editor.entity.GradleEntityDeclarationValueLocationAware)1 GradleEditorEntityValueManager (com.android.tools.idea.gradle.editor.value.GradleEditorEntityValueManager)1 LibraryVersionsManager (com.android.tools.idea.gradle.editor.value.LibraryVersionsManager)1 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1 Project (com.intellij.openapi.project.Project)1 TextRange (com.intellij.openapi.util.TextRange)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)1 Matcher (java.util.regex.Matcher)1