Skip to content

Commit

Permalink
Add styling enhancements to signatures (JavaElementLinks) in Javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
RedeemerSK committed Jan 21, 2024
1 parent 9cd02fe commit 8b1bb92
Show file tree
Hide file tree
Showing 37 changed files with 3,066 additions and 216 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public final class JavaElementLabelsCore {
public final static long M_APP_RETURNTYPE= 1L << 5;

/**
* Method names contain return type (appended)
* Method names contain return type (prepended)
* e.g. <code>int foo</code>
*/
public final static long M_PRE_RETURNTYPE= 1L << 6;
Expand Down
49 changes: 48 additions & 1 deletion org.eclipse.jdt.ui/JavadocHoverStyleSheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ h4 { margin-top: 2em; margin-bottom: 0.3em; }
h5 { margin-top: 0px; margin-bottom: 0px; }
p { margin-top: 1em; margin-bottom: 1em; }
pre { margin-left: 0.6em; }
ul { margin-top: 0px; margin-bottom: 1em; margin-left: 1em; padding-left: 1em;}
ul { margin-top: 0px; margin-bottom: 1em; margin-left: 1em; padding-left: 1em; }
li { margin-top: 0px; margin-bottom: 0px; }
li p { margin-top: 0px; margin-bottom: 0px; }
ol { margin-top: 0px; margin-bottom: 1em; margin-left: 1em; padding-left: 1em; }
Expand All @@ -33,6 +33,53 @@ em { font-style: italic; }
var { font-style: italic; }
th { font-weight: bold; }

/* Styling enhancements */
div#previewWatermark { background-color: white; display: none; position: fixed; bottom: 2px; right: 2px; border: 2px solid black; color: black; border-radius: 5px; padding: 4px 4px 4px 4px; }
input#previewSwitch:checked ~ .styleSwitchParent div#previewWatermark { display: inline; }

div#previewFormatting,
div#previewWrapping,
div#previewTypeParamsLevelsColoring,
div#previewTypeParamsRefsColoring { display: inline; opacity: 0.3; margin-left: 3px; margin-right: 3px; font-weight: normal; }

input#previewSwitch:checked ~input#formattingSwitch:checked ~ .styleSwitchParent div#previewFormatting,
input#previewSwitch:checked ~input#wrappingSwitch:checked ~ .styleSwitchParent div#previewWrapping,
input#previewSwitch:checked ~input#typeParamsLevelsColoringSwitch:checked ~ .styleSwitchParent div#previewTypeParamsLevelsColoring,
input#previewSwitch:checked ~input#typeParamsRefsColoringSwitch:checked ~ .styleSwitchParent div#previewTypeParamsRefsColoring { opacity: 1; color: red; }

input#previewSwitch,
input#formattingSwitch,
input#wrappingSwitch,
input#typeParamsRefsColoringSwitch,
input#typeParamsLevelsColoringSwitch { display: none; }

input#wrappingSwitch:checked ~ .styleSwitchParent .methodPrependTypeParams { display: block}
input#wrappingSwitch:checked ~ .styleSwitchParent .methodParam { display: block; text-indent: 1em; }

input#formattingSwitch:checked ~ .styleSwitchParent .typeParamsLevelNo1 .typeBracketsStart:before,
input#formattingSwitch:checked ~ .styleSwitchParent .methodParams:before { content: " "; }

input#formattingSwitch:checked ~ .styleSwitchParent .methodQualifier { opacity: 0.6; }
input#formattingSwitch:checked ~ .styleSwitchParent .methodParamName { font-style: italic; }
input#formattingSwitch:checked ~ .styleSwitchParent .methodReturn { font-style: italic; }
input#formattingSwitch:checked ~ .styleSwitchParent .methodName { font-weight: 800; }

input#formattingSwitch:checked ~ .styleSwitchParent .typeParamsLevel { font-weight: 200; }
input#formattingSwitch:checked ~ .styleSwitchParent .typeBrackets { font-weight: 800; }

/* Start of dynamic type parameters levels styling section (do not edit this line) */
input#typeParamsLevelsColoringSwitch:checked ~ .styleSwitchParent .typeParamsLevelNo-INDEX-,
input#typeParamsLevelsColoringSwitch:checked ~ .styleSwitchParent .typeParamsLevelNo-INDEX- a.header
{ color: -COLOR-; }
/* End of dynamic type parameters levels styling section (do not edit this line) */

/* Start of dynamic type parameters references styling section (do not edit this line) */
input#typeParamsRefsColoringSwitch:checked ~ .styleSwitchParent .typeParamsReferenceNo-INDEX-,
input#typeParamsRefsColoringSwitch:checked ~ .styleSwitchParent .typeParamsReferenceNo-INDEX- a.header
{ color: -COLOR-; }
/* End of dynamic type parameters references styling section (do not edit this line) */


/* Workarounds for new Javadoc stylesheet (1.7) */
ul.blockList li.blockList, ul.blockListLast li.blockList {
list-style:none;
Expand Down
47 changes: 47 additions & 0 deletions org.eclipse.jdt.ui/JavadocViewStyleSheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,53 @@ em { font-style: italic; }
var { font-style: italic; }
th { font-weight: bold; }

/* Styling enhancements */
div#previewWatermark { background-color: white; display: none; position: fixed; bottom: 2px; right: 2px; border: 2px solid black; color: black; border-radius: 5px; padding: 4px 4px 4px 4px; }
input#previewSwitch:checked ~ .styleSwitchParent div#previewWatermark { display: inline; }

div#previewFormatting,
div#previewWrapping,
div#previewTypeParamsLevelsColoring,
div#previewTypeParamsRefsColoring { display: inline; opacity: 0.3; margin-left: 3px; margin-right: 3px; font-weight: normal; }

input#previewSwitch:checked ~input#formattingSwitch:checked ~ .styleSwitchParent div#previewFormatting,
input#previewSwitch:checked ~input#wrappingSwitch:checked ~ .styleSwitchParent div#previewWrapping,
input#previewSwitch:checked ~input#typeParamsLevelsColoringSwitch:checked ~ .styleSwitchParent div#previewTypeParamsLevelsColoring,
input#previewSwitch:checked ~input#typeParamsRefsColoringSwitch:checked ~ .styleSwitchParent div#previewTypeParamsRefsColoring { opacity: 1; color: red; }

input#previewSwitch,
input#formattingSwitch,
input#wrappingSwitch,
input#typeParamsRefsColoringSwitch,
input#typeParamsLevelsColoringSwitch { display: none; }

input#wrappingSwitch:checked ~ .styleSwitchParent .methodPrependTypeParams { display: block}
input#wrappingSwitch:checked ~ .styleSwitchParent .methodParam { display: block; text-indent: 1em; }

input#formattingSwitch:checked ~ .styleSwitchParent .typeParamsLevelNo1 .typeBracketsStart:before,
input#formattingSwitch:checked ~ .styleSwitchParent .methodParams:before { content: " "; }

input#formattingSwitch:checked ~ .styleSwitchParent .methodQualifier { opacity: 0.6; }
input#formattingSwitch:checked ~ .styleSwitchParent .methodParamName { font-style: italic; }
input#formattingSwitch:checked ~ .styleSwitchParent .methodReturn { font-style: italic; }
input#formattingSwitch:checked ~ .styleSwitchParent .methodName { font-weight: 800; }

input#formattingSwitch:checked ~ .styleSwitchParent .typeParamsLevel { font-weight: 200; }
input#formattingSwitch:checked ~ .styleSwitchParent .typeBrackets { font-weight: 800; }

/* Start of dynamic type parameters levels styling section (do not edit this line) */
input#typeParamsLevelsColoringSwitch:checked ~ .styleSwitchParent .typeParamsLevelNo-INDEX-,
input#typeParamsLevelsColoringSwitch:checked ~ .styleSwitchParent .typeParamsLevelNo-INDEX- a.header
{ color: -COLOR-; }
/* End of dynamic type parameters levels styling section (do not edit this line) */

/* Start of dynamic type parameters references styling section (do not edit this line) */
input#typeParamsRefsColoringSwitch:checked ~ .styleSwitchParent .typeParamsReferenceNo-INDEX-,
input#typeParamsRefsColoringSwitch:checked ~ .styleSwitchParent .typeParamsReferenceNo-INDEX- a.header
{ color: -COLOR-; }
/* End of dynamic type parameters references styling section (do not edit this line) */


/* Workarounds for new Javadoc stylesheet (1.7) */
ul.blockList li.blockList, ul.blockListLast li.blockList {
list-style:none;
Expand Down
1 change: 1 addition & 0 deletions org.eclipse.jdt.ui/css/e4-dark_jdt_syntaxhighlighting.css
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ IEclipsePreferences#org-eclipse-jdt-ui:org-eclipse-jdt-ui { /* pseudo attribute
'semanticHighlighting.restrictedKeywords.color=204,108,29'
'semanticHighlighting.restrictedKeywords.bold=false'
'sourceHoverBackgroundColor=68,68,68'
'javadocElementsStyling.darkModeDefaultColors=true'
}


Expand Down
Binary file added org.eclipse.jdt.ui/icons/full/dlcl16/wrap_all.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added org.eclipse.jdt.ui/icons/full/dlcl16/wrap_all@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added org.eclipse.jdt.ui/icons/full/dview16/members.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added org.eclipse.jdt.ui/icons/full/dview16/types.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ public class JavaPluginImages {
private static final String T_ELCL= "elcl16"; //$NON-NLS-1$
private static final String T_DLCL= "dlcl16"; //$NON-NLS-1$
private static final String T_ETOOL= "etool16"; //$NON-NLS-1$
private static final String T_DTOOL= "dtool16"; //$NON-NLS-1$
private static final String T_EVIEW= "eview16"; //$NON-NLS-1$
private static final String T_DVIEW= "dview16"; //$NON-NLS-1$

/*
* Keys for images available from the Java-UI plug-in image registry.
Expand Down Expand Up @@ -210,6 +212,10 @@ public class JavaPluginImages {
public static final ImageDescriptor DESC_VIEW_ERRORWARNING_TAB= createUnManaged(T_EVIEW, "errorwarning_tab.png"); //$NON-NLS-1$
public static final ImageDescriptor DESC_VIEW_CLASSFILEGENERATION_TAB= createUnManaged(T_EVIEW, "classfilegeneration_tab.png"); //$NON-NLS-1$
public static final ImageDescriptor DESC_VIEW_JDKCOMPLIANCE_TAB= createUnManaged(T_EVIEW, "jdkcompliance_tab.png"); //$NON-NLS-1$
public static final ImageDescriptor DESC_VIEW_MEMBERS= createUnManaged(T_EVIEW, "members.png"); //$NON-NLS-1$
public static final ImageDescriptor DESC_DVIEW_MEMBERS= createUnManaged(T_DVIEW, "members.png"); //$NON-NLS-1$
public static final ImageDescriptor DESC_VIEW_TYPES= createUnManaged(T_EVIEW, "types.png"); //$NON-NLS-1$
public static final ImageDescriptor DESC_DVIEW_TYPES= createUnManaged(T_DVIEW, "types.png"); //$NON-NLS-1$

public static final ImageDescriptor DESC_ELCL_FILTER= createUnManaged(T_ELCL, "filter_ps.png"); //$NON-NLS-1$
public static final ImageDescriptor DESC_DLCL_FILTER= createUnManaged(T_DLCL, "filter_ps.png"); //$NON-NLS-1$
Expand Down Expand Up @@ -466,6 +472,7 @@ public class JavaPluginImages {
public static final ImageDescriptor DESC_OVR_OPENS= createUnManagedCached(T_OVR, "opens_pkg_ovr.png"); //$NON-NLS-1$
public static final ImageDescriptor DESC_OVR_READS= createUnManagedCached(T_OVR, "reads_mod_ovr.png"); //$NON-NLS-1$
public static final ImageDescriptor DESC_OVR_PATCH= createUnManagedCached(T_OVR, "patch_ovr.png"); //$NON-NLS-1$
public static final ImageDescriptor DESC_OVR_MOUSE_CURSOR= createUnManagedCached(T_OVR, "mouse_cursor_ovr.png"); //$NON-NLS-1$

// Call Hierarchy
public static final ImageDescriptor DESC_OVR_RECURSIVE= createUnManaged(T_OVR, "recursive_co.png"); //$NON-NLS-1$
Expand Down Expand Up @@ -549,6 +556,13 @@ public class JavaPluginImages {
public static final ImageDescriptor DESC_DLCL_WRAP_NECESSARY= createUnManaged(T_DLCL, "wrap_necessary.png"); //$NON-NLS-1$
public static final ImageDescriptor DESC_ELCL_WRAP_NOT= createUnManaged(T_ELCL, "wrap_not.png"); //$NON-NLS-1$
public static final ImageDescriptor DESC_DLCL_WRAP_NOT= createUnManaged(T_DLCL, "wrap_not.png"); //$NON-NLS-1$
public static final ImageDescriptor DESC_ELCL_HIERARCHICAL_LAYOUT= createUnManaged(T_ELCL, "hierarchicalLayout.png"); //$NON-NLS-1$
public static final ImageDescriptor DESC_DLCL_HIERARCHICAL_LAYOUT= createUnManaged(T_DLCL, "hierarchicalLayout.png"); //$NON-NLS-1$
public static final ImageDescriptor DESC_ELCL_TEMPLATE= createUnManaged(T_ELCL, "templateprop_co.png"); //$NON-NLS-1$
public static final ImageDescriptor DESC_DLCL_TEMPLATE= createUnManaged(T_DLCL, "templateprop_co.png"); //$NON-NLS-1$

public static final ImageDescriptor DESC_ETOOL_JDOC_HOVER_EDIT= createUnManaged(T_ETOOL, "jdoc_hover_edit.png"); //$NON-NLS-1$
public static final ImageDescriptor DESC_DTOOL_JDOC_HOVER_EDIT= createUnManaged(T_DTOOL, "jdoc_hover_edit.png"); //$NON-NLS-1$

// Keys for correction proposal. We have to put the image into the registry since "code assist" doesn't
// have a life cycle. So no chance to dispose icons.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2023 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -14,6 +14,7 @@
* Brock Janiczak <brockj@tpg.com.au> - [implementation] Streams not being closed in Javadoc views - https://bugs.eclipse.org/bugs/show_bug.cgi?id=214854
* Benjamin Muskalla <bmuskalla@innoopract.com> - [javadoc view] NPE on enumerations - https://bugs.eclipse.org/bugs/show_bug.cgi?id=223586
* Stephan Herrmann - Contribution for Bug 403917 - [1.8] Render TYPE_USE annotations in Javadoc hover/view
* Jozef Tomek - add styling enhancements (issue 1073)
*******************************************************************************/
package org.eclipse.jdt.internal.ui.infoviews;

Expand Down Expand Up @@ -50,6 +51,7 @@
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
import org.eclipse.jface.internal.text.html.BrowserInput;
import org.eclipse.jface.internal.text.html.HTMLPrinter;
Expand Down Expand Up @@ -153,6 +155,9 @@
import org.eclipse.jdt.internal.ui.text.javadoc.JavadocContentAccess2;
import org.eclipse.jdt.internal.ui.viewsupport.BindingLinkedLabelComposer;
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementLinks;
import org.eclipse.jdt.internal.ui.viewsupport.MouseListeningToolItemsConfigurer;
import org.eclipse.jdt.internal.ui.viewsupport.browser.CheckboxInBrowserUtil.BrowserTextAccessor;
import org.eclipse.jdt.internal.ui.viewsupport.javadoc.SignatureStylingMenuToolbarAction;


/**
Expand Down Expand Up @@ -353,6 +358,13 @@ protected boolean canEnableFor(IStructuredSelection selection) {
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=73558
private static final boolean WARNING_DIALOG_ENABLED= false;

/**
* Preference keys prefix for all preferences related to styling of HTML content for element labels
* inside Javadoc view. Postfixes are declared as constants in {@link JavaElementLinks}.
* @see JavaElementLinks
*/
private static final String HTML_STYLING_PREFERENCE_KEY_PREFIX= "javadocElementsStyling.javadocView."; //$NON-NLS-1$

/** The HTML widget. */
private Browser fBrowser;
/** The text widget. */
Expand Down Expand Up @@ -542,6 +554,10 @@ public void setSelection(ISelection selection) {
}
}

public static void initDefaults(IPreferenceStore store) {
JavaElementLinks.initDefaultPreferences(store, HTML_STYLING_PREFERENCE_KEY_PREFIX);
}

@Override
protected void internalCreatePartControl(Composite parent) {
try {
Expand Down Expand Up @@ -621,6 +637,7 @@ private void listenForFontChanges() {
}

private static void initStyleSheet() {
fgStyleSheetLoaded= false; //TODO styling: remove
if (fgStyleSheetLoaded)
return;
fgStyleSheetLoaded= true;
Expand Down Expand Up @@ -672,6 +689,23 @@ protected void fillToolBar(IToolBarManager tbm) {
tbm.add(fForthAction);
tbm.add(new Separator());

if (fIsUsingBrowserWidget) {
BrowserTextAccessor browserAccessor= new BrowserTextAccessor(fBrowser);
// toolbar widget is being re-created later so we need to do our setup then
var stylingMenuAction= new SignatureStylingMenuToolbarAction(fBrowser.getParent().getShell(), browserAccessor, HTML_STYLING_PREFERENCE_KEY_PREFIX, () -> fOriginalInput) {
// we take advantage of this method being called after toolbar item creation (in ActionContributionItem.fill()) which happens when whole toolbar is being re-created to be displayed
@Override
public void addPropertyChangeListener(IPropertyChangeListener listener) {
super.addPropertyChangeListener(listener);
setupMenuReopen(tbm);
MouseListeningToolItemsConfigurer.registerForToolBarManager((ToolBarManager) tbm, browserAccessor::applyChanges);
}
};
stylingMenuAction.setId("JavadocView.SignatureStylingMenuToolbarAction"); //$NON-NLS-1$
tbm.add(stylingMenuAction);
tbm.add(new Separator());
}

super.fillToolBar(tbm);
tbm.add(fOpenBrowserAction);
}
Expand Down Expand Up @@ -1065,7 +1099,7 @@ private String getJavadocHtml(IJavaElement[] result, IWorkbenchPart activePart,
if (buffer.length() == 0)
return null;

HTMLPrinter.insertPageProlog(buffer, 0, fForegroundColorRGB, fBackgroundColorRGB, fgStyleSheet);
HTMLPrinter.insertPageProlog(buffer, 0, fForegroundColorRGB, fBackgroundColorRGB, JavaElementLinks.modifyCssStyleSheet(fgStyleSheet, buffer));
if (base != null) {
int endHeadIdx= buffer.indexOf("</head>"); //$NON-NLS-1$
buffer.insert(endHeadIdx, "\n<base href='" + base + "'>\n"); //$NON-NLS-1$ //$NON-NLS-2$
Expand Down Expand Up @@ -1093,9 +1127,9 @@ private String getInfoText(IJavaElement member, String constantValue, String def
// setting haveSource to false lets the JavadocView *always* show qualified type names,
// would need to track the source of our input to distinguish classfile/compilationUnit:
boolean haveSource= false;
new BindingLinkedLabelComposer(member, label, haveSource).appendBindingLabel(binding, flags);
new BindingLinkedLabelComposer(member, label, haveSource, HTML_STYLING_PREFERENCE_KEY_PREFIX).appendBindingLabel(binding, flags);
} else {
label= new StringBuffer(JavaElementLinks.getElementLabel(member, flags));
label= new StringBuffer(JavaElementLinks.getElementLabel(member, flags, false, HTML_STYLING_PREFERENCE_KEY_PREFIX));
}
if (member.getElementType() == IJavaElement.FIELD && constantValue != null) {
label.append(constantValue);
Expand Down
Loading

0 comments on commit 8b1bb92

Please sign in to comment.