Search in sources :

Example 66 with PropertiesFile

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

the class GradleImplicitPropertyUsageProviderTest method testGradleWrapper.

public void testGradleWrapper() {
    VirtualFile vFile = myFixture.copyFileToProject("projects/projectWithAppandLib/gradle/wrapper/gradle-wrapper.properties", "gradle/wrapper/gradle-wrapper.properties");
    PsiFile file = PsiManager.getInstance(getProject()).findFile(vFile);
    assertNotNull(file);
    PropertiesFile propertiesFile = (PropertiesFile) file;
    GradleImplicitPropertyUsageProvider provider = new GradleImplicitPropertyUsageProvider();
    for (IProperty property : propertiesFile.getProperties()) {
        // All properties are considered used in this file
        String name = property.getName();
        assertTrue(name, provider.isUsed((Property) property));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IProperty(com.intellij.lang.properties.IProperty) PsiFile(com.intellij.psi.PsiFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Property(com.intellij.lang.properties.psi.Property) IProperty(com.intellij.lang.properties.IProperty)

Example 67 with PropertiesFile

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

the class GradleImplicitPropertyUsageProviderTest method testLocalProperties.

public void testLocalProperties() {
    VirtualFile vFile = myFixture.copyFileToProject("test.properties", "local.properties");
    PsiFile file = PsiManager.getInstance(getProject()).findFile(vFile);
    assertNotNull(file);
    PropertiesFile propertiesFile = (PropertiesFile) file;
    GradleImplicitPropertyUsageProvider provider = new GradleImplicitPropertyUsageProvider();
    for (IProperty property : propertiesFile.getProperties()) {
        Property p = (Property) property;
        // Only but the property with "unused" in its name are considered used
        String name = property.getName();
        if (name.contains("unused")) {
            assertFalse(name, provider.isUsed(p));
        } else {
            assertTrue(name, provider.isUsed(p));
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IProperty(com.intellij.lang.properties.IProperty) PsiFile(com.intellij.psi.PsiFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Property(com.intellij.lang.properties.psi.Property) IProperty(com.intellij.lang.properties.IProperty)

Example 68 with PropertiesFile

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

the class DGMMemberContributor method doCollectExtensions.

private static void doCollectExtensions(@NotNull Project project, @NotNull GlobalSearchScope resolveScope, List<String> instanceClasses, List<String> staticClasses) {
    PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage("META-INF.services");
    if (aPackage == null)
        return;
    for (PsiDirectory directory : aPackage.getDirectories(resolveScope)) {
        PsiFile file = directory.findFile(DGMUtil.ORG_CODEHAUS_GROOVY_RUNTIME_EXTENSION_MODULE);
        if (file instanceof PropertiesFile) {
            IProperty inst = ((PropertiesFile) file).findPropertyByKey("extensionClasses");
            IProperty stat = ((PropertiesFile) file).findPropertyByKey("staticExtensionClasses");
            if (inst != null)
                collectClasses(inst, instanceClasses);
            if (stat != null)
                collectClasses(stat, staticClasses);
        }
    }
}
Also used : IProperty(com.intellij.lang.properties.IProperty) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile)

Example 69 with PropertiesFile

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

the class FindManagerTest method searchProperty.

private void searchProperty(String query) {
    FindModel findModel = new FindModel();
    findModel.setStringToFind(query);
    findModel.setWholeWordsOnly(true);
    findModel.setFromCursor(false);
    findModel.setGlobal(true);
    findModel.setMultipleFiles(true);
    findModel.setProjectScope(true);
    findModel.setDirectoryName(mySourceDirs[0].getPath());
    findModel.setWithSubdirectories(true);
    List<UsageInfo> usages = findUsages(findModel);
    assertEquals(2, usages.size());
    if (!(usages.get(0).getFile() instanceof PsiJavaFile)) {
        Collections.swap(usages, 0, 1);
    }
    PsiElement refElement = getParentFromUsage(usages.get(0));
    assertTrue(refElement instanceof PsiLiteralExpression);
    assertEquals("xx.yy", ((PsiLiteralExpression) refElement).getValue());
    VirtualFile file = mySourceDirs[0].findFileByRelativePath("x/dd.properties");
    assertNotNull(file);
    PropertiesFile propertiesFile = (PropertiesFile) PsiManager.getInstance(myProject).findFile(file);
    assertNotNull(propertiesFile);
    refElement = getParentFromUsage(usages.get(1));
    assertTrue(refElement instanceof IProperty);
    assertSame(propertiesFile.findPropertyByKey("xx.yy"), refElement);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) IProperty(com.intellij.lang.properties.IProperty) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) UsageInfo(com.intellij.usageView.UsageInfo)

Example 70 with PropertiesFile

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

the class LibraryManager method getResourceBundleFile.

@Nullable
public Pair<PropertiesFile, Integer> getResourceBundleFile(String locale, String bundleName, ModuleInfo moduleInfo) {
    final Project project = moduleInfo.getModule().getProject();
    LibrarySet librarySet = moduleInfo.getLibrarySet();
    do {
        PropertiesFile propertiesFile;
        for (Library library : librarySet.getLibraries()) {
            if (library.hasResourceBundles() && (propertiesFile = getResourceBundleFile(locale, bundleName, library, project)) != null) {
                return new Pair<>(propertiesFile, librarySet.getId());
            }
        }
    } while ((librarySet = librarySet.getParent()) != null);
    // AS-273
    final Sdk sdk = FlexUtils.getSdkForActiveBC(moduleInfo.getModule());
    VirtualFile dir = sdk == null ? null : sdk.getHomeDirectory();
    if (dir != null) {
        dir = dir.findFileByRelativePath("frameworks/projects");
    }
    if (dir != null) {
        for (String libName : new String[] { "framework", "spark", "mx", "airframework", "rpc", "advancedgrids", "charts", "textLayout" }) {
            VirtualFile file = dir.findFileByRelativePath(libName + "/bundles/" + locale + "/" + bundleName + PROPERTIES_EXTENSION);
            if (file != null) {
                return new Pair<>(virtualFileToProperties(project, file), moduleInfo.getFlexLibrarySet().getId());
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Sdk(com.intellij.openapi.projectRoots.Sdk) Pair(com.intellij.openapi.util.Pair) 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