mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Applied patch for Devin Steffler.
FIXED 94135- All Declarations does not include the namespace scope in the search pattern FIXED 95202- [NPE] on Open Declarations for C++ spec example FIXED 95219- [Ctrl+Click] is enabled on everything except for keywords FIXED 95224- [Open Definition] of destructor should have the same logic as constructors FIXED 95225- [open definition] within constructor in a throw statement fails FIXED 95229- [open declaration] infinite loop on keyword operator FIXED 95372- DOMQuery#isLocal() should not reference internal DOM packages
This commit is contained in:
parent
27570511ea
commit
3fa54b37ea
18 changed files with 306 additions and 66 deletions
|
@ -246,7 +246,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IASTName name_struct = type.getName();
|
||||
assertTrue( name_struct.isDeclaration() );
|
||||
assertFalse( name_struct.isReference() );
|
||||
assertNull("", name_struct.toString()); //$NON-NLS-1$
|
||||
assertEquals("", name_struct.toString()); //$NON-NLS-1$
|
||||
// member - x
|
||||
IASTSimpleDeclaration decl_x = (IASTSimpleDeclaration) type
|
||||
.getMembers()[0];
|
||||
|
@ -1377,7 +1377,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertEquals(d.getDeclarators().length, 1);
|
||||
IASTStandardFunctionDeclarator f = (IASTStandardFunctionDeclarator) d
|
||||
.getDeclarators()[0];
|
||||
assertNull(f.getName().toString());
|
||||
assertEquals(f.getName().toString(), "");
|
||||
assertNotNull(f.getNestedDeclarator());
|
||||
assertEquals(f.getNestedDeclarator().getName().toString(), "pfi"); //$NON-NLS-1$
|
||||
assertTrue(f.getPointerOperators().length == 0);
|
||||
|
@ -1394,7 +1394,7 @@ public class AST2Tests extends AST2BaseTest {
|
|||
d = (IASTSimpleDeclaration) tu.getDeclarations()[0];
|
||||
assertEquals(d.getDeclarators().length, 1);
|
||||
f = (IASTStandardFunctionDeclarator) d.getDeclarators()[0];
|
||||
assertNull(f.getName().toString());
|
||||
assertEquals(f.getName().toString(), "");
|
||||
assertNotNull(f.getNestedDeclarator());
|
||||
assertEquals(f.getNestedDeclarator().getName().toString(), "pfi"); //$NON-NLS-1$
|
||||
}
|
||||
|
|
|
@ -24,4 +24,11 @@ public interface ICPPMethod extends ICPPFunction, ICPPMember {
|
|||
* @throws DOMException
|
||||
*/
|
||||
public boolean isVirtual() throws DOMException;
|
||||
|
||||
/**
|
||||
* is this a destructor
|
||||
*
|
||||
* returns true if its name starts with '~'
|
||||
*/
|
||||
public boolean isDestructor() throws DOMException;
|
||||
}
|
||||
|
|
|
@ -1528,7 +1528,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
final IASTDeclarator[] declarators = ((IASTSimpleDeclaration) ds.getDeclaration()).getDeclarators();
|
||||
if( declarators.length == 0 ||
|
||||
( declarators.length == 1 &&
|
||||
( declarators[0].getName().toString() == null && declarators[0].getNestedDeclarator() == null ) ) )
|
||||
( declarators[0].getName().toCharArray().length == 0 && declarators[0].getNestedDeclarator() == null ) ) )
|
||||
{
|
||||
backup(mark);
|
||||
while (true) {
|
||||
|
|
|
@ -23,6 +23,7 @@ public class CASTName extends CASTNode implements IASTName {
|
|||
private final char[] name;
|
||||
|
||||
private static final char[] EMPTY_CHAR_ARRAY = {};
|
||||
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
|
||||
|
||||
private IBinding binding = null;
|
||||
|
||||
|
@ -71,7 +72,7 @@ public class CASTName extends CASTNode implements IASTName {
|
|||
*/
|
||||
public String toString() {
|
||||
if (name == EMPTY_CHAR_ARRAY)
|
||||
return null;
|
||||
return EMPTY_STRING;
|
||||
return new String(name);
|
||||
}
|
||||
|
||||
|
|
|
@ -1209,7 +1209,7 @@ public class GNUCSourceParser extends AbstractGNUSourceCodeParser {
|
|||
backup(mark);
|
||||
throwBacktrack(bt);
|
||||
}
|
||||
if (declarator == null || declarator.getName().toString() != null) //$NON-NLS-1$
|
||||
if (declarator == null || declarator.getName().toCharArray().length > 0) //$NON-NLS-1$
|
||||
{
|
||||
backup(mark);
|
||||
throwBacktrack(startingOffset, figureEndOffset(declSpecifier,
|
||||
|
|
|
@ -24,6 +24,7 @@ public class CPPASTName extends CPPASTNode implements IASTName {
|
|||
private char[] name;
|
||||
|
||||
private static final char[] EMPTY_CHAR_ARRAY = {};
|
||||
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
|
||||
|
||||
private IBinding binding = null;
|
||||
|
||||
|
@ -72,7 +73,7 @@ public class CPPASTName extends CPPASTNode implements IASTName {
|
|||
*/
|
||||
public String toString() {
|
||||
if (name == EMPTY_CHAR_ARRAY)
|
||||
return null;
|
||||
return EMPTY_STRING;
|
||||
return new String(name);
|
||||
}
|
||||
|
||||
|
|
|
@ -47,6 +47,17 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
|
|||
public boolean isVirtual() throws DOMException {
|
||||
return ((ICPPMethod)getBinding()).isVirtual();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isDestructor()
|
||||
*/
|
||||
public boolean isDestructor() throws DOMException {
|
||||
char[] name = getNameCharArray();
|
||||
if (name.length > 1 && name[0] == '~')
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CPPMethodProblem extends CPPFunctionProblem implements ICPPMethod {
|
||||
|
@ -67,6 +78,17 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
|
|||
public boolean isVirtual() throws DOMException {
|
||||
throw new DOMException( this );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isDestructor()
|
||||
*/
|
||||
public boolean isDestructor() throws DOMException {
|
||||
char[] name = getNameCharArray();
|
||||
if (name.length > 1 && name[0] == '~')
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public CPPMethod( ICPPASTFunctionDeclarator declarator ){
|
||||
|
@ -224,4 +246,15 @@ public class CPPMethod extends CPPFunction implements ICPPMethod {
|
|||
public boolean isMutable() {
|
||||
return hasStorageClass( this, ICPPASTDeclSpecifier.sc_mutable );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isDestructor()
|
||||
*/
|
||||
public boolean isDestructor() throws DOMException {
|
||||
char[] name = getNameCharArray();
|
||||
if (name.length > 1 && name[0] == '~')
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,4 +50,15 @@ public class CPPMethodInstance extends CPPFunctionInstance implements ICPPMethod
|
|||
return ((ICPPMethod)getTemplateDefinition()).isVirtual();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isDestructor()
|
||||
*/
|
||||
public boolean isDestructor() throws DOMException {
|
||||
char[] name = getNameCharArray();
|
||||
if (name.length > 1 && name[0] == '~')
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -71,4 +71,15 @@ public class CPPMethodSpecialization extends CPPFunctionSpecialization
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isDestructor()
|
||||
*/
|
||||
public boolean isDestructor() throws DOMException {
|
||||
char[] name = getNameCharArray();
|
||||
if (name.length > 1 && name[0] == '~')
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -133,4 +133,15 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
|
|||
return super.isInline();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isDestructor()
|
||||
*/
|
||||
public boolean isDestructor() throws DOMException {
|
||||
char[] name = getNameCharArray();
|
||||
if (name.length > 1 && name[0] == '~')
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -53,4 +53,15 @@ public class CPPMethodTemplateSpecialization extends
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod#isDestructor()
|
||||
*/
|
||||
public boolean isDestructor() throws DOMException {
|
||||
char[] name = getNameCharArray();
|
||||
if (name.length > 1 && name[0] == '~')
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -729,8 +729,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
int o = throwExpression != null ? calculateEndOffset(throwExpression)
|
||||
: throwToken.getEndOffset();
|
||||
return buildUnaryExpression(ICPPASTUnaryExpression.op_throw,
|
||||
throwExpression, throwToken.getOffset(), o
|
||||
- throwToken.getOffset());
|
||||
throwExpression, throwToken.getOffset(), o); // fix for 95225
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -943,7 +942,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
- startingOffset);
|
||||
}
|
||||
if (declarator != null) {
|
||||
if (declarator.getName().toString() != null) {
|
||||
if (declarator.getName().toCharArray().length > 0) {
|
||||
backup(mark);
|
||||
throwBacktrack(startingOffset, figureEndOffset(declSpecifier,
|
||||
declarator)
|
||||
|
|
|
@ -19,6 +19,7 @@ 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;
|
||||
|
@ -29,11 +30,15 @@ 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.IFunctionType;
|
||||
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
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.c.ICExternalBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||
|
@ -48,6 +53,8 @@ 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.dom.parser.cpp.CPPASTName;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTQualifiedName;
|
||||
import org.eclipse.cdt.internal.core.search.matching.CSearchPattern;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
|
@ -77,7 +84,7 @@ public class DOMSearchUtil {
|
|||
SearchEngine engine = new SearchEngine();
|
||||
BasicSearchResultCollector results = new BasicSearchResultCollector();
|
||||
|
||||
ICSearchPattern pattern = createPattern(searchName.resolveBinding(), limitTo, true);
|
||||
ICSearchPattern pattern = createPattern(searchName, limitTo, true);
|
||||
|
||||
try {
|
||||
engine.search(CCorePlugin.getWorkspace(), pattern, scope, results, false);
|
||||
|
@ -88,7 +95,8 @@ public class DOMSearchUtil {
|
|||
return results.getSearchResults();
|
||||
}
|
||||
|
||||
private static CSearchPattern createPattern( IBinding binding, LimitTo limitTo, boolean caseSensitive) {
|
||||
private static CSearchPattern createPattern( IASTName searchName, LimitTo limitTo, boolean caseSensitive) {
|
||||
IBinding binding = searchName.resolveBinding();
|
||||
if (binding == null)
|
||||
return null;
|
||||
|
||||
|
@ -131,7 +139,7 @@ public class DOMSearchUtil {
|
|||
searchFor = ICSearchConstants.UNKNOWN_SEARCH_FOR;
|
||||
}
|
||||
|
||||
return CSearchPattern.createPattern(binding.getName(), searchFor, limitTo, ICSearchConstants.EXACT_MATCH, caseSensitive);
|
||||
return CSearchPattern.createPattern(DOMSearchUtil.getSearchPattern(searchName), searchFor, limitTo, ICSearchConstants.EXACT_MATCH, caseSensitive);
|
||||
}
|
||||
|
||||
private static SearchFor createSearchFor( IBinding binding ) {
|
||||
|
@ -350,9 +358,10 @@ public class DOMSearchUtil {
|
|||
names = getNames(tu, binding, limitTo);
|
||||
|
||||
if (names == null || names.length == 0) { // try alternate strategies
|
||||
// fix for 86829
|
||||
try {
|
||||
if (binding instanceof ICPPConstructor && binding.getScope() instanceof ICPPClassScope) {
|
||||
// fix for 86829, 95224
|
||||
if ((binding instanceof ICPPConstructor || (binding instanceof ICPPMethod && ((ICPPMethod)binding).isDestructor()))
|
||||
&& binding.getScope() instanceof ICPPClassScope) {
|
||||
binding = ((ICPPClassScope)binding.getScope()).getClassType();
|
||||
names = getNames(tu, binding, limitTo);
|
||||
}
|
||||
|
@ -425,6 +434,13 @@ public class DOMSearchUtil {
|
|||
public int size() { return nameList.size(); }
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ParserLanguage corresponding to the IPath and IProject. Returns ParserLanguage.CPP if the file type is a header.
|
||||
*
|
||||
* @param path
|
||||
* @param project
|
||||
* @return
|
||||
*/
|
||||
public static ParserLanguage getLanguage( IPath path, IProject project )
|
||||
{
|
||||
ICFileType type = CCorePlugin.getDefault().getFileType(project, path.lastSegment());
|
||||
|
@ -438,4 +454,72 @@ public class DOMSearchUtil {
|
|||
return ParserLanguage.C;
|
||||
return ParserLanguage.CPP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a search pattern String based on the IASTName passed as a parameter.
|
||||
*
|
||||
* Used to generate a string to present to the user as well as a string used by
|
||||
* the SearchEngine to parse for qualified names and parameters.
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public static String getSearchPattern(IASTName name) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("::"); //$NON-NLS-1$
|
||||
|
||||
String[] namespaces = null;
|
||||
|
||||
IASTNode parent = name.getParent();
|
||||
while(!(parent instanceof IASTTranslationUnit) && parent != null) {
|
||||
if (parent instanceof ICPPASTNamespaceDefinition) {
|
||||
namespaces = (String[])ArrayUtil.append(String.class, namespaces, ((ICPPASTNamespaceDefinition)parent).getName().toString());
|
||||
}
|
||||
parent = parent.getParent();
|
||||
}
|
||||
|
||||
if (namespaces != null && namespaces.length > 0) {
|
||||
for( int i=namespaces.length-1; i>=0; i-- ) {
|
||||
if (namespaces[i] != null) {
|
||||
buffer.append(namespaces[i]);
|
||||
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 buffer.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -359,6 +359,30 @@ public class CPPSelectionTestsNoIndexer extends TestCase {
|
|||
assertEquals(((ASTNode)def).getLength(), 7);
|
||||
}
|
||||
|
||||
public void testBug95224() throws Exception{
|
||||
Writer writer = new StringWriter();
|
||||
writer.write( "class A{\n"); //$NON-NLS-1$
|
||||
writer.write( "A();\n"); //$NON-NLS-1$
|
||||
writer.write( "A(const A&); // open definition on A finds class A\n"); //$NON-NLS-1$
|
||||
writer.write( "~A(); // open definition on A finds nothing\n"); //$NON-NLS-1$
|
||||
writer.write( "};\n"); //$NON-NLS-1$
|
||||
|
||||
String code = writer.toString();
|
||||
IFile file = importFile("testBug95224.cpp", code); //$NON-NLS-1$
|
||||
|
||||
int offset = code.indexOf("A(); // open definition "); //$NON-NLS-1$
|
||||
IASTNode def = testF2(file, offset);
|
||||
IASTNode decl = testF3(file, offset);
|
||||
assertTrue(def instanceof IASTName);
|
||||
assertTrue(decl instanceof IASTName);
|
||||
assertEquals(((IASTName)decl).toString(), "~A"); //$NON-NLS-1$
|
||||
assertEquals(((ASTNode)decl).getOffset(), 65);
|
||||
assertEquals(((ASTNode)decl).getLength(), 2);
|
||||
assertEquals(((IASTName)def).toString(), "A"); //$NON-NLS-1$
|
||||
assertEquals(((ASTNode)def).getOffset(), 6);
|
||||
assertEquals(((ASTNode)def).getLength(), 1);
|
||||
}
|
||||
|
||||
public void testBasicTemplateInstance() throws Exception{
|
||||
Writer writer = new StringWriter();
|
||||
writer.write( "namespace N{ \n"); //$NON-NLS-1$
|
||||
|
@ -901,6 +925,53 @@ public class CPPSelectionTestsNoIndexer extends TestCase {
|
|||
assertEquals(((ASTNode)def).getLength(), 1);
|
||||
}
|
||||
|
||||
public void testBug95225() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("class Overflow {\n"); //$NON-NLS-1$
|
||||
buffer.append("public:\n"); //$NON-NLS-1$
|
||||
buffer.append("Overflow(char,double,double);\n"); //$NON-NLS-1$
|
||||
buffer.append("};\n"); //$NON-NLS-1$
|
||||
buffer.append("void f(double x)\n"); //$NON-NLS-1$
|
||||
buffer.append("{\n"); //$NON-NLS-1$
|
||||
buffer.append("throw Overflow('+',x,3.45e107);\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
buffer.append("int foo() {\n"); //$NON-NLS-1$
|
||||
buffer.append("try {\n"); //$NON-NLS-1$
|
||||
buffer.append("f(1.2);\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
buffer.append("catch(Overflow& oo) {\n"); //$NON-NLS-1$
|
||||
buffer.append(" // handle exceptions of type Overflow here\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
buffer.append("}\n"); //$NON-NLS-1$
|
||||
|
||||
String code = buffer.toString();
|
||||
IFile file = importFile("testBug95225.cpp", code); //$NON-NLS-1$
|
||||
|
||||
int offset = code.indexOf("rflow('+',x,3.45e107);"); //$NON-NLS-1$
|
||||
IASTNode def = testF2(file, offset);
|
||||
IASTNode decl = testF3(file, offset);
|
||||
assertTrue(def instanceof IASTName);
|
||||
assertTrue(decl instanceof IASTName);
|
||||
assertEquals(((IASTName)decl).toString(), "Overflow"); //$NON-NLS-1$
|
||||
assertEquals(((ASTNode)decl).getOffset(), 25);
|
||||
assertEquals(((ASTNode)decl).getLength(), 8);
|
||||
assertEquals(((IASTName)def).toString(), "Overflow"); //$NON-NLS-1$
|
||||
assertEquals(((ASTNode)def).getOffset(), 6);
|
||||
assertEquals(((ASTNode)def).getLength(), 8);
|
||||
|
||||
offset = code.indexOf("x,3.45e107);"); //$NON-NLS-1$
|
||||
def = testF2(file, offset);
|
||||
decl = testF3(file, offset);
|
||||
assertTrue(def instanceof IASTName);
|
||||
assertTrue(decl instanceof IASTName);
|
||||
assertEquals(((IASTName)decl).toString(), "x"); //$NON-NLS-1$
|
||||
assertEquals(((ASTNode)decl).getOffset(), 72);
|
||||
assertEquals(((ASTNode)decl).getLength(), 1);
|
||||
assertEquals(((IASTName)def).toString(), "x"); //$NON-NLS-1$
|
||||
assertEquals(((ASTNode)def).getOffset(), 72);
|
||||
assertEquals(((ASTNode)def).getLength(), 1);
|
||||
}
|
||||
|
||||
public void testNoDefinitions() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("extern int a1; // declares a\n"); //$NON-NLS-1$
|
||||
|
@ -985,4 +1056,26 @@ public class CPPSelectionTestsNoIndexer extends TestCase {
|
|||
assertEquals(((ASTNode)def).getLength(), 1);
|
||||
|
||||
}
|
||||
|
||||
public void testBug95229() throws Exception {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("struct A {\n"); //$NON-NLS-1$
|
||||
buffer.append("operator short(); // F3 on operator causes an infinite loop\n"); //$NON-NLS-1$
|
||||
buffer.append("} a;\n"); //$NON-NLS-1$
|
||||
buffer.append("int f(int);\n"); //$NON-NLS-1$
|
||||
buffer.append("int f(float);\n"); //$NON-NLS-1$
|
||||
buffer.append("int i = f(a); // Calls f(int), because short -> int is\n"); //$NON-NLS-1$
|
||||
|
||||
String code = buffer.toString();
|
||||
IFile file = importFile("testBug95229.cpp", code); //$NON-NLS-1$
|
||||
|
||||
int offset = code.indexOf("rator short(); // F3"); //$NON-NLS-1$
|
||||
IASTNode def = testF2(file, offset);
|
||||
IASTNode decl = testF3(file, offset);
|
||||
assertNull(def);
|
||||
assertTrue(decl instanceof IASTName);
|
||||
assertEquals(((IASTName)decl).toString(), "operator short"); //$NON-NLS-1$
|
||||
assertEquals(((ASTNode)decl).getOffset(), 11);
|
||||
assertEquals(((ASTNode)decl).getLength(), 14);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,14 +66,27 @@ public class CElementHyperlinkDetector implements IHyperlinkDetector{
|
|||
private IRegion selectWord(IDocument document, int anchor) {
|
||||
//TODO: Modify this to work with qualified name
|
||||
|
||||
// fix for 95219, return null if the mouse is pointing to a non-java identifier part
|
||||
try {
|
||||
if (!Character.isJavaIdentifierPart(document.getChar(anchor))) {
|
||||
return null;
|
||||
}
|
||||
} catch (BadLocationException e) { return null; }
|
||||
|
||||
boolean isNumber=false;
|
||||
try {
|
||||
int offset= anchor;
|
||||
char c;
|
||||
char oldC='a'; // assume this is the first character
|
||||
|
||||
while (offset >= 0) {
|
||||
c= document.getChar(offset);
|
||||
if (!Character.isJavaIdentifierPart(c))
|
||||
break;
|
||||
if (!Character.isJavaIdentifierPart(c)) {
|
||||
if (Character.isDigit(oldC)) // if the first character is a digit, then assume the word is a number, i.e. 1e13, 0xFF, 123
|
||||
isNumber=true;
|
||||
break;
|
||||
}
|
||||
oldC = c;
|
||||
--offset;
|
||||
}
|
||||
|
||||
|
@ -94,13 +107,19 @@ public class CElementHyperlinkDetector implements IHyperlinkDetector{
|
|||
if (start == end)
|
||||
return new Region(start, 0);
|
||||
|
||||
String selWord = null;
|
||||
// don't select numbers only i.e. 0x1, 1e13, 1234
|
||||
if (isNumber) return null;
|
||||
|
||||
String selWord = null;
|
||||
String slas = document.get(start,1);
|
||||
|
||||
// TODO more need to be added to this list as they are discovered
|
||||
if (slas.equals("\n") || //$NON-NLS-1$
|
||||
slas.equals("\t") || //$NON-NLS-1$
|
||||
slas.equals(" ") || //$NON-NLS-1$
|
||||
slas.equals(">") || //$NON-NLS-1$
|
||||
slas.equals(".")) //$NON-NLS-1$
|
||||
slas.equals(".") || //$NON-NLS-1$
|
||||
slas.equals("(")) //$NON-NLS-1$
|
||||
{
|
||||
|
||||
selWord =document.get(start+1, end - start - 1);
|
||||
|
|
|
@ -148,9 +148,9 @@ public class DOMQuery extends CSearchQuery implements ISearchQuery {
|
|||
|
||||
private boolean isLocal() {
|
||||
IBinding binding = searchName.resolveBinding();
|
||||
if (searchName instanceof CPPASTName) {
|
||||
if (binding instanceof ICPPBinding) {
|
||||
try {
|
||||
if (binding instanceof ICPPBinding && !((ICPPBinding)binding).isGloballyQualified())
|
||||
if (!((ICPPBinding)binding).isGloballyQualified())
|
||||
return true;
|
||||
} catch (DOMException e) {}
|
||||
} else {
|
||||
|
|
|
@ -20,17 +20,10 @@ 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.IASTServiceProvider.UnsupportedDialectException;
|
||||
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.model.ICProject;
|
||||
import org.eclipse.cdt.core.parser.ParseError;
|
||||
|
@ -40,8 +33,6 @@ 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;
|
||||
|
@ -84,42 +75,7 @@ public abstract class FindAction extends SelectionParseAction {
|
|||
* @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);
|
||||
return new DOMQuery(DOMSearchUtil.getSearchPattern(name), name, limitTo, scope, collector);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -429,6 +429,9 @@ public class SelectionParseAction extends Action {
|
|||
case '(': {
|
||||
if (possibleEnd > 0)
|
||||
actualEnd = possibleEnd;
|
||||
|
||||
index++;
|
||||
|
||||
break;
|
||||
}
|
||||
case ']':
|
||||
|
|
Loading…
Add table
Reference in a new issue