本文整理汇总了Java中org.jetbrains.jps.model.java.JavaModuleSourceRootTypes类的典型用法代码示例。如果您正苦于以下问题:Java JavaModuleSourceRootTypes类的具体用法?Java JavaModuleSourceRootTypes怎么用?Java JavaModuleSourceRootTypes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JavaModuleSourceRootTypes类属于org.jetbrains.jps.model.java包,在下文中一共展示了JavaModuleSourceRootTypes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isAvailable
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes; //导入依赖的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: isAvailable
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes; //导入依赖的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;
}
示例3: isAccepted
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes; //导入依赖的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;
});
}
示例4: update
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes; //导入依赖的package包/类
@Override
public void update(AnActionEvent e) {
super.update(e);
final Presentation presentation = e.getPresentation();
if(presentation.isEnabled()) {
final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
final Project project = e.getProject();
if (view != null && project != null) {
ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
PsiDirectory[] dirs = view.getDirectories();
for (PsiDirectory dir : dirs) {
if (projectFileIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) &&
JavaDirectoryService.getInstance().getPackage(dir) != null && isValidForClass(project,dir)) {
return;
}
}
}
presentation.setEnabled(false);
presentation.setVisible(false);
}
}
示例5: addCompletions
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes; //导入依赖的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
示例6: getNonTrivialPackagePrefixes
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes; //导入依赖的package包/类
@NotNull
@Override
public Collection<String> getNonTrivialPackagePrefixes() {
Set<String> names = myNontrivialPackagePrefixes;
if (names == null) {
names = new HashSet<String>();
final ProjectRootManager rootManager = ProjectRootManager.getInstance(myManager.getProject());
final List<VirtualFile> sourceRoots = rootManager.getModuleSourceRoots(JavaModuleSourceRootTypes.SOURCES);
final ProjectFileIndex fileIndex = rootManager.getFileIndex();
for (final VirtualFile sourceRoot : sourceRoots) {
if (sourceRoot.isDirectory()) {
final String packageName = fileIndex.getPackageNameByDirectory(sourceRoot);
if (packageName != null && !packageName.isEmpty()) {
names.add(packageName);
}
}
}
myNontrivialPackagePrefixes = names;
}
return names;
}
示例7: getAllPackagePrefixes
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes; //导入依赖的package包/类
public Collection<String> getAllPackagePrefixes(@Nullable GlobalSearchScope scope) {
MultiMap<String, Module> map = myMap;
if (map != null) {
return getAllPackagePrefixes(scope, map);
}
map = new MultiMap<String, Module>();
for (final Module module : ModuleManager.getInstance(myProject).getModules()) {
for (final ContentEntry entry : ModuleRootManager.getInstance(module).getContentEntries()) {
for (final SourceFolder folder : entry.getSourceFolders(JavaModuleSourceRootTypes.SOURCES)) {
final String prefix = folder.getPackagePrefix();
if (StringUtil.isNotEmpty(prefix)) {
map.putValue(prefix, module);
}
}
}
}
synchronized (LOCK) {
if (myMap == null) {
myMap = map;
}
return getAllPackagePrefixes(scope, myMap);
}
}
示例8: occursInPackagePrefixes
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes; //导入依赖的package包/类
@NotNull
@Override
public VirtualFile[] occursInPackagePrefixes(@NotNull PsiPackage psiPackage) {
List<VirtualFile> result = new ArrayList<VirtualFile>();
final Module[] modules = ModuleManager.getInstance(psiPackage.getProject()).getModules();
String qualifiedName = psiPackage.getQualifiedName();
for (final Module module : modules) {
for (final ContentEntry contentEntry : ModuleRootManager.getInstance(module).getContentEntries()) {
final List<SourceFolder> sourceFolders = contentEntry.getSourceFolders(JavaModuleSourceRootTypes.SOURCES);
for (final SourceFolder sourceFolder : sourceFolders) {
final String packagePrefix = sourceFolder.getPackagePrefix();
if (packagePrefix.startsWith(qualifiedName)) {
final VirtualFile file = sourceFolder.getFile();
if (file != null) {
result.add(file);
}
}
}
}
}
return VfsUtilCore.toVirtualFileArray(result);
}
示例9: adjustElement
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes; //导入依赖的package包/类
@Nullable
@Override
public PsiElement adjustElement(final PsiElement psiElement) {
final ProjectFileIndex index = ProjectRootManager.getInstance(psiElement.getProject()).getFileIndex();
final PsiFile containingFile = psiElement.getContainingFile();
if (containingFile != null) {
final VirtualFile file = containingFile.getVirtualFile();
if (file != null &&
(index.isUnderSourceRootOfType(file, JavaModuleSourceRootTypes.SOURCES) || index.isInLibraryClasses(file) || index.isInLibrarySource(file))) {
if (psiElement instanceof PsiJavaFile) {
final PsiJavaFile psiJavaFile = (PsiJavaFile)psiElement;
if (psiJavaFile.getViewProvider().getBaseLanguage() == JavaLanguage.INSTANCE) {
final PsiClass[] psiClasses = psiJavaFile.getClasses();
if (psiClasses.length == 1) {
return psiClasses[0];
}
}
}
if (psiElement instanceof PsiClass) {
return psiElement;
}
}
return containingFile;
}
return psiElement;
}
示例10: isEnabled
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes; //导入依赖的package包/类
@Override
protected boolean isEnabled(@NotNull RootsSelection selection, @NotNull Module module) {
if (!isJavaModule(module)) return false;
if (selection.myHaveSelectedFilesUnderSourceRoots) {
return false;
}
if (!selection.mySelectedDirectories.isEmpty()) {
return true;
}
for (SourceFolder root : selection.mySelectedRoots) {
JavaSourceRootProperties properties = root.getJpsElement().getProperties(JavaModuleSourceRootTypes.SOURCES);
if (properties != null && !properties.isForGeneratedSources()) {
return true;
}
}
return false;
}
示例11: checkSourceRootsConfigured
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes; //导入依赖的package包/类
public static boolean checkSourceRootsConfigured(final Module module, final boolean askUserToSetupSourceRoots) {
List<VirtualFile> sourceRoots = ModuleRootManager.getInstance(module).getSourceRoots(JavaModuleSourceRootTypes.SOURCES);
if (sourceRoots.isEmpty()) {
if (!askUserToSetupSourceRoots) {
return false;
}
Project project = module.getProject();
Messages.showErrorDialog(project,
ProjectBundle.message("module.source.roots.not.configured.error", module.getName()),
ProjectBundle.message("module.source.roots.not.configured.title"));
ProjectSettingsService.getInstance(project).showModuleConfigurationDialog(module.getName(), CommonContentEntriesEditor.NAME);
sourceRoots = ModuleRootManager.getInstance(module).getSourceRoots(JavaModuleSourceRootTypes.SOURCES);
if (sourceRoots.isEmpty()) {
return false;
}
}
return true;
}
示例12: enableGenerateAccessors
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes; //导入依赖的package包/类
private void enableGenerateAccessors() {
boolean existingNotALibraryClass = false;
if (useExistingClassButton.isSelected()) {
final PsiClass selectedClass =
JavaPsiFacade.getInstance(myProject).findClass(existingClassField.getText(), GlobalSearchScope.projectScope(myProject));
if (selectedClass != null) {
final PsiFile containingFile = selectedClass.getContainingFile();
if (containingFile != null) {
final VirtualFile virtualFile = containingFile.getVirtualFile();
if (virtualFile != null) {
existingNotALibraryClass = ProjectRootManager.getInstance(myProject).getFileIndex().isUnderSourceRootOfType(virtualFile, JavaModuleSourceRootTypes.SOURCES);
}
}
}
}
myGenerateAccessorsCheckBox.setEnabled(existingNotALibraryClass);
myEscalateVisibilityCheckBox.setEnabled(existingNotALibraryClass);
}
示例13: getFilesToPackage
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes; //导入依赖的package包/类
@NotNull
private static List<VirtualFile> getFilesToPackage(@NotNull AnActionEvent e, @NotNull Project project) {
final VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
if (files == null) return Collections.emptyList();
List<VirtualFile> result = new ArrayList<VirtualFile>();
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final CompilerManager compilerManager = CompilerManager.getInstance(project);
for (VirtualFile file : files) {
if (file == null || file.isDirectory() ||
fileIndex.isUnderSourceRootOfType(file, JavaModuleSourceRootTypes.SOURCES) && compilerManager.isCompilableFileType(file.getFileType())) {
return Collections.emptyList();
}
final Collection<? extends Artifact> artifacts = ArtifactBySourceFileFinder.getInstance(project).findArtifacts(file);
for (Artifact artifact : artifacts) {
if (!StringUtil.isEmpty(artifact.getOutputPath())) {
result.add(file);
break;
}
}
}
return result;
}
示例14: markRootAsGenerated
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes; //导入依赖的package包/类
private static void markRootAsGenerated(ModifiableRootModel model, VirtualFile root, Ref<Boolean> modelChangedFlag) {
final ContentEntry contentEntry = findContentEntryForRoot(model, root);
if (contentEntry == null) {
return;
}
for (SourceFolder sourceFolder : contentEntry.getSourceFolders()) {
if (root.equals(sourceFolder.getFile())) {
final JavaSourceRootProperties props = sourceFolder.getJpsElement().getProperties(JavaModuleSourceRootTypes.SOURCES);
if (props != null) {
props.setForGeneratedSources(true);
modelChangedFlag.set(true);
break;
}
}
}
}
示例15: isAvailable
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes; //导入依赖的package包/类
private static boolean isAvailable(DataContext dataContext) {
final Module module = LangDataKeys.MODULE.getData(dataContext);
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
if (module == null ||
view == null ||
view.getDirectories().length == 0) {
return false;
}
final AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet == null || facet.isGradleProject()) {
return false;
}
final ProjectFileIndex projectIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
final JavaDirectoryService dirService = JavaDirectoryService.getInstance();
for (PsiDirectory dir : view.getDirectories()) {
if (projectIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) &&
dirService.getPackage(dir) != null) {
return true;
}
}
return false;
}