Search in sources :

Example 1 with PsiJavaModule

use of com.intellij.psi.PsiJavaModule in project intellij-community by JetBrains.

the class RenameJavaModuleProcessor method findCollisions.

@Override
public void findCollisions(PsiElement element, String newName, Map<? extends PsiElement, String> allRenames, List<UsageInfo> result) {
    Project project = element.getProject();
    PsiJavaModule existing = ContainerUtil.getFirstItem(JavaModuleNameIndex.getInstance().get(newName, project, ProjectScope.getProjectScope(project)));
    if (existing != null) {
        result.add(new UnresolvableCollisionUsageInfo(element, existing) {

            @Override
            public String getDescription() {
                return RefactoringBundle.message("rename.module.already.exists", newName);
            }
        });
    }
}
Also used : Project(com.intellij.openapi.project.Project) PsiJavaModule(com.intellij.psi.PsiJavaModule)

Example 2 with PsiJavaModule

use of com.intellij.psi.PsiJavaModule in project intellij-community by JetBrains.

the class JavaModulePresentationProvider method getPresentation.

@Override
public ItemPresentation getPresentation(@NotNull final PsiJavaModule item) {
    return new ItemPresentation() {

        @Override
        public String getPresentableText() {
            return item.getName();
        }

        @Nullable
        @Override
        public String getLocationString() {
            VirtualFile file = PsiImplUtil.getModuleVirtualFile(item);
            FileIndexFacade index = FileIndexFacade.getInstance(item.getProject());
            if (index.isInLibraryClasses(file)) {
                Matcher matcher = JAR_NAME.matcher(file.getPath());
                if (matcher.find()) {
                    return matcher.group(1);
                }
            } else if (index.isInSource(file)) {
                Module module = index.getModuleForFile(file);
                if (module != null) {
                    return '[' + module.getName() + ']';
                }
            }
            return null;
        }

        @Nullable
        @Override
        public Icon getIcon(boolean unused) {
            return AllIcons.Nodes.JavaModule;
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Matcher(java.util.regex.Matcher) ItemPresentation(com.intellij.navigation.ItemPresentation) PsiJavaModule(com.intellij.psi.PsiJavaModule) Module(com.intellij.openapi.module.Module) FileIndexFacade(com.intellij.openapi.roots.FileIndexFacade)

Example 3 with PsiJavaModule

use of com.intellij.psi.PsiJavaModule in project intellij-community by JetBrains.

the class JavaModuleNameIndex method filterVersions.

private static Collection<PsiJavaModule> filterVersions(Project project, Collection<PsiJavaModule> modules) {
    Map<VirtualFile, PsiJavaModule> filter = ContainerUtil.newHashMap();
    Set<PsiJavaModule> screened = ContainerUtil.newHashSet();
    ProjectFileIndex index = ProjectFileIndex.SERVICE.getInstance(project);
    for (PsiJavaModule module : modules) {
        VirtualFile file = module.getContainingFile().getVirtualFile();
        if (index.isInLibraryClasses(file)) {
            VirtualFile classRoot = index.getClassRootForFile(file);
            if (classRoot != null) {
                PsiJavaModule previous = filter.get(classRoot);
                if (previous == null) {
                    filter.put(classRoot, module);
                } else if (compareVersionNumbers(fileVersion(file), fileVersion(previous.getContainingFile().getVirtualFile())) < 0) {
                    filter.put(classRoot, module);
                    screened.add(previous);
                } else {
                    screened.add(module);
                }
            }
        }
    }
    return screened.isEmpty() ? modules : modules.stream().filter(module -> !screened.contains(module)).collect(Collectors.toList());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiJavaModule(com.intellij.psi.PsiJavaModule)

Aggregations

PsiJavaModule (com.intellij.psi.PsiJavaModule)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 ItemPresentation (com.intellij.navigation.ItemPresentation)1 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 FileIndexFacade (com.intellij.openapi.roots.FileIndexFacade)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 Matcher (java.util.regex.Matcher)1