Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * fb-contrib - Auxiliary detectors for Java programs
   * Copyright (C) 2005-2015 Dave Brosius
   * 
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   * 
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  * 
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 package com.mebigfatguy.fbcontrib.detect;
 
 
 
looks for methods that call a method to retrieve a reference to an object, to use to load a constant. It is simpler and more performant to access the static variable directly from the class itself.
 
 {
 	enum State {SEEN_NOTHING, SEEN_INVOKE, SEEN_POP}
 	
 	private final BugReporter bugReporter;
     private LineNumberTable lnTable;
 	private State state;
     private int invokePC;
     private String returnType;
constructs a NIR detector given the reporter to report bugs on

Parameters:
bugReporter the sync of bug reports
 
 	public NeedlessInstanceRetrieval(BugReporter bugReporter) {
 		this. = bugReporter;
 	}

    
overrides the interface to collect the line number table, and reset state

Parameters:
obj the content object of the currently parsed code
 
     @Override
     public void visitCode(Code obj) {
         try {
              = obj.getLineNumberTable();
             if ( != null) {
                  = .;
                  = -1;
                  = null;
                 super.visitCode(obj);
             }
         } finally {
              = null;
         }
     }
    
overrides the interface to find accesses of static variables off of an instance immediately fetched from a method call.

Parameters:
seen the opcode of the currently visited instruction
 
 	public void sawOpcode(int seen) {
 		switch ()
 		{
 			case :
 				if (seen == 
 				||  seen == ) {
 					Type retType = Type.getReturnType(sig);
 					if (retType.getSignature().startsWith("L")) {
 						if (!"java/lang/Object".equals(clsName)
 						&&  !"java/lang/String".equals(clsName)) {
 						     = retType.getSignature();
 						     = .substring(1, .length() - 1);
 	                         = getPC();
 						}
                     }
 				}
 			break;
				if (seen == )
				else {
					 = null;
				}
			break;
			case :
				if ((seen >=  && seen <= ) || (seen == )) {
				     = .;
else if ((seen == ) || (seen == )) {
                        if (.getSourceLine() == .getSourceLine(getPC())) {
        									.addClass(this)
        									.addMethod(this)
        									.addSourceLine(this));
                        }
				    }
                     = .;
                     = null;
else {
                     = null;
				}
			break;
            
            default:
                 = .;
                 = null;
            break;
		}
	}
}
 
New to GrepCode? Check out our FAQ X