mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Patch for Andrew Niefer.
cdt.core: - Modified ICSearchConstants to use classes (SearchFor & LimitTo) instead of int for constants - Modified MatchLocator to actually invoke the parser to do the search cdt.core.tests: - Added new source Folder search - Added search/ClassDeclarationPatternTests::testMatchSimpleDeclaration - Added search/ClassDeclarationPatternTests::testMatchNamespaceNestedDeclaration - Added new resource folder search & containing file classDecl.cpp - Added new failures package ord.eclipse.cdt.core.search.failedTests - Added new failing test PatternsFailedTests::testBug39652 * Note that both the ClassDeclarationPatternTests and PatternsFailedTests must be run as Plugin Tests * cdt.ui: - Updated Search classes to reflect changes to ICSearchConstants.
This commit is contained in:
parent
4961729ef8
commit
8a70b5e1d2
17 changed files with 1204 additions and 781 deletions
|
@ -21,5 +21,6 @@
|
|||
<classpathentry kind="src" path="/org.junit"/>
|
||||
<classpathentry kind="src" path="/org.eclipse.core.boot"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="src" path="search"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
|
@ -1,3 +1,13 @@
|
|||
2003-07-04 Andrew Niefer
|
||||
Added new source Folder search
|
||||
Added search/ClassDeclarationPatternTests::testMatchSimpleDeclaration
|
||||
Added search/ClassDeclarationPatternTests::testMatchNamespaceNestedDeclaration
|
||||
Added new resource folder search & containing file classDecl.cpp
|
||||
Added new failures package ord.eclipse.cdt.core.search.failedTests
|
||||
Added new failing test PatternsFailedTests::testBug39652
|
||||
|
||||
* Note that ClassDeclarationPatternTests and PatternsFailedTests both must be run as plugin tests
|
||||
|
||||
2003-07-03 Bogdan Gheorghe
|
||||
Added IndexManagerTest::testAddNewFileToIndex()
|
||||
Added IndexManagerTest::testRemoveProjectFromIndex()
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corp. - Rational Software - initial implementation
|
||||
******************************************************************************/
|
||||
/*
|
||||
* Created on Jul 4, 2003
|
||||
*/
|
||||
package org.eclipse.cdt.core.search.failedTests;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.search.ICSearchConstants;
|
||||
import org.eclipse.cdt.internal.core.search.matching.CSearchPattern;
|
||||
import org.eclipse.cdt.internal.core.search.matching.MatchLocator;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchResultCollector;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*
|
||||
* To change the template for this generated type comment go to
|
||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||
*/
|
||||
public class PatternsFailedTests extends TestCase implements ICSearchConstants {
|
||||
|
||||
private MatchLocator matchLocator;
|
||||
private CSearchResultCollector resultCollector;
|
||||
private String cppPath;
|
||||
|
||||
public PatternsFailedTests(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
private void initialize( CSearchPattern pattern ){
|
||||
cppPath = org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.core.tests").find(new Path("/")).getFile();
|
||||
cppPath += "resources/search/classDecl.cpp";
|
||||
|
||||
resultCollector = new CSearchResultCollector();
|
||||
matchLocator = new MatchLocator( pattern, resultCollector, null, null );
|
||||
}
|
||||
|
||||
public void testBug39652() {
|
||||
CSearchPattern pattern = CSearchPattern.createPattern( "A::B", TYPE, DECLARATIONS, EXACT_MATCH, true );
|
||||
|
||||
initialize( pattern );
|
||||
matchLocator.locateMatches( new String[] { cppPath }, null, null );
|
||||
Set matches = resultCollector.getMatches();
|
||||
/* Test should find 1 match */
|
||||
//assertTrue( matches != null );
|
||||
//assertTrue( matches.size() == 1 );
|
||||
|
||||
/* instead it finds none because qualifications are wrong*/
|
||||
assertTrue( matches == null );
|
||||
|
||||
pattern = CSearchPattern.createPattern( "NS::NS2::a", TYPE, DECLARATIONS, EXACT_MATCH, true );
|
||||
initialize( pattern );
|
||||
matchLocator.locateMatches( new String[] { cppPath }, null, null );
|
||||
matches = resultCollector.getMatches();
|
||||
assertTrue( matches == null );
|
||||
|
||||
pattern = CSearchPattern.createPattern( "NS::B::A", TYPE, DECLARATIONS, EXACT_MATCH, true );
|
||||
initialize( pattern );
|
||||
matchLocator.locateMatches( new String[] { cppPath }, null, null );
|
||||
matches = resultCollector.getMatches();
|
||||
assertTrue( matches == null );
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
class A {
|
||||
class B {
|
||||
};
|
||||
};
|
||||
|
||||
namespace NS {
|
||||
namespace NS2{
|
||||
struct a{};
|
||||
}
|
||||
class B {
|
||||
struct A {};
|
||||
};
|
||||
}
|
|
@ -0,0 +1,119 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v0.5
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v05.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corp. - Rational Software - initial implementation
|
||||
******************************************************************************/
|
||||
/*
|
||||
* Created on Jul 3, 2003
|
||||
*/
|
||||
package org.eclipse.cdt.core.search.tests;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.search.ICSearchConstants;
|
||||
import org.eclipse.cdt.internal.core.search.CharOperation;
|
||||
import org.eclipse.cdt.internal.core.search.matching.CSearchPattern;
|
||||
import org.eclipse.cdt.internal.core.search.matching.ClassDeclarationPattern;
|
||||
import org.eclipse.cdt.internal.core.search.matching.MatchLocator;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchResultCollector;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @author aniefer
|
||||
*
|
||||
* To change the template for this generated type comment go to
|
||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||
*/
|
||||
public class ClassDeclarationPatternTests extends TestCase implements ICSearchConstants {
|
||||
|
||||
private MatchLocator matchLocator;
|
||||
private CSearchResultCollector resultCollector;
|
||||
private String cppPath;
|
||||
|
||||
public ClassDeclarationPatternTests(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
private void initialize( CSearchPattern pattern ){
|
||||
cppPath = org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.core.tests").find(new Path("/")).getFile();
|
||||
cppPath += "resources/search/classDecl.cpp";
|
||||
|
||||
resultCollector = new CSearchResultCollector();
|
||||
matchLocator = new MatchLocator( pattern, resultCollector, null, null );
|
||||
}
|
||||
|
||||
public void testMatchSimpleDeclaration(){
|
||||
CSearchPattern pattern = CSearchPattern.createPattern( "A", TYPE, DECLARATIONS, EXACT_MATCH, true );
|
||||
|
||||
assertTrue( pattern instanceof ClassDeclarationPattern );
|
||||
|
||||
initialize( pattern );
|
||||
|
||||
matchLocator.locateMatches( new String [] { cppPath }, null, null );
|
||||
|
||||
Set matches = resultCollector.getMatches();
|
||||
assertEquals( matches.size(), 2 );
|
||||
}
|
||||
|
||||
public void testMatchNamespaceNestedDeclaration(){
|
||||
CSearchPattern pattern = CSearchPattern.createPattern( "NS::B", TYPE, DECLARATIONS, EXACT_MATCH, true );
|
||||
|
||||
assertTrue( pattern instanceof ClassDeclarationPattern );
|
||||
|
||||
ClassDeclarationPattern clsPattern = (ClassDeclarationPattern)pattern;
|
||||
|
||||
assertTrue( CharOperation.equals( new char[] { 'B' }, clsPattern.getName() ) );
|
||||
assertTrue( clsPattern.getContainingTypes().length == 1 );
|
||||
assertTrue( CharOperation.equals( new char[] { 'N', 'S' }, clsPattern.getContainingTypes()[0] ) );
|
||||
|
||||
initialize( pattern );
|
||||
|
||||
matchLocator.locateMatches( new String [] { cppPath }, null, null );
|
||||
|
||||
Set matches = resultCollector.getMatches();
|
||||
assertEquals( matches.size(), 1 );
|
||||
}
|
||||
|
||||
public void failingtestMatchStruct(){
|
||||
CSearchPattern pattern = CSearchPattern.createPattern( "A", STRUCT, DECLARATIONS, EXACT_MATCH, true );
|
||||
|
||||
assertTrue( pattern instanceof ClassDeclarationPattern );
|
||||
|
||||
ClassDeclarationPattern clsPattern = (ClassDeclarationPattern) pattern;
|
||||
|
||||
initialize( pattern );
|
||||
|
||||
matchLocator.locateMatches( new String[] { cppPath }, null, null );
|
||||
|
||||
Set matches = resultCollector.getMatches();
|
||||
assertEquals( matches.size(), 1 );
|
||||
|
||||
pattern = CSearchPattern.createPattern( "NS::B::A", TYPE, DECLARATIONS, EXACT_MATCH, true );
|
||||
|
||||
initialize( pattern );
|
||||
matchLocator.locateMatches( new String[] { cppPath }, null, null );
|
||||
|
||||
Set matches2 = resultCollector.getMatches();
|
||||
assertTrue( matches2 != null );
|
||||
assertEquals( matches2.size(), 1 );
|
||||
|
||||
Iterator iter = matches.iterator();
|
||||
Iterator iter2 = matches2.iterator();
|
||||
|
||||
CSearchResultCollector.Match match = (CSearchResultCollector.Match)iter.next();
|
||||
CSearchResultCollector.Match match2 = (CSearchResultCollector.Match)iter2.next();
|
||||
|
||||
assertTrue( match.path.equals( match2.path ) );
|
||||
assertEquals( match.start, match2.start );
|
||||
assertEquals( match.end, match2.end );
|
||||
}
|
||||
|
||||
}
|
|
@ -6,27 +6,30 @@
|
|||
*/
|
||||
package org.eclipse.cdt.core.suite;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import junit.framework.TestResult;
|
||||
import junit.framework.TestListener;
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.textui.TestRunner;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.core.boot.IPlatformRunnable;
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestListener;
|
||||
import junit.framework.TestResult;
|
||||
import junit.framework.TestSuite;
|
||||
import junit.textui.TestRunner;
|
||||
|
||||
import org.eclipse.cdt.core.build.managed.tests.AllBuildTests;
|
||||
import org.eclipse.cdt.core.model.failedTests.CModelElementsFailedTests;
|
||||
import org.eclipse.cdt.core.model.tests.AllCoreTests;
|
||||
import org.eclipse.cdt.core.model.tests.BinaryTests;
|
||||
import org.eclipse.cdt.core.model.tests.ElementDeltaTests;
|
||||
import org.eclipse.cdt.core.model.tests.WorkingCopyTests;
|
||||
import org.eclipse.cdt.core.parser.failedTests.*;
|
||||
import org.eclipse.cdt.core.parser.failedTests.DOMFailedTest;
|
||||
import org.eclipse.cdt.core.parser.failedTests.LokiFailures;
|
||||
import org.eclipse.cdt.core.parser.failedTests.STLFailedTests;
|
||||
import org.eclipse.cdt.core.parser.tests.ParserTestSuite;
|
||||
import org.eclipse.cdt.core.model.failedTests.*;
|
||||
import org.eclipse.cdt.core.search.failedTests.PatternsFailedTests;
|
||||
import org.eclipse.cdt.core.search.tests.ClassDeclarationPatternTests;
|
||||
import org.eclipse.core.boot.IPlatformRunnable;
|
||||
|
||||
/**
|
||||
* @author vhirsl
|
||||
|
@ -77,6 +80,7 @@ public class AutomatedIntegrationSuite extends TestSuite
|
|||
suite.addTest(BinaryTests.suite());
|
||||
suite.addTest(ElementDeltaTests.suite());
|
||||
suite.addTest(WorkingCopyTests.suite());
|
||||
suite.addTestSuite(ClassDeclarationPatternTests.class );
|
||||
|
||||
// Last test to trigger report generation
|
||||
suite.addTest(suite.new GenerateReport("startFailedTests"));
|
||||
|
@ -86,6 +90,7 @@ public class AutomatedIntegrationSuite extends TestSuite
|
|||
suite.addTestSuite(LokiFailures.class);
|
||||
suite.addTestSuite(STLFailedTests.class);
|
||||
suite.addTestSuite(CModelElementsFailedTests.class);
|
||||
suite.addTestSuite(PatternsFailedTests.class);
|
||||
|
||||
// Last test to trigger report generation
|
||||
suite.addTest(suite.new GenerateReport("generateReport"));
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
2003-07-04 Andrew Niefer
|
||||
* Modified ICSearchConstants to use new nested classes SearchFor and LimitTo instead of int
|
||||
for stronger type safety
|
||||
* Updated MatchLocator to invoke parser to do actual search.
|
||||
|
||||
2003-06-27 Andrew Niefer
|
||||
Modified:
|
||||
search/org.eclipse.cdt.core.search.matching/MatchLocator.java
|
||||
|
|
|
@ -33,64 +33,65 @@ public interface ICSearchConstants {
|
|||
* The nature of searched element or the nature
|
||||
* of match in unknown.
|
||||
*/
|
||||
int UNKNOWN = -1;
|
||||
public static final SearchFor UNKNOWN_SEARCH_FOR = new SearchFor( -1 );
|
||||
public static final LimitTo UNKNOWN_LIMIT_TO = new LimitTo( -1 );
|
||||
|
||||
/* Nature of searched element */
|
||||
|
||||
/**
|
||||
* The searched element is a type.
|
||||
*/
|
||||
int TYPE= 0;
|
||||
public static final SearchFor TYPE = new SearchFor( 0 );
|
||||
|
||||
/**
|
||||
* The searched element is a function.
|
||||
*/
|
||||
int FUNCTION= 1;
|
||||
public static final SearchFor FUNCTION = new SearchFor( 1 );
|
||||
|
||||
/**
|
||||
* The searched element is a namespace.
|
||||
*/
|
||||
int NAMESPACE= 2;
|
||||
public static final SearchFor NAMESPACE = new SearchFor( 2 );
|
||||
|
||||
/**
|
||||
* The searched element is a constructor.
|
||||
*/
|
||||
int CONSTRUCTOR= 3;
|
||||
public static final SearchFor CONSTRUCTOR = new SearchFor( 3 );
|
||||
|
||||
/**
|
||||
* The searched element is a member.
|
||||
*/
|
||||
int MEMBER= 4;
|
||||
public static final SearchFor MEMBER = new SearchFor( 4 );
|
||||
|
||||
/**
|
||||
* The searched element is a variable.
|
||||
* More selective than using TYPE
|
||||
*/
|
||||
int VAR= 5;
|
||||
public static final SearchFor VAR = new SearchFor( 5 );
|
||||
|
||||
/**
|
||||
* The searched element is a class.
|
||||
* More selective than using TYPE
|
||||
*/
|
||||
int CLASS= 6;
|
||||
public static final SearchFor CLASS = new SearchFor( 6 );
|
||||
|
||||
/**
|
||||
* The searched element is a struct.
|
||||
* More selective than using TYPE
|
||||
*/
|
||||
int STRUCT= 7;
|
||||
public static final SearchFor STRUCT = new SearchFor( 7 );
|
||||
|
||||
/**
|
||||
* The searched element is a enum.
|
||||
* More selective than using TYPE
|
||||
*/
|
||||
int ENUM= 8;
|
||||
public static final SearchFor ENUM = new SearchFor( 8 );
|
||||
|
||||
/**
|
||||
* The searched element is a union.
|
||||
* More selective than using TYPE
|
||||
*/
|
||||
int UNION= 9;
|
||||
public static final SearchFor UNION = new SearchFor( 9 );
|
||||
|
||||
|
||||
/* Nature of match */
|
||||
|
@ -100,7 +101,7 @@ public interface ICSearchConstants {
|
|||
* Can be used in conjunction with any of the nature of searched elements
|
||||
* so as to better narrow down the search.
|
||||
*/
|
||||
int DECLARATIONS= 0;
|
||||
public static final LimitTo DECLARATIONS = new LimitTo( 0 );
|
||||
|
||||
/**
|
||||
* The search result is a type that implements an interface.
|
||||
|
@ -109,7 +110,7 @@ public interface ICSearchConstants {
|
|||
* rather exclusively search for classes implementing an interface, or interfaces
|
||||
* extending an interface.
|
||||
*/
|
||||
int DEFINITIONS= 1;
|
||||
public static final LimitTo DEFINITIONS = new LimitTo( 1 );
|
||||
|
||||
/**
|
||||
* The search result is a reference.
|
||||
|
@ -118,7 +119,7 @@ public interface ICSearchConstants {
|
|||
* References can contain implementers since they are more generic kind
|
||||
* of matches.
|
||||
*/
|
||||
int REFERENCES= 2;
|
||||
public static final LimitTo REFERENCES = new LimitTo( 2 );
|
||||
|
||||
/**
|
||||
* The search result is a declaration, a reference, or an implementer
|
||||
|
@ -126,7 +127,7 @@ public interface ICSearchConstants {
|
|||
* Can be used in conjunction with any of the nature of searched elements
|
||||
* so as to better narrow down the search.
|
||||
*/
|
||||
int ALL_OCCURRENCES= 3;
|
||||
public static final LimitTo ALL_OCCURRENCES = new LimitTo( 3 );
|
||||
|
||||
|
||||
/* Syntactic match modes */
|
||||
|
@ -180,4 +181,19 @@ public interface ICSearchConstants {
|
|||
int WAIT_UNTIL_READY_TO_SEARCH = IJob.WaitUntilReady;
|
||||
|
||||
|
||||
public class SearchFor{
|
||||
private SearchFor( int value )
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
private final int value;
|
||||
}
|
||||
|
||||
public class LimitTo {
|
||||
private LimitTo( int value )
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
private final int value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ package org.eclipse.cdt.core.search;
|
|||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
/**
|
||||
|
@ -74,5 +75,17 @@ public interface ICSearchResultCollector {
|
|||
* @return a progress monitor or null if no progress monitor is provided
|
||||
*/
|
||||
public IProgressMonitor getProgressMonitor();
|
||||
/**
|
||||
* @param currentPath
|
||||
* @param start
|
||||
* @param end
|
||||
* @param object
|
||||
* @param accuracyLevel
|
||||
*/
|
||||
public void accept(IPath currentPath,
|
||||
int start,
|
||||
int end,
|
||||
ICElement enclosingElement,
|
||||
int accuracyLevel) throws CoreException;
|
||||
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.eclipse.core.runtime.SubProgressMonitor;
|
|||
* To change the template for this generated type comment go to
|
||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||
*/
|
||||
public class SearchEngine {
|
||||
public class SearchEngine implements ICSearchConstants{
|
||||
|
||||
private boolean VERBOSE = false;
|
||||
|
||||
|
@ -60,7 +60,7 @@ public class SearchEngine {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static ICSearchPattern createSearchPattern( String stringPattern, int searchFor, int limitTo, boolean isCaseSensitive){
|
||||
public static ICSearchPattern createSearchPattern( String stringPattern, SearchFor searchFor, LimitTo limitTo, boolean isCaseSensitive){
|
||||
int mode;
|
||||
|
||||
if( stringPattern.indexOf( '*' ) != -1 || stringPattern.indexOf( '?' ) != -1 ){
|
||||
|
@ -127,7 +127,7 @@ public class SearchEngine {
|
|||
* @param _scope
|
||||
* @param _collector
|
||||
*/
|
||||
public void search(IWorkspace workspace, ICElement elementPattern, int limitTo, ICSearchScope scope, ICSearchResultCollector collector) {
|
||||
public void search(IWorkspace workspace, ICElement elementPattern, LimitTo limitTo, ICSearchScope scope, ICSearchResultCollector collector) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.eclipse.cdt.core.parser.IToken;
|
|||
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ScannerException;
|
||||
import org.eclipse.cdt.core.parser.ast.ClassKind;
|
||||
import org.eclipse.cdt.core.search.ICSearchConstants;
|
||||
import org.eclipse.cdt.core.search.ICSearchPattern;
|
||||
import org.eclipse.cdt.internal.core.search.CharOperation;
|
||||
|
@ -56,26 +57,23 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
|
|||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public static CSearchPattern createPattern( String patternString, int searchFor, int limitTo, int matchMode, boolean caseSensitive ){
|
||||
public static CSearchPattern createPattern( String patternString, SearchFor searchFor, LimitTo limitTo, int matchMode, boolean caseSensitive ){
|
||||
if( patternString == null || patternString.length() == 0 ){
|
||||
return null;
|
||||
}
|
||||
|
||||
CSearchPattern pattern = null;
|
||||
switch( searchFor ){
|
||||
case ICSearchConstants.TYPE:
|
||||
pattern = createClassPattern( patternString, limitTo, matchMode, caseSensitive );
|
||||
break;
|
||||
//case ICSearchConstants.METHOD:
|
||||
if( searchFor == TYPE || searchFor == CLASS || searchFor == STRUCT || searchFor == ENUM || searchFor == UNION ){
|
||||
pattern = createClassPattern( patternString, searchFor, limitTo, matchMode, caseSensitive );
|
||||
} else if ( searchFor == MEMBER ){
|
||||
// pattern = createMethodPattern( patternString, limitTo, matchMode, caseSensitive );
|
||||
// break;
|
||||
case ICSearchConstants.CONSTRUCTOR:
|
||||
pattern = createConstructorPattern( patternString, limitTo, matchMode, caseSensitive );
|
||||
break;
|
||||
} else if ( searchFor == CONSTRUCTOR ){
|
||||
pattern = createConstructorPattern( patternString, limitTo, matchMode, caseSensitive );
|
||||
}
|
||||
//case ICSearchConstants.FIELD:
|
||||
// pattern = createFieldPattern( patternString, limitTo, matchMode, caseSensitive );
|
||||
// break;
|
||||
}
|
||||
|
||||
|
||||
return pattern;
|
||||
}
|
||||
|
@ -87,7 +85,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
|
|||
* @param caseSensitive
|
||||
* @return
|
||||
*/
|
||||
private static CSearchPattern createFieldPattern(String patternString, int limitTo, int matchMode, boolean caseSensitive) {
|
||||
private static CSearchPattern createFieldPattern(String patternString, LimitTo limitTo, int matchMode, boolean caseSensitive) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
@ -99,7 +97,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
|
|||
* @param caseSensitive
|
||||
* @return
|
||||
*/
|
||||
private static CSearchPattern createMethodPattern(String patternString, int limitTo, int matchMode, boolean caseSensitive) {
|
||||
private static CSearchPattern createMethodPattern(String patternString, LimitTo limitTo, int matchMode, boolean caseSensitive) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
@ -111,7 +109,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
|
|||
* @param caseSensitive
|
||||
* @return
|
||||
*/
|
||||
private static CSearchPattern createConstructorPattern(String patternString, int limitTo, int matchMode, boolean caseSensitive) {
|
||||
private static CSearchPattern createConstructorPattern(String patternString, LimitTo limitTo, int matchMode, boolean caseSensitive) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
@ -123,7 +121,7 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
|
|||
* @param caseSensitive
|
||||
* @return
|
||||
*/
|
||||
private static CSearchPattern createClassPattern(String patternString, int limitTo, int matchMode, boolean caseSensitive) {
|
||||
private static CSearchPattern createClassPattern(String patternString, SearchFor searchFor, LimitTo limitTo, int matchMode, boolean caseSensitive) {
|
||||
IScanner scanner = ParserFactory.createScanner( new StringReader( patternString ), "TEXT", null, null, ParserMode.QUICK_PARSE );
|
||||
|
||||
LinkedList list = new LinkedList();
|
||||
|
@ -148,8 +146,19 @@ public abstract class CSearchPattern implements ICSearchConstants, ICSearchPatte
|
|||
} catch (ScannerException e) {
|
||||
}
|
||||
|
||||
char [][] qualifications = new char[1][];
|
||||
return new ClassDeclarationPattern( name.toCharArray(), (char[][])list.toArray( qualifications ), null, matchMode, caseSensitive );
|
||||
ClassKind kind = null;
|
||||
if( searchFor == CLASS ){
|
||||
kind = ClassKind.CLASS;
|
||||
} else if( searchFor == STRUCT ) {
|
||||
kind = ClassKind.STRUCT;
|
||||
} else if ( searchFor == ENUM ) {
|
||||
kind = ClassKind.ENUM;
|
||||
} else if ( searchFor == UNION ) {
|
||||
kind = ClassKind.UNION;
|
||||
}
|
||||
|
||||
char [][] qualifications = new char[0][];
|
||||
return new ClassDeclarationPattern( name.toCharArray(), (char[][])list.toArray( qualifications ), kind, matchMode, caseSensitive );
|
||||
}
|
||||
|
||||
protected boolean matchesName( char[] pattern, char[] name ){
|
||||
|
|
|
@ -58,24 +58,36 @@ public class ClassDeclarationPattern extends CSearchPattern {
|
|||
|
||||
//check containing scopes
|
||||
String [] qualifications = clsSpec.getFullyQualifiedName();
|
||||
int size = containingTypes.length;
|
||||
if( qualifications.length < size )
|
||||
return IMPOSSIBLE_MATCH;
|
||||
if( qualifications != null ){
|
||||
|
||||
for( int i = 0; i < containingTypes.length; i++ ){
|
||||
if( !matchesName( containingTypes[i], qualifications[i].toCharArray() ) ){
|
||||
int size = containingTypes.length;
|
||||
if( qualifications.length < size )
|
||||
return IMPOSSIBLE_MATCH;
|
||||
|
||||
for( int i = 0; i < containingTypes.length; i++ ){
|
||||
if( !matchesName( containingTypes[i], qualifications[i].toCharArray() ) ){
|
||||
return IMPOSSIBLE_MATCH;
|
||||
}
|
||||
}
|
||||
} else if( containingTypes.length > 0 ) {
|
||||
return IMPOSSIBLE_MATCH;
|
||||
}
|
||||
|
||||
//check type
|
||||
if( classKind != clsSpec.getClassKind() ){
|
||||
if( classKind != null && classKind != clsSpec.getClassKind() ){
|
||||
return IMPOSSIBLE_MATCH;
|
||||
}
|
||||
|
||||
return ACCURATE_MATCH;
|
||||
}
|
||||
|
||||
public char [] getName() {
|
||||
return simpleName;
|
||||
}
|
||||
public char[] [] getContainingTypes () {
|
||||
return containingTypes;
|
||||
}
|
||||
|
||||
private char[] simpleName;
|
||||
private char[][] containingTypes;
|
||||
private ClassKind classKind;
|
||||
|
|
|
@ -13,21 +13,33 @@
|
|||
*/
|
||||
package org.eclipse.cdt.internal.core.search.matching;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.eclipse.cdt.core.parser.IParser;
|
||||
import org.eclipse.cdt.core.parser.IProblem;
|
||||
import org.eclipse.cdt.core.parser.IScanner;
|
||||
import org.eclipse.cdt.core.parser.ISourceElementRequestor;
|
||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ast.*;
|
||||
import org.eclipse.cdt.core.search.ICSearchPattern;
|
||||
import org.eclipse.cdt.core.search.ICSearchResultCollector;
|
||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||
import org.eclipse.cdt.internal.core.model.IWorkingCopy;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
|
||||
|
@ -88,15 +100,36 @@ public class MatchLocator implements ISourceElementRequestor {
|
|||
String includePath = inclusion.getFullFileName();
|
||||
|
||||
IPath path = new Path( includePath );
|
||||
IResource resource = workspaceRoot.findMember( path, true );
|
||||
if( resource != null ){
|
||||
resourceStack.addFirst( currentResource );
|
||||
currentResource = resource;
|
||||
IResource resource = null;
|
||||
|
||||
if( workspaceRoot != null ){
|
||||
resource = workspaceRoot.findMember( path, true );
|
||||
if( resource == null ){
|
||||
IFile file = workspaceRoot.getFile( path );
|
||||
try{
|
||||
file.createLink( path, 0, null );
|
||||
} catch ( CoreException e ){
|
||||
file = null;
|
||||
}
|
||||
resource = file;
|
||||
}
|
||||
}
|
||||
|
||||
resourceStack.addFirst( ( currentResource != null ) ? (Object)currentResource : (Object)currentPath );
|
||||
|
||||
currentResource = resource;
|
||||
currentPath = ( resource == null ) ? path : null;
|
||||
}
|
||||
|
||||
public void exitInclusion(IASTInclusion inclusion) {
|
||||
currentResource = (IResource) resourceStack.removeFirst();
|
||||
Object obj = resourceStack.removeFirst();
|
||||
if( obj instanceof IResource ){
|
||||
currentResource = (IResource)obj;
|
||||
currentPath = null;
|
||||
} else {
|
||||
currentPath = (IPath) obj;
|
||||
currentResource = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void enterClassSpecifier(IASTClassSpecifier classSpecification) {
|
||||
|
@ -109,16 +142,100 @@ public class MatchLocator implements ISourceElementRequestor {
|
|||
}
|
||||
|
||||
public void locateMatches( String [] paths, IWorkspace workspace, IWorkingCopy[] workingCopies ){
|
||||
workspaceRoot = workspace.getRoot();
|
||||
workspaceRoot = (workspace != null) ? workspace.getRoot() : null;
|
||||
|
||||
HashMap wcPaths = new HashMap();
|
||||
int wcLength = (workingCopies == null) ? 0 : workingCopies.length;
|
||||
if( wcLength > 0 ){
|
||||
String [] newPaths = new String[ wcLength ];
|
||||
|
||||
for( int i = 0; i < wcLength; i++ ){
|
||||
IWorkingCopy workingCopy = workingCopies[ i ];
|
||||
String path = workingCopy.getOriginalElement().getPath().toString();
|
||||
wcPaths.put( path, workingCopy );
|
||||
newPaths[ i ] = path;
|
||||
}
|
||||
|
||||
int len = paths.length;
|
||||
String [] tempArray = new String[ len + wcLength ];
|
||||
System.arraycopy( paths, 0, tempArray, 0, len );
|
||||
System.arraycopy( newPaths, 0, tempArray, len, wcLength );
|
||||
paths = tempArray;
|
||||
}
|
||||
|
||||
Arrays.sort( paths );
|
||||
|
||||
int length = paths.length;
|
||||
if( progressMonitor != null ){
|
||||
progressMonitor.beginTask( "", length );
|
||||
}
|
||||
|
||||
for( int i = 0; i < length; i++ ){
|
||||
if( progressMonitor != null && progressMonitor.isCanceled() ){
|
||||
throw new OperationCanceledException();
|
||||
}
|
||||
|
||||
String pathString = paths[ i ];
|
||||
|
||||
//skip duplicates
|
||||
if( i > 0 && pathString.equals( paths[ i - 1 ] ) ) continue;
|
||||
|
||||
Reader reader = null;
|
||||
if( workspaceRoot != null ){
|
||||
IWorkingCopy workingCopy = (IWorkingCopy)wcPaths.get( pathString );
|
||||
|
||||
if( workingCopy != null ){
|
||||
currentResource = workingCopy.getOriginalElement().getResource();
|
||||
} else {
|
||||
currentResource = workspaceRoot.findMember( pathString, true );
|
||||
}
|
||||
|
||||
try{
|
||||
if( currentResource == null ){
|
||||
IPath path = new Path( pathString );
|
||||
IFile file = workspaceRoot.getFile( path );
|
||||
file.createLink( path, 0, null );
|
||||
}
|
||||
if( currentResource != null && currentResource instanceof IFile ){
|
||||
IFile file = (IFile) currentResource;
|
||||
reader = new InputStreamReader( file.getContents() );
|
||||
} else continue;
|
||||
} catch ( CoreException e ){
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
IPath path = new Path( pathString );
|
||||
try {
|
||||
currentPath = path;
|
||||
reader = new FileReader( path.toFile() );
|
||||
} catch (FileNotFoundException e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
IScanner scanner = ParserFactory.createScanner( reader, pathString, null, null, ParserMode.QUICK_PARSE );
|
||||
IParser parser = ParserFactory.createParser( scanner, null, ParserMode.QUICK_PARSE );
|
||||
parser.setRequestor( this );
|
||||
|
||||
parser.parse();
|
||||
}
|
||||
}
|
||||
|
||||
protected void report( IASTOffsetableElement node, int accuracyLevel ){
|
||||
protected void report( IASTOffsetableNamedElement node, int accuracyLevel ){
|
||||
try {
|
||||
resultCollector.accept( currentResource,
|
||||
node.getElementStartingOffset(),
|
||||
node.getElementEndingOffset(),
|
||||
null,
|
||||
accuracyLevel );
|
||||
if( currentResource != null ){
|
||||
resultCollector.accept( currentResource,
|
||||
node.getElementNameOffset(),
|
||||
node.getElementNameOffset() + node.getName().length(),
|
||||
null,
|
||||
accuracyLevel );
|
||||
} else if( currentPath != null ){
|
||||
resultCollector.accept( currentPath,
|
||||
node.getElementStartingOffset(),
|
||||
node.getElementEndingOffset(),
|
||||
null,
|
||||
accuracyLevel );
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
@ -128,8 +245,9 @@ public class MatchLocator implements ISourceElementRequestor {
|
|||
private ICSearchPattern searchPattern;
|
||||
private ICSearchResultCollector resultCollector;
|
||||
private IProgressMonitor progressMonitor;
|
||||
private IResource currentResource;
|
||||
private IResource currentResource = null;
|
||||
private IPath currentPath = null;
|
||||
private ICSearchScope searchScope;
|
||||
private LinkedList resourceStack;
|
||||
private LinkedList resourceStack = new LinkedList();
|
||||
private IWorkspaceRoot workspaceRoot;
|
||||
}
|
||||
|
|
|
@ -57,11 +57,9 @@ CSearchPage.searchFor.constructor= Co&nstructor
|
|||
|
||||
CSearchPage.limitTo.label= Limit To
|
||||
CSearchPage.limitTo.declarations= Dec&larations
|
||||
CSearchPage.limitTo.implementors= &Implementors
|
||||
CSearchPage.limitTo.definitions= &Definitions
|
||||
CSearchPage.limitTo.references= &References
|
||||
CSearchPage.limitTo.allOccurrences= All &Occurrences
|
||||
CSearchPage.limitTo.readReferences= Read A&ccess
|
||||
CSearchPage.limitTo.writeReferences= Writ&e Access
|
||||
|
||||
CSearchPage.expression.label= Se&arch string (* = any string, ? = any character):
|
||||
CSearchPage.expression.caseSensitive= Case sens&itive
|
||||
|
|
|
@ -33,21 +33,21 @@ import org.eclipse.ui.actions.WorkspaceModifyOperation;
|
|||
* To change the template for this generated type comment go to
|
||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||
*/
|
||||
public class CSearchOperation extends WorkspaceModifyOperation {
|
||||
public class CSearchOperation extends WorkspaceModifyOperation implements ICSearchConstants{
|
||||
|
||||
public CSearchOperation(IWorkspace workspace, ICElement element, int limitTo, ICSearchScope scope, String scopeDescription, CSearchResultCollector collector) {
|
||||
public CSearchOperation(IWorkspace workspace, ICElement element, LimitTo limitTo, ICSearchScope scope, String scopeDescription, CSearchResultCollector collector) {
|
||||
this( workspace, limitTo, scope, scopeDescription, collector );
|
||||
_elementPattern = element;
|
||||
}
|
||||
|
||||
public CSearchOperation(IWorkspace workspace, String pattern, boolean caseSensitive, int searchFor, int limitTo, ICSearchScope scope, String scopeDescription, CSearchResultCollector collector) {
|
||||
public CSearchOperation(IWorkspace workspace, String pattern, boolean caseSensitive, SearchFor searchFor, LimitTo limitTo, ICSearchScope scope, String scopeDescription, CSearchResultCollector collector) {
|
||||
this( workspace, limitTo, scope, scopeDescription, collector );
|
||||
_stringPattern = pattern;
|
||||
_caseSensitive = caseSensitive;
|
||||
_searchFor = searchFor;
|
||||
}
|
||||
|
||||
public CSearchOperation(IWorkspace workspace, int limitTo, ICSearchScope scope, String scopeDescription, CSearchResultCollector collector ){
|
||||
public CSearchOperation(IWorkspace workspace, LimitTo limitTo, ICSearchScope scope, String scopeDescription, CSearchResultCollector collector ){
|
||||
_workspace = workspace;
|
||||
_limitTo = limitTo;
|
||||
_scope = scope;
|
||||
|
@ -87,13 +87,13 @@ public class CSearchOperation extends WorkspaceModifyOperation {
|
|||
}
|
||||
|
||||
String [] args = new String [] { desc, _scopeDescription };
|
||||
switch( _limitTo ){
|
||||
case ICSearchConstants.DECLARATIONS :
|
||||
return CSearchMessages.getFormattedString( "CSearchOperation.singularDeclarationsPostfix", args ); //$NON_NLS-1$
|
||||
case ICSearchConstants.REFERENCES :
|
||||
return CSearchMessages.getFormattedString( "CSearchOperation.singularReferencesPostfix", args ); //$NON_NLS-1$
|
||||
default:
|
||||
return CSearchMessages.getFormattedString( "CSearchOperation.singularOccurencesPostfix", args ); //$NON_NLS-1$
|
||||
|
||||
if( _limitTo == DECLARATIONS ){
|
||||
return CSearchMessages.getFormattedString( "CSearchOperation.singularDeclarationsPostfix", args ); //$NON_NLS-1$
|
||||
} else if( _limitTo == REFERENCES ){
|
||||
return CSearchMessages.getFormattedString( "CSearchOperation.singularReferencesPostfix", args ); //$NON_NLS-1$
|
||||
} else {
|
||||
return CSearchMessages.getFormattedString( "CSearchOperation.singularOccurencesPostfix", args ); //$NON_NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,13 +110,12 @@ public class CSearchOperation extends WorkspaceModifyOperation {
|
|||
}
|
||||
|
||||
String [] args = new String [] { desc, "{0}", _scopeDescription };
|
||||
switch( _limitTo ){
|
||||
case ICSearchConstants.DECLARATIONS :
|
||||
return CSearchMessages.getFormattedString( "CSearchOperation.pluralDeclarationsPostfix", args ); //$NON_NLS-1$
|
||||
case ICSearchConstants.REFERENCES :
|
||||
return CSearchMessages.getFormattedString( "CSearchOperation.pluralReferencesPostfix", args ); //$NON_NLS-1$
|
||||
default:
|
||||
return CSearchMessages.getFormattedString( "CSearchOperation.pluralOccurencesPostfix", args ); //$NON_NLS-1$
|
||||
if( _limitTo == DECLARATIONS ){
|
||||
return CSearchMessages.getFormattedString( "CSearchOperation.pluralDeclarationsPostfix", args ); //$NON_NLS-1$
|
||||
} else if ( _limitTo == REFERENCES ){
|
||||
return CSearchMessages.getFormattedString( "CSearchOperation.pluralReferencesPostfix", args ); //$NON_NLS-1$
|
||||
} else {
|
||||
return CSearchMessages.getFormattedString( "CSearchOperation.pluralOccurencesPostfix", args ); //$NON_NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -138,8 +137,8 @@ public class CSearchOperation extends WorkspaceModifyOperation {
|
|||
private String _stringPattern;
|
||||
private String _scopeDescription;
|
||||
private boolean _caseSensitive;
|
||||
private int _limitTo;
|
||||
private int _searchFor;
|
||||
private LimitTo _limitTo;
|
||||
private SearchFor _searchFor;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -18,12 +18,14 @@ import java.io.IOException;
|
|||
import java.io.StringReader;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.search.ICSearchConstants;
|
||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||
import org.eclipse.cdt.core.search.SearchEngine;
|
||||
//import org.eclipse.cdt.core.search.SearchFor;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
|
@ -229,21 +231,7 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
|||
int index = fgPreviousSearchPatterns.size() - 1 - fPattern.getSelectionIndex();
|
||||
fInitialData = (SearchPatternData) fgPreviousSearchPatterns.get( index );
|
||||
|
||||
for (int i = 0; i < fSearchFor.length; i++)
|
||||
fSearchFor[i].setSelection(false);
|
||||
|
||||
for (int i = 0; i < fLimitTo.length; i++)
|
||||
fLimitTo[i].setSelection(false);
|
||||
|
||||
fSearchFor[ fInitialData.searchFor ].setSelection( true );
|
||||
setLimitTo( fInitialData.searchFor );
|
||||
fLimitTo[ fInitialData.limitTo ].setSelection( true );
|
||||
|
||||
fPattern.setText( fInitialData.pattern );
|
||||
fIsCaseSensitive = fInitialData.isCaseSensitive;
|
||||
fCElement = fInitialData.cElement;
|
||||
fCaseSensitive.setEnabled( fCElement == null );
|
||||
fCaseSensitive.setSelection( fInitialData.isCaseSensitive );
|
||||
updateSelections();
|
||||
|
||||
if( fInitialData.workingSets != null )
|
||||
getContainer().setSelectedWorkingSets( fInitialData.workingSets );
|
||||
|
@ -272,43 +260,35 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
|||
return result;
|
||||
}
|
||||
|
||||
private int getLimitTo() {
|
||||
private LimitTo getLimitTo() {
|
||||
for (int i= 0; i < fLimitTo.length; i++) {
|
||||
if (fLimitTo[i].getSelection())
|
||||
return i;
|
||||
return fLimitToValues[ i ];
|
||||
}
|
||||
return -1;
|
||||
return null;
|
||||
}
|
||||
private void setLimitTo(int searchFor) {
|
||||
fLimitTo[ DECLARATIONS ].setEnabled( true );
|
||||
//fLimitTo[ IMPLEMENTORS ].setEnabled( false);
|
||||
fLimitTo[ REFERENCES ].setEnabled( true );
|
||||
fLimitTo[ ALL_OCCURRENCES ].setEnabled( true );
|
||||
//fLimitTo[ READ_ACCESSES ].setEnabled( false);
|
||||
//fLimitTo[ WRITE_ACCESSES ].setEnabled( false);
|
||||
|
||||
// if (!(searchFor == TYPE || searchFor == INTERFACE) && fLimitTo[IMPLEMENTORS].getSelection()) {
|
||||
// fLimitTo[ IMPLEMENTORS ].setSelection(false);
|
||||
// fLimitTo[ REFERENCES ].setSelection(true);
|
||||
// }
|
||||
//
|
||||
// if (!(searchFor == FIELD) && (getLimitTo() == READ_ACCESSES || getLimitTo() == WRITE_ACCESSES)) {
|
||||
// fLimitTo[ getLimitTo()].setSelection(false);
|
||||
// fLimitTo[ REFERENCES ].setSelection(true);
|
||||
// }
|
||||
//
|
||||
// switch (searchFor) {
|
||||
// case TYPE:
|
||||
// case INTERFACE:
|
||||
// fLimitTo[ IMPLEMENTORS ].setEnabled(true);
|
||||
// break;
|
||||
// case FIELD:
|
||||
// fLimitTo[ READ_ACCESSES ].setEnabled(true);
|
||||
// fLimitTo[ WRITE_ACCESSES ].setEnabled(true);
|
||||
// break;
|
||||
// default :
|
||||
// break;
|
||||
// }
|
||||
private void setLimitTo( SearchFor searchFor ) {
|
||||
HashSet set = new HashSet();
|
||||
|
||||
if( searchFor == TYPE ){
|
||||
set.add( DECLARATIONS );
|
||||
set.add( REFERENCES );
|
||||
} else if ( searchFor == FUNCTION || searchFor == CONSTRUCTOR ) {
|
||||
set.add( DECLARATIONS );
|
||||
set.add( DEFINITIONS );
|
||||
//set.add( REFERENCES );
|
||||
} else if( searchFor == NAMESPACE ) {
|
||||
set.add( DECLARATIONS );
|
||||
set.add( REFERENCES );
|
||||
} else if( searchFor == MEMBER ) {
|
||||
set.add( DECLARATIONS );
|
||||
set.add( REFERENCES );
|
||||
}
|
||||
set.add( ALL_OCCURRENCES );
|
||||
|
||||
for( int i = 0; i < fLimitTo.length; i++ )
|
||||
fLimitTo[ i ].setEnabled( set.contains( fLimitToValues[ i ] ) );
|
||||
}
|
||||
|
||||
private Control createSearchFor(Composite parent) {
|
||||
|
@ -334,13 +314,13 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
|||
return result;
|
||||
}
|
||||
|
||||
private int getSearchFor() {
|
||||
private SearchFor getSearchFor() {
|
||||
for (int i= 0; i < fSearchFor.length; i++) {
|
||||
if (fSearchFor[i].getSelection())
|
||||
return i;
|
||||
if( fSearchFor[i].getSelection() )
|
||||
return fSearchForValues[ i ];
|
||||
}
|
||||
Assert.isTrue(false, "shouldNeverHappen"); //$NON-NLS-1$
|
||||
return -1;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setContainer(ISearchPageContainer container) {
|
||||
|
@ -399,17 +379,28 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
|||
private void initSelections() {
|
||||
fStructuredSelection = asStructuredSelection();
|
||||
fInitialData = tryStructuredSelection( fStructuredSelection );
|
||||
updateSelections();
|
||||
}
|
||||
|
||||
private void updateSelections(){
|
||||
if (fInitialData == null)
|
||||
fInitialData = trySimpleTextSelection( getContainer().getSelection() );
|
||||
if (fInitialData == null)
|
||||
fInitialData = getDefaultInitValues();
|
||||
|
||||
fCElement = fInitialData.cElement;
|
||||
fIsCaseSensitive = fInitialData.isCaseSensitive;
|
||||
fCaseSensitive.setSelection( fInitialData.isCaseSensitive );
|
||||
fCaseSensitive.setEnabled( fInitialData.cElement == null );
|
||||
fSearchFor[ fInitialData.searchFor ].setSelection( true );
|
||||
|
||||
for (int i = 0; i < fSearchFor.length; i++)
|
||||
fSearchFor[i].setSelection( fSearchForValues[i] == fInitialData.searchFor );
|
||||
|
||||
setLimitTo( fInitialData.searchFor );
|
||||
fLimitTo[ fInitialData.limitTo ].setSelection( true );
|
||||
|
||||
for (int i = 0; i < fLimitTo.length; i++)
|
||||
fLimitTo[i].setSelection( fLimitToValues[i] == fInitialData.limitTo );
|
||||
|
||||
fPattern.setText( fInitialData.pattern );
|
||||
}
|
||||
|
||||
|
@ -456,13 +447,13 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
|||
} catch (IOException ex) {
|
||||
text= ""; //$NON-NLS-1$
|
||||
}
|
||||
result= new SearchPatternData(TYPE, REFERENCES, fIsCaseSensitive, text, null);
|
||||
result= new SearchPatternData( TYPE, REFERENCES, fIsCaseSensitive, text, null);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private SearchPatternData getDefaultInitValues() {
|
||||
return new SearchPatternData(TYPE, REFERENCES, fIsCaseSensitive, "", null); //$NON-NLS-1$
|
||||
return new SearchPatternData( TYPE, REFERENCES, fIsCaseSensitive, "", null); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
private String[] getPreviousSearchPatterns() {
|
||||
|
@ -494,8 +485,8 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
|||
if( element == null )
|
||||
return null;
|
||||
|
||||
int searchFor = UNKNOWN;
|
||||
int limitTo = UNKNOWN;
|
||||
SearchFor searchFor = UNKNOWN_SEARCH_FOR;
|
||||
LimitTo limitTo = UNKNOWN_LIMIT_TO;
|
||||
|
||||
String pattern = null;
|
||||
switch( element.getElementType() ) {
|
||||
|
@ -506,7 +497,7 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
|||
break;*/
|
||||
}
|
||||
|
||||
if( searchFor != UNKNOWN && limitTo != UNKNOWN && pattern != null )
|
||||
if( searchFor != UNKNOWN_SEARCH_FOR && limitTo != UNKNOWN_LIMIT_TO && pattern != null )
|
||||
return new SearchPatternData( searchFor, limitTo, true, pattern, element );
|
||||
|
||||
return null;
|
||||
|
@ -546,19 +537,19 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
|||
}
|
||||
|
||||
private static class SearchPatternData {
|
||||
int searchFor;
|
||||
int limitTo;
|
||||
SearchFor searchFor;
|
||||
LimitTo limitTo;
|
||||
String pattern;
|
||||
boolean isCaseSensitive;
|
||||
ICElement cElement;
|
||||
int scope;
|
||||
IWorkingSet[] workingSets;
|
||||
|
||||
public SearchPatternData(int s, int l, boolean i, String p, ICElement element) {
|
||||
public SearchPatternData(SearchFor s, LimitTo l, boolean i, String p, ICElement element) {
|
||||
this(s, l, p, i, element, ISearchPageContainer.WORKSPACE_SCOPE, null);
|
||||
}
|
||||
|
||||
public SearchPatternData(int s, int l, String p, boolean i, ICElement element, int scope, IWorkingSet[] workingSets) {
|
||||
public SearchPatternData(SearchFor s, LimitTo l, String p, boolean i, ICElement element, int scope, IWorkingSet[] workingSets) {
|
||||
searchFor= s;
|
||||
limitTo= l;
|
||||
pattern= p;
|
||||
|
@ -573,9 +564,10 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
|||
private final static String PAGE_NAME= "CSearchPage"; //$NON-NLS-1$
|
||||
private final static String STORE_CASE_SENSITIVE= PAGE_NAME + "CASE_SENSITIVE"; //$NON-NLS-1$
|
||||
|
||||
private static List fgPreviousSearchPatterns= new ArrayList(20);
|
||||
private static List fgPreviousSearchPatterns = new ArrayList(20);
|
||||
|
||||
private Button[] fSearchFor;
|
||||
private SearchFor[] fSearchForValues = { TYPE, FUNCTION, NAMESPACE, CONSTRUCTOR, MEMBER };
|
||||
private String[] fSearchForText= {
|
||||
CSearchMessages.getString("CSearchPage.searchFor.type"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.searchFor.method"), //$NON-NLS-1$
|
||||
|
@ -584,13 +576,14 @@ public class CSearchPage extends DialogPage implements ISearchPage, ICSearchCons
|
|||
CSearchMessages.getString("CSearchPage.searchFor.field")}; //$NON-NLS-1$
|
||||
|
||||
private Button[] fLimitTo;
|
||||
private LimitTo[] fLimitToValues = { DECLARATIONS, DEFINITIONS, REFERENCES, ALL_OCCURRENCES };
|
||||
private String[] fLimitToText= {
|
||||
CSearchMessages.getString("CSearchPage.limitTo.declarations"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.limitTo.implementors"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.limitTo.definitions"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.limitTo.references"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.limitTo.allOccurrences"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.limitTo.readReferences"), //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.limitTo.writeReferences")}; //$NON-NLS-1$
|
||||
CSearchMessages.getString("CSearchPage.limitTo.allOccurrences") }; //$NON-NLS-1$
|
||||
//CSearchMessages.getString("CSearchPage.limitTo.readReferences"), //$NON-NLS-1$
|
||||
//CSearchMessages.getString("CSearchPage.limitTo.writeReferences")}; //$NON-NLS-1$
|
||||
|
||||
private SearchPatternData fInitialData;
|
||||
private IStructuredSelection fStructuredSelection;
|
||||
|
|
|
@ -15,12 +15,15 @@ package org.eclipse.cdt.internal.ui.search;
|
|||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.search.ICSearchResultCollector;
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.search.ui.IActionGroupFactory;
|
||||
import org.eclipse.search.ui.ISearchResultView;
|
||||
|
@ -34,7 +37,6 @@ import org.eclipse.ui.actions.ActionGroup;
|
|||
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||
*/
|
||||
public class CSearchResultCollector implements ICSearchResultCollector {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -94,6 +96,21 @@ public class CSearchResultCollector implements ICSearchResultCollector {
|
|||
_matchCount++;
|
||||
}
|
||||
|
||||
public void accept(
|
||||
IPath path,
|
||||
int start,
|
||||
int end,
|
||||
ICElement enclosingElement,
|
||||
int accuracy)
|
||||
throws CoreException
|
||||
{
|
||||
if( _matches == null ){
|
||||
_matches = new HashSet();
|
||||
}
|
||||
|
||||
_matches.add( new Match( path.toString(), start, end ) );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.search.ICSearchResultCollector#done()
|
||||
*/
|
||||
|
@ -132,20 +149,38 @@ public class CSearchResultCollector implements ICSearchResultCollector {
|
|||
_operation = operation;
|
||||
}
|
||||
|
||||
public Set getMatches(){
|
||||
return _matches;
|
||||
}
|
||||
|
||||
private class ActionGroupFactory implements IActionGroupFactory {
|
||||
public ActionGroup createActionGroup( ISearchResultView part ){
|
||||
return new CSearchViewActionGroup( part );
|
||||
}
|
||||
}
|
||||
|
||||
public static class Match {
|
||||
public Match( String path, int start, int end ){
|
||||
this.path = path;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
public String path;
|
||||
public int start;
|
||||
public int end;
|
||||
}
|
||||
|
||||
private static final String SEARCHING = CSearchMessages.getString("CSearchResultCollector.searching"); //$NON-NLS-1$
|
||||
private static final String MATCH = CSearchMessages.getString("CSearchResultCollector.match"); //$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 IProgressMonitor _monitor;
|
||||
private CSearchOperation _operation;
|
||||
private ISearchResultView _view;
|
||||
private int _matchCount;
|
||||
private Set _matches;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue