Coverage Report - javafx.reflect.ClassRef
 
Classes in this File Line Coverage Branch Coverage Complexity
ClassRef
38%
9/24
29%
4/14
0
ClassRef$1
0%
0/3
N/A
0
ClassRef$2
0%
0/4
0%
0/2
0
 
 1  
 /*
 2  
  * Copyright 1999-2008 Sun Microsystems, Inc.  All Rights Reserved.
 3  
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  
  *
 5  
  * This code is free software; you can redistribute it and/or modify it
 6  
  * under the terms of the GNU General Public License version 2 only, as
 7  
  * published by the Free Software Foundation.  Sun designates this
 8  
  * particular file as subject to the "Classpath" exception as provided
 9  
  * by Sun in the LICENSE file that accompanied this code.
 10  
  *
 11  
  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  
  * version 2 for more details (a copy is included in the LICENSE file that
 15  
  * accompanied this code).
 16  
  *
 17  
  * You should have received a copy of the GNU General Public License version
 18  
  * 2 along with this work; if not, write to the Free Software Foundation,
 19  
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  
  *
 21  
  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 22  
  * CA 95054 USA or visit www.sun.com if you need additional information or
 23  
  * have any questions.
 24  
  */
 25  
 
 26  
 package javafx.reflect;
 27  
 import java.util.*;
 28  
 
 29  
 /** A run-time representation of a JavaFX class.
 30  
  * Corresponds to {@code java.lang.Class}.
 31  
  */
 32  
 
 33  
 public abstract class ClassRef extends TypeRef {
 34  
     String name;
 35  
     ReflectionContext context;
 36  
     protected int modifiers;
 37  
     protected static final int COMPOUND_CLASS = 1;
 38  
     protected static final int FX_CLASS = 2;
 39  
 
 40  22
     protected ClassRef(ReflectionContext context, int modifiers) {
 41  22
         this.context = context;
 42  22
         this.modifiers = modifiers;
 43  22
     }
 44  
 
 45  
     public String getName() {
 46  98
         return name;
 47  
     }
 48  
     
 49  
     public String toString() {
 50  22
         return "class "+getName();
 51  
     }
 52  
 
 53  
     public boolean equals (ClassRef other) {
 54  0
         return context.equals(other.context) && name.equals(other.name);
 55  
     }
 56  
 
 57  
     /** Get list of super-classes.
 58  
      * Note we don't distinguish between classes and interfaces.
 59  
      * @param all if true include all ancestor classes (including this class).
 60  
      * @return the list of super-classes.  It sorted by class name for
 61  
      *   convenience and consistency.
 62  
      */
 63  
     public abstract List<ClassRef> getSuperClasses(boolean all);
 64  
     
 65  
     public boolean isCompoundClass() {
 66  21
         return (modifiers & COMPOUND_CLASS) != 0;
 67  
     }
 68  
 
 69  
     public boolean isJfxType() {
 70  3
         return (modifiers & FX_CLASS) != 0;
 71  
     }
 72  
 
 73  
      public boolean isAssignableFrom(ClassRef cls) {
 74  0
         if (this.equals(cls))
 75  0
             return true;
 76  0
         List<ClassRef> supers = cls.getSuperClasses(false);
 77  0
         for (ClassRef s : supers) {
 78  0
             if (isAssignableFrom(s))
 79  0
                 return true;
 80  
         }
 81  0
         return false;
 82  
     }
 83  
 
 84  
     public abstract void getMembers(MemberHandler handler, boolean all);
 85  
 
 86  
     public List<MemberRef> getMembers(boolean all) {
 87  0
         final List<MemberRef> result = new ArrayList<MemberRef>();
 88  0
         getMembers(new MemberHandler() {
 89  
             public boolean handle(MemberRef member) {
 90  0
                 result.add(member);
 91  0
                 return false;
 92  
             }
 93  
           }, all);
 94  0
         return result;
 95  
     }
 96  
 
 97  
     public List<AttributeRef> getAttributes(boolean all) {
 98  0
         final List<AttributeRef> result = new ArrayList<AttributeRef>();
 99  0
         getMembers(new MemberHandler() {
 100  
             public boolean handle(MemberRef member) {
 101  0
                 if (member instanceof AttributeRef)
 102  0
                     result.add((AttributeRef) member);
 103  0
                 return false;
 104  
             }
 105  
           }, all);
 106  0
         return result;
 107  
     }
 108  
 
 109  
     public ReflectionContext getReflectionContect() {
 110  18
         return context;
 111  
     }
 112  
 
 113  
     /** Return raw uninitialized object. */
 114  
     public abstract ObjectRef allocate ();
 115  
 
 116  
     /** Create a new initialized object.
 117  
      * This is just {@code allocate}+{@code ObjectRef.initialize}.
 118  
      */
 119  
     public ObjectRef newInstance() {
 120  0
         return allocate().initialize();
 121  
     }
 122  
 
 123  
     /** Get a member with the matching name and type. */
 124  
     public abstract MemberRef getMember(String name, TypeRef type);
 125  
 
 126  
     /** Get the attribute (field) of this class with a given name. */
 127  
     public abstract AttributeRef getAttribute(String name);
 128  
 
 129  
     /** Find the function that (best) matches the name and argument types. */
 130  
     public abstract MethodRef getMethod(String name, TypeRef... argType);
 131  
 
 132  
     /* FIXME - move to FieldRef?
 133  
     public abstract void setAttribute(AttributeRef field, ValueRef value);
 134  
     public abstract void initAttribute(AttributeRef field, ValueRef value);
 135  
     public void initAttribute(String field, ValueRef value) {
 136  
       initAttribute(getAttribute(field), value);
 137  
     }
 138  
     //  public void initAttributeBinding(AttributeRef field, LocationRef value);
 139  
     */
 140  
 }