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

Fix mark occurrences for destructors and template types

This commit is contained in:
Anton Leherbauer 2008-01-14 15:00:15 +00:00
parent f8698c710c
commit f2856c60ce
4 changed files with 77 additions and 8 deletions

View file

@ -119,6 +119,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDeferredTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionScope;
@ -1295,6 +1296,9 @@ public class CPPVisitor {
public CollectReferencesAction( IBinding binding ){
if (binding instanceof ICPPDeferredTemplateInstance) {
binding= ((ICPPDeferredTemplateInstance) binding).getSpecializedBinding();
}
this.binding = binding;
this.refs = new IASTName[ DEFAULT_LIST_SIZE ];
@ -1317,7 +1321,7 @@ public class CPPVisitor {
}
public int visit( IASTName name ){
if( name instanceof ICPPASTQualifiedName ) return PROCESS_CONTINUE;
if( name instanceof ICPPASTQualifiedName || name instanceof ICPPASTTemplateId ) return PROCESS_CONTINUE;
ASTNodeProperty prop = name.getPropertyInParent();
ASTNodeProperty p2 = null;
@ -1394,6 +1398,8 @@ public class CPPVisitor {
candidate = null;
else
candidate = bs[ ++n ];
} else if (potential instanceof ICPPDeferredTemplateInstance) {
candidate= ((ICPPDeferredTemplateInstance) potential).getSpecializedBinding();
} else {
candidate = potential;
}

View file

@ -1,5 +1,6 @@
#define INT int
#define FUNCTION_MACRO(arg) globalFunc(arg)
#define EMPTY_MACRO(arg)
enum Enumeration {
ONE, TWO, THREE
@ -11,15 +12,22 @@ static int globalStaticVariable = 0;
void globalFunc(int a);
static void globalStaticFunc() {
EMPTY_MACRO(n);
globalVariable = 1;
EMPTY_MACRO(1);
return 0;
}
;
class Base1 {
Base1();
~Base1();
};
class Base2 {
};
Base1::~Base1() {}
Base1::Base1() {}
class ClassContainer : Base1, Base2 {
public:
static int staticPubField;
@ -47,6 +55,7 @@ template<class T1, class T2> class TemplateClass {
tArg1 = arg1;
tArg2 = arg2;
}
void m(TemplateClass&);
};
template<class T1> class PartialInstantiatedClass : TemplateClass<T1, Base1> {

View file

@ -187,7 +187,7 @@ public class MarkOccurrenceTest extends TestCase {
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(3);
assertOccurrences(5);
assertOccurrencesInWidget();
}
@ -201,7 +201,7 @@ public class MarkOccurrenceTest extends TestCase {
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(2);
assertOccurrences(3);
assertOccurrencesInWidget();
}
@ -291,6 +291,36 @@ public class MarkOccurrenceTest extends TestCase {
assertOccurrencesInWidget();
}
public void testMarkConstructorOccurrences() {
try {
fMatch= fFindReplaceDocumentAdapter.find(0, "Base1(", true, true, false, false);
} catch (BadLocationException e) {
fail();
}
assertNotNull(fMatch);
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(2);
assertOccurrencesInWidget();
}
public void testMarkDestructorOccurrences() {
try {
fMatch= fFindReplaceDocumentAdapter.find(0, "~Base1", true, true, false, false);
} catch (BadLocationException e) {
fail();
}
assertNotNull(fMatch);
fMatch= new Region(fMatch.getOffset() + 1, fMatch.getLength() - 1);
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(2);
assertOccurrencesInWidget();
}
public void testMarkLocalOccurrences() {
try {
fMatch= fFindReplaceDocumentAdapter.find(0, "localVar", true, true, true, false);
@ -319,6 +349,20 @@ public class MarkOccurrenceTest extends TestCase {
assertOccurrencesInWidget();
}
public void testMarkEmptyMacroOccurrences() {
try {
fMatch= fFindReplaceDocumentAdapter.find(0, "EMPTY_MACRO", true, true, true, false);
} catch (BadLocationException e) {
fail();
}
assertNotNull(fMatch);
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(3);
assertOccurrencesInWidget();
}
public void testMarkEnumeratorOccurrences() {
try {
fMatch= fFindReplaceDocumentAdapter.find(0, "ONE", true, true, true, false);

View file

@ -154,6 +154,7 @@ 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.cpp.ICPPASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants;
import org.eclipse.cdt.core.model.CModelException;
@ -2942,13 +2943,22 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
OccurrenceLocation[] locations= null;
IASTNode selectedNode= astRoot.selectNodeForLocation(astRoot.getFilePath(), wordRegion.getOffset(), wordRegion.getLength());
if (selectedNode == null && astRoot instanceof ICPPASTTranslationUnit && wordRegion.getOffset() > 0) {
// destructor?
try {
if (document.getChar(wordRegion.getOffset() - 1) == '~') {
selectedNode= astRoot.selectNodeForLocation(astRoot.getFilePath(), wordRegion.getOffset() - 1, wordRegion.getLength() + 1);
}
} catch (BadLocationException exc) {
// should not happen
}
}
final class NameFinder extends ASTVisitor {
{
private IASTName fName;
public NameFinder() {
shouldVisitNames= true;
}
IASTName fName;
public int visit(IASTName name) {
fName= name;
return PROCESS_ABORT;