1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

More mark occurrences tests and fixes

This commit is contained in:
Anton Leherbauer 2008-01-25 10:08:32 +00:00
parent c98379b752
commit ccabb31c65
7 changed files with 112 additions and 30 deletions

View file

@ -1408,13 +1408,13 @@ public class CPPVisitor {
boolean found = false; boolean found = false;
if( binding instanceof ICPPUsingDeclaration ){ if( binding instanceof ICPPUsingDeclaration ){
try { try {
found = ArrayUtil.contains( ((ICPPUsingDeclaration)binding).getDelegates(), candidate ); found = ArrayUtil.containsEqual( ((ICPPUsingDeclaration)binding).getDelegates(), candidate );
} catch ( DOMException e ) { } catch ( DOMException e ) {
} }
} else if( potential instanceof ICPPUsingDeclaration ){ } else if( potential instanceof ICPPUsingDeclaration ){
found = ( binding == ((ICPPDelegate)candidate).getBinding() ); found = sameBinding(binding, ((ICPPDelegate)candidate).getBinding());
} else { } else {
found = (binding == candidate ); found = sameBinding(binding, candidate);
} }
if( found ){ if( found ){
@ -1433,6 +1433,13 @@ public class CPPVisitor {
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
} }
private boolean sameBinding(IBinding binding1, IBinding binding2) {
if (binding1 == binding2)
return true;
if (binding1.equals(binding2))
return true;
return false;
}
public IASTName[] getReferences(){ public IASTName[] getReferences(){
if( idx < refs.length ){ if( idx < refs.length ){
IASTName [] temp = new IASTName[ idx ]; IASTName [] temp = new IASTName[ idx ];

View file

@ -1,3 +1,5 @@
#include "occurrences.h"
#define INT int #define INT int
#define FUNCTION_MACRO(arg) globalFunc(arg) #define FUNCTION_MACRO(arg) globalFunc(arg)
#define EMPTY_MACRO(arg) #define EMPTY_MACRO(arg)
@ -22,18 +24,19 @@ class Base1 {
Base1(); Base1();
~Base1(); ~Base1();
}; };
class Base2 {
};
Base1::~Base1() {} Base1::~Base1() {}
Base1::Base1() {} Base1::Base1() {}
Base2::Base2() {}
void Base2::foo() {}
class ClassContainer : Base1, Base2 { class ClassContainer : Base1, Base2 {
public: public:
static int staticPubField; static int staticPubField;
const int constPubField; const int constPubField;
const static int constStaticPubField; const static int constStaticPubField;
int pubField; size_t pubField;
static INT staticPubMethod(int arg) { static INT staticPubMethod(int arg) {
FUNCTION_MACRO(arg); FUNCTION_MACRO(arg);
@ -82,6 +85,7 @@ int namespaceFunc() {
case ONE: case THREE: case ONE: case THREE:
return 1; return 1;
} }
size_t size;
return namespaceVar; return namespaceVar;
} }
} }
@ -92,9 +96,12 @@ INT ClassContainer::pubMethod() {
return pubField + localVar; return pubField + localVar;
} }
using namespace ns;
//using ns::namespaceVar;
INT ClassContainer::staticPrivMethod() { INT ClassContainer::staticPrivMethod() {
CppStruct* st= new CppStruct(); CppStruct* st= new CppStruct();
st->structField= 1; st->structField= namespaceVar;
CppUnion un; CppUnion un;
un.unionField= 2; un.unionField= 2;
staticPubMethod(staticPubField); staticPubMethod(staticPubField);
@ -108,7 +115,7 @@ label:
template<int X> template<int X>
class ConstantTemplate { class ConstantTemplate {
public: public:
int foo(int y) { size_t foo(size_t y) {
return X; return X;
} }
}; };

View file

@ -0,0 +1,6 @@
class Base2 {
Base2();
void foo();
};
typedef int size_t;

View file

@ -19,7 +19,6 @@ import junit.framework.TestSuite;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.text.DocumentEvent; import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentListener; import org.eclipse.jface.text.IDocumentListener;
@ -125,7 +124,7 @@ public class BasicCEditorTest extends BaseUITestCase {
public void testEditTranslationUnit() throws Exception { public void testEditTranslationUnit() throws Exception {
final String file= "/ceditor/src/main.cpp"; final String file= "/ceditor/src/main.cpp";
fCProject= EditorTestHelper.createCProject("ceditor", "resources/ceditor", false); fCProject= EditorTestHelper.createCProject("ceditor", "resources/ceditor", false, false);
IFile mainFile= ResourceTestHelper.findFile(file); IFile mainFile= ResourceTestHelper.findFile(file);
assertNotNull(mainFile); assertNotNull(mainFile);
setUpEditor(mainFile); setUpEditor(mainFile);
@ -187,7 +186,7 @@ public class BasicCEditorTest extends BaseUITestCase {
// } // }
//} //}
public void testEditNewTranslationUnit() throws Exception { public void testEditNewTranslationUnit() throws Exception {
fCProject= EditorTestHelper.createCProject("ceditor", "resources/ceditor", false); fCProject= EditorTestHelper.createCProject("ceditor", "resources/ceditor", false, false);
IFile newFile= createFile(fCProject.getProject(), "Point.cpp", ""); IFile newFile= createFile(fCProject.getProject(), "Point.cpp", "");
assertNotNull(newFile); assertNotNull(newFile);
setUpEditor(newFile); setUpEditor(newFile);
@ -261,7 +260,7 @@ public class BasicCEditorTest extends BaseUITestCase {
public void testEditExternalTranslationUnit() throws Exception { public void testEditExternalTranslationUnit() throws Exception {
final String file= "/ceditor/src/main.cpp"; final String file= "/ceditor/src/main.cpp";
fCProject= EditorTestHelper.createCProject("ceditor", "resources/ceditor", false); fCProject= EditorTestHelper.createCProject("ceditor", "resources/ceditor", false, false);
IFile mainFile= ResourceTestHelper.findFile(file); IFile mainFile= ResourceTestHelper.findFile(file);
assertNotNull(mainFile); assertNotNull(mainFile);
File tmpFile= File.createTempFile("tmp", ".cpp"); File tmpFile= File.createTempFile("tmp", ".cpp");
@ -306,7 +305,7 @@ public class BasicCEditorTest extends BaseUITestCase {
colorMgr.bindColor(ICColorConstants.PP_DIRECTIVE, new RGB(7,7,7)); colorMgr.bindColor(ICColorConstants.PP_DIRECTIVE, new RGB(7,7,7));
final Color ppDirectiveColor= colorMgr.getColor(ICColorConstants.PP_DIRECTIVE); final Color ppDirectiveColor= colorMgr.getColor(ICColorConstants.PP_DIRECTIVE);
final String file= "/ceditor/src/main.cpp"; final String file= "/ceditor/src/main.cpp";
fCProject= EditorTestHelper.createCProject("ceditor", "resources/ceditor", false); fCProject= EditorTestHelper.createCProject("ceditor", "resources/ceditor", false, false);
setUpEditor(file); setUpEditor(file);
fSourceViewer= EditorTestHelper.getSourceViewer(fEditor); fSourceViewer= EditorTestHelper.getSourceViewer(fEditor);
assertTrue(EditorTestHelper.joinReconciler(fSourceViewer, 0, 10000, 100)); assertTrue(EditorTestHelper.joinReconciler(fSourceViewer, 0, 10000, 100));

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2000, 2007 IBM Corporation and others. * Copyright (c) 2000, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -72,7 +72,6 @@ import org.eclipse.ui.wizards.datatransfer.IImportStructureProvider;
import org.eclipse.ui.wizards.datatransfer.ImportOperation; import org.eclipse.ui.wizards.datatransfer.ImportOperation;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.index.IIndexManager; import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.CProjectHelper;
@ -434,11 +433,15 @@ public class EditorTestHelper {
} }
public static ICProject createCProject(String project, String externalSourceFolder) throws CoreException { public static ICProject createCProject(String project, String externalSourceFolder) throws CoreException {
return createCProject(project, externalSourceFolder, false); return createCProject(project, externalSourceFolder, false, false);
} }
public static ICProject createCProject(String project, String externalSourceFolder, boolean linkSourceFolder) throws CoreException { public static ICProject createCProject(String project, String externalSourceFolder, boolean linkSourceFolder) throws CoreException {
ICProject cProject= CProjectHelper.createCCProject(project, "bin", IPDOMManager.ID_NO_INDEXER); return createCProject(project, externalSourceFolder, linkSourceFolder, false);
}
public static ICProject createCProject(String project, String externalSourceFolder, boolean linkSourceFolder, boolean useIndexer) throws CoreException {
ICProject cProject= CProjectHelper.createCCProject(project, "bin", useIndexer ? IIndexManager.ID_FAST_INDEXER : IIndexManager.ID_NO_INDEXER);
IFolder folder; IFolder folder;
if (linkSourceFolder) if (linkSourceFolder)
folder= ResourceHelper.createLinkedFolder((IProject) cProject.getUnderlyingResource(), new Path("src"), CTestPlugin.getDefault(), new Path(externalSourceFolder)); folder= ResourceHelper.createLinkedFolder((IProject) cProject.getUnderlyingResource(), new Path("src"), CTestPlugin.getDefault(), new Path(externalSourceFolder));
@ -449,6 +452,10 @@ public class EditorTestHelper {
Assert.assertNotNull(folder); Assert.assertNotNull(folder);
Assert.assertTrue(folder.exists()); Assert.assertTrue(folder.exists());
CProjectHelper.addCContainer(cProject, "src"); CProjectHelper.addCContainer(cProject, "src");
if (useIndexer) {
IIndexManager indexManager= CCorePlugin.getIndexManager();
indexManager.joinIndexer(5000, new NullProgressMonitor());
}
return cProject; return cProject;
} }

View file

@ -16,7 +16,6 @@ import java.util.Iterator;
import junit.extensions.TestSetup; import junit.extensions.TestSetup;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
@ -50,6 +49,7 @@ import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants; import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.internal.ui.editor.CEditor; import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.viewsupport.ISelectionListenerWithAST; import org.eclipse.cdt.internal.ui.viewsupport.ISelectionListenerWithAST;
@ -61,7 +61,7 @@ import org.eclipse.cdt.internal.ui.viewsupport.SelectionListenerWithASTManager;
* *
* @since 5.0 * @since 5.0
*/ */
public class MarkOccurrenceTest extends TestCase { public class MarkOccurrenceTest extends BaseUITestCase {
private static final String PROJECT = "MarkOccurrenceTest"; private static final String PROJECT = "MarkOccurrenceTest";
@ -87,7 +87,7 @@ public class MarkOccurrenceTest extends TestCase {
} }
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
fCProject= EditorTestHelper.createCProject(PROJECT, "resources/ceditor"); fCProject= EditorTestHelper.createCProject(PROJECT, "resources/ceditor", false, true);
} }
protected void tearDown () throws Exception { protected void tearDown () throws Exception {
if (fCProject != null) if (fCProject != null)
@ -193,6 +193,34 @@ public class MarkOccurrenceTest extends TestCase {
assertOccurrencesInWidget(); assertOccurrencesInWidget();
} }
public void testMarkTypeOccurrences3() {
try {
fMatch= fFindReplaceDocumentAdapter.find(0, "Base2", true, true, true, false);
} catch (BadLocationException e) {
fail();
}
assertNotNull(fMatch);
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(3);
assertOccurrencesInWidget();
}
public void testMarkTypedefOccurrences() {
try {
fMatch= fFindReplaceDocumentAdapter.find(0, "size_t", true, true, true, false);
} catch (BadLocationException e) {
fail();
}
assertNotNull(fMatch);
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(4);
assertOccurrencesInWidget();
}
public void testMarkClassTemplateOccurrences() { public void testMarkClassTemplateOccurrences() {
try { try {
fMatch= fFindReplaceDocumentAdapter.find(0, "TemplateClass", true, true, true, false); fMatch= fFindReplaceDocumentAdapter.find(0, "TemplateClass", true, true, true, false);
@ -380,6 +408,34 @@ public class MarkOccurrenceTest extends TestCase {
assertOccurrencesInWidget(); assertOccurrencesInWidget();
} }
public void testMarkNamespaceOccurrences() {
try {
fMatch= fFindReplaceDocumentAdapter.find(0, "ns", true, true, true, false);
} catch (BadLocationException e) {
fail();
}
assertNotNull(fMatch);
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(3);
assertOccurrencesInWidget();
}
public void testMarkNamespaceVariableOccurrences() {
try {
fMatch= fFindReplaceDocumentAdapter.find(0, "namespaceVar", true, true, true, false);
} catch (BadLocationException e) {
fail();
}
assertNotNull(fMatch);
fEditor.selectAndReveal(fMatch.getOffset(), fMatch.getLength());
assertOccurrences(4);
assertOccurrencesInWidget();
}
public void testNoOccurrencesIfDisabled() { public void testNoOccurrencesIfDisabled() {
CUIPlugin.getDefault().getPreferenceStore().setValue(PreferenceConstants.EDITOR_MARK_OCCURRENCES, false); CUIPlugin.getDefault().getPreferenceStore().setValue(PreferenceConstants.EDITOR_MARK_OCCURRENCES, false);
fOccurrences= Integer.MAX_VALUE; fOccurrences= Integer.MAX_VALUE;

View file

@ -1093,8 +1093,6 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
public static final String INACTIVE_CODE_ENABLE = "inactiveCodeEnable"; //$NON-NLS-1$ public static final String INACTIVE_CODE_ENABLE = "inactiveCodeEnable"; //$NON-NLS-1$
/** Preference key for inactive code painter color */ /** Preference key for inactive code painter color */
public static final String INACTIVE_CODE_COLOR = "inactiveCodeColor"; //$NON-NLS-1$ public static final String INACTIVE_CODE_COLOR = "inactiveCodeColor"; //$NON-NLS-1$
/** Preference key for code formatter tab size */
private final static String CODE_FORMATTER_TAB_SIZE = DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE;
/** Preference key for inserting spaces rather than tabs */ /** Preference key for inserting spaces rather than tabs */
public final static String SPACES_FOR_TABS = DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR; public final static String SPACES_FOR_TABS = DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR;
/** Preference key for automatically closing strings */ /** Preference key for automatically closing strings */
@ -1383,11 +1381,6 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
return; return;
} }
if (CODE_FORMATTER_TAB_SIZE.equals(property) && isTabsToSpacesConversionEnabled()) {
uninstallTabsToSpacesConverter();
installTabsToSpacesConverter();
}
if (DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE.equals(property) if (DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE.equals(property)
|| DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE.equals(property) || DefaultCodeFormatterConstants.FORMATTER_INDENTATION_SIZE.equals(property)
|| DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR.equals(property)) { || DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR.equals(property)) {
@ -1395,6 +1388,12 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
int tabWidth= getSourceViewerConfiguration().getTabWidth(asv); int tabWidth= getSourceViewerConfiguration().getTabWidth(asv);
if (textWidget.getTabs() != tabWidth) if (textWidget.getTabs() != tabWidth)
textWidget.setTabs(tabWidth); textWidget.setTabs(tabWidth);
if (isTabsToSpacesConversionEnabled()) {
uninstallTabsToSpacesConverter();
installTabsToSpacesConverter();
} else {
updateIndentPrefixes();
}
return; return;
} }
@ -2596,13 +2595,14 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
protected String[] collectContextMenuPreferencePages() { protected String[] collectContextMenuPreferencePages() {
// Add C/C++ Editor relevant pages // Add C/C++ Editor relevant pages
String[] parentPrefPageIds = super.collectContextMenuPreferencePages(); String[] parentPrefPageIds = super.collectContextMenuPreferencePages();
String[] prefPageIds = new String[parentPrefPageIds.length + 9]; String[] prefPageIds = new String[parentPrefPageIds.length + 10];
int nIds = 0; int nIds = 0;
prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.CEditorPreferencePage"; //$NON-NLS-1$ prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.CEditorPreferencePage"; //$NON-NLS-1$
prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.CodeAssistPreferencePage"; //$NON-NLS-1$ prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.CodeAssistPreferencePage"; //$NON-NLS-1$
prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.CodeAssistPreferenceAdvanced"; //$NON-NLS-1$ prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.CodeAssistPreferenceAdvanced"; //$NON-NLS-1$
prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.HoverPreferencePage"; //$NON-NLS-1$ prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.HoverPreferencePage"; //$NON-NLS-1$
prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.FoldingPreferencePage"; //$NON-NLS-1$ prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.FoldingPreferencePage"; //$NON-NLS-1$
prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.MarkOccurrencesPreferencePage"; //$NON-NLS-1$
prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.CodeColoringPreferencePage"; //$NON-NLS-1$ prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.CodeColoringPreferencePage"; //$NON-NLS-1$
prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.TemplatePreferencePage"; //$NON-NLS-1$ prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.TemplatePreferencePage"; //$NON-NLS-1$
prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.SmartTypingPreferencePage"; //$NON-NLS-1$ prefPageIds[nIds++] = "org.eclipse.cdt.ui.preferences.SmartTypingPreferencePage"; //$NON-NLS-1$
@ -2645,7 +2645,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
} }
// delayed installation of mark occurrences // delayed installation of mark occurrences
if (isMarkingOccurrences() && !fMarkOccurrenceAnnotations) if (!fMarkOccurrenceAnnotations && isMarkingOccurrences())
getSite().getShell().getDisplay().asyncExec(new Runnable() { getSite().getShell().getDisplay().asyncExec(new Runnable() {
public void run() { public void run() {
installOccurrencesFinder(true); installOccurrencesFinder(true);