MISC: Added a guard condition for setting a variable 82/13082/2
authorkh5325.kim <kh5325.kim@samsung.com>
Thu, 28 Nov 2013 02:33:08 +0000 (11:33 +0900)
committerkh5325.kim <kh5325.kim@samsung.com>
Thu, 28 Nov 2013 02:37:16 +0000 (11:37 +0900)
Added a guard condition for setting a variable consoleName.

Change-Id: I7647ad682b64b073e91cf90710b599ef1f91eb11
Signed-off-by: kh5325.kim <kh5325.kim@samsung.com>
org.tizen.common/src/org/tizen/common/ui/view/console/ConsoleManager2.java
org.tizen.common/src/org/tizen/common/ui/view/console/TextStyle.java

index bc375be..aea101d 100755 (executable)
@@ -56,358 +56,358 @@ public class
 ConsoleManager2
 implements ITizenConsoleManager, IHyperlinkManager
 {
-       
-       /**
-        * MessageConsole to be delegated
-        */
-       protected final MessageConsoleSpy console;
-       
-       /**
-        * Link manager
-        */
-       protected final HyperlinkManager hyperlinkManager;
-       
-       /**
-        * console's name
-        * 
-        * @see {@link IConsole#setName(String)}
-        */
-       private String consoleName;
-       
-       /**
-        * document model's virtual length
-        */
-       protected int documentLength = 0;
-       
-       /**
-        * Constructs a new console manager.
-        * 
-        * @param consoleName - the key title 
-        * @param focus - true if focus on console, false if not
-        */
-       public
-       ConsoleManager2(
-               final String consoleName,
-               final boolean focus
-       )
-       {
-               this.consoleName = consoleName;
-               this.console = createMessageConsole();
-               this.hyperlinkManager = new HyperlinkManager( console );
-               this.console.getDocument().addDocumentListener( hyperlinkManager );
-               
-               if ( focus )
-               {
-                       getConsoleManager().showConsoleView(console);
-               }
-               
-               setName( consoleName );
-       }
-       
-       /**
-        * return {@link IConsoleManager} from {@link ConsolePlugin}
-        * 
-        * @return {@link IConsoleManager}
-        * 
-        * @see ConsolePlugin#getConsoleManager()
-        */
-       protected IConsoleManager getConsoleManager()
-       {
-               return ConsolePlugin.getDefault().getConsoleManager();
-       }
-       
-       /**
-        * return <code>IConsole</code>s to be attached to {@link IConsoleManager}
-        * 
-        * @return <code>IConsole</code>s
-        * 
-        * @see #getConsoleManager()
-        * @see IConsoleManager#getConsoles()
-        */
-       protected IConsole[] getConsoles()
-       {
-               return getConsoleManager().getConsoles();
-       }
-       
-
-       /**
-        * Change Console Name.
-        *
-        * @param newName - console Title. It shown console's tab bar. 
-        * @author Gyeongseok.seo@samsung.com
-        */
-       public void
-       setName(
-               final String newName
-       )
-       {
-           Assert.notNull( newName );
-               this.consoleName = newName;
-               asyncExec( new Runnable()
-               {
-                       public void run()
-                       {
-                               if ( null == console )
-                               {
-                                       return ;
-                               }
-                               console.setName(newName);
-                       }
-               } );
-       }
-       
-       /**
-        * Create message console
-        * 
-        * @return Message console for emulator
-        */
-       synchronized protected MessageConsoleSpy createMessageConsole()
-       {
-               // Delete Old Console from console view
-               final IConsole[] consoles = getConsoles();
-               for ( int i = 0, n = consoles.length ; i < n ; ++i )
-               {
-                       if ( !this.consoleName.equals(consoles[i].getName() ) )
-                       {
-                               continue;
-                       }
-                       getConsoleManager().removeConsoles( new IConsole[] { console } );
-               }
+    
+    /**
+     * MessageConsole to be delegated
+     */
+    protected final MessageConsoleSpy console;
+    
+    /**
+     * Link manager
+     */
+    protected final HyperlinkManager hyperlinkManager;
+    
+    /**
+     * console's name
+     * 
+     * @see {@link IConsole#setName(String)}
+     */
+    private String consoleName;
+    
+    /**
+     * document model's virtual length
+     */
+    protected int documentLength = 0;
+    
+    /**
+     * Constructs a new console manager.
+     * 
+     * @param consoleName - the key title
+     * @param focus - true if focus on console, false if not
+     */
+    public
+    ConsoleManager2(
+        final String consoleName,
+        final boolean focus
+    )
+    {
+        this.consoleName = consoleName;
+        this.console = createMessageConsole();
+        this.hyperlinkManager = new HyperlinkManager( console );
+        this.console.getDocument().addDocumentListener( hyperlinkManager );
+        
+        if ( focus )
+        {
+            getConsoleManager().showConsoleView(console);
+        }
+        
+        setName( consoleName );
+    }
+    
+    /**
+     * return {@link IConsoleManager} from {@link ConsolePlugin}
+     * 
+     * @return {@link IConsoleManager}
+     * 
+     * @see ConsolePlugin#getConsoleManager()
+     */
+    protected IConsoleManager getConsoleManager()
+    {
+        return ConsolePlugin.getDefault().getConsoleManager();
+    }
+    
+    /**
+     * return <code>IConsole</code>s to be attached to {@link IConsoleManager}
+     * 
+     * @return <code>IConsole</code>s
+     * 
+     * @see #getConsoleManager()
+     * @see IConsoleManager#getConsoles()
+     */
+    protected IConsole[] getConsoles()
+    {
+        return getConsoleManager().getConsoles();
+    }
+    
+    
+    /**
+     * Changes Console Name.
+     *
+     * @param newName - console Title. It shown console's tab bar.
+     * @author Gyeongseok.seo@samsung.com
+     */
+    public void
+    setName(
+        final String newName
+    )
+    {
+        Assert.notNull( newName );
+        synchronized ( this ) {
+            this.consoleName = newName;
+        }
+        asyncExec( new Runnable()
+        {
+            public void run()
+            {
+                if ( null == console )
+                {
+                    return ;
+                }
+                console.setName(newName);
+            }
+        } );
+    }
+    
+    /**
+     * Create message console
+     * 
+     * @return Message console for emulator
+     */
+    synchronized protected MessageConsoleSpy createMessageConsole()
+    {
+        // Delete Old Console from console view
+        final IConsole[] consoles = getConsoles();
+        for ( int i = 0, n = consoles.length ; i < n ; ++i )
+        {
+            if ( !this.consoleName.equals(consoles[i].getName() ) )
+            {
+                continue;
+            }
+            getConsoleManager().removeConsoles( new IConsole[] { console } );
+        }
  
-               final MessageConsoleSpy console = new MessageConsoleSpy( this.consoleName );
-               getConsoleManager().addConsoles( new IConsole[] { console } );
-               
-               return console;
-       }
-       
-       /**
-        * return {@link IConsole}
-        * 
-        * @return {@link IConsole} to be managed
-        */
-       public IConsole getConsole() {
-               return this.console;
-       }
-       
-       /**
-        * print <code>line</code> out to {@link IConsole} with line separator
-        * 
-        * @param line text to print
-        */
-       synchronized public void println(String line) {
-               final MessageConsoleStream output = createConsoleStream();
-               
-               try
-               {
-                       output.println( line );
-                       documentLength += ( line.length() + 1 );
-                       
-               } finally
-               {
-                       tryClose( output );
-               }
-       }
-       
-       /**
-        * Print out using {@link Process}
-        * @param process
-        */
-       public void printProcessStreams( final Process process) {
-               
-               clear();
-               // waitAndRead while process is running
-               ConsoleProcessClosure closure = new ConsoleProcessClosure(process, this);
-               
-               closure.runBlocking(); // a blocking cal
-       }
-       
-       
-       /**
-        * Return configured <code>MessageConsoleStream</code> 
-        * 
-        * with <code>fontStyle</code> and <code>color</code>
-        * 
-        * @param fontStyle SWT font style like {@link SWT#BOLD}, {@link SWT#ITALIC}, and etc.
-        * @param color color of message to be printed
-        * 
-        * @return configured <code>MessageConsoleStream</code>
-        * 
-        * @see #configureConsole(MessageConsoleStream, int, Color)
-        */
-       protected
-       MessageConsoleStream
-       getConsoleStream(
-               final int fontStyle,
-               final Color color
-       )
-       {
-               final MessageConsoleStream stream = createConsoleStream();
-               
-               configureConsole( stream, fontStyle, color );
-               
-               return stream;
-       }
-       
-       
-       /**
-        * Factory method for <code>MessageConsoleStream</code>
-        * 
-        * @return <code>MessageConsoleStream</code> to be created
-        * 
-        * @see MessageConsole#newMessageStream()
-        */
-       protected
-       MessageConsoleStream
-       createConsoleStream()
-       {
-               final MessageConsoleStream stream = console.newMessageStream();
-               
-               return stream;
-       }
-       
-       /**
-        * Configure <code>stream</code> with <code>fontStyle</code> and <code>color</code>
-        * 
-        * @param stream <code>MessageConsoleStream</code> to configure
-        * @param fontStyle SWT font style
-        * @param color
-        * 
-        * @see SWT#NORMAL
-        * @see SWT#BOLD
-        * @see SWT#ITALIC
-        */
-       protected void
-       configureConsole(
-               final MessageConsoleStream stream,
-               final int fontStyle,
-               final Color color
-       )
-       {
-               syncExec( new Runnable()
-               {
-                       public void run()
-                       {
-                       // font setting
-                               stream.setFontStyle( fontStyle );
-
-                       // color setting
-                               stream.setColor( color );
-                       }
-               } );
-       }
-
-       /**
-        * print out <code>message</code> with <code>fontStyle</code> and <code>color</code>
-        * 
-        * @param message message to print out
-        * @param fontStyle SWT font style
-        * @param color color of message
-        */
-       synchronized public
-       void
-       print(
-               final String message,
-               final int fontStyle,
-               final Color color
-       )
-       {
-               final MessageConsoleStream stream = getConsoleStream( fontStyle, color );
-               try
-               {
-                       stream.print(message);
-                       documentLength += (message.length() );
-               }
-               finally
-               {
-                       tryClose( stream );
-               }
-       }
-
-       /**
-        * print out with line separator
-        * 
-        * @param message message to print out
-        * @param fontStyle font style
-        * @param color color
-        * 
-        * @see #print(String, int, Color)
-        */
-       public
-       void
-       println(
-               final String message,
-               final int fontStyle,
-               final Color color
-       )
-       {
-               print( message + "\n", fontStyle, color );
-       }
-       
-       /**
-        * clear message console
-        */
-       synchronized public
-       void
-       clear()
-       {
-               syncExec(
-                       new Runnable() {
-                               public void run() {
-                                       IDocument document = console.getDocument();
-                                       if ( null == document )
-                                       {
-                                               return ;
-                                       }
-                                       document.set("");
-                               }
-                       }
-               );
-               documentLength = 0;
-       }
-       
-       /**
-        * Activate console
-        */
-       public
-       void
-       show()
-       {
-               syncExec(
-                       new Runnable() {
-                               public void run() {
-                                       final IWorkbenchPage page = getActivePage();
-                                       if ( null == page )
-                                       {
-                                               // How to handle no active page( no view page )
-                                               throw new IllegalStateException();
-                                       }
-                                       try {
-                                               IConsoleView view = (IConsoleView) page.showView( IConsoleConstants.ID_CONSOLE_VIEW );
-                                               view.display(getConsole());
-                                       } catch (
-                                               final PartInitException e
-                                       )
-                                       {
-                                                ConsolePlugin.log(e);
-                                       }
-                               }
-                       }
-               );
-       }
-       
-       /* (non-Javadoc)
-        * @see org.tizen.common.console.IHyperlinkerManager#addLinker(org.tizen.common.console.LinkInfo)
-        */
-       @Override
-       public
-       void
-       addLinker(
-               final LinkInfo link
-       )
-       {
-               hyperlinkManager.addLinker( link );
-       }
+        final MessageConsoleSpy console = new MessageConsoleSpy( this.consoleName );
+        getConsoleManager().addConsoles( new IConsole[] { console } );
+        
+        return console;
+    }
+    
+    /**
+     * return {@link IConsole}
+     * 
+     * @return {@link IConsole} to be managed
+     */
+    public IConsole getConsole() {
+        return this.console;
+    }
+    
+    /**
+     * print <code>line</code> out to {@link IConsole} with line separator
+     * 
+     * @param line text to print
+     */
+    synchronized public void println(String line) {
+        final MessageConsoleStream output = createConsoleStream();
+        
+        try
+        {
+            output.println( line );
+            documentLength += ( line.length() + 1 );
+            
+        } finally
+        {
+            tryClose( output );
+        }
+    }
+    
+    /**
+     * Prints out using {@link Process}.
+     * @param process
+     */
+    public void printProcessStreams( final Process process) {
+        
+        clear();
+        // waitAndRead while process is running
+        ConsoleProcessClosure closure = new ConsoleProcessClosure(process, this);
+        
+        closure.runBlocking(); // a blocking cal
+    }
+    
+    
+    /**
+     * Returns configured <code>MessageConsoleStream</code> with <code>fontStyle</code> and <code>color</code>.
+     * 
+     * @param fontStyle SWT font style like {@link SWT#BOLD}, {@link SWT#ITALIC}, and etc.
+     * @param color color of message to be printed
+     * 
+     * @return configured <code>MessageConsoleStream</code>
+     * 
+     * @see #configureConsole(MessageConsoleStream, int, Color)
+     */
+    protected
+    MessageConsoleStream
+    getConsoleStream(
+        final int fontStyle,
+        final Color color
+    )
+    {
+        final MessageConsoleStream stream = createConsoleStream();
+        
+        configureConsole( stream, fontStyle, color );
+        
+        return stream;
+    }
+    
+    
+    /**
+     * Factory method for <code>MessageConsoleStream</code>
+     * 
+     * @return <code>MessageConsoleStream</code> to be created
+     * 
+     * @see MessageConsole#newMessageStream()
+     */
+    protected
+    MessageConsoleStream
+    createConsoleStream()
+    {
+        final MessageConsoleStream stream = console.newMessageStream();
+        
+        return stream;
+    }
+    
+    /**
+     * Configure <code>stream</code> with <code>fontStyle</code> and <code>color</code>
+     * 
+     * @param stream <code>MessageConsoleStream</code> to configure
+     * @param fontStyle SWT font style
+     * @param color
+     * 
+     * @see SWT#NORMAL
+     * @see SWT#BOLD
+     * @see SWT#ITALIC
+     */
+    protected void
+    configureConsole(
+        final MessageConsoleStream stream,
+        final int fontStyle,
+        final Color color
+    )
+    {
+        syncExec( new Runnable()
+        {
+            public void run()
+            {
+                // font setting
+                stream.setFontStyle( fontStyle );
 
+                // color setting
+                stream.setColor( color );
+            }
+        } );
+    }
+    
+    /**
+     * print out <code>message</code> with <code>fontStyle</code> and <code>color</code>
+     * 
+     * @param message message to print out
+     * @param fontStyle SWT font style
+     * @param color color of message
+     */
+    synchronized public
+    void
+    print(
+        final String message,
+        final int fontStyle,
+        final Color color
+    )
+    {
+        final MessageConsoleStream stream = getConsoleStream( fontStyle, color );
+        try
+        {
+            stream.print(message);
+            documentLength += (message.length() );
+        }
+        finally
+        {
+            tryClose( stream );
+        }
+    }
+    
+    /**
+     * print out with line separator
+     * 
+     * @param message message to print out
+     * @param fontStyle font style
+     * @param color color
+     * 
+     * @see #print(String, int, Color)
+     */
+    public
+    void
+    println(
+        final String message,
+        final int fontStyle,
+        final Color color
+    )
+    {
+        print( message + "\n", fontStyle, color );
+    }
+    
+    /**
+     * clear message console
+     */
+    synchronized public
+    void
+    clear()
+    {
+        syncExec(
+            new Runnable() {
+                public void run() {
+                    IDocument document = console.getDocument();
+                    if ( null == document )
+                    {
+                        return ;
+                    }
+                    document.set("");
+                }
+            }
+        );
+        documentLength = 0;
+    }
+    
+    /**
+     * Activates console.
+     */
+    public
+    void
+    show()
+    {
+        syncExec(
+            new Runnable() {
+                public void run() {
+                    final IWorkbenchPage page = getActivePage();
+                    if ( null == page )
+                    {
+                        // How to handle no active page( no view page )
+                        throw new IllegalStateException();
+                    }
+                    try {
+                        IConsoleView view = (IConsoleView) page.showView( IConsoleConstants.ID_CONSOLE_VIEW );
+                        view.display(getConsole());
+                    } catch (
+                        final PartInitException e
+                    )
+                    {
+                         ConsolePlugin.log(e);
+                    }
+                }
+            }
+        );
+    }
+    
+    /* (non-Javadoc)
+     * @see org.tizen.common.console.IHyperlinkerManager#addLinker(org.tizen.common.console.LinkInfo)
+     */
+    @Override
+    public
+    void
+    addLinker(
+        final LinkInfo link
+    )
+    {
+        hyperlinkManager.addLinker( link );
+    }
+    
     @Override
     public void print(String line) {
         MessageConsoleStream output = this.console.newMessageStream();
@@ -419,4 +419,3 @@ implements ITizenConsoleManager, IHyperlinkManager
         }
     }
 }
-
index 000c1b0..f729b06 100644 (file)
@@ -29,25 +29,24 @@ import org.eclipse.swt.graphics.Color;
 
 public class TextStyle  {
     private Color foreground;
-       private Color background;
-       private String stripString;
-       
-       TextStyle(Color foreground,Color background,String stripString) {
+    private Color background;
+    private String stripString;
+    
+    TextStyle(Color foreground,Color background,String stripString) {
         this.foreground = foreground;
         this.background = background;
         this.stripString = stripString;
     }
 
-       public Color getForeground() {
-               return foreground;
-       }
+    public Color getForeground() {
+        return foreground;
+    }
 
-       public Color getBackground() {
-               return background;
-       }
+    public Color getBackground() {
+        return background;
+    }
 
-       public String getStripString() {
-               return stripString;
-       }
-   
+    public String getStripString() {
+        return stripString;
+    }
 }