[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Resubmit for 94135: Re: [cdt-patch] FIXED 94055- [open decls/refs/def] need to make sure that qualified names are used in the search engine
|
Resubmitting patch to include a fix
for 94135- All Declarations does not include the namespace scope in the
search pattern.
Note that there is no JUnit test for
this bug fix. I don't know how to register to the Index in a JUnit
to prevent race conditions.
Devin Steffler
IBM's Eclipse CDT
Ottawa (Palladium), Ontario, Canada
Devin Steffler/Ottawa/IBM@IBMCA
Sent by: cdt-patch-bounces@xxxxxxxxxxx
05/09/2005 09:01 AM
Please respond to
"CDT patches and commits are posted to this list." |
|
To
| cdt-patch@xxxxxxxxxxx
|
cc
|
|
Subject
| [cdt-patch] FIXED 94055-
[open decls/refs/def] need to make sure that qualified names are used in
the search engine |
|
FIXED 94055- [open decls/refs/def] need to make sure that qualified names
are used in the search engine
Also fixes F2/F3 with CTags so that the proper offsets are determined based
on the line number.
Devin Steffler
IBM's Eclipse CDT
Ottawa (Palladium), Ontario, Canada
_______________________________________________
cdt-patch mailing list
cdt-patch@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-patch
Index: search/org/eclipse/cdt/core/search/DOMSearchUtil.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/DOMSearchUtil.java,v
retrieving revision 1.5
diff -u -r1.5 DOMSearchUtil.java
--- search/org/eclipse/cdt/core/search/DOMSearchUtil.java 3 May 2005 18:48:20 -0000 1.5
+++ search/org/eclipse/cdt/core/search/DOMSearchUtil.java 9 May 2005 16:03:10 -0000
@@ -19,6 +19,7 @@
import org.eclipse.cdt.core.ICLogConstants;
import org.eclipse.cdt.core.dom.CDOM;
import org.eclipse.cdt.core.dom.IASTServiceProvider;
+import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
@@ -29,11 +30,15 @@
import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IFunction;
+import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
+import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
+import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
@@ -47,6 +52,8 @@
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.search.ICSearchConstants.LimitTo;
import org.eclipse.cdt.core.search.ICSearchConstants.SearchFor;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTQualifiedName;
import org.eclipse.cdt.internal.core.search.matching.CSearchPattern;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -72,11 +79,11 @@
* ( CSearchPattern.DECLARATION | CSearchPattern.REFERENCES | CSearchPattern.ALL_OCCURRENCES )
* @return
*/
- public static Set getMatchesFromSearchEngine(ICSearchScope scope, IASTName searchName, LimitTo limitTo) {
+ public static Set getMatchesFromSearchEngine(String searchPattern, ICSearchScope scope, IASTName searchName, LimitTo limitTo) {
SearchEngine engine = new SearchEngine();
BasicSearchResultCollector results = new BasicSearchResultCollector();
- ICSearchPattern pattern = createPattern(searchName.resolveBinding(), limitTo, true);
+ ICSearchPattern pattern = createPattern(searchPattern, searchName.resolveBinding(), limitTo, true);
try {
engine.search(CCorePlugin.getWorkspace(), pattern, scope, results, false);
@@ -87,7 +94,9 @@
return results.getSearchResults();
}
- private static CSearchPattern createPattern( IBinding binding, LimitTo limitTo, boolean caseSensitive) {
+ private static CSearchPattern createPattern( String searchPattern, IBinding binding, LimitTo limitTo, boolean caseSensitive) {
+ if (binding == null) return null;
+
// build the SearchFor/pattern based on the IBinding
SearchFor searchFor = createSearchFor(binding);
if (binding instanceof IFunction) {
@@ -127,7 +136,7 @@
searchFor = ICSearchConstants.UNKNOWN_SEARCH_FOR;
}
- return CSearchPattern.createPattern(binding.getName(), searchFor, limitTo, ICSearchConstants.EXACT_MATCH, caseSensitive);
+ return CSearchPattern.createPattern(searchPattern, searchFor, limitTo, ICSearchConstants.EXACT_MATCH, caseSensitive);
}
private static SearchFor createSearchFor( IBinding binding ) {
@@ -187,7 +196,7 @@
public static IASTName[] getSelectedNamesFrom(IASTTranslationUnit tu, int offset, int length, ParserLanguage lang) {
IASTNode node = null;
try{
- node = tu.selectNodeForLocation(tu.getFilePath(), offset, length); // TODO Devin untested tu.getContainingFilename() ...
+ node = tu.selectNodeForLocation(tu.getFilePath(), offset, length);
}
catch (ParseError er){}
catch ( VirtualMachineError vmErr){
@@ -410,6 +419,13 @@
public int size() { return nameList.size(); }
}
+ /**
+ * Returns the ParserLanguage corresponding to the IPath and IProject. Returns ParserLanguage.CPP if the file type is a header.
+ *
+ * @param path
+ * @param project
+ * @return
+ */
public static ParserLanguage getLanguage( IPath path, IProject project )
{
ICFileType type = CCorePlugin.getDefault().getFileType(project, path.lastSegment());
@@ -423,4 +439,72 @@
return ParserLanguage.C;
return ParserLanguage.CPP;
}
+
+ /**
+ * Generates a search pattern String based on the IASTName passed as a parameter.
+ *
+ * Used to generate a string to present to the user as well as a string used by
+ * the SearchEngine to parse for qualified names and parameters.
+ *
+ * @param name
+ * @return
+ */
+ public static String getSearchPattern(IASTName name) {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("::"); //$NON-NLS-1$
+
+ String[] namespaces = null;
+
+ IASTNode parent = name.getParent();
+ while(!(parent instanceof IASTTranslationUnit) && parent != null) {
+ if (parent instanceof ICPPASTNamespaceDefinition) {
+ namespaces = (String[])ArrayUtil.append(String.class, namespaces, ((ICPPASTNamespaceDefinition)parent).getName().toString());
+ }
+ parent = parent.getParent();
+ }
+
+ if (namespaces != null && namespaces.length > 0) {
+ for( int i=namespaces.length-1; i>=0; i-- ) {
+ if (namespaces[i] != null) {
+ buffer.append(namespaces[i]);
+ buffer.append("::"); //$NON-NLS-1$
+ }
+ }
+ }
+
+ if (name instanceof CPPASTName && name.getParent() instanceof CPPASTQualifiedName) {
+ IASTName[] names = ((CPPASTQualifiedName)name.getParent()).getNames();
+ for(int i=0; i<names.length; i++) {
+ if (i != 0) buffer.append("::"); //$NON-NLS-1$
+ buffer.append(names[i].toString());
+ }
+ } else {
+ buffer.append(name.toString());
+ }
+
+ if( name.resolveBinding() instanceof IFunction ){
+ try {
+ IBinding binding = name.resolveBinding();
+ IFunctionType type = ((IFunction)binding).getType();
+
+ buffer.append("("); //$NON-NLS-1$
+ if (binding instanceof ICExternalBinding) {
+ buffer.append("..."); //$NON-NLS-1$
+ } else {
+ IType[] parms = type.getParameterTypes();
+ for( int i = 0; i < parms.length; i++ ){
+ if( i != 0 )
+ buffer.append(", "); //$NON-NLS-1$
+ buffer.append(ASTTypeUtil.getType(parms[i]));
+ }
+ }
+ buffer.append(")"); //$NON-NLS-1$
+ } catch (DOMException e) {
+ buffer = new StringBuffer();
+ buffer.append(name.toString());
+ }
+ }
+
+ return buffer.toString();
+ }
}
Index: src/org/eclipse/cdt/internal/ui/search/DOMQuery.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/DOMQuery.java,v
retrieving revision 1.1
diff -u -r1.1 DOMQuery.java
--- src/org/eclipse/cdt/internal/ui/search/DOMQuery.java 27 Apr 2005 17:43:28 -0000 1.1
+++ src/org/eclipse/cdt/internal/ui/search/DOMQuery.java 9 May 2005 16:03:24 -0000
@@ -70,12 +70,14 @@
private IASTName searchName=null;
private LimitTo limitTo=null;
private ICSearchScope scope=null;
+ private String searchPattern=null;
public DOMQuery(String displaySearchPattern, IASTName name, LimitTo limitTo, ICSearchScope scope, ICSearchResultCollector collector) {
super(CUIPlugin.getWorkspace(), displaySearchPattern, false, null, null, null, displaySearchPattern, collector);
this.searchName = name;
this.limitTo = limitTo;
this.scope = scope;
+ this.searchPattern = displaySearchPattern;
}
/* (non-Javadoc)
@@ -88,7 +90,7 @@
NewSearchResultCollector collector = new NewSearchResultCollector(textResult, mainSearchPM);
collector.aboutToStart();
- Set matches = DOMSearchUtil.getMatchesFromSearchEngine(scope, searchName, limitTo);
+ Set matches = DOMSearchUtil.getMatchesFromSearchEngine(searchPattern, scope, searchName, limitTo);
if (matches != null && matches.size() > 0) {
Iterator itr = matches.iterator();
while(itr.hasNext()) {
Index: src/org/eclipse/cdt/internal/ui/search/actions/FindAction.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindAction.java,v
retrieving revision 1.17
diff -u -r1.17 FindAction.java
--- src/org/eclipse/cdt/internal/ui/search/actions/FindAction.java 3 May 2005 18:48:24 -0000 1.17
+++ src/org/eclipse/cdt/internal/ui/search/actions/FindAction.java 9 May 2005 16:03:24 -0000
@@ -20,17 +20,10 @@
import org.eclipse.cdt.core.dom.CDOM;
import org.eclipse.cdt.core.dom.IASTServiceProvider;
import org.eclipse.cdt.core.dom.IASTServiceProvider.UnsupportedDialectException;
-import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
-import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
-import org.eclipse.cdt.core.dom.ast.IBinding;
-import org.eclipse.cdt.core.dom.ast.IFunction;
-import org.eclipse.cdt.core.dom.ast.IFunctionType;
-import org.eclipse.cdt.core.dom.ast.IType;
-import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.parser.ParseError;
@@ -40,8 +33,6 @@
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.ICSearchConstants.LimitTo;
import org.eclipse.cdt.core.search.ICSearchConstants.SearchFor;
-import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
-import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTQualifiedName;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.search.CSearchQuery;
import org.eclipse.cdt.internal.ui.search.CSearchResultCollector;
@@ -84,42 +75,7 @@
* @return
*/
public static CSearchQuery createDOMSearchQueryForName( IASTName name, LimitTo limitTo, ICSearchScope scope, ICSearchResultCollector collector ){
- StringBuffer buffer = new StringBuffer();
- buffer.append("::"); //$NON-NLS-1$
- if (name instanceof CPPASTName && name.getParent() instanceof CPPASTQualifiedName) {
- IASTName[] names = ((CPPASTQualifiedName)name.getParent()).getNames();
- for(int i=0; i<names.length; i++) {
- if (i != 0) buffer.append("::"); //$NON-NLS-1$
- buffer.append(names[i].toString());
- }
- } else {
- buffer.append(name.toString());
- }
-
- if( name.resolveBinding() instanceof IFunction ){
- try {
- IBinding binding = name.resolveBinding();
- IFunctionType type = ((IFunction)binding).getType();
-
- buffer.append("("); //$NON-NLS-1$
- if (binding instanceof ICExternalBinding) {
- buffer.append("..."); //$NON-NLS-1$
- } else {
- IType[] parms = type.getParameterTypes();
- for( int i = 0; i < parms.length; i++ ){
- if( i != 0 )
- buffer.append(", "); //$NON-NLS-1$
- buffer.append(ASTTypeUtil.getType(parms[i]));
- }
- }
- buffer.append(")"); //$NON-NLS-1$
- } catch (DOMException e) {
- buffer = new StringBuffer();
- buffer.append(name.toString());
- }
- }
-
- return new DOMQuery(buffer.toString(), name, limitTo, scope, collector);
+ return new DOMQuery(DOMSearchUtil.getSearchPattern(name), name, limitTo, scope, collector);
}
/**
Index: src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java,v
retrieving revision 1.15
diff -u -r1.15 OpenDeclarationsAction.java
--- src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java 3 May 2005 18:48:24 -0000 1.15
+++ src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java 9 May 2005 16:03:24 -0000
@@ -24,10 +24,12 @@
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserUtil;
+import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.core.search.DOMSearchUtil;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.core.search.SearchEngine;
+import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.model.CProject;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.editor.CEditorMessages;
@@ -153,7 +155,7 @@
// step 3 starts here
ICElement[] scope = new ICElement[1];
scope[0] = new CProject(null, fEditor.getInputFile().getProject());
- Set matches = DOMSearchUtil.getMatchesFromSearchEngine(SearchEngine.createCSearchScope(scope), searchName, ICSearchConstants.DECLARATIONS);
+ Set matches = DOMSearchUtil.getMatchesFromSearchEngine(DOMSearchUtil.getSearchPattern(searchName), SearchEngine.createCSearchScope(scope), searchName, ICSearchConstants.DECLARATIONS);
if (matches != null && matches.size() > 0) {
Iterator itr = matches.iterator();
@@ -165,6 +167,8 @@
storage.setLength(theMatch.getEndOffset() - theMatch.getStartOffset());
storage.setOffset(theMatch.getStartOffset());
storage.setResource(ParserUtil.getResourceForFilename(theMatch.getLocation().toOSString()));
+ if (match instanceof BasicSearchMatch)
+ storage.setOffsetLineNumber(((BasicSearchMatch)match).getOffsetType() == IIndex.LINE);
break;
}
}
@@ -204,14 +208,14 @@
if( storage.getResource() != null )
{
clearStatusLine();
- open( storage.getResource(), nameOffset, nameLength );
+ open( storage.getResource(), nameOffset, nameLength, storage.isOffsetLineNumber() );
return;
}
String fileName = storage.getFileName();
if (fileName != null){
clearStatusLine();
- open( fileName, nameOffset, nameLength);
+ open( fileName, nameOffset, nameLength, storage.isOffsetLineNumber());
}
} catch(Exception x) {
Index: src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java,v
retrieving revision 1.2
diff -u -r1.2 OpenDefinitionAction.java
--- src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java 3 May 2005 18:48:24 -0000 1.2
+++ src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java 9 May 2005 16:03:24 -0000
@@ -23,10 +23,12 @@
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserUtil;
+import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.core.search.DOMSearchUtil;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.core.search.SearchEngine;
+import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.model.CProject;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.editor.CEditorMessages;
@@ -166,7 +168,7 @@
// step 3 starts here
ICElement[] scope = new ICElement[1];
scope[0] = new CProject(null, fEditor.getInputFile().getProject());
- Set matches = DOMSearchUtil.getMatchesFromSearchEngine(SearchEngine.createCSearchScope(scope), searchName, ICSearchConstants.DEFINITIONS);
+ Set matches = DOMSearchUtil.getMatchesFromSearchEngine(DOMSearchUtil.getSearchPattern(searchName), SearchEngine.createCSearchScope(scope), searchName, ICSearchConstants.DEFINITIONS);
if (matches != null && matches.size() > 0) {
Iterator itr = matches.iterator();
@@ -178,6 +180,8 @@
storage.setLength(theMatch.getEndOffset() - theMatch.getStartOffset());
storage.setOffset(theMatch.getStartOffset());
storage.setResource(ParserUtil.getResourceForFilename(theMatch.getLocation().toOSString()));
+ if (match instanceof BasicSearchMatch)
+ storage.setOffsetLineNumber(((BasicSearchMatch)match).getOffsetType() == IIndex.LINE);
break;
}
}
@@ -217,14 +221,14 @@
if( storage.getResource() != null )
{
clearStatusLine();
- open( storage.getResource(), nameOffset, nameLength );
+ open( storage.getResource(), nameOffset, nameLength, storage.isOffsetLineNumber() );
return;
}
String fileName = storage.getFileName();
if (fileName != null){
clearStatusLine();
- open( fileName, nameOffset, nameLength);
+ open( fileName, nameOffset, nameLength, storage.isOffsetLineNumber());
}
} catch(Exception x) {
CUIPlugin.getDefault().log(x);
Index: src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java,v
retrieving revision 1.10
diff -u -r1.10 SelectionParseAction.java
--- src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java 3 May 2005 15:48:34 -0000 1.10
+++ src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java 9 May 2005 16:03:24 -0000
@@ -32,7 +32,6 @@
import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.core.resources.FileStorage;
-import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.search.CSearchMessages;
import org.eclipse.cdt.internal.ui.util.EditorUtility;
@@ -553,6 +552,7 @@
private String fileName;
private int offset=0;
private int length=0;
+ private boolean offsetLineNumber=false;
public final String getFileName() {
return fileName;
@@ -580,6 +580,12 @@
public void setResource(IResource resource) {
this.resource = resource;
}
+ public boolean isOffsetLineNumber() {
+ return offsetLineNumber;
+ }
+ public void setOffsetLineNumber(boolean offsetLineNumber) {
+ this.offsetLineNumber = offsetLineNumber;
+ }
}
@@ -587,25 +593,25 @@
* @param string
* @param i
*/
- protected boolean open(String filename, int offset, int length) throws PartInitException, CModelException {
+ protected boolean open(String filename, int offset, int length, boolean isLineNumber) throws PartInitException, CModelException {
IPath path = new Path( filename );
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
if( file != null )
{
- open( file, offset, length );
+ open( file, offset, length, isLineNumber );
return true;
}
ICProject cproject = CoreModel.getDefault().getCModel().getCProject( projectName );
ITranslationUnit unit = CoreModel.getDefault().createTranslationUnitFrom(cproject, path);
if (unit != null) {
- setSelectionAtOffset( EditorUtility.openInEditor(unit), offset, length );
+ setSelectionAtOffset( EditorUtility.openInEditor(unit), offset, length, isLineNumber );
return true;
}
FileStorage storage = new FileStorage(null, path);
IEditorPart part = EditorUtility.openInEditor(storage);
- setSelectionAtOffset(part, offset, length);
+ setSelectionAtOffset(part, offset, length, isLineNumber);
return true;
}
@@ -613,18 +619,12 @@
return fEditor.getSite().getShell();
}
-
- protected void open( IMatch element ) throws CModelException, PartInitException
- {
- open( element.getResource(), element.getStartOffset(), element.getEndOffset() - element.getStartOffset() );
- }
-
/**
* Opens the editor on the given element and subsequently selects it.
*/
- protected void open( IResource resource, int offset, int length ) throws CModelException, PartInitException {
+ protected void open( IResource resource, int offset, int length, boolean isLineNumber ) throws CModelException, PartInitException {
IEditorPart part= EditorUtility.openInEditor(resource);
- setSelectionAtOffset(part, offset, length);
+ setSelectionAtOffset(part, offset, length, isLineNumber);
}
/**
@@ -632,11 +632,27 @@
* @param offset
* @param length TODO
*/
- protected void setSelectionAtOffset(IEditorPart part, int offset, int length) {
+ protected void setSelectionAtOffset(IEditorPart part, int offset, int length, boolean isLineNumber) {
if( part instanceof AbstractTextEditor )
{
+ int actualOffset=0;
+ int actualLength=0;
+
+ if (isLineNumber) {
+ IDocumentProvider docProv = ((AbstractTextEditor)part).getDocumentProvider();
+ IDocument doc = docProv.getDocument(part.getEditorInput());
+ try {
+ actualOffset = doc.getLineOffset(offset-1);
+ actualLength = doc.getLineLength(offset-1);
+ } catch (BadLocationException e) {
+ }
+ } else {
+ actualOffset=offset;
+ actualLength=length;
+ }
+
try {
- ((AbstractTextEditor) part).selectAndReveal(offset, length);
+ ((AbstractTextEditor) part).selectAndReveal(actualOffset, actualLength);
} catch (Exception e) {}
}
}