
de.is24.deadcode4j.analyzer.CustomInterfacesAnalyzer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of deadcode4j-maven-plugin Show documentation
Show all versions of deadcode4j-maven-plugin Show documentation
Finds unused classes of a project
package de.is24.deadcode4j.analyzer;
import de.is24.deadcode4j.AnalysisContext;
import de.is24.deadcode4j.AnalysisSink;
import de.is24.deadcode4j.AnalyzedCode;
import javax.annotation.Nonnull;
import java.util.HashSet;
import static com.google.common.collect.Sets.newHashSet;
/**
* Analyzes class files: marks a class as being in use if it explicitly implements one of the specified interfaces.
*
* @since 1.4
*/
public final class CustomInterfacesAnalyzer extends InterfacesAnalyzer {
@Nonnull
private final HashSet interfacesNotFoundInClassPath;
/**
* Creates a new CustomInterfacesAnalyzer
.
*
* @param customInterfaces a list of fully qualified interface names indicating that the implementing class is in use
* @since 1.4
*/
public CustomInterfacesAnalyzer(@Nonnull Iterable customInterfaces) {
super("_custom-interfaces_", customInterfaces);
interfacesNotFoundInClassPath = newHashSet(customInterfaces);
}
@Override
public void finishAnalysis(@Nonnull AnalysisContext analysisContext) {
super.finishAnalysis(analysisContext);
interfacesNotFoundInClassPath.removeAll(getInterfacesFoundInClassPath(analysisContext));
}
@Override
public void finishAnalysis(@Nonnull AnalysisSink analysisSink, @Nonnull AnalyzedCode analyzedCode) {
super.finishAnalysis(analysisSink, analyzedCode);
for (String interfaceName : interfacesNotFoundInClassPath) {
logger.warn("Interface [{}] wasn't ever found in the class path. You should remove the configuration entry.", interfaceName);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy