mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 21:05:37 +02:00
Bug 314635 - Marking occurrences is very slow on a large file due to searching for implicitReferences (interim fix)
This commit is contained in:
parent
ca9f612e04
commit
599285f0c3
3 changed files with 43 additions and 11 deletions
|
@ -54,6 +54,7 @@ import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
|
||||||
import org.eclipse.cdt.ui.tests.BaseUITestCase;
|
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.editor.SemanticHighlightings;
|
||||||
import org.eclipse.cdt.internal.ui.viewsupport.ISelectionListenerWithAST;
|
import org.eclipse.cdt.internal.ui.viewsupport.ISelectionListenerWithAST;
|
||||||
import org.eclipse.cdt.internal.ui.viewsupport.SelectionListenerWithASTManager;
|
import org.eclipse.cdt.internal.ui.viewsupport.SelectionListenerWithASTManager;
|
||||||
|
|
||||||
|
@ -116,7 +117,12 @@ public class MarkOccurrenceTest extends BaseUITestCase {
|
||||||
fProjectSetup.setUp();
|
fProjectSetup.setUp();
|
||||||
}
|
}
|
||||||
assertNotNull(fgHighlightRGB);
|
assertNotNull(fgHighlightRGB);
|
||||||
CUIPlugin.getDefault().getPreferenceStore().setValue(PreferenceConstants.EDITOR_MARK_OCCURRENCES, true);
|
final IPreferenceStore store = CUIPlugin.getDefault().getPreferenceStore();
|
||||||
|
store.setValue(PreferenceConstants.EDITOR_MARK_OCCURRENCES, true);
|
||||||
|
// TLETODO temporary fix for bug 314635
|
||||||
|
store.setValue(PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX
|
||||||
|
+ SemanticHighlightings.OVERLOADED_OPERATOR
|
||||||
|
+ PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_ENABLED_SUFFIX, true);
|
||||||
fEditor= openCEditor(new Path("/" + PROJECT + "/src/occurrences.cpp"));
|
fEditor= openCEditor(new Path("/" + PROJECT + "/src/occurrences.cpp"));
|
||||||
assertNotNull(fEditor);
|
assertNotNull(fEditor);
|
||||||
fTextWidget= fEditor.getViewer().getTextWidget();
|
fTextWidget= fEditor.getViewer().getTextWidget();
|
||||||
|
@ -153,6 +159,12 @@ public class MarkOccurrenceTest extends BaseUITestCase {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
|
final IPreferenceStore store = CUIPlugin.getDefault().getPreferenceStore();
|
||||||
|
store.setToDefault(PreferenceConstants.EDITOR_MARK_OCCURRENCES);
|
||||||
|
// TLETODO temporary fix for bug 314635
|
||||||
|
store.setToDefault(PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX
|
||||||
|
+ SemanticHighlightings.OVERLOADED_OPERATOR
|
||||||
|
+ PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_ENABLED_SUFFIX);
|
||||||
SelectionListenerWithASTManager.getDefault().removeListener(fEditor, fSelWASTListener);
|
SelectionListenerWithASTManager.getDefault().removeListener(fEditor, fSelWASTListener);
|
||||||
EditorTestHelper.closeAllEditors();
|
EditorTestHelper.closeAllEditors();
|
||||||
if (fProjectSetup != null) {
|
if (fProjectSetup != null) {
|
||||||
|
|
|
@ -3283,18 +3283,18 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
// try {
|
|
||||||
// IASTFileLocation location= name.getFileLocation();
|
|
||||||
// if (!document.get(location.getNodeOffset(), location.getNodeLength()).equals(name.toString())) {
|
|
||||||
// System.err.println("CEditor.updateOccurrenceAnnotations() invalid ast");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// } catch (BadLocationException exc) {
|
|
||||||
// }
|
|
||||||
IBinding binding= name.resolveBinding();
|
IBinding binding= name.resolveBinding();
|
||||||
if (binding != null) {
|
if (binding != null) {
|
||||||
OccurrencesFinder occurrencesFinder= new OccurrencesFinder();
|
OccurrencesFinder occurrencesFinder= new OccurrencesFinder();
|
||||||
if (occurrencesFinder.initialize(astRoot, name) == null) {
|
if (occurrencesFinder.initialize(astRoot, name) == null) {
|
||||||
|
// TLETODO temporary fix for bug 314635
|
||||||
|
boolean overloadedOperatorsEnabled = getPreferenceStore().getBoolean(
|
||||||
|
PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_PREFIX
|
||||||
|
+ SemanticHighlightings.OVERLOADED_OPERATOR
|
||||||
|
+ PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_ENABLED_SUFFIX);
|
||||||
|
if (!overloadedOperatorsEnabled) {
|
||||||
|
occurrencesFinder.setOptions(OccurrencesFinder.OPTION_EXCLUDE_IMPLICIT_REFERENCES);
|
||||||
|
}
|
||||||
locations= occurrencesFinder.getOccurrences();
|
locations= occurrencesFinder.getOccurrences();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2000, 2009 IBM Corporation and others.
|
* Copyright (c) 2000, 2010 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
|
||||||
|
@ -32,12 +32,19 @@ public class OccurrencesFinder implements IOccurrencesFinder {
|
||||||
|
|
||||||
public static final String ID= "OccurrencesFinder"; //$NON-NLS-1$
|
public static final String ID= "OccurrencesFinder"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If set, don't search for implicit references.
|
||||||
|
*/
|
||||||
|
public static final int OPTION_EXCLUDE_IMPLICIT_REFERENCES = 1;
|
||||||
|
|
||||||
private IASTTranslationUnit fRoot;
|
private IASTTranslationUnit fRoot;
|
||||||
private IASTName fSelectedNode;
|
private IASTName fSelectedNode;
|
||||||
private IBinding fTarget;
|
private IBinding fTarget;
|
||||||
|
|
||||||
private List<OccurrenceLocation> fResult;
|
private List<OccurrenceLocation> fResult;
|
||||||
private String fDescription;
|
private String fDescription;
|
||||||
|
|
||||||
|
private int fOptions;
|
||||||
|
|
||||||
public OccurrencesFinder() {
|
public OccurrencesFinder() {
|
||||||
super();
|
super();
|
||||||
|
@ -56,6 +63,15 @@ public class OccurrencesFinder implements IOccurrencesFinder {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify search options.
|
||||||
|
*
|
||||||
|
* @param options
|
||||||
|
*/
|
||||||
|
public void setOptions(int options) {
|
||||||
|
fOptions = options;
|
||||||
|
}
|
||||||
|
|
||||||
private void performSearch() {
|
private void performSearch() {
|
||||||
if (fResult == null) {
|
if (fResult == null) {
|
||||||
fResult= new ArrayList<OccurrenceLocation>();
|
fResult= new ArrayList<OccurrenceLocation>();
|
||||||
|
@ -71,7 +87,7 @@ public class OccurrencesFinder implements IOccurrencesFinder {
|
||||||
addUsage(candidate, candidate.resolveBinding());
|
addUsage(candidate, candidate.resolveBinding());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (canHaveImplicitReference(fTarget)) {
|
if (needImplicitReferences() && canHaveImplicitReference(fTarget)) {
|
||||||
names= CPPVisitor.getImplicitReferences(fRoot, fTarget);
|
names= CPPVisitor.getImplicitReferences(fRoot, fTarget);
|
||||||
for (IASTName candidate : names) {
|
for (IASTName candidate : names) {
|
||||||
if (candidate.isPartOfTranslationUnitFile()) {
|
if (candidate.isPartOfTranslationUnitFile()) {
|
||||||
|
@ -82,6 +98,10 @@ public class OccurrencesFinder implements IOccurrencesFinder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean needImplicitReferences() {
|
||||||
|
return (fOptions & OPTION_EXCLUDE_IMPLICIT_REFERENCES) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean canHaveImplicitReference(IBinding binding) {
|
private boolean canHaveImplicitReference(IBinding binding) {
|
||||||
final char[] op = Keywords.cOPERATOR;
|
final char[] op = Keywords.cOPERATOR;
|
||||||
final char[] nameCharArray = binding.getNameCharArray();
|
final char[] nameCharArray = binding.getNameCharArray();
|
||||||
|
|
Loading…
Add table
Reference in a new issue