public static URL getJavadocBaseLocation(IJavaElement element) throws JavaModelException { if (element.getElementType() == IJavaElement.JAVA_PROJECT) { return getProjectJavadocLocation((IJavaProject) element); } IPackageFragmentRoot root = JavaModelUtil.getPackageFragmentRoot(element); if (root == null) { return null; } if (root.getKind() == IPackageFragmentRoot.K_BINARY) { IClasspathEntry entry = root.getResolvedClasspathEntry(); URL javadocLocation = getLibraryJavadocLocation(entry); if (javadocLocation != null) { return getLibraryJavadocLocation(entry); } entry = root.getRawClasspathEntry(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: return getLibraryJavadocLocation(entry); default: return null; } } else { return getProjectJavadocLocation(root.getJavaProject()); } }
/** * Initializes the source folder field with a valid package fragment root. The package fragment * root is computed from the given Java element. * * @param elem the Java element used to compute the initial package fragment root used as the * source folder */ protected void initContainerPage(IJavaElement elem) { IPackageFragmentRoot initRoot = null; if (elem != null) { initRoot = JavaModelUtil.getPackageFragmentRoot(elem); try { if (initRoot == null || initRoot.getKind() != IPackageFragmentRoot.K_SOURCE) { IJavaProject jproject = elem.getJavaProject(); if (jproject != null) { initRoot = null; if (jproject.exists()) { IPackageFragmentRoot[] roots = jproject.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE) { initRoot = roots[i]; break; } } } if (initRoot == null) { initRoot = jproject.getPackageFragmentRoot(jproject.getResource()); } } } } catch (JavaModelException e) { JavaPlugin.log(e); } } setPackageFragmentRoot(initRoot, true); }
public JavadocHelpContext(IContext context, Object[] elements) throws JavaModelException { Assert.isNotNull(elements); if (context instanceof IContext2) fTitle = ((IContext2) context).getTitle(); List helpResources = new ArrayList(); String javadocSummary = null; for (int i = 0; i < elements.length; i++) { if (elements[i] instanceof IJavaElement) { IJavaElement element = (IJavaElement) elements[i]; // if element isn't on the build path skip it if (!ActionUtil.isOnBuildPath(element)) continue; // Create Javadoc summary if (BUG_85721_FIXED) { if (javadocSummary == null) { javadocSummary = retrieveText(element); if (javadocSummary != null) { String elementLabel = JavaElementLabels.getTextLabel(element, JavaElementLabels.ALL_DEFAULT); // FIXME: needs to be NLSed once the code becomes active javadocSummary = "<b>Javadoc for " + elementLabel + ":</b><br>" + javadocSummary; //$NON-NLS-1$//$NON-NLS-2$ } } else { javadocSummary = ""; // no Javadoc summary for multiple selection //$NON-NLS-1$ } } URL url = JavaUI.getJavadocLocation(element, true); if (url == null || doesNotExist(url)) { IPackageFragmentRoot root = JavaModelUtil.getPackageFragmentRoot(element); if (root != null) { url = JavaUI.getJavadocBaseLocation(element); if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { element = element.getJavaProject(); } else { element = root; } url = JavaUI.getJavadocLocation(element, false); } } if (url != null) { IHelpResource javaResource = new JavaUIHelpResource(element, getURLString(url)); helpResources.add(javaResource); } } } // Add static help topics if (context != null) { IHelpResource[] resources = context.getRelatedTopics(); if (resources != null) { for (int j = 0; j < resources.length; j++) { helpResources.add(resources[j]); } } } fHelpResources = (IHelpResource[]) helpResources.toArray(new IHelpResource[helpResources.size()]); if (context != null) fText = context.getText(); if (BUG_85721_FIXED) { if (javadocSummary != null && javadocSummary.length() > 0) { if (fText != null) fText = context.getText() + "<br><br>" + javadocSummary; // $NON-NLS-1$ else fText = javadocSummary; } } if (fText == null) fText = ""; // $NON-NLS-1$ }