From 831bcb463a0ed651ee8e06ce9e608bec314e4024 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Mon, 18 May 2015 13:26:01 +0200 Subject: [PATCH] cleanup (prepare to fix IDEA-137908 External documentation (from javadoc.jar) is not shown) --- .../lang/java/JavaDocumentationProvider.java | 20 ++++---- .../PlatformDocumentationUtil.java | 20 ++++---- .../documentation/DocumentationComponent.java | 48 ++++++++++--------- .../ide/actions/ExternalJavaDocAction.java | 10 ++-- .../ide/browsers/BrowserLauncherAppless.java | 6 +-- .../browsers/impl/WebBrowserServiceImpl.java | 2 +- 6 files changed, 55 insertions(+), 51 deletions(-) diff --git a/java/java-impl/src/com/intellij/lang/java/JavaDocumentationProvider.java b/java/java-impl/src/com/intellij/lang/java/JavaDocumentationProvider.java index cb215d06380d..8163544fd81a 100644 --- a/java/java-impl/src/com/intellij/lang/java/JavaDocumentationProvider.java +++ b/java/java-impl/src/com/intellij/lang/java/JavaDocumentationProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -684,7 +684,7 @@ public class JavaDocumentationProvider implements CodeDocumentationProvider, Ext } @Nullable - public static List findUrlForClass(PsiClass aClass) { + public static List findUrlForClass(@NotNull PsiClass aClass) { String qName = aClass.getQualifiedName(); if (qName == null) return null; @@ -696,11 +696,11 @@ public class JavaDocumentationProvider implements CodeDocumentationProvider, Ext String packageName = ((PsiJavaFile)file).getPackageName(); String relPath; - if (packageName.length() > 0) { - relPath = packageName.replace('.', '/') + '/' + qName.substring(packageName.length() + 1) + HTML_EXTENSION; + if (packageName.isEmpty()) { + relPath = qName + HTML_EXTENSION; } else { - relPath = qName + HTML_EXTENSION; + relPath = packageName.replace('.', '/') + '/' + qName.substring(packageName.length() + 1) + HTML_EXTENSION; } return findUrlForVirtualFile(file.getProject(), virtualFile, relPath); @@ -728,11 +728,11 @@ public class JavaDocumentationProvider implements CodeDocumentationProvider, Ext } } - final List orderEntries = fileIndex.getOrderEntriesForFile(virtualFile); - for (OrderEntry orderEntry : orderEntries) { - final String[] files = JavadocOrderRootType.getUrls(orderEntry); - final List httpRoot = PlatformDocumentationUtil.getHttpRoots(files, relPath); - if (httpRoot != null) return httpRoot; + for (OrderEntry orderEntry : fileIndex.getOrderEntriesForFile(virtualFile)) { + List httpRoot = PlatformDocumentationUtil.getHttpRoots(JavadocOrderRootType.getUrls(orderEntry), relPath); + if (httpRoot != null) { + return httpRoot; + } } return null; } diff --git a/platform/core-impl/src/com/intellij/codeInsight/documentation/PlatformDocumentationUtil.java b/platform/core-impl/src/com/intellij/codeInsight/documentation/PlatformDocumentationUtil.java index 966d8173c150..fa519f0249bb 100644 --- a/platform/core-impl/src/com/intellij/codeInsight/documentation/PlatformDocumentationUtil.java +++ b/platform/core-impl/src/com/intellij/codeInsight/documentation/PlatformDocumentationUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,10 +19,11 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.vfs.ex.http.HttpFileSystem; +import com.intellij.util.SmartList; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.regex.Matcher; @@ -30,7 +31,6 @@ import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; public class PlatformDocumentationUtil { - private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.documentation.PlatformDocumentationUtil"); private static final @NonNls Pattern ourLtFixupPattern = Pattern.compile("<([^/^\\w^!])"); @@ -38,19 +38,23 @@ public class PlatformDocumentationUtil { private static final @NonNls String LT_ENTITY = "<"; @Nullable - public static List getHttpRoots(final String[] roots, String relPath) { - final ArrayList result = new ArrayList(); + public static List getHttpRoots(@NotNull String[] roots, String relPath) { + List result = new SmartList(); for (String root : roots) { - final VirtualFile virtualFile = VirtualFileManager.getInstance().findFileByUrl(root); + VirtualFile virtualFile = VirtualFileManager.getInstance().findFileByUrl(root); if (virtualFile != null) { if (virtualFile.getFileSystem() instanceof HttpFileSystem) { String url = virtualFile.getUrl(); - if (!url.endsWith("/")) url += "/"; + if (!url.endsWith("/")) { + url += "/"; + } result.add(url + relPath); } else { VirtualFile file = virtualFile.findFileByRelativePath(relPath); - if (file != null) result.add(file.getUrl()); + if (file != null) { + result.add(file.getUrl()); + } } } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationComponent.java b/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationComponent.java index d687848a4949..36e8f4005070 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationComponent.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationComponent.java @@ -705,33 +705,35 @@ public class DocumentationComponent extends JPanel implements Disposable, DataPr @Override public void actionPerformed(AnActionEvent e) { - if (myElement != null) { - final PsiElement element = myElement.getElement(); - final DocumentationProvider provider = DocumentationManager.getProviderFromElement(element); - final PsiElement originalElement = DocumentationManager.getOriginalElement(element); - boolean processed = false; - if (provider instanceof CompositeDocumentationProvider) { - for (DocumentationProvider p : ((CompositeDocumentationProvider)provider).getAllProviders()) { - if (p instanceof ExternalDocumentationHandler && ((ExternalDocumentationHandler)p).handleExternal(element, originalElement)) { - processed = true; - break; - } - } - } + if (myElement == null) { + return; + } - if (!processed) { - final Component component = PlatformDataKeys.CONTEXT_COMPONENT.getData(e.getDataContext()); - final List urls; - if (!StringUtil.isEmptyOrSpaces(myEffectiveExternalUrl)) { - urls = Collections.singletonList(myEffectiveExternalUrl); - } else { - urls = provider.getUrlFor(element, originalElement); - assert urls != null : provider; - assert !urls.isEmpty() : provider; + final PsiElement element = myElement.getElement(); + final DocumentationProvider provider = DocumentationManager.getProviderFromElement(element); + final PsiElement originalElement = DocumentationManager.getOriginalElement(element); + boolean processed = false; + if (provider instanceof CompositeDocumentationProvider) { + for (DocumentationProvider p : ((CompositeDocumentationProvider)provider).getAllProviders()) { + if (p instanceof ExternalDocumentationHandler && ((ExternalDocumentationHandler)p).handleExternal(element, originalElement)) { + processed = true; + break; } - ExternalJavaDocAction.showExternalJavadoc(urls, component); } } + + if (!processed) { + List urls; + if (!StringUtil.isEmptyOrSpaces(myEffectiveExternalUrl)) { + urls = Collections.singletonList(myEffectiveExternalUrl); + } + else { + urls = provider.getUrlFor(element, originalElement); + assert urls != null : provider; + assert !urls.isEmpty() : provider; + } + ExternalJavaDocAction.showExternalJavadoc(urls, PlatformDataKeys.CONTEXT_COMPONENT.getData(e.getDataContext())); + } } @Override diff --git a/platform/lang-impl/src/com/intellij/ide/actions/ExternalJavaDocAction.java b/platform/lang-impl/src/com/intellij/ide/actions/ExternalJavaDocAction.java index 9d73cd569c40..f974d35afd8d 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/ExternalJavaDocAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/ExternalJavaDocAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,11 +35,13 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiReference; import com.intellij.util.ArrayUtil; +import gnu.trove.THashSet; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.awt.*; -import java.util.HashSet; import java.util.List; +import java.util.Set; public class ExternalJavaDocAction extends AnAction { @@ -90,8 +92,8 @@ public class ExternalJavaDocAction extends AnAction { } } - public static void showExternalJavadoc(List urls, Component component) { - final HashSet set = new HashSet(urls); + public static void showExternalJavadoc(@NotNull List urls, Component component) { + Set set = new THashSet(urls); if (set.size() > 1) { JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep("Choose external documentation root", ArrayUtil.toStringArray(set)) { @Override diff --git a/platform/platform-api/src/com/intellij/ide/browsers/BrowserLauncherAppless.java b/platform/platform-api/src/com/intellij/ide/browsers/BrowserLauncherAppless.java index 2385d0000bee..c7f3989c8b7c 100644 --- a/platform/platform-api/src/com/intellij/ide/browsers/BrowserLauncherAppless.java +++ b/platform/platform-api/src/com/intellij/ide/browsers/BrowserLauncherAppless.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -137,10 +137,6 @@ public class BrowserLauncherAppless extends BrowserLauncher { private void openOrBrowse(@NotNull String url, boolean browse, @Nullable Project project) { url = url.trim(); - if (url.startsWith("jar:")) { - return; - } - URI uri; if (BrowserUtil.isAbsoluteURL(url)) { uri = VfsUtil.toUri(url); diff --git a/xml/impl/src/com/intellij/ide/browsers/impl/WebBrowserServiceImpl.java b/xml/impl/src/com/intellij/ide/browsers/impl/WebBrowserServiceImpl.java index 6cd24659c003..097a1d1859fc 100644 --- a/xml/impl/src/com/intellij/ide/browsers/impl/WebBrowserServiceImpl.java +++ b/xml/impl/src/com/intellij/ide/browsers/impl/WebBrowserServiceImpl.java @@ -48,7 +48,7 @@ public class WebBrowserServiceImpl extends WebBrowserService { VirtualFile file = request.getVirtualFile(); return file instanceof LightVirtualFile || !request.getFile().getViewProvider().isPhysical() ? Collections.emptyList() - : Collections.singleton(Urls.newFromVirtualFile(file)); + : Collections.singletonList(Urls.newFromVirtualFile(file)); } @NotNull