Search in sources :

Example 66 with PsiManager

use of com.intellij.psi.PsiManager in project android by JetBrains.

the class AndroidSourceTypeNode method getSourceDirectories.

protected List<PsiDirectory> getSourceDirectories() {
    PsiManager psiManager = PsiManager.getInstance(myProject);
    List<PsiDirectory> psiDirectories = Lists.newArrayListWithExpectedSize(mySourceRoots.size());
    for (VirtualFile root : mySourceRoots) {
        if (!root.isValid()) {
            continue;
        }
        final PsiDirectory directory = psiManager.findDirectory(root);
        if (directory != null) {
            psiDirectories.add(directory);
        }
    }
    return psiDirectories;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiManager(com.intellij.psi.PsiManager)

Example 67 with PsiManager

use of com.intellij.psi.PsiManager in project android by JetBrains.

the class NonAndroidSourceTypeNode method getDirectories.

@NotNull
@Override
public PsiDirectory[] getDirectories() {
    PsiManager psiManager = PsiManager.getInstance(myProject);
    List<VirtualFile> sourceFolders = getSourceFolders();
    List<PsiDirectory> psiDirectories = Lists.newArrayListWithExpectedSize(sourceFolders.size());
    for (VirtualFile f : sourceFolders) {
        PsiDirectory dir = psiManager.findDirectory(f);
        if (dir != null) {
            psiDirectories.add(dir);
        }
    }
    return psiDirectories.toArray(new PsiDirectory[psiDirectories.size()]);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiManager(com.intellij.psi.PsiManager) NotNull(org.jetbrains.annotations.NotNull)

Example 68 with PsiManager

use of com.intellij.psi.PsiManager in project android by JetBrains.

the class LayoutPullParserFactoryTest method testIsSupported.

@SuppressWarnings("ConstantConditions")
public void testIsSupported() throws Exception {
    VirtualFile layoutFile = myFixture.copyFileToProject("xmlpull/layout.xml", "res/layout-land-v14/foo.xml");
    VirtualFile menuFile = myFixture.copyFileToProject("menus/menu1.xml", "res/menu/menu1.xml");
    VirtualFile drawableFile = myFixture.copyFileToProject("menus/menu1.xml", "res/menu/menu1.xml");
    PsiManager psiManager = PsiManager.getInstance(getProject());
    assertTrue(LayoutPullParserFactory.isSupported(psiManager.findFile(layoutFile)));
    assertTrue(LayoutPullParserFactory.isSupported(psiManager.findFile(menuFile)));
    assertTrue(LayoutPullParserFactory.isSupported(psiManager.findFile(drawableFile)));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiManager(com.intellij.psi.PsiManager)

Example 69 with PsiManager

use of com.intellij.psi.PsiManager in project android by JetBrains.

the class AndroidResourceUtilTest method testIsRJavaFileImportedNoManifest.

/** Tests that a module without an Android Manifest can still import a lib's R class */
public void testIsRJavaFileImportedNoManifest() throws Exception {
    Module libModule = myAdditionalModules.get(0);
    // Remove the current lib manifest (has wrong package name) and copy a manifest with proper package into the lib module.
    deleteManifest(libModule);
    myFixture.copyFileToProject("util/lib/AndroidManifest.xml", "additionalModules/lib/AndroidManifest.xml");
    // Copy an empty R class with the proper package into the lib module.
    VirtualFile libRFile = myFixture.copyFileToProject("util/lib/R.java", "additionalModules/lib/gen/p1/p2/lib/R.java");
    // Add some lib string resources.
    myFixture.copyFileToProject("util/lib/strings.xml", "additionalModules/lib/res/values/strings.xml");
    // Remove the manifest from the main module.
    deleteManifest(myModule);
    // The main module doesn't get a generated R class and inherit fields (lack of manifest)
    AndroidFacet facet = AndroidFacet.getInstance(myModule);
    assertThat(facet).isNotNull();
    PsiField[] mainFields = AndroidResourceUtil.findResourceFields(facet, "string", "lib_hello", false);
    assertEmpty(mainFields);
    // However, if the main module happens to get a handle on the lib's R class
    // (e.g., via "import p1.p2.lib.R;"), then that R class should be recognized
    // (e.g., for goto navigation).
    PsiManager psiManager = PsiManager.getInstance(getProject());
    PsiFile libRClassFile = psiManager.findFile(libRFile);
    assertNotNull(libRClassFile);
    assertTrue(AndroidResourceUtil.isRJavaFile(myFacet, libRClassFile));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiField(com.intellij.psi.PsiField) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 70 with PsiManager

use of com.intellij.psi.PsiManager in project intellij-plugins by JetBrains.

the class ConfigFileRunSettingsSection method getConfigFile.

@Nullable
private PsiFile getConfigFile(@NotNull Project project) {
    String directoryName = myConfigFileTextFieldWithBrowseButton.getText();
    if (directoryName.length() == 0)
        return null;
    directoryName = directoryName.replace(File.separatorChar, '/');
    VirtualFile path = LocalFileSystem.getInstance().findFileByPath(directoryName);
    while (path == null && directoryName.length() > 0) {
        int pos = directoryName.lastIndexOf('/');
        if (pos <= 0)
            break;
        directoryName = directoryName.substring(0, pos);
        path = LocalFileSystem.getInstance().findFileByPath(directoryName);
    }
    if (path != null) {
        PsiManager psiManager = PsiManager.getInstance(project);
        if (!path.isDirectory()) {
            return psiManager.findFile(path);
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiManager(com.intellij.psi.PsiManager) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsiManager (com.intellij.psi.PsiManager)120 VirtualFile (com.intellij.openapi.vfs.VirtualFile)84 PsiFile (com.intellij.psi.PsiFile)61 PsiDirectory (com.intellij.psi.PsiDirectory)31 NotNull (org.jetbrains.annotations.NotNull)26 Project (com.intellij.openapi.project.Project)20 File (java.io.File)19 PsiElement (com.intellij.psi.PsiElement)18 ArrayList (java.util.ArrayList)18 Module (com.intellij.openapi.module.Module)17 Nullable (org.jetbrains.annotations.Nullable)16 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)11 XmlFile (com.intellij.psi.xml.XmlFile)11 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)9 PsiClass (com.intellij.psi.PsiClass)7 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)6 HashSet (java.util.HashSet)6 Nullable (javax.annotation.Nullable)5 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)4 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)4