Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bypass API analysis for classes from a test classpath entry #1313

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}

}
Loading