diff --git a/bundles/org.eclipse.ui.views.log/META-INF/MANIFEST.MF b/bundles/org.eclipse.ui.views.log/META-INF/MANIFEST.MF index 0f5e26f97f7..bd6a40d317d 100644 --- a/bundles/org.eclipse.ui.views.log/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.ui.views.log/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %name Bundle-SymbolicName: org.eclipse.ui.views.log;singleton:=true -Bundle-Version: 1.4.900.qualifier +Bundle-Version: 1.4.1000.qualifier Bundle-Activator: org.eclipse.ui.internal.views.log.Activator Bundle-Vendor: %provider-name Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)", diff --git a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/AbstractEntry.java b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/AbstractEntry.java index 5230dcd8be4..6e43d3166ba 100644 --- a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/AbstractEntry.java +++ b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/AbstractEntry.java @@ -29,7 +29,7 @@ public abstract class AbstractEntry extends PlatformObject implements IWorkbench /** * The collection of direct children of this entry */ - private List children = new ArrayList<>(); + private final List children = new ArrayList<>(); protected Object parent; /** diff --git a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/EventDetailsDialog.java b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/EventDetailsDialog.java index ac751cf7c6d..6cd739878b2 100644 --- a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/EventDetailsDialog.java +++ b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/EventDetailsDialog.java @@ -54,15 +54,15 @@ public class EventDetailsDialog extends TrayDialog { public static final String FILTER_ENABLED = "detailsStackFilterEnabled"; //$NON-NLS-1$ public static final String FILTER_LIST = "detailsStackFilterList"; //$NON-NLS-1$ - private LogView logView; - private IMemento memento; + private final LogView logView; + private final IMemento memento; private AbstractEntry entry; private AbstractEntry parentEntry; // parent of the entry private AbstractEntry[] entryChildren; // children of the entry - private LogViewLabelProvider labelProvider; - private TreeViewer provider; + private final LogViewLabelProvider labelProvider; + private final TreeViewer provider; private static int COPY_ID = 22; @@ -151,15 +151,14 @@ private void initialize() { } private void resetChildIndex() { - if (entryChildren == null) + if (entryChildren == null) { return; + } LogEntry thisEntry = (LogEntry) entry; for (int i = 0; i < entryChildren.length; i++) { - if (entryChildren[i] instanceof LogEntry) { - - LogEntry logEntry = (LogEntry) entryChildren[i]; + if (entryChildren[i] instanceof LogEntry logEntry) { if (logEntry == thisEntry) { childIndex = i; @@ -215,14 +214,16 @@ public void create() { super.create(); // dialog location - if (dialogLocation != null) + if (dialogLocation != null) { getShell().setLocation(dialogLocation); + } // dialog size - if (dialogSize != null) + if (dialogSize != null) { getShell().setSize(dialogSize); - else + } else { getShell().setSize(500, 550); + } applyDialogFont(buttonBar); getButton(IDialogConstants.OK_ID).setFocus(); @@ -231,16 +232,17 @@ public void create() { @Override protected void buttonPressed(int buttonId) { - if (IDialogConstants.OK_ID == buttonId) + if (IDialogConstants.OK_ID == buttonId) { okPressed(); - else if (IDialogConstants.CANCEL_ID == buttonId) + } else if (IDialogConstants.CANCEL_ID == buttonId) { cancelPressed(); - else if (IDialogConstants.BACK_ID == buttonId) + } else if (IDialogConstants.BACK_ID == buttonId) { backPressed(); - else if (IDialogConstants.NEXT_ID == buttonId) + } else if (IDialogConstants.NEXT_ID == buttonId) { nextPressed(); - else if (COPY_ID == buttonId) + } else if (COPY_ID == buttonId) { copyPressed(); + } } protected void backPressed() { @@ -303,8 +305,9 @@ private void setComparator(byte sortType, final int sortOrder) { comparator = (e1, e2) -> { Date date1 = ((LogEntry) e1).getDate(); Date date2 = ((LogEntry) e2).getDate(); - if (sortOrder == LogView.ASCENDING) + if (sortOrder == LogView.ASCENDING) { return date1.getTime() < date2.getTime() ? LogView.DESCENDING : LogView.ASCENDING; + } return date1.getTime() > date2.getTime() ? LogView.DESCENDING : LogView.ASCENDING; }; } else if (sortType == LogView.PLUGIN) { @@ -354,13 +357,12 @@ public void updateProperties() { parentEntry = (AbstractEntry) entry.getParent(entry); setEntryChildren(parentEntry); resetChildIndex(); - if (childIndex == entryChildren.length - 1) + if (childIndex == entryChildren.length - 1) { isLastChild = true; + } } - if (entry instanceof LogEntry) { - LogEntry logEntry = (LogEntry) entry; - + if (entry instanceof LogEntry logEntry) { String strDate = MessageFormat.format("{0}, {1}", //$NON-NLS-1$ dateFormat.format(logEntry.getDate().toInstant()), // timeFormat.format(logEntry.getDate().toInstant())); @@ -496,8 +498,9 @@ private boolean nextChildExists(AbstractEntry originalEntry, AbstractEntry origi private void setEntryChildren() { AbstractEntry[] children = getElements(); - if (comparator != null) + if (comparator != null) { Arrays.sort(children, comparator); + } entryChildren = new AbstractEntry[children.length]; System.arraycopy(children, 0, entryChildren, 0, children.length); @@ -510,8 +513,9 @@ private void setEntryChildren() { private void setEntryChildren(AbstractEntry entry) { Object[] children = entry.getChildren(entry); - if (comparator != null) + if (comparator != null) { Arrays.sort(children, comparator); + } List result = new ArrayList<>(); for (Object element : children) { @@ -826,8 +830,9 @@ private IDialogSettings getDialogSettings() { IDialogSettings settings = PlatformUI .getDialogSettingsProvider(FrameworkUtil.getBundle(EventDetailsDialog.class)).getDialogSettings(); IDialogSettings dialogSettings = settings.getSection(getClass().getName()); - if (dialogSettings == null) + if (dialogSettings == null) { dialogSettings = settings.addNewSection(getClass().getName()); + } return dialogSettings; } diff --git a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/EventDetailsDialogAction.java b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/EventDetailsDialogAction.java index 200dc235dbd..667962b9fe5 100644 --- a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/EventDetailsDialogAction.java +++ b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/EventDetailsDialogAction.java @@ -28,15 +28,15 @@ */ public class EventDetailsDialogAction extends SelectionProviderAction { - private LogView logView; + private final LogView logView; /** * The control that the dialog should appear on top of. */ - private Control control; - private ISelectionProvider provider; + private final Control control; + private final ISelectionProvider provider; private EventDetailsDialog propertyDialog; private Comparator comparator; - private IMemento memento; + private final IMemento memento; /** * Creates a new action for opening a property dialog @@ -57,8 +57,9 @@ public EventDetailsDialogAction(LogView logView, Control control, ISelectionProv public boolean resetSelection(byte sortType, int sortOrder) { IAdaptable element = (IAdaptable) getStructuredSelection().getFirstElement(); - if (element == null) + if (element == null) { return false; + } if (propertyDialog != null && propertyDialog.isOpen()) { propertyDialog.resetSelection(element, sortType, sortOrder); return true; @@ -68,21 +69,25 @@ public boolean resetSelection(byte sortType, int sortOrder) { public void resetSelection() { IAdaptable element = (IAdaptable) getStructuredSelection().getFirstElement(); - if ((element == null) || (!(element instanceof LogEntry))) + if ((element == null) || (!(element instanceof LogEntry))) { return; - if (propertyDialog != null && propertyDialog.isOpen()) + } + if (propertyDialog != null && propertyDialog.isOpen()) { propertyDialog.resetSelection(element); + } } public void resetDialogButtons() { - if (propertyDialog != null && propertyDialog.isOpen()) + if (propertyDialog != null && propertyDialog.isOpen()) { propertyDialog.resetButtons(); + } } public void setComparator(Comparator comparator) { this.comparator = comparator; - if (propertyDialog != null && propertyDialog.isOpen()) + if (propertyDialog != null && propertyDialog.isOpen()) { propertyDialog.setComparator(comparator); + } } @Override @@ -99,8 +104,9 @@ public void run() { //get initial selection IAdaptable element = (IAdaptable) getStructuredSelection().getFirstElement(); - if ((element == null) || (!(element instanceof LogEntry))) + if ((element == null) || (!(element instanceof LogEntry))) { return; + } propertyDialog = new EventDetailsDialog(control.getShell(), logView, element, provider, comparator, memento); propertyDialog.create(); diff --git a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/FilterDialog.java b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/FilterDialog.java index 68ef6854e46..da628af82a0 100644 --- a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/FilterDialog.java +++ b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/FilterDialog.java @@ -52,7 +52,7 @@ public class FilterDialog extends TrayDialog { private Button removeFilter; private List filterList; - private IMemento memento; + private final IMemento memento; public FilterDialog(Shell parentShell, IMemento memento) { super(parentShell); @@ -127,8 +127,9 @@ public void widgetSelected(SelectionEvent e) { }); limitText.addModifyListener(e -> { try { - if (okButton == null) + if (okButton == null) { return; + } int value = Integer.parseInt(limitText.getText()); okButton.setEnabled(value > 0); } catch (NumberFormatException e1) { @@ -151,8 +152,9 @@ public void widgetSelected(SelectionEvent e) { maxLogTailSizeText.addModifyListener(e -> { try { - if (okButton == null) + if (okButton == null) { return; + } int value = Integer.parseInt(maxLogTailSizeText.getText()); okButton.setEnabled(value > 0); } catch (NumberFormatException e1) { diff --git a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/Group.java b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/Group.java index a6f1de2cc9b..d191668a67d 100644 --- a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/Group.java +++ b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/Group.java @@ -23,7 +23,7 @@ */ public class Group extends AbstractEntry { - private String name; + private final String name; public Group(String name) { this.name = name; diff --git a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/ImportLogAction.java b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/ImportLogAction.java index 5c9a6ad2684..b05cea954fd 100644 --- a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/ImportLogAction.java +++ b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/ImportLogAction.java @@ -37,14 +37,14 @@ public class ImportLogAction extends Action implements IMenuCreator { */ private final LogView logView; private ImportConfigurationLogAction[] actions; - private IMemento fMemento; + private final IMemento fMemento; /** * Action imports log file from given location to Log View. */ private class ImportConfigurationLogAction extends Action { - private String name; - private String location; + private final String name; + private final String location; public ImportConfigurationLogAction(String name, String location) { super(name, AS_RADIO_BUTTON); @@ -69,8 +69,7 @@ public void run() { @Override public boolean equals(Object o) { - if (o instanceof ImportConfigurationLogAction) { - ImportConfigurationLogAction action = (ImportConfigurationLogAction) o; + if (o instanceof ImportConfigurationLogAction action) { return name.equals(action.name) && location.equals(action.name); } diff --git a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogReader.java b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogReader.java index cc8774a1866..9e89f62a530 100644 --- a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogReader.java +++ b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogReader.java @@ -37,12 +37,14 @@ class LogReader { public static LogSession parseLogFile(File file, long maxLogTailSizeInMegaByte, List entries, IMemento memento) { - if (!file.exists()) + if (!file.exists()) { return null; + } if (memento.getString(LogView.P_USE_LIMIT).equals("true") //$NON-NLS-1$ - && memento.getInteger(LogView.P_LOG_LIMIT).intValue() == 0) + && memento.getInteger(LogView.P_LOG_LIMIT).intValue() == 0) { return null; + } ArrayList parents = new ArrayList<>(); LogEntry current = null; @@ -58,8 +60,9 @@ public static LogSession parseLogFile(File file, long maxLogTailSizeInMegaByte, new InputStreamReader(new TailInputStream(file, maxTailSizeInBytes), StandardCharsets.UTF_8))) { for (;;) { String line0 = reader.readLine(); - if (line0 == null) + if (line0 == null) { break; + } String line = line0.trim(); if (line.startsWith(LogSession.SESSION)) { @@ -72,13 +75,15 @@ public static LogSession parseLogFile(File file, long maxLogTailSizeInMegaByte, state = MESSAGE_STATE; } else if (line.startsWith("!STACK")) { //$NON-NLS-1$ state = STACK_STATE; - } else + } else { state = TEXT_STATE; + } if (state == TEXT_STATE) { if (writer != null) { - if (swriter.getBuffer().length() > 0) + if (swriter.getBuffer().length() > 0) { writer.println(); + } writer.print(line0); } continue; @@ -106,8 +111,9 @@ public static LogSession parseLogFile(File file, long maxLogTailSizeInMegaByte, writerState = SESSION_STATE; currentSession = updateCurrentSession(currentSession, session); // if current session is most recent and not showing all sessions - if (currentSession.equals(session) && !memento.getString(LogView.P_SHOW_ALL_SESSIONS).equals("true")) //$NON-NLS-1$ + if (currentSession.equals(session) && !memento.getString(LogView.P_SHOW_ALL_SESSIONS).equals("true")) { //$NON-NLS-1$ entries.clear(); + } break; case ENTRY_STATE: if (currentSession == null) { // create fake session if there was no any @@ -143,10 +149,12 @@ public static LogSession parseLogFile(File file, long maxLogTailSizeInMegaByte, swriter = new StringWriter(); writer = new PrintWriter(swriter, true); String message = ""; //$NON-NLS-1$ - if (line.length() > 8) + if (line.length() > 8) { message = line.substring(9); - if (current != null) + } + if (current != null) { current.setMessage(message); + } writerState = MESSAGE_STATE; break; default: @@ -191,8 +199,9 @@ private static void setData(LogEntry current, LogSession session, int writerStat } else if (writerState == MESSAGE_STATE && current != null) { StringBuilder sb = new StringBuilder(current.getMessage()); String continuation = swriter.toString(); - if (continuation.length() > 0) + if (continuation.length() > 0) { sb.append(System.lineSeparator()).append(continuation); + } current.setMessage(sb.toString()); } } @@ -206,12 +215,13 @@ private static LogSession updateCurrentSession(LogSession currentSession, LogSes } Date currentDate = currentSession.getDate(); Date sessionDate = session.getDate(); - if (currentDate == null && sessionDate != null) + if (currentDate == null && sessionDate != null) { return session; - else if (currentDate != null && sessionDate == null) + } else if (currentDate != null && sessionDate == null) { return session; - else if (currentDate != null && sessionDate != null && sessionDate.after(currentDate)) + } else if (currentDate != null && sessionDate != null && sessionDate.after(currentDate)) { return session; + } return currentSession; } @@ -254,9 +264,10 @@ public static boolean isLogged(LogEntry entry, IMemento memento) { } private static void setNewParent(ArrayList parents, LogEntry entry, int depth) { - if (depth + 1 > parents.size()) + if (depth + 1 > parents.size()) { parents.add(entry); - else + } else { parents.set(depth, entry); + } } } diff --git a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogSession.java b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogSession.java index 127122874f3..b898a0ff8fe 100644 --- a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogSession.java +++ b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogSession.java @@ -48,7 +48,7 @@ public Date getDate() { /** * Returns a pretty-print formatting for the date for this entry - * + * * @return the formatted date for this entry */ public String getFormattedDate() { diff --git a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogView.java b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogView.java index de72f3b04ca..5a22046aa0f 100644 --- a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogView.java +++ b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogView.java @@ -114,7 +114,7 @@ public class LogView extends ViewPart implements LogListener { private ServiceTracker logReaderServiceTracker; private final List elements; - private Map groups; + private final Map groups; private LogSession currentSession; private final List batchedEntries; @@ -161,7 +161,7 @@ public class LogView extends ViewPart implements LogListener { * Action called when user selects "Group by -> ..." from menu. */ class GroupByAction extends Action { - private int groupBy; + private final int groupBy; public GroupByAction(String text, int groupBy) { super(text, IAction.AS_RADIO_BUTTON); @@ -238,8 +238,9 @@ public void removedService(ServiceReference reference, LogRead @Override public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, IWorkbenchPartReference partRef, String changeId) { - if (!(partRef instanceof IViewReference)) + if (!(partRef instanceof IViewReference)) { return; + } IWorkbenchPart part = partRef.getPart(false); if (part == null) { @@ -323,8 +324,9 @@ private void createActions() { mgr.add(fActivateViewErrorAction); mgr.add(new Separator()); - if (fFilteredTree.getFilterControl() != null) + if (fFilteredTree.getFilterControl() != null) { mgr.add(createShowTextFilter()); + } fPropertiesAction = createPropertiesAction(); @@ -573,8 +575,7 @@ private void createViewer(Composite parent) { PatternFilter filter = new PatternFilter() { @Override protected boolean isLeafMatch(Viewer viewer, Object element) { - if (element instanceof LogEntry) { - LogEntry logEntry = (LogEntry) element; + if (element instanceof LogEntry logEntry) { String message = logEntry.getMessage(); String plugin = logEntry.getPluginId(); DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); @@ -607,8 +608,9 @@ protected boolean isLeafMatch(Viewer viewer, Object element) { fLabelProvider.connect(this); fFilteredTree.getViewer().addSelectionChangedListener(e -> { handleSelectionChanged(e.getStructuredSelection()); - if (fPropertiesAction.isEnabled()) + if (fPropertiesAction.isEnabled()) { ((EventDetailsDialogAction) fPropertiesAction).resetSelection(); + } }); fFilteredTree.getViewer().addDoubleClickListener(event -> { ((EventDetailsDialogAction) fPropertiesAction).setComparator(fComparator); @@ -632,8 +634,9 @@ public void widgetSelected(SelectionEvent e) { fFilteredTree.getViewer().setComparator(comparator); boolean isComparatorSet = ((EventDetailsDialogAction) fPropertiesAction).resetSelection(MESSAGE, MESSAGE_ORDER); setComparator(MESSAGE); - if (!isComparatorSet) + if (!isComparatorSet) { ((EventDetailsDialogAction) fPropertiesAction).setComparator(fComparator); + } fMemento.putInteger(P_ORDER_VALUE, MESSAGE_ORDER); fMemento.putInteger(P_ORDER_TYPE, MESSAGE); setColumnSorting(fColumn1, MESSAGE_ORDER); @@ -651,8 +654,9 @@ public void widgetSelected(SelectionEvent e) { fFilteredTree.getViewer().setComparator(comparator); boolean isComparatorSet = ((EventDetailsDialogAction) fPropertiesAction).resetSelection(PLUGIN, PLUGIN_ORDER); setComparator(PLUGIN); - if (!isComparatorSet) + if (!isComparatorSet) { ((EventDetailsDialogAction) fPropertiesAction).setComparator(fComparator); + } fMemento.putInteger(P_ORDER_VALUE, PLUGIN_ORDER); fMemento.putInteger(P_ORDER_TYPE, PLUGIN); setColumnSorting(fColumn2, PLUGIN_ORDER); @@ -683,12 +687,13 @@ private void initializeViewerSorter() { byte orderType = fMemento.getInteger(P_ORDER_TYPE).byteValue(); ViewerComparator comparator = getViewerComparator(orderType); fFilteredTree.getViewer().setComparator(comparator); - if (orderType == MESSAGE) + if (orderType == MESSAGE) { setColumnSorting(fColumn1, MESSAGE_ORDER); - else if (orderType == PLUGIN) + } else if (orderType == PLUGIN) { setColumnSorting(fColumn2, PLUGIN_ORDER); - else if (orderType == DATE) + } else if (orderType == DATE) { setColumnSorting(fColumn3, DATE_ORDER); + } } private void setColumnSorting(TreeColumn column, int order) { @@ -704,8 +709,9 @@ public void dispose() { if (fClipboard != null) { fClipboard.dispose(); } - if (fTextShell != null) + if (fTextShell != null) { fTextShell.dispose(); + } fLabelProvider.disconnect(this); fFilteredTree.dispose(); super.dispose(); @@ -717,8 +723,9 @@ public void dispose() { void handleImport() { FileDialog dialog = new FileDialog(getViewSite().getShell()); dialog.setFilterExtensions(new String[] {"*.log"}); //$NON-NLS-1$ - if (fDirectory != null) + if (fDirectory != null) { dialog.setFilterPath(fDirectory); + } String path = dialog.open(); if (path == null) { // cancel return; @@ -770,19 +777,22 @@ protected void setLogFile(File path) { private void handleExport(boolean exportWholeLog) { FileDialog dialog = new FileDialog(getViewSite().getShell(), SWT.SAVE); dialog.setFilterExtensions(new String[] {"*.log"}); //$NON-NLS-1$ - if (fDirectory != null) + if (fDirectory != null) { dialog.setFilterPath(fDirectory); + } String path = dialog.open(); if (path != null) { - if (path.indexOf('.') == -1 && !path.endsWith(".log")) //$NON-NLS-1$ + if (path.indexOf('.') == -1 && !path.endsWith(".log")) { //$NON-NLS-1$ path += ".log"; //$NON-NLS-1$ + } File outputFile = IPath.fromOSString(path).toFile(); fDirectory = outputFile.getParent(); if (outputFile.exists()) { String message = NLS.bind(Messages.LogView_confirmOverwrite_message, outputFile.toString()); if (!MessageDialog.openQuestion(getViewSite().getShell(), - (exportWholeLog ? Messages.LogView_exportLog : Messages.LogView_exportLogEntry), message)) + (exportWholeLog ? Messages.LogView_exportLog : Messages.LogView_exportLogEntry), message)) { return; + } } BufferedReader in = null; @@ -802,8 +812,9 @@ private void handleExport(boolean exportWholeLog) { // do nothing } finally { try { - if (in != null) + if (in != null) { in.close(); + } } catch (IOException e) { // do nothing } @@ -823,8 +834,9 @@ private void handleFilter() { FilterDialog dialog = new FilterDialog(getSite().getShell(), fMemento); dialog.create(); dialog.getShell().setText(Messages.LogView_FilterDialog_title); - if (dialog.open() == Window.OK) + if (dialog.open() == Window.OK) { reloadLog(); + } } @@ -1006,7 +1018,7 @@ private void limitEntriesCount() { return; } Comparator dateComparator = Comparator.comparing( - entry -> entry instanceof LogEntry ? ((LogEntry) entry).getDate() : null, + entry -> entry instanceof LogEntry l ? l.getDate() : null, Comparator.nullsLast((d1, d2) -> d1.before(d2) ? -1 : 1)); synchronized (elements) { @@ -1092,8 +1104,7 @@ public void logged(org.osgi.service.log.LogEntry input) { return; } FrameworkLogEntry betterInput = null; - if (input instanceof ExtendedLogEntry) { - ExtendedLogEntry logEntry = (ExtendedLogEntry) input; + if (input instanceof ExtendedLogEntry logEntry) { Object context = logEntry.getContext(); if (context instanceof FrameworkLogEntry) { betterInput = (FrameworkLogEntry) context; @@ -1241,7 +1252,7 @@ private Throttler createMutualActivate(Display display) { private void asyncRefreshAndActivate(int severity) { asyncRefresh(); - if ((fActivateViewAction != null && fActivateViewAction.isChecked()) + if ((fActivateViewAction != null && fActivateViewAction.isChecked()) || (severity >= IStatus.WARNING && fActivateViewWarnAction != null && fActivateViewWarnAction.isChecked()) || (severity >= IStatus.ERROR && fActivateViewErrorAction != null && fActivateViewErrorAction.isChecked())) { mutualActivate.throttledExec(); @@ -1296,9 +1307,9 @@ private void updateSelectionStack(IStructuredSelection selection) { private void updateStatus(IStructuredSelection selection) { IStatusLineManager status = getViewSite().getActionBars().getStatusLineManager(); - if (selection.isEmpty()) + if (selection.isEmpty()) { status.setMessage(null); - else { + } else { Object element = selection.getFirstElement(); status.setMessage(((LogViewLabelProvider) fFilteredTree.getViewer().getLabelProvider()).getColumnText(element, 0)); } @@ -1311,8 +1322,9 @@ private void updateStatus(IStructuredSelection selection) { private static String selectionToString(IStructuredSelection selection) { String textVersion = null; try (StringWriter writer = new StringWriter(); PrintWriter pwriter = new PrintWriter(writer)) { - if (selection.isEmpty()) + if (selection.isEmpty()) { return null; + } AbstractEntry entry = (AbstractEntry) selection.getFirstElement(); entry.write(pwriter); pwriter.flush(); @@ -1337,10 +1349,11 @@ private void copyToClipboard(IStructuredSelection selection) { @Override public void init(IViewSite site, IMemento memento) throws PartInitException { super.init(site, memento); - if (memento == null) + if (memento == null) { this.fMemento = XMLMemento.createWriteRoot("LOGVIEW"); //$NON-NLS-1$ - else + } else { this.fMemento = memento; + } readSettings(); // initialize column ordering @@ -1395,8 +1408,9 @@ private void initializeMemento() { @Override public void saveState(IMemento memento) { - if (this.fMemento == null || memento == null) + if (this.fMemento == null || memento == null) { return; + } //store some sane values to prevent the view from being broken this.fMemento.putInteger(P_COLUMN_1, getColumnWidth(fColumn1, 300)); this.fMemento.putInteger(P_COLUMN_2, getColumnWidth(fColumn2, 150)); @@ -1517,13 +1531,15 @@ void onMouseDown(Event e) { } void onMouseHover(Event e) { - if (!fCanOpenTextShell || fTextShell == null || fTextShell.isDisposed()) + if (!fCanOpenTextShell || fTextShell == null || fTextShell.isDisposed()) { return; + } fCanOpenTextShell = false; Point point = new Point(e.x, e.y); TreeItem item = fTree.getItem(point); - if (item == null) + if (item == null) { return; + } String message = null; if (item.getData() instanceof LogEntry) { @@ -1537,8 +1553,9 @@ void onMouseHover(Event e) { } } - if (message == null) + if (message == null) { return; + } fTextLabel.setText(message); Rectangle bounds = fTree.getDisplay().getBounds(); @@ -1547,10 +1564,12 @@ void onMouseHover(Event e) { int y = point.y + 25; int width = fTree.getColumn(0).getWidth(); int height = 125; - if (cursorPoint.x + width > bounds.width) + if (cursorPoint.x + width > bounds.width) { x -= width; - if (cursorPoint.y + height + 25 > bounds.height) + } + if (cursorPoint.y + height + 25 > bounds.height) { y -= height + 27; + } fTextShell.setLocation(fTree.toDisplay(x, y)); fTextShell.setSize(width, height); @@ -1558,17 +1577,18 @@ void onMouseHover(Event e) { } void onMouseMove(Event e) { - if (fTextShell != null && !fTextShell.isDisposed() && fTextShell.isVisible()) + if (fTextShell != null && !fTextShell.isDisposed() && fTextShell.isVisible()) { fTextShell.setVisible(false); + } Point point = new Point(e.x, e.y); TreeItem item = fTree.getItem(point); - if (item == null) + if (item == null) { return; + } Image image = item.getImage(); Object data = item.getData(); - if (data instanceof LogEntry) { - LogEntry entry = (LogEntry) data; + if (data instanceof LogEntry entry) { int parentCount = getNumberOfParents(entry); int startRange = 20 + Math.max(image.getBounds().width + 2, 7 + 2) * parentCount; int endRange = startRange + 16; @@ -1578,8 +1598,9 @@ void onMouseMove(Event e) { private int getNumberOfParents(AbstractEntry entry) { AbstractEntry parent = (AbstractEntry) entry.getParent(entry); - if (parent == null) + if (parent == null) { return 0; + } return 1 + getNumberOfParents(parent); } @@ -1602,28 +1623,26 @@ private void setComparator(byte sortType) { if (date1 == date2) { // XXX: this breaks stable sort, as elements is mutable int result = elements.indexOf(e2) - elements.indexOf(e1); - if (DATE_ORDER == DESCENDING) + if (DATE_ORDER == DESCENDING) { result *= DESCENDING; + } return result; } - if (DATE_ORDER == DESCENDING) + if (DATE_ORDER == DESCENDING) { return date1 > date2 ? DESCENDING : ASCENDING; + } return date1 < date2 ? DESCENDING : ASCENDING; }; } else if (sortType == PLUGIN) { fComparator = (e1, e2) -> { - if ((e1 instanceof LogEntry) && (e2 instanceof LogEntry)) { - LogEntry entry1 = (LogEntry) e1; - LogEntry entry2 = (LogEntry) e2; + if ((e1 instanceof LogEntry entry1) && (e2 instanceof LogEntry entry2)) { return getDefaultComparator().compare(entry1.getPluginId(), entry2.getPluginId()) * PLUGIN_ORDER; } return 0; }; } else { fComparator = (e1, e2) -> { - if ((e1 instanceof LogEntry) && (e2 instanceof LogEntry)) { - LogEntry entry1 = (LogEntry) e1; - LogEntry entry2 = (LogEntry) e2; + if ((e1 instanceof LogEntry entry1) && (e2 instanceof LogEntry entry2)) { return getDefaultComparator().compare(entry1.getMessage(), entry2.getMessage()) * MESSAGE_ORDER; } return 0; @@ -1640,9 +1659,7 @@ private ViewerComparator getViewerComparator(byte sortType) { return new ViewerComparator() { @Override public int compare(Viewer viewer, Object e1, Object e2) { - if ((e1 instanceof LogEntry) && (e2 instanceof LogEntry)) { - LogEntry entry1 = (LogEntry) e1; - LogEntry entry2 = (LogEntry) e2; + if ((e1 instanceof LogEntry entry1) && (e2 instanceof LogEntry entry2)) { return getComparator().compare(entry1.getPluginId(), entry2.getPluginId()) * PLUGIN_ORDER; } return 0; @@ -1652,9 +1669,7 @@ public int compare(Viewer viewer, Object e1, Object e2) { return new ViewerComparator() { @Override public int compare(Viewer viewer, Object e1, Object e2) { - if ((e1 instanceof LogEntry) && (e2 instanceof LogEntry)) { - LogEntry entry1 = (LogEntry) e1; - LogEntry entry2 = (LogEntry) e2; + if ((e1 instanceof LogEntry entry1) && (e2 instanceof LogEntry entry2)) { return getComparator().compare(entry1.getMessage(), entry2.getMessage()) * MESSAGE_ORDER; } return 0; @@ -1663,11 +1678,14 @@ public int compare(Viewer viewer, Object e1, Object e2) { } else { return new ViewerComparator() { private int indexOf(Object[] array, Object o) { - if (o == null) + if (o == null) { return -1; - for (int i = 0; i < array.length; ++i) - if (o.equals(array[i])) + } + for (int i = 0; i < array.length; ++i) { + if (o.equals(array[i])) { return i; + } + } return -1; } @@ -1687,8 +1705,9 @@ public int compare(Viewer viewer, Object e1, Object e2) { // Everything that appears in LogView should be an AbstractEntry. AbstractEntry parent = (AbstractEntry) ((AbstractEntry) e1).getParent(null); Object[] children = null; - if (parent != null) + if (parent != null) { children = parent.getChildren(parent); + } int result = 0; if (children != null) { @@ -1700,12 +1719,14 @@ public int compare(Viewer viewer, Object e1, Object e2) { // mutable result = elements.indexOf(e1) - elements.indexOf(e2); } - if (DATE_ORDER == DESCENDING) + if (DATE_ORDER == DESCENDING) { result *= DESCENDING; + } return result; } - if (DATE_ORDER == DESCENDING) + if (DATE_ORDER == DESCENDING) { return date1 > date2 ? DESCENDING : ASCENDING; + } return date1 < date2 ? DESCENDING : ASCENDING; } }; diff --git a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogViewContentProvider.java b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogViewContentProvider.java index 59f9a2f5546..1be1ab71085 100644 --- a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogViewContentProvider.java +++ b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogViewContentProvider.java @@ -17,7 +17,7 @@ import org.eclipse.jface.viewers.ITreeContentProvider; public class LogViewContentProvider implements ITreeContentProvider { - private LogView logView; + private final LogView logView; public LogViewContentProvider(LogView logView) { this.logView = logView; diff --git a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogViewLabelProvider.java b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogViewLabelProvider.java index b31a69cbad1..a165982ae29 100644 --- a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogViewLabelProvider.java +++ b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/LogViewLabelProvider.java @@ -26,14 +26,14 @@ public class LogViewLabelProvider extends LabelProvider implements ITableLabelPr private static int MAX_LABEL_LENGTH = 200; - private Image infoImage; - private Image okImage; - private Image errorImage; - private Image warningImage; - private Image errorWithStackImage; - private Image hierarchicalImage; + private final Image infoImage; + private final Image okImage; + private final Image errorImage; + private final Image warningImage; + private final Image errorWithStackImage; + private final Image hierarchicalImage; ArrayList consumers = new ArrayList<>(); - private LogView logView; + private final LogView logView; public LogViewLabelProvider(LogView logView) { errorImage = SharedImages.getImage(SharedImages.DESC_ERROR_ST_OBJ); @@ -73,10 +73,10 @@ public Image getColumnImage(Object element, int columnIndex) { @Override public String getColumnText(Object element, int columnIndex) { - if ((element instanceof LogSession) && (columnIndex == 2)) { - LogSession session = (LogSession) element; - if (session.getDate() == null) + if ((element instanceof LogSession session) && (columnIndex == 2)) { + if (session.getDate() == null) { return ""; //$NON-NLS-1$ + } return session.getFormattedDate(); } @@ -85,8 +85,7 @@ public String getColumnText(Object element, int columnIndex) { return element.toString(); } - if (element instanceof LogEntry) { - LogEntry entry = (LogEntry) element; + if (element instanceof LogEntry entry) { switch (columnIndex) { case 0 : if (entry.getMessage() != null) { @@ -100,8 +99,9 @@ public String getColumnText(Object element, int columnIndex) { return entry.getMessage(); } case 1 : - if (entry.getPluginId() != null) + if (entry.getPluginId() != null) { return entry.getPluginId(); + } case 2 : return entry.getFormattedDate(); } @@ -111,8 +111,9 @@ public String getColumnText(Object element, int columnIndex) { } public void connect(Object consumer) { - if (!consumers.contains(consumer)) + if (!consumers.contains(consumer)) { consumers.add(consumer); + } } public void disconnect(Object consumer) { diff --git a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/OpenIDELogFileAction.java b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/OpenIDELogFileAction.java index 64286ffdb88..d368c784b80 100644 --- a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/OpenIDELogFileAction.java +++ b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/OpenIDELogFileAction.java @@ -28,7 +28,7 @@ */ public class OpenIDELogFileAction extends Action { - private LogView fView; + private final LogView fView; public OpenIDELogFileAction(LogView logView) { fView = logView; diff --git a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/OpenLogDialog.java b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/OpenLogDialog.java index 55ed1eac8cf..c6ecd30bfbc 100644 --- a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/OpenLogDialog.java +++ b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/OpenLogDialog.java @@ -32,13 +32,13 @@ */ public final class OpenLogDialog extends TrayDialog { // input log file - private File logFile; + private final File logFile; // location/size configuration private IDialogSettings dialogSettings; private Point dialogLocation; private Point dialogSize; - private int DEFAULT_WIDTH = 750; - private int DEFAULT_HEIGHT = 800; + private final int DEFAULT_WIDTH = 750; + private final int DEFAULT_HEIGHT = 800; public OpenLogDialog(Shell parentShell, File logFile) { super(parentShell); @@ -63,13 +63,15 @@ protected void createButtonsForButtonBar(Composite parent) { public void create() { super.create(); // dialog location - if (dialogLocation != null) + if (dialogLocation != null) { getShell().setLocation(dialogLocation); + } // dialog size - if (dialogSize != null) + if (dialogSize != null) { getShell().setSize(dialogSize); - else + } else { getShell().setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); + } getButton(IDialogConstants.CLOSE_ID).setFocus(); } @@ -127,8 +129,9 @@ private IDialogSettings getDialogSettings() { IDialogSettings settings = PlatformUI.getDialogSettingsProvider(FrameworkUtil.getBundle(OpenLogDialog.class)) .getDialogSettings(); dialogSettings = settings.getSection(getClass().getName()); - if (dialogSettings == null) + if (dialogSettings == null) { dialogSettings = settings.addNewSection(getClass().getName()); + } return dialogSettings; } @@ -179,15 +182,19 @@ void readLargeFile(PrintWriter writer) throws FileNotFoundException, IOException random.seek(logFile.length() - LogReader.MAX_FILE_LENGTH); for (;;) { String line = random.readLine(); - if (line == null) + if (line == null) { break; + } line = line.trim(); - if (line.isEmpty()) + if (line.isEmpty()) { continue; - if (!hasStarted && (line.startsWith("!ENTRY") || line.startsWith(LogSession.SESSION))) //$NON-NLS-1$ + } + if (!hasStarted && (line.startsWith("!ENTRY") || line.startsWith(LogSession.SESSION))) { //$NON-NLS-1$ hasStarted = true; - if (hasStarted) + } + if (hasStarted) { writer.println(line); + } continue; } } diff --git a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/TailInputStream.java b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/TailInputStream.java index cb4f34b4adc..d4c0f5dc8f3 100644 --- a/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/TailInputStream.java +++ b/bundles/org.eclipse.ui.views.log/src/org/eclipse/ui/internal/views/log/TailInputStream.java @@ -17,9 +17,9 @@ public class TailInputStream extends InputStream { - private RandomAccessFile fRaf; + private final RandomAccessFile fRaf; - private long fTail; + private final long fTail; public TailInputStream(File file, long maxLength) throws IOException { super();