1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-06 17:26:01 +02:00

bug 269034, mark occurrences for overloaded operators

This commit is contained in:
Mike Kucera 2009-03-18 13:17:31 +00:00
parent 7086a42dea
commit 88c96a3712
5 changed files with 47 additions and 8 deletions

View file

@ -38,6 +38,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
@ -1438,7 +1439,8 @@ public class CPPVisitor extends ASTQueries {
prop == ICPPASTUsingDeclaration.NAME ||
prop == IASTNamedTypeSpecifier.NAME ||
prop == ICPPASTConstructorChainInitializer.MEMBER_ID ||
prop == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) {
prop == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT ||
prop == IASTImplicitNameOwner.IMPLICIT_NAME) {
break;
}
return PROCESS_CONTINUE;
@ -1828,6 +1830,18 @@ public class CPPVisitor extends ASTQueries {
return action.getReferences();
}
public static IASTName[] getImplicitReferences(IASTTranslationUnit tu, IBinding binding) {
CollectReferencesAction action = new CollectReferencesAction(binding) {
{
shouldVisitNames = false;
shouldVisitImplicitNames = true;
shouldVisitImplicitNameAlternates = true;
}
};
tu.accept(action);
return action.getReferences();
}
public static IASTName[] getDeclarations(IASTTranslationUnit tu, IBinding binding) {
CollectDeclarationsAction action = new CollectDeclarationsAction(binding);
tu.accept(action);

View file

@ -71,6 +71,7 @@ struct CppStruct {
union CppUnion {
int unionField;
CppUnion operator+(CppUnion);
};
typedef CppUnion TUnion;
@ -105,6 +106,7 @@ INT ClassContainer::staticPrivMethod() {
CppUnion un;
un.unionField= 2;
staticPubMethod(staticPubField);
un + un;
label:
FUNCTION_MACRO(0);
if (un.unionField < st->structField)

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2008 IBM Corporation and others.
* Copyright (c) 2000, 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -479,6 +479,21 @@ public class MarkOccurrenceTest extends BaseUITestCase {
assertOccurrencesInWidget();
}
public void testMarkOperatorOccurrences() {
try {
fMatch= fFindReplaceDocumentAdapter.find(0, "operator+", true, true, true, false);
} catch (BadLocationException e) {
fail();
}
assertNotNull(fMatch);
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(2);
assertOccurrencesInWidget();
}
public void testNoOccurrencesIfDisabled() {
CUIPlugin.getDefault().getPreferenceStore().setValue(PreferenceConstants.EDITOR_MARK_OCCURRENCES, false);
fOccurrences= Integer.MAX_VALUE;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2008 IBM Corporation and others.
* Copyright (c) 2005, 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -3204,6 +3204,8 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
IASTNodeSelector selector= astRoot.getNodeSelector(null);
IASTName name= selector.findEnclosingName(selection.getOffset(), selection.getLength());
if(name == null)
name = selector.findEnclosingImplicitName(selection.getOffset(), selection.getLength());
if (validator != null && !validator.isValid(selection)) {
return;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2008 IBM Corporation and others.
* Copyright (c) 2000, 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -21,6 +21,8 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.ui.util.Messages;
public class OccurrencesFinder implements IOccurrencesFinder {
@ -55,15 +57,19 @@ public class OccurrencesFinder implements IOccurrencesFinder {
if (fResult == null) {
fResult= new ArrayList<OccurrenceLocation>();
IASTName[] names= fRoot.getDeclarationsInAST(fTarget);
for (int i= 0; i < names.length; i++) {
IASTName candidate= names[i];
for (IASTName candidate : names) {
if (candidate.isPartOfTranslationUnitFile()) {
addUsage(candidate, candidate.resolveBinding());
}
}
names= fRoot.getReferences(fTarget);
for (int i= 0; i < names.length; i++) {
IASTName candidate= names[i];
for (IASTName candidate : names) {
if (candidate.isPartOfTranslationUnitFile()) {
addUsage(candidate, candidate.resolveBinding());
}
}
names= CPPVisitor.getImplicitReferences(fRoot, fTarget);
for (IASTName candidate : names) {
if (candidate.isPartOfTranslationUnitFile()) {
addUsage(candidate, candidate.resolveBinding());
}