1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/build/annotationProcessors/classloader/AnnotatableEntity.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,57 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +package org.mozilla.gecko.annotationProcessors.classloader; 1.9 + 1.10 +import org.mozilla.gecko.annotationProcessors.AnnotationInfo; 1.11 + 1.12 +import java.lang.reflect.Constructor; 1.13 +import java.lang.reflect.Field; 1.14 +import java.lang.reflect.Member; 1.15 +import java.lang.reflect.Method; 1.16 + 1.17 +/** 1.18 + * Union type to hold either a method, field, or ctor. Allows us to iterate "The generatable stuff", despite 1.19 + * the fact that such things can be of either flavour. 1.20 + */ 1.21 +public class AnnotatableEntity { 1.22 + public enum ENTITY_TYPE {METHOD, FIELD, CONSTRUCTOR} 1.23 + 1.24 + private final Member mMember; 1.25 + public final ENTITY_TYPE mEntityType; 1.26 + 1.27 + public final AnnotationInfo mAnnotationInfo; 1.28 + 1.29 + public AnnotatableEntity(Member aObject, AnnotationInfo aAnnotationInfo) { 1.30 + mMember = aObject; 1.31 + mAnnotationInfo = aAnnotationInfo; 1.32 + 1.33 + if (aObject instanceof Method) { 1.34 + mEntityType = ENTITY_TYPE.METHOD; 1.35 + } else if (aObject instanceof Field) { 1.36 + mEntityType = ENTITY_TYPE.FIELD; 1.37 + } else { 1.38 + mEntityType = ENTITY_TYPE.CONSTRUCTOR; 1.39 + } 1.40 + } 1.41 + 1.42 + public Method getMethod() { 1.43 + if (mEntityType != ENTITY_TYPE.METHOD) { 1.44 + throw new UnsupportedOperationException("Attempt to cast to unsupported member type."); 1.45 + } 1.46 + return (Method) mMember; 1.47 + } 1.48 + public Field getField() { 1.49 + if (mEntityType != ENTITY_TYPE.FIELD) { 1.50 + throw new UnsupportedOperationException("Attempt to cast to unsupported member type."); 1.51 + } 1.52 + return (Field) mMember; 1.53 + } 1.54 + public Constructor getConstructor() { 1.55 + if (mEntityType != ENTITY_TYPE.CONSTRUCTOR) { 1.56 + throw new UnsupportedOperationException("Attempt to cast to unsupported member type."); 1.57 + } 1.58 + return (Constructor) mMember; 1.59 + } 1.60 +}