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