Skip to content

Commit

Permalink
Bypass API analysis for classes from a test classpath entry
Browse files Browse the repository at this point in the history
  • Loading branch information
merks authored and laeubi committed Jun 26, 2024
1 parent a5391bd commit 40fe485
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ protected IApiProblem createProblem(IReference reference, IJavaProject javaProje
if (typeInProject != null) {
type =typeInProject;
}
if (type == null) {
if (type == null || Util.isTest(type)) {
return null;
}
ICompilationUnit compilationUnit = type.getCompilationUnit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,7 @@ private void checkSinceTags(final Delta delta, final IApiComponent component) {
return;
}
IMember member = Util.getIMember(delta, fJavaProject);
if (member == null || member.isBinary()) {
if (member == null || member.isBinary() || member instanceof IType iType && Util.isTest(iType)) {
return;
}
ICompilationUnit cunit = member.getCompilationUnit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IJavaElement;
Expand Down Expand Up @@ -2673,5 +2674,35 @@ public static IType findSourceTypeinJavaProject(IJavaProject javaProject, String
return type;
}

/**
* Returns whether the type is made available via a
* {@link IClasspathEntry#isTest() test classpath entry}.
*
* @param type the type in question.
* @return whether the type is made available via a test classpath entry.
*/
public static boolean isTest(IType type) {
try {
if (type != null) {
IPackageFragment packageFragment = type.getPackageFragment();
if (packageFragment != null) {
IJavaElement parent = packageFragment.getParent();
if (parent != null) {
IResource underlyingResource = parent.getUnderlyingResource();
if (underlyingResource != null) {
IClasspathEntry classPathEntry = type.getJavaProject()
.getClasspathEntryFor(underlyingResource.getFullPath());
if (classPathEntry.isTest()) {
return true;
}
}
}
}
}
} catch (JavaModelException e) {
// ignore
}
return false;
}

}

0 comments on commit 40fe485

Please sign in to comment.