001 package de.java2html.javasource;
002
003 import java.util.HashSet;
004 import java.util.Set;
005
006 public class JavaKeywords {
007
008 /*
009 * As defined by Java Language Specification SE §3,
010 */
011 private final static String[] JAVA_KEYWORDS = {
012 "assert",
013 "abstract",
014 "default",
015 "if",
016 "private",
017 "this",
018 "do",
019 "implements",
020 "protected",
021 "throw",
022 "break",
023 "import",
024 "public",
025 "throws",
026 "else",
027 "instanceof",
028 "return",
029 "transient",
030 "case",
031 "extends",
032 "try",
033 "catch",
034 "final",
035 "interface",
036 "static",
037 "finally",
038 "strictfp",
039 "volatile",
040 "class",
041 "native",
042 "super",
043 "while",
044 "const",
045 "for",
046 "new",
047 "strictfp",
048 "switch",
049 "continue",
050 "goto",
051 "package",
052 "synchronized",
053 "threadsafe",
054 "null",
055 "true",
056 "false",
057 //Enum keyword from JDK1.5 (TypeSafe Enums)
058 "enum",
059 "@interface" };
060
061 private final static String[] JAVADOC_KEYWORDS = {
062 "@author",
063 "@beaninfo",
064 "@docRoot",
065 "@deprecated",
066 "@exception",
067 "@link",
068 "@param",
069 "@return",
070 "@see",
071 "@serial",
072 "@serialData",
073 "@serialField",
074 "@since",
075 "@throws",
076 "@version",
077 //new in JDK1.4
078 "@linkplain",
079 "@inheritDoc",
080 "@value",
081 //from iDoclet
082 "@pre",
083 "@post",
084 "@inv",
085 //from disy
086 "@published" };
087
088 /** Hashtables for fast access to JavaDoc keywords (tags) */
089 private static final Set<String> tableJavaDocKeywords = new HashSet<String>();
090
091 /** Hashtables for fast access to keywords */
092 private static final Set<String> tableJavaKeywords = new HashSet<String>();
093
094 private final static JavaKeywords instance = new JavaKeywords();
095
096 public static JavaKeywords getInstance() {
097 return instance;
098 }
099
100 private JavaKeywords() {
101 for (int i = 0; i < JAVADOC_KEYWORDS.length; ++i) {
102 tableJavaDocKeywords.add(JAVADOC_KEYWORDS[i]);
103 }
104
105 for (int i = 0; i < JAVA_KEYWORDS.length; ++i) {
106 tableJavaKeywords.add(JAVA_KEYWORDS[i]);
107 }
108 }
109
110 public boolean isJavaKeyWord(String s) {
111 return tableJavaKeywords.contains(s);
112 }
113
114 public boolean isJavaDocKeyword(String s) {
115 return tableJavaDocKeywords.contains(s);
116 }
117 }
|