use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class FormEditingUtil method collectUsedLocales.
public static Locale[] collectUsedLocales(final Module module, final IRootContainer rootContainer) {
final Set<Locale> locales = new HashSet<>();
final PropertiesReferenceManager propManager = PropertiesReferenceManager.getInstance(module.getProject());
for (String bundleName : collectUsedBundleNames(rootContainer)) {
List<PropertiesFile> propFiles = propManager.findPropertiesFiles(module, bundleName.replace('/', '.'));
for (PropertiesFile propFile : propFiles) {
locales.add(propFile.getLocale());
}
}
return locales.toArray(new Locale[locales.size()]);
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class StringDescriptorManager method resolveToProperty.
public IProperty resolveToProperty(@NotNull StringDescriptor descriptor, @Nullable Locale locale) {
String propFileName = descriptor.getDottedBundleName();
Pair<Locale, String> cacheKey = Pair.create(locale, propFileName);
PropertiesFile propertiesFile;
synchronized (myPropertiesFileCache) {
propertiesFile = myPropertiesFileCache.get(cacheKey);
}
if (propertiesFile == null || !propertiesFile.getContainingFile().isValid()) {
propertiesFile = PropertiesUtilBase.getPropertiesFile(propFileName, myModule, locale);
synchronized (myPropertiesFileCache) {
myPropertiesFileCache.put(cacheKey, propertiesFile);
}
}
if (propertiesFile != null) {
final IProperty propertyByKey = propertiesFile.findPropertyByKey(descriptor.getKey());
if (propertyByKey != null) {
return propertyByKey;
}
}
return null;
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class AntDomProperty method buildProperties.
private Map<String, String> buildProperties() {
Map<String, String> result = myCachedProperties;
if (result != null) {
return result;
}
result = Collections.emptyMap();
final String propertyName = getName().getRawText();
if (propertyName != null) {
final String propertyValue = getValue().getRawText();
if (propertyValue != null) {
result = Collections.singletonMap(propertyName, propertyValue);
} else {
String locValue = getLocation().getStringValue();
if (locValue != null) {
final File file = new File(locValue);
if (!file.isAbsolute()) {
final String baseDir = getContextAntProject().getProjectBasedirPath();
if (baseDir != null) {
locValue = PathUtil.getCanonicalPath(new File(baseDir, locValue).getPath());
}
}
result = Collections.singletonMap(propertyName, FileUtil.toSystemDependentName(locValue));
} else {
// todo: process refid attrib if specified for the value
final String tagText = getXmlTag().getText();
result = Collections.singletonMap(propertyName, tagText);
}
}
} else {
// name attrib is not specified
final PsiFileSystemItem psiFile = getFile().getValue();
if (psiFile != null) {
final PropertiesFile file = toPropertiesFile(psiFile);
if (file != null) {
result = new HashMap<>();
for (final IProperty property : file.getProperties()) {
result.put(property.getUnescapedKey(), property.getUnescapedValue());
}
}
} else if (getEnvironment().getRawText() != null) {
String prefix = getEnvironment().getRawText();
if (!prefix.endsWith(".")) {
prefix += ".";
}
result = new HashMap<>();
for (Map.Entry<String, String> entry : System.getenv().entrySet()) {
result.put(prefix + entry.getKey(), entry.getValue());
}
} else {
// todo: consider Url attribute?
final String resource = getResource().getStringValue();
if (resource != null) {
final ClassLoader loader = getClassLoader();
if (loader != null) {
final InputStream stream = loader.getResourceAsStream(resource);
if (stream != null) {
try {
// todo: Remote file can be XmlPropertiesFile
final PropertiesFile propFile = (PropertiesFile) CustomAntElementsRegistry.loadContentAsFile(getXmlTag().getProject(), stream, StdFileTypes.PROPERTIES);
result = new HashMap<>();
for (final IProperty property : propFile.getProperties()) {
result.put(property.getUnescapedKey(), property.getUnescapedValue());
}
} catch (IOException ignored) {
}
}
}
}
}
}
return (myCachedProperties = result);
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class AntResolveInspection method getPropertyFiles.
@NotNull
private static Collection<PropertiesFile> getPropertyFiles(@Nullable AntDomProject antDomProject, @NotNull XmlElement stopElement) {
if (antDomProject == null) {
return Collections.emptyList();
}
final Set<PropertiesFile> files = new java.util.HashSet<>();
final int stopOffset = stopElement.getTextOffset();
for (Iterator<AntDomElement> iterator = antDomProject.getAntChildrenIterator(); iterator.hasNext(); ) {
AntDomElement child = iterator.next();
final XmlElement xmlElement = child.getXmlElement();
if (xmlElement != null && xmlElement.getTextOffset() >= stopOffset) {
// no need to offer to add properties to files that are imported after the property reference
break;
}
if (child instanceof AntDomProperty) {
final AntDomProperty property = (AntDomProperty) child;
final PropertiesFile file = property.getPropertiesFile();
if (file != null) {
files.add(file);
}
}
}
return files;
}
use of com.intellij.lang.properties.psi.PropertiesFile in project android by JetBrains.
the class AndroidPropertyFilesUpdater method updateProjectPropertiesIfNecessary.
@Nullable
private static Pair<VirtualFile, List<Runnable>> updateProjectPropertiesIfNecessary(@NotNull AndroidFacet facet) {
if (facet.isDisposed()) {
return null;
}
final Module module = facet.getModule();
final Pair<PropertiesFile, VirtualFile> pair = AndroidRootUtil.findPropertyFile(module, SdkConstants.FN_PROJECT_PROPERTIES);
if (pair == null) {
return null;
}
final PropertiesFile projectProperties = pair.getFirst();
final VirtualFile projectPropertiesVFile = pair.getSecond();
final Pair<Properties, VirtualFile> localProperties = AndroidRootUtil.readPropertyFile(module, SdkConstants.FN_LOCAL_PROPERTIES);
final List<Runnable> changes = new ArrayList<Runnable>();
final IAndroidTarget androidTarget = facet.getConfiguration().getAndroidTarget();
final String androidTargetHashString = androidTarget != null ? androidTarget.hashString() : null;
final VirtualFile[] dependencies = collectDependencies(module);
final String[] dependencyPaths = toSortedPaths(dependencies);
final List<Object> newState = Arrays.asList(androidTargetHashString, facet.getProjectType(), Arrays.asList(dependencyPaths), facet.getProperties().ENABLE_MANIFEST_MERGING, facet.getProperties().ENABLE_PRE_DEXING);
final List<Object> state = facet.getUserData(ANDROID_PROPERTIES_STATE_KEY);
if (state == null || !Comparing.equal(state, newState)) {
updateTargetProperty(facet, projectProperties, changes);
updateProjectTypeProperty(facet, projectProperties, changes);
updateManifestMergerProperty(facet, projectProperties, changes);
updateDependenciesInPropertyFile(projectProperties, localProperties, dependencies, changes);
facet.putUserData(ANDROID_PROPERTIES_STATE_KEY, newState);
}
return changes.size() > 0 ? Pair.create(projectPropertiesVFile, changes) : null;
}
Aggregations