Search in sources :

Example 16 with PropertiesFile

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

the class I18nUtil method createProperty.

public static void createProperty(final Project project, final Collection<PropertiesFile> propertiesFiles, final String key, final String value) throws IncorrectOperationException {
    for (PropertiesFile file : propertiesFiles) {
        PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
        documentManager.commitDocument(documentManager.getDocument(file.getContainingFile()));
        IProperty existingProperty = file.findPropertyByKey(key);
        if (existingProperty == null) {
            file.addProperty(key, value);
        }
    }
}
Also used : IProperty(com.intellij.lang.properties.IProperty) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) XmlPropertiesFile(com.intellij.lang.properties.xml.XmlPropertiesFile) PsiDocumentManager(com.intellij.psi.PsiDocumentManager)

Example 17 with PropertiesFile

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

the class PropertyReference method getQuickFixes.

public LocalQuickFix[] getQuickFixes() {
    List<PropertiesFile> propertiesFiles = retrievePropertyFilesByBundleName(myBundleName, getElement());
    LocalQuickFix fix = PropertiesQuickFixFactory.getInstance().createCreatePropertyFix(myElement, myKey, propertiesFiles);
    return new LocalQuickFix[] { fix };
}
Also used : LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile)

Example 18 with PropertiesFile

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

the class PropertyReferenceBase method multiResolve.

@NotNull
public ResolveResult[] multiResolve(final boolean incompleteCode) {
    final String key = getKeyText();
    List<IProperty> properties;
    final List<PropertiesFile> propertiesFiles = getPropertiesFiles();
    if (propertiesFiles == null) {
        properties = PropertiesImplUtil.findPropertiesByKey(getElement().getProject(), key);
    } else {
        properties = new ArrayList<>();
        for (PropertiesFile propertiesFile : propertiesFiles) {
            properties.addAll(propertiesFile.findPropertiesByKey(key));
        }
    }
    // put default properties file first
    ContainerUtil.quickSort(properties, (o1, o2) -> {
        String name1 = o1.getPropertiesFile().getName();
        String name2 = o2.getPropertiesFile().getName();
        return Comparing.compare(name1, name2);
    });
    return getResolveResults(properties);
}
Also used : IProperty(com.intellij.lang.properties.IProperty) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with PropertiesFile

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

the class PropertiesUtil method findAllProperties.

/**
   * @deprecated use PropertiesUtil.findAllProperties(ResourceBundle resourceBundle, String key)
   */
@NotNull
@Deprecated
public static List<IProperty> findAllProperties(Project project, @NotNull ResourceBundle resourceBundle, String key) {
    List<IProperty> result = new SmartList<>();
    List<PropertiesFile> propertiesFiles = resourceBundle.getPropertiesFiles();
    for (PropertiesFile propertiesFile : propertiesFiles) {
        result.addAll(propertiesFile.findPropertiesByKey(key));
    }
    return result;
}
Also used : PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) SmartList(com.intellij.util.SmartList) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with PropertiesFile

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

the class MvcModuleStructureUtil method findApplicationProperties.

@Nullable
public static PropertiesFile findApplicationProperties(@NotNull Module module, MvcFramework framework) {
    VirtualFile root = framework.findAppRoot(module);
    if (root == null)
        return null;
    VirtualFile appChild = root.findChild(APPLICATION_PROPERTIES);
    if (appChild == null || !appChild.isValid())
        return null;
    PsiManager manager = PsiManager.getInstance(module.getProject());
    PsiFile psiFile = manager.findFile(appChild);
    if (psiFile instanceof PropertiesFile) {
        return (PropertiesFile) psiFile;
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile) 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