blob: a948da97a7383b44d1da3cdcaf12d695f3d5488e [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2009, 2019 Stephan Wahlbrink and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
package org.eclipse.statet.internal.r.ui.editors;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.statet.ltk.ui.sourceediting.ISourceEditor;
import org.eclipse.statet.r.core.model.IRSourceUnit;
import org.eclipse.statet.r.core.model.RElementAccess;
import org.eclipse.statet.r.ui.sourceediting.ROpenDeclarationHandler;
public class RElementHyperlinkDetector extends AbstractHyperlinkDetector {
public RElementHyperlinkDetector() {
}
@Override
public IHyperlink[] detectHyperlinks(final ITextViewer textViewer,
final IRegion region, final boolean canShowMultipleHyperlinks) {
final ISourceEditor editor= getAdapter(ISourceEditor.class);
if (editor == null) {
return null;
}
final List<IHyperlink> hyperlinks= new ArrayList<>(4);
final RElementAccess access= ROpenDeclarationHandler.searchAccess(editor, region);
if (access != null) {
hyperlinks.add(new OpenRElementHyperlink(editor, (IRSourceUnit) editor.getSourceUnit(), access));
}
if (!hyperlinks.isEmpty()) {
return hyperlinks.toArray(new IHyperlink[hyperlinks.size()]);
}
return null;
}
}