Esempio n. 1
0
  private Type getMirrorType(final Type type) {
    int numDimensions = 0;
    final Type basicType;

    if (type.getSort() == Type.ARRAY) {
      numDimensions = type.getDimensions();
      basicType = type.getElementType();
    } else {
      basicType = type;
    }

    if (basicType.getSort() != Type.OBJECT) {
      return type;
    }

    final Mirror mirror = getMirror(basicType.getInternalName());

    if (mirror.isClassMirror()) {
      final StringBuilder name = new StringBuilder();

      for (int i = 0; i < numDimensions; ++i) {
        name.append('[');
      }
      name.append('L').append(mirror.getTranslatedName()).append(';');

      return Type.getType(name.toString());
    }

    return type;
  }
 private ClassMetadata getClassMetadata(
     ClassMetadataResolver resolver, Type type, boolean ignoreArray) {
   if (type.getSort() == Type.ARRAY) {
     return resolver.resolve(
         type.getElementType().getClassName(), ignoreArray ? 0 : type.getDimensions());
   } else {
     return resolver.resolve(type.getClassName(), 0);
   }
 }
Esempio n. 3
0
 private void addType(final Type t) {
   switch (t.getSort()) {
     case Type.ARRAY:
       addType(t.getElementType());
       break;
     case Type.OBJECT:
       addName(t.getClassName().replace('.', '/'));
       break;
   }
 }
Esempio n. 4
0
 private void addType(Type t) {
   switch (t.getSort()) {
     case Type.ARRAY:
       addType(t.getElementType());
       break;
     case Type.OBJECT:
       addName(t.getInternalName());
       break;
   }
 }
 /**
  * Inspects the given type recursively and add it as outgoing reference if necessary
  *
  * @param type Referenced type
  */
 private void inspectType(Type type) {
   switch (type.getSort()) {
     case Type.ARRAY:
       inspectType(type.getElementType());
       break;
     case Type.OBJECT:
       String typeName = refactor(type.getClassName());
       checkReference(typeName);
       break;
   }
 }
 private void addType(final Type type) {
   switch (type.getSort()) {
     case Type.ARRAY:
       addType(type.getElementType());
       break;
     case Type.OBJECT:
       addPackage(type.getInternalName());
       break;
     case Type.METHOD:
       addMethodTypes(type.getDescriptor());
       break;
   }
 }
 void addType(final Type t) {
   switch (t.getSort()) {
     case Type.ARRAY:
       addType(t.getElementType());
       break;
     case Type.OBJECT:
       addName(t.getInternalName());
       break;
     case Type.METHOD:
       addMethodDesc(t.getDescriptor());
       break;
   }
 }
Esempio n. 8
0
 private String getDescriptor(Type type) {
   if (type.getSort() == Type.OBJECT) {
     String name = type.getInternalName();
     int index = name.lastIndexOf('/');
     return name.substring(index + 1);
   }
   if (type.getSort() == Type.ARRAY) {
     StringBuilder sb = new StringBuilder(getDescriptor(type.getElementType()));
     for (int dim = type.getDimensions(); dim > 0; --dim) {
       sb.append("[]");
     }
     return sb.toString();
   }
   return type.getClassName();
 }
Esempio n. 9
0
  private static boolean appendTypeName(StringBuilder tpl, Type type, String sourceClass) {
    switch (type.getSort()) {
      case Type.BOOLEAN:
        tpl.append("boolean");
        return false;
      case Type.CHAR:
        tpl.append("char");
        return false;
      case Type.BYTE:
        tpl.append("byte");
        return false;
      case Type.SHORT:
        tpl.append("short");
        return false;
      case Type.INT:
        tpl.append("int");
        return false;
      case Type.FLOAT:
        tpl.append("float");
        return false;
      case Type.LONG:
        tpl.append("long");
        return false;
      case Type.DOUBLE:
        tpl.append("double");
        return false;
      case Type.ARRAY:
        EventProxy.appendTypeName(tpl, type.getElementType(), sourceClass);
        return true;
      case Type.OBJECT:
        String typeName = type.getClassName();
        typeName = typeName.substring(typeName.lastIndexOf('.') + 1);
        tpl.append(typeName);
        if (typeName.endsWith("ReturnEventInfo"))
          tpl.append('<').append(sourceClass).append(", ?>");
        else if (typeName.endsWith("EventInfo")) tpl.append('<').append(sourceClass).append('>');
        return false;
    }

    tpl.append("Object");

    return false;
  }
Esempio n. 10
0
 public JavaType convertAsmType(org.objectweb.asm.Type asmType) {
   JavaType result;
   switch (asmType.getSort()) {
     case org.objectweb.asm.Type.OBJECT:
       result = getClassSymbol(asmType.getInternalName()).type;
       break;
     case org.objectweb.asm.Type.BYTE:
       result = symbols.byteType;
       break;
     case org.objectweb.asm.Type.CHAR:
       result = symbols.charType;
       break;
     case org.objectweb.asm.Type.SHORT:
       result = symbols.shortType;
       break;
     case org.objectweb.asm.Type.INT:
       result = symbols.intType;
       break;
     case org.objectweb.asm.Type.LONG:
       result = symbols.longType;
       break;
     case org.objectweb.asm.Type.FLOAT:
       result = symbols.floatType;
       break;
     case org.objectweb.asm.Type.DOUBLE:
       result = symbols.doubleType;
       break;
     case org.objectweb.asm.Type.BOOLEAN:
       result = symbols.booleanType;
       break;
     case org.objectweb.asm.Type.ARRAY:
       result = new ArrayJavaType(convertAsmType(asmType.getElementType()), symbols.arrayClass);
       break;
     case org.objectweb.asm.Type.VOID:
       result = symbols.voidType;
       break;
     default:
       throw new IllegalArgumentException(asmType.toString());
   }
   return result;
 }
Esempio n. 11
0
    private void addConventionGetter(String getterName, String flagName, MetaBeanProperty property)
        throws Exception {
      // GENERATE public <type> <getter>() { return
      // (<type>)getConventionMapping().getConventionValue(super.<getter>(), '<prop>', <prop>Set); }
      MetaMethod getter = property.getGetter();

      Type returnType = Type.getType(getter.getReturnType());
      String methodDescriptor = Type.getMethodDescriptor(returnType, new Type[0]);
      MethodVisitor methodVisitor =
          visitor.visitMethod(
              Opcodes.ACC_PUBLIC, getterName, methodDescriptor, null, new String[0]);
      methodVisitor.visitCode();

      methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
      methodVisitor.visitMethodInsn(
          Opcodes.INVOKEINTERFACE,
          conventionAwareType.getInternalName(),
          "getConventionMapping",
          Type.getMethodDescriptor(conventionMappingType, new Type[0]));

      methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
      methodVisitor.visitMethodInsn(
          Opcodes.INVOKESPECIAL, superclassType.getInternalName(), getterName, methodDescriptor);

      Type boxedType = null;
      if (getter.getReturnType().isPrimitive()) {
        // Box value
        boxedType =
            Type.getType(JavaReflectionUtil.getWrapperTypeForPrimitiveType(getter.getReturnType()));
        String valueOfMethodDescriptor =
            Type.getMethodDescriptor(boxedType, new Type[] {returnType});
        methodVisitor.visitMethodInsn(
            Opcodes.INVOKESTATIC, boxedType.getInternalName(), "valueOf", valueOfMethodDescriptor);
      }

      methodVisitor.visitLdcInsn(property.getName());

      methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
      methodVisitor.visitFieldInsn(
          Opcodes.GETFIELD,
          generatedType.getInternalName(),
          flagName,
          Type.BOOLEAN_TYPE.getDescriptor());

      String getConventionValueDesc =
          Type.getMethodDescriptor(
              ConventionMapping.class.getMethod(
                  "getConventionValue", Object.class, String.class, Boolean.TYPE));
      methodVisitor.visitMethodInsn(
          Opcodes.INVOKEINTERFACE,
          conventionMappingType.getInternalName(),
          "getConventionValue",
          getConventionValueDesc);

      if (getter.getReturnType().isPrimitive()) {
        // Unbox value
        methodVisitor.visitTypeInsn(Opcodes.CHECKCAST, boxedType.getInternalName());
        String valueMethodDescriptor = Type.getMethodDescriptor(returnType, new Type[0]);
        methodVisitor.visitMethodInsn(
            Opcodes.INVOKEVIRTUAL,
            boxedType.getInternalName(),
            getter.getReturnType().getName() + "Value",
            valueMethodDescriptor);
      } else {
        // Cast to return type
        methodVisitor.visitTypeInsn(
            Opcodes.CHECKCAST,
            getter.getReturnType().isArray()
                ? "[" + returnType.getElementType().getDescriptor()
                : returnType.getInternalName());
      }

      methodVisitor.visitInsn(returnType.getOpcode(Opcodes.IRETURN));
      methodVisitor.visitMaxs(0, 0);
      methodVisitor.visitEnd();
    }