コード例 #1
1
  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());
   }
 }
コード例 #3
1
  /**
   * 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;
  }
コード例 #5
0
ファイル: Types.java プロジェクト: hnwyllmm/voltdb
 @Nullable
 @Override
 Class<?> getOwnerType(Class<?> rawType) {
   if (rawType.isLocalClass()) {
     return null;
   } else {
     return rawType.getEnclosingClass();
   }
 }
コード例 #6
0
ファイル: isLocalClass.java プロジェクト: niloc132/mauve-gwt
  /**
   * 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());
  }
コード例 #7
0
ファイル: isLocalClass.java プロジェクト: niloc132/mauve-gwt
  /**
   * 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 CharConversionException("xyzzy");

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

    harness.check(!c.isLocalClass());
  }
コード例 #8
0
  public static boolean isAnnotationReturnType(Class cls) {
    // TODO review this calculation
    Class targetType = cls;
    if (cls.isArray() && (targetType = cls.getComponentType()).isArray()) {
      return false;
    }

    return (targetType.isAnnotation() || targetType.isEnum() || targetType.isPrimitive())
        || (!targetType.isAnonymousClass() && !targetType.isLocalClass());
  }
コード例 #9
0
ファイル: TypeReference.java プロジェクト: ghaith/xtext
 public TypeReference(final Class<?> clazz, final List<TypeReference> arguments) {
   boolean _isPrimitive = clazz.isPrimitive();
   if (_isPrimitive) {
     String _name = clazz.getName();
     String _plus = ("Type is primitive: " + _name);
     throw new IllegalArgumentException(_plus);
   }
   boolean _isAnonymousClass = clazz.isAnonymousClass();
   if (_isAnonymousClass) {
     String _name_1 = clazz.getName();
     String _plus_1 = ("Class is anonymous: " + _name_1);
     throw new IllegalArgumentException(_plus_1);
   }
   boolean _isLocalClass = clazz.isLocalClass();
   if (_isLocalClass) {
     String _name_2 = clazz.getName();
     String _plus_2 = ("Class is local: " + _name_2);
     throw new IllegalArgumentException(_plus_2);
   }
   Package _package = clazz.getPackage();
   String _name_3 = _package.getName();
   this.packageName = _name_3;
   ArrayList<String> _newArrayList = CollectionLiterals.<String>newArrayList();
   this.simpleNames = _newArrayList;
   List<TypeReference> _elvis = null;
   if (arguments != null) {
     _elvis = arguments;
   } else {
     List<TypeReference> _emptyList = Collections.<TypeReference>emptyList();
     _elvis = _emptyList;
   }
   this.typeArguments = _elvis;
   Class<?> c = clazz;
   do {
     {
       String _simpleName = c.getSimpleName();
       this.simpleNames.add(0, _simpleName);
       Class<?> _declaringClass = c.getDeclaringClass();
       c = _declaringClass;
     }
   } while ((c != null));
 }
コード例 #10
0
  /**
   * @return Return true if the given type can be managed by the driver, and subsequently by the UI.
   *     <p>E.g. of managed types are: int, Integer, java.lang.Integer, org.kie.SomeClass,
   *     List<Integer>, java.util.List<org.kie.SomeClass>
   *     <p>e.g. of not manged types are: int[], java.util.List<List<String>>, List<Map<String,
   *     org.kie.SomeClass>>
   */
  public static boolean isManagedType(Type type, ClassTypeResolver classTypeResolver)
      throws ModelDriverException {

    // quickest checks first.
    if (type.isPrimitive()) {
      return true;
    }

    if (type.isArray()) {
      return false;
    }

    if (type.isParameterized() && type.getTypeArguments().size() > 1) {
      return false;
    }

    try {

      Class<?> clazz = classTypeResolver.resolveType(type.getName());

      if (clazz.isAnonymousClass() || clazz.isLocalClass() || clazz.isMemberClass()) {
        return false;
      }

      if (type.isParameterized()) {
        Class<?> bag = classTypeResolver.resolveType(type.getName());
        if (!Collection.class.isAssignableFrom(bag)) {
          return false;
        }

        return isSimpleClass(((List<Type>) type.getTypeArguments()).get(0));
      }

      return true;

    } catch (ClassNotFoundException e) {
      throw new ModelDriverException(
          "Class could not be resolved for name: " + type.getName() + ". " + e.getMessage(), e);
    }
  }
コード例 #11
0
  private static void addFromClasspath(Set<Class<? extends Module>> modules) {
    ClassClassLoaderResolver<Module> resolver = new ClassClassLoaderResolver<Module>();
    Set<Class<Module>> moduleClasses;
    try {
      moduleClasses =
          resolver.findByLocators(
              new ClassClassLoaderResolver.IsA(Module.class),
              false,
              GuiceContainer.guiceExcludeModules,
              "guice");
    } catch (IOException e) {
      throw new RuntimeException(e);
    }

    Set<Class<Module>> matches = new HashSet<Class<Module>>(moduleClasses);

    for (Class<Module> moduleClass : moduleClasses) {
      // Ensure the class is not abstract
      if ((moduleClass.getModifiers() & Modifier.ABSTRACT) != 0
          || moduleClass.isAnonymousClass()
          || moduleClass.isLocalClass()) {
        matches.remove(moduleClass);
        continue;
      }

      // Remove any instances of this classes parents from the matches
      Class<?> parent = moduleClass.getSuperclass();
      while (Module.class.isAssignableFrom(parent)) {
        matches.remove(parent);
        parent = parent.getSuperclass();
      }
    }

    for (Class<Module> match : matches) {
      logger.info("Adding module [" + match + "] from classpath to Guice injector.");
    }

    modules.addAll(matches);
  }
コード例 #12
0
  /**
   * This method is used to filter classes that are added to the {@link DeployedUnit}. When this
   * method is used, only classes that are meant to be used with serialization are added to the
   * deployment. This feature can be used to, for example, make sure that
   * non-serialization-compatible classes (such as interfaces), do not complicate the use of a
   * deployment with the remote services (REST/JMS/WS). Note to other developers, it's possible that
   * classpath problems may arise, because of either classloader or lazy class resolution problems:
   * I simply don't know enough about the inner workings of the JAXB implementations (plural!) to
   * figure this out.
   *
   * @param deployedUnit The {@link DeployedUnit} to which the classes are added. The {@link
   *     DeployedUnit} to which the classes are added. The {@link DeployedUnit} to which the classes
   *     are added.
   * @param classToAdd The class to add to the {@link DeployedUnit}.
   */
  private static void filterClassesAddedToDeployedUnit(
      DeployedUnit deployedUnit, Class classToAdd) {

    if (classToAdd.isInterface()
        || classToAdd.isAnnotation()
        || classToAdd.isLocalClass()
        || classToAdd.isMemberClass()) {
      return;
    }

    boolean jaxbClass = false;
    boolean remoteableClass = false;
    // @XmlRootElement and @XmlType may be used with inheritance
    for (Annotation anno : classToAdd.getAnnotations()) {
      if (XmlRootElement.class.equals(anno.annotationType())) {
        jaxbClass = true;
        break;
      }
      if (XmlType.class.equals(anno.annotationType())) {
        jaxbClass = true;
        break;
      }
    }
    // @Remotable is not inheritable, and may not be used as such
    for (Annotation anno : classToAdd.getDeclaredAnnotations()) {
      if (Remotable.class.equals(anno.annotationType())) {
        remoteableClass = true;
        break;
      }
    }

    if (jaxbClass || remoteableClass) {
      DeployedUnitImpl deployedUnitImpl = (DeployedUnitImpl) deployedUnit;
      deployedUnitImpl.addClass(classToAdd);
    }
  }
コード例 #13
0
 private boolean isAnonymousOrLocal(Class<?> clazz) {
   return !Enum.class.isAssignableFrom(clazz)
       && (clazz.isAnonymousClass() || clazz.isLocalClass());
 }
コード例 #14
0
ファイル: Fixjure.java プロジェクト: douglasrodrigo/fixjures
  /**
   * Creates a new un-sourced fixture builder of the given class.
   *
   * @param cls fixture class
   * @param <T> fixture type
   * @return new un-sourced fixture builder
   */
  public static <T> FixtureBuilder<T> of(final Class<T> cls) {
    checkNotNull(cls);
    checkArgument(!cls.isLocalClass(), "Class cannot be local.");

    return new FixtureBuilder<T>(TypeWrapper.wrap(cls));
  }
コード例 #15
0
ファイル: Types.java プロジェクト: MineHQ/mc-dev-1.8.7
 @Nullable
 Class<?> getOwnerType(Class<?> var1) {
   return var1.isLocalClass() ? null : var1.getEnclosingClass();
 }
コード例 #16
0
  @SuppressWarnings("rawtypes")
  @Test
  public void searchAndTest() {
    Reflections reflections = new Reflections("org.estatio.dom");

    System.out.println("EstatioDomainObjectContractTestAll_jdoAnnotations");

    Set<Class<? extends UdoDomainObject>> subtypes =
        reflections.getSubTypesOf(UdoDomainObject.class);
    for (Class<? extends UdoDomainObject> subtype : subtypes) {
      if (subtype.isAnonymousClass()
          || subtype.isLocalClass()
          || subtype.isMemberClass()
          || subtype.getName().endsWith("ForTesting")) {
        // skip (probably a testing class)
        continue;
      }
      if (UdoDomainObject.class == subtype || EstatioDomainObject.class == subtype) {
        // skip
        continue;
      }

      System.out.println(">>> " + subtype.getName());

      // must have a @PersistenceCapable(identityType=...) annotation
      final PersistenceCapable persistenceCapable = subtype.getAnnotation(PersistenceCapable.class);
      assertThat(
          "Class "
              + subtype.getName()
              + " inherits from EstatioDomainObject "
              + "but is not annotated with @PersistenceCapable",
          persistenceCapable,
          is(not(nullValue())));
      IdentityType identityType = persistenceCapable.identityType();
      assertThat(
          "Class "
              + subtype.getName()
              + " @PersistenceCapable annotation "
              + "does not specify the identityType",
          identityType,
          is(not(nullValue())));

      if (identityType == IdentityType.DATASTORE) {
        // NOT mandatory to have a @DatastoreIdentity, but if does, then @DatastoreIdentity(...,
        // column="id")
        final DatastoreIdentity datastoreIdentity = subtype.getAnnotation(DatastoreIdentity.class);
        if (datastoreIdentity != null) {
          assertThat(
              "Class "
                  + subtype.getName()
                  + " @DataStoreIdentity annotation does not specify column=\"id\"",
              datastoreIdentity.column(),
              is("id"));
        }
      }

      Inheritance inheritance = subtype.getAnnotation(Inheritance.class);

      if (inheritance != null && inheritance.strategy() == InheritanceStrategy.SUPERCLASS_TABLE) {
        // must NOT have a @Discriminator(..., column="discriminator")
        final Annotation[] declaredAnnotations = subtype.getDeclaredAnnotations();
        for (Annotation declaredAnnotation : declaredAnnotations) {
          if (declaredAnnotation.annotationType() == Discriminator.class) {
            Assert.fail(
                "Class "
                    + subtype.getName()
                    + " inherits from "
                    + subtype.getSuperclass().getName()
                    + "and has (incorrectly) been annotated with @Discriminator");
          }
        }

        // check if supertype has discriminator

        // must have a @Discriminator(..., column="discriminator") on one of its supertypes
        final Discriminator superDiscriminator =
            subtype.getSuperclass().getAnnotation(Discriminator.class);
        assertThat(
            "Class "
                + subtype.getSuperclass().getName()
                + " is inherited by "
                + subtype.getName()
                + "but is not annotated with @Discriminator",
            superDiscriminator,
            is(not(nullValue())));

        assertThat(
            "Class "
                + subtype.getName()
                + " @Discriminator annotation does not specify column=\"discriminator\"",
            superDiscriminator.column(),
            is("discriminator"));
      }

      if (subtype.getSuperclass().equals(UdoDomainObject.class)) {
        // must have a @Version(..., column="version")
        final Version version = getAnnotationOfTypeOfItsSupertypes(subtype, Version.class);

        assertThat(
            "Class "
                + subtype.getName()
                + " inherits from EstatioMutableObject "
                + "but is not annotated with @Version",
            version,
            is(not(nullValue())));

        assertThat(
            "Class "
                + subtype.getName()
                + " @Version annotation does not specify have column=\"version\"",
            version.column(),
            is("version"));
      }
    }
  }
コード例 #17
0
 public static boolean isValidAnnotationBaseReturnType(Class cls) {
   // TODO review this calculation
   return (cls.isAnnotation() || cls.isEnum() || NamingUtils.isPrimitiveTypeId(cls.getName()))
       || (!cls.isAnonymousClass() && !cls.isLocalClass());
 }
コード例 #18
0
 @Test
 public void testIsLocalClass() throws Exception {
   for (Class<?> type : standardTypes) {
     assertThat(describe(type).isLocalClass(), is(type.isLocalClass()));
   }
 }