mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
External markers patch: allows searches on external included files
This commit is contained in:
parent
d46e5977ea
commit
5ab48f40ff
10 changed files with 118 additions and 43 deletions
|
@ -1,3 +1,17 @@
|
||||||
|
2004-03-24 Bogdan Gheorghe
|
||||||
|
Modified BasicSearchMatch to keep track of what files contained the match in order
|
||||||
|
to create file links to support external file markers.
|
||||||
|
|
||||||
|
Modified MatchLocator to pass in the referring file path to BasicSearchMatch if the
|
||||||
|
match has no resource attached to it (ie. the match is external).
|
||||||
|
|
||||||
|
* search/org/eclipse/cdt/core/search/BasicSearchResultCollector.java
|
||||||
|
* search/org/eclipse/cdt/core/search/BasicSearchMatch.java
|
||||||
|
* search/org/eclipse/cdt/core/search/ICSearchResultCollector.java
|
||||||
|
* search/org/eclipse/cdt/core/search/IMatch.java
|
||||||
|
* search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java
|
||||||
|
|
||||||
|
|
||||||
2004-03-08 Bogdan Gheorghe
|
2004-03-08 Bogdan Gheorghe
|
||||||
BasicSearchResultCollector patch from Chris Wiebe - adds setProgressMonitor method,
|
BasicSearchResultCollector patch from Chris Wiebe - adds setProgressMonitor method,
|
||||||
cleans up some of the CoreException warnings
|
cleans up some of the CoreException warnings
|
||||||
|
|
|
@ -35,6 +35,7 @@ public class BasicSearchMatch implements IMatch, Comparable {
|
||||||
path = basicMatch.path;
|
path = basicMatch.path;
|
||||||
startOffset = basicMatch.startOffset;
|
startOffset = basicMatch.startOffset;
|
||||||
endOffset = basicMatch.endOffset;
|
endOffset = basicMatch.endOffset;
|
||||||
|
referringElement = basicMatch.referringElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int hashCode(){
|
public int hashCode(){
|
||||||
|
@ -134,6 +135,8 @@ public class BasicSearchMatch implements IMatch, Comparable {
|
||||||
boolean isVolatile = false;
|
boolean isVolatile = false;
|
||||||
boolean isStatic = false;
|
boolean isStatic = false;
|
||||||
|
|
||||||
|
public IPath referringElement = null;
|
||||||
|
|
||||||
public int getElementType() {
|
public int getElementType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
@ -165,6 +168,10 @@ public class BasicSearchMatch implements IMatch, Comparable {
|
||||||
return path;
|
return path;
|
||||||
else return null;
|
else return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IPath getReferenceLocation() {
|
||||||
|
return referringElement;
|
||||||
|
}
|
||||||
|
|
||||||
public int getStartOffset() {
|
public int getStartOffset() {
|
||||||
return startOffset;
|
return startOffset;
|
||||||
|
|
|
@ -77,13 +77,13 @@ public class BasicSearchResultCollector implements ICSearchResultCollector {
|
||||||
fProgressMonitor = monitor;
|
fProgressMonitor = monitor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IMatch createMatch(Object fileResource, int start, int end, ISourceElementCallbackDelegate node )
|
public IMatch createMatch(Object fileResource, int start, int end, ISourceElementCallbackDelegate node, IPath referringElement)
|
||||||
{
|
{
|
||||||
BasicSearchMatch result = new BasicSearchMatch();
|
BasicSearchMatch result = new BasicSearchMatch();
|
||||||
return createMatch( result, fileResource, start, end, node );
|
return createMatch( result, fileResource, start, end, node, referringElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IMatch createMatch( BasicSearchMatch result, Object fileResource, int start, int end, ISourceElementCallbackDelegate node ) {
|
public IMatch createMatch( BasicSearchMatch result, Object fileResource, int start, int end, ISourceElementCallbackDelegate node, IPath referringElement ) {
|
||||||
if( fileResource instanceof IResource )
|
if( fileResource instanceof IResource )
|
||||||
result.resource = (IResource) fileResource;
|
result.resource = (IResource) fileResource;
|
||||||
else if( fileResource instanceof IPath )
|
else if( fileResource instanceof IPath )
|
||||||
|
@ -92,6 +92,7 @@ public class BasicSearchResultCollector implements ICSearchResultCollector {
|
||||||
result.startOffset = start;
|
result.startOffset = start;
|
||||||
result.endOffset = end;
|
result.endOffset = end;
|
||||||
result.parentName = ""; //$NON-NLS-1$
|
result.parentName = ""; //$NON-NLS-1$
|
||||||
|
result.referringElement = referringElement;
|
||||||
|
|
||||||
IASTOffsetableNamedElement offsetable = null;
|
IASTOffsetableNamedElement offsetable = null;
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ package org.eclipse.cdt.core.search;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
|
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,7 +48,7 @@ public interface ICSearchResultCollector {
|
||||||
public void done();
|
public void done();
|
||||||
|
|
||||||
public IMatch createMatch( Object fileResource, int start, int end,
|
public IMatch createMatch( Object fileResource, int start, int end,
|
||||||
ISourceElementCallbackDelegate node ) throws CoreException;
|
ISourceElementCallbackDelegate node, IPath referringElement) throws CoreException;
|
||||||
|
|
||||||
//return whether or not the match was accepted
|
//return whether or not the match was accepted
|
||||||
public boolean acceptMatch( IMatch match ) throws CoreException;
|
public boolean acceptMatch( IMatch match ) throws CoreException;
|
||||||
|
@ -58,15 +59,4 @@ public interface ICSearchResultCollector {
|
||||||
* @return a progress monitor or null if no progress monitor is provided
|
* @return a progress monitor or null if no progress monitor is provided
|
||||||
*/
|
*/
|
||||||
public IProgressMonitor getProgressMonitor();
|
public IProgressMonitor getProgressMonitor();
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns an IMatch object that contains any information the client cared
|
|
||||||
* to extract from the IAST node.
|
|
||||||
* Note that clients should not reference information in the node itself so
|
|
||||||
* that it can be garbage collected
|
|
||||||
* @param node
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
//public IMatch createMatch(ISourceElementCallbackDelegate node, IASTScope parent );
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,8 @@ public interface IMatch {
|
||||||
IResource getResource();
|
IResource getResource();
|
||||||
|
|
||||||
IPath getLocation();
|
IPath getLocation();
|
||||||
|
|
||||||
|
IPath getReferenceLocation();
|
||||||
|
|
||||||
int getStartOffset();
|
int getStartOffset();
|
||||||
|
|
||||||
|
|
|
@ -389,7 +389,7 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
|
||||||
|
|
||||||
Reader reader = null;
|
Reader reader = null;
|
||||||
|
|
||||||
IPath realPath = null;
|
realPath = null;
|
||||||
IProject project = null;
|
IProject project = null;
|
||||||
|
|
||||||
if( workspaceRoot != null ){
|
if( workspaceRoot != null ){
|
||||||
|
@ -525,11 +525,11 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
|
||||||
object = node;
|
object = node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( currentResource != null ){
|
if( currentResource != null ){
|
||||||
match = resultCollector.createMatch( currentResource, offset, end, object );
|
match = resultCollector.createMatch( currentResource, offset, end, object, null );
|
||||||
} else if( currentPath != null ){
|
} else if( currentPath != null ){
|
||||||
match = resultCollector.createMatch( currentPath, offset, end, object );
|
match = resultCollector.createMatch( currentPath, offset, end, object, realPath );
|
||||||
}
|
}
|
||||||
if( match != null ){
|
if( match != null ){
|
||||||
//Save till later
|
//Save till later
|
||||||
|
@ -584,6 +584,7 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
|
||||||
private IPath currentPath = null;
|
private IPath currentPath = null;
|
||||||
private ICSearchScope searchScope;
|
private ICSearchScope searchScope;
|
||||||
private IWorkspaceRoot workspaceRoot;
|
private IWorkspaceRoot workspaceRoot;
|
||||||
|
private IPath realPath;
|
||||||
|
|
||||||
private IResource currentResource = null;
|
private IResource currentResource = null;
|
||||||
private LinkedList resourceStack = new LinkedList();
|
private LinkedList resourceStack = new LinkedList();
|
||||||
|
|
|
@ -1,3 +1,13 @@
|
||||||
|
2004-03-24 Bogdan Gheorghe
|
||||||
|
|
||||||
|
Modified CSearchResultCollector to create markers on external matches.
|
||||||
|
Modified RenameRefactoringAction to get the openInclude working again (changes approved by Hoda).
|
||||||
|
Updated TypeSearchResultCollector to reflect changes made to BasicSearchResultCollector.
|
||||||
|
|
||||||
|
* src/org/eclipse/cdt/internal/ui/search/CSearchResultCollector.java
|
||||||
|
* refactor/org/eclipse/cdt/internal/ui/refactoring/actions/RenameRefactoringACtion.java
|
||||||
|
* browser/org/eclipse/cdt/ui/browser/typeinfo/AllTypesCache.java
|
||||||
|
|
||||||
2004-03-23 Alain Magloire
|
2004-03-23 Alain Magloire
|
||||||
|
|
||||||
Show the objects on the IOuputEntry path should
|
Show the objects on the IOuputEntry path should
|
||||||
|
|
|
@ -34,10 +34,12 @@ import org.eclipse.cdt.internal.ui.browser.util.ArrayUtil;
|
||||||
import org.eclipse.cdt.internal.ui.browser.util.ProgressMonitorMultiWrapper;
|
import org.eclipse.cdt.internal.ui.browser.util.ProgressMonitorMultiWrapper;
|
||||||
import org.eclipse.core.resources.IWorkspace;
|
import org.eclipse.core.resources.IWorkspace;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.jobs.IJobManager;
|
||||||
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
||||||
import org.eclipse.core.runtime.jobs.Job;
|
import org.eclipse.core.runtime.jobs.Job;
|
||||||
|
|
||||||
|
@ -98,10 +100,10 @@ public class AllTypesCache {
|
||||||
super(monitor);
|
super(monitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IMatch createMatch(Object fileResource, int start, int end, ISourceElementCallbackDelegate node )
|
public IMatch createMatch(Object fileResource, int start, int end, ISourceElementCallbackDelegate node, IPath realPath )
|
||||||
{
|
{
|
||||||
TypeInfo result= new TypeInfo();
|
TypeInfo result= new TypeInfo();
|
||||||
return super.createMatch( result, fileResource, start, end, node );
|
return super.createMatch( result, fileResource, start, end, node, realPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean acceptMatch(IMatch match) throws CoreException {
|
public boolean acceptMatch(IMatch match) throws CoreException {
|
||||||
|
|
|
@ -59,16 +59,22 @@ public class RenameRefactoringAction extends SelectionDispatchAction {
|
||||||
try {
|
try {
|
||||||
element = SelectionConverter.getElementAtOffset(fEditor);
|
element = SelectionConverter.getElementAtOffset(fEditor);
|
||||||
}catch (CModelException e) {
|
}catch (CModelException e) {
|
||||||
enable = false;
|
setEnabled(false);
|
||||||
}
|
}
|
||||||
if((element == null) || (element instanceof ITranslationUnit)){
|
if((element == null) || (element instanceof ITranslationUnit)){
|
||||||
|
setEnabled(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ITextSelection textSelection= (ITextSelection)fEditor.getSelectionProvider().getSelection();
|
||||||
|
|
||||||
|
if (textSelection == null) {
|
||||||
|
setEnabled(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( (((CElement)element).getIdStartPos() != textSelection.getOffset())
|
||||||
|
|| (((CElement)element).getIdLength() != textSelection.getLength())) {
|
||||||
enable = false;
|
enable = false;
|
||||||
} else {
|
|
||||||
ITextSelection textSelection= (ITextSelection)fEditor.getSelectionProvider().getSelection();
|
|
||||||
if( (((CElement)element).getIdStartPos() != textSelection.getOffset())
|
|
||||||
|| (((CElement)element).getIdLength() != textSelection.getLength())) {
|
|
||||||
enable = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
setEnabled(enable);
|
setEnabled(enable);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,13 +16,23 @@ package org.eclipse.cdt.internal.ui.search;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
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.IMatch;
|
import org.eclipse.cdt.core.search.IMatch;
|
||||||
import org.eclipse.cdt.ui.*;
|
import org.eclipse.cdt.ui.CSearchResultLabelProvider;
|
||||||
|
import org.eclipse.core.resources.IFile;
|
||||||
|
import org.eclipse.core.resources.IFolder;
|
||||||
import org.eclipse.core.resources.IMarker;
|
import org.eclipse.core.resources.IMarker;
|
||||||
|
import org.eclipse.core.resources.IPathVariableManager;
|
||||||
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.resources.IWorkspace;
|
||||||
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.search.ui.IGroupByKeyComputer;
|
import org.eclipse.search.ui.IGroupByKeyComputer;
|
||||||
import org.eclipse.search.ui.ISearchResultView;
|
import org.eclipse.search.ui.ISearchResultView;
|
||||||
import org.eclipse.search.ui.SearchUI;
|
import org.eclipse.search.ui.SearchUI;
|
||||||
|
@ -83,28 +93,60 @@ public class CSearchResultCollector extends BasicSearchResultCollector{
|
||||||
public boolean acceptMatch( IMatch match ) throws CoreException
|
public boolean acceptMatch( IMatch match ) throws CoreException
|
||||||
{
|
{
|
||||||
BasicSearchMatch searchMatch = (BasicSearchMatch) match;
|
BasicSearchMatch searchMatch = (BasicSearchMatch) match;
|
||||||
|
|
||||||
if( !super.acceptMatch( match ) )
|
if( !super.acceptMatch( match ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( searchMatch.resource == null )
|
if( searchMatch.resource == null &&
|
||||||
|
searchMatch.path == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
IMarker marker = searchMatch.resource.createMarker( SearchUI.SEARCH_MARKER );
|
if (searchMatch.resource != null){
|
||||||
|
IMarker marker = searchMatch.resource.createMarker( SearchUI.SEARCH_MARKER );
|
||||||
HashMap markerAttributes = new HashMap( 2 );
|
|
||||||
|
|
||||||
//we can hang any other info we want off the marker
|
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 ) ) );
|
//we can hang any other info we want off the marker
|
||||||
markerAttributes.put( IMATCH, searchMatch );
|
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 );
|
marker.setAttributes( markerAttributes );
|
||||||
|
|
||||||
if( _view != null ){
|
if( _view != null ){
|
||||||
_view.addMatch( searchMatch.name, _computer.computeGroupByKey( marker ), searchMatch.resource, marker );
|
_view.addMatch( searchMatch.name, _computer.computeGroupByKey( marker ), searchMatch.resource, marker );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//Create Link in referring file's project
|
||||||
|
IPath refLocation = searchMatch.getReferenceLocation();
|
||||||
|
IFile refFile = CCorePlugin.getWorkspace().getRoot().getFileForLocation(refLocation);
|
||||||
|
IProject refProject = refFile.getProject();
|
||||||
|
IPath externalMatchLocation = searchMatch.getLocation();
|
||||||
|
IFile linksFile = refProject.getFile(externalMatchLocation.lastSegment());
|
||||||
|
|
||||||
|
//Check to see if the file already exists - create if doesn't, mark team private
|
||||||
|
if (!linksFile.exists()){
|
||||||
|
linksFile.createLink(externalMatchLocation,IResource.NONE,null);
|
||||||
|
//linksFile.setTeamPrivateMember(true);
|
||||||
|
linksFile.setDerived(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
IMarker marker = linksFile.createMarker( SearchUI.SEARCH_MARKER );
|
||||||
|
|
||||||
|
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( IMATCH, searchMatch );
|
||||||
|
|
||||||
|
marker.setAttributes( markerAttributes );
|
||||||
|
|
||||||
|
if( _view != null ){
|
||||||
|
_view.addMatch( searchMatch.name, _computer.computeGroupByKey( marker ), linksFile, marker );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
_matchCount++;
|
_matchCount++;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Add table
Reference in a new issue