Search in sources :

Example 6 with DataBindingInfo

use of com.android.tools.idea.res.DataBindingInfo in project android by JetBrains.

the class DataBindingUtil method getViewClassNameFromLayoutReferenceTag.

private static String getViewClassNameFromLayoutReferenceTag(XmlTag tag, AndroidFacet facet) {
    String layout = tag.getAttributeValue(SdkConstants.ATTR_LAYOUT);
    if (layout == null) {
        return null;
    }
    LocalResourceRepository moduleResources = facet.getModuleResources(false);
    if (moduleResources == null) {
        return null;
    }
    ResourceUrl resourceUrl = ResourceUrl.parse(layout);
    if (resourceUrl == null || resourceUrl.type != ResourceType.LAYOUT) {
        return null;
    }
    DataBindingInfo info = moduleResources.getDataBindingInfoForLayout(resourceUrl.name);
    if (info == null) {
        return null;
    }
    return info.getQualifiedName();
}
Also used : LocalResourceRepository(com.android.tools.idea.res.LocalResourceRepository) DataBindingInfo(com.android.tools.idea.res.DataBindingInfo) ResourceUrl(com.android.ide.common.resources.ResourceUrl)

Example 7 with DataBindingInfo

use of com.android.tools.idea.res.DataBindingInfo in project android by JetBrains.

the class DataBindingUtil method invalidateAllSources.

public static boolean invalidateAllSources(DataBindingProjectComponent component) {
    boolean invalidated = false;
    for (AndroidFacet facet : component.getDataBindingEnabledFacets()) {
        LocalResourceRepository moduleResources = facet.getModuleResources(true);
        Map<String, DataBindingInfo> dataBindingResourceFiles = moduleResources.getDataBindingResourceFiles();
        if (dataBindingResourceFiles == null) {
            continue;
        }
        for (DataBindingInfo info : dataBindingResourceFiles.values()) {
            PsiClass psiClass = info.getPsiClass();
            if (psiClass != null) {
                PsiFile containingFile = psiClass.getContainingFile();
                if (containingFile != null) {
                    containingFile.subtreeChanged();
                    invalidated = true;
                }
            }
        }
    }
    return invalidated;
}
Also used : LocalResourceRepository(com.android.tools.idea.res.LocalResourceRepository) DataBindingInfo(com.android.tools.idea.res.DataBindingInfo) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 8 with DataBindingInfo

use of com.android.tools.idea.res.DataBindingInfo in project android by JetBrains.

the class DataBindingClassFinder method findClass.

@Nullable
@Override
public PsiClass findClass(@NotNull String qualifiedName, @NotNull GlobalSearchScope scope) {
    if (!isEnabled()) {
        return null;
    }
    for (AndroidFacet facet : myComponent.getDataBindingEnabledFacets()) {
        LocalResourceRepository moduleResources = facet.getModuleResources(true);
        Map<String, DataBindingInfo> dataBindingResourceFiles = moduleResources.getDataBindingResourceFiles();
        if (dataBindingResourceFiles == null) {
            continue;
        }
        DataBindingInfo dataBindingInfo = dataBindingResourceFiles.get(qualifiedName);
        if (dataBindingInfo == null) {
            continue;
        }
        VirtualFile file = dataBindingInfo.getPsiFile().getVirtualFile();
        if (file != null && scope.accept(file)) {
            return DataBindingUtil.getOrCreatePsiClass(dataBindingInfo);
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalResourceRepository(com.android.tools.idea.res.LocalResourceRepository) DataBindingInfo(com.android.tools.idea.res.DataBindingInfo) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with DataBindingInfo

use of com.android.tools.idea.res.DataBindingInfo in project android by JetBrains.

the class DataBindingShortNamesCache method getClassesByName.

@NotNull
@Override
public PsiClass[] getClassesByName(@NotNull @NonNls String name, @NotNull GlobalSearchScope scope) {
    if (!isEnabled()) {
        return PsiClass.EMPTY_ARRAY;
    }
    List<DataBindingInfo> infoList = myNameCache.getValue().get(name);
    if (infoList == null || infoList.size() == 0) {
        return PsiClass.EMPTY_ARRAY;
    }
    List<PsiClass> selected = Lists.newArrayList();
    for (DataBindingInfo info : infoList) {
        if (scope.accept(info.getPsiFile().getVirtualFile())) {
            selected.add(DataBindingUtil.getOrCreatePsiClass(info));
        }
    }
    if (selected.isEmpty()) {
        return PsiClass.EMPTY_ARRAY;
    }
    return selected.toArray(new PsiClass[selected.size()]);
}
Also used : PsiClass(com.intellij.psi.PsiClass) DataBindingInfo(com.android.tools.idea.res.DataBindingInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with DataBindingInfo

use of com.android.tools.idea.res.DataBindingInfo in project android by JetBrains.

the class LightBindingClass method getExtendsListTypes.

@NotNull
@Override
public PsiClassType[] getExtendsListTypes() {
    if (myExtendsListTypes == null) {
        DataBindingInfo mergedInfo = myInfo.getMergedInfo();
        String superClassName = mergedInfo == null ? SdkConstants.CLASS_DATA_BINDING_BASE_BINDING : mergedInfo.getQualifiedName();
        myExtendsListTypes = new PsiClassType[] { PsiType.getTypeByName(superClassName, myInfo.getProject(), myFacet.getModule().getModuleWithDependenciesAndLibrariesScope(false)) };
    }
    return myExtendsListTypes;
}
Also used : DataBindingInfo(com.android.tools.idea.res.DataBindingInfo) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DataBindingInfo (com.android.tools.idea.res.DataBindingInfo)11 Nullable (org.jetbrains.annotations.Nullable)5 LocalResourceRepository (com.android.tools.idea.res.LocalResourceRepository)4 Module (com.intellij.openapi.module.Module)3 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)3 NotNull (org.jetbrains.annotations.NotNull)3 PsiDataBindingResourceItem (com.android.tools.idea.res.PsiDataBindingResourceItem)2 PsiClass (com.intellij.psi.PsiClass)2 ResourceUrl (com.android.ide.common.resources.ResourceUrl)1 Project (com.intellij.openapi.project.Project)1 TextRange (com.intellij.openapi.util.TextRange)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)1 ArrayList (java.util.ArrayList)1