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;
}
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;
}
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;
}
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;
}
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));
}
}
Aggregations