1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Patch for Andrew Niefer

core : 
- add function parameter information to search results

ui:
- modified Search result sorting to sort by offset if the label is the 
same for two items
This commit is contained in:
John Camelon 2003-08-11 13:48:39 +00:00
parent e1a20e1a7d
commit 78d86df8e3
7 changed files with 150 additions and 31 deletions

View file

@ -5,6 +5,9 @@
- adding a project to scope, include referenced projects
- adding individual CElements to scope
2003-08-08 Andrew Niefer
- add function parameter information to search results
2003-08-06 Andrew Niefer
- Create OrPattern which matches for search if any of its constituent patterns matches
- modified MatchLocator to support the OrPattern

View file

@ -14,13 +14,16 @@
package org.eclipse.cdt.core.search;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
import org.eclipse.cdt.core.parser.ast.ASTPointerOperator;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
import org.eclipse.cdt.core.parser.ast.IASTField;
@ -29,9 +32,12 @@ import org.eclipse.cdt.core.parser.ast.IASTMethod;
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
import org.eclipse.cdt.core.parser.ast.IASTOffsetableElement;
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement;
import org.eclipse.cdt.core.parser.ast.IASTReference;
import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
@ -93,12 +99,80 @@ public class BasicSearchResultCollector implements ICSearchResultCollector {
result.name = offsetable.getName();
}
if( offsetable instanceof IASTFunction ){
result.name += getParameterString( (IASTFunction) offsetable );
}
setElementInfo( result, offsetable );
return result;
}
/**
* @param function
* @return
*/
private String getParameterString(IASTFunction function) {
if( function == null )
return "";
String paramString = "(";
Iterator iter = function.getParameters();
boolean first = true;
while( iter.hasNext() ){
IASTParameterDeclaration param = (IASTParameterDeclaration) iter.next();
if( !first ) paramString += ", ";
IASTTypeSpecifier typeSpec = param.getTypeSpecifier();
if( param.isConst() )
paramString += "const ";
if( typeSpec instanceof IASTSimpleTypeSpecifier ){
paramString += ((IASTSimpleTypeSpecifier)typeSpec).getTypename();
} else if( typeSpec instanceof IASTOffsetableNamedElement ){
paramString += ((IASTOffsetableNamedElement)typeSpec).getName();
} else if( typeSpec instanceof IASTElaboratedTypeSpecifier ){
ASTClassKind kind = ((IASTElaboratedTypeSpecifier)typeSpec).getClassKind();
if( kind == ASTClassKind.CLASS ){
paramString += "class ";
} else if( kind == ASTClassKind.STRUCT ){
paramString += "struct ";
} else if( kind == ASTClassKind.ENUM ){
paramString += "enum ";
} else if( kind == ASTClassKind.UNION ){
paramString += "union ";
}
paramString += ((IASTElaboratedTypeSpecifier)typeSpec).getName();
}
Iterator ptrs = param.getPointerOperators();
if( ptrs.hasNext() ) paramString += " ";
while( ptrs.hasNext() ){
ASTPointerOperator ptr = (ASTPointerOperator)ptrs.next();
if( ptr == ASTPointerOperator.POINTER )
paramString += "*";
else if( ptr == ASTPointerOperator.REFERENCE )
paramString += "&";
else if( ptr == ASTPointerOperator.CONST_POINTER )
paramString += " const * ";
else if( ptr == ASTPointerOperator.VOLATILE_POINTER )
paramString += " volatile * ";
ptr = ASTPointerOperator.POINTER;
}
first = false;
}
paramString += ")";
return paramString;
}
public boolean acceptMatch(IMatch match) throws CoreException {
if( !results.contains( match ) ){
results.add( match );

View file

@ -2,6 +2,9 @@
- Filled out CSearchScopeFactory to translate working sets
into CElements
2003-08-08 Andrew Niefer
- modified Search result sorting to sort by offset if the label is the same for two items
2003-08-01 Andrew Niefer
- Modified CSearchResultCollector to reflect changes in BasicSearchResultCollector,
acceptMatch will return false if the match was not accepted because it has already

View file

@ -137,7 +137,8 @@ CSearchOperation.pluralReferencesPostfix={0} - {1} References in {2}
CSearchOperation.pluralReadReferencesPostfix={0} - {1} Read References in {2}
CSearchOperation.pluralWriteReferencesPostfix={0} - {1} Write References in {2}
CSearchOperation.pluralImplementorsPostfix={0} - {1} Implementors in {2}
CSearchOperation.pluralOccurrencesPostfix={0} - {1} Occurrences in {2}
CSearchOperation.pluralOccurencesPostfix={0} - {1} Occurrences in {2}
# The first argument will be replaced by the element name and the second one by the file name
JavaSearchInFile.singularPostfix={0} - 1 Occurrence in {1}

View file

@ -13,7 +13,8 @@
*/
package org.eclipse.cdt.internal.ui.search;
import org.eclipse.cdt.ui.*;
import org.eclipse.cdt.ui.CSearchResultLabelProvider;
import org.eclipse.core.resources.IMarker;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;
@ -32,11 +33,18 @@ public class ElementNameSorter extends ViewerSorter {
public int compare( Viewer viewer, Object e1, Object e2 ){
String name1 = null, name2 = null;
if (e1 instanceof ISearchResultViewEntry)
name1= _labelProvider.getText( e1 );
ISearchResultViewEntry entry1 = null;
ISearchResultViewEntry entry2 = null;
if (e1 instanceof ISearchResultViewEntry){
name1 = _labelProvider.getText(e1);
entry1 = (ISearchResultViewEntry)e1;
}
if (e2 instanceof ISearchResultViewEntry)
name2= _labelProvider.getText( e2 );
if (e2 instanceof ISearchResultViewEntry){
name2 = _labelProvider.getText(e2);
entry2 = (ISearchResultViewEntry)e2;
}
if (name1 == null)
name1= ""; //$NON-NLS-1$
@ -44,7 +52,23 @@ public class ElementNameSorter extends ViewerSorter {
if (name2 == null)
name2= ""; //$NON-NLS-1$
return getCollator().compare(name1, name2);
int compare = getCollator().compare( name1, name2 );
if( compare == 0 ){
int startPos1 = -1;
int startPos2 = -1;
IMarker marker1 = entry1.getSelectedMarker();
IMarker marker2 = entry2.getSelectedMarker();
if (marker1 != null)
startPos1 = marker1.getAttribute( IMarker.CHAR_START, -1 );
if (marker2 != null)
startPos2 = marker2.getAttribute( IMarker.CHAR_START, -1 );
compare = startPos1 - startPos2;
}
return compare;
}
public boolean isSorterProperty( Object element, String property ){

View file

@ -13,7 +13,8 @@
*/
package org.eclipse.cdt.internal.ui.search;
import org.eclipse.cdt.ui.*;
import org.eclipse.cdt.ui.CSearchResultLabelProvider;
import org.eclipse.core.resources.IMarker;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;
@ -33,11 +34,18 @@ public class ParentNameSorter extends ViewerSorter {
String name1= null;
String name2= null;
if (e1 instanceof ISearchResultViewEntry)
name1= _labelProvider.getText(e1);
ISearchResultViewEntry entry1 = null;
ISearchResultViewEntry entry2 = null;
if (e1 instanceof ISearchResultViewEntry){
name1 = _labelProvider.getText(e1);
entry1 = (ISearchResultViewEntry)e1;
}
if (e2 instanceof ISearchResultViewEntry)
name2= _labelProvider.getText(e2);
if (e2 instanceof ISearchResultViewEntry){
name2 = _labelProvider.getText(e2);
entry2 = (ISearchResultViewEntry)e2;
}
if (name1 == null)
name1= ""; //$NON-NLS-1$
@ -45,7 +53,23 @@ public class ParentNameSorter extends ViewerSorter {
if (name2 == null)
name2= ""; //$NON-NLS-1$
return getCollator().compare(name1, name2);
int compare = getCollator().compare( name1, name2 );
if( compare == 0 ){
int startPos1 = -1;
int startPos2 = -1;
IMarker marker1 = entry1.getSelectedMarker();
IMarker marker2 = entry2.getSelectedMarker();
if (marker1 != null)
startPos1 = marker1.getAttribute( IMarker.CHAR_START, -1 );
if (marker2 != null)
startPos2 = marker2.getAttribute( IMarker.CHAR_START, -1 );
compare = startPos1 - startPos2;
}
return compare;
}
/*

View file

@ -13,10 +13,8 @@
*/
package org.eclipse.cdt.internal.ui.search;
import org.eclipse.cdt.ui.*;
import org.eclipse.cdt.ui.CSearchResultLabelProvider;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;
@ -55,18 +53,10 @@ public class PathNameSorter extends ViewerSorter {
if( name2 == null )
name2 = ""; //$NON-NLS-1$
IResource resource = null;
if( entry1 != null)
resource = entry1.getResource();
if( resource != null && entry2 != null && resource == entry2.getResource() ) {
if( resource instanceof IProject || resource.getFileExtension().equalsIgnoreCase("jar") || resource.getFileExtension().equalsIgnoreCase("zip") ) //$NON-NLS-2$ //$NON-NLS-1$
// binary archives
return getCollator().compare(name1, name2);
// Sort by marker start position if resource is equal.
int compare = getCollator().compare( name1, name2 );
if( compare == 0 ){
int startPos1 = -1;
int startPos2 = -1;
IMarker marker1 = entry1.getSelectedMarker();
@ -76,11 +66,11 @@ public class PathNameSorter extends ViewerSorter {
startPos1 = marker1.getAttribute( IMarker.CHAR_START, -1 );
if (marker2 != null)
startPos2 = marker2.getAttribute( IMarker.CHAR_START, -1 );
return startPos1 - startPos2;
compare = startPos1 - startPos2;
}
return getCollator().compare(name1, name2);
return compare;
}
/*