use of com.intellij.openapi.roots.OrderEntry in project intellij-community by JetBrains.
the class GradleScriptType method patchResolveScopeInner.
public GlobalSearchScope patchResolveScopeInner(@Nullable Module module, @NotNull GlobalSearchScope baseScope) {
if (module == null)
return GlobalSearchScope.EMPTY_SCOPE;
if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module))
return baseScope;
GlobalSearchScope result = GlobalSearchScope.EMPTY_SCOPE;
final Project project = module.getProject();
for (OrderEntry entry : ModuleRootManager.getInstance(module).getOrderEntries()) {
if (entry instanceof JdkOrderEntry) {
GlobalSearchScope scopeForSdk = LibraryScopeCache.getInstance(project).getScopeForSdk((JdkOrderEntry) entry);
result = result.uniteWith(scopeForSdk);
}
}
String modulePath = ExternalSystemApiUtil.getExternalProjectPath(module);
if (modulePath == null)
return result;
final Collection<VirtualFile> files = GradleBuildClasspathManager.getInstance(project).getModuleClasspathEntries(modulePath);
result = new ExternalModuleBuildGlobalSearchScope(project, result.uniteWith(new NonClasspathDirectoriesScope(files)), modulePath);
return result;
}
use of com.intellij.openapi.roots.OrderEntry in project intellij-community by JetBrains.
the class ModuleDependencyDataService method importData.
@Override
protected Map<OrderEntry, OrderAware> importData(@NotNull final Collection<DataNode<ModuleDependencyData>> toImport, @NotNull final Module module, @NotNull final IdeModifiableModelsProvider modelsProvider) {
final Map<Pair<String, DependencyScope>, ModuleOrderEntry> /* dependency module scope */
toRemove = ContainerUtilRt.newHashMap();
final Map<OrderEntry, OrderAware> orderEntryDataMap = ContainerUtil.newLinkedHashMap();
for (OrderEntry entry : modelsProvider.getOrderEntries(module)) {
if (entry instanceof ModuleOrderEntry) {
ModuleOrderEntry e = (ModuleOrderEntry) entry;
toRemove.put(Pair.create(e.getModuleName(), e.getScope()), e);
}
}
final Set<ModuleDependencyData> processed = ContainerUtil.newHashSet();
final ModifiableRootModel modifiableRootModel = modelsProvider.getModifiableRootModel(module);
for (DataNode<ModuleDependencyData> dependencyNode : toImport) {
final ModuleDependencyData dependencyData = dependencyNode.getData();
if (processed.contains(dependencyData))
continue;
processed.add(dependencyData);
toRemove.remove(Pair.create(dependencyData.getInternalName(), dependencyData.getScope()));
final ModuleData moduleData = dependencyData.getTarget();
Module ideDependencyModule = modelsProvider.findIdeModule(moduleData);
ModuleOrderEntry orderEntry;
if (module.equals(ideDependencyModule)) {
// skip recursive module dependency check
continue;
} else {
if (ideDependencyModule == null) {
LOG.warn(String.format("Can't import module dependency for '%s' module. Reason: target module (%s) is not found at the ide", module.getName(), dependencyData));
}
orderEntry = modelsProvider.findIdeModuleDependency(dependencyData, module);
if (orderEntry == null) {
orderEntry = ReadAction.compute(() -> ideDependencyModule == null ? modifiableRootModel.addInvalidModuleEntry(moduleData.getInternalName()) : modifiableRootModel.addModuleOrderEntry(ideDependencyModule));
}
}
orderEntry.setScope(dependencyData.getScope());
orderEntry.setExported(dependencyData.isExported());
final boolean productionOnTestDependency = dependencyData.isProductionOnTestDependency();
if (orderEntry instanceof ModuleOrderEntryImpl) {
((ModuleOrderEntryImpl) orderEntry).setProductionOnTestDependency(productionOnTestDependency);
} else if (productionOnTestDependency) {
LOG.warn("Unable to set productionOnTestDependency for entry: " + orderEntry);
}
orderEntryDataMap.put(orderEntry, dependencyData);
}
if (!toRemove.isEmpty()) {
removeData(toRemove.values(), module, modelsProvider);
}
return orderEntryDataMap;
}
use of com.intellij.openapi.roots.OrderEntry in project intellij-community by JetBrains.
the class DocumentationManager method navigateByLink.
void navigateByLink(final DocumentationComponent component, final String url) {
component.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
final PsiElement psiElement = component.getElement();
if (psiElement == null) {
return;
}
final PsiManager manager = PsiManager.getInstance(getProject(psiElement));
if (url.startsWith("open")) {
final PsiFile containingFile = psiElement.getContainingFile();
OrderEntry libraryEntry = null;
if (containingFile != null) {
final VirtualFile virtualFile = containingFile.getVirtualFile();
libraryEntry = LibraryUtil.findLibraryEntry(virtualFile, myProject);
} else if (psiElement instanceof PsiDirectoryContainer) {
PsiDirectory[] directories = ((PsiDirectoryContainer) psiElement).getDirectories();
for (PsiDirectory directory : directories) {
final VirtualFile virtualFile = directory.getVirtualFile();
libraryEntry = LibraryUtil.findLibraryEntry(virtualFile, myProject);
if (libraryEntry != null) {
break;
}
}
}
if (libraryEntry != null) {
ProjectSettingsService.getInstance(myProject).openLibraryOrSdkSettings(libraryEntry);
}
} else if (url.startsWith(DocumentationManagerProtocol.PSI_ELEMENT_PROTOCOL)) {
String refText = url.substring(DocumentationManagerProtocol.PSI_ELEMENT_PROTOCOL.length());
int separatorPos = refText.lastIndexOf(DocumentationManagerProtocol.PSI_ELEMENT_PROTOCOL_REF_SEPARATOR);
String ref = null;
if (separatorPos >= 0) {
ref = refText.substring(separatorPos + DocumentationManagerProtocol.PSI_ELEMENT_PROTOCOL_REF_SEPARATOR.length());
refText = refText.substring(0, separatorPos);
}
DocumentationProvider provider = getProviderFromElement(psiElement);
PsiElement targetElement = provider.getDocumentationElementForLink(manager, refText, psiElement);
if (targetElement == null) {
for (DocumentationProvider documentationProvider : Extensions.getExtensions(DocumentationProvider.EP_NAME)) {
targetElement = documentationProvider.getDocumentationElementForLink(manager, refText, psiElement);
if (targetElement != null) {
break;
}
}
}
if (targetElement == null) {
for (Language language : Language.getRegisteredLanguages()) {
DocumentationProvider documentationProvider = LanguageDocumentation.INSTANCE.forLanguage(language);
if (documentationProvider != null) {
targetElement = documentationProvider.getDocumentationElementForLink(manager, refText, psiElement);
if (targetElement != null) {
break;
}
}
}
}
if (targetElement != null) {
fetchDocInfo(getDefaultCollector(targetElement, null, ref), component);
}
} else {
final DocumentationProvider provider = getProviderFromElement(psiElement);
boolean processed = false;
if (provider instanceof CompositeDocumentationProvider) {
for (DocumentationProvider p : ((CompositeDocumentationProvider) provider).getAllProviders()) {
if (!(p instanceof ExternalDocumentationHandler))
continue;
final ExternalDocumentationHandler externalHandler = (ExternalDocumentationHandler) p;
if (externalHandler.canFetchDocumentationLink(url)) {
fetchDocInfo(new DocumentationCollector() {
@Override
public String getDocumentation() throws Exception {
return externalHandler.fetchExternalDocumentation(url, psiElement);
}
@Override
public PsiElement getElement() {
return psiElement;
}
@Nullable
@Override
public String getEffectiveExternalUrl() {
return url;
}
@Nullable
@Override
public String getRef() {
return null;
}
}, component);
processed = true;
} else if (externalHandler.handleExternalLink(manager, url, psiElement)) {
processed = true;
break;
}
}
}
if (!processed) {
fetchDocInfo(new DocumentationCollector() {
@Override
public String getDocumentation() throws Exception {
if (BrowserUtil.isAbsoluteURL(url)) {
BrowserUtil.browse(url);
return "";
} else {
return CodeInsightBundle.message("javadoc.error.resolving.url", url);
}
}
@Override
public PsiElement getElement() {
return psiElement;
}
@Nullable
@Override
public String getEffectiveExternalUrl() {
return url;
}
@Nullable
@Override
public String getRef() {
return null;
}
}, component);
}
}
component.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
use of com.intellij.openapi.roots.OrderEntry in project intellij-community by JetBrains.
the class LibraryEditingUtil method getNotAddedSuitableLibrariesCondition.
public static Predicate<Library> getNotAddedSuitableLibrariesCondition(final ModuleRootModel rootModel, final FacetsProvider facetsProvider) {
final OrderEntry[] orderEntries = rootModel.getOrderEntries();
final Set<Library> result = new HashSet<>(orderEntries.length);
for (OrderEntry orderEntry : orderEntries) {
if (orderEntry instanceof LibraryOrderEntry && orderEntry.isValid()) {
final LibraryImpl library = (LibraryImpl) ((LibraryOrderEntry) orderEntry).getLibrary();
if (library != null) {
final Library source = library.getSource();
result.add(source != null ? source : library);
}
}
}
return new Predicate<Library>() {
@Override
public boolean apply(Library library) {
if (result.contains(library))
return false;
if (library instanceof LibraryImpl) {
final Library source = ((LibraryImpl) library).getSource();
if (source != null && result.contains(source))
return false;
}
PersistentLibraryKind<?> kind = ((LibraryEx) library).getKind();
if (kind != null) {
LibraryType type = LibraryType.findByKind(kind);
if (type != null && !type.isSuitableModule(rootModel.getModule(), facetsProvider)) {
return false;
}
}
return true;
}
};
}
use of com.intellij.openapi.roots.OrderEntry in project intellij-community by JetBrains.
the class ModuleSourceItemGroup method collectDependentModules.
private static void collectDependentModules(final Module module, Set<Module> modules, ArtifactEditorContext context) {
if (!modules.add(module))
return;
for (OrderEntry entry : context.getModulesProvider().getRootModel(module).getOrderEntries()) {
if (entry instanceof ModuleOrderEntry) {
final ModuleOrderEntry moduleEntry = (ModuleOrderEntry) entry;
final Module dependency = moduleEntry.getModule();
final DependencyScope scope = moduleEntry.getScope();
if (dependency != null && scope.isForProductionRuntime()) {
collectDependentModules(dependency, modules, context);
}
}
}
}
Aggregations