mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Applied patch for Devin Steffler.
Open Declarations/Search For Refs/Search for Decls actions reworked to use the new DOM.
This commit is contained in:
parent
8b54fcec9e
commit
0fedc36b90
31 changed files with 3357 additions and 476 deletions
|
@ -1,5 +1,5 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003 Rational Software Corporation and others.
|
||||
* Copyright (c) 2002,2005 Rational Software 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
|
||||
|
@ -16,6 +16,7 @@ import junit.framework.TestSuite;
|
|||
|
||||
import org.eclipse.cdt.core.model.tests.CModelElementsTests;
|
||||
import org.eclipse.cdt.core.model.tests.StructuralCModelElementsTests;
|
||||
import org.eclipse.cdt.core.parser.tests.ast2.DOMGCCParserExtensionTestSuite;
|
||||
import org.eclipse.cdt.core.parser.tests.ast2.DOMParserTestSuite;
|
||||
import org.eclipse.cdt.core.parser.tests.scanner2.IncludeTest;
|
||||
import org.eclipse.cdt.core.parser.tests.scanner2.ObjectMapTest;
|
||||
|
@ -55,6 +56,7 @@ public class ParserTestSuite extends TestCase {
|
|||
suite.addTest( ScannerParserLoopTest.suite() );
|
||||
suite.addTest( GCCParserExtensionTestSuite.suite() );
|
||||
suite.addTest( DOMParserTestSuite.suite() );
|
||||
suite.addTest( DOMGCCParserExtensionTestSuite.suite() );
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,155 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
/*
|
||||
* Created on Sept 28, 2004
|
||||
*/
|
||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.core.testplugin.FileManager;
|
||||
import org.eclipse.cdt.internal.core.index.sourceindexer.SourceIndexer;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
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.NullProgressMonitor;
|
||||
|
||||
/**
|
||||
* @author dsteffle
|
||||
*/
|
||||
public class DOMFileBasePluginTest extends TestCase {
|
||||
static NullProgressMonitor monitor;
|
||||
static IWorkspace workspace;
|
||||
static IProject project;
|
||||
static FileManager fileManager;
|
||||
static int numProjects = 0;
|
||||
static Class className;
|
||||
static ICProject cPrj;
|
||||
|
||||
private void initialize(Class aClassName){
|
||||
if( CCorePlugin.getDefault() != null && CCorePlugin.getDefault().getCoreModel() != null){
|
||||
//(CCorePlugin.getDefault().getCoreModel().getIndexManager()).reset();
|
||||
monitor = new NullProgressMonitor();
|
||||
|
||||
workspace = ResourcesPlugin.getWorkspace();
|
||||
|
||||
try {
|
||||
cPrj = CProjectHelper.createCCProject("ParserTestProject", "bin"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
project = cPrj.getProject();
|
||||
project.setSessionProperty(SourceIndexer.activationKey,new Boolean(false));
|
||||
|
||||
// ugly
|
||||
if (className == null || !className.equals(aClassName)) {
|
||||
className = aClassName;
|
||||
numProjects++;
|
||||
}
|
||||
} catch ( CoreException e ) {
|
||||
/*boo*/
|
||||
}
|
||||
if (project == null)
|
||||
throw new NullPointerException("Unable to create project"); //$NON-NLS-1$
|
||||
|
||||
//Create file manager
|
||||
fileManager = new FileManager();
|
||||
}
|
||||
}
|
||||
|
||||
public DOMFileBasePluginTest(String name, Class className)
|
||||
{
|
||||
super(name);
|
||||
initialize(className);
|
||||
}
|
||||
|
||||
public void cleanupProject() throws Exception {
|
||||
numProjects--;
|
||||
|
||||
try{
|
||||
if (numProjects == 0) {
|
||||
project.delete( true, false, monitor );
|
||||
project = null;
|
||||
}
|
||||
} catch( Throwable e ){
|
||||
/*boo*/
|
||||
}
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
if( project == null || !project.exists() )
|
||||
return;
|
||||
|
||||
IResource [] members = project.members();
|
||||
for( int i = 0; i < members.length; i++ ){
|
||||
if( members[i].getName().equals( ".project" ) || members[i].getName().equals( ".cdtproject" ) ) //$NON-NLS-1$ //$NON-NLS-2$
|
||||
continue;
|
||||
try{
|
||||
members[i].delete( false, monitor );
|
||||
} catch( Throwable e ){
|
||||
/*boo*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// below can be used to work with large files (too large for memory)
|
||||
// protected IFile importFile(String fileName) throws Exception {
|
||||
// IFile file = cPrj.getProject().getFile(fileName);
|
||||
// if (!file.exists()) {
|
||||
// try{
|
||||
// FileInputStream fileIn = new FileInputStream(
|
||||
// CTestPlugin.getDefault().getFileInPlugin(new Path("resources/parser/" + fileName)));
|
||||
// file.create(fileIn,false, monitor);
|
||||
// } catch (CoreException e) {
|
||||
// e.printStackTrace();
|
||||
// } catch (FileNotFoundException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return file;
|
||||
// }
|
||||
|
||||
protected IFolder importFolder(String folderName) throws Exception {
|
||||
IFolder folder = project.getProject().getFolder(folderName);
|
||||
|
||||
//Create file input stream
|
||||
if( !folder.exists() )
|
||||
folder.create( false, false, monitor );
|
||||
|
||||
return folder;
|
||||
}
|
||||
public IFile importFile(String fileName, String contents ) throws Exception{
|
||||
//Obtain file handle
|
||||
IFile file = project.getProject().getFile(fileName);
|
||||
|
||||
InputStream stream = new ByteArrayInputStream( contents.getBytes() );
|
||||
//Create file input stream
|
||||
if( file.exists() )
|
||||
file.setContents( stream, false, false, monitor );
|
||||
else
|
||||
file.create( stream, false, monitor );
|
||||
|
||||
fileManager.addFile(file);
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2004, 2005 IBM Canada Ltd. 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 Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
*/
|
||||
public class DOMGCCParserExtensionTestSuite extends TestCase {
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite= new TestSuite(DOMGCCParserExtensionTestSuite.class.getName());
|
||||
// suite.addTestSuite( GCCScannerExtensionsTest.class );
|
||||
// suite.addTestSuite( GCCQuickParseExtensionsTest.class );
|
||||
// suite.addTestSuite( GCCCompleteParseExtensionsTest.class );
|
||||
suite.addTestSuite( DOMGCCSelectionParseExtensionsTest.class);
|
||||
return suite;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002, 2005 Rational Software 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 Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
*/
|
||||
public class DOMGCCSelectionParseExtensionsTest extends DOMSelectionParseBaseTest {
|
||||
|
||||
public DOMGCCSelectionParseExtensionsTest(String name) {
|
||||
super(name, DOMGCCSelectionParseExtensionsTest.class);
|
||||
}
|
||||
|
||||
public void testBug43021() throws Exception
|
||||
{
|
||||
Writer writer = new StringWriter();
|
||||
writer.write( "extern int johnc(__const char *__restrict __format, ...);\n" ); //$NON-NLS-1$
|
||||
writer.write( "void m() {johnc(\"HI\");}" ); //$NON-NLS-1$
|
||||
String code = writer.toString();
|
||||
int startIndex = code.indexOf( "{johnc") + 1; //$NON-NLS-1$
|
||||
IASTNode node = parse( code, startIndex, startIndex + 5 );
|
||||
assertNotNull( node );
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2004 IBM Corporation and others.
|
||||
* Copyright (c) 2004,2005 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -42,9 +42,9 @@ public class DOMParserTestSuite extends TestCase {
|
|||
suite.addTestSuite( AST2CPPSpecFailingTest.class );
|
||||
suite.addTestSuite( AST2CSpecTest.class );
|
||||
suite.addTestSuite( AST2CSpecFailingTest.class );
|
||||
suite.addTestSuite( DOMSelectionParseTest.class );
|
||||
suite.addTest( CompletionTestSuite.suite() );
|
||||
return suite;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002-2005 Rational Software 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 Rational Software - Initial API and implementation */
|
||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.search.DOMSearchUtil;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
||||
/**
|
||||
* @author johnc
|
||||
*
|
||||
*/
|
||||
public class DOMSelectionParseBaseTest extends DOMFileBasePluginTest {
|
||||
|
||||
public DOMSelectionParseBaseTest(String name, Class className) {
|
||||
super(name, className);
|
||||
}
|
||||
|
||||
protected IASTNode parse(String code, int offset1, int offset2) throws Exception {
|
||||
return parse( code, offset1, offset2, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param code
|
||||
* @param offset1
|
||||
* @param offset2
|
||||
* @param b
|
||||
* @return
|
||||
*/
|
||||
protected IASTNode parse(String code, int offset1, int offset2, boolean expectedToPass) throws Exception {
|
||||
IFile file = importFile("temp.cpp", code); //$NON-NLS-1$
|
||||
IASTName[] names = DOMSearchUtil.getSelectedNamesFrom(file, offset1, offset2 - offset1);
|
||||
|
||||
if (!expectedToPass) return null;
|
||||
|
||||
if (names.length == 0) {
|
||||
assertFalse(true);
|
||||
} else {
|
||||
return names[0];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected IASTNode parse(IFile file, int offset1, int offset2, boolean expectedToPass) throws Exception {
|
||||
IASTName[] names = DOMSearchUtil.getSelectedNamesFrom(file, offset1, offset2 - offset1);
|
||||
|
||||
if (!expectedToPass) return null;
|
||||
|
||||
if (names.length == 0) {
|
||||
assertFalse(true);
|
||||
} else {
|
||||
return names[0];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected IASTName[] getDeclarationOffTU(IASTName name) {
|
||||
return name.getTranslationUnit().getDeclarations(name.resolveBinding());
|
||||
}
|
||||
|
||||
protected IASTName[] getReferencesOffTU(IASTName name) {
|
||||
return name.getTranslationUnit().getReferences(name.resolveBinding());
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -34,5 +34,13 @@ public interface IEntryResult {
|
|||
* offset array
|
||||
*/
|
||||
public int[][] getOffsetLengths();
|
||||
|
||||
/**
|
||||
* Returns the simple name for this IEntryResult.
|
||||
*
|
||||
* ex:
|
||||
* typeDecl/V/foo/namespace returns "foo"
|
||||
*/
|
||||
public String extractSimpleName();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2005 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.core.index.cindexstorage;
|
|||
|
||||
import org.eclipse.cdt.internal.core.CharOperation;
|
||||
import org.eclipse.cdt.internal.core.index.IEntryResult;
|
||||
import org.eclipse.cdt.internal.core.index.IIndex;
|
||||
|
||||
|
||||
public class EntryResult implements IEntryResult {
|
||||
|
@ -86,9 +87,45 @@ public String toString(){
|
|||
public int[][] getOffsets() {
|
||||
return offsets;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.index.IEntryResult#getOffsetLengths()
|
||||
*/
|
||||
public int[][] getOffsetLengths() {
|
||||
return offsetLengths;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.index.IEntryResult#extractSimpleName()
|
||||
*/
|
||||
public String extractSimpleName() {
|
||||
return EntryResult.extractSimpleName(getWord());
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.index.IEntryResult#extractSimpleName(char[])
|
||||
*/
|
||||
public static String extractSimpleName(char[] word) {
|
||||
String aWord = new String(word);
|
||||
String longName=null;
|
||||
|
||||
String typeDecl = Index.getDescriptionOf(IIndex.TYPE, IIndex.ANY, IIndex.DECLARATION);
|
||||
String typeDef = Index.getDescriptionOf(IIndex.TYPE, IIndex.ANY, IIndex.DEFINITION);
|
||||
String typeRef = Index.getDescriptionOf(IIndex.TYPE, IIndex.ANY, IIndex.REFERENCE);
|
||||
|
||||
if (aWord.indexOf(typeDecl) == 0) {
|
||||
longName = aWord.substring(aWord.indexOf(IndexerOutput.SEPARATOR, typeDecl.length())+1);
|
||||
} else if (aWord.indexOf(typeRef) == 0) {
|
||||
longName = aWord.substring(aWord.indexOf(IndexerOutput.SEPARATOR, typeRef.length())+1);
|
||||
} else if (aWord.indexOf(typeDef) == 0) {
|
||||
longName = aWord.substring(aWord.indexOf(IndexerOutput.SEPARATOR, typeDef.length())+1);
|
||||
} else {
|
||||
longName = aWord.substring(aWord.indexOf(IndexerOutput.SEPARATOR)+1);
|
||||
}
|
||||
|
||||
int sepPos=longName.indexOf(IndexerOutput.SEPARATOR);
|
||||
if (sepPos>=0)
|
||||
return aWord.substring(0, longName.indexOf(IndexerOutput.SEPARATOR));
|
||||
else
|
||||
return longName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2004 QNX Software Systems and others.
|
||||
* Copyright (c) 2000, 2005 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -193,6 +193,12 @@ public interface ICElement extends IAdaptable {
|
|||
* struct C;
|
||||
*/
|
||||
static final int C_UNION_DECLARATION = 87;
|
||||
|
||||
/**
|
||||
* An unknown ICElement. Mainly used to determine what elements are not yet implemented.
|
||||
* i.e. the new DOM Parser supports open declaration on labels, while the old parser did not
|
||||
*/
|
||||
static final int C_UNKNOWN_DECLARATION = 88;
|
||||
|
||||
/**
|
||||
* Modifier indicating a class constructor
|
||||
|
|
|
@ -374,4 +374,63 @@ public class ASTTypeUtil {
|
|||
return getType(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* This can be used to invoke the IType's isConst() if it has an isConst() method.
|
||||
* This returns the result of that invoked isConst() method.
|
||||
* It is a convenience function so that the structure of IType does not need
|
||||
* to be known to determine if the IType is const or not.
|
||||
*
|
||||
* Note: false is returned if no isConst() method is found
|
||||
*
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
public static boolean isConst(IType type) {
|
||||
if (type instanceof IQualifierType) {
|
||||
try {
|
||||
return ((IQualifierType)type).isConst();
|
||||
} catch (DOMException e) {
|
||||
return false;
|
||||
}
|
||||
} else if (type instanceof ITypeContainer) {
|
||||
try {
|
||||
return isConst(((ITypeContainer)type).getType());
|
||||
} catch (DOMException e) {
|
||||
return false;
|
||||
}
|
||||
} else if (type instanceof IArrayType) {
|
||||
try {
|
||||
return isConst(((IArrayType)type).getType());
|
||||
} catch (DOMException e) {
|
||||
return false;
|
||||
}
|
||||
} else if (type instanceof ICPPReferenceType) {
|
||||
try {
|
||||
return isConst(((ICPPReferenceType)type).getType());
|
||||
} catch (DOMException e) {
|
||||
return false;
|
||||
}
|
||||
} else if (type instanceof IFunctionType) {
|
||||
try {
|
||||
return isConst(((IFunctionType)type).getReturnType());
|
||||
} catch (DOMException e) {
|
||||
return false;
|
||||
}
|
||||
} else if (type instanceof IPointerType) {
|
||||
try {
|
||||
return isConst(((IPointerType)type).getType());
|
||||
} catch (DOMException e) {
|
||||
return false;
|
||||
}
|
||||
} else if (type instanceof ITypedef) {
|
||||
try {
|
||||
return isConst(((ITypedef)type).getType());
|
||||
} catch (DOMException e) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 IBM Corporation and others.
|
||||
* Copyright (c) 2004,2005 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -212,7 +212,7 @@ public class CharArrayUtils {
|
|||
for( int i = 0; i < array.length; i++ ){
|
||||
if( toBeFound[j] == array[i] ){
|
||||
if( ++j == toBeFound.length )
|
||||
return i - j;
|
||||
return i - j + 1;
|
||||
}
|
||||
else j = 0;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,330 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2005 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.search;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.ICLogConstants;
|
||||
import org.eclipse.cdt.core.dom.CDOM;
|
||||
import org.eclipse.cdt.core.dom.IASTServiceProvider;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.c.CASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias;
|
||||
import org.eclipse.cdt.core.filetype.ICFileType;
|
||||
import org.eclipse.cdt.core.filetype.ICFileTypeConstants;
|
||||
import org.eclipse.cdt.core.parser.ParseError;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.core.search.ICSearchConstants.LimitTo;
|
||||
import org.eclipse.cdt.core.search.ICSearchConstants.SearchFor;
|
||||
import org.eclipse.cdt.internal.core.search.matching.CSearchPattern;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
|
||||
/**
|
||||
* Utility class to have commonly used algorithms in one place for searching with the DOM.
|
||||
*
|
||||
* @author dsteffle
|
||||
*/
|
||||
public class DOMSearchUtil {
|
||||
private static final IASTName[] BLANK_NAME_ARRAY = new IASTName[0];
|
||||
private static final IASTName[] EMPTY_NAME_LIST = BLANK_NAME_ARRAY;
|
||||
private static final Set EMPTY_MATCHES = new HashSet(0);
|
||||
|
||||
/**
|
||||
* This is a convenience method that uses the SearchEngine to find declarations, references, or both that correspond
|
||||
* to the IASTName searchName found in the index.
|
||||
*
|
||||
* @param scope is used to limit the scope that SearchEngine searches the index against
|
||||
* @param searchName is the IASTName whose delcarations/references are sought after
|
||||
* @param limitTo used to specify whether to get declarations, references, or both, one of:
|
||||
* ( CSearchPattern.DECLARATION | CSearchPattern.REFERENCES | CSearchPattern.ALL_OCCURRENCES )
|
||||
* @return
|
||||
*/
|
||||
public static Set getMatchesFromSearchEngine(ICSearchScope scope, IASTName searchName, LimitTo limitTo) {
|
||||
SearchEngine engine = new SearchEngine();
|
||||
BasicSearchResultCollector results = new BasicSearchResultCollector();
|
||||
|
||||
ICSearchPattern pattern = createPattern(searchName.resolveBinding(), limitTo, true);
|
||||
|
||||
try {
|
||||
engine.search(CCorePlugin.getWorkspace(), pattern, scope, results, false);
|
||||
} catch (InterruptedException e) {
|
||||
return EMPTY_MATCHES;
|
||||
}
|
||||
|
||||
return results.getSearchResults();
|
||||
}
|
||||
|
||||
private static CSearchPattern createPattern( IBinding binding, LimitTo limitTo, boolean caseSensitive) {
|
||||
// build the SearchFor/pattern based on the IBinding
|
||||
SearchFor searchFor = createSearchFor(binding);
|
||||
if (binding instanceof IFunction) {
|
||||
searchFor = ICSearchConstants.FUNCTION;
|
||||
} else if (binding instanceof ICPPNamespace || binding instanceof ICPPNamespaceAlias) {
|
||||
searchFor = ICSearchConstants.NAMESPACE;
|
||||
} else if (binding instanceof ICPPField) {
|
||||
searchFor = ICSearchConstants.FIELD;
|
||||
} else if (binding instanceof IEnumerator) {
|
||||
searchFor = ICSearchConstants.ENUMTOR;
|
||||
} else if (binding instanceof ICPPMethod) {
|
||||
searchFor = ICSearchConstants.METHOD;
|
||||
} else if (binding instanceof IMacroBinding) {
|
||||
searchFor = ICSearchConstants.MACRO;
|
||||
} else if (binding instanceof ITypedef) {
|
||||
searchFor = ICSearchConstants.TYPEDEF;
|
||||
} else if (binding instanceof IVariable) {
|
||||
searchFor = ICSearchConstants.VAR;
|
||||
} else if (binding instanceof ICPPClassType) {
|
||||
searchFor = ICSearchConstants.CLASS;
|
||||
} else if (binding instanceof ICompositeType) {
|
||||
try {
|
||||
switch(((ICompositeType)binding).getKey()) {
|
||||
case ICompositeType.k_struct:
|
||||
searchFor = ICSearchConstants.CLASS_STRUCT;
|
||||
break;
|
||||
case ICompositeType.k_union:
|
||||
searchFor = ICSearchConstants.UNION;
|
||||
break;
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
searchFor = ICSearchConstants.UNKNOWN_SEARCH_FOR;
|
||||
}
|
||||
} else if (binding instanceof IEnumeration) {
|
||||
searchFor = ICSearchConstants.ENUM;
|
||||
} else {
|
||||
searchFor = ICSearchConstants.UNKNOWN_SEARCH_FOR;
|
||||
}
|
||||
|
||||
return CSearchPattern.createPattern(binding.getName(), searchFor, limitTo, ICSearchConstants.EXACT_MATCH, caseSensitive);
|
||||
}
|
||||
|
||||
private static SearchFor createSearchFor( IBinding binding ) {
|
||||
SearchFor searchFor = null;
|
||||
if (binding instanceof IFunction) {
|
||||
searchFor = ICSearchConstants.FUNCTION;
|
||||
} else if (binding instanceof ICPPNamespace || binding instanceof ICPPNamespaceAlias) {
|
||||
searchFor = ICSearchConstants.NAMESPACE;
|
||||
} else if (binding instanceof ICPPField) {
|
||||
searchFor = ICSearchConstants.FIELD;
|
||||
} else if (binding instanceof IEnumerator) {
|
||||
searchFor = ICSearchConstants.ENUMTOR;
|
||||
} else if (binding instanceof ICPPMethod) {
|
||||
searchFor = ICSearchConstants.METHOD;
|
||||
} else if (binding instanceof IMacroBinding) {
|
||||
searchFor = ICSearchConstants.MACRO;
|
||||
} else if (binding instanceof ITypedef) {
|
||||
searchFor = ICSearchConstants.TYPEDEF;
|
||||
} else if (binding instanceof IVariable) {
|
||||
searchFor = ICSearchConstants.VAR;
|
||||
} else if (binding instanceof ICPPClassType) {
|
||||
searchFor = ICSearchConstants.CLASS;
|
||||
} else if (binding instanceof ICompositeType) {
|
||||
try {
|
||||
switch(((ICompositeType)binding).getKey()) {
|
||||
case ICompositeType.k_struct:
|
||||
searchFor = ICSearchConstants.CLASS_STRUCT;
|
||||
break;
|
||||
case ICompositeType.k_union:
|
||||
searchFor = ICSearchConstants.UNION;
|
||||
break;
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
searchFor = ICSearchConstants.UNKNOWN_SEARCH_FOR;
|
||||
}
|
||||
} else if (binding instanceof IEnumeration) {
|
||||
searchFor = ICSearchConstants.ENUM;
|
||||
} else {
|
||||
searchFor = ICSearchConstants.UNKNOWN_SEARCH_FOR;
|
||||
}
|
||||
return searchFor;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used to get a List of selected names in an IFile based on the offset and length into that IFile.
|
||||
*
|
||||
* ex: IFile contains: int foo;
|
||||
* then getSelectedNamesFrom(file, 4, 3) will return the IASTName corresponding to foo
|
||||
*
|
||||
* @param file the IFile whose selection
|
||||
* @param offset
|
||||
* @param length
|
||||
* @return
|
||||
*/
|
||||
public static IASTName[] getSelectedNamesFrom(IFile file, int offset, int length) {
|
||||
IASTNode node = null;
|
||||
IASTTranslationUnit tu = null;
|
||||
try {
|
||||
tu = CDOM.getInstance().getASTService().getTranslationUnit(
|
||||
file,
|
||||
CDOM.getInstance().getCodeReaderFactory(
|
||||
CDOM.PARSE_WORKING_COPY_WHENEVER_POSSIBLE));
|
||||
} catch (IASTServiceProvider.UnsupportedDialectException e) {
|
||||
return EMPTY_NAME_LIST;
|
||||
}
|
||||
try{
|
||||
node = tu.selectNodeForLocation(file.getRawLocation().toOSString(), offset, length);
|
||||
}
|
||||
catch (ParseError er){}
|
||||
catch ( VirtualMachineError vmErr){
|
||||
if (vmErr instanceof OutOfMemoryError){
|
||||
org.eclipse.cdt.internal.core.model.Util.log(null, "Open Declarations Out Of Memory error: " + vmErr.getMessage() + " on File: " + file.getName(), ICLogConstants.CDT); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
||||
catch (Exception ex){}
|
||||
|
||||
finally{
|
||||
if (node == null){
|
||||
return EMPTY_NAME_LIST;
|
||||
}
|
||||
}
|
||||
|
||||
if (node instanceof IASTName) {
|
||||
IASTName[] results = new IASTName[1];
|
||||
results[0] = (IASTName)node;
|
||||
return results;
|
||||
} else {
|
||||
ASTVisitor collector = null;
|
||||
if (getLanguageFromFile(file) == ParserLanguage.CPP) {
|
||||
collector = new CPPNameCollector();
|
||||
} else {
|
||||
collector = new CNameCollector();
|
||||
}
|
||||
|
||||
node.accept( collector );
|
||||
|
||||
List names = null;
|
||||
if (collector instanceof CPPNameCollector) {
|
||||
names = ((CPPNameCollector)collector).nameList;
|
||||
} else {
|
||||
names = ((CNameCollector)collector).nameList;
|
||||
}
|
||||
|
||||
IASTName[] results = new IASTName[names.size()];
|
||||
for(int i=0; i<names.size(); i++) {
|
||||
if (names.get(i) instanceof IASTName)
|
||||
results[i] = (IASTName)names.get(i);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This retrieves the ParserLanguage from an IFile.
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static ParserLanguage getLanguageFromFile(IFile file) {
|
||||
IProject project = file.getProject();
|
||||
ICFileType type = CCorePlugin.getDefault().getFileType(project, file.getFullPath().lastSegment());
|
||||
String lid = type.getLanguage().getId();
|
||||
if ( lid != null && lid.equals(ICFileTypeConstants.LANG_CXX) ) {
|
||||
return ParserLanguage.CPP;
|
||||
}
|
||||
|
||||
return ParserLanguage.C;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used to get the names from the TU that the IASTName searchName belongs to.
|
||||
*
|
||||
* @param searchName the IASTName whose references/delcarations are to be retrieved
|
||||
* @param limitTo used to specify whether to get declarations, references, or both, one of:
|
||||
* ( CSearchPattern.DECLARATION | CSearchPattern.REFERENCES | CSearchPattern.ALL_OCCURRENCES )
|
||||
* @return IASTName[] declarations, references, or both depending on limitTo that correspond to the IASTName searchName searched for
|
||||
*/
|
||||
public static IASTName[] getNamesFromDOM(IASTName searchName, LimitTo limitTo) {
|
||||
IASTName[] names = null;
|
||||
IASTTranslationUnit tu = searchName.getTranslationUnit();
|
||||
|
||||
if (tu == null) {
|
||||
return BLANK_NAME_ARRAY;
|
||||
}
|
||||
|
||||
if (limitTo == ICSearchConstants.DECLARATIONS) {
|
||||
names = tu.getDeclarations(searchName.resolveBinding());
|
||||
} else if (limitTo == ICSearchConstants.REFERENCES) {
|
||||
names = tu.getReferences(searchName.resolveBinding());
|
||||
} else { // assume ALL
|
||||
names = tu.getDeclarations(searchName.resolveBinding());
|
||||
names = (IASTName[])ArrayUtil.addAll(IASTName.class, names, tu.getReferences(searchName.resolveBinding()));
|
||||
}
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
/**
|
||||
* The CPPNameCollector used to get IASTNames from an IASTNode.
|
||||
*
|
||||
* @author dsteffle
|
||||
*/
|
||||
static public class CPPNameCollector extends CPPASTVisitor {
|
||||
{
|
||||
shouldVisitNames = true;
|
||||
}
|
||||
public List nameList = new ArrayList();
|
||||
public int visit( IASTName name ){
|
||||
nameList.add( name );
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
public IASTName getName( int idx ){
|
||||
if( idx < 0 || idx >= nameList.size() )
|
||||
return null;
|
||||
return (IASTName) nameList.get( idx );
|
||||
}
|
||||
public int size() { return nameList.size(); }
|
||||
}
|
||||
|
||||
/**
|
||||
* The CNameCollector used to get IASTNames from an IASTNode.
|
||||
*
|
||||
* @author dsteffle
|
||||
*/
|
||||
static public class CNameCollector extends CASTVisitor {
|
||||
{
|
||||
shouldVisitNames = true;
|
||||
}
|
||||
public List nameList = new ArrayList();
|
||||
public int visit( IASTName name ){
|
||||
nameList.add( name );
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
public IASTName getName( int idx ){
|
||||
if( idx < 0 || idx >= nameList.size() )
|
||||
return null;
|
||||
return (IASTName) nameList.get( idx );
|
||||
}
|
||||
public int size() { return nameList.size(); }
|
||||
}
|
||||
}
|
|
@ -216,6 +216,10 @@ public class DOMAST extends ViewPart {
|
|||
|
||||
return tu;
|
||||
}
|
||||
|
||||
public ParserLanguage getTULanguage() {
|
||||
return lang;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
}
|
||||
|
@ -1084,7 +1088,7 @@ public class DOMAST extends ViewPart {
|
|||
|
||||
private class DisplaySearchResultAction extends Action {
|
||||
protected void displayNames(IASTName[] names, String queryLabel, String pattern) {
|
||||
DOMQuery job = new DOMQuery(names, queryLabel, pattern);
|
||||
DOMDisplaySearchNames job = new DOMDisplaySearchNames(names, queryLabel, pattern);
|
||||
NewSearchUI.activateSearchResultView();
|
||||
NewSearchUI.runQueryInBackground(job);
|
||||
}
|
||||
|
@ -1094,7 +1098,7 @@ public class DOMAST extends ViewPart {
|
|||
private static final String IASTPROBLEM = "IASTProblem"; //$NON-NLS-1$
|
||||
private static final String PROBLEMS_FOUND = "Problems Found"; //$NON-NLS-1$
|
||||
protected void displayProblems(IASTProblem[] problems, String queryLabel, String pattern) {
|
||||
DOMQuery job = new DOMQuery(problems, queryLabel, pattern);
|
||||
DOMDisplaySearchNames job = new DOMDisplaySearchNames(problems, queryLabel, pattern);
|
||||
NewSearchUI.activateSearchResultView();
|
||||
NewSearchUI.runQueryInBackground(job);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,259 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2005 IBM Canada 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 Rational Software - Initial API and implementation
|
||||
**********************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.DOMAST;
|
||||
|
||||
import org.eclipse.cdt.core.browser.PathUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.IField;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
||||
import org.eclipse.cdt.core.search.IMatch;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchQuery;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchResult;
|
||||
import org.eclipse.cdt.internal.ui.search.NewSearchResultCollector;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
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.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.eclipse.search.ui.ISearchQuery;
|
||||
import org.eclipse.search.ui.ISearchResult;
|
||||
|
||||
/**
|
||||
* This is used for the DOM AST Viewer only... it requires that the names to be displayed
|
||||
* in the search view were already found elsewhere.
|
||||
* @author dsteffle
|
||||
*/
|
||||
public class DOMDisplaySearchNames extends CSearchQuery implements ISearchQuery {
|
||||
|
||||
private static final String BLANK_STRING = ""; //$NON-NLS-1$
|
||||
private CSearchResult _result;
|
||||
private IASTNode[] nodes = null;
|
||||
private String queryLabel = null;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public DOMDisplaySearchNames(IASTNode[] nodes, String queryLabel, String pattern) {
|
||||
super(CUIPlugin.getWorkspace(), pattern, false, null, null, null, queryLabel, null);
|
||||
this.nodes = nodes;
|
||||
this.queryLabel = queryLabel;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.search.ui.ISearchQuery#run(org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
public IStatus run(IProgressMonitor monitor)
|
||||
throws OperationCanceledException {
|
||||
|
||||
final CSearchResult textResult= (CSearchResult) getSearchResult();
|
||||
|
||||
IProgressMonitor mainSearchPM= new SubProgressMonitor(monitor, 1000);
|
||||
NewSearchResultCollector collector = new NewSearchResultCollector(textResult, mainSearchPM);
|
||||
|
||||
collector.aboutToStart();
|
||||
|
||||
for (int i=0; i<nodes.length; i++) {
|
||||
try {
|
||||
String fileName = null;
|
||||
IPath path = null;
|
||||
int start = 0;
|
||||
int end = 0;
|
||||
if ( nodes[i] != null ) {
|
||||
IASTFileLocation location = nodes[i].getTranslationUnit().flattenLocationsToFile( nodes[i].getNodeLocations() );
|
||||
if (location == null) {
|
||||
return new Status(IStatus.ERROR, CUIPlugin.getPluginId(), 0, "Null Location associated with IASTFileLocation.", null); //$NON-NLS-1$
|
||||
}
|
||||
fileName = location.getFileName();
|
||||
start = location.getNodeOffset();
|
||||
end = location.getNodeOffset() + location.getNodeLength();
|
||||
path = new Path(fileName);
|
||||
Object fileResource=null;
|
||||
IResource res = ParserUtil.getResourceForFilename(fileName);
|
||||
if (res != null)
|
||||
fileResource = res;
|
||||
else {
|
||||
fileResource = PathUtil.getWorkspaceRelativePath(fileName);
|
||||
}
|
||||
|
||||
collector.acceptMatch( createMatch(fileResource, start, end, nodes[i], path ) );
|
||||
}
|
||||
} catch (CoreException ce) {}
|
||||
}
|
||||
|
||||
mainSearchPM.done();
|
||||
collector.done();
|
||||
|
||||
return new Status(IStatus.OK, CUIPlugin.getPluginId(), 0, BLANK_STRING, null); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public IMatch createMatch( Object fileResource, int start, int end, IASTNode node, IPath referringElement ) {
|
||||
BasicSearchMatch result = new BasicSearchMatch();
|
||||
|
||||
if( fileResource instanceof IResource )
|
||||
result.resource = (IResource) fileResource;
|
||||
else if( fileResource instanceof IPath )
|
||||
result.path = (IPath) fileResource;
|
||||
|
||||
result.startOffset = start;
|
||||
result.endOffset = end;
|
||||
result.parentName = BLANK_STRING; //$NON-NLS-1$
|
||||
result.referringElement = referringElement;
|
||||
|
||||
if (node instanceof IASTName)
|
||||
result.name = node.toString();
|
||||
else if (node instanceof IASTProblem)
|
||||
result.name = ((IASTProblem)node).getMessage();
|
||||
else
|
||||
result.name = node.toString();
|
||||
|
||||
// set the type and visibility of the match
|
||||
if (node instanceof IASTName) {
|
||||
IBinding binding = ((IASTName)node).resolveBinding();
|
||||
if (binding instanceof ICPPClassType) {
|
||||
result.type = ICElement.C_CLASS;
|
||||
} else if (binding instanceof ICompositeType) {
|
||||
int key=ICompositeType.k_struct;
|
||||
try {
|
||||
key = ((ICompositeType)binding).getKey();
|
||||
} catch (DOMException e) {}
|
||||
switch (key) {
|
||||
case ICompositeType.k_struct:
|
||||
result.type = ICElement.C_STRUCT;
|
||||
break;
|
||||
case ICompositeType.k_union:
|
||||
result.type = ICElement.C_UNION;
|
||||
break;
|
||||
}
|
||||
} else if (binding instanceof ICPPNamespace) {
|
||||
result.type = ICElement.C_NAMESPACE;
|
||||
} else if (binding instanceof IEnumeration) {
|
||||
result.type = ICElement.C_ENUMERATION;
|
||||
} else if (binding instanceof IMacroBinding) {
|
||||
result.type = ICElement.C_MACRO;
|
||||
} else if (binding instanceof IField) {
|
||||
result.type = ICElement.C_FIELD;
|
||||
try {
|
||||
result.setStatic(((IField)binding).isStatic());
|
||||
} catch (DOMException e) {}
|
||||
if (binding instanceof ICPPMember) {
|
||||
try {
|
||||
switch (((ICPPMember)binding).getVisibility()) {
|
||||
case ICPPMember.v_private:
|
||||
result.visibility = ICElement.CPP_PRIVATE;
|
||||
break;
|
||||
case ICPPMember.v_public:
|
||||
result.visibility = ICElement.CPP_PUBLIC;
|
||||
break;
|
||||
// no ICElement.CPP_PROTECTED
|
||||
}
|
||||
} catch (DOMException e) {}
|
||||
}
|
||||
try {
|
||||
result.setConst(ASTTypeUtil.isConst(((IField)binding).getType()));
|
||||
} catch (DOMException e) {}
|
||||
} else if (binding instanceof IVariable) {
|
||||
result.type = ICElement.C_VARIABLE;
|
||||
try {
|
||||
result.setConst(ASTTypeUtil.isConst(((IVariable)binding).getType()));
|
||||
} catch (DOMException e) {}
|
||||
} else if (binding instanceof IEnumerator) {
|
||||
result.type = ICElement.C_ENUMERATOR;
|
||||
} else if (binding instanceof ICPPMethod) {
|
||||
result.type = ICElement.C_METHOD;
|
||||
if (binding instanceof ICPPMember) {
|
||||
try {
|
||||
switch (((ICPPMember)binding).getVisibility()) {
|
||||
case ICPPMember.v_private:
|
||||
result.visibility = ICElement.CPP_PRIVATE;
|
||||
break;
|
||||
case ICPPMember.v_public:
|
||||
result.visibility = ICElement.CPP_PUBLIC;
|
||||
break;
|
||||
// there is no ICElement.CPP_PROTECTED
|
||||
}
|
||||
} catch (DOMException e) {}
|
||||
}
|
||||
try {
|
||||
result.setConst(ASTTypeUtil.isConst(((ICPPMethod)binding).getType()));
|
||||
} catch (DOMException e) {}
|
||||
} else if (binding instanceof IFunction) {
|
||||
result.type = ICElement.C_FUNCTION;
|
||||
try {
|
||||
result.setStatic(((IFunction)binding).isStatic());
|
||||
} catch (DOMException e) {}
|
||||
} else if (binding instanceof ITypedef) {
|
||||
result.type = ICElement.C_TYPEDEF;
|
||||
}
|
||||
} else {
|
||||
result.type = ICElement.C_UNKNOWN_DECLARATION;
|
||||
}
|
||||
|
||||
result.returnType = BLANK_STRING;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.search.ui.ISearchQuery#getLabel()
|
||||
*/
|
||||
public String getLabel() {
|
||||
return queryLabel;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.search.ui.ISearchQuery#canRerun()
|
||||
*/
|
||||
public boolean canRerun() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.search.ui.ISearchQuery#canRunInBackground()
|
||||
*/
|
||||
public boolean canRunInBackground() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.search.ui.ISearchQuery#getSearchResult()
|
||||
*/
|
||||
public ISearchResult getSearchResult() {
|
||||
if (_result == null)
|
||||
_result= new CSearchResult(this);
|
||||
return _result;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,150 +0,0 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2005 IBM Canada 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 Rational Software - Initial API and implementation
|
||||
**********************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.DOMAST;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
||||
import org.eclipse.cdt.core.search.IMatch;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchQuery;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchResult;
|
||||
import org.eclipse.cdt.internal.ui.search.NewSearchResultCollector;
|
||||
import org.eclipse.cdt.ui.testplugin.CTestPlugin;
|
||||
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.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.eclipse.search.ui.ISearchQuery;
|
||||
import org.eclipse.search.ui.ISearchResult;
|
||||
|
||||
/**
|
||||
* @author dsteffle
|
||||
*/
|
||||
public class DOMQuery extends CSearchQuery implements ISearchQuery {
|
||||
|
||||
private static final String BLANK_STRING = ""; //$NON-NLS-1$
|
||||
private CSearchResult _result;
|
||||
private IASTNode[] nodes = null;
|
||||
private String queryLabel = null;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public DOMQuery(IASTNode[] nodes, String queryLabel, String pattern) {
|
||||
super(CTestPlugin.getWorkspace(), pattern, false, null, null, null, queryLabel, null);
|
||||
this.nodes = nodes;
|
||||
this.queryLabel = queryLabel;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.search.ui.ISearchQuery#run(org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
public IStatus run(IProgressMonitor monitor)
|
||||
throws OperationCanceledException {
|
||||
|
||||
final CSearchResult textResult= (CSearchResult) getSearchResult();
|
||||
|
||||
IProgressMonitor mainSearchPM= new SubProgressMonitor(monitor, 1000);
|
||||
NewSearchResultCollector collector = new NewSearchResultCollector(textResult, mainSearchPM);
|
||||
|
||||
collector.aboutToStart();
|
||||
|
||||
for (int i=0; i<nodes.length; i++) {
|
||||
try {
|
||||
String fileName = null;
|
||||
IPath path = null;
|
||||
int start = 0;
|
||||
int end = 0;
|
||||
if ( nodes[i] != null ) {
|
||||
IASTFileLocation location = nodes[i].getTranslationUnit().flattenLocationsToFile( nodes[i].getNodeLocations() );
|
||||
fileName = location.getFileName();
|
||||
path = new Path(fileName);
|
||||
start = location.getNodeOffset();
|
||||
end = location.getNodeOffset() + location.getNodeLength();
|
||||
collector.acceptMatch( createMatch(path, start, end, nodes[i], path ) );
|
||||
}
|
||||
} catch (CoreException ce) {}
|
||||
}
|
||||
|
||||
mainSearchPM.done();
|
||||
collector.done();
|
||||
|
||||
return new Status(IStatus.OK, CTestPlugin.getPluginId(), 0, BLANK_STRING, null); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public IMatch createMatch( Object fileResource, int start, int end, IASTNode node, IPath referringElement ) {
|
||||
BasicSearchMatch result = new BasicSearchMatch();
|
||||
if( fileResource instanceof IResource )
|
||||
result.resource = (IResource) fileResource;
|
||||
else if( fileResource instanceof IPath )
|
||||
result.path = (IPath) fileResource;
|
||||
|
||||
result.startOffset = start;
|
||||
result.endOffset = end;
|
||||
result.parentName = BLANK_STRING; //$NON-NLS-1$
|
||||
result.referringElement = referringElement;
|
||||
|
||||
if (node instanceof IASTName)
|
||||
result.name = node.toString();
|
||||
else if (node instanceof IASTProblem)
|
||||
result.name = ((IASTProblem)node).getMessage();
|
||||
else
|
||||
result.name = node.toString();
|
||||
|
||||
result.type = ICElement.C_FIELD; // TODO Devin static for now, want something like BasicSearchResultCollector#setElementInfo
|
||||
result.visibility = ICElement.CPP_PUBLIC; // TODO Devin static for now, want something like BasicSearchResultCollector#setElementInfo
|
||||
result.returnType = BLANK_STRING;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.search.ui.ISearchQuery#getLabel()
|
||||
*/
|
||||
public String getLabel() {
|
||||
return queryLabel;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.search.ui.ISearchQuery#canRerun()
|
||||
*/
|
||||
public boolean canRerun() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.search.ui.ISearchQuery#canRunInBackground()
|
||||
*/
|
||||
public boolean canRunInBackground() {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.search.ui.ISearchQuery#getSearchResult()
|
||||
*/
|
||||
public ISearchResult getSearchResult() {
|
||||
if (_result == null)
|
||||
_result= new CSearchResult(this);
|
||||
return _result;
|
||||
}
|
||||
|
||||
}
|
|
@ -68,7 +68,7 @@ public class ShowInDOMViewAction extends ActionDelegate implements
|
|||
}
|
||||
}
|
||||
|
||||
private void showMessage(String message) {
|
||||
protected void showMessage(String message) {
|
||||
MessageDialog.openInformation(CTestPlugin.getStandardDisplay().getActiveShell(), DOMAST.VIEW_NAME, message);
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,8 @@ public class StubUtility {
|
|||
* Examines a string and returns the first line delimiter found.
|
||||
*/
|
||||
public static String getLineDelimiterUsed(ICElement elem) throws CModelException {
|
||||
if (elem == null) return ""; //$NON-NLS-1$
|
||||
|
||||
ITranslationUnit cu= (ITranslationUnit) elem.getAncestor(ICElement.C_UNIT);
|
||||
if (cu != null && cu.exists()) {
|
||||
IBuffer buf= cu.getBuffer();
|
||||
|
|
|
@ -87,7 +87,9 @@ CSearchOperation.pluralOccurrencesPostfix={0} - {1} Occurrences in {2}
|
|||
CSearchResultLabelProvider.potentialMatch= \ (inexact)
|
||||
|
||||
CSearchOperation.operationUnavailable.title= Operation Unavailable
|
||||
CSearchOperation.operationUnavailable.message= The operation is unavailable on the current selection.
|
||||
CSearchOperation.operationUnavailable.message= The operation is unavailable on the current selection.
|
||||
CSearchOperation.tooManyNames.message= The operation is unavailable on the current selection (too many different names selected).
|
||||
CSearchOperation.noNamesSelected.message= The operation is unavailable on the current selection (no name selected).
|
||||
|
||||
|
||||
WorkspaceScope= Workspace
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 IBM Corporation and others.
|
||||
* Copyright (c) 2004,2005 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
|
||||
|
@ -10,16 +10,15 @@
|
|||
******************************************************************************/
|
||||
/*
|
||||
* Created on Mar 26, 2004
|
||||
*
|
||||
* To change the template for this generated file go to
|
||||
* Window - Preferences - Java - Code Generation - Code and Comments
|
||||
*/
|
||||
package org.eclipse.cdt.internal.ui.search;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.search.ICSearchConstants;
|
||||
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.core.search.OrPattern;
|
||||
import org.eclipse.cdt.core.search.SearchEngine;
|
||||
|
@ -35,37 +34,34 @@ import org.eclipse.search.ui.ISearchQuery;
|
|||
import org.eclipse.search.ui.ISearchResult;
|
||||
/**
|
||||
* @author bog
|
||||
*
|
||||
* To change the template for this generated type comment go to
|
||||
* Window - Preferences - Java - Code Generation - Code and Comments
|
||||
*/
|
||||
public class CSearchQuery implements ISearchQuery, ICSearchConstants {
|
||||
|
||||
private CSearchResultCollector _collector;
|
||||
private IWorkspace _workspace;
|
||||
private ICSearchScope _scope;
|
||||
private String _stringPattern;
|
||||
private String _scopeDescription;
|
||||
private boolean _caseSensitive;
|
||||
private LimitTo _limitTo;
|
||||
private List _searchFor;
|
||||
private CSearchResult _result;
|
||||
private ICSearchResultCollector _collector;
|
||||
private IWorkspace _workspace;
|
||||
private ICSearchScope _scope;
|
||||
private String _stringPattern;
|
||||
private String _scopeDescription;
|
||||
private boolean _caseSensitive;
|
||||
private LimitTo _limitTo;
|
||||
private List _searchFor;
|
||||
private CSearchResult _result;
|
||||
|
||||
public CSearchQuery(IWorkspace workspace, String pattern, boolean caseSensitive, List searchFor, LimitTo limitTo, ICSearchScope scope, String scopeDescription, CSearchResultCollector collector) {
|
||||
public CSearchQuery(IWorkspace workspace, String pattern, boolean caseSensitive, List searchFor, LimitTo limitTo, ICSearchScope scope, String scopeDescription, ICSearchResultCollector collector) {
|
||||
this( workspace, limitTo, scope, scopeDescription, collector );
|
||||
_stringPattern = pattern;
|
||||
_caseSensitive = caseSensitive;
|
||||
_searchFor = searchFor;
|
||||
}
|
||||
|
||||
public CSearchQuery(IWorkspace workspace, LimitTo limitTo, ICSearchScope scope, String scopeDescription, CSearchResultCollector collector ){
|
||||
public CSearchQuery(IWorkspace workspace, LimitTo limitTo, ICSearchScope scope, String scopeDescription, ICSearchResultCollector collector ){
|
||||
_workspace = workspace;
|
||||
_limitTo = limitTo;
|
||||
_scope = scope;
|
||||
_scopeDescription = scopeDescription;
|
||||
_collector = collector;
|
||||
if (_collector != null)
|
||||
_collector.setOperation( this );
|
||||
if (_collector instanceof CSearchResultCollector)
|
||||
((CSearchResultCollector)_collector).setOperation( this );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -133,8 +129,6 @@ public class CSearchQuery implements ISearchQuery, ICSearchConstants {
|
|||
textResult.removeAll();
|
||||
|
||||
SearchEngine engine = new SearchEngine( CUIPlugin.getSharedWorkingCopies() );
|
||||
int matchCount= 0;
|
||||
|
||||
|
||||
int totalTicks= 1000;
|
||||
|
||||
|
@ -165,7 +159,6 @@ public class CSearchQuery implements ISearchQuery, ICSearchConstants {
|
|||
}
|
||||
}
|
||||
monitor.done();
|
||||
matchCount = finalCollector.getMatchCount();
|
||||
|
||||
return new Status(IStatus.OK, CUIPlugin.getPluginId(), 0,"", null); //$NON-NLS-1$
|
||||
}
|
||||
|
@ -214,6 +207,5 @@ public class CSearchQuery implements ISearchQuery, ICSearchConstants {
|
|||
_result= new CSearchResult(this);
|
||||
return _result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,284 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2005 IBM Canada 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 Rational Software - Initial API and implementation
|
||||
**********************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.search;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.browser.PathUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.IField;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||
import org.eclipse.cdt.core.search.BasicSearchMatch;
|
||||
import org.eclipse.cdt.core.search.DOMSearchUtil;
|
||||
import org.eclipse.cdt.core.search.ICSearchResultCollector;
|
||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||
import org.eclipse.cdt.core.search.IMatch;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchQuery;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchResult;
|
||||
import org.eclipse.cdt.internal.ui.search.NewSearchResultCollector;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
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.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.eclipse.search.ui.ISearchQuery;
|
||||
import org.eclipse.search.ui.ISearchResult;
|
||||
|
||||
/**
|
||||
* This is used to search the DOM for IASTNames and populate the Search View with the results.
|
||||
*
|
||||
* @author dsteffle
|
||||
*/
|
||||
public class DOMQuery extends CSearchQuery implements ISearchQuery {
|
||||
private static final String BLANK_STRING = ""; //$NON-NLS-1$
|
||||
|
||||
private CSearchResult _result;
|
||||
|
||||
// attributes required for the search
|
||||
private IASTName searchName=null;
|
||||
private LimitTo limitTo=null;
|
||||
private ICSearchScope scope=null;
|
||||
|
||||
public DOMQuery(String displaySearchPattern, IASTName name, LimitTo limitTo, ICSearchScope scope, ICSearchResultCollector collector) {
|
||||
super(CUIPlugin.getWorkspace(), displaySearchPattern, false, null, null, null, displaySearchPattern, collector);
|
||||
this.searchName = name;
|
||||
this.limitTo = limitTo;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.search.ui.ISearchQuery#run(org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
public IStatus run(IProgressMonitor monitor)
|
||||
throws OperationCanceledException {
|
||||
final CSearchResult textResult= (CSearchResult) getSearchResult();
|
||||
IProgressMonitor mainSearchPM= new SubProgressMonitor(monitor, 1000);
|
||||
NewSearchResultCollector collector = new NewSearchResultCollector(textResult, mainSearchPM);
|
||||
collector.aboutToStart();
|
||||
|
||||
Set matches = DOMSearchUtil.getMatchesFromSearchEngine(scope, searchName, limitTo);
|
||||
if (matches != null && matches.size() > 0) {
|
||||
Iterator itr = matches.iterator();
|
||||
while(itr.hasNext()) {
|
||||
Object next = itr.next();
|
||||
if (next instanceof IMatch) {
|
||||
try {
|
||||
collector.acceptMatch((IMatch)next);
|
||||
} catch (CoreException e) {
|
||||
// don't do anything if the match wasn't accepted
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { // only search against the DOM if the index failed to get results... i.e. don't want duplicates
|
||||
IASTName[] foundNames = DOMSearchUtil.getNamesFromDOM(searchName, limitTo);
|
||||
|
||||
for (int i=0; i<foundNames.length; i++) {
|
||||
try {
|
||||
String fileName = null;
|
||||
IPath path = null;
|
||||
int start = 0;
|
||||
int end = 0;
|
||||
|
||||
if ( foundNames[i].getTranslationUnit() != null ) {
|
||||
IASTFileLocation location = foundNames[i].getTranslationUnit().flattenLocationsToFile( foundNames[i].getNodeLocations() );
|
||||
fileName = location.getFileName();
|
||||
start = location.getNodeOffset();
|
||||
end = location.getNodeOffset() + location.getNodeLength();
|
||||
}
|
||||
|
||||
path = new Path(fileName);
|
||||
Object fileResource=null;
|
||||
IResource res = ParserUtil.getResourceForFilename(fileName);
|
||||
if (res != null)
|
||||
fileResource = res;
|
||||
else {
|
||||
fileResource = PathUtil.getWorkspaceRelativePath(fileName);
|
||||
}
|
||||
|
||||
collector.acceptMatch( createMatch(fileResource, start, end, foundNames[i], path ) );
|
||||
|
||||
} catch (CoreException ce) {}
|
||||
}
|
||||
}
|
||||
|
||||
mainSearchPM.done();
|
||||
collector.done();
|
||||
|
||||
return new Status(IStatus.OK, CUIPlugin.getPluginId(), 0, BLANK_STRING, null); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/**
|
||||
* This method creates an IMatch corresponding to an IASTNode found at a specific
|
||||
* fileResource (an IResource if external or an IPath if internal), the start/end offsets
|
||||
* of the IASTNode, as well as the referringElement where it is found.
|
||||
*
|
||||
* @param fileResource
|
||||
* @param start
|
||||
* @param end
|
||||
* @param node
|
||||
* @param referringElement
|
||||
* @return
|
||||
*/
|
||||
public IMatch createMatch( Object fileResource, int start, int end, IASTNode node, IPath referringElement ) {
|
||||
BasicSearchMatch result = new BasicSearchMatch();
|
||||
|
||||
if( fileResource instanceof IResource )
|
||||
result.resource = (IResource) fileResource;
|
||||
else if( fileResource instanceof IPath )
|
||||
result.path = (IPath) fileResource;
|
||||
|
||||
result.startOffset = start;
|
||||
result.endOffset = end;
|
||||
result.parentName = BLANK_STRING; //$NON-NLS-1$
|
||||
result.referringElement = referringElement;
|
||||
|
||||
if (node instanceof IASTName)
|
||||
result.name = node.toString();
|
||||
else if (node instanceof IASTProblem)
|
||||
result.name = ((IASTProblem)node).getMessage();
|
||||
else
|
||||
result.name = node.toString();
|
||||
|
||||
// set the type and visibility of the match
|
||||
if (node instanceof IASTName) {
|
||||
IBinding binding = ((IASTName)node).resolveBinding();
|
||||
if (binding instanceof ICPPClassType) {
|
||||
result.type = ICElement.C_CLASS;
|
||||
} else if (binding instanceof ICompositeType) {
|
||||
int key=ICompositeType.k_struct;
|
||||
try {
|
||||
key = ((ICompositeType)binding).getKey();
|
||||
} catch (DOMException e) {}
|
||||
switch (key) {
|
||||
case ICompositeType.k_struct:
|
||||
result.type = ICElement.C_STRUCT;
|
||||
break;
|
||||
case ICompositeType.k_union:
|
||||
result.type = ICElement.C_UNION;
|
||||
break;
|
||||
}
|
||||
} else if (binding instanceof ICPPNamespace) {
|
||||
result.type = ICElement.C_NAMESPACE;
|
||||
} else if (binding instanceof IEnumeration) {
|
||||
result.type = ICElement.C_ENUMERATION;
|
||||
} else if (binding instanceof IMacroBinding) {
|
||||
result.type = ICElement.C_MACRO;
|
||||
} else if (binding instanceof IField) {
|
||||
result.type = ICElement.C_FIELD;
|
||||
try {
|
||||
result.setStatic(((IField)binding).isStatic());
|
||||
} catch (DOMException e) {}
|
||||
if (binding instanceof ICPPMember) {
|
||||
try {
|
||||
switch (((ICPPMember)binding).getVisibility()) {
|
||||
case ICPPMember.v_private:
|
||||
result.visibility = ICElement.CPP_PRIVATE;
|
||||
break;
|
||||
case ICPPMember.v_public:
|
||||
result.visibility = ICElement.CPP_PUBLIC;
|
||||
break;
|
||||
// no ICElement.CPP_PROTECTED
|
||||
}
|
||||
} catch (DOMException e) {}
|
||||
}
|
||||
try {
|
||||
result.setConst(ASTTypeUtil.isConst(((IField)binding).getType()));
|
||||
} catch (DOMException e) {}
|
||||
} else if (binding instanceof IVariable) {
|
||||
result.type = ICElement.C_VARIABLE;
|
||||
try {
|
||||
result.setConst(ASTTypeUtil.isConst(((IVariable)binding).getType()));
|
||||
} catch (DOMException e) {}
|
||||
} else if (binding instanceof IEnumerator) {
|
||||
result.type = ICElement.C_ENUMERATOR;
|
||||
} else if (binding instanceof ICPPMethod) {
|
||||
result.type = ICElement.C_METHOD;
|
||||
if (binding instanceof ICPPMember) {
|
||||
try {
|
||||
switch (((ICPPMember)binding).getVisibility()) {
|
||||
case ICPPMember.v_private:
|
||||
result.visibility = ICElement.CPP_PRIVATE;
|
||||
break;
|
||||
case ICPPMember.v_public:
|
||||
result.visibility = ICElement.CPP_PUBLIC;
|
||||
break;
|
||||
// there is no ICElement.CPP_PROTECTED
|
||||
}
|
||||
} catch (DOMException e) {}
|
||||
}
|
||||
try {
|
||||
result.setConst(ASTTypeUtil.isConst(((ICPPMethod)binding).getType()));
|
||||
} catch (DOMException e) {}
|
||||
} else if (binding instanceof IFunction) {
|
||||
result.type = ICElement.C_FUNCTION;
|
||||
try {
|
||||
result.setStatic(((IFunction)binding).isStatic());
|
||||
} catch (DOMException e) {}
|
||||
} else if (binding instanceof ITypedef) {
|
||||
result.type = ICElement.C_TYPEDEF;
|
||||
}
|
||||
} else {
|
||||
result.type = ICElement.C_UNKNOWN_DECLARATION;
|
||||
}
|
||||
|
||||
result.returnType = BLANK_STRING;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.search.ui.ISearchQuery#canRerun()
|
||||
*/
|
||||
public boolean canRerun() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.search.ui.ISearchQuery#canRunInBackground()
|
||||
*/
|
||||
public boolean canRunInBackground() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.search.ui.ISearchQuery#getSearchResult()
|
||||
*/
|
||||
public ISearchResult getSearchResult() {
|
||||
if (_result == null)
|
||||
_result= new CSearchResult(this);
|
||||
return _result;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 IBM Corporation and others.
|
||||
* Copyright (c) 2004,2005 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
|
||||
|
@ -11,27 +11,45 @@
|
|||
|
||||
package org.eclipse.cdt.internal.ui.search.actions;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.ICLogConstants;
|
||||
import org.eclipse.cdt.core.dom.CDOM;
|
||||
import org.eclipse.cdt.core.dom.IASTServiceProvider;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunctionType;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.parser.IParser;
|
||||
import org.eclipse.cdt.core.parser.ParseError;
|
||||
import org.eclipse.cdt.core.parser.ast.ASTUtil;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTQualifiedNameElement;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.search.DOMSearchUtil;
|
||||
import org.eclipse.cdt.core.search.ICSearchResultCollector;
|
||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||
import org.eclipse.cdt.core.search.ICSearchConstants.LimitTo;
|
||||
import org.eclipse.cdt.core.search.ICSearchConstants.SearchFor;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTQualifiedName;
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchQuery;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchResultCollector;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchUtil;
|
||||
import org.eclipse.cdt.internal.ui.search.DOMQuery;
|
||||
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
||||
import org.eclipse.jface.operation.IRunnableWithProgress;
|
||||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
|
@ -48,6 +66,99 @@ public abstract class FindAction extends SelectionParseAction {
|
|||
super( site );
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used to create a DOMSearchQuery based on an IASTName, LimitTo, ICSearchScope and an ICSearchCollector if
|
||||
* one should be used.
|
||||
*
|
||||
* This is a convenience method to setup the title of the DOMSearchQuery as the rest of the parameters are passed directly
|
||||
* to the DOMSearchQuery constructor:
|
||||
*
|
||||
* return new DOMQuery(buffer.toString(), name, limitTo, scope, collector);
|
||||
*
|
||||
* @param name
|
||||
* @param limitTo
|
||||
* @param scope
|
||||
* @param collector
|
||||
* @return
|
||||
*/
|
||||
public static CSearchQuery createDOMSearchQueryForName( IASTName name, LimitTo limitTo, ICSearchScope scope, ICSearchResultCollector collector ){
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("::"); //$NON-NLS-1$
|
||||
if (name instanceof CPPASTName && name.getParent() instanceof CPPASTQualifiedName) {
|
||||
IASTName[] names = ((CPPASTQualifiedName)name.getParent()).getNames();
|
||||
for(int i=0; i<names.length; i++) {
|
||||
if (i != 0) buffer.append("::"); //$NON-NLS-1$
|
||||
buffer.append(names[i].toString());
|
||||
}
|
||||
} else {
|
||||
buffer.append(name.toString());
|
||||
}
|
||||
|
||||
if( name.resolveBinding() instanceof IFunction ){
|
||||
try {
|
||||
IBinding binding = name.resolveBinding();
|
||||
IFunctionType type = ((IFunction)binding).getType();
|
||||
|
||||
buffer.append("("); //$NON-NLS-1$
|
||||
if (binding instanceof ICExternalBinding) {
|
||||
buffer.append("..."); //$NON-NLS-1$
|
||||
} else {
|
||||
IType[] parms = type.getParameterTypes();
|
||||
for( int i = 0; i < parms.length; i++ ){
|
||||
if( i != 0 )
|
||||
buffer.append(", "); //$NON-NLS-1$
|
||||
buffer.append(ASTTypeUtil.getType(parms[i]));
|
||||
}
|
||||
}
|
||||
buffer.append(")"); //$NON-NLS-1$
|
||||
} catch (DOMException e) {
|
||||
buffer = new StringBuffer();
|
||||
buffer.append(name.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return new DOMQuery(buffer.toString(), name, limitTo, scope, collector);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a convenience method and is the same as invoking:
|
||||
* createDOMSearchQueryForName( name, limitTo, scope, null );
|
||||
*
|
||||
* @param name
|
||||
* @param limitTo
|
||||
* @param scope
|
||||
* @return
|
||||
*/
|
||||
public static CSearchQuery createSearchQueryForName( IASTName name, LimitTo limitTo, ICSearchScope scope ){
|
||||
return createDOMSearchQueryForName( name, limitTo, scope, null );
|
||||
}
|
||||
|
||||
public void run() {
|
||||
ISelection sel = getSelection();
|
||||
|
||||
if (sel instanceof IStructuredSelection) {
|
||||
run((IStructuredSelection) sel);
|
||||
} else if (sel instanceof ITextSelection) {
|
||||
run((ITextSelection) sel);
|
||||
}
|
||||
}
|
||||
|
||||
public void run(IStructuredSelection sel){
|
||||
Object obj = sel.getFirstElement();
|
||||
if( obj == null || !(obj instanceof ICElement ) ){
|
||||
operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
|
||||
return;
|
||||
} else {
|
||||
clearStatusLine();
|
||||
}
|
||||
ICElement element = (ICElement) obj;
|
||||
|
||||
CSearchQuery job = createSearchQuery( element.getElementName(), CSearchUtil.getSearchForFromElement(element));
|
||||
NewSearchUI.activateSearchResultView();
|
||||
|
||||
NewSearchUI.runQueryInBackground(job);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param node
|
||||
*/
|
||||
|
@ -71,81 +182,50 @@ public abstract class FindAction extends SelectionParseAction {
|
|||
op = new CSearchQuery(CCorePlugin.getWorkspace(), pattern,true,search,limitTo,scope,scopeDescription,collector);
|
||||
return op;
|
||||
|
||||
}
|
||||
|
||||
protected CSearchQuery createSearchQuery( IASTOffsetableNamedElement node ){
|
||||
String pattern = null;
|
||||
|
||||
if( node instanceof IASTQualifiedNameElement ){
|
||||
String [] qualNames = ((IASTQualifiedNameElement)node).getFullyQualifiedName();
|
||||
pattern = "::" + qualNames[0]; //$NON-NLS-1$
|
||||
for( int i = 1; i < qualNames.length; i++ ){
|
||||
pattern += "::"; //$NON-NLS-1$
|
||||
pattern += qualNames[i];
|
||||
}
|
||||
} else {
|
||||
pattern = node.getName();
|
||||
}
|
||||
|
||||
if( node instanceof IASTFunction ){
|
||||
pattern += '(';
|
||||
String[] parameterTypes = ASTUtil.getFunctionParameterTypes((IASTFunction) node);
|
||||
for( int i = 0; i < parameterTypes.length; i++ ){
|
||||
if( i != 0 )
|
||||
pattern += ", "; //$NON-NLS-1$
|
||||
pattern += parameterTypes[i];
|
||||
}
|
||||
pattern += ')';
|
||||
}
|
||||
|
||||
return createSearchQuery( pattern, CSearchUtil.getSearchForFromNode(node) );
|
||||
}
|
||||
|
||||
public void run() {
|
||||
ISelection sel = getSelection();
|
||||
|
||||
if (sel instanceof IStructuredSelection) {
|
||||
run((IStructuredSelection) sel);
|
||||
} else if (sel instanceof ITextSelection) {
|
||||
run((ITextSelection) sel);
|
||||
}
|
||||
}
|
||||
|
||||
public void run(IStructuredSelection sel){
|
||||
Object obj = sel.getFirstElement();
|
||||
if( obj == null || !(obj instanceof ICElement ) ){
|
||||
operationNotAvailable();
|
||||
return;
|
||||
} else {
|
||||
clearStatusLine();
|
||||
}
|
||||
ICElement element = (ICElement) obj;
|
||||
|
||||
CSearchQuery job = createSearchQuery( element.getElementName(), CSearchUtil.getSearchForFromElement(element));
|
||||
NewSearchUI.activateSearchResultView();
|
||||
|
||||
NewSearchUI.runQueryInBackground(job);
|
||||
}
|
||||
|
||||
public void run(ITextSelection sel){
|
||||
if(sel == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
SelSearchNode selNode = getSelection( sel );
|
||||
|
||||
int selectionStart = selNode.selStart;
|
||||
int selectionEnd = selNode.selEnd;
|
||||
|
||||
IFile resourceFile = fEditor.getInputFile();
|
||||
IParser parser = setupParser(resourceFile);
|
||||
IASTOffsetableNamedElement node = null;
|
||||
IParser.ISelectionParseResult result = null;
|
||||
if(sel == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
SelSearchNode selNode = getSelection( sel );
|
||||
|
||||
IFile resourceFile = null;
|
||||
if (fEditor.getEditorInput() instanceof ExternalEditorInput) {
|
||||
// TODO Devin should be able to implement this somehow, see PR 78118
|
||||
operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
|
||||
return;
|
||||
} else {
|
||||
resourceFile = fEditor.getInputFile();
|
||||
}
|
||||
|
||||
IASTTranslationUnit tu = null;
|
||||
IASTNode foundNode = null;
|
||||
|
||||
ParseWithProgress runnable = new ParseWithProgress(resourceFile);
|
||||
ProgressMonitorDialog progressMonitor = new ProgressMonitorDialog(fEditor.getSite().getShell());
|
||||
try {
|
||||
progressMonitor.run(true, true, runnable);
|
||||
tu = runnable.getTu();
|
||||
} catch (InvocationTargetException e1) {
|
||||
operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
|
||||
return;
|
||||
} catch (InterruptedException e1) {
|
||||
operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
String file=null;
|
||||
if( resourceFile != null )
|
||||
file = resourceFile.getLocation().toOSString();
|
||||
else
|
||||
{
|
||||
if( resourceFile instanceof ExternalEditorInput )
|
||||
file = ((ExternalEditorInput)resourceFile).getStorage().getFullPath().toOSString();
|
||||
}
|
||||
try{
|
||||
result = parser.parse(selectionStart,selectionEnd);
|
||||
if( result != null )
|
||||
node = result.getOffsetableNamedElement();
|
||||
foundNode = tu.selectNodeForLocation(file, selNode.selStart, selNode.selEnd - selNode.selStart);
|
||||
}
|
||||
catch (ParseError er){}
|
||||
catch (Exception ex){}
|
||||
|
@ -155,14 +235,49 @@ public abstract class FindAction extends SelectionParseAction {
|
|||
}
|
||||
}
|
||||
|
||||
if (node == null || !( node instanceof IASTNode )){
|
||||
operationNotAvailable();
|
||||
return;
|
||||
IASTName foundName = null;
|
||||
if (foundNode instanceof IASTName) {
|
||||
foundName = (IASTName)foundNode;
|
||||
} else {
|
||||
clearStatusLine();
|
||||
ASTVisitor collector = null;
|
||||
if (DOMSearchUtil.getLanguageFromFile(resourceFile) == ParserLanguage.CPP) {
|
||||
collector = new DOMSearchUtil.CPPNameCollector();
|
||||
} else {
|
||||
collector = new DOMSearchUtil.CNameCollector();
|
||||
}
|
||||
|
||||
if (foundNode == null) { // nothing found
|
||||
operationNotAvailable(CSEARCH_OPERATION_NO_NAMES_SELECTED_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
foundNode.accept( collector );
|
||||
|
||||
List names = null;
|
||||
if (collector instanceof DOMSearchUtil.CPPNameCollector) {
|
||||
names = ((DOMSearchUtil.CPPNameCollector)collector).nameList;
|
||||
} else {
|
||||
names = ((DOMSearchUtil.CNameCollector)collector).nameList;
|
||||
}
|
||||
|
||||
if (names.size() == 1) { // just right
|
||||
clearStatusLine();
|
||||
} else if (names.size() == 0) { // no names selected
|
||||
operationNotAvailable(CSEARCH_OPERATION_NO_NAMES_SELECTED_MESSAGE);
|
||||
return;
|
||||
} else if (names.size() > 1) { // too many names selected
|
||||
operationNotAvailable(CSEARCH_OPERATION_TOO_MANY_NAMES_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
foundName = (IASTName)names.get(0);
|
||||
}
|
||||
|
||||
CSearchQuery job = createSearchQuery(node);
|
||||
|
||||
LimitTo limitTo = getLimitTo();
|
||||
ICSearchScope searchScope = null;
|
||||
searchScope = getScope();
|
||||
|
||||
CSearchQuery job = FindAction.createSearchQueryForName(foundName, limitTo, searchScope);
|
||||
|
||||
if (job == null)
|
||||
return;
|
||||
|
@ -171,10 +286,37 @@ public abstract class FindAction extends SelectionParseAction {
|
|||
|
||||
NewSearchUI.runQueryInBackground(job);
|
||||
}
|
||||
|
||||
private class ParseWithProgress implements IRunnableWithProgress
|
||||
{
|
||||
private IFile file=null;
|
||||
private IASTTranslationUnit tu = null;
|
||||
|
||||
public ParseWithProgress(IFile file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public void run(IProgressMonitor monitor) {
|
||||
try {
|
||||
tu = CDOM.getInstance().getASTService().getTranslationUnit(
|
||||
file,
|
||||
CDOM.getInstance().getCodeReaderFactory(
|
||||
CDOM.PARSE_WORKING_COPY_WHENEVER_POSSIBLE));
|
||||
} catch (IASTServiceProvider.UnsupportedDialectException e) {
|
||||
operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public IASTTranslationUnit getTu() {
|
||||
return tu;
|
||||
}
|
||||
};
|
||||
|
||||
abstract protected String getScopeDescription();
|
||||
abstract protected String getScopeDescription();
|
||||
|
||||
abstract protected ICSearchScope getScope();
|
||||
|
||||
abstract protected LimitTo getLimitTo();
|
||||
|
||||
}
|
||||
|
|
|
@ -11,12 +11,15 @@
|
|||
|
||||
package org.eclipse.cdt.internal.ui.search.actions;
|
||||
|
||||
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.ICSearchConstants.LimitTo;
|
||||
import org.eclipse.cdt.internal.core.model.CProject;
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchMessages;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.ui.IWorkbenchSite;
|
||||
|
||||
|
||||
|
@ -51,10 +54,10 @@ public class FindDeclarationsAction extends FindAction {
|
|||
setToolTipText(tooltip);
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.ui.editor.selsearch.FindAction#getScope()
|
||||
* @see org.eclipse.cdt.internal.ui.editor.selsearch.FindAction#getScope(org.eclipse.core.resources.IProject)
|
||||
*/
|
||||
protected ICSearchScope getScope() {
|
||||
return SearchEngine.createWorkspaceScope();
|
||||
return SearchEngine.createWorkspaceScope();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.ui.editor.selsearch.FindAction#getScopeDescription()
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.eclipse.cdt.internal.ui.editor.CEditor;
|
|||
import org.eclipse.cdt.internal.ui.search.CSearchMessages;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchScopeFactory;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchUtil;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.ui.IWorkbenchSite;
|
||||
import org.eclipse.ui.IWorkingSet;
|
||||
|
||||
|
@ -71,7 +72,7 @@ public class FindDeclarationsInWorkingSetAction extends FindAction {
|
|||
return scopeDescription;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.ui.editor.selsearch.FindAction#getScope()
|
||||
* @see org.eclipse.cdt.internal.ui.editor.selsearch.FindAction#getScope(org.eclipse.core.resources.IProject)
|
||||
*/
|
||||
protected ICSearchScope getScope() {
|
||||
IWorkingSet[] workingSets= null;
|
||||
|
|
|
@ -10,12 +10,15 @@
|
|||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.search.actions;
|
||||
|
||||
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.ICSearchConstants.LimitTo;
|
||||
import org.eclipse.cdt.internal.core.model.CProject;
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchMessages;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.ui.IWorkbenchSite;
|
||||
|
||||
|
||||
|
@ -64,11 +67,11 @@ public class FindRefsAction extends FindAction {
|
|||
return CSearchMessages.getString("WorkspaceScope"); //$NON-NLS-1$
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.ui.editor.selsearch.FindAction#getScope()
|
||||
* @see org.eclipse.cdt.internal.ui.editor.selsearch.FindAction#getScope(org.eclipse.core.resources.IProject)
|
||||
*/
|
||||
protected ICSearchScope getScope() {
|
||||
return SearchEngine.createWorkspaceScope();
|
||||
}
|
||||
protected ICSearchScope getScope() {
|
||||
return SearchEngine.createWorkspaceScope();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.ui.editor.selsearch.FindAction#getLimitTo()
|
||||
*/
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.eclipse.cdt.internal.ui.editor.CEditor;
|
|||
import org.eclipse.cdt.internal.ui.search.CSearchMessages;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchScopeFactory;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchUtil;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.ui.IWorkbenchSite;
|
||||
import org.eclipse.ui.IWorkingSet;
|
||||
|
||||
|
@ -77,7 +78,7 @@ public class FindRefsInWorkingSetAction extends FindAction {
|
|||
return scopeDescription;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.ui.editor.selsearch.FindAction#getScope()
|
||||
* @see org.eclipse.cdt.internal.ui.editor.selsearch.FindAction#getScope(org.eclipse.core.resources.IProject)
|
||||
*/
|
||||
protected ICSearchScope getScope() {
|
||||
IWorkingSet[] workingSets= null;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2004 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2005 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -11,33 +11,28 @@
|
|||
|
||||
package org.eclipse.cdt.internal.ui.search.actions;
|
||||
|
||||
import org.eclipse.cdt.core.ICLogConstants;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.parser.IParser;
|
||||
import org.eclipse.cdt.core.parser.ParseError;
|
||||
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTField;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTFunction;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTMethod;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTOffsetableNamedElement;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
||||
import org.eclipse.cdt.core.resources.FileStorage;
|
||||
import org.eclipse.cdt.core.search.DOMSearchUtil;
|
||||
import org.eclipse.cdt.core.search.ICSearchConstants;
|
||||
import org.eclipse.cdt.core.search.IMatch;
|
||||
import org.eclipse.cdt.core.search.SearchEngine;
|
||||
import org.eclipse.cdt.core.search.ICSearchConstants.SearchFor;
|
||||
import org.eclipse.cdt.internal.core.model.CProject;
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditorMessages;
|
||||
import org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput;
|
||||
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
||||
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
|
@ -53,12 +48,12 @@ import org.eclipse.jface.viewers.ISelection;
|
|||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.texteditor.AbstractTextEditor;
|
||||
import org.eclipse.ui.texteditor.IUpdate;
|
||||
|
||||
|
||||
public class OpenDeclarationsAction extends SelectionParseAction implements IUpdate {
|
||||
|
||||
//private String fDialogTitle;
|
||||
public static final IASTName[] BLANK_NAME_ARRAY = new IASTName[0];
|
||||
//private String fDialogTitle;
|
||||
//private String fDialogMessage;
|
||||
SearchEngine searchEngine = null;
|
||||
|
||||
|
@ -94,44 +89,38 @@ public class OpenDeclarationsAction extends SelectionParseAction implements IUpd
|
|||
String projectName = ""; //$NON-NLS-1$
|
||||
private static class Storage
|
||||
{
|
||||
private IASTOffsetableNamedElement element;
|
||||
private IResource resource;
|
||||
private String fileName;
|
||||
private int offset=0;
|
||||
private int length=0;
|
||||
|
||||
public IASTOffsetableNamedElement getNamedElement()
|
||||
{
|
||||
return element;
|
||||
}
|
||||
/**
|
||||
* @return Returns the fileName.
|
||||
*/
|
||||
public final String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
/**
|
||||
* @param fileName The fileName to set.
|
||||
*/
|
||||
public final void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
public Storage() {
|
||||
}
|
||||
/**
|
||||
* @return Returns the resource.
|
||||
*/
|
||||
public final IResource getResource() {
|
||||
return resource;
|
||||
}
|
||||
/**
|
||||
* @param resource The resource to set.
|
||||
*/
|
||||
public final void setResource(IResource resource) {
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
public int getOffset() {
|
||||
return offset;
|
||||
}
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
public void setLength(int length) {
|
||||
this.length = length;
|
||||
}
|
||||
public void setOffset(int offset) {
|
||||
this.offset = offset;
|
||||
}
|
||||
public void setResource(IResource resource) {
|
||||
this.resource = resource;
|
||||
}
|
||||
/**
|
||||
* @param element The element to set.
|
||||
*/
|
||||
public final void setElement(IASTOffsetableNamedElement element) {
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -145,94 +134,130 @@ public class OpenDeclarationsAction extends SelectionParseAction implements IUpd
|
|||
}
|
||||
|
||||
final Storage storage = new Storage();
|
||||
|
||||
|
||||
IRunnableWithProgress runnable = new IRunnableWithProgress()
|
||||
{
|
||||
// steps:
|
||||
// 1- parse and get the best selected name based on the offset/length into that TU
|
||||
// 2- based on the IASTName selected, find the best declaration of it in the TU
|
||||
// 3- if no IASTName is found for a declaration, then search the Index
|
||||
public void run(IProgressMonitor monitor) {
|
||||
IFile resourceFile = fEditor.getInputFile();
|
||||
projectName = findProjectName(resourceFile);
|
||||
|
||||
IParser parser = setupParser(resourceFile);
|
||||
int selectionStart = selNode.selStart;
|
||||
int selectionEnd = selNode.selEnd;
|
||||
int selectionStart = selNode.selStart;
|
||||
int selectionLength = selNode.selEnd - selNode.selStart;
|
||||
|
||||
IFile resourceFile = null;
|
||||
|
||||
IASTName[] selectedNames = BLANK_NAME_ARRAY;
|
||||
if (fEditor.getEditorInput() instanceof ExternalEditorInput) {
|
||||
if( fEditor.getEditorInput() instanceof ITranslationUnitEditorInput )
|
||||
{
|
||||
ITranslationUnitEditorInput ip = (ITranslationUnitEditorInput) fEditor.getEditorInput();
|
||||
IResource r = ip.getTranslationUnit().getUnderlyingResource();
|
||||
if( r.getType() == IResource.FILE )
|
||||
resourceFile = (IFile) r;
|
||||
else
|
||||
{
|
||||
operationNotAvailable(CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE);
|
||||
return;
|
||||
|
||||
IParser.ISelectionParseResult result = null;
|
||||
IASTOffsetableNamedElement node = null;
|
||||
try{
|
||||
result = parser.parse(selectionStart,selectionEnd);
|
||||
if( result != null )
|
||||
node = result.getOffsetableNamedElement();
|
||||
}
|
||||
catch (ParseError er){}
|
||||
catch ( VirtualMachineError vmErr){
|
||||
if (vmErr instanceof OutOfMemoryError){
|
||||
org.eclipse.cdt.internal.core.model.Util.log(null, "Open Declarations Out Of Memory error: " + vmErr.getMessage() + " on File: " + resourceFile.getName(), ICLogConstants.CDT); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
||||
catch (Exception ex){}
|
||||
|
||||
finally{
|
||||
if (node == null){
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
resourceFile = fEditor.getInputFile();
|
||||
|
||||
|
||||
storage.setFileName( result.getFilename() );
|
||||
storage.setElement( node );
|
||||
storage.setResource( ParserUtil.getResourceForFilename( result.getFilename() ) );
|
||||
if (resourceFile != null)
|
||||
projectName = findProjectName(resourceFile);
|
||||
|
||||
// step 1 starts here
|
||||
if (resourceFile != null)
|
||||
selectedNames = DOMSearchUtil.getSelectedNamesFrom(resourceFile, selectionStart, selectionLength);
|
||||
|
||||
if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
|
||||
IASTName searchName = selectedNames[0];
|
||||
// step 2 starts here
|
||||
IASTName[] domNames = DOMSearchUtil.getNamesFromDOM(searchName, ICSearchConstants.DECLARATIONS);
|
||||
if (domNames != null && domNames.length > 0 && domNames[0] != null) {
|
||||
String fileName=null;
|
||||
int start=0;
|
||||
int end=0;
|
||||
|
||||
if ( domNames[0].getTranslationUnit() != null ) {
|
||||
IASTFileLocation location = domNames[0].getTranslationUnit().flattenLocationsToFile( domNames[0].getNodeLocations() );
|
||||
fileName = location.getFileName();
|
||||
start = location.getNodeOffset();
|
||||
end = location.getNodeOffset() + location.getNodeLength();
|
||||
}
|
||||
|
||||
if (fileName != null) {
|
||||
storage.setFileName(fileName);
|
||||
storage.setLength(end - start);
|
||||
storage.setOffset(start);
|
||||
storage.setResource(ParserUtil.getResourceForFilename( fileName ));
|
||||
}
|
||||
} else {
|
||||
// step 3 starts here
|
||||
ICElement[] scope = new ICElement[1];
|
||||
scope[0] = new CProject(null, fEditor.getInputFile().getProject());
|
||||
Set matches = DOMSearchUtil.getMatchesFromSearchEngine(SearchEngine.createCSearchScope(scope), searchName, ICSearchConstants.DECLARATIONS);
|
||||
|
||||
if (matches != null) {
|
||||
Iterator itr = matches.iterator();
|
||||
while(itr.hasNext()) {
|
||||
Object match = itr.next();
|
||||
if (match instanceof IMatch) {
|
||||
IMatch theMatch = (IMatch)match;
|
||||
storage.setFileName(theMatch.getLocation().toOSString());
|
||||
storage.setLength(theMatch.getEndOffset() - theMatch.getStartOffset());
|
||||
storage.setOffset(theMatch.getStartOffset());
|
||||
storage.setResource(ParserUtil.getResourceForFilename(theMatch.getLocation().toOSString()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (selectedNames.length == 0){
|
||||
operationNotAvailable(CSEARCH_OPERATION_NO_NAMES_SELECTED_MESSAGE);
|
||||
return;
|
||||
} else {
|
||||
operationNotAvailable(CSEARCH_OPERATION_TOO_MANY_NAMES_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private String findProjectName(IFile resourceFile) {
|
||||
if( resourceFile == null ) return ""; //$NON-NLS-1$
|
||||
IProject [] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
|
||||
for( int i = 0; i < projects.length; ++i )
|
||||
{
|
||||
if( projects[i].contains(resourceFile) )
|
||||
return projects[i].getName();
|
||||
}
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
private String findProjectName(IFile resourceFile) {
|
||||
if( resourceFile == null ) return ""; //$NON-NLS-1$
|
||||
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
|
||||
for( int i = 0; i < projects.length; ++i )
|
||||
{
|
||||
if( projects[i].contains(resourceFile) )
|
||||
return projects[i].getName();
|
||||
}
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
ProgressMonitorDialog progressMonitor = new ProgressMonitorDialog(getShell());
|
||||
progressMonitor.run(true, true, runnable);
|
||||
|
||||
IASTOffsetableNamedElement namedElement = storage.getNamedElement();
|
||||
if( namedElement == null ){
|
||||
operationNotAvailable();
|
||||
return;
|
||||
} else {
|
||||
clearStatusLine();
|
||||
}
|
||||
|
||||
int nameOffset = storage.getOffset();
|
||||
int nameLength = storage.getLength();
|
||||
if( storage.getResource() != null )
|
||||
{
|
||||
int nameOffset = 0;
|
||||
int nameEndOffset = 0;
|
||||
|
||||
nameOffset = namedElement.getNameOffset();
|
||||
nameEndOffset = namedElement.getNameEndOffset();
|
||||
|
||||
open( storage.getResource(), nameOffset, nameEndOffset - nameOffset );
|
||||
clearStatusLine();
|
||||
open( storage.getResource(), nameOffset, nameLength );
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
String fileName = null;
|
||||
int nameOffset = 0;
|
||||
int nameEndOffset = 0;
|
||||
|
||||
fileName = storage.getFileName();
|
||||
nameOffset = namedElement.getNameOffset();
|
||||
nameEndOffset = namedElement.getNameEndOffset();
|
||||
|
||||
if (fileName != null){
|
||||
open( fileName,nameOffset, nameEndOffset - nameOffset);
|
||||
}
|
||||
}
|
||||
String fileName = storage.getFileName();
|
||||
|
||||
if (fileName != null){
|
||||
clearStatusLine();
|
||||
open( fileName, nameOffset, nameLength);
|
||||
}
|
||||
|
||||
} catch(Exception x) {
|
||||
CUIPlugin.getDefault().log(x);
|
||||
|
@ -252,15 +277,13 @@ public class OpenDeclarationsAction extends SelectionParseAction implements IUpd
|
|||
return true;
|
||||
}
|
||||
|
||||
ICProject cproject = CoreModel.getDefault().getCModel().getCProject( projectName );
|
||||
ICProject cproject = CoreModel.getDefault().getCModel().getCProject( projectName );
|
||||
ITranslationUnit unit = CoreModel.getDefault().createTranslationUnitFrom(cproject, path);
|
||||
if (unit != null) {
|
||||
setSelectionAtOffset( EditorUtility.openInEditor(unit), offset, length );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
FileStorage storage = new FileStorage(null, path);
|
||||
IEditorPart part = EditorUtility.openInEditor(storage);
|
||||
setSelectionAtOffset(part, offset, length);
|
||||
|
@ -291,19 +314,12 @@ public class OpenDeclarationsAction extends SelectionParseAction implements IUpd
|
|||
* @param length TODO
|
||||
*/
|
||||
private void setSelectionAtOffset(IEditorPart part, int offset, int length) {
|
||||
//int line = element.getStartOffset();
|
||||
//if(line > 0) line--;
|
||||
if(part instanceof CEditor) {
|
||||
CEditor ed = (CEditor)part;
|
||||
|
||||
try {
|
||||
//IDocument document= ed.getDocumentProvider().getDocument(ed.getEditorInput());
|
||||
//if(line > 3) {
|
||||
// ed.selectAndReveal(document.getLineOffset(line - 3), 0);
|
||||
//}
|
||||
ed.selectAndReveal(offset, length);
|
||||
if( part instanceof AbstractTextEditor )
|
||||
{
|
||||
try {
|
||||
((AbstractTextEditor) part).selectAndReveal(offset, length);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
// /**
|
||||
// * Shows a dialog for resolving an ambigous C element.
|
||||
|
@ -346,48 +362,6 @@ public class OpenDeclarationsAction extends SelectionParseAction implements IUpd
|
|||
public void update() {
|
||||
setEnabled(getSelectedStringFromEditor() != null);
|
||||
}
|
||||
|
||||
private SearchFor getSearchForFromNode(IASTNode node){
|
||||
SearchFor searchFor = null;
|
||||
|
||||
if (node instanceof IASTClassSpecifier){
|
||||
//Find out if class, struct, union
|
||||
IASTClassSpecifier tempNode = (IASTClassSpecifier) node;
|
||||
if(tempNode.getClassKind().equals(ASTClassKind.CLASS)){
|
||||
searchFor = ICSearchConstants.CLASS;
|
||||
}
|
||||
else if (tempNode.getClassKind().equals(ASTClassKind.STRUCT)){
|
||||
searchFor = ICSearchConstants.STRUCT;
|
||||
}
|
||||
else if (tempNode.getClassKind().equals(ASTClassKind.UNION)){
|
||||
searchFor = ICSearchConstants.UNION;
|
||||
}
|
||||
}
|
||||
else if (node instanceof IASTMethod){
|
||||
searchFor = ICSearchConstants.METHOD;
|
||||
}
|
||||
else if (node instanceof IASTFunction){
|
||||
searchFor = ICSearchConstants.FUNCTION;
|
||||
}
|
||||
else if (node instanceof IASTField){
|
||||
searchFor = ICSearchConstants.FIELD;
|
||||
}
|
||||
else if (node instanceof IASTVariable){
|
||||
searchFor = ICSearchConstants.VAR;
|
||||
}
|
||||
else if (node instanceof IASTEnumerationSpecifier){
|
||||
searchFor = ICSearchConstants.ENUM;
|
||||
}
|
||||
else if (node instanceof IASTEnumerator){
|
||||
searchFor = ICSearchConstants.FIELD;
|
||||
}
|
||||
else if (node instanceof IASTNamespaceDefinition){
|
||||
searchFor = ICSearchConstants.NAMESPACE;
|
||||
}
|
||||
|
||||
return searchFor;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004 IBM Corporation and others.
|
||||
* Copyright (c) 2004,2005 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
|
||||
|
@ -49,7 +49,10 @@ import org.eclipse.ui.texteditor.IDocumentProvider;
|
|||
* Created on Jun 2, 2004
|
||||
*/
|
||||
public class SelectionParseAction extends Action {
|
||||
|
||||
protected static final String CSEARCH_OPERATION_TOO_MANY_NAMES_MESSAGE = "CSearchOperation.tooManyNames.message"; //$NON-NLS-1$
|
||||
protected static final String CSEARCH_OPERATION_NO_NAMES_SELECTED_MESSAGE = "CSearchOperation.noNamesSelected.message"; //$NON-NLS-1$
|
||||
protected static final String CSEARCH_OPERATION_OPERATION_UNAVAILABLE_MESSAGE = "CSearchOperation.operationUnavailable.message"; //$NON-NLS-1$
|
||||
|
||||
protected IWorkbenchSite fSite;
|
||||
protected CEditor fEditor;
|
||||
|
||||
|
@ -122,27 +125,45 @@ public class SelectionParseAction extends Action {
|
|||
return parser;
|
||||
}
|
||||
|
||||
protected void operationNotAvailable() {
|
||||
IStatusLineManager statusManager = null;
|
||||
if (fSite instanceof IViewSite){
|
||||
statusManager = ((IViewSite) fSite).getActionBars().getStatusLineManager();
|
||||
}
|
||||
else if (fSite instanceof IEditorSite){
|
||||
statusManager = ((IEditorSite) fSite).getActionBars().getStatusLineManager();
|
||||
}
|
||||
if( statusManager != null )
|
||||
statusManager.setErrorMessage(CSearchMessages.getString("CSearchOperation.operationUnavailable.message"));//$NON-NLS-1$
|
||||
protected void operationNotAvailable(final String message) {
|
||||
// run the code to update the status line on the Display thread
|
||||
// this way any other thread can invoke operationNotAvailable(String)
|
||||
CUIPlugin.getStandardDisplay().asyncExec(new Runnable(){
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
public void run() {
|
||||
IStatusLineManager statusManager = null;
|
||||
if (fSite instanceof IViewSite){
|
||||
statusManager = ((IViewSite) fSite).getActionBars().getStatusLineManager();
|
||||
}
|
||||
else if (fSite instanceof IEditorSite){
|
||||
statusManager = ((IEditorSite) fSite).getActionBars().getStatusLineManager();
|
||||
}
|
||||
if( statusManager != null )
|
||||
statusManager.setErrorMessage(CSearchMessages.getString(message));//$NON-NLS-1$
|
||||
}
|
||||
});
|
||||
}
|
||||
protected void clearStatusLine() {
|
||||
IStatusLineManager statusManager = null;
|
||||
if (fSite instanceof IViewSite){
|
||||
statusManager = ((IViewSite) fSite).getActionBars().getStatusLineManager();
|
||||
}
|
||||
else if (fSite instanceof IEditorSite){
|
||||
statusManager = ((IEditorSite) fSite).getActionBars().getStatusLineManager();
|
||||
}
|
||||
if( statusManager != null )
|
||||
statusManager.setErrorMessage( "" ); //$NON-NLS-1$
|
||||
// run the code to update the status line on the Display thread
|
||||
// this way any other thread can invoke clearStatusLine()
|
||||
CUIPlugin.getStandardDisplay().asyncExec(new Runnable(){
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
public void run() {
|
||||
IStatusLineManager statusManager = null;
|
||||
if (fSite instanceof IViewSite){
|
||||
statusManager = ((IViewSite) fSite).getActionBars().getStatusLineManager();
|
||||
}
|
||||
else if (fSite instanceof IEditorSite){
|
||||
statusManager = ((IEditorSite) fSite).getActionBars().getStatusLineManager();
|
||||
}
|
||||
if( statusManager != null )
|
||||
statusManager.setErrorMessage( "" ); //$NON-NLS-1$
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//TODO: Change this to work with qualified identifiers
|
||||
|
@ -161,8 +182,12 @@ public class SelectionParseAction extends Action {
|
|||
try{
|
||||
while (pos >= 0) {
|
||||
c= doc.getChar(pos);
|
||||
|
||||
// TODO this logic needs to be improved
|
||||
// ex: ~destr[cursor]uctors, p2->ope[cursor]rator=(zero), etc
|
||||
if (!Character.isJavaIdentifierPart(c))
|
||||
break;
|
||||
break;
|
||||
|
||||
--pos;
|
||||
}
|
||||
fStartPos= pos + 1;
|
||||
|
@ -188,7 +213,7 @@ public class SelectionParseAction extends Action {
|
|||
|
||||
return sel;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the selected string from the editor
|
||||
* @return The string currently selected, or null if there is no valid selection
|
||||
|
|
|
@ -9,6 +9,7 @@ package org.eclipse.cdt.internal.ui.search.actions;
|
|||
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||
import org.eclipse.cdt.core.search.ICSearchConstants.LimitTo;
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
|
@ -43,7 +44,7 @@ public class WorkingSetFindAction extends FindAction {
|
|||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.ui.search.actions.FindAction#getScope()
|
||||
* @see org.eclipse.cdt.internal.ui.search.actions.FindAction#getScope(org.eclipse.core.resources.IProject)
|
||||
*/
|
||||
protected ICSearchScope getScope() {
|
||||
// TODO Auto-generated method stub
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2003, 2004 IBM Corporation and others.
|
||||
* Copyright (c) 2003, 2005 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -138,6 +138,10 @@ public class CSearchResultLabelProvider extends LabelProvider {
|
|||
flags |= CElementImageDescriptor.TEMPLATE;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
imageDescriptor = CPluginImages.DESC_OBJS_UNKNOWN;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
package org.eclipse.cdt.ui;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
|
@ -54,6 +55,7 @@ import org.eclipse.core.resources.ResourcesPlugin;
|
|||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IAdapterManager;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
|
|
Loading…
Add table
Reference in a new issue