本文整理汇总了Java中com.intellij.openapi.roots.ProjectRootManager类的典型用法代码示例。如果您正苦于以下问题:Java ProjectRootManager类的具体用法?Java ProjectRootManager怎么用?Java ProjectRootManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProjectRootManager类属于com.intellij.openapi.roots包,在下文中一共展示了ProjectRootManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isAvailable
import com.intellij.openapi.roots.ProjectRootManager; //导入依赖的package包/类
@CheckReturnValue
@VisibleForTesting
@SuppressWarnings("WeakerAccess")
static boolean isAvailable(@Nonnull AnActionEvent event) {
final Project project = event.getProject();
if (project == null) {
return false;
}
final IdeView view = event.getData(LangDataKeys.IDE_VIEW);
if (view == null) {
return false;
}
final ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
final ProjectFileIndex fileIndex = rootManager.getFileIndex();
final Optional<PsiDirectory> sourceDirectory = Stream.of(view.getDirectories())
.filter(directory -> {
final VirtualFile virtualFile = directory.getVirtualFile();
return fileIndex.isUnderSourceRootOfType(virtualFile, JavaModuleSourceRootTypes.SOURCES);
})
.findFirst();
return sourceDirectory.isPresent();
}
示例2: selectSdk
import com.intellij.openapi.roots.ProjectRootManager; //导入依赖的package包/类
private void selectSdk(@NotNull final Project project) {
Validate.notNull(project);
final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(project);
final Sdk projectSdk = projectRootManager.getProjectSdk();
if (null == projectSdk) {
return;
}
if (StringUtils.isNotBlank(projectSdk.getVersionString())) {
final JavaSdkVersion sdkVersion = JdkVersionUtil.getVersion(projectSdk.getVersionString());
final LanguageLevelProjectExtension languageLevelExt = LanguageLevelProjectExtension.getInstance(project);
if (sdkVersion.getMaxLanguageLevel() != languageLevelExt.getLanguageLevel()) {
languageLevelExt.setLanguageLevel(sdkVersion.getMaxLanguageLevel());
}
}
}
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:21,代码来源:ImportProjectProgressModalWindow.java
示例3: getWizard
import com.intellij.openapi.roots.ProjectRootManager; //导入依赖的package包/类
private AddModuleWizard getWizard(final Project project) throws ConfigurationException {
final HybrisProjectImportProvider provider = getHybrisProjectImportProvider();
final String basePath = project.getBasePath();
final String projectName = project.getName();
final Sdk jdk = ProjectRootManager.getInstance(project).getProjectSdk();
final String compilerOutputUrl = CompilerProjectExtension.getInstance(project).getCompilerOutputUrl();
final HybrisProjectSettings settings = HybrisProjectSettingsComponent.getInstance(project).getState();
final AddModuleWizard wizard = new AddModuleWizard(null, basePath, provider) {
protected void init() {
// non GUI mode
}
};
final WizardContext wizardContext = wizard.getWizardContext();
wizardContext.setProjectJdk(jdk);
wizardContext.setProjectName(projectName);
wizardContext.setCompilerOutputDirectory(compilerOutputUrl);
final StepSequence stepSequence = wizard.getSequence();
for (ModuleWizardStep step : stepSequence.getAllSteps()) {
if (step instanceof NonGuiSupport) {
((NonGuiSupport) step).nonGuiModeImport(settings);
}
}
return wizard;
}
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:27,代码来源:ProjectRefreshAction.java
示例4: setJdk
import com.intellij.openapi.roots.ProjectRootManager; //导入依赖的package包/类
protected void setJdk(@NotNull Project project) {
JdkComboBox.JdkComboBoxItem selectedItem = myJdkComboBox.getSelectedItem();
if (selectedItem instanceof JdkComboBox.SuggestedJdkItem) {
SdkType type = ((JdkComboBox.SuggestedJdkItem)selectedItem).getSdkType();
String path = ((JdkComboBox.SuggestedJdkItem)selectedItem).getPath();
myModel.addSdk(type, path, sdk -> {
myJdkComboBox.reloadModel(new JdkComboBox.ActualJdkComboBoxItem(sdk), project);
myJdkComboBox.setSelectedJdk(sdk);
});
}
try {
myModel.apply();
} catch (ConfigurationException e) {
LOG.error(e);
}
ApplicationManager.getApplication().runWriteAction(() -> {
ProjectRootManager.getInstance(project).setProjectSdk(myJdkComboBox.getSelectedJdk());
});
}
示例5: isAvailable
import com.intellij.openapi.roots.ProjectRootManager; //导入依赖的package包/类
/**
* Checked whether or not this action can be enabled.
*
* <p>Requirements to be enabled: * User must be in a Java source folder.
*
* @param dataContext to figure out where the user is.
* @return {@code true} when the action is available, {@code false} when the action is not
* available.
*/
private boolean isAvailable(DataContext dataContext) {
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project == null) {
return false;
}
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
if (view == null || view.getDirectories().length == 0) {
return false;
}
ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
for (PsiDirectory dir : view.getDirectories()) {
if (projectFileIndex.isUnderSourceRootOfType(
dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES)
&& checkPackageExists(dir)) {
return true;
}
}
return false;
}
示例6: isAccepted
import com.intellij.openapi.roots.ProjectRootManager; //导入依赖的package包/类
@Override
public boolean isAccepted(PsiClass klass) {
return ApplicationManager.getApplication().runReadAction((Computable<Boolean>) () -> {
if (isSketchClass(klass)) {
final CompilerConfiguration compilerConfiguration = CompilerConfiguration.getInstance(project);
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(klass);
if (virtualFile == null) {
return false;
}
return ! compilerConfiguration.isExcludedFromCompilation(virtualFile) &&
! ProjectRootManager.getInstance(project)
.getFileIndex()
.isUnderSourceRootOfType(virtualFile, JavaModuleSourceRootTypes.RESOURCES);
}
return false;
});
}
示例7: getProjectForFile
import com.intellij.openapi.roots.ProjectRootManager; //导入依赖的package包/类
/**
* Look through all open projects and see if git head symlink file is contained in it.
*/
private Project getProjectForFile(VirtualFile gitHeadFile) {
//
for (Project project : ProjectManager.getInstance().getOpenProjects()) {
try {
VirtualFile[] contentRootArray = ProjectRootManager.getInstance(project).getContentRoots();
for (VirtualFile virtualFile : contentRootArray) {
String expectedLoc = virtualFile.getCanonicalPath() + "/.git/HEAD";
if (expectedLoc.equals(gitHeadFile.getCanonicalPath())) {
return project;
}
}
} catch (Exception e) {
// ignore
}
}
return null;
}
示例8: findFiles
import com.intellij.openapi.roots.ProjectRootManager; //导入依赖的package包/类
private Set<VirtualFile> findFiles(VirtualFile file) {
Set<VirtualFile> files = new HashSet<VirtualFile>(0);
Project project = thumbnailView.getProject();
if (!project.isDisposed()) {
ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
boolean projectIgnored = rootManager.getFileIndex().isExcluded(file);
if (!projectIgnored && !FileTypeManager.getInstance().isFileIgnored(file)) {
ImageFileTypeManager typeManager = ImageFileTypeManager.getInstance();
if (file.isDirectory()) {
if (thumbnailView.isRecursive()) {
files.addAll(findFiles(file.getChildren()));
} else if (isImagesInDirectory(file)) {
files.add(file);
}
} else if (typeManager.isImage(file)) {
files.add(file);
}
}
}
return files;
}
示例9: belongs
import com.intellij.openapi.roots.ProjectRootManager; //导入依赖的package包/类
public boolean belongs(String url) {
final VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url);
if (file != null) {
for (FileIndex index : getFileIndices()) {
if (index.isInSourceContent(file)) {
return true;
}
}
}
else {
// the file might be deleted
for (VirtualFile root : ProjectRootManager.getInstance(myProject).getContentSourceRoots()) {
final String rootUrl = root.getUrl();
if (FileUtil.startsWith(url, rootUrl.endsWith("/")? rootUrl : rootUrl + "/")) {
return true;
}
}
}
return false;
//return !FileUtil.startsWith(url, myTempDirUrl);
}
示例10: isVersioned
import com.intellij.openapi.roots.ProjectRootManager; //导入依赖的package包/类
public boolean isVersioned(@NotNull VirtualFile f, boolean shouldBeInContent) {
if (!f.isInLocalFileSystem()) return false;
if (!f.isDirectory() && StringUtil.endsWith(f.getNameSequence(), ".class")) return false;
Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
boolean isInContent = false;
for (Project each : openProjects) {
if (each.isDefault()) continue;
if (!each.isInitialized()) continue;
if (Comparing.equal(each.getWorkspaceFile(), f)) return false;
ProjectFileIndex index = ProjectRootManager.getInstance(each).getFileIndex();
if (index.isExcluded(f)) return false;
isInContent |= index.isInContent(f);
}
if (shouldBeInContent && !isInContent) return false;
// optimisation: FileTypeManager.isFileIgnored(f) already checked inside ProjectFileIndex.isIgnored()
return openProjects.length != 0 || !FileTypeManager.getInstance().isFileIgnored(f);
}
示例11: groupUsage
import com.intellij.openapi.roots.ProjectRootManager; //导入依赖的package包/类
@Override
public UsageGroup groupUsage(@NotNull Usage usage) {
if (!(usage instanceof PsiElementUsage)) {
return null;
}
PsiElementUsage elementUsage = (PsiElementUsage)usage;
PsiElement element = elementUsage.getElement();
VirtualFile virtualFile = PsiUtilCore.getVirtualFile(element);
if (virtualFile == null) {
return null;
}
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(element.getProject()).getFileIndex();
boolean isInLib = fileIndex.isInLibraryClasses(virtualFile) || fileIndex.isInLibrarySource(virtualFile);
if (isInLib) return LIBRARY;
boolean isInTest = fileIndex.isInTestSourceContent(virtualFile);
return isInTest ? TEST : PRODUCTION;
}
示例12: getScope
import com.intellij.openapi.roots.ProjectRootManager; //导入依赖的package包/类
@Nullable
private AnalysisScope getScope() {
final Set<PsiFile> selectedScope = getSelectedScope(myRightTree);
Set<PsiFile> result = new HashSet<PsiFile>();
((PackageDependenciesNode)myLeftTree.getModel().getRoot()).fillFiles(result, !mySettings.UI_FLATTEN_PACKAGES);
selectedScope.removeAll(result);
if (selectedScope.isEmpty()) return null;
List<VirtualFile> files = new ArrayList<VirtualFile>();
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
for (PsiFile psiFile : selectedScope) {
final VirtualFile file = psiFile.getVirtualFile();
LOG.assertTrue(file != null);
if (fileIndex.isInContent(file)) {
files.add(file);
}
}
if (!files.isEmpty()) {
return new AnalysisScope(myProject, files);
}
return null;
}
示例13: addCompletions
import com.intellij.openapi.roots.ProjectRootManager; //导入依赖的package包/类
@Override
public void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet resultSet, @NotNull String[] query) {
Project project = parameters.getOriginalFile().getManager().getProject();
List<VirtualFile> resourceRoots = ProjectRootManager.getInstance(project).getModuleSourceRoots(JavaModuleSourceRootTypes.PRODUCTION);
resourceRoots.addAll(ProjectRootManager.getInstance(project).getModuleSourceRoots(JavaModuleSourceRootTypes.TESTS));
ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
for (final VirtualFile sourceRoot : resourceRoots) {
if (sourceRoot.isValid() && sourceRoot.getCanonicalFile() != null) {
VfsUtil.processFilesRecursively(sourceRoot.getCanonicalFile(), virtualFile -> {
propertyCompletionProviders.stream()
.filter(p -> p.isValidExtension(virtualFile.getCanonicalPath()) && !projectFileIndex.isExcluded(sourceRoot))
.forEach(p -> p.buildResultSet(resultSet, virtualFile));
return true;
});
}
}
}
开发者ID:camel-idea-plugin,项目名称:camel-idea-plugin,代码行数:19,代码来源:CamelPropertyPlaceholderSmartCompletionExtension.java
示例14: toString
import com.intellij.openapi.roots.ProjectRootManager; //导入依赖的package包/类
@Override
public String toString() {
if (myText == null) {
Module module = ModuleUtilCore.findModuleForPsiElement(myClass);
if (module != null) {
myText = module.getName();
}
else {
VirtualFile virtualFile = myClass.getContainingFile().getVirtualFile();
final ProjectFileIndex index = ProjectRootManager.getInstance(myClass.getProject()).getFileIndex();
VirtualFile root = index.getSourceRootForFile(virtualFile);
if (root == null) {
root = index.getClassRootForFile(virtualFile);
}
if (root != null) {
myText = root.getName();
}
else {
myText = virtualFile.getPath();
}
}
}
return myText;
}
示例15: getDirCoverageInfo
import com.intellij.openapi.roots.ProjectRootManager; //导入依赖的package包/类
@Nullable
protected DirCoverageInfo getDirCoverageInfo(@NotNull final PsiDirectory directory,
@NotNull final CoverageSuitesBundle currentSuite) {
final VirtualFile dir = directory.getVirtualFile();
final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(directory.getProject()).getFileIndex();
//final Module module = projectFileIndex.getModuleForFile(dir);
final boolean isInTestContent = projectFileIndex.isInTestSourceContent(dir);
if (!currentSuite.isTrackTestFolders() && isInTestContent) {
return null;
}
final String path = normalizeFilePath(dir.getPath());
return isInTestContent ? myTestDirCoverageInfos.get(path) : myDirCoverageInfos.get(path);
}