Search in sources :

Example 1 with ResourceEntry

use of org.jetbrains.android.util.ResourceEntry in project android by JetBrains.

the class AndroidBuildDataCache method parseValueResourceFile.

@NotNull
private static List<ResourceEntry> parseValueResourceFile(@NotNull File valueResXmlFile) throws IOException {
    final ArrayList<ResourceEntry> result = new ArrayList<ResourceEntry>();
    final InputStream inputStream = new BufferedInputStream(new FileInputStream(valueResXmlFile));
    try {
        FormsParsing.parse(inputStream, new ValueResourcesFileParser() {

            @Override
            protected void stop() {
                throw new FormsParsing.ParserStoppedException();
            }

            @Override
            protected void process(@NotNull ResourceEntry resourceEntry) {
                result.add(resourceEntry);
            }
        });
    } finally {
        inputStream.close();
    }
    return result;
}
Also used : FormsParsing(org.jetbrains.jps.incremental.java.FormsParsing) ResourceEntry(org.jetbrains.android.util.ResourceEntry) ValueResourcesFileParser(org.jetbrains.android.util.ValueResourcesFileParser) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ResourceEntry

use of org.jetbrains.android.util.ResourceEntry in project android by JetBrains.

the class ResourceTypeClassBase method buildResourceFields.

@NotNull
static PsiField[] buildResourceFields(@NotNull ResourceManager manager, boolean nonFinal, @NotNull String resClassName, @NotNull final PsiClass context) {
    ResourceType resourceType = ResourceType.getEnum(resClassName);
    if (resourceType == null) {
        return PsiField.EMPTY_ARRAY;
    }
    final Map<String, PsiType> fieldNames = new HashMap<String, PsiType>();
    final boolean styleable = ResourceType.STYLEABLE == resourceType;
    final PsiType basicType = styleable ? PsiType.INT.createArrayType() : PsiType.INT;
    for (String resName : manager.getResourceNames(resourceType)) {
        fieldNames.put(resName, basicType);
    }
    if (styleable) {
        for (ResourceEntry entry : manager.getValueResourceEntries(ResourceType.ATTR)) {
            final String resName = entry.getName();
            final String resContext = entry.getContext();
            if (resContext.length() > 0) {
                fieldNames.put(resContext + '_' + resName, PsiType.INT);
            }
        }
    }
    final PsiField[] result = new PsiField[fieldNames.size()];
    final PsiElementFactory factory = JavaPsiFacade.getElementFactory(context.getProject());
    int idIterator = resourceType.ordinal() * 100000;
    int i = 0;
    for (Map.Entry<String, PsiType> entry : fieldNames.entrySet()) {
        final String fieldName = AndroidResourceUtil.getFieldNameByResourceName(entry.getKey());
        final PsiType type = entry.getValue();
        final int id = -(idIterator++);
        final AndroidLightField field = new AndroidLightField(fieldName, context, type, !nonFinal, nonFinal ? null : id);
        field.setInitializer(factory.createExpressionFromText(Integer.toString(id), field));
        result[i++] = field;
    }
    return result;
}
Also used : HashMap(com.intellij.util.containers.HashMap) ResourceType(com.android.resources.ResourceType) ResourceEntry(org.jetbrains.android.util.ResourceEntry) HashMap(com.intellij.util.containers.HashMap) Map(java.util.Map) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ResourceEntry

use of org.jetbrains.android.util.ResourceEntry in project android by JetBrains.

the class ResourceManager method getValueResourceNames.

@NotNull
public Collection<String> getValueResourceNames(@NotNull final ResourceType resourceType) {
    final Set<String> result = new HashSet<String>();
    final boolean attr = ResourceType.ATTR == resourceType;
    for (ResourceEntry entry : getValueResourceEntries(resourceType)) {
        final String name = entry.getName();
        if (!attr || !name.startsWith("android:")) {
            result.add(name);
        }
    }
    return result;
}
Also used : ResourceEntry(org.jetbrains.android.util.ResourceEntry) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with ResourceEntry

use of org.jetbrains.android.util.ResourceEntry in project android by JetBrains.

the class ResourceManager method getValueResourceEntries.

@NotNull
public Collection<ResourceEntry> getValueResourceEntries(@NotNull final ResourceType resourceType) {
    final FileBasedIndex index = FileBasedIndex.getInstance();
    final ResourceEntry typeMarkerEntry = AndroidValueResourcesIndex.createTypeMarkerKey(resourceType.getName());
    final GlobalSearchScope scope = GlobalSearchScope.allScope(myProject);
    final Map<VirtualFile, Set<ResourceEntry>> file2resourceSet = new HashMap<VirtualFile, Set<ResourceEntry>>();
    index.processValues(AndroidValueResourcesIndex.INDEX_ID, typeMarkerEntry, null, new FileBasedIndex.ValueProcessor<ImmutableSet<AndroidValueResourcesIndex.MyResourceInfo>>() {

        @Override
        public boolean process(@NotNull VirtualFile file, ImmutableSet<AndroidValueResourcesIndex.MyResourceInfo> infos) {
            for (AndroidValueResourcesIndex.MyResourceInfo info : infos) {
                Set<ResourceEntry> resourcesInFile = file2resourceSet.get(file);
                if (resourcesInFile == null) {
                    resourcesInFile = new HashSet<ResourceEntry>();
                    file2resourceSet.put(file, resourcesInFile);
                }
                resourcesInFile.add(info.getResourceEntry());
            }
            return true;
        }
    }, scope);
    final List<ResourceEntry> result = new ArrayList<ResourceEntry>();
    for (VirtualFile file : getAllValueResourceFiles()) {
        final Set<ResourceEntry> entries = file2resourceSet.get(file);
        if (entries != null) {
            for (ResourceEntry entry : entries) {
                if (isResourcePublic(entry.getType(), entry.getName())) {
                    result.add(entry);
                }
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashSet(com.intellij.util.containers.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) HashMap(com.intellij.util.containers.HashMap) ImmutableSet(com.google.common.collect.ImmutableSet) ResourceEntry(org.jetbrains.android.util.ResourceEntry) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) AndroidValueResourcesIndex(org.jetbrains.android.AndroidValueResourcesIndex) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with ResourceEntry

use of org.jetbrains.android.util.ResourceEntry in project android by JetBrains.

the class AndroidAptValidityState method save.

@Override
public void save(DataOutput out) throws IOException {
    out.writeInt(SIGNATURE);
    out.writeByte(VERSION);
    out.writeUTF(myPackageName);
    out.writeInt(myResources.size());
    for (Map.Entry<String, ResourceFileData> entry : myResources.entrySet()) {
        out.writeUTF(entry.getKey());
        final ResourceFileData fileData = entry.getValue();
        final List<ResourceEntry> resources = fileData.getValueResources();
        out.writeInt(resources.size());
        for (ResourceEntry resource : resources) {
            out.writeUTF(resource.getType());
            out.writeUTF(resource.getName());
            out.writeUTF(resource.getContext());
        }
        out.writeLong(fileData.getTimestamp());
    }
    out.writeInt(myManifestElements.size());
    for (ResourceEntry manifestElement : myManifestElements) {
        out.writeUTF(manifestElement.getType());
        out.writeUTF(manifestElement.getName());
        out.writeUTF(manifestElement.getContext());
    }
    out.writeInt(myLibRTxtFilesAndPackages.size());
    for (Pair<String, String> pair : myLibRTxtFilesAndPackages) {
        out.writeUTF(pair.getFirst());
        out.writeUTF(pair.getSecond());
    }
    out.writeUTF(myProguardOutputCfgFile);
    out.writeUTF(myRTxtOutputDir);
    out.writeBoolean(myLibrary);
    out.writeInt(myValueResourceFilesTimestamps.size());
    for (Object key : myValueResourceFilesTimestamps.keys()) {
        final String strKey = (String) key;
        out.writeUTF(strKey);
        out.writeLong(myValueResourceFilesTimestamps.get(strKey));
    }
}
Also used : ResourceFileData(org.jetbrains.android.util.ResourceFileData) ResourceEntry(org.jetbrains.android.util.ResourceEntry) HashMap(com.intellij.util.containers.HashMap) TObjectLongHashMap(gnu.trove.TObjectLongHashMap)

Aggregations

ResourceEntry (org.jetbrains.android.util.ResourceEntry)5 NotNull (org.jetbrains.annotations.NotNull)4 HashMap (com.intellij.util.containers.HashMap)3 HashSet (com.intellij.util.containers.HashSet)2 ResourceType (com.android.resources.ResourceType)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 FileBasedIndex (com.intellij.util.indexing.FileBasedIndex)1 TObjectLongHashMap (gnu.trove.TObjectLongHashMap)1 Map (java.util.Map)1 AndroidValueResourcesIndex (org.jetbrains.android.AndroidValueResourcesIndex)1 ResourceFileData (org.jetbrains.android.util.ResourceFileData)1 ValueResourcesFileParser (org.jetbrains.android.util.ValueResourcesFileParser)1 FormsParsing (org.jetbrains.jps.incremental.java.FormsParsing)1