Java Class.isLocalClass Examples

Java Class.isLocalClass - 18 examples found. These are the top rated real world Java examples of Class.isLocalClass extracted from open source projects. You can rate examples to help us improve the quality of examples.
  protected <T> T executeCommand(Command cmd) {
    if (AcceptedClientCommands.isSendObjectParameterCommandClass(cmd.getClass())) {
      List<Object> extraClassInstanceList = new ArrayList<Object>();
      preprocessParameterCommand(cmd, extraClassInstanceList);

      if (!extraClassInstanceList.isEmpty()) {
        Set<Class<?>> extraJaxbClasses = new HashSet<Class<?>>();
        for (Object jaxbObject : extraClassInstanceList) {
          Class<?> jaxbClass = jaxbObject.getClass();
          if (jaxbClass.isLocalClass() || jaxbClass.isAnonymousClass()) {
            throw new SerializationException(
                "Only proper classes are allowed as parameters for the remote API: neither local nor anonymous classes are accepted: "
                    + jaxbClass.getName());
          }
          extraJaxbClasses.add(jaxbClass);
        }
        if (config.addJaxbClasses(extraJaxbClasses)) {
          for (Class<?> extraClass : extraJaxbClasses) {
            logger.debug(
                "Adding {} to the JAXBContext instance in this client instance.",
                extraClass.getName());
          }
          config.initializeJaxbSerializationProvider();
        }
      }
    }

    preprocessCommand(cmd);

    if (config.isRest()) {
      return executeRestCommand(cmd);
    } else {
      return executeJmsCommand(cmd);
    }
  }
 @Test
 public void should_generate_assertion_for_classes_in_package_using_provided_class_loader()
     throws Exception {
   ClassLoader customClassLoader =
       new MyClassLoader(Thread.currentThread().getContextClassLoader());
   Set<Class<?>> classes =
       collectClasses(customClassLoader, "org.assertj.assertions.generator.data");
   for (Class<?> clazz : classes) {
     assertThat(clazz.isAnonymousClass())
         .as("check that " + clazz.getSimpleName() + " is not anonymous")
         .isFalse();
     assertThat(clazz.isLocalClass())
         .as("check that " + clazz.getSimpleName() + " is not local")
         .isFalse();
     assertThat(isPublic(clazz.getModifiers()))
         .as("check that " + clazz.getSimpleName() + " is public")
         .isTrue();
     logger.info("Generating assertions for {}", clazz.getName());
     final ClassDescription classDescription = converter.convertToClassDescription(clazz);
     File customAssertionFile = assertionGenerator.generateCustomAssertionFor(classDescription);
     logger.info(
         "Generated {} assertions file -> {}",
         clazz.getSimpleName(),
         customAssertionFile.getAbsolutePath());
   }
 }
  /**
   * Default constructor associates this handler with the queue for the current thread.
   *
   * <p>If there isn't one, this handler won't be able to receive messages.
   */
  public Handler() {
    if (FIND_POTENTIAL_LEAKS) {
      final Class<? extends Handler> klass = getClass();
      if ((klass.isAnonymousClass() || klass.isMemberClass() || klass.isLocalClass())
          && (klass.getModifiers() & Modifier.STATIC) == 0) {
        Log.w(
            TAG,
            "The following Handler class should be static or leaks might occur: "
                + klass.getCanonicalName());
      }
    }
    // @wujl commented

    mLooper = Looper.myLooper();
    if (mLooper == null) {
      throw new RuntimeException(
          "Can't create handler inside thread that has not called Looper.prepare()");
    }
    mQueue = mLooper.mQueue;

    // #wujl
    // @wujl added
    // mLooper = null;
    // mQueue = null;
    // #wujl
    mCallback = null;
  }
  /*
   * TODO: Profiling shows that the reflection and conditional logic in this
   * method is a hotspot. This could be remedied by generating synthetic
   * InstantiateCommand types that initialize themselves.
   */
  private IdentityValueCommand makeObject(Class<?> type, Object value)
      throws SerializationException {

    if (type.isAnonymousClass() || type.isLocalClass()) {
      throw new SerializationException("Cannot serialize anonymous or local classes");
    }

    Class<?> manualType = type;
    Class<?> customSerializer;
    do {
      customSerializer = SerializabilityUtil.hasCustomFieldSerializer(manualType);
      if (customSerializer != null) {
        break;
      }
      manualType = manualType.getSuperclass();
    } while (manualType != null);

    IdentityValueCommand ins;
    if (customSerializer != null) {
      ins = serializeWithCustomSerializer(customSerializer, value, type, manualType);
    } else {
      ins = new InstantiateCommand(type);
      identityMap.put(value, ins);
    }

    /*
     * If we're looking at a subclass of a manually-serialized type, the
     * subclass must be tagged as serializable in order to qualify for
     * serialization.
     */
    if (type != manualType) {
      if (!Serializable.class.isAssignableFrom(type)
          && !IsSerializable.class.isAssignableFrom(type)) {
        throw new SerializationException(type.getName() + " is not a serializable type");
      }
    }

    while (type != manualType) {
      Field[] serializableFields = clientOracle.getOperableFields(type);
      for (Field declField : serializableFields) {
        assert (declField != null);

        Accessor accessor = CommandSerializationUtil.getAccessor(declField.getType());
        ValueCommand valueCommand;
        Object fieldValue = accessor.get(value, declField);
        if (fieldValue == null) {
          valueCommand = NullValueCommand.INSTANCE;
        } else {
          Class<? extends Object> fieldType =
              declField.getType().isPrimitive() ? declField.getType() : fieldValue.getClass();
          valueCommand = makeValue(fieldType, fieldValue);
        }

        ((HasSetters) ins).set(declField.getDeclaringClass(), declField.getName(), valueCommand);
      }
      type = type.getSuperclass();
    }
    return ins;
  }
Example #5
0
 @Nullable
 @Override
 Class<?> getOwnerType(Class<?> rawType) {
   if (rawType.isLocalClass()) {
     return null;
   } else {
     return rawType.getEnclosingClass();
   }
 }
Example #6
0
  /**
   * Runs the test using the specified harness.
   *
   * @param harness the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness) {
    // create instance of a class Double
    Object o = new NegativeArraySizeException("NegativeArraySizeException");

    // get a runtime class of an object "o"
    Class c = o.getClass();

    harness.check(!c.isLocalClass());
  }