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