build/annotationProcessors/classloader/AnnotatableEntity.java

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 package org.mozilla.gecko.annotationProcessors.classloader;
     7 import org.mozilla.gecko.annotationProcessors.AnnotationInfo;
     9 import java.lang.reflect.Constructor;
    10 import java.lang.reflect.Field;
    11 import java.lang.reflect.Member;
    12 import java.lang.reflect.Method;
    14 /**
    15  * Union type to hold either a method, field, or ctor. Allows us to iterate "The generatable stuff", despite
    16  * the fact that such things can be of either flavour.
    17  */
    18 public class AnnotatableEntity {
    19     public enum ENTITY_TYPE {METHOD, FIELD, CONSTRUCTOR}
    21     private final Member mMember;
    22     public final ENTITY_TYPE mEntityType;
    24     public final AnnotationInfo mAnnotationInfo;
    26     public AnnotatableEntity(Member aObject, AnnotationInfo aAnnotationInfo) {
    27         mMember = aObject;
    28         mAnnotationInfo = aAnnotationInfo;
    30         if (aObject instanceof Method) {
    31             mEntityType = ENTITY_TYPE.METHOD;
    32         } else if (aObject instanceof Field) {
    33             mEntityType = ENTITY_TYPE.FIELD;
    34         } else {
    35             mEntityType = ENTITY_TYPE.CONSTRUCTOR;
    36         }
    37     }
    39     public Method getMethod() {
    40         if (mEntityType != ENTITY_TYPE.METHOD) {
    41             throw new UnsupportedOperationException("Attempt to cast to unsupported member type.");
    42         }
    43         return (Method) mMember;
    44     }
    45     public Field getField() {
    46         if (mEntityType != ENTITY_TYPE.FIELD) {
    47             throw new UnsupportedOperationException("Attempt to cast to unsupported member type.");
    48         }
    49         return (Field) mMember;
    50     }
    51     public Constructor getConstructor() {
    52         if (mEntityType != ENTITY_TYPE.CONSTRUCTOR) {
    53             throw new UnsupportedOperationException("Attempt to cast to unsupported member type.");
    54         }
    55         return (Constructor) mMember;
    56     }
    57 }

mercurial