Skip to content

Instantly share code, notes, and snippets.

@marchof
Created August 30, 2019 09:20
Show Gist options
  • Save marchof/3a299e72947cd354f5613fd64ce2b615 to your computer and use it in GitHub Desktop.
Save marchof/3a299e72947cd354f5613fd64ce2b615 to your computer and use it in GitHub Desktop.
New API on JaCoCo Analyzer and Instrumenter?
/**
* This method is called for every class. If it returns <code>true</code>
* the class is filtered out and not processed. The default implementation
* always returns <code>false</code>, which means all provided classes are
* processed.
*
* @param classname
* internal vm name of the class
* @param id
* JaCoCo class id
* @param location
* location description
* @return
*/
protected boolean filter(final String classname, final long id, final String location) {
return false;
}
@Godin
Copy link

Godin commented Aug 30, 2019

For jacoco/jacoco#930 something like

public abstract class ExtendedAnalyzer extends Analyzer {

  public ExtendedAnalyzer(ExecutionDataStore executionData, ICoverageVisitor coverageVisitor) {
    super(executionData, coverageVisitor);
  }

  @Override
  public void analyzeClass(byte[] buffer, String location) throws IOException {
    String fileName = location.substring(location.lastIndexOf('/'));
    String binaryClassName = location.substring(0, fileName.length() - ".class".length());
    String className = binaryClassName.substring(0, binaryClassName.indexOf('$'));
    if (isExcluded(className))
      return;
    super.analyzeClass(buffer, location);
  }

  abstract boolean isExcluded(String className);

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment