Coverage Report - net.sourceforge.acelogger.location.resolver.UserCodeFrameResolver
 
Classes in this File Line Coverage Branch Coverage Complexity
UserCodeFrameResolver
90%
9/10
75%
6/8
5
 
 1  
 /*
 2  
  * This file is part of AceLogger.
 3  
  * 
 4  
  * AceLogger is free software: you can redistribute it and/or modify it under the terms of the GNU
 5  
  * Lesser General Public License as published by the Free Software Foundation, either version 3 of
 6  
  * the License, or (at your option) any later version.
 7  
  * 
 8  
  * AceLogger is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 9  
  * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 10  
  * Lesser General Public License for more details.
 11  
  * 
 12  
  * You should have received a copy of the GNU Lesser General Public License along with AceLogger.
 13  
  * If not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
 14  
  */
 15  
 package net.sourceforge.acelogger.location.resolver;
 16  
 
 17  
 import net.sourceforge.acelogger.Logger;
 18  
 
 19  
 /**
 20  
  * An implementation of CodeFrameResolver that finds the first call out of our packages.
 21  
  * 
 22  
  * @author Zardi (https://sourceforge.net/users/daniel_zardi)
 23  
  * @version 1.0.0
 24  
  * @since 1.0.0
 25  
  */
 26  0
 public class UserCodeFrameResolver extends BaseCodeFrameResolver {
 27  
 
 28  
         /**
 29  
          * The suffix of the our packages.
 30  
          */
 31  1
         private static final String LOGGER_PACKAGE = Logger.class.getPackage().getName();
 32  
 
 33  
         /** {@inheritDoc} */
 34  
         public StackTraceElement getCodeFrame(Thread currentThread) {
 35  1
                 StackTraceElement[] stackTrace = currentThread.getStackTrace();
 36  1
                 int userCodeCallIndex = 0;
 37  4
                 for (int i = 0; i < stackTrace.length; i++) {
 38  4
                         String frameClassName = stackTrace[i].getClassName();
 39  4
                         if (!frameClassName.startsWith("java.util.concurrent")
 40  
                                         && !frameClassName.startsWith("java.lang.Thread")
 41  
                                         && !frameClassName.startsWith(LOGGER_PACKAGE)) {
 42  1
                                 userCodeCallIndex = i;
 43  1
                                 break;
 44  
                         }
 45  
                 }
 46  1
                 return stackTrace[userCodeCallIndex];
 47  
         }
 48  
 
 49  
 }