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;
}
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()]);
}
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)));
}
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));
}
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;
}
Aggregations