classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: StringContent.java minor fixes


From: David Gilbert
Subject: [cp-patches] FYI: StringContent.java minor fixes
Date: Tue, 24 Jan 2006 14:07:57 +0000
User-agent: Mozilla Thunderbird 1.0.7 (X11/20051013)

I wrote some Mauve tests for StringContent.java and this patch (committed) fixes a couple of minor failures:

2006-01-24  David Gilbert  <address@hidden>

        * javax/swing/text/StringContent.java
        (remove): Modified argument check to prevent removal of last character,
        (getChars): Removed null argument check to allow NullPointerException,
        added API docs,
        (checkLocation): Added API docs and white space.

Regards,

Dave
Index: javax/swing/text/StringContent.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/text/StringContent.java,v
retrieving revision 1.5
diff -u -r1.5 StringContent.java
--- javax/swing/text/StringContent.java 13 Sep 2005 23:44:50 -0000      1.5
+++ javax/swing/text/StringContent.java 24 Jan 2006 13:58:48 -0000
@@ -1,5 +1,5 @@
 /* StringContent.java --
-   Copyright (C) 2005 Free Software Foundation, Inc.
+   Copyright (C) 2005, 2006 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -254,7 +254,7 @@
   
   public UndoableEdit remove(int where, int nitems) throws BadLocationException
   {
-    checkLocation(where, nitems);
+    checkLocation(where, nitems + 1);
     char[] temp = new char[(this.content.length - nitems)];
     this.count = this.count - nitems;
     RemoveUndo rundo = new RemoveUndo(where, new String(this.content, where, 
nitems));
@@ -284,25 +284,45 @@
     return new String (this.content, where, len);
   }
   
-  public void getChars(int where, int len, Segment txt) throws 
BadLocationException
+  /**
+   * Updates <code>txt</code> to contain a direct reference to the underlying 
+   * character array.
+   * 
+   * @param where  the index of the first character.
+   * @param len  the number of characters.
+   * @param txt  a carrier for the return result (<code>null</code> not 
+   *             permitted).
+   *             
+   * @throws BadLocationException if the requested character range is not 
+   *                              within the bounds of the content.
+   * @throws NullPointerException if <code>txt</code> is <code>null</code>.
+   */
+  public void getChars(int where, int len, Segment txt) 
+    throws BadLocationException
   {
     checkLocation(where, len);
-    if (txt != null)
-      {
-        txt.array = this.content;
-        txt.offset = where;
-        txt.count = len;
-      }
+    txt.array = this.content;
+    txt.offset = where;
+    txt.count = len;
   }
 
-  // This is package-private to avoid an accessor method.
+  /** 
+   * A utility method that checks the validity of the specified character
+   * range.
+   * 
+   * @param where  the first character in the range.
+   * @param len  the number of characters in the range.
+   * 
+   * @throws BadLocationException if the specified range is not within the
+   *         bounds of the content.
+   */
   void checkLocation(int where, int len) throws BadLocationException
   {
     if (where < 0)
       throw new BadLocationException("Invalid location", 1);
     else if (where > this.count)
       throw new BadLocationException("Invalid location", this.count);
-    else if ((where + len)>this.count)
+    else if ((where + len) > this.count)
       throw new BadLocationException("Invalid range", this.count);
   }
   

reply via email to

[Prev in Thread] Current Thread [Next in Thread]