@Test public void testReference(){ URI uri = project.getFile("src/java/Foo2.java").getRawLocationURI(); String fileURI = ResourceUtils.fixURI(uri); ReferenceParams param = new ReferenceParams(); param.setPosition(new Position(5,16)); param.setContext(new ReferenceContext(true)); param.setTextDocument( new TextDocumentIdentifier(fileURI)); List<Location> references = handler.findReferences(param, monitor); assertNotNull("findReferences should not return null",references); assertEquals(1, references.size()); Location l = references.get(0); String refereeUri = ResourceUtils.fixURI(project.getFile("src/java/Foo3.java").getRawLocationURI()); assertEquals(refereeUri, l.getUri()); }
@Override public CompletableFuture<List<? extends Location>> references(final ReferenceParams params) { final Function1<CancelIndicator, List<? extends Location>> _function = (CancelIndicator cancelIndicator) -> { final URI uri = this._uriExtensions.toUri(params.getTextDocument().getUri()); final IResourceServiceProvider resourceServiceProvider = this.languagesRegistry.getResourceServiceProvider(uri); DocumentSymbolService _get = null; if (resourceServiceProvider!=null) { _get=resourceServiceProvider.<DocumentSymbolService>get(DocumentSymbolService.class); } final DocumentSymbolService documentSymbolService = _get; if ((documentSymbolService == null)) { return CollectionLiterals.<Location>emptyList(); } final Function2<Document, XtextResource, List<? extends Location>> _function_1 = (Document document, XtextResource resource) -> { return documentSymbolService.getReferences(document, resource, params, this.resourceAccess, this.workspaceManager.getIndex(), cancelIndicator); }; return this.workspaceManager.<List<? extends Location>>doRead(uri, _function_1); }; return this.requestManager.<List<? extends Location>>runRead(_function); }
@Test public void testEmpty(){ ReferenceParams param = new ReferenceParams(); param.setPosition(new Position(1, 1)); param.setContext(new ReferenceContext(false)); param.setTextDocument( new TextDocumentIdentifier("/foo/bar")); List<Location> references = handler.findReferences(param, monitor); assertNotNull(references); assertTrue("references are not empty", references.isEmpty()); }
public List<? extends Location> getReferences(final Document document, final XtextResource resource, final ReferenceParams params, final IReferenceFinder.IResourceAccess resourceAccess, final IResourceDescriptions indexData, final CancelIndicator cancelIndicator) { final int offset = document.getOffSet(params.getPosition()); List<? extends Location> _xifexpression = null; boolean _isIncludeDeclaration = params.getContext().isIncludeDeclaration(); if (_isIncludeDeclaration) { _xifexpression = this.getDefinitions(resource, offset, resourceAccess, cancelIndicator); } else { _xifexpression = CollectionLiterals.emptyList(); } final List<? extends Location> definitions = _xifexpression; final List<? extends Location> references = this.getReferences(resource, offset, resourceAccess, indexData, cancelIndicator); final Iterable<Location> result = Iterables.<Location>concat(definitions, references); return IterableExtensions.<Location>toList(result); }
@Override public void actionPerformed(ActionEvent e) { EditorPartPresenter activeEditor = editorAgent.getActiveEditor(); // TODO replace this if (!(activeEditor instanceof TextEditor)) { return; } TextEditor textEditor = ((TextEditor) activeEditor); String path = activeEditor.getEditorInput().getFile().getLocation().toString(); ReferenceParams paramsDTO = dtoFactory.createDto(ReferenceParams.class); Position Position = dtoFactory.createDto(Position.class); Position.setLine(textEditor.getCursorPosition().getLine()); Position.setCharacter(textEditor.getCursorPosition().getCharacter()); TextDocumentIdentifier identifierDTO = dtoFactory.createDto(TextDocumentIdentifier.class); identifierDTO.setUri(path); ReferenceContext contextDTO = dtoFactory.createDto(ReferenceContext.class); contextDTO.setIncludeDeclaration(true); paramsDTO.setUri(path); paramsDTO.setPosition(Position); paramsDTO.setTextDocument(identifierDTO); paramsDTO.setContext(contextDTO); Promise<List<Location>> promise = client.references(paramsDTO); presenter.openLocation(promise); }
@Override public CompletableFuture<List<? extends Location>> references(ReferenceParams params) { LOGGER.info("references: " + params.getTextDocument()); return CompletableFuture.completedFuture(Collections.emptyList()); }
@Override public CompletableFuture<List<? extends Location>> references(final ReferenceParams params) { // TODO Auto-generated method stub return null; }
@Override public CompletableFuture<List<? extends Location>> references(ReferenceParams params) { logInfo(">> document/references"); ReferencesHandler handler = new ReferencesHandler(this.preferenceManager); return computeAsync((cc) -> handler.findReferences(params, toMonitor(cc))); }
public List<Location> findReferences(ReferenceParams param, IProgressMonitor monitor) { final List<Location> locations = new ArrayList<>(); try { IJavaElement elementToSearch = JDTUtils.findElementAtSelection(JDTUtils.resolveTypeRoot(param.getTextDocument().getUri()), param.getPosition().getLine(), param.getPosition().getCharacter(), this.preferenceManager, monitor); if(elementToSearch == null) { return locations; } SearchEngine engine = new SearchEngine(); SearchPattern pattern = SearchPattern.createPattern(elementToSearch, IJavaSearchConstants.REFERENCES); engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, createSearchScope(), new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { Object o = match.getElement(); if (o instanceof IJavaElement) { IJavaElement element = (IJavaElement) o; ICompilationUnit compilationUnit = (ICompilationUnit) element .getAncestor(IJavaElement.COMPILATION_UNIT); Location location = null; if (compilationUnit != null) { location = JDTUtils.toLocation(compilationUnit, match.getOffset(), match.getLength()); } else{ IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE); if (cf != null && cf.getSourceRange() != null) { location = JDTUtils.toLocation(cf, match.getOffset(), match.getLength()); } } if (location != null ) { locations.add(location); } } } }, monitor); } catch (CoreException e) { JavaLanguageServerPlugin.logException("Find references failure ", e); } return locations; }
@Override public CompletableFuture<List<? extends Location>> references(ReferenceParams params) { throw new UnsupportedOperationException(); }
@Override public CompletableFuture<List<? extends Location>> references(ReferenceParams params) { return null; }
@PostConstruct public void configureMethods() { dtoToDtoList( "definition", TextDocumentPositionParams.class, LocationDto.class, this::definition); dtoToDtoList("codeAction", CodeActionParams.class, CommandDto.class, this::codeAction); dtoToDtoList( "documentSymbol", DocumentSymbolParams.class, SymbolInformationDto.class, this::documentSymbol); dtoToDtoList("formatting", DocumentFormattingParams.class, TextEditDto.class, this::formatting); dtoToDtoList( "rangeFormatting", DocumentRangeFormattingParams.class, TextEditDto.class, this::rangeFormatting); dtoToDtoList("references", ReferenceParams.class, LocationDto.class, this::references); dtoToDtoList( "onTypeFormatting", DocumentOnTypeFormattingParams.class, TextEditDto.class, this::onTypeFormatting); dtoToDto( "completionItem/resolve", ExtendedCompletionItem.class, ExtendedCompletionItemDto.class, this::completionItemResolve); dtoToDto( "documentHighlight", TextDocumentPositionParams.class, DocumentHighlight.class, this::documentHighlight); dtoToDto( "completion", TextDocumentPositionParams.class, ExtendedCompletionListDto.class, this::completion); dtoToDto("hover", TextDocumentPositionParams.class, HoverDto.class, this::hover); dtoToDto( "signatureHelp", TextDocumentPositionParams.class, SignatureHelpDto.class, this::signatureHelp); dtoToDto("rename", RenameParams.class, RenameResultDto.class, this::rename); dtoToNothing("didChange", DidChangeTextDocumentParams.class, this::didChange); dtoToNothing("didClose", DidCloseTextDocumentParams.class, this::didClose); dtoToNothing("didOpen", DidOpenTextDocumentParams.class, this::didOpen); dtoToNothing("didSave", DidSaveTextDocumentParams.class, this::didSave); }
/** * The references request is sent from the client to the server to resolve * project-wide references for the symbol denoted by the given text document * position. * * Registration Options: TextDocumentRegistrationOptions */ @JsonRequest CompletableFuture<List<? extends Location>> references(ReferenceParams params);
/** * GWT client implementation of {@link TextDocumentService#references(ReferenceParams)} * * @param params * @return */ public Promise<List<Location>> references(ReferenceParams params) { return transmitDtoAndReceiveDtoList(params, "textDocument/references", Location.class); }