001 package edu.rice.cs.cunit.classFile.constantPool.visitors;
002
003 import edu.rice.cs.cunit.classFile.constantPool.*;
004
005 /**
006 * Check that the host is a UTF info.
007 *
008 * @author Mathias Ricken
009 */
010 public class CheckUTFOrEmptyVisitor extends ADefaultPoolInfoVisitor<APoolInfo, Object> {
011 /**
012 * Singleton constructor.
013 */
014 private CheckUTFOrEmptyVisitor() {
015 }
016
017 /**
018 * Singleton instance.
019 */
020 private static CheckUTFOrEmptyVisitor _instance = new CheckUTFOrEmptyVisitor();
021
022 /**
023 * Singleton accessor.
024 *
025 * @return singleton
026 */
027 public static CheckUTFOrEmptyVisitor singleton() {
028 return _instance;
029 }
030
031 /**
032 * All other cases throw.
033 *
034 * @param host non-UTF host
035 * @param o not used
036 *
037 * @return nothing
038 */
039 public AUTFPoolInfo defaultCase(APoolInfo host, Object o) {
040 throw new ClassFormatError("Info is of type " + host.getClass().getName() + ", needs to be AUTFPoolInfo or EmptyInfo");
041 }
042
043 /**
044 * Return host.
045 *
046 * @param host UTF host
047 * @param o not used
048 *
049 * @return host
050 */
051 public APoolInfo asciizCase(ASCIIPoolInfo host, Object o) {
052 return host;
053 }
054
055 /**
056 * Return host.
057 *
058 * @param host UTF host
059 * @param o not used
060 *
061 * @return host
062 */
063 public APoolInfo unicodeCase(UnicodePoolInfo host, Object o) {
064 return host;
065 }
066
067 /**
068 * Return host.
069 *
070 * @param host UTF host
071 * @param o not used
072 *
073 * @return host
074 */
075 public APoolInfo emptyCase(EmptyPoolInfo host, Object o) {
076 return host;
077 }
078 }