Java Aspectj Usage createConstant(InstructionFactory fact, int value)

Here you can find the source of createConstant(InstructionFactory fact, int value)

Description

create Constant

License

Open Source License

Declaration

public static Instruction createConstant(InstructionFactory fact, int value) 

Method Source Code

//package com.java2s;
/* *******************************************************************
 * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
 * All rights reserved. /*from  ww w  .  j av  a 2  s .  c  o m*/
 * This program and the accompanying materials are made available 
 * under the terms of the Eclipse Public License v1.0 
 * which accompanies this distribution and is available at 
 * http://www.eclipse.org/legal/epl-v10.html 
 *  
 * Contributors: 
 *     PARC     initial implementation 
 * ******************************************************************/

import org.aspectj.apache.bcel.Constants;

import org.aspectj.apache.bcel.generic.Instruction;
import org.aspectj.apache.bcel.generic.InstructionByte;
import org.aspectj.apache.bcel.generic.InstructionCP;
import org.aspectj.apache.bcel.generic.InstructionConstants;
import org.aspectj.apache.bcel.generic.InstructionFactory;

import org.aspectj.apache.bcel.generic.InstructionShort;

public class Main {
    public static Instruction createConstant(InstructionFactory fact, int value) {
        Instruction inst;
        switch (value) {
        case -1:
            inst = InstructionConstants.ICONST_M1;
            break;
        case 0:
            inst = InstructionConstants.ICONST_0;
            break;
        case 1:
            inst = InstructionConstants.ICONST_1;
            break;
        case 2:
            inst = InstructionConstants.ICONST_2;
            break;
        case 3:
            inst = InstructionConstants.ICONST_3;
            break;
        case 4:
            inst = InstructionConstants.ICONST_4;
            break;
        case 5:
            inst = InstructionConstants.ICONST_5;
            break;
        default:
            if (value <= Byte.MAX_VALUE && value >= Byte.MIN_VALUE) {
                inst = new InstructionByte(Constants.BIPUSH, (byte) value);
            } else if (value <= Short.MAX_VALUE && value >= Short.MIN_VALUE) {
                inst = new InstructionShort(Constants.SIPUSH, (short) value);
            } else {
                int ii = fact.getClassGen().getConstantPool().addInteger(value);
                inst = new InstructionCP(value <= Constants.MAX_BYTE ? Constants.LDC : Constants.LDC_W, ii);
            }
            break;
        }
        return inst;
    }
}

Related

  1. classOrInterface(int access_flags)
  2. collectArguments(JoinPoint jp)
  3. combine(String[] one, String[] two)
  4. convertToFile(String path)
  5. copyInstruction(Instruction i)
  6. createInstanceof(InstructionFactory fact, ReferenceType t)
  7. genPointcutDetails(Pointcut pcd)
  8. genSignature(IProgramElement node)
  9. getArgsMap(JoinPoint pjp)