private LineData getOrCreateLine(int classLine) { LineData ld = classData.getLineData(classLine); if (ld == null) { ld = classData.addLine(classLine, null, null); } return ld; } }
public void setSource(String source) { logger.debug("source: " + source); classData.setSourceFileName(source); }
/** * This is called by instrumented bytecode. */ public ClassData getOrCreateClassData(String name) { lock.lock(); try { ClassData classData = (ClassData) this.classes.get(name); if (classData == null) { classData = new ClassData(name); addClassData(classData); } return classData; } finally { lock.unlock(); } }
public LineData getLineCoverage(int lineNumber) { lock.lock(); try { Iterator iter = this.children.values().iterator(); while (iter.hasNext()) { ClassData classData = (ClassData) iter.next(); if (classData.isValidSourceLineNumber(lineNumber)) return classData.getLineCoverage(lineNumber); } } finally { lock.unlock(); } return null; }
baseName = sourceFileName; else { baseName = getBaseName(); int firstDollarSign = baseName.indexOf('$'); if (firstDollarSign == -1 || firstDollarSign == 0) String packageName = getPackageName(); if (packageName.equals("")) return baseName;
ClassData diffClasses( ClassData larger, ClassData smaller ) { ClassData result = new ClassData( larger.getName() ); for( Object o : larger.getLines()) { LineData lld = (LineData) o; long afterHits = lld.getHits(); long prevConditions = 0; if ( smaller != null ) { LineData sld = smaller.getLineCoverage( lld.getLineNumber() ); if ( sld != null ) { prevHits = sld.getHits(); result.addLine( lld.getLineNumber(), lld.getMethodName(), lld.getMethodDescriptor() ); if ( diffHits > 0 ) { result.touch( lld.getLineNumber(), diffHits ); errors.add( "Coverage decreased on line " + lld.getLineNumber() + " of " + larger.getName()); errors.add( "Jump or Switch disappeared on line " + lld.getLineNumber() + " of " + larger.getName() ); if ( cd instanceof JumpData) { JumpData ljd = (JumpData) cd; result.addLineJump( lld.getLineNumber(), i ); long prevTrue = 0; long prevFalse = 0; if ( smaller != null ) { LineData sld = smaller.getLineCoverage( lld.getLineNumber() ); if ( sld != null ) { JumpData sjd = (JumpData) sld.getConditionData( i );
ClassData classData = (ClassData) iter.next(); CoverageRate coverageRate = findMinimumCoverageRate(classData .getName()); totalBranches += classData.getNumberOfValidBranches(); totalBranchesCovered += classData.getNumberOfCoveredBranches(); totalLines += classData.getNumberOfValidLines(); totalLinesCovered += classData.getNumberOfCoveredLines(); .getPackageName()); if (packageBranchCoverageRate > 0.0) { packageCoverage.addBranchCount(classData .getNumberOfValidBranches()); packageCoverage.addBranchCoverage(classData .getNumberOfCoveredBranches()); packageCoverage.addLineCount(classData.getNumberOfValidLines()); packageCoverage.addLineCoverage(classData .getNumberOfCoveredLines()); logger.debug("Class " + classData.getName() + ", line coverage rate: " + percentage(classData.getLineCoverageRate()) + "%, branch coverage rate: " + percentage(classData.getBranchCoverageRate()) + "%"); if (classData.getBranchCoverageRate() < coverageRate .getBranchCoverageRate()) {
.replace('/', '.')); if (source != null) { classData.setSourceFileName(source); classData.setContainsInstrumentationInfo(); int lastLine = 0; int jumpsInLine = 0; classData.addLine(tpd.getLineNumber(), ((LineTouchPointDescriptor) tpd).getMethodName(), ((LineTouchPointDescriptor) tpd) .getMethodSignature()); } else if (tpd instanceof JumpTouchPointDescriptor) { classData.addLineJump(tpd.getLineNumber(), jumpsInLine++); } else if (tpd instanceof SwitchTouchPointDescriptor) { int countersCnt = ((SwitchTouchPointDescriptor) tpd) .getCountersForLabelsCnt(); classData.addLineSwitch(tpd.getLineNumber(), toucesInLine++, 0, countersCnt - 2, Integer.MAX_VALUE);
private void dumpClass(ClassData classData) { logger.debug("Dumping class " + classData.getName()); println("<class name=\"" + classData.getName() + "\" filename=\"" + classData.getSourceFileName() + "\" line-rate=\"" + classData.getLineCoverageRate() + "\" branch-rate=\"" + classData.getBranchCoverageRate() + "\" complexity=\"" + complexity.getCCNForClass(classData) + "\"" + ">"); increaseIndentation(); dumpMethods(classData); dumpLines(classData); decreaseIndentation(); println("</class>"); }
public void instrument( String file, int line ) { if ( isExcluded( file ) ) { getLogger().debug("ignoring " + file); } else { ClassData classData = coverageProjectData.getOrCreateClassData( ApparatUtil.toClassname( file ) ); classData.setSourceFileName( getSourceFilePath( file ) ); classData.addLine( line, null, null ); } } };
if (!this.getName().equals(classData.getName())) return; getBothLocks(classData); try { super.merge(coverageData); .getMethodNamesAndDescriptors()); if (classData.sourceFileName != null) this.sourceFileName = classData.sourceFileName;
List<FunctionMetric> methodMetrics = getFunctionMetricsForSingleFile(classData.getSourceFileName()); if (goldenMethodName.equals("<init>")) { isConstructor = true; goldenMethodName = classData.getBaseName(); goldenMethodName = classData.getName() + "." + goldenMethodName; goldenParameterTypes[i] = ClassUtils.getClass(goldenParameterTypeStrings[i].trim(), false); Class<?> klass = ClassUtils.getClass(classData.getName(), false); if (isConstructor) { Constructor<?> realMethod = klass.getDeclaredConstructor(goldenParameterTypes);
public void addClassData(ClassData classData) { lock.lock(); try { if (children.containsKey(classData.getBaseName())) throw new IllegalArgumentException("Source file " + this.name + " already contains a class with the name " + classData.getBaseName()); // Each key is a class basename, stored as an String object. // Each value is information about the class, stored as a ClassData object. children.put(classData.getBaseName(), classData); } finally { lock.unlock(); } }
public void visitLineNumber(int line, Label start) { // Record initial information about this line of code currentLine = line; classData.addLine(currentLine, myName, myDescriptor); currentJump = 0; currentSwitch = 0; lineLabels.put(start, new Integer(line)); //removed because the MethodNode doesn't reproduce visitLineNumber where they are but at the end of the file :-(( //therefore we don't need them //We can directly instrument the visit line number here, but it is better to leave all instrumentation in the second pass //therefore we just collects what label is the line ... //super.visitLineNumber(line, start); }
public void addClassData(ClassData classData) { lock.lock(); try { String packageName = classData.getPackageName(); PackageData packageData = (PackageData) children.get(packageName); if (packageData == null) { packageData = new PackageData(packageName); // Each key is a package name, stored as an String object. // Each value is information about the package, stored as a PackageData object. this.children.put(packageName, packageData); } packageData.addClassData(classData); this.classes.put(classData.getName(), classData); } finally { lock.unlock(); } }
public MethodData(ClassData classData, String methodNameAndDescriptor) { this.lines = new ArrayList<LineData>( ); lines.addAll( (Collection) classData.getLines(methodNameAndDescriptor) ); Collections.sort( this.lines, new Comparator<CoverageData>() { @Override public int compare(CoverageData o1, CoverageData o2) { LineData l1 = (LineData) o1; LineData l2 = (LineData) o2; Integer i1 = new Integer( l1.getLineNumber() ); Integer i2 = new Integer( l2.getLineNumber() ); return i1.compareTo( i2 ); } }); this.data = classData; name = methodNameAndDescriptor; }
void buildClassDataHelpers() { for( Object o : getData().getClasses() ) { ClassData cd = (ClassData) o; ClassData dcd = null; if ( getSamePackageData() != null ) { dcd = (ClassData) getSamePackageData().getChild( cd.getBaseName() ); } try { ClassDataPair cdp = getFactory().makeClassDataPair( cd, dcd, this ); addChild( cdp ); } catch( RuntimeException e ) { throw new RuntimeException( "Could not create ClassDataPair " + cd.getName(), e ); } } }
public void visitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels) { super.visitLookupSwitchInsn(dflt, keys, labels); if (currentLine != 0) { switchTargetLabels.put(dflt, new SwitchHolder(currentLine, currentSwitch, -1)); for (int i = labels.length -1; i >=0; i--) switchTargetLabels.put(labels[i], new SwitchHolder(currentLine, currentSwitch, i)); classData.addLineSwitch(currentLine, currentSwitch++, keys); } }
private void dumpMethods(ClassData classData) { println("<methods>"); increaseIndentation(); SortedSet sortedMethods = new TreeSet(); sortedMethods.addAll(classData.getMethodNamesAndDescriptors()); Iterator iter = sortedMethods.iterator(); while (iter.hasNext()) { dumpMethod(classData, (String) iter.next()); } decreaseIndentation(); println("</methods>"); }
public void visitJumpInsn(int opcode, Label label) { // Ignore any jump instructions in the "class init" method. // When initializing static variables, the JVM first checks // that the variable is null before attempting to set it. // This check contains an IFNONNULL jump instruction which // would confuse people if it showed up in the reports. if ((opcode != GOTO) && (opcode != JSR) && (currentLine != 0) && (!this.myName.equals("<clinit>"))) { classData.addLineJump(currentLine, currentJump); jumpTargetLabels.put(label, new JumpHolder(currentLine, currentJump++)); } super.visitJumpInsn(opcode, label); }