Search in sources :

Example 96 with PropertiesFile

use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.

the class ResourceBundleManager method closeResourceBundleEditors.

private static void closeResourceBundleEditors(@NotNull ResourceBundle resourceBundle) {
    final FileEditorManager fileEditorManager = FileEditorManager.getInstance(resourceBundle.getProject());
    fileEditorManager.closeFile(new ResourceBundleAsVirtualFile(resourceBundle));
    for (final PropertiesFile propertiesFile : resourceBundle.getPropertiesFiles()) {
        fileEditorManager.closeFile(propertiesFile.getVirtualFile());
    }
}
Also used : FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) ResourceBundleAsVirtualFile(com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile)

Example 97 with PropertiesFile

use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.

the class ResourceBundleFileStructureViewElement method getPropertiesMap.

public static MultiMap<String, IProperty> getPropertiesMap(ResourceBundle resourceBundle, boolean onlyIncomplete) {
    List<PropertiesFile> propertiesFiles = resourceBundle.getPropertiesFiles();
    final MultiMap<String, IProperty> propertyNames;
    if (onlyIncomplete) {
        propertyNames = getChildrenIdShowOnlyIncomplete(resourceBundle);
    } else {
        propertyNames = MultiMap.createLinked();
        for (PropertiesFile propertiesFile : propertiesFiles) {
            List<IProperty> properties = propertiesFile.getProperties();
            for (IProperty property : properties) {
                String name = property.getKey();
                propertyNames.putValue(name, property);
            }
        }
    }
    return propertyNames;
}
Also used : IProperty(com.intellij.lang.properties.IProperty) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile)

Example 98 with PropertiesFile

use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.

the class EnterInPropertiesFileHandler method preprocessEnter.

@Override
public Result preprocessEnter(@NotNull final PsiFile file, @NotNull final Editor editor, @NotNull final Ref<Integer> caretOffsetRef, @NotNull final Ref<Integer> caretAdvance, @NotNull final DataContext dataContext, final EditorActionHandler originalHandler) {
    if (file instanceof PropertiesFile) {
        int caretOffset = caretOffsetRef.get().intValue();
        Document document = editor.getDocument();
        PsiDocumentManager.getInstance(file.getProject()).commitDocument(document);
        PsiElement psiAtOffset = file.findElementAt(caretOffset);
        handleEnterInPropertiesFile(editor, document, psiAtOffset, caretOffset);
        return Result.Stop;
    }
    return Result.Continue;
}
Also used : PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement)

Example 99 with PropertiesFile

use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.

the class ResourcesFavoriteNodeProvider method elementContainsFile.

@Override
public boolean elementContainsFile(final Object element, final VirtualFile vFile) {
    if (element instanceof ResourceBundle) {
        ResourceBundle bundle = (ResourceBundle) element;
        final List<PropertiesFile> propertiesFiles = bundle.getPropertiesFiles();
        for (PropertiesFile file : propertiesFiles) {
            final VirtualFile virtualFile = file.getVirtualFile();
            if (virtualFile == null)
                continue;
            if (vFile.getPath().equals(virtualFile.getPath())) {
                return true;
            }
        }
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ResourceBundle(com.intellij.lang.properties.ResourceBundle) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile)

Example 100 with PropertiesFile

use of com.intellij.lang.properties.psi.PropertiesFile in project intellij-community by JetBrains.

the class PropertiesUtil method getParent.

/**
   * messages_en.properties is a parent of the messages_en_US.properties
   */
@Nullable
public static PropertiesFile getParent(@NotNull PropertiesFile file, @NotNull Collection<PropertiesFile> candidates) {
    VirtualFile virtualFile = file.getVirtualFile();
    if (virtualFile == null)
        return null;
    String name = virtualFile.getNameWithoutExtension();
    String[] parts = name.split("_");
    if (parts.length == 1)
        return null;
    List<String> partsList = Arrays.asList(parts);
    for (int i = parts.length - 1; i >= 1; i--) {
        String parentName = StringUtil.join(partsList.subList(0, i), "_") + "." + virtualFile.getExtension();
        for (PropertiesFile candidate : candidates) {
            if (parentName.equals(candidate.getName()))
                return candidate;
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)143 IProperty (com.intellij.lang.properties.IProperty)44 PsiFile (com.intellij.psi.PsiFile)42 VirtualFile (com.intellij.openapi.vfs.VirtualFile)22 ResourceBundle (com.intellij.lang.properties.ResourceBundle)19 PsiElement (com.intellij.psi.PsiElement)19 NotNull (org.jetbrains.annotations.NotNull)19 Nullable (org.jetbrains.annotations.Nullable)18 Property (com.intellij.lang.properties.psi.Property)15 Project (com.intellij.openapi.project.Project)10 XmlPropertiesFile (com.intellij.lang.properties.xml.XmlPropertiesFile)9 PsiDirectory (com.intellij.psi.PsiDirectory)8 IncorrectOperationException (com.intellij.util.IncorrectOperationException)8 THashSet (gnu.trove.THashSet)8 ArrayList (java.util.ArrayList)7 Module (com.intellij.openapi.module.Module)6 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)6 HashSet (com.intellij.util.containers.HashSet)6 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)5 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)5