Esempio n. 1
0
  private static void initializeAndModify(
      TypesCache temporaryTypes, ObjectType type, List<Class<?>> modifications) {
    State typeState = type.getState();
    Map<String, Object> typeOriginals = typeState.getSimpleValues();

    try {
      type.initialize();
      temporaryTypes.add(type);

      // Apply type-specific modifications.
      if (modifications != null) {
        for (Class<?> modification : modifications) {
          type.modify(modification);
        }
      }

    } catch (IncompatibleClassChangeError ex) {
      LOGGER.info(
          "Skipped initializing [{}] because its class is in an inconsistent state! ([{}])",
          type.getInternalName(),
          ex.getMessage());
    }

    if (typeState.isNew()) {
      type.save();

    } else if (!typeState.getSimpleValues().equals(typeOriginals)) {
      temporaryTypes.changed.add(type.getId());
    }
  }
Esempio n. 2
0
  /**
   * @param resource
   * @param path
   * @param b
   * @param uri
   * @param dip
   * @param width
   * @param height
   * @return
   */
  public static Bitmap createChattingImage(
      int resource, String path, byte[] b, Uri uri, float dip, int width, int height) {
    if (width <= 0 || height <= 0) {
      return null;
    }

    BitmapFactory.Options options = new BitmapFactory.Options();
    int outWidth = 0;
    int outHeight = 0;
    int sampleSize = 0;
    try {

      do {
        if (dip != 0.0F) {
          options.inDensity = (int) (160.0F * dip);
        }
        options.inJustDecodeBounds = true;
        decodeMuilt(options, b, path, uri, resource);
        //
        outWidth = options.outWidth;
        outHeight = options.outHeight;

        options.inPreferredConfig = Bitmap.Config.ARGB_8888;
        if (outWidth <= width || outHeight <= height) {
          sampleSize = 0;
          setInNativeAlloc(options);
          Bitmap decodeMuiltBitmap = decodeMuilt(options, b, path, uri, resource);
          return decodeMuiltBitmap;
        } else {
          options.inSampleSize = (int) Math.max(outWidth / width, outHeight / height);
          sampleSize = options.inSampleSize;
        }
      } while (sampleSize != 0);

    } catch (IncompatibleClassChangeError e) {
      e.printStackTrace();
      throw ((IncompatibleClassChangeError)
          new IncompatibleClassChangeError("May cause dvmFindCatchBlock crash!").initCause(e));
    } catch (Throwable throwable) {
      throwable.printStackTrace();
      BitmapFactory.Options catchOptions = new BitmapFactory.Options();
      if (dip != 0.0F) {
        catchOptions.inDensity = (int) (160.0F * dip);
      }
      catchOptions.inPreferredConfig = Bitmap.Config.RGB_565;
      if (sampleSize != 0) {
        catchOptions.inSampleSize = sampleSize;
      }
      setInNativeAlloc(catchOptions);
      try {
        return decodeMuilt(options, b, path, uri, resource);
      } catch (IncompatibleClassChangeError twoE) {
        twoE.printStackTrace();
        throw ((IncompatibleClassChangeError)
            new IncompatibleClassChangeError("May cause dvmFindCatchBlock crash!").initCause(twoE));
      } catch (Throwable twoThrowable) {
        twoThrowable.printStackTrace();
      }
    }

    return null;
  }
Esempio n. 3
0
  protected void checkRedeclaration(
      AbstractClassTypeDeclarationDescr typeDescr,
      TypeDeclaration type,
      PackageRegistry pkgRegistry) {
    TypeDeclaration previousTypeDeclaration =
        kbuilder
            .getPackageRegistry(typeDescr.getNamespace())
            .getPackage()
            .getTypeDeclaration(typeDescr.getTypeName());

    try {
      // if there is no previous declaration, then the original declaration was a POJO
      // to the behavior previous these changes
      if (previousTypeDeclaration == null) {
        // new declarations of a POJO can't declare new fields,
        // except if the POJO was previously generated/compiled and saved into the kjar
        Class<?> existingDeclarationClass =
            TypeDeclarationUtils.getExistingDeclarationClass(typeDescr, pkgRegistry);
        if (!kbuilder.getBuilderConfiguration().isPreCompiled()
            && !GeneratedFact.class.isAssignableFrom(existingDeclarationClass)
            && !type.getTypeClassDef().getFields().isEmpty()) {
          try {
            Class existingClass =
                pkgRegistry
                    .getPackage()
                    .getTypeResolver()
                    .resolveType(typeDescr.getType().getFullName());
            ClassFieldInspector cfi = new ClassFieldInspector(existingClass);

            int fieldCount = 0;
            for (String existingFieldName : cfi.getFieldTypesField().keySet()) {
              if (!cfi.isNonGetter(existingFieldName)
                  && !"class".equals(existingFieldName)
                  && cfi.getSetterMethods().containsKey(existingFieldName)
                  && cfi.getGetterMethods().containsKey(existingFieldName)) {
                if (!typeDescr.getFields().containsKey(existingFieldName)) {
                  type.setValid(false);
                  kbuilder.addBuilderResult(
                      new TypeDeclarationError(
                          typeDescr,
                          "New declaration of "
                              + typeDescr.getType().getFullName()
                              + " does not include field "
                              + existingFieldName));
                } else {
                  String fldType = cfi.getFieldTypes().get(existingFieldName).getName();
                  fldType =
                      TypeDeclarationUtils.toBuildableType(fldType, kbuilder.getRootClassLoader());
                  TypeFieldDescr declaredField = typeDescr.getFields().get(existingFieldName);
                  if (!fldType.equals(
                      type.getTypeClassDef().getField(existingFieldName).getTypeName())) {
                    type.setValid(false);
                    kbuilder.addBuilderResult(
                        new TypeDeclarationError(
                            typeDescr,
                            "New declaration of "
                                + typeDescr.getType().getFullName()
                                + " redeclared field "
                                + existingFieldName
                                + " : \n"
                                + "existing : "
                                + fldType
                                + " vs declared : "
                                + declaredField.getPattern().getObjectType()));
                  } else {
                    fieldCount++;
                  }
                }
              }
            }

            if (fieldCount != typeDescr.getFields().size()) {
              kbuilder.addBuilderResult(reportDeclarationDiff(cfi, typeDescr));
            }
          } catch (IOException e) {
            e.printStackTrace();
            type.setValid(false);
            kbuilder.addBuilderResult(
                new TypeDeclarationError(
                    typeDescr,
                    "Unable to redeclare "
                        + typeDescr.getType().getFullName()
                        + " : "
                        + e.getMessage()));
          } catch (ClassNotFoundException e) {
            type.setValid(false);
            kbuilder.addBuilderResult(
                new TypeDeclarationError(
                    typeDescr,
                    "Unable to redeclare "
                        + typeDescr.getType().getFullName()
                        + " : "
                        + e.getMessage()));
          }
        }
      } else {

        int typeComparisonResult = this.compareTypeDeclarations(previousTypeDeclaration, type);

        if (typeComparisonResult < 0) {
          // oldDeclaration is "less" than newDeclaration -> error
          kbuilder.addBuilderResult(
              new TypeDeclarationError(
                  typeDescr,
                  typeDescr.getType().getFullName()
                      + " declares more fields than the already existing version"));
          type.setValid(false);
        } else if (typeComparisonResult > 0 && !type.getTypeClassDef().getFields().isEmpty()) {
          // oldDeclaration is "grater" than newDeclaration -> error
          kbuilder.addBuilderResult(
              new TypeDeclarationError(
                  typeDescr,
                  typeDescr.getType().getFullName()
                      + " declares less fields than the already existing version"));
          type.setValid(false);
        }

        // if they are "equal" -> no problem

        // in the case of a declaration, we need to copy all the
        // fields present in the previous declaration
        if (type.getNature() == TypeDeclaration.Nature.DECLARATION) {
          mergeTypeDeclarations(previousTypeDeclaration, type);
        }
      }

    } catch (IncompatibleClassChangeError error) {
      // if the types are incompatible -> error
      kbuilder.addBuilderResult(new TypeDeclarationError(typeDescr, error.getMessage()));
    }
  }