use of com.intellij.lang.properties.psi.PropertiesFile in project android by JetBrains.
the class AndroidPropertyFilesUpdater method createProperty.
// workaround for behavior of Android SDK , which uses non-escaped ':' characters
@NotNull
private static IProperty createProperty(@NotNull Project project, @NotNull String targetPropertyValue) {
final String text = AndroidUtils.ANDROID_TARGET_PROPERTY + "=" + targetPropertyValue;
final PropertiesFile dummyFile = PropertiesElementFactory.createPropertiesFile(project, text);
return dummyFile.getProperties().get(0);
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-plugins by JetBrains.
the class SocketInputHandlerImpl method getResourceBundle.
private void getResourceBundle() throws IOException {
initResultFile();
final boolean fromModuleSource = reader.readBoolean();
final int moduleId = readEntityId();
final String locale = reader.readUTF();
final String bundleName = reader.readUTF();
final ModuleInfo moduleInfo = Client.getInstance().getRegisteredModules().getNullableInfo(moduleId);
PropertiesFile resourceBundle = null;
int sourceId = -1;
if (moduleInfo == null) {
// project may be closed, but client is not closed yet (AppTest#testCloseAndOpenProject)
LOG.warn("Skip getResourceBundle(" + locale + ", " + bundleName + ") due to cannot find module with id " + moduleId);
} else {
if (fromModuleSource) {
resourceBundle = getResourceBundleFromModuleSource(moduleInfo.getModule(), bundleName);
sourceId = moduleId;
} else {
Pair<PropertiesFile, Integer> bundleInfo = LibraryManager.getInstance().getResourceBundleFile(locale, bundleName, moduleInfo);
if (bundleInfo != null) {
resourceBundle = bundleInfo.first;
sourceId = bundleInfo.second;
}
}
}
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed") final FileOutputStream fileOut = new FileOutputStream(resultFile);
final AccessToken token = ReadAction.start();
try {
writeResourceBundle(resourceBundle, fileOut, sourceId);
} finally {
token.finish();
fileOut.close();
}
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-plugins by JetBrains.
the class SocketInputHandlerImpl method getResourceBundleFromModuleSource.
private static PropertiesFile getResourceBundleFromModuleSource(Module module, final String bundleName) {
final AccessToken token = ReadAction.start();
try {
final PsiManager psiManager = PsiManager.getInstance(module.getProject());
final List<VirtualFile> result = new ArrayList<>();
FileTypeIndex.processFiles(PropertiesFileType.INSTANCE, file -> {
if (file.getNameWithoutExtension().equals(bundleName)) {
result.add(file);
if (file.getParent().getName().equals("en_US")) {
return false;
}
}
return true;
}, module.getModuleScope(false));
PropertiesFile defaultResourceBundle = null;
for (VirtualFile file : result) {
PsiFile psiFile = psiManager.findFile(file);
if (psiFile != null) {
if (file.getParent().getName().equals("en_US")) {
defaultResourceBundle = (PropertiesFile) psiFile;
} else {
return (PropertiesFile) psiFile;
}
}
}
return defaultResourceBundle;
} finally {
token.finish();
}
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-plugins by JetBrains.
the class InjectedPsiVisitor method processResourceDirective.
private ValueWriter processResourceDirective(JSAttribute attribute) {
String key = null;
PropertiesFile bundle = null;
for (JSAttributeNameValuePair p : attribute.getValues()) {
final String name = p.getName();
if ("key".equals(name)) {
key = p.getSimpleValue();
} else if ("bundle".equals(name)) {
try {
// IDEA-74868
final PsiFileSystemItem referencedPsiFile = InjectionUtil.getReferencedPsiFile(p);
if (referencedPsiFile instanceof PropertiesFile) {
bundle = (PropertiesFile) referencedPsiFile;
} else {
LOG.warn("skip resource directive, referenced file is not properties file " + host.getText());
}
} catch (InvalidPropertyException e) {
invalidPropertyException = e;
return InjectedASWriter.IGNORE;
}
}
}
if (key == null || key.isEmpty() || bundle == null) {
LOG.warn("skip resource directive, one of the required attributes is missed " + host.getText());
return InjectedASWriter.IGNORE;
}
final IProperty property = bundle.findPropertyByKey(key);
if (property == null) {
LOG.warn("skip resource directive, key not found " + host.getText());
return InjectedASWriter.IGNORE;
}
return new ResourceDirectiveValueWriter(property.getUnescapedValue());
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class AntResolveInspection method checkReferences.
private static void checkReferences(final XmlElement xmlElement, @NonNls final DomElementAnnotationHolder holder, DomElement domElement) {
if (xmlElement == null) {
return;
}
Set<PsiReference> processed = null;
// to be initialized lazily
Collection<PropertiesFile> propertyFiles = null;
for (final PsiReference ref : xmlElement.getReferences()) {
if (!(ref instanceof AntDomReference)) {
continue;
}
final AntDomReference antDomRef = (AntDomReference) ref;
if (antDomRef.shouldBeSkippedByAnnotator()) {
continue;
}
if (processed != null && processed.contains(ref)) {
continue;
}
if (!isResolvable(ref)) {
final List<LocalQuickFix> quickFixList = new SmartList<>();
quickFixList.add(new AntChangeContextLocalFix());
if (ref instanceof AntDomPropertyReference) {
final String canonicalText = ref.getCanonicalText();
quickFixList.add(new AntCreatePropertyFix(canonicalText, null));
final PsiFile containingFile = xmlElement.getContainingFile();
if (containingFile != null) {
if (propertyFiles == null) {
propertyFiles = getPropertyFiles(AntSupport.getAntDomProject(containingFile), xmlElement);
}
for (PropertiesFile propertyFile : propertyFiles) {
quickFixList.add(new AntCreatePropertyFix(canonicalText, propertyFile));
}
}
} else if (ref instanceof AntDomTargetReference) {
quickFixList.add(new AntCreateTargetFix(ref.getCanonicalText()));
}
holder.createProblem(domElement, ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, antDomRef.getUnresolvedMessagePattern(), ref.getRangeInElement(), quickFixList.toArray((new LocalQuickFix[quickFixList.size()])));
if (ref instanceof AntDomFileReference) {
if (processed == null) {
processed = new HashSet<>();
}
ContainerUtil.addAll(processed, ((AntDomFileReference) ref).getFileReferenceSet().getAllReferences());
}
}
}
}
Aggregations