Package org.apache.bcel.classfile

Examples of org.apache.bcel.classfile.Method



    /** @return deep copy of this method
     */
    public MethodGen copy( String class_name, ConstantPoolGen cp ) {
        Method m = ((MethodGen) clone()).getMethod();
        MethodGen mg = new MethodGen(m, class_name, this.cp);
        if (this.cp != cp) {
            mg.setConstantPool(cp);
            mg.getInstructionList().replaceConstantPool(this.cp, cp);
        }
View Full Code Here


                // OK, got a bug
                int offset = 0;
                if (getMethodName().equals("tearDown")) {
                    offset = obj.getCode().length - 1;
                }
                Method superMethod = Lookup.findImplementation(we, getMethodName(), "()V");
                Code superCode = superMethod.getCode();
                if (superCode != null && superCode.getCode().length > 3) {
                    bugReporter.reportBug(new BugInstance(this, getMethodName().equals("setUp") ? "IJU_SETUP_NO_SUPER"
                            : "IJU_TEARDOWN_NO_SUPER", NORMAL_PRIORITY).addClassAndMethod(this).addMethod(we, superMethod)
                            .describe(MethodAnnotation.METHOD_OVERRIDDEN).addSourceLine(this, offset));
                }
View Full Code Here

    }

    @Override
    protected Iterable<Method> getMethodVisitOrder(JavaClass obj) {
        ArrayList<Method> visitOrder = new ArrayList<Method>();
        Method staticInitializer = null;
        for(Method m : obj.getMethods()) {
            String name = m.getName();
            if (name.equals("<clinit>")) {
                staticInitializer = m;
            } else if (name.equals("<init>")) {
View Full Code Here

    @Nonnull
    public BugInstance addSourceLine(MethodDescriptor methodDescriptor, Location location) {
        try {
            IAnalysisCache analysisCache = Global.getAnalysisCache();
            ClassContext classContext = analysisCache.getClassAnalysis(ClassContext.class, methodDescriptor.getClassDescriptor());
            Method method = analysisCache.getMethodAnalysis(Method.class, methodDescriptor);
            return addSourceLine(classContext, method, location);
        } catch (CheckedAnalysisException e) {
            return addSourceLine(SourceLineAnnotation.createReallyUnknown(methodDescriptor.getClassDescriptor()
                    .toDottedClassName()));
        }
View Full Code Here

        super.visitClassContext(classContext);
    }

    @Override
    public void visit(Code obj) {
        Method m = getMethod();
        if (m.isStatic() || alreadyReported) {
            return;
        }

        state = SEEN_NOTHING;
        super.visit(obj);
View Full Code Here

                state = State.SEEN_NOTHING;
                invokePC = 0;
                super.visitCode(obj);
                if ((state == State.SEEN_RETURN) && (invokePC != 0)) {
                    // Do this check late, as it is potentially expensive
                    Method superMethod = findSuperclassMethod(superclassName, getMethod());
                    if ((superMethod == null) || differentAttributes(getMethod(), superMethod)
                            || getMethod().isProtected()
                            && !samePackage(getDottedClassName(), superclassName)) {
                        return;
                    }
View Full Code Here

      // INVOKEINTERFACE is an InvokeInstruction, the argument and return types are resolved/verified,
      // too. So are the allowed method names.
      String classname = o.getClassName(cpg);
      JavaClass jc = Repository.lookupClass(classname);
      Method[] ms = jc.getMethods();
      Method m = null;
      for (int i=0; i<ms.length; i++){
        if ( (ms[i].getName().equals(o.getMethodName(cpg))) &&
             (Type.getReturnType(ms[i].getSignature()).equals(o.getReturnType(cpg))) &&
             (objarrayequals(Type.getArgumentTypes(ms[i].getSignature()), o.getArgumentTypes(cpg))) ){
          m = ms[i];
View Full Code Here

      // INVOKESPECIAL is an InvokeInstruction, the argument and return types are resolved/verified,
      // too. So are the allowed method names.
      String classname = o.getClassName(cpg);
      JavaClass jc = Repository.lookupClass(classname);
      Method[] ms = jc.getMethods();
      Method m = null;
      for (int i=0; i<ms.length; i++){
        if ( (ms[i].getName().equals(o.getMethodName(cpg))) &&
             (Type.getReturnType(ms[i].getSignature()).equals(o.getReturnType(cpg))) &&
             (objarrayequals(Type.getArgumentTypes(ms[i].getSignature()), o.getArgumentTypes(cpg))) ){
          m = ms[i];
          break;
        }
      }
      if (m == null){
        constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' with expected signature '"+o.getSignature(cpg)+"' not found in class '"+jc.getClassName()+"'. The native verifier does allow the method to be declared in some superclass or implemented interface, which the Java Virtual Machine Specification, Second Edition does not.");
      }
     
      JavaClass current = Repository.lookupClass(myOwner.getClassName());
      if (current.isSuper()){
     
        if ((Repository.instanceOf( current, jc )) && (!current.equals(jc))){
         
          if (! (o.getMethodName(cpg).equals(Constants.CONSTRUCTOR_NAME) )){
            // Special lookup procedure for ACC_SUPER classes.
           
            int supidx = -1;
           
            Method meth = null;
            while (supidx != 0){
              supidx = current.getSuperclassNameIndex();
              current = Repository.lookupClass(current.getSuperclassName());
             
              Method[] meths = current.getMethods();
View Full Code Here

      // INVOKESTATIC is an InvokeInstruction, the argument and return types are resolved/verified,
      // too. So are the allowed method names.
      String classname = o.getClassName(cpg);
      JavaClass jc = Repository.lookupClass(classname);
      Method[] ms = jc.getMethods();
      Method m = null;
      for (int i=0; i<ms.length; i++){
        if ( (ms[i].getName().equals(o.getMethodName(cpg))) &&
             (Type.getReturnType(ms[i].getSignature()).equals(o.getReturnType(cpg))) &&
             (objarrayequals(Type.getArgumentTypes(ms[i].getSignature()), o.getArgumentTypes(cpg))) ){
          m = ms[i];
          break;
        }
      }
      if (m == null){
        constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' with expected signature '"+o.getSignature(cpg) +"' not found in class '"+jc.getClassName()+"'. The native verifier possibly allows the method to be declared in some superclass or implemented interface, which the Java Virtual Machine Specification, Second Edition does not.");
      } else if (! (m.isStatic())){ // implies it's not abstract, verified in pass 2.
        constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' has ACC_STATIC unset.");
      }
   
        } catch (ClassNotFoundException e) {
      // FIXME: maybe not the best way to handle this
View Full Code Here

      // INVOKEVIRTUAL is an InvokeInstruction, the argument and return types are resolved/verified,
      // too. So are the allowed method names.
      String classname = o.getClassName(cpg);
      JavaClass jc = Repository.lookupClass(classname);
      Method[] ms = jc.getMethods();
      Method m = null;
      for (int i=0; i<ms.length; i++){
        if ( (ms[i].getName().equals(o.getMethodName(cpg))) &&
             (Type.getReturnType(ms[i].getSignature()).equals(o.getReturnType(cpg))) &&
             (objarrayequals(Type.getArgumentTypes(ms[i].getSignature()), o.getArgumentTypes(cpg))) ){
          m = ms[i];
View Full Code Here

TOP

Related Classes of org.apache.bcel.classfile.Method

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.