michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.annotationProcessors.classloader; michael@0: michael@0: import org.mozilla.gecko.annotationProcessors.AnnotationInfo; michael@0: michael@0: import java.lang.reflect.Constructor; michael@0: import java.lang.reflect.Field; michael@0: import java.lang.reflect.Member; michael@0: import java.lang.reflect.Method; michael@0: michael@0: /** michael@0: * Union type to hold either a method, field, or ctor. Allows us to iterate "The generatable stuff", despite michael@0: * the fact that such things can be of either flavour. michael@0: */ michael@0: public class AnnotatableEntity { michael@0: public enum ENTITY_TYPE {METHOD, FIELD, CONSTRUCTOR} michael@0: michael@0: private final Member mMember; michael@0: public final ENTITY_TYPE mEntityType; michael@0: michael@0: public final AnnotationInfo mAnnotationInfo; michael@0: michael@0: public AnnotatableEntity(Member aObject, AnnotationInfo aAnnotationInfo) { michael@0: mMember = aObject; michael@0: mAnnotationInfo = aAnnotationInfo; michael@0: michael@0: if (aObject instanceof Method) { michael@0: mEntityType = ENTITY_TYPE.METHOD; michael@0: } else if (aObject instanceof Field) { michael@0: mEntityType = ENTITY_TYPE.FIELD; michael@0: } else { michael@0: mEntityType = ENTITY_TYPE.CONSTRUCTOR; michael@0: } michael@0: } michael@0: michael@0: public Method getMethod() { michael@0: if (mEntityType != ENTITY_TYPE.METHOD) { michael@0: throw new UnsupportedOperationException("Attempt to cast to unsupported member type."); michael@0: } michael@0: return (Method) mMember; michael@0: } michael@0: public Field getField() { michael@0: if (mEntityType != ENTITY_TYPE.FIELD) { michael@0: throw new UnsupportedOperationException("Attempt to cast to unsupported member type."); michael@0: } michael@0: return (Field) mMember; michael@0: } michael@0: public Constructor getConstructor() { michael@0: if (mEntityType != ENTITY_TYPE.CONSTRUCTOR) { michael@0: throw new UnsupportedOperationException("Attempt to cast to unsupported member type."); michael@0: } michael@0: return (Constructor) mMember; michael@0: } michael@0: }