Java Class.getEnclosingClass Examples

Java Class.getEnclosingClass - 30 examples found. These are the top rated real world Java examples of Class.getEnclosingClass extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
 public Bean(String classPackage, String clazz, ClassLoaderStrategy cls, Bean topLevelBean)
     throws Exception {
   // Get the no-arg constructor and create the bean
   try {
     Class classOfBean = ObjectXml.getClassOfBean((ClassLoader) cls, classPackage + "." + clazz);
     Constructor ct = null;
     // check whether this class is an inner class
     if (classOfBean.getEnclosingClass() != null) {
       ct = classOfBean.getConstructor(new Class[] {classOfBean.getEnclosingClass()});
       beanObject = ct.newInstance(new Object[] {topLevelBean.getBeanObject()});
     } else {
       ct = classOfBean.getConstructor((Class[]) null);
       beanObject = ct.newInstance((Object[]) null);
     }
     // Get an array of property descriptors
     beanInfo = Introspector.getBeanInfo(classOfBean);
     PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
     // load property descriptors into hashtable
     propDesc = new Properties();
     for (int i = 0; i < pds.length; i++) {
       propDesc.put(pds[i].getName(), pds[i]);
     }
   } catch (Exception e) {
     System.err.println("Exception creating bean: " + e.getMessage());
     e.printStackTrace();
     throw e;
   }
 }
Example #2
0
    public ParameterizedTypeImpl(Type ownerType, Type rawType, Type... typeArguments) {
      // require an owner type if the raw type needs it
      if (rawType instanceof Class<?>) {
        Class<?> rawTypeAsClass = (Class<?>) rawType;
        try {
          Assert.isTrue(ownerType != null || rawTypeAsClass.getEnclosingClass() == null);
          Assert.isTrue(ownerType == null || rawTypeAsClass.getEnclosingClass() != null);
        } catch (RuntimeException e) {
          // R][2011-09-27 21:08:14,570] [ORM._log] ownerType:null
          // [ERROR][2011-09-27 21:08:14,572] [ORM._log]
          // rawTypeAsClass:interface java.util.Map$Entry
          // [ERROR][2011-09-27 21:08:14,573] [ORM._log]
          // getEnclosingClass:interface java.util.Map

          LogUtil.error("ownerType:" + ownerType);
          LogUtil.error("rawTypeAsClass:" + rawTypeAsClass);
          LogUtil.error("getEnclosingClass:" + rawTypeAsClass.getEnclosingClass());
          throw e;
        }
      }

      this.ownerType = ownerType == null ? null : canonicalize(ownerType);
      this.rawType = canonicalize(rawType);
      this.typeArguments = typeArguments.clone();
      for (int t = 0; t < this.typeArguments.length; t++) {
        Assert.notNull(this.typeArguments[t]);
        checkNotPrimitive(this.typeArguments[t]);
        this.typeArguments[t] = canonicalize(this.typeArguments[t]);
      }
    }
Example #3
0
 @NotNull
 public static ContractsContext getContext(@NotNull Class<?> clazz) {
   Class<?> outer = clazz;
   while (outer.getEnclosingClass() != null) {
     outer = outer.getEnclosingClass();
   }
   synchronized (CONTEXTS) {
     return getContext0(outer.getName());
   }
 }
 @Test
 public void testEnclosingType() throws Exception {
   for (Class<?> type : standardTypes) {
     assertThat(
         describe(type).getEnclosingType(),
         type.getEnclosingClass() == null
             ? nullValue(TypeDescription.class)
             : is((TypeDescription) new TypeDescription.ForLoadedType(type.getEnclosingClass())));
   }
 }
 /**
  * @return Returns the given objects enclosing container type, i.e the first class on the
  *     enclosing classes path that is abstract or the outermost enclosing class. The latter is the
  *     primary type.
  */
 public static Class<?> getEnclosingContainerType(Object o) {
   if (o == null) {
     return null;
   }
   Class<?> c = o.getClass();
   while (!Modifier.isAbstract(c.getModifiers()) && c.getEnclosingClass() != null) {
     c = c.getEnclosingClass();
   }
   return c;
 }
Example #6
0
 @Override
 public String shorten(Class<?> cls) {
   if (cls.getEnclosingClass() != null) {
     return shorten(cls.getEnclosingClass()) + "." + cls.getSimpleName();
   } else if (cls.getPackage() != null) {
     return getPrefixForTopLevelClass(cls.getPackage().getName(), cls.getSimpleName())
         + cls.getSimpleName();
   } else {
     return cls.getSimpleName();
   }
 }