< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/util/Name.java

Print this page




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.util;
  27 
  28 import com.sun.tools.javac.jvm.ClassFile;
  29 import com.sun.tools.javac.jvm.PoolConstant;
  30 import com.sun.tools.javac.util.DefinedBy.Api;
  31 
  32 /** An abstraction for internal compiler strings. They are stored in
  33  *  Utf8 format. Names are stored in a Name.Table, and are unique within
  34  *  that table.
  35  *
  36  *  <p><b>This is NOT part of any supported API.
  37  *  If you write code that depends on this, you do so at your own risk.
  38  *  This code and its internal interfaces are subject to change or
  39  *  deletion without notice.</b>
  40  */
  41 public abstract class Name implements javax.lang.model.element.Name, PoolConstant {
  42 
  43     public final Table table;
  44 
  45     protected Name(Table table) {
  46         this.table = table;
  47     }
  48 
  49     /**
  50      * {@inheritDoc}
  51      */
  52     @DefinedBy(Api.LANGUAGE_MODEL)
  53     public boolean contentEquals(CharSequence cs) {
  54         return toString().equals(cs.toString());
  55     }
  56 
  57     @Override
  58     public int poolTag() {
  59         return ClassFile.CONSTANT_Utf8;
  60     }
  61 
  62     /**
  63      * {@inheritDoc}
  64      */
  65     public int length() {
  66         return toString().length();
  67     }
  68 
  69     /**
  70      * {@inheritDoc}
  71      */
  72     public char charAt(int index) {
  73         return toString().charAt(index);
  74     }
  75 
  76     /**
  77      * {@inheritDoc}
  78      */
  79     public CharSequence subSequence(int start, int end) {
  80         return toString().subSequence(start, end);
  81     }


 177     public abstract int getByteLength();
 178 
 179     /** Returns i'th byte of this name.
 180      */
 181     public abstract byte getByteAt(int i);
 182 
 183     /** Copy all bytes of this name to buffer cs, starting at start.
 184      */
 185     public void getBytes(byte cs[], int start) {
 186         System.arraycopy(getByteArray(), getByteOffset(), cs, start, getByteLength());
 187     }
 188 
 189     /** Get the underlying byte array for this name. The contents of the
 190      * array must not be modified.
 191      */
 192     public abstract byte[] getByteArray();
 193 
 194     /** Get the start offset of this name within its byte array.
 195      */
 196     public abstract int getByteOffset();
 197 
 198     public interface NameMapper<X> {
 199         X map(byte[] bytes, int offset, int len);
 200     }
 201 
 202     public <X> X map(NameMapper<X> mapper) {
 203         return mapper.map(getByteArray(), getByteOffset(), getByteLength());
 204     }
 205 
 206     /** An abstraction for the hash table used to create unique Name instances.
 207      */
 208     public static abstract class Table {
 209         /** Standard name table.
 210          */
 211         public final Names names;
 212 
 213         Table(Names names) {
 214             this.names = names;
 215         }
 216 
 217         /** Get the name from the characters in cs[start..start+len-1].
 218          */
 219         public abstract Name fromChars(char[] cs, int start, int len);
 220 
 221         /** Get the name for the characters in string s.
 222          */
 223         public Name fromString(String s) {
 224             char[] cs = s.toCharArray();




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.util;
  27 


  28 import com.sun.tools.javac.util.DefinedBy.Api;
  29 
  30 /** An abstraction for internal compiler strings. They are stored in
  31  *  Utf8 format. Names are stored in a Name.Table, and are unique within
  32  *  that table.
  33  *
  34  *  <p><b>This is NOT part of any supported API.
  35  *  If you write code that depends on this, you do so at your own risk.
  36  *  This code and its internal interfaces are subject to change or
  37  *  deletion without notice.</b>
  38  */
  39 public abstract class Name implements javax.lang.model.element.Name {
  40 
  41     public final Table table;
  42 
  43     protected Name(Table table) {
  44         this.table = table;
  45     }
  46 
  47     /**
  48      * {@inheritDoc}
  49      */
  50     @DefinedBy(Api.LANGUAGE_MODEL)
  51     public boolean contentEquals(CharSequence cs) {
  52         return toString().equals(cs.toString());
  53     }
  54 





  55     /**
  56      * {@inheritDoc}
  57      */
  58     public int length() {
  59         return toString().length();
  60     }
  61 
  62     /**
  63      * {@inheritDoc}
  64      */
  65     public char charAt(int index) {
  66         return toString().charAt(index);
  67     }
  68 
  69     /**
  70      * {@inheritDoc}
  71      */
  72     public CharSequence subSequence(int start, int end) {
  73         return toString().subSequence(start, end);
  74     }


 170     public abstract int getByteLength();
 171 
 172     /** Returns i'th byte of this name.
 173      */
 174     public abstract byte getByteAt(int i);
 175 
 176     /** Copy all bytes of this name to buffer cs, starting at start.
 177      */
 178     public void getBytes(byte cs[], int start) {
 179         System.arraycopy(getByteArray(), getByteOffset(), cs, start, getByteLength());
 180     }
 181 
 182     /** Get the underlying byte array for this name. The contents of the
 183      * array must not be modified.
 184      */
 185     public abstract byte[] getByteArray();
 186 
 187     /** Get the start offset of this name within its byte array.
 188      */
 189     public abstract int getByteOffset();








 190 
 191     /** An abstraction for the hash table used to create unique Name instances.
 192      */
 193     public static abstract class Table {
 194         /** Standard name table.
 195          */
 196         public final Names names;
 197 
 198         Table(Names names) {
 199             this.names = names;
 200         }
 201 
 202         /** Get the name from the characters in cs[start..start+len-1].
 203          */
 204         public abstract Name fromChars(char[] cs, int start, int len);
 205 
 206         /** Get the name for the characters in string s.
 207          */
 208         public Name fromString(String s) {
 209             char[] cs = s.toCharArray();


< prev index next >