use of com.intellij.openapi.roots.ProjectRootManager in project intellij-community by JetBrains.
the class PyBuiltinCache method findSdkForNonModuleFile.
@Nullable
public static Sdk findSdkForNonModuleFile(PsiFileSystemItem psiFile) {
Project project = psiFile.getProject();
Sdk sdk = null;
final VirtualFile vfile = psiFile instanceof PsiFile ? ((PsiFile) psiFile).getOriginalFile().getVirtualFile() : psiFile.getVirtualFile();
if (vfile != null) {
// reality
final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(project);
sdk = projectRootManager.getProjectSdk();
if (sdk == null) {
final List<OrderEntry> orderEntries = projectRootManager.getFileIndex().getOrderEntriesForFile(vfile);
for (OrderEntry orderEntry : orderEntries) {
if (orderEntry instanceof JdkOrderEntry) {
sdk = ((JdkOrderEntry) orderEntry).getJdk();
} else if (orderEntry instanceof ModuleLibraryOrderEntryImpl) {
sdk = PythonSdkType.findPythonSdk(orderEntry.getOwnerModule());
}
}
}
}
return sdk;
}
use of com.intellij.openapi.roots.ProjectRootManager in project kotlin by JetBrains.
the class MoveKotlinNestedClassesToUpperLevelDialog method getTargetContainer.
@Nullable
private PsiElement getTargetContainer() {
if (targetContainer instanceof PsiDirectory) {
PsiDirectory psiDirectory = (PsiDirectory) targetContainer;
FqName oldPackageFqName = getTargetPackageFqName();
String targetName = packageNameField.getText();
if (!Comparing.equal(oldPackageFqName != null ? oldPackageFqName.asString() : null, targetName)) {
ProjectRootManager projectRootManager = ProjectRootManager.getInstance(project);
List<VirtualFile> contentSourceRoots = JavaProjectRootsUtil.getSuitableDestinationSourceRoots(project);
final PackageWrapper newPackage = new PackageWrapper(PsiManager.getInstance(project), targetName);
final VirtualFile targetSourceRoot;
if (contentSourceRoots.size() > 1) {
PsiDirectory initialDir = null;
PsiPackage oldPackage = oldPackageFqName != null ? JavaPsiFacade.getInstance(project).findPackage(oldPackageFqName.asString()) : null;
if (oldPackage != null) {
PsiDirectory[] directories = oldPackage.getDirectories();
VirtualFile root = projectRootManager.getFileIndex().getContentRootForFile(psiDirectory.getVirtualFile());
for (PsiDirectory dir : directories) {
if (Comparing.equal(projectRootManager.getFileIndex().getContentRootForFile(dir.getVirtualFile()), root)) {
initialDir = dir;
}
}
}
VirtualFile sourceRoot = MoveClassesOrPackagesUtil.chooseSourceRoot(newPackage, contentSourceRoots, initialDir);
if (sourceRoot == null)
return null;
targetSourceRoot = sourceRoot;
} else {
targetSourceRoot = contentSourceRoots.get(0);
}
PsiDirectory dir = RefactoringUtil.findPackageDirectoryInSourceRoot(newPackage, targetSourceRoot);
if (dir == null) {
dir = ApplicationManager.getApplication().runWriteAction(new NullableComputable<PsiDirectory>() {
@Override
public PsiDirectory compute() {
try {
return RefactoringUtil.createPackageDirectoryInSourceRoot(newPackage, targetSourceRoot);
} catch (IncorrectOperationException e) {
return null;
}
}
});
}
return dir;
}
return targetContainer;
}
if (targetContainer instanceof KtFile || targetContainer instanceof KtClassOrObject)
return targetContainer;
return null;
}
use of com.intellij.openapi.roots.ProjectRootManager in project intellij-elixir by KronicDeth.
the class MixExUnitRunConfigurationProducer method setupConfigurationFromContextImpl.
private boolean setupConfigurationFromContextImpl(@NotNull MixExUnitRunConfiguration configuration, @NotNull PsiElement psiElement) {
boolean contextApplicable = false;
if (psiElement instanceof PsiDirectory) {
PsiDirectory psiDirectory = (PsiDirectory) psiElement;
Module module = ModuleUtilCore.findModuleForPsiElement(psiDirectory);
Sdk sdk;
if (module != null) {
ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
sdk = moduleRootManager.getSdk();
} else {
ProjectRootManager projectRootManager = ProjectRootManager.getInstance(psiDirectory.getProject());
sdk = projectRootManager.getProjectSdk();
}
SdkTypeId sdkTypeId = null;
if (sdk != null) {
sdkTypeId = sdk.getSdkType();
}
if ((sdkTypeId == null || sdkTypeId.equals(ElixirSdkType.getInstance())) && ProjectRootsUtil.isInTestSource(psiDirectory.getVirtualFile(), psiDirectory.getProject())) {
String basePath = psiElement.getProject().getBasePath();
String workingDirectory = workingDirectory(psiElement, basePath);
configuration.setWorkingDirectory(workingDirectory);
PsiDirectory dir = (PsiDirectory) psiElement;
configuration.setName(configurationName(dir, workingDirectory, basePath));
configuration.setProgramParameters(programParameters(dir, workingDirectory));
contextApplicable = true;
}
} else {
PsiFile containingFile = psiElement.getContainingFile();
if (!(containingFile instanceof ElixirFile || containingFile instanceof PsiDirectory))
return false;
if (ProjectRootsUtil.isInTestSource(containingFile)) {
String basePath = psiElement.getProject().getBasePath();
String workingDirectory = workingDirectory(psiElement, basePath);
configuration.setWorkingDirectory(workingDirectory);
int lineNumber = lineNumber(psiElement);
configuration.setName(configurationName(containingFile, lineNumber, workingDirectory, basePath));
configuration.setProgramParameters(programParameters(containingFile, lineNumber, workingDirectory));
contextApplicable = true;
}
}
return contextApplicable;
}
use of com.intellij.openapi.roots.ProjectRootManager in project intellij-plugins by JetBrains.
the class RubyMotionFacetConfigurator method configureSdk.
private static void configureSdk(final Project project) {
final ProjectRootManager manager = ProjectRootManager.getInstance(project);
final Sdk sdk = manager.getProjectSdk();
if (!RubySdkUtil.isNativeRuby19(sdk)) {
for (final Sdk newSdk : ProjectJdkTable.getInstance().getSdksOfType(RubySdkType.getInstance())) {
if (RubySdkUtil.isNativeRuby19(newSdk) && !RubySdkUtil.isNativeRuby20(newSdk) && !RubyRemoteInterpreterManager.getInstance().isRemoteSdk(newSdk)) {
new WriteAction() {
@Override
protected void run(@NotNull Result result) throws Throwable {
ProjectRootManager.getInstance(project).setProjectSdk(newSdk);
}
}.execute();
}
}
}
}
use of com.intellij.openapi.roots.ProjectRootManager in project flutter-intellij by flutter.
the class IntelliJAndroidSdk method setCurrent.
/**
* Changes the project's Java SDK to this one.
*/
public void setCurrent(@NotNull Project project) {
assert ApplicationManager.getApplication().isWriteAccessAllowed();
final ProjectRootManager roots = ProjectRootManager.getInstance(project);
roots.setProjectSdk(sdk);
}
Aggregations