build/annotationProcessors/classloader/AnnotatableEntity.java

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial