mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 10:16:03 +02:00
Fix for 174568, navigation of namespace members.
This commit is contained in:
parent
ed4ed2309a
commit
0bcbbd2a29
1 changed files with 57 additions and 83 deletions
|
@ -8,12 +8,11 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* P.Tomaszewski
|
* P.Tomaszewski
|
||||||
* Anton Leherbauer (Wind River Systems)
|
* Anton Leherbauer (Wind River Systems)
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.actions;
|
package org.eclipse.cdt.internal.ui.actions;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
import org.eclipse.jface.text.ITextSelection;
|
import org.eclipse.jface.text.ITextSelection;
|
||||||
|
@ -23,6 +22,8 @@ import org.eclipse.ui.texteditor.TextEditorAction;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
import org.eclipse.cdt.core.model.IParent;
|
||||||
|
import org.eclipse.cdt.core.model.ISourceRange;
|
||||||
import org.eclipse.cdt.core.model.ISourceReference;
|
import org.eclipse.cdt.core.model.ISourceReference;
|
||||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
@ -89,91 +90,64 @@ public class GoToNextPreviousMemberAction extends TextEditorAction {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final ICElement[] elements = workingCopy.getChildren();
|
ISourceReference next= fGotoNext ?
|
||||||
final Integer[] elementOffsets = createSourceIndexes(elements);
|
getNextElement(workingCopy, selection.getOffset()) :
|
||||||
final ICElement selectedElement = workingCopy.getElementAtOffset(selection.getOffset());
|
getPrevElement(workingCopy, selection.getOffset());
|
||||||
if (selectedElement != null && selectedElement instanceof ISourceReference) {
|
if (next != null) {
|
||||||
final int offset = ((ISourceReference) selectedElement).getSourceRange().getStartPos();
|
editor.selectAndReveal(next.getSourceRange().getIdStartPos(), 0);
|
||||||
final int offsetToSelect = fGotoNext ? getNextOffset(elementOffsets, offset) : getPreviousOffset(elementOffsets, offset);
|
|
||||||
editor.selectAndReveal(offsetToSelect, 0);
|
|
||||||
} else if (selectedElement == null) {
|
|
||||||
final int offset = selection.getOffset();
|
|
||||||
final int offsetToSelect = fGotoNext ? getNextOffset(elementOffsets, offset) : getPreviousOffset(elementOffsets, offset);
|
|
||||||
editor.selectAndReveal(offsetToSelect, 0);
|
|
||||||
} else {
|
|
||||||
//System.out.println("Selected element class:" + selectedElement.getClass()); //$NON-NLS-1$
|
|
||||||
}
|
}
|
||||||
} catch (CModelException e) {
|
} catch (CModelException e) {
|
||||||
CUIPlugin.getDefault().log(e);
|
CUIPlugin.getDefault().log(e);
|
||||||
//System.out.println("Exception:" + e.getMessage()); //$NON-NLS-1$
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private ISourceReference getNextElement(IParent parent, int offset) throws CModelException {
|
||||||
* Searches for next offset within array of offsets.
|
ICElement[] children= parent.getChildren();
|
||||||
* @param offsets Offsets to search.
|
for (int i = 0; i < children.length; i++) {
|
||||||
* @param actualOffset Actual offsets.
|
ICElement element = children[i];
|
||||||
* @return Found offset or actual.
|
if (element instanceof ISourceReference) {
|
||||||
*/
|
final ISourceReference candidate1= (ISourceReference) element;
|
||||||
private static int getNextOffset(Integer[] offsets, int actualOffset) {
|
final ISourceRange range= candidate1.getSourceRange();
|
||||||
if (offsets.length > 0) {
|
final int idpos1= range.getIdStartPos();
|
||||||
if (actualOffset < offsets[0].intValue())
|
if (element instanceof IParent && range.getStartPos() + range.getLength() > offset) {
|
||||||
{
|
ISourceReference candidate2= getNextElement((IParent) element, offset);
|
||||||
return offsets[0].intValue();
|
if (candidate2 != null) {
|
||||||
}
|
final int idpos2= candidate2.getSourceRange().getIdStartPos();
|
||||||
}
|
if (idpos1 <= offset || idpos1 > idpos2) {
|
||||||
for (int i = 0; i < offsets.length - 1; i++) {
|
return candidate2;
|
||||||
if (offsets[i].intValue() == actualOffset) {
|
}
|
||||||
return offsets[i + 1].intValue();
|
}
|
||||||
} else if ((actualOffset > offsets[i].intValue())
|
}
|
||||||
&& (actualOffset < offsets[i + 1].intValue())) {
|
if (idpos1 > offset) {
|
||||||
return offsets[i + 1].intValue();
|
return candidate1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return actualOffset;
|
}
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
private ISourceReference getPrevElement(IParent parent, int offset) throws CModelException {
|
||||||
* Searches for previous offset within array of offsets.
|
ICElement[] children= parent.getChildren();
|
||||||
* @param offsets Offsets to search.
|
for (int i= children.length-1; i >= 0; i--) {
|
||||||
* @param actualOffset Actual offset.
|
ICElement element = children[i];
|
||||||
* @return Found offset or actual.
|
if (element instanceof ISourceReference) {
|
||||||
*/
|
final ISourceReference candidate1= (ISourceReference) element;
|
||||||
private static int getPreviousOffset(Integer[] offsets, int actualOffset) {
|
final ISourceRange range= candidate1.getSourceRange();
|
||||||
if (offsets.length > 0) {
|
final int idpos1= range.getIdStartPos();
|
||||||
if (actualOffset > offsets[offsets.length - 1].intValue())
|
if (element instanceof IParent && range.getStartPos() < offset) {
|
||||||
{
|
ISourceReference candidate2= getPrevElement((IParent) element, offset);
|
||||||
return offsets[offsets.length - 1].intValue();
|
if (candidate2 != null) {
|
||||||
}
|
final int idpos2= candidate2.getSourceRange().getIdStartPos();
|
||||||
}
|
if (idpos1 >= offset || idpos1 < idpos2) {
|
||||||
for (int i = 1; i < offsets.length; i++) {
|
return candidate2;
|
||||||
if (offsets[i].intValue() == actualOffset) {
|
}
|
||||||
return offsets[i - 1].intValue();
|
}
|
||||||
} else if ((actualOffset > offsets[i - 1].intValue())
|
}
|
||||||
&& (actualOffset < offsets[i].intValue())) {
|
if (idpos1 < offset) {
|
||||||
return offsets[i - 1].intValue();
|
return candidate1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return actualOffset;
|
}
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Creates array in indexes from ICElements.
|
|
||||||
* @param elements Elements to retrieve needed data.
|
|
||||||
* @return indexes.
|
|
||||||
* @throws CModelException Thrown if source range not found.
|
|
||||||
*/
|
|
||||||
private static Integer[] createSourceIndexes(ICElement[] elements) throws CModelException
|
|
||||||
{
|
|
||||||
final List indexesList = new LinkedList();
|
|
||||||
for (int i = 0; i < elements.length; i++) {
|
|
||||||
if (elements[i] instanceof ISourceReference) {
|
|
||||||
indexesList.add(new Integer(((ISourceReference) elements[i]).getSourceRange().getStartPos()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//System.out.println("Indexes list:" + indexesList); //$NON-NLS-1$
|
|
||||||
final Integer[] indexes = new Integer[indexesList.size()];
|
|
||||||
indexesList.toArray(indexes);
|
|
||||||
return indexes;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue