1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 06:32:10 +02:00

Changed IMatch to return a IMatchLocatable instead of startOffset/endOffset (IMatchLocatable can then be further cast into IOffsetLocatable or ILineLocatable)

Updated all clients.
This commit is contained in:
Bogdan Gheorghe 2005-05-16 18:24:31 +00:00
parent bdecfcfc41
commit b920965dab
30 changed files with 419 additions and 146 deletions

View file

@ -33,6 +33,7 @@ import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchPattern;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.core.search.IOffsetLocatable;
import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.internal.core.browser.cache.TypeCacheManager;
@ -152,7 +153,7 @@ public class SearchRegressionTests extends BaseTestFramework implements ICSearch
Iterator i = matches.iterator();
while( i.hasNext() ){
IMatch match = (IMatch) i.next();
if( match.getStartOffset() == offset && match.getLocation().equals( file.getLocation() ) )
if( ((IOffsetLocatable)match.getLocatable()).getNameStartOffset() == offset && match.getLocation().equals( file.getLocation() ) )
return; //match
}
fail( "Match at offset " + offset + " in \"" + file.getLocation() + "\" not found." ); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$

View file

@ -16,9 +16,11 @@ package org.eclipse.cdt.core.search.tests;
import java.util.Iterator;
import java.util.Set;
import org.eclipse.cdt.core.parser.IOffsetDuple;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchPattern;
import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.core.search.IOffsetLocatable;
import org.eclipse.cdt.core.search.OrPattern;
import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.core.CharOperation;
@ -115,8 +117,8 @@ public class ClassDeclarationPatternTests extends BaseSearchTest implements ICSe
IMatch match2 = (IMatch)iter2.next();
//assertTrue( match.path.equals( match2.path ) );
assertEquals( match.getStartOffset(), match2.getStartOffset() );
assertEquals( match.getEndOffset(), match2.getEndOffset() );
assertEquals( ((IOffsetLocatable) match.getLocatable()).getNameStartOffset(), ((IOffsetLocatable) match2.getLocatable()).getNameStartOffset() );
assertEquals( ((IOffsetLocatable) match.getLocatable()).getNameEndOffset() , ((IOffsetLocatable) match2.getLocatable()).getNameEndOffset() );
}
public void testWildcardQualification() {

View file

@ -17,6 +17,7 @@ import java.util.Set;
import org.eclipse.cdt.core.search.ICSearchPattern;
import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.core.search.IOffsetLocatable;
import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.index.IIndex;
@ -141,7 +142,7 @@ public class FunctionMethodPatternTests extends BaseSearchTest {
assertEquals( matches.size(), 1 );
IMatch match2 = (IMatch) matches.iterator().next();
assertTrue( match1.getStartOffset() == match2.getStartOffset() );
assertTrue( ((IOffsetLocatable)match1.getLocatable()).getNameStartOffset() == ((IOffsetLocatable)match2.getLocatable()).getNameStartOffset() );
pattern = SearchEngine.createSearchPattern( "operator \\*=", METHOD, DECLARATIONS, true ); //$NON-NLS-1$
search( workspace, pattern, scope, resultCollector );
@ -155,7 +156,7 @@ public class FunctionMethodPatternTests extends BaseSearchTest {
assertEquals( matches.size(), 1 );
match2 = (IMatch) matches.iterator().next();
assertTrue( match1.getStartOffset() != match2.getStartOffset() );
assertTrue( ((IOffsetLocatable)match1.getLocatable()).getNameStartOffset() != ((IOffsetLocatable)match2.getLocatable()).getNameStartOffset() );
pattern = SearchEngine.createSearchPattern( "operator *", METHOD, DECLARATIONS, true ); //$NON-NLS-1$
search( workspace, pattern, scope, resultCollector );

View file

@ -137,7 +137,7 @@ class CTagsIndexAll extends CTagsIndexRequest {
String[] args = {"--excmd=number", //$NON-NLS-1$
"--format=2", //$NON-NLS-1$
"--sort=no", //$NON-NLS-1$
"--fields=aiKlmnsz", //$NON-NLS-1$
"--fields=aiKlmnsSz", //$NON-NLS-1$
"--c-types=cdefgmnpstuvx", //$NON-NLS-1$
"--c++-types=cdefgmnpstuvx", //$NON-NLS-1$
"--languages=c,c++", //$NON-NLS-1$

View file

@ -60,7 +60,7 @@ public class CTagsIndexerRunner extends AbstractIndexer {
"--excmd=number", //$NON-NLS-1$
"--format=2", //$NON-NLS-1$
"--sort=no", //$NON-NLS-1$
"--fields=aiKlmnsz", //$NON-NLS-1$
"--fields=aiKlmnsSz", //$NON-NLS-1$
"--c-types=cdefgmnpstuvx", //$NON-NLS-1$
"--c++-types=cdefgmnpstuvx", //$NON-NLS-1$
"--languages=c,c++", //$NON-NLS-1$

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2003, 2004 IBM Corporation and others.
* Copyright (c) 2003, 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
@ -33,8 +33,7 @@ public class BasicSearchMatch implements IMatch, Comparable {
returnType = basicMatch.returnType;
resource = basicMatch.resource;
path = basicMatch.path;
startOffset = basicMatch.startOffset;
endOffset = basicMatch.endOffset;
locatable = basicMatch.locatable;
referringElement = basicMatch.referringElement;
}
@ -53,9 +52,9 @@ public class BasicSearchMatch implements IMatch, Comparable {
hashBuffer.append( getLocation().toString() );
}
hashBuffer.append( HASH_SEPERATOR );
hashBuffer.append( startOffset );
hashBuffer.append( locatable instanceof IOffsetLocatable ? ((IOffsetLocatable)locatable).getNameStartOffset():((ILineLocatable)locatable).getStartLine());
hashBuffer.append( HASH_SEPERATOR );
hashBuffer.append( endOffset );
hashBuffer.append( locatable instanceof IOffsetLocatable ? ((IOffsetLocatable)locatable).getNameEndOffset(): ((ILineLocatable)locatable).getEndLine());
hashBuffer.append( HASH_SEPERATOR );
hashBuffer.append( type );
hashBuffer.append( HASH_SEPERATOR );
@ -72,8 +71,27 @@ public class BasicSearchMatch implements IMatch, Comparable {
}
BasicSearchMatch match = (BasicSearchMatch)obj;
if( startOffset != match.getStartOffset() || endOffset != match.getEndOffset() )
if ((locatable != null && match.locatable==null) ||
(locatable==null && match.locatable!=null)){
return false;
}
if (locatable!=null && match.locatable !=null){
if (!(locatable instanceof IOffsetLocatable && match.locatable instanceof IOffsetLocatable) ||
!(locatable instanceof ILineLocatable && match.locatable instanceof ILineLocatable))
return false;
if (locatable instanceof IOffsetLocatable){
if (((IOffsetLocatable)locatable).getNameStartOffset() != ((IOffsetLocatable)match.locatable).getNameStartOffset() ||
((IOffsetLocatable)locatable).getNameEndOffset() != ((IOffsetLocatable)match.locatable).getNameEndOffset())
return false;
} else {
if (((ILineLocatable)locatable).getStartLine() != ((ILineLocatable)match.locatable).getStartLine())
return false;
}
}
if( type != match.getElementType() || visibility != match.getVisibility() )
return false;
@ -121,8 +139,21 @@ public class BasicSearchMatch implements IMatch, Comparable {
int result = getLocation().toString().compareTo( match.getLocation().toString() );
if( result != 0 ) return result;
result = getStartOffset() - match.getStartOffset();
if( result != 0 ) return result;
if (locatable instanceof IOffsetLocatable && match.getLocatable() instanceof IOffsetLocatable){
result = ((IOffsetLocatable)locatable).getNameStartOffset() - ((IOffsetLocatable)match.locatable).getNameStartOffset();
if( result != 0 ) return result;
result = ((IOffsetLocatable)locatable).getNameEndOffset() - ((IOffsetLocatable)match.locatable).getNameEndOffset();
if( result != 0 ) return result;
}
else if (locatable instanceof ILineLocatable && match.getLocatable() instanceof ILineLocatable){
result = ((ILineLocatable)locatable).getStartLine() - ((ILineLocatable)match.locatable).getStartLine();
if( result != 0 ) return result;
result = ((ILineLocatable)locatable).getEndLine() - ((ILineLocatable)match.locatable).getEndLine();
if( result != 0 ) return result;
}
result = getName().compareTo( match.getName() );
if( result != 0 ) return result;
@ -140,10 +171,7 @@ public class BasicSearchMatch implements IMatch, Comparable {
public IResource resource = null;
public IPath path = null;
public int startOffset = 0;
public int endOffset = 0;
public int type = 0;
public int visibility = 0;
@ -155,7 +183,7 @@ public class BasicSearchMatch implements IMatch, Comparable {
public IPath referringElement = null;
public int offsetType;
public IMatchLocatable locatable = null;
public int getElementType() {
return type;
@ -193,14 +221,6 @@ public class BasicSearchMatch implements IMatch, Comparable {
return referringElement;
}
public int getStartOffset() {
return startOffset;
}
public int getEndOffset() {
return endOffset;
}
public boolean isStatic() {
return isStatic;
}
@ -218,13 +238,6 @@ public class BasicSearchMatch implements IMatch, Comparable {
return type;
}
/**
* @param i
*/
public void setEndOffset(int i) {
endOffset = i;
}
/**
* @param b
*/
@ -266,14 +279,6 @@ public class BasicSearchMatch implements IMatch, Comparable {
public void setReturnType(String string) {
returnType = string;
}
/**
* @param i
*/
public void setStartOffset(int i) {
startOffset = i;
}
/**
* @param i
*/
@ -287,13 +292,9 @@ public class BasicSearchMatch implements IMatch, Comparable {
public void setVisibility(int i) {
visibility = i;
}
public int getOffsetType() {
return offsetType;
}
public void setOffsetType(int offsetType) {
this.offsetType = offsetType;
public IMatchLocatable getLocatable() {
return locatable;
}
}

View file

@ -84,9 +84,8 @@ public class BasicSearchResultCollector implements ICSearchResultCollector {
result.resource = (IResource) fileResource;
else if( fileResource instanceof IPath )
result.path = (IPath) fileResource;
result.startOffset = start;
result.endOffset = end;
result.locatable = new OffsetLocatable(start,end);
result.parentName = ""; //$NON-NLS-1$
result.referringElement = referringElement;

View file

@ -0,0 +1,6 @@
package org.eclipse.cdt.core.search;
public interface ILineLocatable extends IMatchLocatable {
int getStartLine();
int getEndLine();
}

View file

@ -33,26 +33,9 @@ public interface IMatch {
IPath getLocation();
IPath getReferenceLocation();
/**
* Returns the start offset for this match. Note that clients should use
* getOffsetType to determine if this is a LINE or an OFFSET
* @return start offset
*/
int getStartOffset();
/**
* Returns the end offset for this match. Note that clients should use
* getOffsetType to determine if this is a LINE or an OFFSET. The end offset
* is meaningless for LINE offsets; instead use IDocument.getLineLength to
* figure out the length of the line.
* @return end offset
*/
int getEndOffset();
/**
* Returns the type of offset either IIndex.LINE or IIndex.OFFSET
* @return IIndex.LINE or IIndex.OFFSET
*/
public int getOffsetType();
IMatchLocatable getLocatable();
boolean isStatic();
boolean isConst();
boolean isVolatile();

View file

@ -0,0 +1,5 @@
package org.eclipse.cdt.core.search;
public interface IMatchLocatable {
}

View file

@ -0,0 +1,9 @@
package org.eclipse.cdt.core.search;
public interface IOffsetLocatable extends IMatchLocatable {
int getNameStartOffset();
int getNameEndOffset();
int getElementStartOffset();
int getElementEndOffset();
}

View file

@ -0,0 +1,20 @@
package org.eclipse.cdt.core.search;
public class LineLocatable implements ILineLocatable {
int startLine;
int endLine;
public LineLocatable(int startLine, int endLine){
this.startLine = startLine;
this.endLine = endLine;
}
public int getStartLine() {
return startLine;
}
public int getEndLine() {
return endLine;
}
}

View file

@ -0,0 +1,49 @@
package org.eclipse.cdt.core.search;
public class OffsetLocatable implements IOffsetLocatable {
int nameStartOffset;
int nameEndOffset;
int elementStartOffset;
int elementEndOffset;
/**
* Used to create an OffsetLocatable that contains just the name offsets
* @param nameStartOffset - the starting offset of the name
* @param nameEndOffset - the ending offset of the name
*/
public OffsetLocatable(int nameStartOffset, int nameEndOffset){
this(nameStartOffset, nameEndOffset, 0, 0);
}
/**
* Create an OffsetLocatable that contains both the offsets of the name and the offsets
* of the element itself
* @param nameStartOffset - the starting offset of the name
* @param nameEndOffset - the ending offset of the name
* @param elementStartOffset - the starting offset of the element
* @param elementEndOffset - the ending offset of the element
*/
public OffsetLocatable(int nameStartOffset, int nameEndOffset, int elementStartOffset, int elementEndOffset){
this.nameStartOffset = nameStartOffset;
this.nameEndOffset = nameEndOffset;
this.elementStartOffset=elementStartOffset;
this.elementEndOffset=elementEndOffset;
}
public int getNameStartOffset() {
return nameStartOffset;
}
public int getNameEndOffset() {
return nameEndOffset;
}
public int getElementStartOffset(){
return elementStartOffset;
}
public int getElementEndOffset(){
return elementEndOffset;
}
}

View file

@ -27,6 +27,8 @@ import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement;
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.LineLocatable;
import org.eclipse.cdt.core.search.OffsetLocatable;
import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.IIndex;
@ -183,12 +185,11 @@ public class ClassDeclarationPattern extends CSearchPattern {
//Offsets can either be LINE or OFFSET
int offsetType = Integer.valueOf(String.valueOf(offsets[i][j]).substring(0,1)).intValue();
if (offsetType==IIndex.LINE){
match.startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
match.offsetType = IIndex.LINE;
match.locatable = new LineLocatable(Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue(),0);
}else if (offsetType==IIndex.OFFSET){
match.startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
match.endOffset= match.startOffset + offsetLengths[i][j];
match.offsetType=IIndex.OFFSET;
int startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
int endOffset= startOffset + offsetLengths[i][j];
match.locatable = new OffsetLocatable(startOffset, endOffset);
}
match.parentName = ""; //$NON-NLS-1$

View file

@ -28,6 +28,8 @@ import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter;
import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.LineLocatable;
import org.eclipse.cdt.core.search.OffsetLocatable;
import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.cindexstorage.Index;
import org.eclipse.cdt.internal.core.index.cindexstorage.IndexedFileEntry;
@ -161,12 +163,11 @@ public class FieldDeclarationPattern extends CSearchPattern {
//Offsets can either be LINE or OFFSET
int offsetType = Integer.valueOf(String.valueOf(offsets[i][j]).substring(0,1)).intValue();
if (offsetType==Index.LINE){
match.startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
match.offsetType = Index.LINE;
match.locatable = new LineLocatable(Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue(),0);
}else if (offsetType==Index.OFFSET){
match.startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
match.endOffset= match.startOffset + offsetLengths[i][j];
match.offsetType=Index.OFFSET;
int startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
int endOffset= startOffset + offsetLengths[i][j];
match.locatable = new OffsetLocatable(startOffset, endOffset);
}
match.parentName = ""; //$NON-NLS-1$
if (searchFor == FIELD){

View file

@ -22,6 +22,8 @@ import org.eclipse.cdt.core.parser.ast.IASTMacro;
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.LineLocatable;
import org.eclipse.cdt.core.search.OffsetLocatable;
import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.index.cindexstorage.Index;
@ -90,12 +92,11 @@ public class MacroDeclarationPattern extends CSearchPattern {
//Offsets can either be LINE or OFFSET
int offsetType = Integer.valueOf(String.valueOf(offsets[i][j]).substring(0,1)).intValue();
if (offsetType==IIndex.LINE){
match.startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
match.offsetType=IIndex.LINE;
match.locatable = new LineLocatable(Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue(),0);
}else if (offsetType==IIndex.OFFSET){
match.startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
match.endOffset= match.startOffset + offsetLengths[i][j];
match.offsetType=IIndex.OFFSET;
int startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
int endOffset= startOffset + offsetLengths[i][j];
match.locatable = new OffsetLocatable(startOffset, endOffset);
}
match.parentName = ""; //$NON-NLS-1$
match.type = ICElement.C_MACRO;

View file

@ -24,6 +24,8 @@ import org.eclipse.cdt.core.parser.ast.IASTMethod;
import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement;
import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.LineLocatable;
import org.eclipse.cdt.core.search.OffsetLocatable;
import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.IIndex;
@ -186,12 +188,11 @@ public class MethodDeclarationPattern extends CSearchPattern {
//Offsets can either be LINE or OFFSET
int offsetType = Integer.valueOf(String.valueOf(offsets[i][j]).substring(0,1)).intValue();
if (offsetType==IIndex.LINE){
match.startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
match.offsetType = IIndex.LINE;
match.locatable = new LineLocatable(Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue(),0);
}else if (offsetType==IIndex.OFFSET){
match.startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
match.endOffset= match.startOffset + offsetLengths[i][j];
match.offsetType=IIndex.OFFSET;
int startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
int endOffset= startOffset + offsetLengths[i][j];
match.locatable = new OffsetLocatable(startOffset, endOffset);
}
match.parentName = ""; //$NON-NLS-1$
if (searchFor == METHOD){

View file

@ -21,6 +21,8 @@ import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.LineLocatable;
import org.eclipse.cdt.core.search.OffsetLocatable;
import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.index.cindexstorage.Index;
@ -102,12 +104,11 @@ public class NamespaceDeclarationPattern extends CSearchPattern {
//Offsets can either be LINE or OFFSET
int offsetType = Integer.valueOf(String.valueOf(offsets[i][j]).substring(0,1)).intValue();
if (offsetType==IIndex.LINE){
match.startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
match.offsetType = IIndex.LINE;
match.locatable = new LineLocatable(Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue(),0);
}else if (offsetType==IIndex.OFFSET){
match.startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
match.endOffset= match.startOffset + offsetLengths[i][j];
match.offsetType=IIndex.OFFSET;
int startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
int endOffset= startOffset + offsetLengths[i][j];
match.locatable = new OffsetLocatable(startOffset, endOffset);
}
match.parentName = ""; //$NON-NLS-1$
match.type=ICElement.C_NAMESPACE;

View file

@ -34,6 +34,8 @@ import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.core.search.IOffsetLocatable;
import org.eclipse.cdt.core.search.OffsetLocatable;
import org.eclipse.cdt.internal.ui.search.CSearchQuery;
import org.eclipse.cdt.internal.ui.search.CSearchResult;
import org.eclipse.cdt.internal.ui.search.NewSearchResultCollector;
@ -126,8 +128,9 @@ public class DOMDisplaySearchNames extends CSearchQuery implements ISearchQuery
else if( fileResource instanceof IPath )
result.path = (IPath) fileResource;
result.startOffset = start;
result.endOffset = end;
IOffsetLocatable locatable = new OffsetLocatable(start,end);
result.locatable = locatable;
result.parentName = BLANK_STRING; //$NON-NLS-1$
result.referringElement = referringElement;

View file

@ -15,7 +15,11 @@ import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.core.search.IMatchLocatable;
import org.eclipse.cdt.core.search.LineLocatable;
import org.eclipse.cdt.core.search.OffsetLocatable;
import org.eclipse.cdt.internal.core.index.IEntryResult;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.ui.search.CSearchQuery;
import org.eclipse.cdt.internal.ui.search.CSearchResult;
import org.eclipse.cdt.internal.ui.search.NewSearchResultCollector;
@ -193,15 +197,20 @@ public class IndexerQuery extends CSearchQuery implements ISearchQuery {
result.resource = (IResource) fileResource;
else if( fileResource instanceof IPath )
result.path = (IPath) fileResource;
result.startOffset = start;
result.endOffset = end;
IMatchLocatable locatable=null;
if (offsetType == IIndex.LINE)
{
locatable = new LineLocatable(start,end);
}
else if (offsetType == IIndex.OFFSET){
locatable = new OffsetLocatable(start,end);
}
result.locatable = locatable;
result.parentName = BLANK_STRING; //$NON-NLS-1$
result.referringElement = referringElement;
result.name = name;
result.offsetType = offsetType;
result.type = ICElement.C_FIELD; // TODO Devin static for now, want something like BasicSearchResultCollector#setElementInfo
result.visibility = ICElement.CPP_PUBLIC; // TODO Devin static for now, want something like BasicSearchResultCollector#setElementInfo

View file

@ -41,6 +41,9 @@ import org.eclipse.cdt.core.model.IVariable;
import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.ILineLocatable;
import org.eclipse.cdt.core.search.IMatchLocatable;
import org.eclipse.cdt.core.search.IOffsetLocatable;
import org.eclipse.cdt.core.search.OrPattern;
import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.corext.Assert;
@ -401,7 +404,17 @@ public class RenameElementProcessor extends RenameProcessor implements IReferenc
for (int j= 0; j < results.length; j++){
BasicSearchMatch searchResult= results[j];
int oldNameLength = getCurrentElementNameLength();
int offset= searchResult.getEndOffset() - oldNameLength;
IMatchLocatable locatable =searchResult.getLocatable();
//Refactoring will only work with offsets, so any matches
//returning lines shall be skipped
int endOffset=0;
if (locatable instanceof IOffsetLocatable){
endOffset=((IOffsetLocatable)locatable).getNameEndOffset();
} else if (locatable instanceof ILineLocatable){
endOffset=((ILineLocatable)locatable).getEndLine();
}
int offset= endOffset - oldNameLength;
manager.get(wc).addTextEdit(name,
new ReplaceEdit(offset, oldNameLength, fNewElementName));
}
@ -712,7 +725,7 @@ public class RenameElementProcessor extends RenameProcessor implements IReferenc
if(( returnType == null) || (returnType.length() == 0) )
return true;
if(getCurrentElementName().startsWith("~")) //$NON-NLS-1$
if(getCurrentElementName().startsWith("~"))
return true;
return false;

View file

@ -118,8 +118,8 @@ public class CSearchResultCollector extends BasicSearchResultCollector{
HashMap markerAttributes = new HashMap( 2 );
//we can hang any other info we want off the marker
markerAttributes.put( IMarker.CHAR_START, new Integer( Math.max( searchMatch.startOffset, 0 ) ) );
markerAttributes.put( IMarker.CHAR_END, new Integer( Math.max( searchMatch.endOffset, 0 ) ) );
/*markerAttributes.put( IMarker.CHAR_START, new Integer( Math.max( searchMatch.startOffset, 0 ) ) );
markerAttributes.put( IMarker.CHAR_END, new Integer( Math.max( searchMatch.endOffset, 0 ) ) );*/
markerAttributes.put( IMATCH, searchMatch );
marker.setAttributes( markerAttributes );
@ -159,8 +159,8 @@ public class CSearchResultCollector extends BasicSearchResultCollector{
HashMap markerAttributes = new HashMap( 2 );
markerAttributes.put( IMarker.CHAR_START, new Integer( Math.max( searchMatch.startOffset, 0 ) ) );
markerAttributes.put( IMarker.CHAR_END, new Integer( Math.max( searchMatch.endOffset, 0 ) ) );
/*markerAttributes.put( IMarker.CHAR_START, new Integer( Math.max( searchMatch.startOffset, 0 ) ) );
markerAttributes.put( IMarker.CHAR_END, new Integer( Math.max( searchMatch.endOffset, 0 ) ) );*/
markerAttributes.put( IMATCH, searchMatch );
marker.setAttributes( markerAttributes );
@ -218,12 +218,12 @@ public class CSearchResultCollector extends BasicSearchResultCollector{
private static final String MATCHES = CSearchMessages.getString("CSearchResultCollector.matches"); //$NON-NLS-1$
private static final String DONE = CSearchMessages.getString("CSearchResultCollector.done"); //$NON-NLS-1$
private IProgressMonitor _monitor;
private CSearchOperation _operation;
private ISearchResultView _view;
private IGroupByKeyComputer _computer;
private int _matchCount;
private CSearchQuery _query;
private IProgressMonitor _monitor;
private CSearchOperation _operation;
private ISearchResultView _view;
private IGroupByKeyComputer _computer;
private int _matchCount;
private CSearchQuery _query;
/**
* @param query

View file

@ -17,7 +17,9 @@ import java.util.HashMap;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.core.search.ILineLocatable;
import org.eclipse.cdt.core.search.IMatchLocatable;
import org.eclipse.cdt.core.search.IOffsetLocatable;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
import org.eclipse.cdt.internal.ui.editor.ExternalSearchFile;
@ -34,6 +36,8 @@ import org.eclipse.core.runtime.Path;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TreeViewer;
@ -113,16 +117,52 @@ public class CSearchResultPage extends AbstractTextSearchViewPage {
BasicSearchMatch searchMatch = ((CSearchMatch) match).getSearchMatch();
if (searchMatch.resource != null){
editor = IDE.openEditor(CUIPlugin.getActivePage(), getCanonicalFile((IFile) searchMatch.resource), false);
showWithMarker(editor, getCanonicalFile((IFile) searchMatch.resource), searchMatch.getOffsetType(), currentOffset, currentLength);
IMatchLocatable searchLocatable = searchMatch.locatable;
showWithMarker(editor, getCanonicalFile((IFile) searchMatch.resource), searchLocatable, currentOffset, currentLength);
}
else {
//Match is outside of the workspace
try {
IEditorInput input =EditorUtility.getEditorInput(new ExternalSearchFile(searchMatch.path, searchMatch));
IWorkbenchPage p= CUIPlugin.getActivePage();
IEditorPart editorPart= p.openEditor(input, "org.eclipse.cdt.ui.editor.ExternalSearchEditor"); //$NON-NLS-1$
if (editorPart instanceof ITextEditor) {
ITextEditor textEditor= (ITextEditor) editorPart;
textEditor.selectAndReveal(searchMatch.startOffset, searchMatch.endOffset - searchMatch.startOffset);
IMatchLocatable searchLocatable = searchMatch.locatable;
int startOffset=0;
int length=0;
if (searchLocatable instanceof IOffsetLocatable){
startOffset = ((IOffsetLocatable)searchLocatable).getNameStartOffset();
length = ((IOffsetLocatable)searchLocatable).getNameEndOffset() - startOffset;
} else if (searchLocatable instanceof ILineLocatable){
int tempstartLine = ((ILineLocatable)searchLocatable).getStartLine();
int tempendLine = ((ILineLocatable)searchLocatable).getEndLine();
//Convert the given line number into an offset in order to be able to use
//the text editor to open
IDocument doc =textEditor.getDocumentProvider().getDocument(input);
if (doc == null)
return;
try {
startOffset = doc.getLineOffset(tempstartLine);
length=doc.getLineLength(tempstartLine);
} catch (BadLocationException e) {}
//See if an end line number has been provided - if so
//use it to calculate the length of the reveal...
//Make sure that an end offset exists that is greater than 0
//and that is greater than the start line number
if (tempendLine>0 && tempendLine > tempstartLine){
int endOffset;
try {
endOffset = doc.getLineOffset(tempendLine);
length = endOffset - startOffset;
} catch (BadLocationException e) {}
}
}
textEditor.selectAndReveal(startOffset,length);
}
//TODO: Put in once we have marker support for External Translation Units
@ -191,14 +231,14 @@ public class CSearchResultPage extends AbstractTextSearchViewPage {
setSortOrder(_currentSortOrder);
}
private void showWithMarker(IEditorPart editor, IFile file,int offsetType, int offset, int length) throws PartInitException {
private void showWithMarker(IEditorPart editor, IFile file,IMatchLocatable searchLocatable, int offset, int length) throws PartInitException {
try {
IMarker marker= file.createMarker(NewSearchUI.SEARCH_MARKER);
HashMap attributes= new HashMap(4);
if (offsetType==IIndex.OFFSET){
if (searchLocatable instanceof IOffsetLocatable){
attributes.put(IMarker.CHAR_START, new Integer(offset));
attributes.put(IMarker.CHAR_END, new Integer(offset + length));
} else if (offsetType == IIndex.LINE){
} else if (searchLocatable instanceof ILineLocatable){
attributes.put(IMarker.LINE_NUMBER, new Integer(offset));
}
marker.setAttributes(attributes);

View file

@ -44,6 +44,7 @@ import org.eclipse.cdt.core.search.DOMSearchUtil;
import org.eclipse.cdt.core.search.ICSearchResultCollector;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.core.search.OffsetLocatable;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IResource;
@ -183,8 +184,7 @@ public class DOMQuery extends CSearchQuery implements ISearchQuery {
else if( fileResource instanceof IPath )
result.path = (IPath) fileResource;
result.startOffset = start;
result.endOffset = end;
result.locatable = new OffsetLocatable(start,end);
result.parentName = BLANK_STRING; //$NON-NLS-1$
result.referringElement = referringElement;

View file

@ -20,7 +20,11 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.parser.IOffsetDuple;
import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.core.search.ILineLocatable;
import org.eclipse.cdt.core.search.IMatchLocatable;
import org.eclipse.cdt.core.search.IOffsetLocatable;
import org.eclipse.cdt.ui.CElementContentProvider;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
@ -68,11 +72,19 @@ public class LevelTreeContentProvider extends CSearchContentProvider implements
if (child instanceof CSearchMatch){
BasicSearchMatch tempMatch = ((CSearchMatch) child).getSearchMatch();
IMatchLocatable locatable = tempMatch.getLocatable();
int startOffset =0;
if (locatable instanceof IOffsetLocatable){
startOffset = ((IOffsetLocatable)locatable).getNameStartOffset();
} else if (locatable instanceof ILineLocatable){
startOffset = ((ILineLocatable)locatable).getStartLine();
}
ICElement cTransUnit = CCorePlugin.getDefault().getCoreModel().create(tempMatch.getResource());
if (cTransUnit instanceof ITranslationUnit){
try {
child = ((ITranslationUnit) cTransUnit).getElementAtOffset(tempMatch.startOffset);
child = ((ITranslationUnit) cTransUnit).getElementAtOffset(startOffset);
} catch (CModelException e) {}
}
if( child == null ){

View file

@ -15,7 +15,10 @@ import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.core.search.BasicSearchResultCollector;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ILineLocatable;
import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.core.search.IMatchLocatable;
import org.eclipse.cdt.core.search.IOffsetLocatable;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@ -87,8 +90,23 @@ public class NewSearchResultCollector extends BasicSearchResultCollector {
if (searchMatch.resource != null){
fMatchCount++;
int start = match.getStartOffset();
int end = match.getEndOffset();
int start =0;
int end = 0;
IMatchLocatable locatable = match.getLocatable();
if (locatable instanceof IOffsetLocatable){
start = ((IOffsetLocatable)locatable).getNameStartOffset();
end = ((IOffsetLocatable)locatable).getNameEndOffset();
} else if (locatable instanceof ILineLocatable){
start = ((ILineLocatable)locatable).getStartLine();
//Not all line based indexers can provide an ending line; check
//to see if there is a value stored here
int tempEnd = ((ILineLocatable)locatable).getEndLine();
if (tempEnd > 0 && tempEnd > start){
end = tempEnd;
}
}
String classifier = PARENT + match.getParentName() + NAME + match.getName() + LOCATION + match.getLocation().toOSString() + ELEMENTTYPE + match.getElementType() + VISIBILITY + match.getVisibility();
fSearch.addMatch(new CSearchMatch(classifier,start,end-start, match));
@ -96,8 +114,23 @@ public class NewSearchResultCollector extends BasicSearchResultCollector {
}
else {
fMatchCount++;
int start = match.getStartOffset();
int end = match.getEndOffset();
int start =0;
int end = 0;
IMatchLocatable locatable = match.getLocatable();
if (locatable instanceof IOffsetLocatable){
start = ((IOffsetLocatable)locatable).getNameStartOffset();
end = ((IOffsetLocatable)locatable).getNameEndOffset();
} else if (locatable instanceof ILineLocatable){
start = ((ILineLocatable)locatable).getStartLine();
//Not all line based indexers can provide an ending line; check
//to see if there is a value stored here
int tempEnd = ((ILineLocatable)locatable).getEndLine();
if (tempEnd > 0 && tempEnd > start){
end = tempEnd;
}
}
String classifier = PARENT + match.getParentName() + NAME + match.getName() + LOCATION + match.getLocation().toOSString() + ELEMENTTYPE + match.getElementType() + VISIBILITY + match.getVisibility();
fSearch.addMatch(new CSearchMatch(classifier,start,end-start, match));

View file

@ -27,7 +27,10 @@ import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.search.DOMSearchUtil;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ILineLocatable;
import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.core.search.IMatchLocatable;
import org.eclipse.cdt.core.search.IOffsetLocatable;
import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.core.model.CProject;
import org.eclipse.cdt.internal.ui.editor.CEditor;
@ -40,6 +43,8 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.ui.texteditor.IUpdate;
public class OpenDeclarationsAction extends SelectionParseAction implements IUpdate {
@ -175,8 +180,34 @@ public class OpenDeclarationsAction extends SelectionParseAction implements IUpd
if (match instanceof IMatch) {
IMatch theMatch = (IMatch)match;
storage.setFileName(theMatch.getLocation().toOSString());
storage.setLength(theMatch.getEndOffset() - theMatch.getStartOffset());
storage.setOffset(theMatch.getStartOffset());
IMatchLocatable searchLocatable = theMatch.getLocatable();
int startOffset=0;
int length=0;
if (searchLocatable instanceof IOffsetLocatable){
startOffset = ((IOffsetLocatable)searchLocatable).getNameStartOffset();
length = ((IOffsetLocatable)searchLocatable).getNameEndOffset() - startOffset;
} else if (searchLocatable instanceof ILineLocatable){
int tempstartOffset = ((ILineLocatable)searchLocatable).getStartLine();
IDocument doc =fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
try {
startOffset = doc.getLineOffset(tempstartOffset);
length=doc.getLineLength(tempstartOffset);
} catch (BadLocationException e) {}
//Check to see if an end offset is provided
int tempendOffset = ((ILineLocatable)searchLocatable).getEndLine();
//Make sure that there is a real value for the end line
if (tempendOffset>0 && tempendOffset>tempstartOffset){
try {
int endOffset = doc.getLineOffset(tempendOffset);
length=endOffset - startOffset;
} catch (BadLocationException e) {}
}
}
storage.setLength(length);
storage.setOffset(startOffset);
storage.setResource(ParserUtil.getResourceForFilename(theMatch.getLocation().toOSString()));
break;
}

View file

@ -26,7 +26,10 @@ import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.core.search.DOMSearchUtil;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ILineLocatable;
import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.core.search.IMatchLocatable;
import org.eclipse.cdt.core.search.IOffsetLocatable;
import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.core.model.CProject;
import org.eclipse.cdt.internal.ui.editor.CEditor;
@ -39,6 +42,8 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.ui.texteditor.IUpdate;
/**
@ -178,7 +183,7 @@ public class OpenDefinitionAction extends SelectionParseAction implements
// 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(SearchEngine.createCSearchScope(scope), searchName, ICSearchConstants.DEFINITIONS);
if (matches != null && matches.size() > 0) {
Iterator itr = matches.iterator();
@ -187,8 +192,33 @@ public class OpenDefinitionAction extends SelectionParseAction implements
if (match instanceof IMatch) {
IMatch theMatch = (IMatch)match;
storage.setFileName(theMatch.getLocation().toOSString());
storage.setLength(theMatch.getEndOffset() - theMatch.getStartOffset());
storage.setOffset(theMatch.getStartOffset());
IMatchLocatable searchLocatable = theMatch.getLocatable();
int startOffset=0;
int length=0;
if (searchLocatable instanceof IOffsetLocatable){
startOffset = ((IOffsetLocatable)searchLocatable).getNameStartOffset();
length = ((IOffsetLocatable)searchLocatable).getNameEndOffset() - startOffset;
} else if (searchLocatable instanceof ILineLocatable){
int tempstartOffset = ((ILineLocatable)searchLocatable).getStartLine();
IDocument doc =fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
try {
startOffset = doc.getLineOffset(tempstartOffset);
length=doc.getLineLength(tempstartOffset);
} catch (BadLocationException e) {}
//Check to see if an end offset is provided
int tempendOffset = ((ILineLocatable)searchLocatable).getEndLine();
//Make sure that there is a real value for the end line
if (tempendOffset>0 && tempendOffset>tempstartOffset){
try {
int endOffset = doc.getLineOffset(tempendOffset);
length=endOffset - startOffset;
} catch (BadLocationException e) {}
}
}
storage.setLength(length);
storage.setOffset(startOffset);
storage.setResource(ParserUtil.getResourceForFilename(theMatch.getLocation().toOSString()));
break;
}

View file

@ -32,7 +32,6 @@ import org.eclipse.cdt.core.parser.ParserMode;
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;
@ -613,12 +612,6 @@ public class SelectionParseAction extends Action {
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.
*/

View file

@ -24,7 +24,10 @@ import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.search.BasicSearchResultCollector;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.core.search.ICSearchScope;
import org.eclipse.cdt.core.search.ILineLocatable;
import org.eclipse.cdt.core.search.IMatch;
import org.eclipse.cdt.core.search.IMatchLocatable;
import org.eclipse.cdt.core.search.IOffsetLocatable;
import org.eclipse.cdt.core.search.OrPattern;
import org.eclipse.cdt.core.search.SearchEngine;
import org.eclipse.cdt.internal.ui.codemanipulation.StubUtility;
@ -84,7 +87,7 @@ public class CSourceHover extends AbstractCEditorTextHover implements ITextHover
ICElement curr = copy.getElement(expression);
if (curr == null) {
// Try with the indexer
source = findMatches(expression);
source = findMatches(expression, textViewer);
} else {
source= ((ISourceReference) curr).getSource();
}
@ -152,7 +155,7 @@ public class CSourceHover extends AbstractCEditorTextHover implements ITextHover
return source.substring(i);
}
private String findMatches(String name) {
private String findMatches(String name, ITextViewer textViewer) {
IEditorPart editor = getEditor();
if (editor != null) {
IEditorInput input= editor.getEditorInput();
@ -191,8 +194,33 @@ public class CSourceHover extends AbstractCEditorTextHover implements ITextHover
ICElement celement = CoreModel.getDefault().create(resource);
if (celement instanceof ITranslationUnit) {
ITranslationUnit unit = (ITranslationUnit)celement;
int startOffset = matches[0].getStartOffset();
int length = matches[0].getEndOffset() - startOffset;
//Check offset type
IMatchLocatable searchLocatable = matches[0].getLocatable();
int startOffset=0;
int length=0;
if (searchLocatable instanceof IOffsetLocatable){
startOffset = ((IOffsetLocatable)searchLocatable).getNameStartOffset();
length = ((IOffsetLocatable)searchLocatable).getNameEndOffset() - startOffset;
} else if (searchLocatable instanceof ILineLocatable){
int tempstartOffset = ((ILineLocatable)searchLocatable).getStartLine();
IDocument doc =textViewer.getDocument();
try {
startOffset = doc.getLineOffset(tempstartOffset);
length=doc.getLineLength(tempstartOffset);
} catch (BadLocationException e) {}
//Check to see if an end offset is provided
int tempendOffset = ((ILineLocatable)searchLocatable).getEndLine();
//Make sure that there is a real value for the end line
if (tempendOffset>0 && tempendOffset>tempstartOffset){
try {
int endOffset = doc.getLineOffset(tempendOffset);
length=endOffset - startOffset;
} catch (BadLocationException e) {}
}
}
return unit.getBuffer().getText(startOffset, length);
}
}