Java Code Examples for org.eclipse.jdt.ls.core.internal.JDTUtils#findFile()

The following examples show how to use org.eclipse.jdt.ls.core.internal.JDTUtils#findFile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SyntaxDocumentLifeCycleHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public ICompilationUnit resolveCompilationUnit(String uri) {
	IFile resource = JDTUtils.findFile(uri);
	ICompilationUnit unit = JDTUtils.resolveCompilationUnit(resource);
	if (JDTUtils.isOnClassPath(unit)) {
		return unit;
	}

	// Open file not on the classpath.
	IPath filePath = ResourceUtils.canonicalFilePathFromURI(uri);
	Collection<IPath> rootPaths = preferenceManager.getPreferences().getRootPaths();
	Optional<IPath> belongedRootPath = rootPaths.stream().filter(rootPath -> rootPath.isPrefixOf(filePath)).findFirst();
	if (belongedRootPath.isPresent()) {
		if (tryUpdateClasspath(filePath, belongedRootPath.get())) {
			unit = JDTUtils.resolveCompilationUnit(uri);
			projectsManager.registerWatchers(true);;
		}
	}

	if (unit == null) {
		unit = JDTUtils.getFakeCompilationUnit(uri);
	}

	return unit;
}
 
Example 2
Source File: DelegateCommandHandler.java    From vscode-checkstyle with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected Map<String, List<CheckResult>> checkCode(List<String> filesToCheckUris) throws Exception {
    if (filesToCheckUris.isEmpty() || checkerService == null) {
        return Collections.emptyMap();
    }
    final List<File> filesToCheck = filesToCheckUris.stream().map(File::new).collect(Collectors.toList());
    final IFile resource = JDTUtils.findFile(filesToCheck.get(0).toURI().toString());
    return checkerService.checkCode(filesToCheck, resource != null ? resource.getCharset() : "utf8");
}
 
Example 3
Source File: ProjectConfigurationUpdateHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public void updateConfiguration(TextDocumentIdentifier param) {
	IFile file = JDTUtils.findFile(param.getUri());
	if (file == null) {
		return;
	}
	// most likely the handler is invoked intentionally by the user, that's why
	// we force the update despite no changes of in build descriptor being made
	projectManager.updateProject(file.getProject(), true);
}