Search in sources :

Example 1 with OccurrencesFinder

use of org.eclipse.jdt.internal.core.manipulation.search.OccurrencesFinder in project eclipse.jdt.ls by eclipse.

the class DocumentHighlightHandler method computeOccurrences.

private List<DocumentHighlight> computeOccurrences(ITypeRoot unit, int line, int column, IProgressMonitor monitor) {
    if (unit != null) {
        try {
            int offset = JsonRpcHelpers.toOffset(unit.getBuffer(), line, column);
            OccurrencesFinder finder = new OccurrencesFinder();
            CompilationUnit ast = CoreASTProvider.getInstance().getAST(unit, CoreASTProvider.WAIT_YES, monitor);
            if (ast != null) {
                String error = finder.initialize(ast, offset, 0);
                if (error == null) {
                    List<DocumentHighlight> result = new ArrayList<>();
                    OccurrenceLocation[] occurrences = finder.getOccurrences();
                    if (occurrences != null) {
                        for (OccurrenceLocation loc : occurrences) {
                            if (monitor.isCanceled()) {
                                return Collections.emptyList();
                            }
                            result.add(convertToHighlight(unit, loc));
                        }
                    }
                    return result;
                }
            }
        } catch (JavaModelException e) {
            JavaLanguageServerPlugin.logException("Problem with compute occurrences for" + unit.getElementName(), e);
        }
    }
    return Collections.emptyList();
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) DocumentHighlight(org.eclipse.lsp4j.DocumentHighlight) JavaModelException(org.eclipse.jdt.core.JavaModelException) ArrayList(java.util.ArrayList) OccurrenceLocation(org.eclipse.jdt.internal.core.manipulation.search.IOccurrencesFinder.OccurrenceLocation) IOccurrencesFinder(org.eclipse.jdt.internal.core.manipulation.search.IOccurrencesFinder) OccurrencesFinder(org.eclipse.jdt.internal.core.manipulation.search.OccurrencesFinder)

Aggregations

ArrayList (java.util.ArrayList)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)1 IOccurrencesFinder (org.eclipse.jdt.internal.core.manipulation.search.IOccurrencesFinder)1 OccurrenceLocation (org.eclipse.jdt.internal.core.manipulation.search.IOccurrencesFinder.OccurrenceLocation)1 OccurrencesFinder (org.eclipse.jdt.internal.core.manipulation.search.OccurrencesFinder)1 DocumentHighlight (org.eclipse.lsp4j.DocumentHighlight)1