Esempio n. 1
0
  @Override
  public final void visit(String name, Object value) {
    if (value == null) throw new Error();

    Type type;
    if (value.getClass().equals(String.class)) {
      type = Type.getType(String.class);
    } else if (value.getClass().equals(Boolean.class)) {
      type = Type.BOOLEAN_TYPE;
    } else if (value.getClass().equals(Integer.class)) {
      type = Type.INT_TYPE;
    } else if (value.getClass().equals(Long.class)) {
      type = Type.LONG_TYPE;
    } else if (value.getClass().equals(Type.class)) {
      type = Type.getType(Class.class);
    } else {
      throw new Error("name=" + name + " value=" + value + " " + value.getClass());
    }

    if (name == null) {
      anon(type, value);
    } else {
      add(name, new AnnotationValue(type, value));
    }
  }
Esempio n. 2
0
  private static byte[] visitEnd() {
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    cw.visit(Opcodes.V1_1, Opcodes.ACC_PUBLIC, RubyIDClassName, null, "java/lang/Object", null);
    Method staticBlock = Method.getMethod("void <clinit> ()V");
    GeneratorAdapter staticBlockMg =
        new GeneratorAdapter(Opcodes.ACC_STATIC, staticBlock, null, null, cw);

    for (Map.Entry<String, String> e : idMap.entrySet()) {
      cw.visitField(
          Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC,
          e.getValue(),
          Types.RUBY_ID_TYPE.getDescriptor(),
          null,
          null);

      staticBlockMg.push(e.getKey());
      staticBlockMg.invokeStatic(
          Type.getType(RubyID.class),
          Method.getMethod("com.xruby.runtime.lang.RubyID intern(String)"));
      staticBlockMg.putStatic(
          Type.getType("L" + RubyIDClassName + ";"), e.getValue(), Types.RUBY_ID_TYPE);
    }

    staticBlockMg.returnValue();
    staticBlockMg.endMethod();
    cw.visitEnd();

    return cw.toByteArray();
  }
    public void addSetMethod(MetaBeanProperty property) throws Exception {
      MetaMethod setter = property.getSetter();
      Type paramType = Type.getType(setter.getParameterTypes()[0].getTheClass());
      Type returnType = Type.getType(setter.getReturnType());
      String setterDescriptor = Type.getMethodDescriptor(returnType, new Type[] {paramType});

      // GENERATE public void <propName>(<type> v) { <setter>(v) }
      String setMethodDescriptor = Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {paramType});
      MethodVisitor methodVisitor =
          visitor.visitMethod(
              Opcodes.ACC_PUBLIC, property.getName(), setMethodDescriptor, null, new String[0]);
      methodVisitor.visitCode();

      // GENERATE <setter>(v)

      methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
      methodVisitor.visitVarInsn(paramType.getOpcode(Opcodes.ILOAD), 1);

      methodVisitor.visitMethodInsn(
          Opcodes.INVOKEVIRTUAL,
          generatedType.getInternalName(),
          setter.getName(),
          setterDescriptor);

      // END

      methodVisitor.visitInsn(Opcodes.RETURN);
      methodVisitor.visitMaxs(0, 0);
      methodVisitor.visitEnd();
    }
  public JvmObjectConstant(Object constant) {
    super(
        constant == null
            ? null
            : constant instanceof Integer
                ? Type.INT_TYPE
                : constant instanceof Long
                    ? Type.LONG_TYPE
                    : constant instanceof Float
                        ? Type.FLOAT_TYPE
                        : constant instanceof Double
                            ? Type.DOUBLE_TYPE
                            : constant instanceof Byte
                                ? Type.BYTE_TYPE
                                : constant instanceof Short
                                    ? Type.SHORT_TYPE
                                    : constant instanceof Character
                                        ? Type.CHAR_TYPE
                                        : constant instanceof String
                                            ? Type.getType(String.class)
                                            : constant instanceof Type
                                                ? Type.getType(Class.class)
                                                : null);

    this.constant = constant;
  }
  public void insertInvokeSpecialForMockedSuperclass(MethodCallReplacementMethodAdapter mv) {
    int numArguments = Type.getArgumentTypes(replacementDesc).length;
    mv.push(numArguments);
    mv.newArray(Type.getType(Object.class));
    for (int i = 0; i < numArguments; i++) {
      // param, array
      mv.dupX1(); // array, param, array
      mv.swap(); // array, array, param
      mv.push(numArguments - i - 1); // array, array, param, index
      mv.swap(); // array, array, index, param
      mv.arrayStore(Type.getType(Object.class));
      // array
    }
    mv.push(methodName);
    mv.push(desc);
    Method invokeSpecialMethod = InvokeSpecialMock.class.getDeclaredMethods()[0];

    mv.visitMethodInsn(
        Opcodes.INVOKESTATIC,
        InvokeSpecialMock.class.getCanonicalName().replace('.', '/'),
        "invokeSpecial",
        Type.getMethodDescriptor(invokeSpecialMethod),
        false);

    if (Type.getReturnType(desc).equals(Type.VOID_TYPE)) {
      mv.pop();
    } else {
      mv.visitTypeInsn(Opcodes.CHECKCAST, Type.getReturnType(desc).getInternalName());
    }
  }
    private ClassBuilderImpl(Class<T> type) {
      this.type = type;

      visitor = new ClassWriter(ClassWriter.COMPUTE_MAXS);
      typeName = type.getName() + "_Decorated";
      generatedType = Type.getType("L" + typeName.replaceAll("\\.", "/") + ";");
      superclassType = Type.getType(type);
    }
Esempio n. 7
0
 @Override
 public final void visitEnum(String name, String desc, String value) {
   if (name == null) {
     anon(Type.getType(desc), value);
     return;
   }
   add(name, new AnnotationValue(Type.getType(desc), value));
 }
Esempio n. 8
0
 /**
  * Transforms the given method type into a stack manipulation that loads its type onto the operand
  * stack.
  *
  * @param methodType The method type that should be loaded onto the operand stack.
  * @return A stack manipulation that loads the given method type.
  */
 public static StackManipulation of(JavaInstance.MethodType methodType) {
   Type[] parameterType = new Type[methodType.getParameterTypes().size()];
   int index = 0;
   for (TypeDescription typeDescription : methodType.getParameterTypes()) {
     parameterType[index++] = Type.getType(typeDescription.getDescriptor());
   }
   return new MethodTypeConstant(
       Type.getMethodType(
           Type.getType(methodType.getReturnType().getDescriptor()), parameterType));
 }
      /** @see org.objectweb.asm.MethodVisitor#visitFieldInsn(int, String, String, String) */
      public void visitFieldInsn(int opcode, String owner, String name, String descriptor) {
        if (owner.charAt(0) == '[') {
          Type type = Type.getType(owner);
          inspectType(type);
        } else {
          String typeName = refactor(owner.replace('/', '.'));
          checkReference(typeName);
        }

        inspectType(Type.getType(descriptor));
      }
Esempio n. 10
0
  @SuppressWarnings("unchecked")
  protected void onMethodEnter() {
    try {
      Class wd = Wustendorf.class;
      if (hook == HOOK_LIGHT_OVERRIDE
          || hook == HOOK_LIGHT_DISPLAY
          || hook == HOOK_LIGHT_OVERRIDE_CACHE
          || hook == HOOK_LIGHT_DISPLAY_CACHE) {
        /* We're writing this code:
        int override = wustendorf.Wustendorf.overrideSkyLight(this, par2, par3, par4);
        if (override != -1) {
            return override;
        }
        */
        loadThis(); // this

        if (hook == HOOK_LIGHT_OVERRIDE_CACHE || hook == HOOK_LIGHT_DISPLAY_CACHE) {
          getField(
              Type.getType("L%conf:OBF_CHUNK_CACHE%;"),
              "%conf:OBF_CHUNK_CACHE_WORLD%",
              Type.getType("L%conf:OBF_WORLD%;"));
        }
        loadArgs(0, 3); // our own arguments 1-3

        // Ask Wustendorf if it has an override.
        String world = "%conf:OBF_WORLD%";
        if (hook == HOOK_LIGHT_OVERRIDE || hook == HOOK_LIGHT_OVERRIDE_CACHE) {
          invokeStatic(Type.getType(wd), new Method("overrideLight", "(L" + world + ";III)I"));
        } else { // if (hook == HOOK_LIGHT_DISPLAY) {
          invokeStatic(
              Type.getType(wd), new Method("overrideLightDisplay", "(L" + world + ";III)I"));
        }

        dup(); // Duplicate the return value.
        Label keep_going = new Label();
        visitJumpInsn(Opcodes.IFLT, keep_going); // If the override set
        returnValue(); // Use it.
        visitLabel(keep_going); // Otherwise, keep going
        pop(); // (and nix the copy)
      } else if (hook == HOOK_CONSIDER_KILL) {
        /* We're writing this code:
        wustendorf.Wustendorf.considerKillingCritter(this);
        */
        loadThis(); // this

        String entityliving = "%conf:OBF_ENTITY_LIVING%";
        invokeStatic(
            Type.getType(wd), new Method("considerKillingCritter", "(L" + entityliving + ";)V"));
      }
    } catch (Exception e) {
      System.out.println("Wustendorf: HOOK FAILED!");
      e.printStackTrace();
    }
  }
  // the overload of type Object for Groovy coercions:  public void setFoo(Object foo)
  private void createTypeConvertingSetter(
      ClassVisitor visitor, Type generatedType, ModelProperty<?> property) {
    if (!property.isWritable() || !(property.getSchema() instanceof ScalarValueSchema)) {
      return;
    }

    Class<?> propertyClass = property.getType().getConcreteClass();
    Type propertyType = Type.getType(propertyClass);
    Class<?> boxedClass =
        propertyClass.isPrimitive() ? BOXED_TYPES.get(propertyClass) : propertyClass;
    Type boxedType = Type.getType(boxedClass);

    Method setter = property.getSetter().getMethod();
    MethodVisitor methodVisitor =
        declareMethod(
            visitor,
            setter.getName(),
            SET_OBJECT_PROPERTY_DESCRIPTOR,
            SET_OBJECT_PROPERTY_DESCRIPTOR);

    putThisOnStack(methodVisitor);
    putTypeConverterFieldValueOnStack(methodVisitor, generatedType);

    // Object converted = $typeConverter.convert(foo, Float.class, false);
    methodVisitor.visitVarInsn(ALOAD, 1); // put var #1 ('foo') on the stack
    methodVisitor.visitLdcInsn(boxedType); // push the constant Class onto the stack
    methodVisitor.visitInsn(
        propertyClass.isPrimitive()
            ? ICONST_1
            : ICONST_0); // push int 1 or 0 (interpreted as true or false) onto the stack
    methodVisitor.visitMethodInsn(
        INVOKEINTERFACE,
        TYPE_CONVERTER_TYPE.getInternalName(),
        "convert",
        COERCE_TO_SCALAR_DESCRIPTOR,
        true);
    methodVisitor.visitTypeInsn(CHECKCAST, boxedType.getInternalName());

    if (propertyClass.isPrimitive()) {
      unboxType(methodVisitor, propertyClass);
    }

    // invoke the typed setter, popping 'this' and 'converted' from the stack
    methodVisitor.visitMethodInsn(
        INVOKEVIRTUAL,
        generatedType.getInternalName(),
        setter.getName(),
        Type.getMethodDescriptor(Type.VOID_TYPE, propertyType),
        false);
    finishVisitingMethod(methodVisitor);
  }
  public void visitFunctionDeclaration(FunctionDeclarationContext function) {
    symbolTable.newScope();

    Function f = buildFunction(function);
    returnType = f.getReturnValueType();

    f.getArguments().stream().forEach(symbolTable::defineVariable);
    Type[] argTypes =
        f.getArguments()
            .stream()
            .flatMap(variable -> Stream.of(variable.getValueType().toAsmType()))
            .toArray(Type[]::new);
    String descriptor = Type.getMethodDescriptor(f.getReturnValueType().toAsmType(), argTypes);
    if ("main".equals(f.getName())) {
      if (!f.getArguments().isEmpty()) {
        throw new GenerationException("Main function must have zero arguments");
      }
      descriptor = Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(String[].class));
    }
    method = writer.visitMethod(ACC_PUBLIC | ACC_STATIC, f.getName(), descriptor, null, null);

    BlockContext block = function.functionBody().block();
    visitBlock(block);
    checkReturn(block);

    method.visitMaxs(0, 0);
    method.visitEnd();

    symbolTable.dropScope();
  }
  /**
   * Gets string that contains rule types (parameters types and return type).
   *
   * @param ruleInfo rule info
   * @return string with rule types
   */
  private static String getMethodTypes(RuleInfo ruleInfo) {

    Class<?> returnType = ruleInfo.getReturnType();
    Class<?>[] paramTypes = ruleInfo.getParamTypes();

    StringBuilder builder = new StringBuilder("(");

    for (int i = 0; i < paramTypes.length; i++) {
      builder.append(Type.getType(paramTypes[i]));
    }

    builder.append(")");
    builder.append(Type.getType(returnType));

    return builder.toString();
  }
Esempio n. 14
0
  /** {@inheritDoc} */
  @Override
  public List<Mutation> apply(
      MethodNode mn,
      String className,
      String methodName,
      BytecodeInstruction instruction,
      Frame frame) {
    List<Mutation> mutations = new LinkedList<Mutation>();

    FieldInsnNode node = (FieldInsnNode) instruction.getASMNode();
    Type fieldType = Type.getType(node.desc);

    // insert mutation into bytecode with conditional
    InsnList mutation = new InsnList();
    logger.debug("Mutation deletefield for statement " + node.name + node.desc);
    if (node.getOpcode() == Opcodes.GETFIELD) {
      logger.debug("Deleting source of type " + node.owner);
      mutation.add(new InsnNode(Opcodes.POP));
    }
    mutation.add(getDefault(fieldType));
    // insert mutation into pool
    Mutation mutationObject =
        MutationPool.addMutation(
            className,
            methodName,
            NAME + " " + node.name + node.desc,
            instruction,
            mutation,
            getInfectionDistance(node, mutation));

    mutations.add(mutationObject);
    return mutations;
  }
Esempio n. 15
0
  private void generateAccessor(
      ClassWriter cw,
      Class<?> parentType,
      String internalName,
      Property<Class<?>, Method> property) {
    Method accessor = property.getAccessor();

    MethodVisitor mv =
        cw.visitMethod(
            ACC_PUBLIC, accessor.getName(), Type.getMethodDescriptor(accessor), null, null);
    mv.visitCode();
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(
        GETFIELD,
        internalName,
        property.getName(),
        Type.getDescriptor(property.getLeastSpecificType()));

    if (!property.isLeastSpecificType()) {
      mv.visitTypeInsn(CHECKCAST, Type.getInternalName(property.getType()));
    }
    mv.visitInsn(Type.getType(property.getType()).getOpcode(IRETURN));
    mv.visitMaxs(0, 0);
    mv.visitEnd();
  }
Esempio n. 16
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;
  }
Esempio n. 17
0
 public Param(String typeDesc) {
   loadInstruction = Opcodes.ALOAD;
   storeInstruction = Opcodes.ASTORE;
   typeId = TypeIdMap.TYPEID_OBJECT;
   t = Type.getType(typeDesc);
   assert t.getDescriptor().equals(typeDesc);
 }
  protected String printTypeInsnNode(TypeInsnNode tin) {
    try {
      String desc = tin.desc;
      try {
        if (Type.getType(tin.desc) != null) desc = Type.getType(tin.desc).getClassName();

        if (desc == null || desc.equals("null")) desc = tin.desc;
      } catch (java.lang.ArrayIndexOutOfBoundsException e) {

      }
      return nameOpcode(tin.opcode()) + " " + desc;
    } catch (Exception e) {
      new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
    }
    return "//error";
  }
Esempio n. 19
0
      /** @see org.objectweb.asm.AnnotationVisitor#visitEnum(String, String, String) */
      public void visitEnum(String name, String descriptor, String value) {
        Type type = Type.getType(descriptor);

        if (type != null) {
          inspectType(type);
        }
      }
  private void writeSetter(ClassVisitor visitor, Type generatedType, ModelProperty<?> property) {
    WeaklyTypeReferencingMethod<?, Void> weakSetter = property.getSetter();
    // There is no setter for this property
    if (weakSetter == null) {
      return;
    }

    String propertyName = property.getName();
    Class<?> propertyClass = property.getType().getConcreteClass();
    Type propertyType = Type.getType(propertyClass);
    Label calledOutsideOfConstructor = new Label();

    Method setter = weakSetter.getMethod();

    // the regular typed setter
    String methodDescriptor = Type.getMethodDescriptor(Type.VOID_TYPE, propertyType);
    MethodVisitor methodVisitor =
        declareMethod(
            visitor, setter.getName(), methodDescriptor, AsmClassGeneratorUtils.signature(setter));

    putCanCallSettersFieldValueOnStack(methodVisitor, generatedType);
    jumpToLabelIfStackEvaluatesToTrue(methodVisitor, calledOutsideOfConstructor);
    throwExceptionBecauseCalledOnItself(methodVisitor);

    methodVisitor.visitLabel(calledOutsideOfConstructor);
    putStateFieldValueOnStack(methodVisitor, generatedType);
    putConstantOnStack(methodVisitor, propertyName);
    putFirstMethodArgumentOnStack(methodVisitor, propertyType);
    if (propertyClass.isPrimitive()) {
      boxType(methodVisitor, propertyClass);
    }
    invokeStateSetMethod(methodVisitor);

    finishVisitingMethod(methodVisitor);
  }
  private void writeConstructor(
      ClassVisitor visitor,
      Type generatedType,
      Type superclassType,
      StructSchema<?> delegateSchema) {
    String constructorDescriptor;
    Type delegateType;
    if (delegateSchema == null) {
      delegateType = null;
      constructorDescriptor = NO_DELEGATE_CONSTRUCTOR_DESCRIPTOR;
    } else {
      delegateType = Type.getType(delegateSchema.getType().getConcreteClass());
      constructorDescriptor =
          Type.getMethodDescriptor(
              Type.VOID_TYPE, MODEL_ELEMENT_STATE_TYPE, TYPE_CONVERTER_TYPE, delegateType);
    }
    MethodVisitor constructorVisitor =
        declareMethod(visitor, CONSTRUCTOR_NAME, constructorDescriptor, CONCRETE_SIGNATURE);

    invokeSuperConstructor(constructorVisitor, superclassType);
    assignStateField(constructorVisitor, generatedType);
    assignTypeConverterField(constructorVisitor, generatedType);
    if (delegateType != null) {
      assignDelegateField(constructorVisitor, generatedType, delegateType);
    }
    setCanCallSettersField(constructorVisitor, generatedType, true);
    finishVisitingMethod(constructorVisitor);
  }
  protected void injectGetByIndex(
      ClassWriter classWriter, String targetClassName, List<Field> fields) {
    MethodVisitor methodVisitor =
        classWriter.visitMethod(
            ACC_PUBLIC,
            "get",
            "(Ljava/lang/Object;I)Ljava/lang/Object;",
            null,
            new String[] {getInternalName(ILLEGAL_ACCESS_EXCEPTION.getCanonicalName())});

    Boxer boxer = new Boxer(methodVisitor);

    methodVisitor.visitCode();
    methodVisitor.visitVarInsn(ILOAD, 2);

    int maxStack = 6;

    Label[] labels = new Label[fields.size()];
    Label errorLabel = new Label();

    for (int i = 0; i < fields.size(); i++) {
      labels[i] = new Label();
    }

    methodVisitor.visitTableSwitchInsn(0, labels.length - 1, errorLabel, labels);

    if (!fields.isEmpty()) {
      maxStack--;

      for (int i = 0; i < fields.size(); i++) {
        Field field = fields.get(i);
        Class<?> type = field.getType();
        String fieldDescriptor = Type.getDescriptor(type);

        methodVisitor.visitLabel(labels[i]);

        if (i == 0) methodVisitor.visitFrame(F_APPEND, 1, new Object[] {targetClassName}, 0, null);
        else methodVisitor.visitFrame(F_SAME, 0, null, 0, null);

        if (isPublic(field)) {
          methodVisitor.visitVarInsn(ALOAD, 1);
          methodVisitor.visitTypeInsn(CHECKCAST, targetClassName);
          methodVisitor.visitFieldInsn(GETFIELD, targetClassName, field.getName(), fieldDescriptor);

          boxer.box(Type.getType(type));
        } else {
          injectReflectiveGetter(methodVisitor);
        }

        methodVisitor.visitInsn(ARETURN);
      }

      methodVisitor.visitLabel(errorLabel);
      methodVisitor.visitFrame(F_SAME, 0, null, 0, null);
    }

    injectException(methodVisitor, IllegalAccessException.class);
    methodVisitor.visitMaxs(maxStack, 3);
    methodVisitor.visitEnd();
  }
Esempio n. 23
0
  /**
   * Translates a simple type descriptor, specifically. Only translates names in the descriptor, if
   * they are represented by class mirrors.
   */
  protected String translateDescriptor(final String descriptor) {
    Type type = Type.getType(descriptor);

    type = getMirrorType(type);

    return type.getDescriptor();
  }
  /** Returns the reference/primitive class to store the */
  private static String findReferenceDesc(String desc) {
    Type type = Type.getType(desc);

    switch (type.getSort()) {
      case Type.ARRAY:
        return "Lorg/multiverse/transactional/refs/BasicRef;";
      case Type.BOOLEAN:
        return "Lorg/multiverse/transactional/refs/BooleanRef;";
      case Type.BYTE:
        return "Lorg/multiverse/transactional/refs/ByteRef;";
      case Type.CHAR:
        return "Lorg/multiverse/transactional/refs/CharRef;";
      case Type.DOUBLE:
        return "Lorg/multiverse/transactional/refs/DoubleRef;";
      case Type.FLOAT:
        return "Lorg/multiverse/transactional/refs/FloatRef;";
      case Type.INT:
        return "Lorg/multiverse/transactional/refs/IntRef;";
      case Type.LONG:
        return "Lorg/multiverse/transactional/refs/LongRef;";
      case Type.SHORT:
        return "Lorg/multiverse/transactional/refs/ShortRef;";
      case Type.OBJECT:
        return "Lorg/multiverse/transactional/refs/BasicRef;";
      default:
        throw new IllegalStateException("Unhandeled sort: " + type.getSort());
    }
  }
Esempio n. 25
0
      /** @see org.objectweb.asm.AnnotationVisitor#visitEnd() */
      public void visitEnd() {
        Type type = Type.getType(m_descriptor);

        if (type != null) {
          inspectType(type);
        }
      }
Esempio n. 26
0
  public static void visitAnnotationFields(AnnotationVisitor visitor, Map<String, Object> fields) {
    try {
      for (Map.Entry<String, Object> fieldEntry : fields.entrySet()) {
        Object value = fieldEntry.getValue();
        String key = fieldEntry.getKey();

        if (value instanceof Map) {
          @SuppressWarnings("unchecked")
          Map<Class, Map<String, Object>> nestedAnnotationMap =
              (Map<Class, Map<String, Object>>) value;

          for (Map.Entry<Class, Map<String, Object>> nestedAnnotation :
              nestedAnnotationMap.entrySet()) {
            AnnotationVisitor annotationV;

            annotationV =
                visitor.visitAnnotation(
                    key, Type.getType(nestedAnnotation.getKey()).getDescriptor());
            visitAnnotationFields(annotationV, nestedAnnotation.getValue());
            annotationV.visitEnd();
          }
        } else if (value.getClass().isArray()) {
          Object[] values = (Object[]) value;

          AnnotationVisitor arrayV = visitor.visitArray(key);
          for (int i = 0; i < values.length; i++) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put(null, values[i]);
            visitAnnotationFields(arrayV, map);
          }
          arrayV.visitEnd();
        } else if (value.getClass().isEnum()) {
          visitor.visitEnum(key, ci(value.getClass()), value.toString());
        } else if (value instanceof Class) {
          visitor.visit(key, Type.getType((Class) value));
        } else {
          visitor.visit(key, value);
        }
      }
    } catch (ClassCastException e) {
      throw new InvalidAnnotationDescriptorException(
          "Fields "
              + fields
              + " did not match annotation format.  See CodegenUtils#visitAnnotationFields for format",
          e);
    }
  }
 @Override
 public FieldVisitor visitField(
     int access, String name, String desc, String signature, Object value) {
   FieldVisitor toDecorate = super.visitField(access, name, desc, signature, value);
   String type = Type.getType(desc).getClassName();
   fieldList.add(type);
   return toDecorate;
 };
Esempio n. 28
0
 @Override
 public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
   JavaType annotationType = convertAsmType(org.objectweb.asm.Type.getType(desc));
   AnnotationInstanceResolve annotationInstance =
       new AnnotationInstanceResolve(annotationType.getSymbol());
   classSymbol.metadata().addAnnotation(annotationInstance);
   return new BytecodeAnnotationVisitor(annotationInstance, this);
 }
Esempio n. 29
0
 @Override
 public void visitLocalVariable(
     String name, String desc, String signature, Label start, Label end, int index) {
   // only remember the local variables of Type org.parboiled.support.Var that are not parameters
   if (index > parameterCount && Var.class.isAssignableFrom(getClassForType(Type.getType(desc)))) {
     if (localVarVariables == null) localVarVariables = new ArrayList<LocalVariableNode>();
     localVarVariables.add(new LocalVariableNode(name, desc, null, null, null, index));
   }
 }
 @Override
 public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object... bsmArgs) {
   if (bsm.getOwner().equals(LambdaNaming.LAMBDA_METAFACTORY)) {
     backportLambda(name, Type.getType(desc), bsm, bsmArgs);
   } else {
     super.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs);
   }
 }