diff options
Diffstat (limited to 'org.jacoco.core/src/org/jacoco/core/analysis')
16 files changed, 108 insertions, 97 deletions
diff --git a/org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java b/org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java index 53dbf0c0..76b7be3c 100644 --- a/org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java +++ b/org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors + * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors * All rights reserved. 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 @@ -30,8 +30,10 @@ import org.jacoco.core.internal.analysis.ClassCoverageImpl; import org.jacoco.core.internal.analysis.StringPool; import org.jacoco.core.internal.data.CRC64; import org.jacoco.core.internal.flow.ClassProbesAdapter; +import org.jacoco.core.internal.instr.InstrSupport; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.Opcodes; /** * An {@link Analyzer} instance processes a set of Java class files and @@ -99,15 +101,17 @@ public class Analyzer { return new ClassProbesAdapter(analyzer, false); } - /** - * Analyzes the class given as a ASM reader. - * - * @param reader - * reader with class definitions - */ - public void analyzeClass(final ClassReader reader) { - final ClassVisitor visitor = createAnalyzingVisitor( - CRC64.classId(reader.b), reader.getClassName()); + private void analyzeClass(final byte[] source) { + final long classId = CRC64.classId(source); + final ClassReader reader = InstrSupport.classReaderFor(source); + if ((reader.getAccess() & Opcodes.ACC_MODULE) != 0) { + return; + } + if ((reader.getAccess() & Opcodes.ACC_SYNTHETIC) != 0) { + return; + } + final ClassVisitor visitor = createAnalyzingVisitor(classId, + reader.getClassName()); reader.accept(visitor, 0); } @@ -124,7 +128,7 @@ public class Analyzer { public void analyzeClass(final byte[] buffer, final String location) throws IOException { try { - analyzeClass(new ClassReader(buffer)); + analyzeClass(buffer); } catch (final RuntimeException cause) { throw analyzerError(location, cause); } diff --git a/org.jacoco.core/src/org/jacoco/core/analysis/CounterComparator.java b/org.jacoco.core/src/org/jacoco/core/analysis/CounterComparator.java index 1848c6fc..8a67b970 100644 --- a/org.jacoco.core/src/org/jacoco/core/analysis/CounterComparator.java +++ b/org.jacoco.core/src/org/jacoco/core/analysis/CounterComparator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors + * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors * All rights reserved. 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 diff --git a/org.jacoco.core/src/org/jacoco/core/analysis/CoverageBuilder.java b/org.jacoco.core/src/org/jacoco/core/analysis/CoverageBuilder.java index a44afb78..784fbd82 100644 --- a/org.jacoco.core/src/org/jacoco/core/analysis/CoverageBuilder.java +++ b/org.jacoco.core/src/org/jacoco/core/analysis/CoverageBuilder.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors + * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors * All rights reserved. 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 @@ -95,26 +95,22 @@ public class CoverageBuilder implements ICoverageVisitor { return result; } - // === IStructureVisitor === + // === ICoverageVisitor === public void visitCoverage(final IClassCoverage coverage) { - // Only consider classes that actually contain code: - if (coverage.getInstructionCounter().getTotalCount() > 0) { - final String name = coverage.getName(); - final IClassCoverage dup = classes.put(name, coverage); - if (dup != null) { - if (dup.getId() != coverage.getId()) { - throw new IllegalStateException( - "Can't add different class with same name: " - + name); - } - } else { - final String source = coverage.getSourceFileName(); - if (source != null) { - final SourceFileCoverageImpl sourceFile = getSourceFile( - source, coverage.getPackageName()); - sourceFile.increment(coverage); - } + final String name = coverage.getName(); + final IClassCoverage dup = classes.put(name, coverage); + if (dup != null) { + if (dup.getId() != coverage.getId()) { + throw new IllegalStateException( + "Can't add different class with same name: " + name); + } + } else { + final String source = coverage.getSourceFileName(); + if (source != null) { + final SourceFileCoverageImpl sourceFile = getSourceFile(source, + coverage.getPackageName()); + sourceFile.increment(coverage); } } } diff --git a/org.jacoco.core/src/org/jacoco/core/analysis/CoverageNodeImpl.java b/org.jacoco.core/src/org/jacoco/core/analysis/CoverageNodeImpl.java index c1bcb26a..6be3bb6f 100644 --- a/org.jacoco.core/src/org/jacoco/core/analysis/CoverageNodeImpl.java +++ b/org.jacoco.core/src/org/jacoco/core/analysis/CoverageNodeImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors + * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors * All rights reserved. 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 @@ -143,6 +143,10 @@ public class CoverageNodeImpl implements ICoverageNode { throw new AssertionError(entity); } + public boolean containsCode() { + return getInstructionCounter().getTotalCount() != 0; + } + public ICoverageNode getPlainCopy() { final CoverageNodeImpl copy = new CoverageNodeImpl(elementType, name); copy.instructionCounter = CounterImpl.getInstance(instructionCounter); diff --git a/org.jacoco.core/src/org/jacoco/core/analysis/IBundleCoverage.java b/org.jacoco.core/src/org/jacoco/core/analysis/IBundleCoverage.java index afcdc1aa..d488f475 100644 --- a/org.jacoco.core/src/org/jacoco/core/analysis/IBundleCoverage.java +++ b/org.jacoco.core/src/org/jacoco/core/analysis/IBundleCoverage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors + * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors * All rights reserved. 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 @@ -25,6 +25,6 @@ public interface IBundleCoverage extends ICoverageNode { * * @return all packages */ - public Collection<IPackageCoverage> getPackages(); + Collection<IPackageCoverage> getPackages(); -}
\ No newline at end of file +} diff --git a/org.jacoco.core/src/org/jacoco/core/analysis/IClassCoverage.java b/org.jacoco.core/src/org/jacoco/core/analysis/IClassCoverage.java index f72b7a85..81cc6fe7 100644 --- a/org.jacoco.core/src/org/jacoco/core/analysis/IClassCoverage.java +++ b/org.jacoco.core/src/org/jacoco/core/analysis/IClassCoverage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors + * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors * All rights reserved. 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 @@ -27,7 +27,7 @@ public interface IClassCoverage extends ISourceNode { * * @return class identifier */ - public long getId(); + long getId(); /** * Returns if the the analyzed class does match the execution data provided. @@ -37,14 +37,14 @@ public interface IClassCoverage extends ISourceNode { * @return <code>true</code> if this class does not match to the provided * execution data. */ - public boolean isNoMatch(); + boolean isNoMatch(); /** * Returns the VM signature of the class. * * @return VM signature of the class (may be <code>null</code>) */ - public String getSignature(); + String getSignature(); /** * Returns the VM name of the superclass. @@ -52,34 +52,34 @@ public interface IClassCoverage extends ISourceNode { * @return VM name of the super class (may be <code>null</code>, i.e. * <code>java/lang/Object</code>) */ - public String getSuperName(); + String getSuperName(); /** * Returns the VM names of implemented/extended interfaces. * * @return VM names of implemented/extended interfaces */ - public String[] getInterfaceNames(); + String[] getInterfaceNames(); /** * Returns the VM name of the package this class belongs to. * * @return VM name of the package */ - public String getPackageName(); + String getPackageName(); /** * Returns the optional name of the corresponding source file. * * @return name of the corresponding source file */ - public String getSourceFileName(); + String getSourceFileName(); /** * Returns the methods included in this class. * * @return methods of this class */ - public Collection<IMethodCoverage> getMethods(); + Collection<IMethodCoverage> getMethods(); -}
\ No newline at end of file +} diff --git a/org.jacoco.core/src/org/jacoco/core/analysis/ICounter.java b/org.jacoco.core/src/org/jacoco/core/analysis/ICounter.java index 5f30e02b..60c8dcc5 100644 --- a/org.jacoco.core/src/org/jacoco/core/analysis/ICounter.java +++ b/org.jacoco.core/src/org/jacoco/core/analysis/ICounter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors + * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors * All rights reserved. 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 @@ -20,7 +20,7 @@ public interface ICounter { /** * Different values provided by a counter. */ - public enum CounterValue { + enum CounterValue { /** Total number of items */ TOTALCOUNT, @@ -41,22 +41,22 @@ public interface ICounter { /** * Status flag for no items (value is 0x00). */ - public static final int EMPTY = 0x00; + int EMPTY = 0x00; /** * Status flag when all items are not covered (value is 0x01). */ - public static final int NOT_COVERED = 0x01; + int NOT_COVERED = 0x01; /** * Status flag when all items are covered (value is 0x02). */ - public static final int FULLY_COVERED = 0x02; + int FULLY_COVERED = 0x02; /** * Status flag when items are partly covered (value is 0x03). */ - public static final int PARTLY_COVERED = NOT_COVERED | FULLY_COVERED; + int PARTLY_COVERED = NOT_COVERED | FULLY_COVERED; /** * Returns the counter value of the given type. @@ -65,28 +65,28 @@ public interface ICounter { * value type to return * @return counter value */ - public double getValue(CounterValue value); + double getValue(CounterValue value); /** * Returns the total count of items. * * @return total count of items */ - public int getTotalCount(); + int getTotalCount(); /** * Returns the count of covered items. * * @return count of covered items */ - public int getCoveredCount(); + int getCoveredCount(); /** * Returns the count of missed items. * * @return count of missed items */ - public int getMissedCount(); + int getMissedCount(); /** * Calculates the ratio of covered to total count items. If total count @@ -94,7 +94,7 @@ public interface ICounter { * * @return ratio of covered to total count items */ - public double getCoveredRatio(); + double getCoveredRatio(); /** * Calculates the ratio of missed to total count items. If total count items @@ -102,7 +102,7 @@ public interface ICounter { * * @return ratio of missed to total count items */ - public double getMissedRatio(); + double getMissedRatio(); /** * Returns the coverage status of this counter. @@ -114,6 +114,6 @@ public interface ICounter { * * @return status of this line */ - public int getStatus(); + int getStatus(); } diff --git a/org.jacoco.core/src/org/jacoco/core/analysis/ICoverageNode.java b/org.jacoco.core/src/org/jacoco/core/analysis/ICoverageNode.java index 0756f410..20b107d4 100644 --- a/org.jacoco.core/src/org/jacoco/core/analysis/ICoverageNode.java +++ b/org.jacoco.core/src/org/jacoco/core/analysis/ICoverageNode.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors + * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors * All rights reserved. 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 @@ -20,7 +20,7 @@ public interface ICoverageNode { /** * Type of a Java element represented by a {@link ICoverageNode} instance. */ - public enum ElementType { + enum ElementType { /** Method */ METHOD, @@ -45,7 +45,7 @@ public interface ICoverageNode { /** * Different counter types supported by JaCoCo. */ - public enum CounterEntity { + enum CounterEntity { /** Counter for instructions */ INSTRUCTION, @@ -71,56 +71,56 @@ public interface ICoverageNode { * * @return type of this node */ - public abstract ElementType getElementType(); + ElementType getElementType(); /** * Returns the name of this node. * * @return name of this node */ - public String getName(); + String getName(); /** * Returns the counter for byte code instructions. * * @return counter for instructions */ - public abstract ICounter getInstructionCounter(); + ICounter getInstructionCounter(); /** * Returns the counter for branches. * * @return counter for branches */ - public ICounter getBranchCounter(); + ICounter getBranchCounter(); /** * Returns the counter for lines. * * @return counter for lines */ - public ICounter getLineCounter(); + ICounter getLineCounter(); /** * Returns the counter for cyclomatic complexity. * * @return counter for complexity */ - public ICounter getComplexityCounter(); + ICounter getComplexityCounter(); /** * Returns the counter for methods. * * @return counter for methods */ - public ICounter getMethodCounter(); + ICounter getMethodCounter(); /** * Returns the counter for classes. * * @return counter for classes */ - public ICounter getClassCounter(); + ICounter getClassCounter(); /** * Generic access to the the counters. @@ -129,7 +129,14 @@ public interface ICoverageNode { * entity we're we want to have the counter for * @return counter for the given entity */ - public ICounter getCounter(CounterEntity entity); + ICounter getCounter(CounterEntity entity); + + /** + * Checks whether this node contains code relevant for code coverage. + * + * @return <code>true</code> if this node contains code relevant for code coverage + */ + boolean containsCode(); /** * Creates a plain copy of this node. While {@link ICoverageNode} @@ -139,6 +146,6 @@ public interface ICoverageNode { * * @return copy with counters only */ - public ICoverageNode getPlainCopy(); + ICoverageNode getPlainCopy(); -}
\ No newline at end of file +} diff --git a/org.jacoco.core/src/org/jacoco/core/analysis/ICoverageVisitor.java b/org.jacoco.core/src/org/jacoco/core/analysis/ICoverageVisitor.java index 5a71859f..3f702906 100644 --- a/org.jacoco.core/src/org/jacoco/core/analysis/ICoverageVisitor.java +++ b/org.jacoco.core/src/org/jacoco/core/analysis/ICoverageVisitor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors + * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors * All rights reserved. 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 @@ -23,6 +23,6 @@ public interface ICoverageVisitor { * @param coverage * coverage data for a class */ - public void visitCoverage(IClassCoverage coverage); + void visitCoverage(IClassCoverage coverage); } diff --git a/org.jacoco.core/src/org/jacoco/core/analysis/ILine.java b/org.jacoco.core/src/org/jacoco/core/analysis/ILine.java index cdd91eba..ef65dc0d 100644 --- a/org.jacoco.core/src/org/jacoco/core/analysis/ILine.java +++ b/org.jacoco.core/src/org/jacoco/core/analysis/ILine.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors + * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors * All rights reserved. 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 @@ -22,14 +22,14 @@ public interface ILine { * * @return instruction counter */ - public ICounter getInstructionCounter(); + ICounter getInstructionCounter(); /** * Returns the branches counter for this line. * * @return branches counter */ - public ICounter getBranchCounter(); + ICounter getBranchCounter(); /** * Returns the coverage status of this line, calculated from the @@ -42,6 +42,6 @@ public interface ILine { * * @return status of this line */ - public int getStatus(); + int getStatus(); } diff --git a/org.jacoco.core/src/org/jacoco/core/analysis/IMethodCoverage.java b/org.jacoco.core/src/org/jacoco/core/analysis/IMethodCoverage.java index 3bd75169..b6755170 100644 --- a/org.jacoco.core/src/org/jacoco/core/analysis/IMethodCoverage.java +++ b/org.jacoco.core/src/org/jacoco/core/analysis/IMethodCoverage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors + * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors * All rights reserved. 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 @@ -22,13 +22,13 @@ public interface IMethodCoverage extends ISourceNode { * * @return descriptor */ - public String getDesc(); + String getDesc(); /** * Returns the generic signature of the method if defined. * * @return generic signature or <code>null</code> */ - public String getSignature(); + String getSignature(); -}
\ No newline at end of file +} diff --git a/org.jacoco.core/src/org/jacoco/core/analysis/IPackageCoverage.java b/org.jacoco.core/src/org/jacoco/core/analysis/IPackageCoverage.java index 8ff1a184..32121620 100644 --- a/org.jacoco.core/src/org/jacoco/core/analysis/IPackageCoverage.java +++ b/org.jacoco.core/src/org/jacoco/core/analysis/IPackageCoverage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors + * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors * All rights reserved. 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 @@ -28,13 +28,13 @@ public interface IPackageCoverage extends ICoverageNode { * * @return all classes */ - public Collection<IClassCoverage> getClasses(); + Collection<IClassCoverage> getClasses(); /** * Returns all source files in this package. * * @return all source files */ - public Collection<ISourceFileCoverage> getSourceFiles(); + Collection<ISourceFileCoverage> getSourceFiles(); -}
\ No newline at end of file +} diff --git a/org.jacoco.core/src/org/jacoco/core/analysis/ISourceFileCoverage.java b/org.jacoco.core/src/org/jacoco/core/analysis/ISourceFileCoverage.java index 6a49490b..5f01160a 100644 --- a/org.jacoco.core/src/org/jacoco/core/analysis/ISourceFileCoverage.java +++ b/org.jacoco.core/src/org/jacoco/core/analysis/ISourceFileCoverage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors + * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors * All rights reserved. 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 @@ -22,6 +22,6 @@ public interface ISourceFileCoverage extends ISourceNode { * * @return package name */ - public String getPackageName(); + String getPackageName(); -}
\ No newline at end of file +} diff --git a/org.jacoco.core/src/org/jacoco/core/analysis/ISourceNode.java b/org.jacoco.core/src/org/jacoco/core/analysis/ISourceNode.java index d6c90e5a..d64b2cc1 100644 --- a/org.jacoco.core/src/org/jacoco/core/analysis/ISourceNode.java +++ b/org.jacoco.core/src/org/jacoco/core/analysis/ISourceNode.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors + * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors * All rights reserved. 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 @@ -18,7 +18,7 @@ package org.jacoco.core.analysis; public interface ISourceNode extends ICoverageNode { /** Place holder for unknown lines (no debug information) */ - public static int UNKNOWN_LINE = -1; + int UNKNOWN_LINE = -1; /** * The number of the first line coverage information is available for. If no @@ -26,7 +26,7 @@ public interface ISourceNode extends ICoverageNode { * * @return number of the first line or {@link #UNKNOWN_LINE} */ - public int getFirstLine(); + int getFirstLine(); /** * The number of the last line coverage information is available for. If no @@ -34,7 +34,7 @@ public interface ISourceNode extends ICoverageNode { * * @return number of the last line or {@link #UNKNOWN_LINE} */ - public int getLastLine(); + int getLastLine(); /** * Returns the line information for given line. @@ -43,6 +43,6 @@ public interface ISourceNode extends ICoverageNode { * line number of interest * @return line information */ - public ILine getLine(int nr); + ILine getLine(int nr); } diff --git a/org.jacoco.core/src/org/jacoco/core/analysis/NodeComparator.java b/org.jacoco.core/src/org/jacoco/core/analysis/NodeComparator.java index da94e07c..3fea25fb 100644 --- a/org.jacoco.core/src/org/jacoco/core/analysis/NodeComparator.java +++ b/org.jacoco.core/src/org/jacoco/core/analysis/NodeComparator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors + * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors * All rights reserved. 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 diff --git a/org.jacoco.core/src/org/jacoco/core/analysis/package-info.java b/org.jacoco.core/src/org/jacoco/core/analysis/package-info.java index afee23c2..d1a5e73b 100644 --- a/org.jacoco.core/src/org/jacoco/core/analysis/package-info.java +++ b/org.jacoco.core/src/org/jacoco/core/analysis/package-info.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors + * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors * All rights reserved. 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 @@ -34,4 +34,4 @@ * +-- {@linkplain org.jacoco.core.analysis.ICoverageNode.ElementType#METHOD Method} * </pre> */ -package org.jacoco.core.analysis;
\ No newline at end of file +package org.jacoco.core.analysis; |