use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class CombinePropertiesFilesAction method getPropertiesFiles.
@Nullable
private static List<PropertiesFile> getPropertiesFiles(AnActionEvent e) {
final PsiElement[] psiElements = e.getData(LangDataKeys.PSI_ELEMENT_ARRAY);
if (psiElements == null || psiElements.length == 0) {
return null;
}
final List<PropertiesFile> files = new ArrayList<>(psiElements.length);
for (PsiElement psiElement : psiElements) {
final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(psiElement);
if (propertiesFile == null) {
return null;
}
files.add(propertiesFile);
}
return files;
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class DissociateResourceBundleAction method extractResourceBundles.
@NotNull
private static Collection<ResourceBundle> extractResourceBundles(final AnActionEvent event) {
final Set<ResourceBundle> targetResourceBundles = new HashSet<>();
final ResourceBundle[] chosenResourceBundles = event.getData(ResourceBundle.ARRAY_DATA_KEY);
if (chosenResourceBundles != null) {
for (ResourceBundle resourceBundle : chosenResourceBundles) {
if (resourceBundle.getPropertiesFiles().size() > 1) {
targetResourceBundles.add(resourceBundle);
}
}
}
final PsiElement[] psiElements = event.getData(LangDataKeys.PSI_ELEMENT_ARRAY);
if (psiElements != null) {
for (PsiElement element : psiElements) {
final PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(element);
if (propertiesFile != null) {
final ResourceBundle bundle = propertiesFile.getResourceBundle();
if (bundle.getPropertiesFiles().size() > 1) {
targetResourceBundles.add(bundle);
}
}
}
}
return targetResourceBundles;
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class DissociateResourceBundleAction method dissociate.
public static void dissociate(final Collection<ResourceBundle> resourceBundles, final Project project) {
final Set<PsiFileSystemItem> toUpdateInProjectView = new HashSet<>();
for (ResourceBundle resourceBundle : resourceBundles) {
for (final PropertiesFile propertiesFile : resourceBundle.getPropertiesFiles()) {
PsiDirectory containingDirectory = propertiesFile.getContainingFile().getContainingDirectory();
if (containingDirectory != null) {
toUpdateInProjectView.add(containingDirectory);
}
}
ResourceBundleManager.getInstance(project).dissociateResourceBundle(resourceBundle);
}
AbstractProjectViewPane currentProjectViewPane = ProjectView.getInstance(project).getCurrentProjectViewPane();
if (currentProjectViewPane == null) {
return;
}
AbstractTreeBuilder treeBuilder = currentProjectViewPane.getTreeBuilder();
if (treeBuilder != null) {
for (PsiFileSystemItem item : toUpdateInProjectView) {
treeBuilder.queueUpdateFrom(item, false);
}
}
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class GotoPropertyParentDeclarationHandler method getGotoDeclarationTarget.
@Nullable
@Override
public PsiElement getGotoDeclarationTarget(@Nullable PsiElement sourceElement, Editor editor) {
Property property = findProperty(sourceElement);
if (property == null)
return null;
final String key = property.getKey();
if (key == null)
return null;
PropertiesFile currentFile = PropertiesImplUtil.getPropertiesFile(property.getContainingFile());
if (currentFile == null)
return null;
do {
currentFile = PropertiesUtil.getParent(currentFile, currentFile.getResourceBundle().getPropertiesFiles());
if (currentFile != null) {
final IProperty parent = currentFile.findPropertyByKey(key);
if (parent != null)
return parent.getPsiElement();
} else {
return null;
}
} while (true);
}
use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.
the class PropertiesInheritorsSearcher method processQuery.
@Override
public void processQuery(@NotNull DefinitionsScopedSearch.SearchParameters queryParameters, @NotNull Processor<PsiElement> consumer) {
final PsiElement element = queryParameters.getElement();
Property prop = ReadAction.compute(() -> GotoPropertyParentDeclarationHandler.findProperty(element));
if (prop == null || !(queryParameters.getScope() instanceof GlobalSearchScope)) {
return;
}
ReadAction.run(() -> {
final String key = prop.getKey();
if (!prop.isValid() || key == null)
return;
final PropertiesFile currentFile = PropertiesImplUtil.getPropertiesFile(prop.getContainingFile());
LOG.assertTrue(currentFile != null);
final GlobalSearchScope scope = (GlobalSearchScope) queryParameters.getScope();
currentFile.getResourceBundle().getPropertiesFiles().stream().filter(f -> f.equals(currentFile)).filter(f -> scope.contains(f.getVirtualFile())).filter(f -> PropertiesUtil.getParent(f, Collections.singleton(currentFile)) == currentFile).map(f -> f.findPropertyByKey(key)).filter(Objects::nonNull).map(IProperty::getPsiElement).anyMatch(psiElement -> {
ProgressManager.checkCanceled();
return !consumer.process(psiElement);
});
});
}
Aggregations