Top Description Inners Fields Constructors Methods
com.sun.codemodel

public Class JJavaName

extends Object
Class Inheritance
Imports
java.util.Arrays, .HashSet, java.util.regex.Matcher, .Pattern

Utility methods that convert arbitrary strings into Java identifiers.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static HashSet<String>
reservedKeywords

All reserved keywords of Java.

private static final JJavaName.Entry[]

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

always non-null.
getPluralForm
(String
a word, such as "child", "apple". Must not be null. It accepts word concatanation forms that are common in programming languages, such as "my_child", "MyChild", "myChild", "MY-CHILD", "CODE003-child", etc, and mostly tries to do the right thing. ("my_children","MyChildren","myChildren", and "MY-CHILDREN", "CODE003-children" respectively)

Although this method only works for English words, it handles non-English words gracefully (by just returning it as-is.) For example, "日本語" will be returned as-is without modified, not "日本語s"

This method doesn't handle suffixes very well. For example, passing "person56" will return "person56s", not "people56".

word
)

Experimental API: converts an English word into a plural form.

public static boolean
isFullyQualifiedClassName(String s)

Checks if the given string is a valid fully qualified name.

public static boolean
isJavaIdentifier(String s)

Checks if a given string is usable as a Java identifier.

public static boolean
isJavaPackageName(String s)

Checks if the given string is a valid Java package name.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

reservedKeywordsback to summary
private static HashSet<String> reservedKeywords

All reserved keywords of Java.

TABLEback to summary
private static final JJavaName.Entry[] TABLE

Constructor Detail

JJavaNameback to summary
private JJavaName()

Method Detail

getPluralFormback to summary
public static String getPluralForm(String word)

Experimental API: converts an English word into a plural form.

Parameters
word:String

a word, such as "child", "apple". Must not be null. It accepts word concatanation forms that are common in programming languages, such as "my_child", "MyChild", "myChild", "MY-CHILD", "CODE003-child", etc, and mostly tries to do the right thing. ("my_children","MyChildren","myChildren", and "MY-CHILDREN", "CODE003-children" respectively)

Although this method only works for English words, it handles non-English words gracefully (by just returning it as-is.) For example, "日本語" will be returned as-is without modified, not "日本語s"

This method doesn't handle suffixes very well. For example, passing "person56" will return "person56s", not "people56".

Returns:String

always non-null.

isFullyQualifiedClassNameback to summary
public static boolean isFullyQualifiedClassName(String s)

Checks if the given string is a valid fully qualified name.

isJavaIdentifierback to summary
public static boolean isJavaIdentifier(String s)

Checks if a given string is usable as a Java identifier.

isJavaPackageNameback to summary
public static boolean isJavaPackageName(String s)

Checks if the given string is a valid Java package name.

com.sun.codemodel back to summary

private Class JJavaName.Entry

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final Pattern
private final String

Constructor Summary

AccessConstructor and Description
public
Entry(String pattern, String replacement)

Method Summary

Modifier and TypeMethod and Description
pack-priv String
apply(String word)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

patternback to summary
private final Pattern pattern
replacementback to summary
private final String replacement

Constructor Detail

Entryback to summary
public Entry(String pattern, String replacement)

Method Detail

applyback to summary
pack-priv String apply(String word)