From fafe3ae97c5c21159b2e0ca42429ff51bf4639bc Mon Sep 17 00:00:00 2001 From: Bon-Yong Lee Date: Tue, 28 Aug 2012 11:09:27 +0900 Subject: [PATCH] [Title] Code enhancement as static analysis [Type] Enhancement [Module] Sub [Priority] Minor [CQ#] // CQ Issue Number [Redmine#] // Redmine Isuue Number [Problem] // Problem Description [Cause] // Cause Description [Solution] // Solution Description [TestCase] // Executed the test-target (How to) --- .../tizen/common/connection/log/AddViewDialog.java | 16 + .../org/tizen/common/connection/log/LogPanel.java | 24 ++ .../org/tizen/common/connection/log/LogTab.java | 34 +- .../ui/TizenRemoteFileContentProvider.java | 18 + .../common/core/application/InstallPathConfig.java | 16 +- .../common/ui/view/console/AnsicodeAdapter.java | 16 +- .../org/tizen/common/ui/widget/PictureLabel.java | 26 +- .../src/org/tizen/common/util/CollectionUtil.java | 425 ++------------------- .../src/org/tizen/common/util/StringUtil.java | 2 + .../org/tizen/common/util/CollectionUtilTest.java | 2 + 10 files changed, 157 insertions(+), 422 deletions(-) mode change 100644 => 100755 org.tizen.common.connection/src/org/tizen/common/connection/log/LogTab.java mode change 100644 => 100755 org.tizen.common.connection/src/org/tizen/common/connection/ui/TizenRemoteFileContentProvider.java mode change 100644 => 100755 org.tizen.common/src/org/tizen/common/core/application/InstallPathConfig.java mode change 100644 => 100755 org.tizen.common/src/org/tizen/common/ui/widget/PictureLabel.java mode change 100644 => 100755 org.tizen.common/src/org/tizen/common/util/CollectionUtil.java mode change 100644 => 100755 org.tizen.common/test/src/org/tizen/common/util/CollectionUtilTest.java diff --git a/org.tizen.common.connection/src/org/tizen/common/connection/log/AddViewDialog.java b/org.tizen.common.connection/src/org/tizen/common/connection/log/AddViewDialog.java index 13cb202..d44e1a3 100755 --- a/org.tizen.common.connection/src/org/tizen/common/connection/log/AddViewDialog.java +++ b/org.tizen.common.connection/src/org/tizen/common/connection/log/AddViewDialog.java @@ -146,7 +146,9 @@ public class AddViewDialog extends Dialog while (!shell.isDisposed()) { if (!display.readAndDispatch()) + { display.sleep(); + } } return bOk; @@ -178,7 +180,9 @@ public class AddViewDialog extends Dialog tabNameText = new Text(top, SWT.SINGLE | SWT.BORDER); if (tabName != null) + { tabNameText.setText(tabName); + } tabNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); l = new Label(top, SWT.NONE); @@ -195,7 +199,9 @@ public class AddViewDialog extends Dialog for (IDevice d : devices) { if (d.isOnline()) + { dCombo.add(d.getSerialNumber()); + } } if (device != null) @@ -225,7 +231,9 @@ public class AddViewDialog extends Dialog tagText = new Text(mid, SWT.SINGLE | SWT.BORDER); if (tagKeyword != null) + { tagText.setText(tagKeyword); + } tagText.setMessage("Separated by a space and comma"); tagText.setToolTipText("Search Tag Keywords are separated by a space as well as a comma"); tagText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); @@ -235,7 +243,9 @@ public class AddViewDialog extends Dialog pidText = new Text(mid, SWT.SINGLE | SWT.BORDER); if (pidKeyword != null) + { pidText.setText(pidKeyword); + } pidText.setMessage("Separated by a space and comma"); pidText.setToolTipText("Search Pid Keywords are separated by a space as well as a comma"); pidText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); @@ -245,7 +255,9 @@ public class AddViewDialog extends Dialog msgText = new Text(mid, SWT.SINGLE | SWT.BORDER); if (msgKeyword != null) + { msgText.setText(msgKeyword); + } msgText.setMessage("Separated by a space and comma"); msgText.setToolTipText("Search Message Keywords are separated by a space as well as a comma"); msgText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); @@ -268,10 +280,14 @@ public class AddViewDialog extends Dialog if (tab.getLogTabName().equals(newName)) { if (oldTab != null && oldTab == tab) + { continue; + } int ret = FileDialogUtils.checkTabName(newName); if (ret == IDialogConstants.OK_ID) + { return; + } } } diff --git a/org.tizen.common.connection/src/org/tizen/common/connection/log/LogPanel.java b/org.tizen.common.connection/src/org/tizen/common/connection/log/LogPanel.java index 2f9427d..cb7fca8 100755 --- a/org.tizen.common.connection/src/org/tizen/common/connection/log/LogPanel.java +++ b/org.tizen.common.connection/src/org/tizen/common/connection/log/LogPanel.java @@ -277,7 +277,9 @@ public class LogPanel extends Panel implements IDeviceChangeListener for (IDevice device : getDevices()) { if (device.isOffline()) + { continue; + } LogTab dTab = createLogTab(ConnectionExplorerLabelProvider.getDeviceSerialWithName(device), device, true); dTab.start(); } @@ -559,7 +561,9 @@ public class LogPanel extends Panel implements IDeviceChangeListener public boolean save() { if (getSelectionLogTab() == null) + { return false; + } FileDialog dlg = new FileDialog(parent.getShell(), SWT.SAVE); dlg.setText(LogUIMessages.Log_Title_Tab_Export); @@ -583,7 +587,9 @@ public class LogPanel extends Panel implements IDeviceChangeListener again = false; fileName = dlg.open(); if (fileName == null) + { return false; + } checkFile = new File(fileName); if (checkFile.exists()) { @@ -624,7 +630,9 @@ public class LogPanel extends Panel implements IDeviceChangeListener { LogTab tab = getSelectionLogTab(); if ( tab != null) + { tab.clear(); + } } /** @@ -656,7 +664,9 @@ public class LogPanel extends Panel implements IDeviceChangeListener LogTab tab = getSelectionLogTab(); if (tab == null) + { return; + } if (!checkTabConnection(tab, LogUIMessages.Log_Title_Tab_AddTab_Error)) { @@ -666,7 +676,9 @@ public class LogPanel extends Panel implements IDeviceChangeListener AddViewDialog dlg = new AddViewDialog(parent.getShell(), tab.getDeviceSerialNumber()); if (dlg.getDevice() == null) + { return; + } if (dlg.open()) { @@ -687,7 +699,9 @@ public class LogPanel extends Panel implements IDeviceChangeListener } } } else + { return; + } } public void removeTab(LogTab tab) @@ -703,7 +717,9 @@ public class LogPanel extends Panel implements IDeviceChangeListener { int index = tabFolder.getSelectionIndex(); if (index < 0) + { return; + } LogTab tab = logTabList.get(index); removeTab(tab); logTabList.remove(tab); @@ -722,7 +738,9 @@ public class LogPanel extends Panel implements IDeviceChangeListener LogTab oldTab = getSelectionLogTab(); if (oldTab == null) + { return; + } if (oldTab.isDefault()) { @@ -794,7 +812,9 @@ public class LogPanel extends Panel implements IDeviceChangeListener for(LogTab logTab : logTabList) { if(logTab.getTabItem() == item) + { return logTab; + } } } return null; @@ -814,9 +834,13 @@ public class LogPanel extends Panel implements IDeviceChangeListener IDevice[] devices; SmartDevelopmentBridge sdbBridge = SmartDevelopmentBridge.getBridge(); if(sdbBridge != null) + { devices = sdbBridge.getDevices(); + } else + { devices = new IDevice[0]; + } return devices; } diff --git a/org.tizen.common.connection/src/org/tizen/common/connection/log/LogTab.java b/org.tizen.common.connection/src/org/tizen/common/connection/log/LogTab.java old mode 100644 new mode 100755 index bfd7b6d..e52f7af --- a/org.tizen.common.connection/src/org/tizen/common/connection/log/LogTab.java +++ b/org.tizen.common.connection/src/org/tizen/common/connection/log/LogTab.java @@ -25,6 +25,8 @@ */ package org.tizen.common.connection.log; +import static org.tizen.common.util.SWTUtil.syncExec; + import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; @@ -131,27 +133,39 @@ public class LogTab { pidInput = pid; if (pid != null) + { pidFilters = setFilter(pid.split("[\\s\t,]")); + } else + { pidFilters = null; + } } public void setTagFilter(String tag) { tagInput = tag; if (tag != null) + { tagFilters = setFilter(tag.split("[\\s\t,]")); + } else + { tagFilters = null; + } } public void setMsgFilter(String msg) { msgInput = msg; if (msg != null) + { msgFilters = setFilter(msg.split("[\\s\t,]")); + } else + { msgFilters = null; + } } private String[] setFilter(String[] array) @@ -195,9 +209,13 @@ public class LogTab public String getDeviceSerialNumber() { if (device != null) + { return device.getSerialNumber(); + } else + { return null; + } } public void setTabItem(TabItem tabItem) @@ -304,7 +322,9 @@ public class LogTab { filteredMessages.add(newMessage); if(filteredByIconAndText(newMessage)) + { newMessages.add(newMessage); + } } } } @@ -347,7 +367,9 @@ public class LogTab for (String filter : pidFilters) { if (logMessage.data.pidString.contains(filter)) + { return true; + } } } @@ -356,7 +378,9 @@ public class LogTab for (String filter : tagFilters) { if (logMessage.data.tag.toLowerCase().contains(filter.toLowerCase())) + { return true; + } } } @@ -365,7 +389,9 @@ public class LogTab for (String filter : msgFilters) { if (logMessage.msg.toLowerCase().contains(filter.toLowerCase())) + { return true; + } } } return false; @@ -382,7 +408,9 @@ public class LogTab boolean filteredByIconAndText(LogMessage logMessage) { if (logMessage == null) + { return false; + } if (levelMode != LEVEL_ALL) { @@ -390,7 +418,9 @@ public class LogTab a = (levelMode & (0x1 << (logMessage.data.logLevel.getPriority() - 2))); if (a == 0) + { return false; + } } if (filteredByText(logMessage)) @@ -746,10 +776,8 @@ public class LogTab table.removeAll(); } else { - Display d = table.getDisplay(); - // run sync as we need to update right now. - d.syncExec(new Runnable() + syncExec(new Runnable() { @Override public void run() diff --git a/org.tizen.common.connection/src/org/tizen/common/connection/ui/TizenRemoteFileContentProvider.java b/org.tizen.common.connection/src/org/tizen/common/connection/ui/TizenRemoteFileContentProvider.java old mode 100644 new mode 100755 index 164482c..7fe5d7e --- a/org.tizen.common.connection/src/org/tizen/common/connection/ui/TizenRemoteFileContentProvider.java +++ b/org.tizen.common.connection/src/org/tizen/common/connection/ui/TizenRemoteFileContentProvider.java @@ -62,9 +62,13 @@ public class TizenRemoteFileContentProvider implements ITreeContentProvider { FileEntry[] children = null; if (isInitialized == false) + { children = parent.getCachedChildren(); + } else + { children = parent.getFileListingService().getChildren(parent, false, null); + } List entries = new ArrayList(); for (FileEntry child : children) { @@ -78,7 +82,9 @@ public class TizenRemoteFileContentProvider implements ITreeContentProvider { } return entries.toArray(); } else + { return new Object[0]; + } } @Override @@ -115,17 +121,29 @@ public class TizenRemoteFileContentProvider implements ITreeContentProvider { if (arg0 instanceof FileEntry) { FileEntry entry = (FileEntry) arg0; if (entry.getType() == FileListingService.TYPE_DIRECTORY_LINK) + { return true; + } else if (entry.getType() == FileListingService.TYPE_LINK) + { return true; + } else if (entry.getType() == FileListingService.TYPE_DIRECTORY) + { return true; + } else if (entry.getType() == FileListingService.TYPE_ROOT_EMULATOR) + { return true; + } else if (entry.getType() == FileListingService.TYPE_ROOT_DEVICE) + { return true; + } else + { return false; + } } return false; } diff --git a/org.tizen.common/src/org/tizen/common/core/application/InstallPathConfig.java b/org.tizen.common/src/org/tizen/common/core/application/InstallPathConfig.java old mode 100644 new mode 100755 index d0d268e..57d8a60 --- a/org.tizen.common/src/org/tizen/common/core/application/InstallPathConfig.java +++ b/org.tizen.common/src/org/tizen/common/core/application/InstallPathConfig.java @@ -25,6 +25,8 @@ package org.tizen.common.core.application; +import static org.tizen.common.util.IOUtil.tryClose; + import java.io.BufferedReader; import java.io.File; import java.io.IOException; @@ -132,9 +134,13 @@ final public class InstallPathConfig { public static String getSDBPath() { String toolsPath = getToolsPath(); if (OSChecker.isWindows()) + { return toolsPath + File.separator + "sdb.exe"; + } else + { return toolsPath + File.separator + "sdb"; + } } public static String getSdbWinUsbApiPath() { @@ -162,7 +168,9 @@ final public class InstallPathConfig { if (HostUtil.exists(sdkPath)) { String[] fileContent = HostUtil.getContents(sdkPath).split("="); if (HostUtil.exists(fileContent[1])) + { sdkInstallPath = fileContent[1]; + } else { status = false; } @@ -198,13 +206,7 @@ final public class InstallPathConfig { } catch (IOException e) { e.printStackTrace(); } finally { - if (br != null) { - try { - br.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } + tryClose( br ); } return value; diff --git a/org.tizen.common/src/org/tizen/common/ui/view/console/AnsicodeAdapter.java b/org.tizen.common/src/org/tizen/common/ui/view/console/AnsicodeAdapter.java index 822d5ea..f303ce0 100755 --- a/org.tizen.common/src/org/tizen/common/ui/view/console/AnsicodeAdapter.java +++ b/org.tizen.common/src/org/tizen/common/ui/view/console/AnsicodeAdapter.java @@ -151,21 +151,31 @@ public class AnsicodeAdapter { if (codes[j].length() > 0 && codes[j].matches("[\\d]*")) { int code = Integer.parseInt(codes[j]); if (code == 0) + { brighter = false; + } else if (code == 1) + { brighter = true; + } else if (code >= 30 && code <= 39) { if (code == 39) + { color[0] = BLACK; //default foreground color + } else if (code >= 30 && code <= 37) { color[0] = getColorFromANSICode(code, brighter); brighter = false; } } else if (code >= 40 && code <= 49) { if (code == 49) + { color[1] = WHITE; //default background color + } else if (code >= 40 && code <= 47) + { color[1] = getColorFromANSICode(code, brighter); + } } } } @@ -196,10 +206,6 @@ public class AnsicodeAdapter { } public static List getStringStyles(String newLineStr) { List styles = parseAnsiString(newLineStr); - if (styles != null) { - return styles; - }else { - return null; - } + return styles; } } diff --git a/org.tizen.common/src/org/tizen/common/ui/widget/PictureLabel.java b/org.tizen.common/src/org/tizen/common/ui/widget/PictureLabel.java old mode 100644 new mode 100755 index c56ed62..fb871f3 --- a/org.tizen.common/src/org/tizen/common/ui/widget/PictureLabel.java +++ b/org.tizen.common/src/org/tizen/common/ui/widget/PictureLabel.java @@ -25,13 +25,23 @@ package org.tizen.common.ui.widget; -import java.util.List; import java.util.ArrayList; +import java.util.List; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.events.*; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseTrackAdapter; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; /** * Reference to http://www.eclipse.org/articles/Article-Writing%20Your%20Own%20Widget/Writing%20Your%20Own%20Widget.htm @@ -162,7 +172,9 @@ public class PictureLabel extends Canvas { int imageHeight = image.getBounds().height; gc.dispose(); if (imageWidth >= textWidth) + { width = imageWidth + 2; + } else width = textWidth + 2; height = textHeight + imageHeight + 7; @@ -178,9 +190,13 @@ public class PictureLabel extends Canvas { height = extent.y + 2; } if (wHint != -1) + { width = wHint; + } if (hHint != -1) + { height = hHint; + } return new Point(width + 2, height + 2); } diff --git a/org.tizen.common/src/org/tizen/common/util/CollectionUtil.java b/org.tizen.common/src/org/tizen/common/util/CollectionUtil.java old mode 100644 new mode 100755 index 2d5a024..4077279 --- a/org.tizen.common/src/org/tizen/common/util/CollectionUtil.java +++ b/org.tizen.common/src/org/tizen/common/util/CollectionUtil.java @@ -27,6 +27,7 @@ package org.tizen.common.util; import static org.tizen.common.util.StringUtil.EMPTY_STRING; import static org.tizen.common.util.StringUtil.NULL_STRING; +import java.lang.reflect.Array; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Arrays; @@ -871,411 +872,31 @@ public class CollectionUtil else if ( obj instanceof Object[] ) { return toString( ( Object[] ) obj ); - } - else if ( obj instanceof boolean[] ) - { - return toString( ( boolean[] ) obj ); - } - else if ( obj instanceof byte[] ) - { - return toString( ( byte[] )obj ); - } - else if ( obj instanceof char[] ) - { - return toString( ( char[] ) obj ); - } - else if ( obj instanceof double[] ) - { - return toString( ( double[] ) obj ); - } - else if ( obj instanceof float[] ) - { - return toString( (float[] ) obj ); - } - else if ( obj instanceof int[] ) - { - return toString( (int[] ) obj ); - } - else if ( obj instanceof long[] ) - { - return toString( ( long[] ) obj ); - } - else if ( obj instanceof short[] ) - { - return toString( ( short[] )obj ); + } else if ( obj.getClass().isArray() ) + { + int length = Array.getLength( obj ); + + if ( 0 == length ) + { + return EMPTY_ARRAY; + } + + final StringBuilder buffer= new StringBuilder(); + + buffer.append( ARRAY_START); + for ( int i=0 ; iarray boolean[] to String. - * - * @param array boolean[] to convert - * - * @return converted String - */ - public static - String - toString( - final boolean[] array - ) - { - if ( null == array ) - { - return NULL_STRING; - } - - final int length = array.length; - - if ( 0 == length ) - { - return EMPTY_ARRAY; - } - - final StringBuilder buffer= new StringBuilder(); - - buffer.append( ARRAY_START); - for ( int i=0 ; iarray byte[] to String. - * - * @param array byte[] to convert - * - * @return converted String - */ - public static - String - toString( - final byte[] array - ) - { - if ( null == array ) - { - return NULL_STRING; - } - - final int length = array.length; - - if ( 0 == length ) - { - return EMPTY_ARRAY; - } - - final StringBuilder buffer= new StringBuilder(); - - buffer.append( ARRAY_START); - for ( int i=0 ; iarray char[] to String. - * - * @param array char[] to convert - * - * @return converted String - */ - public static - String - toString( - final char[] array - ) - { - if ( null == array ) - { - return NULL_STRING; - } - - final int length = array.length; - - if ( 0 == length ) - { - return EMPTY_ARRAY; - } - - final StringBuilder buffer= new StringBuilder(); - - buffer.append( ARRAY_START); - for ( int i=0 ; iarray short[] to String. - * - * @param array short[] to convert - * - * @return converted String - */ - public static - String - toString( - final short[] array - ) - { - if ( null == array ) - { - return NULL_STRING; - } - - final int length = array.length; - - if ( 0 == length ) - { - return EMPTY_ARRAY; - } - - final StringBuilder buffer = new StringBuilder(); - for( int i=0 ; iarray int[] to String. - * - * @param array int[] to String - * - * @return converted String - */ - public static - String - toString( - final int[] array - ) - { - if ( null == array ) - { - return NULL_STRING; - } - - final int length = array.length; - - if ( 0 == length ) - { - return EMPTY_ARRAY; - } - - final StringBuilder buffer = new StringBuilder(); - for( int i=0 ; iarray long[] to String. - * - * @param array long[] to convert - * - * @return converted String - */ - public static - String - toString( - final long[] array - ) - { - if ( null == array ) - { - return NULL_STRING; - } - - int length = array.length; - - if ( 0 == length ) - { - return EMPTY_ARRAY; - } - - final StringBuilder buffer = new StringBuilder(); - for( int i=0 ; iarray double[] to String. - * - * @param array double[] to convert - * - * @return converted String - */ - public static - String - toString( - final double[] array - ) - { - if ( null == array ) - { - return NULL_STRING; - } - - int length= array.length; - - if ( 0 == length ) - { - return EMPTY_ARRAY; - } - - StringBuilder buffer = new StringBuilder(); - for( int i=0 ; iarray float[] to String. - * - * @param array float[] to convert - * - * @return converted String - */ - public static - String - toString( - final float[] array - ) - { - if ( null == array ) - { - return NULL_STRING; - } - - int length = array.length; - - if ( 0 == length ) - { - return EMPTY_ARRAY; - } - - final StringBuilder buffer = new StringBuilder(); - for( int i=0 ; i < length ; ++i ) - { - if ( 0 == i ) - { - buffer.append( ARRAY_START ); - } - else - { - buffer.append( ARRAY_ELEMENT_SEPARATOR ); - } - - buffer.append( array[i] ); - } - buffer.append( ARRAY_END ); - return buffer.toString(); - } - - /** - * Converts array Object[] to String. - * - * @param array Object[] to convert - * - * @return converted String - */ - public static - String - toString( - final T[] array - ) - { - if ( null == array ) - { - return NULL_STRING; - } - - final int length = array.length; - - if ( 0 == length ) - { - return EMPTY_ARRAY; - } - - final StringBuilder buffer= new StringBuilder(); - - buffer.append( ARRAY_START); - buffer.append( concatenate( array, ARRAY_ELEMENT_SEPARATOR ) ); - buffer.append( ARRAY_END ); - return buffer.toString(); - } /** * Returns a String from array Object[] with String separator. diff --git a/org.tizen.common/src/org/tizen/common/util/StringUtil.java b/org.tizen.common/src/org/tizen/common/util/StringUtil.java index 8b97822..c00cae2 100755 --- a/org.tizen.common/src/org/tizen/common/util/StringUtil.java +++ b/org.tizen.common/src/org/tizen/common/util/StringUtil.java @@ -225,7 +225,9 @@ public class StringUtil byte[] b = new byte[4096]; for (int n; (n = is.read(b)) != -1;) + { out.append(new String(b,0,n)); + } return out.toString(); } diff --git a/org.tizen.common/test/src/org/tizen/common/util/CollectionUtilTest.java b/org.tizen.common/test/src/org/tizen/common/util/CollectionUtilTest.java old mode 100644 new mode 100755 index cbce552..e991acf --- a/org.tizen.common/test/src/org/tizen/common/util/CollectionUtilTest.java +++ b/org.tizen.common/test/src/org/tizen/common/util/CollectionUtilTest.java @@ -703,6 +703,8 @@ CollectionUtilTest assertEquals( "{T, i, Z, e, N}", result ); result = CollectionUtil.toString( charArray2 ); assertEquals( "{}", result ); + + assertEquals( "{true, false}", CollectionUtil.toString( new boolean[] { true, false } ) ); } /** -- 2.7.4