mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +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:
parent
bdecfcfc41
commit
b920965dab
30 changed files with 419 additions and 146 deletions
|
@ -33,6 +33,7 @@ import org.eclipse.cdt.core.search.ICSearchConstants;
|
||||||
import org.eclipse.cdt.core.search.ICSearchPattern;
|
import org.eclipse.cdt.core.search.ICSearchPattern;
|
||||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||||
import org.eclipse.cdt.core.search.IMatch;
|
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.search.SearchEngine;
|
||||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||||
import org.eclipse.cdt.internal.core.browser.cache.TypeCacheManager;
|
import org.eclipse.cdt.internal.core.browser.cache.TypeCacheManager;
|
||||||
|
@ -152,7 +153,7 @@ public class SearchRegressionTests extends BaseTestFramework implements ICSearch
|
||||||
Iterator i = matches.iterator();
|
Iterator i = matches.iterator();
|
||||||
while( i.hasNext() ){
|
while( i.hasNext() ){
|
||||||
IMatch match = (IMatch) i.next();
|
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
|
return; //match
|
||||||
}
|
}
|
||||||
fail( "Match at offset " + offset + " in \"" + file.getLocation() + "\" not found." ); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
|
fail( "Match at offset " + offset + " in \"" + file.getLocation() + "\" not found." ); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
|
||||||
|
|
|
@ -16,9 +16,11 @@ package org.eclipse.cdt.core.search.tests;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.parser.IOffsetDuple;
|
||||||
import org.eclipse.cdt.core.search.ICSearchConstants;
|
import org.eclipse.cdt.core.search.ICSearchConstants;
|
||||||
import org.eclipse.cdt.core.search.ICSearchPattern;
|
import org.eclipse.cdt.core.search.ICSearchPattern;
|
||||||
import org.eclipse.cdt.core.search.IMatch;
|
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.OrPattern;
|
||||||
import org.eclipse.cdt.core.search.SearchEngine;
|
import org.eclipse.cdt.core.search.SearchEngine;
|
||||||
import org.eclipse.cdt.internal.core.CharOperation;
|
import org.eclipse.cdt.internal.core.CharOperation;
|
||||||
|
@ -115,8 +117,8 @@ public class ClassDeclarationPatternTests extends BaseSearchTest implements ICSe
|
||||||
IMatch match2 = (IMatch)iter2.next();
|
IMatch match2 = (IMatch)iter2.next();
|
||||||
|
|
||||||
//assertTrue( match.path.equals( match2.path ) );
|
//assertTrue( match.path.equals( match2.path ) );
|
||||||
assertEquals( match.getStartOffset(), match2.getStartOffset() );
|
assertEquals( ((IOffsetLocatable) match.getLocatable()).getNameStartOffset(), ((IOffsetLocatable) match2.getLocatable()).getNameStartOffset() );
|
||||||
assertEquals( match.getEndOffset(), match2.getEndOffset() );
|
assertEquals( ((IOffsetLocatable) match.getLocatable()).getNameEndOffset() , ((IOffsetLocatable) match2.getLocatable()).getNameEndOffset() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWildcardQualification() {
|
public void testWildcardQualification() {
|
||||||
|
|
|
@ -17,6 +17,7 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.search.ICSearchPattern;
|
import org.eclipse.cdt.core.search.ICSearchPattern;
|
||||||
import org.eclipse.cdt.core.search.IMatch;
|
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.search.SearchEngine;
|
||||||
import org.eclipse.cdt.internal.core.CharOperation;
|
import org.eclipse.cdt.internal.core.CharOperation;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndex;
|
import org.eclipse.cdt.internal.core.index.IIndex;
|
||||||
|
@ -141,7 +142,7 @@ public class FunctionMethodPatternTests extends BaseSearchTest {
|
||||||
assertEquals( matches.size(), 1 );
|
assertEquals( matches.size(), 1 );
|
||||||
IMatch match2 = (IMatch) matches.iterator().next();
|
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$
|
pattern = SearchEngine.createSearchPattern( "operator \\*=", METHOD, DECLARATIONS, true ); //$NON-NLS-1$
|
||||||
search( workspace, pattern, scope, resultCollector );
|
search( workspace, pattern, scope, resultCollector );
|
||||||
|
@ -155,7 +156,7 @@ public class FunctionMethodPatternTests extends BaseSearchTest {
|
||||||
assertEquals( matches.size(), 1 );
|
assertEquals( matches.size(), 1 );
|
||||||
match2 = (IMatch) matches.iterator().next();
|
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$
|
pattern = SearchEngine.createSearchPattern( "operator *", METHOD, DECLARATIONS, true ); //$NON-NLS-1$
|
||||||
search( workspace, pattern, scope, resultCollector );
|
search( workspace, pattern, scope, resultCollector );
|
||||||
|
|
|
@ -137,7 +137,7 @@ class CTagsIndexAll extends CTagsIndexRequest {
|
||||||
String[] args = {"--excmd=number", //$NON-NLS-1$
|
String[] args = {"--excmd=number", //$NON-NLS-1$
|
||||||
"--format=2", //$NON-NLS-1$
|
"--format=2", //$NON-NLS-1$
|
||||||
"--sort=no", //$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$
|
||||||
"--c++-types=cdefgmnpstuvx", //$NON-NLS-1$
|
"--c++-types=cdefgmnpstuvx", //$NON-NLS-1$
|
||||||
"--languages=c,c++", //$NON-NLS-1$
|
"--languages=c,c++", //$NON-NLS-1$
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class CTagsIndexerRunner extends AbstractIndexer {
|
||||||
"--excmd=number", //$NON-NLS-1$
|
"--excmd=number", //$NON-NLS-1$
|
||||||
"--format=2", //$NON-NLS-1$
|
"--format=2", //$NON-NLS-1$
|
||||||
"--sort=no", //$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$
|
||||||
"--c++-types=cdefgmnpstuvx", //$NON-NLS-1$
|
"--c++-types=cdefgmnpstuvx", //$NON-NLS-1$
|
||||||
"--languages=c,c++", //$NON-NLS-1$
|
"--languages=c,c++", //$NON-NLS-1$
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Common Public License v1.0
|
* are made available under the terms of the Common Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -33,8 +33,7 @@ public class BasicSearchMatch implements IMatch, Comparable {
|
||||||
returnType = basicMatch.returnType;
|
returnType = basicMatch.returnType;
|
||||||
resource = basicMatch.resource;
|
resource = basicMatch.resource;
|
||||||
path = basicMatch.path;
|
path = basicMatch.path;
|
||||||
startOffset = basicMatch.startOffset;
|
locatable = basicMatch.locatable;
|
||||||
endOffset = basicMatch.endOffset;
|
|
||||||
referringElement = basicMatch.referringElement;
|
referringElement = basicMatch.referringElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,9 +52,9 @@ public class BasicSearchMatch implements IMatch, Comparable {
|
||||||
hashBuffer.append( getLocation().toString() );
|
hashBuffer.append( getLocation().toString() );
|
||||||
}
|
}
|
||||||
hashBuffer.append( HASH_SEPERATOR );
|
hashBuffer.append( HASH_SEPERATOR );
|
||||||
hashBuffer.append( startOffset );
|
hashBuffer.append( locatable instanceof IOffsetLocatable ? ((IOffsetLocatable)locatable).getNameStartOffset():((ILineLocatable)locatable).getStartLine());
|
||||||
hashBuffer.append( HASH_SEPERATOR );
|
hashBuffer.append( HASH_SEPERATOR );
|
||||||
hashBuffer.append( endOffset );
|
hashBuffer.append( locatable instanceof IOffsetLocatable ? ((IOffsetLocatable)locatable).getNameEndOffset(): ((ILineLocatable)locatable).getEndLine());
|
||||||
hashBuffer.append( HASH_SEPERATOR );
|
hashBuffer.append( HASH_SEPERATOR );
|
||||||
hashBuffer.append( type );
|
hashBuffer.append( type );
|
||||||
hashBuffer.append( HASH_SEPERATOR );
|
hashBuffer.append( HASH_SEPERATOR );
|
||||||
|
@ -72,8 +71,27 @@ public class BasicSearchMatch implements IMatch, Comparable {
|
||||||
}
|
}
|
||||||
BasicSearchMatch match = (BasicSearchMatch)obj;
|
BasicSearchMatch match = (BasicSearchMatch)obj;
|
||||||
|
|
||||||
if( startOffset != match.getStartOffset() || endOffset != match.getEndOffset() )
|
if ((locatable != null && match.locatable==null) ||
|
||||||
|
(locatable==null && match.locatable!=null)){
|
||||||
return false;
|
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() )
|
if( type != match.getElementType() || visibility != match.getVisibility() )
|
||||||
return false;
|
return false;
|
||||||
|
@ -121,8 +139,21 @@ public class BasicSearchMatch implements IMatch, Comparable {
|
||||||
int result = getLocation().toString().compareTo( match.getLocation().toString() );
|
int result = getLocation().toString().compareTo( match.getLocation().toString() );
|
||||||
if( result != 0 ) return result;
|
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() );
|
result = getName().compareTo( match.getName() );
|
||||||
if( result != 0 ) return result;
|
if( result != 0 ) return result;
|
||||||
|
@ -140,10 +171,7 @@ public class BasicSearchMatch implements IMatch, Comparable {
|
||||||
|
|
||||||
public IResource resource = null;
|
public IResource resource = null;
|
||||||
public IPath path = null;
|
public IPath path = null;
|
||||||
|
|
||||||
public int startOffset = 0;
|
|
||||||
public int endOffset = 0;
|
|
||||||
|
|
||||||
public int type = 0;
|
public int type = 0;
|
||||||
public int visibility = 0;
|
public int visibility = 0;
|
||||||
|
|
||||||
|
@ -155,7 +183,7 @@ public class BasicSearchMatch implements IMatch, Comparable {
|
||||||
|
|
||||||
public IPath referringElement = null;
|
public IPath referringElement = null;
|
||||||
|
|
||||||
public int offsetType;
|
public IMatchLocatable locatable = null;
|
||||||
|
|
||||||
public int getElementType() {
|
public int getElementType() {
|
||||||
return type;
|
return type;
|
||||||
|
@ -193,14 +221,6 @@ public class BasicSearchMatch implements IMatch, Comparable {
|
||||||
return referringElement;
|
return referringElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStartOffset() {
|
|
||||||
return startOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getEndOffset() {
|
|
||||||
return endOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isStatic() {
|
public boolean isStatic() {
|
||||||
return isStatic;
|
return isStatic;
|
||||||
}
|
}
|
||||||
|
@ -218,13 +238,6 @@ public class BasicSearchMatch implements IMatch, Comparable {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param i
|
|
||||||
*/
|
|
||||||
public void setEndOffset(int i) {
|
|
||||||
endOffset = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param b
|
* @param b
|
||||||
*/
|
*/
|
||||||
|
@ -266,14 +279,6 @@ public class BasicSearchMatch implements IMatch, Comparable {
|
||||||
public void setReturnType(String string) {
|
public void setReturnType(String string) {
|
||||||
returnType = string;
|
returnType = string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param i
|
|
||||||
*/
|
|
||||||
public void setStartOffset(int i) {
|
|
||||||
startOffset = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param i
|
* @param i
|
||||||
*/
|
*/
|
||||||
|
@ -287,13 +292,9 @@ public class BasicSearchMatch implements IMatch, Comparable {
|
||||||
public void setVisibility(int i) {
|
public void setVisibility(int i) {
|
||||||
visibility = i;
|
visibility = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getOffsetType() {
|
public IMatchLocatable getLocatable() {
|
||||||
return offsetType;
|
return locatable;
|
||||||
}
|
|
||||||
|
|
||||||
public void setOffsetType(int offsetType) {
|
|
||||||
this.offsetType = offsetType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,9 +84,8 @@ public class BasicSearchResultCollector implements ICSearchResultCollector {
|
||||||
result.resource = (IResource) fileResource;
|
result.resource = (IResource) fileResource;
|
||||||
else if( fileResource instanceof IPath )
|
else if( fileResource instanceof IPath )
|
||||||
result.path = (IPath) fileResource;
|
result.path = (IPath) fileResource;
|
||||||
|
|
||||||
result.startOffset = start;
|
result.locatable = new OffsetLocatable(start,end);
|
||||||
result.endOffset = end;
|
|
||||||
result.parentName = ""; //$NON-NLS-1$
|
result.parentName = ""; //$NON-NLS-1$
|
||||||
result.referringElement = referringElement;
|
result.referringElement = referringElement;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
package org.eclipse.cdt.core.search;
|
||||||
|
|
||||||
|
public interface ILineLocatable extends IMatchLocatable {
|
||||||
|
int getStartLine();
|
||||||
|
int getEndLine();
|
||||||
|
}
|
|
@ -33,26 +33,9 @@ public interface IMatch {
|
||||||
IPath getLocation();
|
IPath getLocation();
|
||||||
|
|
||||||
IPath getReferenceLocation();
|
IPath getReferenceLocation();
|
||||||
/**
|
|
||||||
* Returns the start offset for this match. Note that clients should use
|
IMatchLocatable getLocatable();
|
||||||
* 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();
|
|
||||||
|
|
||||||
boolean isStatic();
|
boolean isStatic();
|
||||||
boolean isConst();
|
boolean isConst();
|
||||||
boolean isVolatile();
|
boolean isVolatile();
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package org.eclipse.cdt.core.search;
|
||||||
|
|
||||||
|
public interface IMatchLocatable {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package org.eclipse.cdt.core.search;
|
||||||
|
|
||||||
|
public interface IOffsetLocatable extends IMatchLocatable {
|
||||||
|
int getNameStartOffset();
|
||||||
|
int getNameEndOffset();
|
||||||
|
|
||||||
|
int getElementStartOffset();
|
||||||
|
int getElementEndOffset();
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.parser.ast.IASTTypedefDeclaration;
|
||||||
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
||||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
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.CharOperation;
|
||||||
import org.eclipse.cdt.internal.core.index.IEntryResult;
|
import org.eclipse.cdt.internal.core.index.IEntryResult;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndex;
|
import org.eclipse.cdt.internal.core.index.IIndex;
|
||||||
|
@ -183,12 +185,11 @@ public class ClassDeclarationPattern extends CSearchPattern {
|
||||||
//Offsets can either be LINE or OFFSET
|
//Offsets can either be LINE or OFFSET
|
||||||
int offsetType = Integer.valueOf(String.valueOf(offsets[i][j]).substring(0,1)).intValue();
|
int offsetType = Integer.valueOf(String.valueOf(offsets[i][j]).substring(0,1)).intValue();
|
||||||
if (offsetType==IIndex.LINE){
|
if (offsetType==IIndex.LINE){
|
||||||
match.startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
|
match.locatable = new LineLocatable(Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue(),0);
|
||||||
match.offsetType = IIndex.LINE;
|
|
||||||
}else if (offsetType==IIndex.OFFSET){
|
}else if (offsetType==IIndex.OFFSET){
|
||||||
match.startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
|
int startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
|
||||||
match.endOffset= match.startOffset + offsetLengths[i][j];
|
int endOffset= startOffset + offsetLengths[i][j];
|
||||||
match.offsetType=IIndex.OFFSET;
|
match.locatable = new OffsetLocatable(startOffset, endOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
match.parentName = ""; //$NON-NLS-1$
|
match.parentName = ""; //$NON-NLS-1$
|
||||||
|
|
|
@ -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.parser.ast.IASTVariable;
|
||||||
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
||||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
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.IEntryResult;
|
||||||
import org.eclipse.cdt.internal.core.index.cindexstorage.Index;
|
import org.eclipse.cdt.internal.core.index.cindexstorage.Index;
|
||||||
import org.eclipse.cdt.internal.core.index.cindexstorage.IndexedFileEntry;
|
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
|
//Offsets can either be LINE or OFFSET
|
||||||
int offsetType = Integer.valueOf(String.valueOf(offsets[i][j]).substring(0,1)).intValue();
|
int offsetType = Integer.valueOf(String.valueOf(offsets[i][j]).substring(0,1)).intValue();
|
||||||
if (offsetType==Index.LINE){
|
if (offsetType==Index.LINE){
|
||||||
match.startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
|
match.locatable = new LineLocatable(Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue(),0);
|
||||||
match.offsetType = Index.LINE;
|
|
||||||
}else if (offsetType==Index.OFFSET){
|
}else if (offsetType==Index.OFFSET){
|
||||||
match.startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
|
int startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
|
||||||
match.endOffset= match.startOffset + offsetLengths[i][j];
|
int endOffset= startOffset + offsetLengths[i][j];
|
||||||
match.offsetType=Index.OFFSET;
|
match.locatable = new OffsetLocatable(startOffset, endOffset);
|
||||||
}
|
}
|
||||||
match.parentName = ""; //$NON-NLS-1$
|
match.parentName = ""; //$NON-NLS-1$
|
||||||
if (searchFor == FIELD){
|
if (searchFor == FIELD){
|
||||||
|
|
|
@ -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.parser.ast.IASTOffsetableNamedElement;
|
||||||
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
||||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
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.IEntryResult;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndex;
|
import org.eclipse.cdt.internal.core.index.IIndex;
|
||||||
import org.eclipse.cdt.internal.core.index.cindexstorage.Index;
|
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
|
//Offsets can either be LINE or OFFSET
|
||||||
int offsetType = Integer.valueOf(String.valueOf(offsets[i][j]).substring(0,1)).intValue();
|
int offsetType = Integer.valueOf(String.valueOf(offsets[i][j]).substring(0,1)).intValue();
|
||||||
if (offsetType==IIndex.LINE){
|
if (offsetType==IIndex.LINE){
|
||||||
match.startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
|
match.locatable = new LineLocatable(Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue(),0);
|
||||||
match.offsetType=IIndex.LINE;
|
|
||||||
}else if (offsetType==IIndex.OFFSET){
|
}else if (offsetType==IIndex.OFFSET){
|
||||||
match.startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
|
int startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
|
||||||
match.endOffset= match.startOffset + offsetLengths[i][j];
|
int endOffset= startOffset + offsetLengths[i][j];
|
||||||
match.offsetType=IIndex.OFFSET;
|
match.locatable = new OffsetLocatable(startOffset, endOffset);
|
||||||
}
|
}
|
||||||
match.parentName = ""; //$NON-NLS-1$
|
match.parentName = ""; //$NON-NLS-1$
|
||||||
match.type = ICElement.C_MACRO;
|
match.type = ICElement.C_MACRO;
|
||||||
|
|
|
@ -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.parser.ast.IASTQualifiedNameElement;
|
||||||
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
||||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
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.CharOperation;
|
||||||
import org.eclipse.cdt.internal.core.index.IEntryResult;
|
import org.eclipse.cdt.internal.core.index.IEntryResult;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndex;
|
import org.eclipse.cdt.internal.core.index.IIndex;
|
||||||
|
@ -186,12 +188,11 @@ public class MethodDeclarationPattern extends CSearchPattern {
|
||||||
//Offsets can either be LINE or OFFSET
|
//Offsets can either be LINE or OFFSET
|
||||||
int offsetType = Integer.valueOf(String.valueOf(offsets[i][j]).substring(0,1)).intValue();
|
int offsetType = Integer.valueOf(String.valueOf(offsets[i][j]).substring(0,1)).intValue();
|
||||||
if (offsetType==IIndex.LINE){
|
if (offsetType==IIndex.LINE){
|
||||||
match.startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
|
match.locatable = new LineLocatable(Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue(),0);
|
||||||
match.offsetType = IIndex.LINE;
|
|
||||||
}else if (offsetType==IIndex.OFFSET){
|
}else if (offsetType==IIndex.OFFSET){
|
||||||
match.startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
|
int startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
|
||||||
match.endOffset= match.startOffset + offsetLengths[i][j];
|
int endOffset= startOffset + offsetLengths[i][j];
|
||||||
match.offsetType=IIndex.OFFSET;
|
match.locatable = new OffsetLocatable(startOffset, endOffset);
|
||||||
}
|
}
|
||||||
match.parentName = ""; //$NON-NLS-1$
|
match.parentName = ""; //$NON-NLS-1$
|
||||||
if (searchFor == METHOD){
|
if (searchFor == METHOD){
|
||||||
|
|
|
@ -21,6 +21,8 @@ import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
||||||
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
||||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
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.IEntryResult;
|
||||||
import org.eclipse.cdt.internal.core.index.IIndex;
|
import org.eclipse.cdt.internal.core.index.IIndex;
|
||||||
import org.eclipse.cdt.internal.core.index.cindexstorage.Index;
|
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
|
//Offsets can either be LINE or OFFSET
|
||||||
int offsetType = Integer.valueOf(String.valueOf(offsets[i][j]).substring(0,1)).intValue();
|
int offsetType = Integer.valueOf(String.valueOf(offsets[i][j]).substring(0,1)).intValue();
|
||||||
if (offsetType==IIndex.LINE){
|
if (offsetType==IIndex.LINE){
|
||||||
match.startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
|
match.locatable = new LineLocatable(Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue(),0);
|
||||||
match.offsetType = IIndex.LINE;
|
|
||||||
}else if (offsetType==IIndex.OFFSET){
|
}else if (offsetType==IIndex.OFFSET){
|
||||||
match.startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
|
int startOffset=Integer.valueOf(String.valueOf(offsets[i][j]).substring(1)).intValue();
|
||||||
match.endOffset= match.startOffset + offsetLengths[i][j];
|
int endOffset= startOffset + offsetLengths[i][j];
|
||||||
match.offsetType=IIndex.OFFSET;
|
match.locatable = new OffsetLocatable(startOffset, endOffset);
|
||||||
}
|
}
|
||||||
match.parentName = ""; //$NON-NLS-1$
|
match.parentName = ""; //$NON-NLS-1$
|
||||||
match.type=ICElement.C_NAMESPACE;
|
match.type=ICElement.C_NAMESPACE;
|
||||||
|
|
|
@ -34,6 +34,8 @@ import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||||
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
||||||
import org.eclipse.cdt.core.search.IMatch;
|
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.CSearchQuery;
|
||||||
import org.eclipse.cdt.internal.ui.search.CSearchResult;
|
import org.eclipse.cdt.internal.ui.search.CSearchResult;
|
||||||
import org.eclipse.cdt.internal.ui.search.NewSearchResultCollector;
|
import org.eclipse.cdt.internal.ui.search.NewSearchResultCollector;
|
||||||
|
@ -126,8 +128,9 @@ public class DOMDisplaySearchNames extends CSearchQuery implements ISearchQuery
|
||||||
else if( fileResource instanceof IPath )
|
else if( fileResource instanceof IPath )
|
||||||
result.path = (IPath) fileResource;
|
result.path = (IPath) fileResource;
|
||||||
|
|
||||||
result.startOffset = start;
|
IOffsetLocatable locatable = new OffsetLocatable(start,end);
|
||||||
result.endOffset = end;
|
result.locatable = locatable;
|
||||||
|
|
||||||
result.parentName = BLANK_STRING; //$NON-NLS-1$
|
result.parentName = BLANK_STRING; //$NON-NLS-1$
|
||||||
result.referringElement = referringElement;
|
result.referringElement = referringElement;
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,11 @@ import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
||||||
import org.eclipse.cdt.core.search.IMatch;
|
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.IEntryResult;
|
||||||
|
import org.eclipse.cdt.internal.core.index.IIndex;
|
||||||
import org.eclipse.cdt.internal.ui.search.CSearchQuery;
|
import org.eclipse.cdt.internal.ui.search.CSearchQuery;
|
||||||
import org.eclipse.cdt.internal.ui.search.CSearchResult;
|
import org.eclipse.cdt.internal.ui.search.CSearchResult;
|
||||||
import org.eclipse.cdt.internal.ui.search.NewSearchResultCollector;
|
import org.eclipse.cdt.internal.ui.search.NewSearchResultCollector;
|
||||||
|
@ -193,15 +197,20 @@ public class IndexerQuery extends CSearchQuery implements ISearchQuery {
|
||||||
result.resource = (IResource) fileResource;
|
result.resource = (IResource) fileResource;
|
||||||
else if( fileResource instanceof IPath )
|
else if( fileResource instanceof IPath )
|
||||||
result.path = (IPath) fileResource;
|
result.path = (IPath) fileResource;
|
||||||
|
|
||||||
result.startOffset = start;
|
IMatchLocatable locatable=null;
|
||||||
result.endOffset = end;
|
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.parentName = BLANK_STRING; //$NON-NLS-1$
|
||||||
result.referringElement = referringElement;
|
result.referringElement = referringElement;
|
||||||
|
|
||||||
result.name = name;
|
result.name = name;
|
||||||
|
|
||||||
result.offsetType = offsetType;
|
|
||||||
|
|
||||||
result.type = ICElement.C_FIELD; // TODO Devin static for now, want something like BasicSearchResultCollector#setElementInfo
|
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
|
result.visibility = ICElement.CPP_PUBLIC; // TODO Devin static for now, want something like BasicSearchResultCollector#setElementInfo
|
||||||
|
|
|
@ -41,6 +41,9 @@ import org.eclipse.cdt.core.model.IVariable;
|
||||||
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
||||||
import org.eclipse.cdt.core.search.ICSearchConstants;
|
import org.eclipse.cdt.core.search.ICSearchConstants;
|
||||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
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.OrPattern;
|
||||||
import org.eclipse.cdt.core.search.SearchEngine;
|
import org.eclipse.cdt.core.search.SearchEngine;
|
||||||
import org.eclipse.cdt.internal.corext.Assert;
|
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++){
|
for (int j= 0; j < results.length; j++){
|
||||||
BasicSearchMatch searchResult= results[j];
|
BasicSearchMatch searchResult= results[j];
|
||||||
int oldNameLength = getCurrentElementNameLength();
|
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,
|
manager.get(wc).addTextEdit(name,
|
||||||
new ReplaceEdit(offset, oldNameLength, fNewElementName));
|
new ReplaceEdit(offset, oldNameLength, fNewElementName));
|
||||||
}
|
}
|
||||||
|
@ -712,7 +725,7 @@ public class RenameElementProcessor extends RenameProcessor implements IReferenc
|
||||||
if(( returnType == null) || (returnType.length() == 0) )
|
if(( returnType == null) || (returnType.length() == 0) )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if(getCurrentElementName().startsWith("~")) //$NON-NLS-1$
|
if(getCurrentElementName().startsWith("~"))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -118,8 +118,8 @@ public class CSearchResultCollector extends BasicSearchResultCollector{
|
||||||
HashMap markerAttributes = new HashMap( 2 );
|
HashMap markerAttributes = new HashMap( 2 );
|
||||||
|
|
||||||
//we can hang any other info we want off the marker
|
//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_START, new Integer( Math.max( searchMatch.startOffset, 0 ) ) );
|
||||||
markerAttributes.put( IMarker.CHAR_END, new Integer( Math.max( searchMatch.endOffset, 0 ) ) );
|
markerAttributes.put( IMarker.CHAR_END, new Integer( Math.max( searchMatch.endOffset, 0 ) ) );*/
|
||||||
markerAttributes.put( IMATCH, searchMatch );
|
markerAttributes.put( IMATCH, searchMatch );
|
||||||
|
|
||||||
marker.setAttributes( markerAttributes );
|
marker.setAttributes( markerAttributes );
|
||||||
|
@ -159,8 +159,8 @@ public class CSearchResultCollector extends BasicSearchResultCollector{
|
||||||
|
|
||||||
HashMap markerAttributes = new HashMap( 2 );
|
HashMap markerAttributes = new HashMap( 2 );
|
||||||
|
|
||||||
markerAttributes.put( IMarker.CHAR_START, new Integer( Math.max( searchMatch.startOffset, 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( IMarker.CHAR_END, new Integer( Math.max( searchMatch.endOffset, 0 ) ) );*/
|
||||||
markerAttributes.put( IMATCH, searchMatch );
|
markerAttributes.put( IMATCH, searchMatch );
|
||||||
|
|
||||||
marker.setAttributes( markerAttributes );
|
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 MATCHES = CSearchMessages.getString("CSearchResultCollector.matches"); //$NON-NLS-1$
|
||||||
private static final String DONE = CSearchMessages.getString("CSearchResultCollector.done"); //$NON-NLS-1$
|
private static final String DONE = CSearchMessages.getString("CSearchResultCollector.done"); //$NON-NLS-1$
|
||||||
|
|
||||||
private IProgressMonitor _monitor;
|
private IProgressMonitor _monitor;
|
||||||
private CSearchOperation _operation;
|
private CSearchOperation _operation;
|
||||||
private ISearchResultView _view;
|
private ISearchResultView _view;
|
||||||
private IGroupByKeyComputer _computer;
|
private IGroupByKeyComputer _computer;
|
||||||
private int _matchCount;
|
private int _matchCount;
|
||||||
private CSearchQuery _query;
|
private CSearchQuery _query;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param query
|
* @param query
|
||||||
|
|
|
@ -17,7 +17,9 @@ import java.util.HashMap;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
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.CPluginImages;
|
||||||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||||
import org.eclipse.cdt.internal.ui.editor.ExternalSearchFile;
|
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.IMenuManager;
|
||||||
import org.eclipse.jface.action.IToolBarManager;
|
import org.eclipse.jface.action.IToolBarManager;
|
||||||
import org.eclipse.jface.action.MenuManager;
|
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.StructuredViewer;
|
||||||
import org.eclipse.jface.viewers.TableViewer;
|
import org.eclipse.jface.viewers.TableViewer;
|
||||||
import org.eclipse.jface.viewers.TreeViewer;
|
import org.eclipse.jface.viewers.TreeViewer;
|
||||||
|
@ -113,16 +117,52 @@ public class CSearchResultPage extends AbstractTextSearchViewPage {
|
||||||
BasicSearchMatch searchMatch = ((CSearchMatch) match).getSearchMatch();
|
BasicSearchMatch searchMatch = ((CSearchMatch) match).getSearchMatch();
|
||||||
if (searchMatch.resource != null){
|
if (searchMatch.resource != null){
|
||||||
editor = IDE.openEditor(CUIPlugin.getActivePage(), getCanonicalFile((IFile) searchMatch.resource), false);
|
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 {
|
else {
|
||||||
|
//Match is outside of the workspace
|
||||||
try {
|
try {
|
||||||
IEditorInput input =EditorUtility.getEditorInput(new ExternalSearchFile(searchMatch.path, searchMatch));
|
IEditorInput input =EditorUtility.getEditorInput(new ExternalSearchFile(searchMatch.path, searchMatch));
|
||||||
IWorkbenchPage p= CUIPlugin.getActivePage();
|
IWorkbenchPage p= CUIPlugin.getActivePage();
|
||||||
IEditorPart editorPart= p.openEditor(input, "org.eclipse.cdt.ui.editor.ExternalSearchEditor"); //$NON-NLS-1$
|
IEditorPart editorPart= p.openEditor(input, "org.eclipse.cdt.ui.editor.ExternalSearchEditor"); //$NON-NLS-1$
|
||||||
if (editorPart instanceof ITextEditor) {
|
if (editorPart instanceof ITextEditor) {
|
||||||
ITextEditor textEditor= (ITextEditor) editorPart;
|
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
|
//TODO: Put in once we have marker support for External Translation Units
|
||||||
|
@ -191,14 +231,14 @@ public class CSearchResultPage extends AbstractTextSearchViewPage {
|
||||||
setSortOrder(_currentSortOrder);
|
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 {
|
try {
|
||||||
IMarker marker= file.createMarker(NewSearchUI.SEARCH_MARKER);
|
IMarker marker= file.createMarker(NewSearchUI.SEARCH_MARKER);
|
||||||
HashMap attributes= new HashMap(4);
|
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_START, new Integer(offset));
|
||||||
attributes.put(IMarker.CHAR_END, new Integer(offset + length));
|
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));
|
attributes.put(IMarker.LINE_NUMBER, new Integer(offset));
|
||||||
}
|
}
|
||||||
marker.setAttributes(attributes);
|
marker.setAttributes(attributes);
|
||||||
|
|
|
@ -44,6 +44,7 @@ import org.eclipse.cdt.core.search.DOMSearchUtil;
|
||||||
import org.eclipse.cdt.core.search.ICSearchResultCollector;
|
import org.eclipse.cdt.core.search.ICSearchResultCollector;
|
||||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||||
import org.eclipse.cdt.core.search.IMatch;
|
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.internal.core.dom.parser.cpp.CPPASTName;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
@ -183,8 +184,7 @@ public class DOMQuery extends CSearchQuery implements ISearchQuery {
|
||||||
else if( fileResource instanceof IPath )
|
else if( fileResource instanceof IPath )
|
||||||
result.path = (IPath) fileResource;
|
result.path = (IPath) fileResource;
|
||||||
|
|
||||||
result.startOffset = start;
|
result.locatable = new OffsetLocatable(start,end);
|
||||||
result.endOffset = end;
|
|
||||||
result.parentName = BLANK_STRING; //$NON-NLS-1$
|
result.parentName = BLANK_STRING; //$NON-NLS-1$
|
||||||
result.referringElement = referringElement;
|
result.referringElement = referringElement;
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,11 @@ import org.eclipse.cdt.core.CCorePlugin;
|
||||||
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.ITranslationUnit;
|
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.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.cdt.ui.CElementContentProvider;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
@ -68,11 +72,19 @@ public class LevelTreeContentProvider extends CSearchContentProvider implements
|
||||||
|
|
||||||
if (child instanceof CSearchMatch){
|
if (child instanceof CSearchMatch){
|
||||||
BasicSearchMatch tempMatch = ((CSearchMatch) child).getSearchMatch();
|
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());
|
ICElement cTransUnit = CCorePlugin.getDefault().getCoreModel().create(tempMatch.getResource());
|
||||||
|
|
||||||
if (cTransUnit instanceof ITranslationUnit){
|
if (cTransUnit instanceof ITranslationUnit){
|
||||||
try {
|
try {
|
||||||
child = ((ITranslationUnit) cTransUnit).getElementAtOffset(tempMatch.startOffset);
|
child = ((ITranslationUnit) cTransUnit).getElementAtOffset(startOffset);
|
||||||
} catch (CModelException e) {}
|
} catch (CModelException e) {}
|
||||||
}
|
}
|
||||||
if( child == null ){
|
if( child == null ){
|
||||||
|
|
|
@ -15,7 +15,10 @@ import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
||||||
import org.eclipse.cdt.core.search.BasicSearchResultCollector;
|
import org.eclipse.cdt.core.search.BasicSearchResultCollector;
|
||||||
import org.eclipse.cdt.core.search.ICSearchConstants;
|
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.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.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
@ -87,8 +90,23 @@ public class NewSearchResultCollector extends BasicSearchResultCollector {
|
||||||
|
|
||||||
if (searchMatch.resource != null){
|
if (searchMatch.resource != null){
|
||||||
fMatchCount++;
|
fMatchCount++;
|
||||||
int start = match.getStartOffset();
|
int start =0;
|
||||||
int end = match.getEndOffset();
|
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();
|
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));
|
fSearch.addMatch(new CSearchMatch(classifier,start,end-start, match));
|
||||||
|
|
||||||
|
@ -96,8 +114,23 @@ public class NewSearchResultCollector extends BasicSearchResultCollector {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fMatchCount++;
|
fMatchCount++;
|
||||||
int start = match.getStartOffset();
|
int start =0;
|
||||||
int end = match.getEndOffset();
|
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();
|
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));
|
fSearch.addMatch(new CSearchMatch(classifier,start,end-start, match));
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,10 @@ import org.eclipse.cdt.core.parser.ParserUtil;
|
||||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
import org.eclipse.cdt.core.search.DOMSearchUtil;
|
import org.eclipse.cdt.core.search.DOMSearchUtil;
|
||||||
import org.eclipse.cdt.core.search.ICSearchConstants;
|
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.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.core.search.SearchEngine;
|
||||||
import org.eclipse.cdt.internal.core.model.CProject;
|
import org.eclipse.cdt.internal.core.model.CProject;
|
||||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
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.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
||||||
import org.eclipse.jface.operation.IRunnableWithProgress;
|
import org.eclipse.jface.operation.IRunnableWithProgress;
|
||||||
|
import org.eclipse.jface.text.BadLocationException;
|
||||||
|
import org.eclipse.jface.text.IDocument;
|
||||||
import org.eclipse.ui.texteditor.IUpdate;
|
import org.eclipse.ui.texteditor.IUpdate;
|
||||||
|
|
||||||
public class OpenDeclarationsAction extends SelectionParseAction implements IUpdate {
|
public class OpenDeclarationsAction extends SelectionParseAction implements IUpdate {
|
||||||
|
@ -175,8 +180,34 @@ public class OpenDeclarationsAction extends SelectionParseAction implements IUpd
|
||||||
if (match instanceof IMatch) {
|
if (match instanceof IMatch) {
|
||||||
IMatch theMatch = (IMatch)match;
|
IMatch theMatch = (IMatch)match;
|
||||||
storage.setFileName(theMatch.getLocation().toOSString());
|
storage.setFileName(theMatch.getLocation().toOSString());
|
||||||
storage.setLength(theMatch.getEndOffset() - theMatch.getStartOffset());
|
IMatchLocatable searchLocatable = theMatch.getLocatable();
|
||||||
storage.setOffset(theMatch.getStartOffset());
|
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()));
|
storage.setResource(ParserUtil.getResourceForFilename(theMatch.getLocation().toOSString()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,10 @@ import org.eclipse.cdt.core.parser.ParserUtil;
|
||||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||||
import org.eclipse.cdt.core.search.DOMSearchUtil;
|
import org.eclipse.cdt.core.search.DOMSearchUtil;
|
||||||
import org.eclipse.cdt.core.search.ICSearchConstants;
|
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.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.core.search.SearchEngine;
|
||||||
import org.eclipse.cdt.internal.core.model.CProject;
|
import org.eclipse.cdt.internal.core.model.CProject;
|
||||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
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.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
||||||
import org.eclipse.jface.operation.IRunnableWithProgress;
|
import org.eclipse.jface.operation.IRunnableWithProgress;
|
||||||
|
import org.eclipse.jface.text.BadLocationException;
|
||||||
|
import org.eclipse.jface.text.IDocument;
|
||||||
import org.eclipse.ui.texteditor.IUpdate;
|
import org.eclipse.ui.texteditor.IUpdate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -178,7 +183,7 @@ public class OpenDefinitionAction extends SelectionParseAction implements
|
||||||
// step 3 starts here
|
// step 3 starts here
|
||||||
ICElement[] scope = new ICElement[1];
|
ICElement[] scope = new ICElement[1];
|
||||||
scope[0] = new CProject(null, fEditor.getInputFile().getProject());
|
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) {
|
if (matches != null && matches.size() > 0) {
|
||||||
Iterator itr = matches.iterator();
|
Iterator itr = matches.iterator();
|
||||||
|
@ -187,8 +192,33 @@ public class OpenDefinitionAction extends SelectionParseAction implements
|
||||||
if (match instanceof IMatch) {
|
if (match instanceof IMatch) {
|
||||||
IMatch theMatch = (IMatch)match;
|
IMatch theMatch = (IMatch)match;
|
||||||
storage.setFileName(theMatch.getLocation().toOSString());
|
storage.setFileName(theMatch.getLocation().toOSString());
|
||||||
storage.setLength(theMatch.getEndOffset() - theMatch.getStartOffset());
|
IMatchLocatable searchLocatable = theMatch.getLocatable();
|
||||||
storage.setOffset(theMatch.getStartOffset());
|
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()));
|
storage.setResource(ParserUtil.getResourceForFilename(theMatch.getLocation().toOSString()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,6 @@ import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||||
import org.eclipse.cdt.core.resources.FileStorage;
|
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.editor.CEditor;
|
||||||
import org.eclipse.cdt.internal.ui.search.CSearchMessages;
|
import org.eclipse.cdt.internal.ui.search.CSearchMessages;
|
||||||
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
||||||
|
@ -613,12 +612,6 @@ public class SelectionParseAction extends Action {
|
||||||
return fEditor.getSite().getShell();
|
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.
|
* Opens the editor on the given element and subsequently selects it.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -24,7 +24,10 @@ import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||||
import org.eclipse.cdt.core.search.BasicSearchResultCollector;
|
import org.eclipse.cdt.core.search.BasicSearchResultCollector;
|
||||||
import org.eclipse.cdt.core.search.ICSearchConstants;
|
import org.eclipse.cdt.core.search.ICSearchConstants;
|
||||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
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.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.OrPattern;
|
||||||
import org.eclipse.cdt.core.search.SearchEngine;
|
import org.eclipse.cdt.core.search.SearchEngine;
|
||||||
import org.eclipse.cdt.internal.ui.codemanipulation.StubUtility;
|
import org.eclipse.cdt.internal.ui.codemanipulation.StubUtility;
|
||||||
|
@ -84,7 +87,7 @@ public class CSourceHover extends AbstractCEditorTextHover implements ITextHover
|
||||||
ICElement curr = copy.getElement(expression);
|
ICElement curr = copy.getElement(expression);
|
||||||
if (curr == null) {
|
if (curr == null) {
|
||||||
// Try with the indexer
|
// Try with the indexer
|
||||||
source = findMatches(expression);
|
source = findMatches(expression, textViewer);
|
||||||
} else {
|
} else {
|
||||||
source= ((ISourceReference) curr).getSource();
|
source= ((ISourceReference) curr).getSource();
|
||||||
}
|
}
|
||||||
|
@ -152,7 +155,7 @@ public class CSourceHover extends AbstractCEditorTextHover implements ITextHover
|
||||||
return source.substring(i);
|
return source.substring(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String findMatches(String name) {
|
private String findMatches(String name, ITextViewer textViewer) {
|
||||||
IEditorPart editor = getEditor();
|
IEditorPart editor = getEditor();
|
||||||
if (editor != null) {
|
if (editor != null) {
|
||||||
IEditorInput input= editor.getEditorInput();
|
IEditorInput input= editor.getEditorInput();
|
||||||
|
@ -191,8 +194,33 @@ public class CSourceHover extends AbstractCEditorTextHover implements ITextHover
|
||||||
ICElement celement = CoreModel.getDefault().create(resource);
|
ICElement celement = CoreModel.getDefault().create(resource);
|
||||||
if (celement instanceof ITranslationUnit) {
|
if (celement instanceof ITranslationUnit) {
|
||||||
ITranslationUnit unit = (ITranslationUnit)celement;
|
ITranslationUnit unit = (ITranslationUnit)celement;
|
||||||
int startOffset = matches[0].getStartOffset();
|
//Check offset type
|
||||||
int length = matches[0].getEndOffset() - startOffset;
|
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);
|
return unit.getBuffer().getText(startOffset, length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue