1
0
Fork 0
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:
Bogdan Gheorghe 2004-03-24 15:29:07 +00:00
parent d46e5977ea
commit 5ab48f40ff
10 changed files with 118 additions and 43 deletions

View file

@ -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
BasicSearchResultCollector patch from Chris Wiebe - adds setProgressMonitor method,
cleans up some of the CoreException warnings

View file

@ -35,6 +35,7 @@ public class BasicSearchMatch implements IMatch, Comparable {
path = basicMatch.path;
startOffset = basicMatch.startOffset;
endOffset = basicMatch.endOffset;
referringElement = basicMatch.referringElement;
}
public int hashCode(){
@ -134,6 +135,8 @@ public class BasicSearchMatch implements IMatch, Comparable {
boolean isVolatile = false;
boolean isStatic = false;
public IPath referringElement = null;
public int getElementType() {
return type;
}
@ -166,6 +169,10 @@ public class BasicSearchMatch implements IMatch, Comparable {
else return null;
}
public IPath getReferenceLocation() {
return referringElement;
}
public int getStartOffset() {
return startOffset;
}

View file

@ -77,13 +77,13 @@ public class BasicSearchResultCollector implements ICSearchResultCollector {
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();
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 )
result.resource = (IResource) fileResource;
else if( fileResource instanceof IPath )
@ -92,6 +92,7 @@ public class BasicSearchResultCollector implements ICSearchResultCollector {
result.startOffset = start;
result.endOffset = end;
result.parentName = ""; //$NON-NLS-1$
result.referringElement = referringElement;
IASTOffsetableNamedElement offsetable = null;

View file

@ -15,6 +15,7 @@ package org.eclipse.cdt.core.search;
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
/**
@ -47,7 +48,7 @@ public interface ICSearchResultCollector {
public void done();
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
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
*/
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 );
}

View file

@ -36,6 +36,8 @@ public interface IMatch {
IPath getLocation();
IPath getReferenceLocation();
int getStartOffset();
int getEndOffset();

View file

@ -389,7 +389,7 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
Reader reader = null;
IPath realPath = null;
realPath = null;
IProject project = null;
if( workspaceRoot != null ){
@ -527,9 +527,9 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
}
if( currentResource != null ){
match = resultCollector.createMatch( currentResource, offset, end, object );
match = resultCollector.createMatch( currentResource, offset, end, object, null );
} else if( currentPath != null ){
match = resultCollector.createMatch( currentPath, offset, end, object );
match = resultCollector.createMatch( currentPath, offset, end, object, realPath );
}
if( match != null ){
//Save till later
@ -584,6 +584,7 @@ public class MatchLocator implements ISourceElementRequestor, ICSearchConstants
private IPath currentPath = null;
private ICSearchScope searchScope;
private IWorkspaceRoot workspaceRoot;
private IPath realPath;
private IResource currentResource = null;
private LinkedList resourceStack = new LinkedList();

View file

@ -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
Show the objects on the IOuputEntry path should

View file

@ -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.core.resources.IWorkspace;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
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.Job;
@ -98,10 +100,10 @@ public class AllTypesCache {
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();
return super.createMatch( result, fileResource, start, end, node );
return super.createMatch( result, fileResource, start, end, node, realPath);
}
public boolean acceptMatch(IMatch match) throws CoreException {

View file

@ -59,17 +59,23 @@ public class RenameRefactoringAction extends SelectionDispatchAction {
try {
element = SelectionConverter.getElementAtOffset(fEditor);
}catch (CModelException e) {
enable = false;
setEnabled(false);
}
if((element == null) || (element instanceof ITranslationUnit)){
enable = false;
} else {
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;
}
}
setEnabled(enable);
}

View file

@ -16,13 +16,23 @@ package org.eclipse.cdt.internal.ui.search;
import java.text.MessageFormat;
import java.util.HashMap;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.search.BasicSearchMatch;
import org.eclipse.cdt.core.search.BasicSearchResultCollector;
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.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.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.search.ui.IGroupByKeyComputer;
import org.eclipse.search.ui.ISearchResultView;
import org.eclipse.search.ui.SearchUI;
@ -87,9 +97,11 @@ public class CSearchResultCollector extends BasicSearchResultCollector{
if( !super.acceptMatch( match ) )
return false;
if( searchMatch.resource == null )
if( searchMatch.resource == null &&
searchMatch.path == null)
return false;
if (searchMatch.resource != null){
IMarker marker = searchMatch.resource.createMarker( SearchUI.SEARCH_MARKER );
HashMap markerAttributes = new HashMap( 2 );
@ -104,7 +116,37 @@ public class CSearchResultCollector extends BasicSearchResultCollector{
if( _view != null ){
_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++;
return true;