public final static Location fixLocation()

in com.microsoft.java.lsif.core/src/com/microsoft/java/lsif/core/internal/JdtlsUtils.java [68:93]


	public final static Location fixLocation(IJavaElement element, Location location, IJavaProject javaProject) {
		if (!javaProject.equals(element.getJavaProject())
				&& element.getJavaProject().getProject().getName().equals(ProjectsManager.DEFAULT_PROJECT_NAME)) {
			// see issue at: https://github.com/eclipse/eclipse.jdt.ls/issues/842 and
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=541573
			// for jdk classes, jdt will reuse the java model by altering project to share
			// the model between projects
			// so that sometimes the project for `element` is default project and the
			// project is different from the project for `unit`
			// this fix is to replace the project name with non-default ones since default
			// project should be transparent to users.
			if (location.getUri().contains(ProjectsManager.DEFAULT_PROJECT_NAME)) {
				String patched = StringUtils.replaceOnce(location.getUri(), ProjectsManager.DEFAULT_PROJECT_NAME,
						javaProject.getProject().getName());
				try {
					IClassFile cf = (IClassFile) JavaCore.create(JDTUtils.toURI(patched).getQuery());
					if (cf != null && cf.exists()) {
						location.setUri(patched);
					}
				} catch (Exception ex) {

				}
			}
		}
		return location;
	}