Ejemplo n.º 1
0
 /**
  * Converts a string to a UTF8 byte array.
  *
  * @param string string to be converted
  * @return byte array
  */
 private static byte[] utf8(final String string) {
   final char[] arr = string.toCharArray();
   final int al = arr.length;
   final TokenBuilder tb = new TokenBuilder(al << 1);
   for (int c = 0; c < al; ++c) {
     final char ch = arr[c];
     tb.add(
         Character.isHighSurrogate(ch) && c < al - 1 && Character.isLowSurrogate(arr[c + 1])
             ? Character.toCodePoint(ch, arr[++c])
             : ch);
   }
   return tb.finish();
 }
Ejemplo n.º 2
0
 public static String getJavaIdentifier(String candidateID) {
   int len = candidateID.length();
   StringBuffer buf = new StringBuffer();
   for (int i = 0; i < len; i++) {
     char ch = candidateID.charAt(i);
     boolean good =
         i == 0 ? Character.isJavaIdentifierStart(ch) : Character.isJavaIdentifierPart(ch);
     if (good) {
       buf.append(ch);
     } else {
       buf.append('_');
     }
   }
   return buf.toString();
 }
Ejemplo n.º 3
0
 // keyboard discovery code
 private void _mapKey(char charCode, int keyindex, boolean shift, boolean altgraph) {
   log("_mapKey: " + charCode);
   // if character is not in map, add it
   if (!charMap.containsKey(new Integer(charCode))) {
     log("Notified: " + (char) charCode);
     KeyEvent event =
         new KeyEvent(
             applet(),
             0,
             0,
             (shift ? KeyEvent.SHIFT_MASK : 0) + (altgraph ? KeyEvent.ALT_GRAPH_MASK : 0),
             ((Integer) vkKeys.get(keyindex)).intValue(),
             (char) charCode);
     charMap.put(new Integer(charCode), event);
     log("Mapped char " + (char) charCode + " to KeyEvent " + event);
     if (((char) charCode) >= 'a' && ((char) charCode) <= 'z') {
       // put shifted version of a-z in automatically
       int uppercharCode = (int) Character.toUpperCase((char) charCode);
       event =
           new KeyEvent(
               applet(),
               0,
               0,
               KeyEvent.SHIFT_MASK + (altgraph ? KeyEvent.ALT_GRAPH_MASK : 0),
               ((Integer) vkKeys.get(keyindex)).intValue(),
               (char) uppercharCode);
       charMap.put(new Integer(uppercharCode), event);
       log("Mapped char " + (char) uppercharCode + " to KeyEvent " + event);
     }
   }
 }
Ejemplo n.º 4
0
    // get a list of whitespace separated classnames from a property.
    private String[] parseClassNames(String propertyName) {
	String hands = getProperty(propertyName);
	if (hands == null) {
	    return new String[0];
	}
	hands = hands.trim();
	int ix = 0;
	Vector result = new Vector();
	while (ix < hands.length()) {
	    int end = ix;
	    while (end < hands.length()) {
		if (Character.isWhitespace(hands.charAt(end))) {
		    break;
		}
		if (hands.charAt(end) == ',') {
		    break;
		}
		end++;
	    }
	    String word = hands.substring(ix, end);
	    ix = end+1;
	    word = word.trim();
	    if (word.length() == 0) {
		continue;
	    }
	    result.add(word);
	}
	return (String[]) result.toArray(new String[result.size()]);
    }
Ejemplo n.º 5
0
 public static boolean isJavaIdentifier(String id) {
   if (id == null) {
     return false;
   }
   int len = id.length();
   if (len == 0) {
     return false;
   }
   if (!Character.isJavaIdentifierStart(id.charAt(0))) {
     return false;
   }
   for (int i = 1; i < len; i++) {
     if (!Character.isJavaIdentifierPart(id.charAt(i))) {
       return false;
     }
   }
   return true;
 }
Ejemplo n.º 6
0
 /**
  * Converts the given string to camel case.
  *
  * @param string string to convert
  * @return resulting string
  */
 public static String camelCase(final String string) {
   final StringBuilder sb = new StringBuilder(string.length());
   boolean dash = false;
   for (int p = 0; p < string.length(); p++) {
     final char ch = string.charAt(p);
     if (dash) {
       sb.append(Character.toUpperCase(ch));
       dash = false;
     } else {
       dash = ch == '-';
       if (!dash) sb.append(ch);
     }
   }
   return sb.toString();
 }
Ejemplo n.º 7
0
 private static StringBuilder appendTypeString(StringBuilder sb, Class<?> type) {
   while (type.isArray()) {
     sb.append('[');
     type = type.getComponentType();
   }
   if (type.isPrimitive()) {
     char typeLetter;
     if (type == Boolean.TYPE) {
       typeLetter = 'Z';
     } else if (type == Long.TYPE) {
       typeLetter = 'J';
     } else {
       String typeName = type.getName();
       typeLetter = Character.toUpperCase(typeName.charAt(0));
     }
     sb.append(typeLetter);
   } else {
     sb.append('L');
     sb.append(type.getName().replace('.', '/'));
     sb.append(';');
   }
   return sb;
 }
Ejemplo n.º 8
0
 /**
  * Converts a character to lower case.
  *
  * @param ch character to be converted
  * @return resulting character
  */
 public static int lc(final int ch) {
   return ch >= 'A' && ch <= 'Z' ? ch | 0x20 : ch > 0x7F ? Character.toLowerCase(ch) : ch;
 }
Ejemplo n.º 9
0
 /**
  * Converts a character to upper case.
  *
  * @param ch character to be converted
  * @return resulting character
  */
 public static int uc(final int ch) {
   return ch >= 'a' && ch <= 'z' ? ch - 0x20 : ch > 0x7F ? Character.toUpperCase(ch) : ch;
 }
Ejemplo n.º 10
0
 /**
  * Returns true if the specified character is a full-text letter or digit.
  *
  * @param ch character to be tested
  * @return result of check
  */
 public static boolean ftChar(final int ch) {
   return ch >= '0' && (ch < 0x80 ? LOD[ch - '0'] : Character.isLetterOrDigit(ch));
 }
Ejemplo n.º 11
0
  /**
   * Parses annotation instances from the javadoc annotation instance type
   *
   * @param annotationDocs Annotations decorated on some type
   * @return Serializable representation of annotations
   */
  protected static AnnotationInstance[] ParseAnnotationInstances(
      AnnotationDesc[] annotationDocs, String origin) {
    AnnotationInstance[] annotations = null;

    if (annotationDocs != null && annotationDocs.length > 0) {
      ArrayList<AnnotationInstance> list = new ArrayList<AnnotationInstance>();

      for (AnnotationDesc annot : annotationDocs) {
        AnnotationInstance instance = new AnnotationInstance();

        AnnotationTypeDoc annotTypeInfo = null;
        try {
          annotTypeInfo = annot.annotationType();
          instance.name = annot.annotationType().name();
          instance.qualifiedName = annot.annotationType().qualifiedTypeName();

        } catch (ClassCastException castException) {
          log.error("Unable to obtain type data about an annotation found on: " + origin);
          log.error("Add to the -cp parameter the class/jar that defines this annotation.");
          instance.name = null;
          instance.qualifiedName = null;
        }

        AnnotationDesc.ElementValuePair[] arguments = annot.elementValues();
        if (arguments != null && arguments.length > 0) {
          ArrayList<AnnotationArgument> argumentList = new ArrayList<AnnotationArgument>();

          for (AnnotationDesc.ElementValuePair pair : arguments) {
            AnnotationArgument annotationArgument = new AnnotationArgument();
            annotationArgument.name = pair.element().name();

            Type annotationArgumentType = pair.element().returnType();
            annotationArgument.type = annotationArgumentType.qualifiedTypeName();
            annotationArgument.isPrimitive = annotationArgumentType.isPrimitive();
            annotationArgument.isArray = annotationArgumentType.dimension().length() > 0;

            Object objValue = pair.value().value();
            if (objValue instanceof AnnotationValue[]) {
              AnnotationValue[] realValues = (AnnotationValue[]) objValue;
              String[] values = new String[realValues.length];

              for (int i = 0; i < realValues.length; i++) {
                values[i] = realValues[i].value().toString();
              }
              annotationArgument.value = values;
            } else if (objValue instanceof Number) {
              Number number = (Number) objValue;
              annotationArgument.value = new String[] {number.toString()};
            } else if (objValue instanceof Character) {
              Character character = (Character) objValue;
              annotationArgument.value = new String[] {character.toString()};
            } else if (objValue instanceof Boolean) {
              Boolean booleanValue = (Boolean) objValue;
              annotationArgument.value = new String[] {booleanValue.toString()};
            } else if (objValue instanceof String) {
              String stringValue = (String) objValue;
              annotationArgument.value = new String[] {stringValue};
            } else if (objValue instanceof FieldDoc) {
              FieldDoc field = (FieldDoc) objValue;
              annotationArgument.value = new String[] {field.name()};
            } else if (objValue instanceof ClassDoc) {
              ClassDoc classDoc = (ClassDoc) objValue;
              annotationArgument.value = new String[] {classDoc.qualifiedTypeName()};
            }
            argumentList.add(annotationArgument);
          }

          instance.arguments = argumentList.toArray(new AnnotationArgument[] {});
        }

        list.add(instance);
      }

      annotations = list.toArray(new AnnotationInstance[] {});
    }

    return annotations;
  }
Ejemplo n.º 12
0
 /** Skip any whitespace. @return @throws Exception */
 int skipWs() throws Exception {
   while (Character.isWhitespace(current())) read();
   return current();
 }