/** Returns the ClassMemberSpecification currently represented in this dialog. */
  public ClassMemberSpecification getClassMemberSpecification() {
    String name = nameTextField.getText();
    String type = typeTextField.getText();
    String arguments = argumentsTextField.getText();

    if (name.equals("") || name.equals("*")) {
      name = null;
    }

    if (type.equals("") || type.equals("*")) {
      type = null;
    }

    if (name != null || type != null) {
      if (isField) {
        if (type == null) {
          type = ClassConstants.EXTERNAL_TYPE_INT;
        }

        type = ClassUtil.internalType(type);
      } else {
        if (type == null) {
          type = ClassConstants.EXTERNAL_TYPE_VOID;
        }

        type = ClassUtil.internalMethodDescriptor(type, ListUtil.commaSeparatedList(arguments));
      }
    }

    ClassMemberSpecification classMemberSpecification =
        new ClassMemberSpecification(0, 0, name, type);

    // Also get the access radio button settings.
    getClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_PUBLIC, publicRadioButtons);
    getClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_PRIVATE, privateRadioButtons);
    getClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_PROTECTED, protectedRadioButtons);
    getClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_STATIC, staticRadioButtons);
    getClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_FINAL, finalRadioButtons);
    getClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_VOLATILE, volatileRadioButtons);
    getClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_TRANSIENT, transientRadioButtons);
    getClassMemberSpecificationRadioButtons(
        classMemberSpecification,
        ClassConstants.INTERNAL_ACC_SYNCHRONIZED,
        synchronizedRadioButtons);
    getClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_NATIVE, nativeRadioButtons);
    getClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_ABSTRACT, abstractRadioButtons);
    getClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_STRICT, strictRadioButtons);

    return classMemberSpecification;
  }
Beispiel #2
0
  @Test
  public void test() {

    Assert.assertTrue(ClassUtil.instantiate(Dummy.class.getCanonicalName(), Dummy.class) != null);

    Dummy dummy = ClassUtil.instantiate(Dummy.class.getCanonicalName(), Dummy.class);
    Assert.assertTrue(dummy instanceof Dummy);

    String dataXServerJson =
        "{\n"
            + "\t\"core\": {\n"
            + "\t\t\"dataXServer\": {\n"
            + "\t\t\t\"address\": \"http://localhost/test\",\n"
            + "\t\t\t\"timeout\": 5000\n"
            + "\t\t}\n"
            + "\t}\n"
            + "}";
    Assert.assertTrue(
        ClassUtil.instantiate(
                DummyContainer.class.getCanonicalName(),
                DummyContainer.class,
                Configuration.from(dataXServerJson))
            instanceof DummyContainer);

    Assert.assertTrue(
        ClassUtil.instantiate(
                DummyContainer.class.getCanonicalName(),
                DummyContainer.class,
                Configuration.from(dataXServerJson))
            instanceof DummyContainer);
  }
  public void visitProgramClass(ProgramClass programClass) {
    String name = programClass.getName();
    String newName = ClassObfuscator.newClassName(programClass);

    ps.println(
        ClassUtil.externalClassName(name) + " -> " + ClassUtil.externalClassName(newName) + ":");

    // Print out the class members.
    programClass.fieldsAccept(this);
    programClass.methodsAccept(this);
  }
 @SuppressWarnings("unchecked")
 public <T extends CatalogType> Histogram<T> buildHistogramForType(Class<T> search_key) {
   Histogram<T> h = new ObjectHistogram<T>();
   for (CatalogPair e : this) {
     if (ClassUtil.getSuperClasses(e.getFirst().getClass()).contains(search_key)) {
       h.put((T) e.getFirst());
     }
     if (ClassUtil.getSuperClasses(e.getSecond().getClass()).contains(search_key)) {
       h.put((T) e.getSecond());
     }
   } // FOR
   return (h);
 }
 @SuppressWarnings("unchecked")
 public <T extends CatalogType> Collection<T> findAllForType(Class<T> search_key) {
   List<T> found = new ArrayList<T>();
   for (CatalogPair e : this) {
     if (ClassUtil.getSuperClasses(e.getFirst().getClass()).contains(search_key)) {
       found.add((T) e.getFirst());
     }
     if (ClassUtil.getSuperClasses(e.getSecond().getClass()).contains(search_key)) {
       found.add((T) e.getSecond());
     }
   } // FOR
   return (found);
 }
Beispiel #6
0
  public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute) {
    //        DEBUG =
    //            clazz.getName().equals("abc/Def") &&
    //            method.getName(clazz).equals("abc");

    // The minimum variable size is determined by the arguments.
    codeAttribute.u2maxLocals =
        ClassUtil.internalMethodParameterSize(method.getDescriptor(clazz), method.getAccessFlags());

    if (DEBUG) {
      System.out.println(
          "VariableSizeUpdater: "
              + clazz.getName()
              + "."
              + method.getName(clazz)
              + method.getDescriptor(clazz));
      System.out.println("  Max locals: " + codeAttribute.u2maxLocals + " <- parameters");
    }

    // Go over all instructions.
    codeAttribute.instructionsAccept(clazz, method, this);

    // Remove the unused variables of the attributes.
    codeAttribute.attributesAccept(clazz, method, variableCleaner);
  }
  protected BeanPropertyWriter _constructVirtualProperty(
      JsonAppend.Prop prop, MapperConfig<?> config, AnnotatedClass ac) {
    PropertyMetadata metadata =
        prop.required() ? PropertyMetadata.STD_REQUIRED : PropertyMetadata.STD_OPTIONAL;
    PropertyName propName = _propertyName(prop.name(), prop.namespace());
    JavaType type = config.constructType(prop.type());
    // now, then, we need a placeholder for member (no real Field/Method):
    AnnotatedMember member =
        new VirtualAnnotatedMember(
            ac, ac.getRawType(), propName.getSimpleName(), type.getRawClass());
    // and with that and property definition
    SimpleBeanPropertyDefinition propDef =
        SimpleBeanPropertyDefinition.construct(config, member, propName, metadata, prop.include());

    Class<?> implClass = prop.value();

    HandlerInstantiator hi = config.getHandlerInstantiator();
    VirtualBeanPropertyWriter bpw =
        (hi == null) ? null : hi.virtualPropertyWriterInstance(config, implClass);
    if (bpw == null) {
      bpw =
          (VirtualBeanPropertyWriter)
              ClassUtil.createInstance(implClass, config.canOverrideAccessModifiers());
    }

    // one more thing: give it necessary contextual information
    return bpw.withConfig(config, ac, propDef, type);
  }
Beispiel #8
0
  /**
   * Initialize the backend systems, the log handler and the restrictor. A subclass can tune this
   * step by overriding {@link #createRestrictor(String)} and {@link
   * #createLogHandler(ServletConfig, boolean)}
   *
   * @param pServletConfig servlet configuration
   */
  @Override
  public void init(ServletConfig pServletConfig) throws ServletException {
    super.init(pServletConfig);

    Configuration config = initConfig(pServletConfig);

    // Create a log handler early in the lifecycle, but not too early
    String logHandlerClass = config.get(ConfigKey.LOGHANDLER_CLASS);
    logHandler =
        logHandlerClass != null
            ? (LogHandler) ClassUtil.newInstance(logHandlerClass)
            : createLogHandler(pServletConfig, Boolean.valueOf(config.get(ConfigKey.DEBUG)));

    // Different HTTP request handlers
    httpGetHandler = newGetHttpRequestHandler();
    httpPostHandler = newPostHttpRequestHandler();

    if (restrictor == null) {
      restrictor =
          createRestrictor(NetworkUtil.replaceExpression(config.get(ConfigKey.POLICY_LOCATION)));
    } else {
      logHandler.info("Using custom access restriction provided by " + restrictor);
    }
    configMimeType = config.get(ConfigKey.MIME_TYPE);
    backendManager = new BackendManager(config, logHandler, restrictor);
    requestHandler = new HttpRequestHandler(config, backendManager, logHandler);

    initDiscoveryMulticast(config);
  }
  /** Returns a shrunk descriptor or signature of the given method. */
  private String shrinkDescriptor(Method method, String descriptor) {
    // All parameters of non-static methods are shifted by one in the local
    // variable frame.
    int parameterIndex =
        (method.getAccessFlags() & ClassConstants.INTERNAL_ACC_STATIC) != 0 ? 0 : 1;

    // Go over the parameters.
    InternalTypeEnumeration internalTypeEnumeration = new InternalTypeEnumeration(descriptor);

    StringBuffer newDescriptorBuffer = new StringBuffer();

    newDescriptorBuffer.append(internalTypeEnumeration.formalTypeParameters());
    newDescriptorBuffer.append(ClassConstants.INTERNAL_METHOD_ARGUMENTS_OPEN);

    while (internalTypeEnumeration.hasMoreTypes()) {
      String type = internalTypeEnumeration.nextType();
      if (ParameterUsageMarker.isParameterUsed(method, parameterIndex)) {
        newDescriptorBuffer.append(type);
      } else if (DEBUG) {
        System.out.println("  Deleting parameter #" + parameterIndex + " [" + type + "]");
      }

      parameterIndex += ClassUtil.isInternalCategory2Type(type) ? 2 : 1;
    }

    newDescriptorBuffer.append(ClassConstants.INTERNAL_METHOD_ARGUMENTS_CLOSE);
    newDescriptorBuffer.append(internalTypeEnumeration.returnType());

    return newDescriptorBuffer.toString();
  }
 public void visitLibraryClass(LibraryClass libraryClass) {
   notePrinter.print(
       libraryClass.getName(),
       "Note: duplicate definition of library class ["
           + ClassUtil.externalClassName(libraryClass.getName())
           + "]");
 }
 public void visitProgramClass(ProgramClass programClass) {
   notePrinter.print(
       programClass.getName(),
       "Note: duplicate definition of program class ["
           + ClassUtil.externalClassName(programClass.getName())
           + "]");
 }
Beispiel #12
0
  /**
   * Marks the hierarchy of implementing or overriding methods corresponding to the given method, if
   * any.
   */
  protected void markMethodHierarchy(Clazz clazz, Method method) {
    int accessFlags = method.getAccessFlags();
    if ((accessFlags & (ClassConstants.ACC_PRIVATE | ClassConstants.ACC_STATIC)) == 0
        && !ClassUtil.isInitializer(method.getName(clazz))) {
      // We can skip private and static methods in the hierarchy, and
      // also abstract methods, unless they might widen a current
      // non-public access.
      int requiredUnsetAccessFlags =
          ClassConstants.ACC_PRIVATE
              | ClassConstants.ACC_STATIC
              | ((accessFlags & ClassConstants.ACC_PUBLIC) == 0 ? 0 : ClassConstants.ACC_ABSTRACT);

      clazz.accept(
          new ConcreteClassDownTraveler(
              new ClassHierarchyTraveler(
                  true,
                  true,
                  false,
                  true,
                  new NamedMethodVisitor(
                      method.getName(clazz),
                      method.getDescriptor(clazz),
                      new MemberAccessFilter(0, requiredUnsetAccessFlags, this)))));
    }
  }
Beispiel #13
0
  public void visitSignatureAttribute(Clazz clazz, SignatureAttribute signatureAttribute) {
    // Process the generic definitions, superclass, and implemented
    // interfaces.
    String signature = clazz.getString(signatureAttribute.u2signatureIndex);

    // Count the signature types.
    InternalTypeEnumeration internalTypeEnumeration = new InternalTypeEnumeration(signature);

    int count = 0;
    int interfacesCount = -1;
    while (internalTypeEnumeration.hasMoreTypes()) {
      String internalType = internalTypeEnumeration.nextType();

      count++;

      if (ClassUtil.isInternalClassType(internalType)) {
        interfacesCount++;
      }
    }

    // Put the signature types in an array.
    internalTypeEnumeration = new InternalTypeEnumeration(signature);

    String[] internalTypes = new String[count];

    for (int index = 0; index < count; index++) {
      String internalType = internalTypeEnumeration.nextType();

      internalTypes[index] = internalType;
    }

    // Sort the interface types in the array.
    Arrays.sort(internalTypes, count - interfacesCount, count);

    // Recompose the signature types in a string.
    StringBuffer newSignatureBuffer = new StringBuffer();

    for (int index = 0; index < count; index++) {
      // Is this not an interface type, or an interface type that isn't
      // a duplicate of the previous interface type?
      if (index < count - interfacesCount
          || !internalTypes[index].equals(internalTypes[index - 1])) {
        newSignatureBuffer.append(internalTypes[index]);
      }
    }

    String newSignature = newSignatureBuffer.toString();

    // Did the signature change?
    if (!newSignature.equals(signature)) {
      // Update the signature.
      ((Utf8Constant) ((ProgramClass) clazz).constantPool[signatureAttribute.u2signatureIndex])
          .setString(newSignatureBuffer.toString());

      // Clear the referenced classes.
      // TODO: Properly update the referenced classes.
      signatureAttribute.referencedClasses = null;
    }
  }
Beispiel #14
0
    @Test
    public void classWithSubInterface() {
      String interfaceName = SearchedInterface.class.getCanonicalName();

      Class<?> found = ClassUtil.searchInterface(ClassWithSubInterface.class, interfaceName);

      assertThat(SearchedInterface.class.equals(found), is(true));
    }
Beispiel #15
0
    @Test
    public void classWithSubInterfaceOther() {
      String interfaceName = "other";

      Class<?> found = ClassUtil.searchInterface(ClassWithSubInterface.class, interfaceName);

      assertThat(found, is(nullValue()));
    }
Beispiel #16
0
    @Test
    public void classWithoutSomeInterface() {
      String interfaceName = SearchedInterface.class.getCanonicalName();

      Class<?> found = ClassUtil.searchInterface(ClassWithSomeInterface.class, interfaceName);

      assertThat(found, is(nullValue()));
    }
Beispiel #17
0
    @Test
    public void superclassExtendsClassWithSearchedInterfaceOther() {
      String interfaceName = "other";

      Class<?> found =
          ClassUtil.searchInterface(
              SuperclassExtendsClassWithSearchedInterface.class, interfaceName);

      assertThat(found, is(nullValue()));
    }
  /** Shrinks the array of referenced classes of the given method. */
  private Clazz[] shrinkReferencedClasses(
      Method method, String descriptor, Clazz[] referencedClasses) {
    if (referencedClasses != null) {
      // All parameters of non-static methods are shifted by one in the local
      // variable frame.
      int parameterIndex =
          (method.getAccessFlags() & ClassConstants.INTERNAL_ACC_STATIC) != 0 ? 0 : 1;

      int referencedClassIndex = 0;
      int newReferencedClassIndex = 0;

      // Go over the parameters.
      InternalTypeEnumeration internalTypeEnumeration = new InternalTypeEnumeration(descriptor);

      // Also look at the formal type parameters.
      String type = internalTypeEnumeration.formalTypeParameters();
      int count = new DescriptorClassEnumeration(type).classCount();
      for (int counter = 0; counter < count; counter++) {
        referencedClasses[newReferencedClassIndex++] = referencedClasses[referencedClassIndex++];
      }

      while (internalTypeEnumeration.hasMoreTypes()) {
        // Consider the classes referenced by this parameter type.
        type = internalTypeEnumeration.nextType();
        count = new DescriptorClassEnumeration(type).classCount();

        if (ParameterUsageMarker.isParameterUsed(method, parameterIndex)) {
          // Copy the referenced classes.
          for (int counter = 0; counter < count; counter++) {
            referencedClasses[newReferencedClassIndex++] =
                referencedClasses[referencedClassIndex++];
          }
        } else {
          // Skip the referenced classes.
          referencedClassIndex += count;
        }

        parameterIndex += ClassUtil.isInternalCategory2Type(type) ? 2 : 1;
      }

      // Also look at the return value.
      type = internalTypeEnumeration.returnType();
      count = new DescriptorClassEnumeration(type).classCount();
      for (int counter = 0; counter < count; counter++) {
        referencedClasses[newReferencedClassIndex++] = referencedClasses[referencedClassIndex++];
      }

      // Clear the unused entries.
      while (newReferencedClassIndex < referencedClassIndex) {
        referencedClasses[newReferencedClassIndex++] = null;
      }
    }

    return referencedClasses;
  }
  /** Sets the ClassMemberSpecification to be represented in this dialog. */
  public void setClassMemberSpecification(ClassMemberSpecification classMemberSpecification) {
    String name = classMemberSpecification.name;
    String descriptor = classMemberSpecification.descriptor;

    // Set the access radio buttons.
    setClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_PUBLIC, publicRadioButtons);
    setClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_PRIVATE, privateRadioButtons);
    setClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_PROTECTED, protectedRadioButtons);
    setClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_STATIC, staticRadioButtons);
    setClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_FINAL, finalRadioButtons);
    setClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_VOLATILE, volatileRadioButtons);
    setClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_TRANSIENT, transientRadioButtons);
    setClassMemberSpecificationRadioButtons(
        classMemberSpecification,
        ClassConstants.INTERNAL_ACC_SYNCHRONIZED,
        synchronizedRadioButtons);
    setClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_NATIVE, nativeRadioButtons);
    setClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_ABSTRACT, abstractRadioButtons);
    setClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_STRICT, strictRadioButtons);

    // Set the class name text fields.
    nameTextField.setText(name == null ? "" : name);

    if (isField) {
      typeTextField.setText(descriptor == null ? "" : ClassUtil.externalType(descriptor));
    } else {
      typeTextField.setText(
          descriptor == null ? "" : ClassUtil.externalMethodReturnType(descriptor));
      argumentsTextField.setText(
          descriptor == null ? "" : ClassUtil.externalMethodArguments(descriptor));
    }
  }
 public static void main(String[] args) {
   /* LOG.debug("version: "+getVersion()) */
   LOG.version(getVersion()).tag("methodCall").debug();
   System.out.println("Hadoop " + getVersion());
   System.out.println("Subversion " + getUrl() + " -r " + getRevision());
   System.out.println("Compiled by " + getUser() + " on " + getDate());
   System.out.println("Compiled with protoc " + getProtocVersion());
   System.out.println("From source with checksum " + getSrcChecksum());
   System.out.println(
       "This command was run using " + ClassUtil.findContainingJar(VersionInfo.class));
 }
Beispiel #21
0
 /** 通过反射创建实例 */
 @SuppressWarnings("unchecked")
 public static <T> T newInstance(String className) {
   T instance;
   try {
     Class<?> commandClass = ClassUtil.loadClass(className);
     instance = (T) commandClass.newInstance();
   } catch (Exception e) {
     logger.error("创建实例出错!", e);
     throw new RuntimeException(e);
   }
   return instance;
 }
 private Analyzer getLuceneAnalyzer() throws ProviderException {
   try {
     Class clazz = ClassUtil.findClass("", m_analyzerClass);
     Constructor constructor = clazz.getConstructor(Version.LUCENE_36.getClass());
     Analyzer analyzer = (Analyzer) constructor.newInstance(Version.LUCENE_36);
     return analyzer;
   } catch (Exception e) {
     String msg = "Could not get LuceneAnalyzer class " + m_analyzerClass + ", reason: ";
     log.error(msg, e);
     throw new ProviderException(msg + e);
   }
 }
Beispiel #23
0
  public List<ClassMetadata> execute() {
    ExecutorService threadPool = newThreadPool();

    List<File> classes = ClassUtil.find(targetClasses);
    List<ClassMetadata> processed = rewriteComponents(classes, threadPool);
    rewriteFieldAccess(classes, packedFieldAccess(processed));
    rewriteProfilers(classes);

    if (ClassMetadata.GlobalConfiguration.optimizeEntitySystems) rewriteEntitySystems(classes);

    return processed;
  }
 public void visitProgramField(ProgramClass programClass, ProgramField programField) {
   String newName = MemberObfuscator.newMemberName(programField);
   if (newName != null) {
     ps.println(
         "    "
             +
             // lineNumberRange(programClass, programField) +
             ClassUtil.externalFullFieldDescription(
                 0, programField.getName(programClass), programField.getDescriptor(programClass))
             + " -> "
             + newName);
   }
 }
Beispiel #25
0
 /**
  * 将sql中问号替换成实际值
  *
  * @param sql select * from a where name=?
  * @param paramValues
  * @return
  */
 public static String formatSql(final String sql, final Object[] paramValues) {
   String fsql = sql;
   for (Object value : paramValues) {
     String tmp = fsql;
     fsql = StringUtils.substringBefore(tmp, "?");
     if (value instanceof String) {
       fsql += "'" + value + "'";
     } else {
       fsql += ClassUtil.convertValueToString(value);
     }
     fsql += StringUtils.substringAfter(tmp, "?");
   }
   return fsql;
 }
Beispiel #26
0
  public void read(DataEntry dataEntry) throws IOException {
    try {
      // Get the input stream.
      InputStream inputStream = dataEntry.getInputStream();

      // Wrap it into a data input stream.
      DataInputStream dataInputStream = new DataInputStream(inputStream);

      // Create a Clazz representation.
      Clazz clazz;
      if (isLibrary) {
        clazz = new LibraryClass();
        clazz.accept(
            new LibraryClassReader(
                dataInputStream, skipNonPublicLibraryClasses, skipNonPublicLibraryClassMembers));
      } else {
        clazz = new ProgramClass();
        clazz.accept(new ProgramClassReader(dataInputStream));
      }

      // Apply the visitor, if we have a real class.
      String className = clazz.getName();
      if (className != null) {
        if (!dataEntry
                .getName()
                .replace(File.pathSeparatorChar, ClassConstants.PACKAGE_SEPARATOR)
                .equals(className + ClassConstants.CLASS_FILE_EXTENSION)
            && warningPrinter != null) {
          warningPrinter.print(
              className,
              "Warning: class ["
                  + dataEntry.getName()
                  + "] unexpectedly contains class ["
                  + ClassUtil.externalClassName(className)
                  + "]");
        }

        clazz.accept(classVisitor);
      }

      dataEntry.closeInputStream();
    } catch (Exception ex) {
      throw (IOException)
          new IOException(
                  "Can't process class [" + dataEntry.getName() + "] (" + ex.getMessage() + ")")
              .initCause(ex);
    }
  }
  /*
   * (non-Javadoc)
   *
   * @see java.util.concurrent.Callable#call()
   */
  public AnnotationInfo call() throws Exception {
    Field riakKeyField = null;
    Field riakVClockField = null;
    Field usermetaMapField = null;
    Field linksField = null;
    List<UsermetaField> usermetaItemFields = new ArrayList<UsermetaField>();
    List<RiakIndexField> indexFields = new ArrayList<RiakIndexField>();

    final Field[] fields = classToScan.getDeclaredFields();

    for (Field field : fields) {

      if (field.isAnnotationPresent(RiakKey.class)) {

        riakKeyField = ClassUtil.checkAndFixAccess(field);
      }

      if (field.isAnnotationPresent(RiakVClock.class)) {

        // restrict the field type to byte[] or VClock
        if (!(field.getType().isArray() && field.getType().getComponentType().equals(byte.class))
            && !field.getType().isAssignableFrom(VClock.class)) {
          throw new IllegalArgumentException(field.getType().toString());
        }

        riakVClockField = ClassUtil.checkAndFixAccess(field);
      }

      if (field.isAnnotationPresent(RiakUsermeta.class)) {
        RiakUsermeta a = field.getAnnotation(RiakUsermeta.class);
        String key = a.key();

        if (!"".equals(key)) {
          usermetaItemFields.add(new UsermetaField(ClassUtil.checkAndFixAccess(field)));
        } else {
          usermetaMapField = ClassUtil.checkAndFixAccess(field);
        }
      }

      if (field.isAnnotationPresent(RiakIndex.class)) {
        indexFields.add(new RiakIndexField(ClassUtil.checkAndFixAccess(field)));
      }

      if (field.isAnnotationPresent(RiakLinks.class)) {
        linksField = ClassUtil.checkAndFixAccess(field);
      }
    }
    return new AnnotationInfo(
        riakKeyField,
        usermetaItemFields,
        usermetaMapField,
        indexFields,
        linksField,
        riakVClockField);
  }
Beispiel #28
0
  /**
   * Marks the hierarchy of implementing or overriding methods corresponding to the given method, if
   * any.
   */
  protected void markMethodHierarchy(Clazz clazz, Method method) {
    int accessFlags = method.getAccessFlags();
    if ((accessFlags & (ClassConstants.ACC_PRIVATE | ClassConstants.ACC_STATIC)) == 0
        && !ClassUtil.isInitializer(method.getName(clazz))) {
      // We can skip private and static methods in the hierarchy, and
      // also abstract methods, unless they might widen a current
      // non-public access.
      int requiredUnsetAccessFlags =
          ClassConstants.ACC_PRIVATE
              | ClassConstants.ACC_STATIC
              | ((accessFlags & ClassConstants.ACC_PUBLIC) == 0 ? 0 : ClassConstants.ACC_ABSTRACT);

      // Mark default implementations in interfaces down the hierarchy.
      // TODO: This may be premature if there aren't any concrete implementing classes.
      clazz.accept(
          new ClassAccessFilter(
              ClassConstants.ACC_ABSTRACT,
              0,
              new ClassHierarchyTraveler(
                  false,
                  false,
                  false,
                  true,
                  new ProgramClassFilter(
                      new ClassAccessFilter(
                          ClassConstants.ACC_ABSTRACT,
                          0,
                          new NamedMethodVisitor(
                              method.getName(clazz),
                              method.getDescriptor(clazz),
                              new MemberAccessFilter(
                                  0, requiredUnsetAccessFlags, defaultMethodUsageMarker)))))));

      // Mark other implementations.
      clazz.accept(
          new ConcreteClassDownTraveler(
              new ClassHierarchyTraveler(
                  true,
                  true,
                  false,
                  true,
                  new NamedMethodVisitor(
                      method.getName(clazz),
                      method.getDescriptor(clazz),
                      new MemberAccessFilter(0, requiredUnsetAccessFlags, this)))));
    }
  }
Beispiel #29
0
 @SuppressWarnings({"rawtypes", "unchecked"})
 public static <T> Map entityToMap(T t) {
   Map map = new HashMap<String, Object>();
   if (ObjectUtil.isNull(t)) {
     return ObjectUtil.getNull();
   }
   List<Field> listField = ClassUtil.listField(t.getClass());
   try {
     for (Field field : listField) {
       field.setAccessible(true);
       map.put(field.getName(), field.get(t));
     }
   } catch (IllegalArgumentException e) {
   } catch (IllegalAccessException e) {
   }
   return map;
 }
Beispiel #30
0
  public static void main(String[] args) {
    ExecutorService threadPool = newThreadPool();
    List<ClassMetadata> processed = new ArrayList<ClassMetadata>();
    if (args.length == 0) {
      for (File f : ClassUtil.find(".")) {
        processClass(threadPool, f.getAbsolutePath(), processed);
      }
    } else {
      for (String arg : args) {
        // eclipse sends folders along too
        if (arg.endsWith(".class")) processClass(threadPool, arg, processed);
      }
    }
    awaitTermination(threadPool);

    //		rewriteFieldAccess(packedFieldAccess(processed));
  }