1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-28 19:35:36 +02:00

bug 268359 - semantic highlighting for overloaded operators

This commit is contained in:
Mike Kucera 2009-03-13 14:40:41 +00:00
parent 7f116f9120
commit e866b579f7
9 changed files with 237 additions and 88 deletions

View file

@ -92,6 +92,8 @@ struct CppStruct {
union CppUnion {
int unionField;
CppUnion operator+(CppUnion);
CppUnion operator[](int);
};
typedef CppUnion TUnion;
@ -119,6 +121,7 @@ INT ClassContainer::staticPrivMethod() {
CppUnion un;
un.unionField= 2;
staticPubMethod(staticPrivField);
un + un[6];
label:
FUNCTION_MACRO(0);
if (un.unionField < st->structField) goto label;

View file

@ -45,7 +45,7 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
createPosition(45, 15, 15),
createPosition(59, 21, 20),
createPosition(60, 15, 15),
createPosition(120, 20, 15),
createPosition(122, 20, 15),
};
if (PRINT_POSITIONS) System.out.println(toString(actual));
assertEqualPositions(expected, actual);
@ -73,13 +73,13 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
createPosition(81, 8, 5),
createPosition(89, 8, 11),
createPosition(93, 8, 10),
createPosition(107, 11, 9),
createPosition(112, 11, 8),
createPosition(117, 8, 11),
createPosition(119, 7, 10),
createPosition(120, 20, 15),
createPosition(123, 11, 10),
createPosition(123, 28, 11),
createPosition(109, 11, 9),
createPosition(114, 11, 8),
createPosition(119, 8, 11),
createPosition(121, 7, 10),
createPosition(122, 20, 15),
createPosition(126, 11, 10),
createPosition(126, 28, 11),
};
if (PRINT_POSITIONS) System.out.println(toString(actual));
assertEqualPositions(expected, actual);
@ -96,9 +96,11 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
createPosition(64, 15, 16),
createPosition(65, 8, 10),
createPosition(79, 4, 13),
createPosition(106, 4, 26),
createPosition(110, 4, 25),
createPosition(115, 4, 32),
createPosition(94, 13, 9),
createPosition(95, 13, 10),
createPosition(108, 4, 26),
createPosition(112, 4, 25),
createPosition(117, 4, 32),
};
if (PRINT_POSITIONS) System.out.println(toString(actual));
assertEqualPositions(expected, actual);
@ -114,12 +116,14 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
createPosition(64, 15, 16),
createPosition(65, 8, 10),
createPosition(79, 4, 13),
createPosition(106, 4, 26),
createPosition(110, 4, 25),
createPosition(115, 4, 32),
createPosition(116, 23, 9),
createPosition(120, 4, 15),
createPosition(127, 13, 9),
createPosition(94, 13, 9),
createPosition(95, 13, 10),
createPosition(108, 4, 26),
createPosition(112, 4, 25),
createPosition(117, 4, 32),
createPosition(118, 23, 9),
createPosition(122, 4, 15),
createPosition(130, 13, 9),
};
Position[] actual= getSemanticHighlightingPositions();
if (PRINT_POSITIONS) System.out.println(toString(actual));
@ -129,7 +133,7 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
public void testStaticMethodInvocationHighlighting() throws Exception {
setUpSemanticHighlighting(SemanticHighlightings.STATIC_METHOD_INVOCATION);
Position[] expected= new Position[] {
createPosition(120, 4, 15),
createPosition(122, 4, 15),
};
Position[] actual= getSemanticHighlightingPositions();
if (PRINT_POSITIONS) System.out.println(toString(actual));
@ -139,10 +143,10 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
public void testLocalVariableDeclarationHighlighting() throws Exception {
setUpSemanticHighlighting(SemanticHighlightings.LOCAL_VARIABLE_DECLARATION);
Position[] expected= new Position[] {
createPosition(111, 8, 8),
createPosition(116, 15, 2),
createPosition(118, 13, 2),
createPosition(126, 13, 8),
createPosition(113, 8, 8),
createPosition(118, 15, 2),
createPosition(120, 13, 2),
createPosition(129, 13, 8),
};
Position[] actual= getSemanticHighlightingPositions();
if (PRINT_POSITIONS) System.out.println(toString(actual));
@ -152,12 +156,14 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
public void testLocalVariableReferencesHighlighting() throws Exception {
setUpSemanticHighlighting(SemanticHighlightings.LOCAL_VARIABLE);
Position[] expected= new Position[] {
createPosition(112, 22, 8),
createPosition(117, 4, 2),
createPosition(114, 22, 8),
createPosition(119, 4, 2),
createPosition(123, 8, 2),
createPosition(123, 24, 2),
createPosition(127, 4, 8),
createPosition(121, 4, 2),
createPosition(123, 4, 2),
createPosition(123, 9, 2),
createPosition(126, 8, 2),
createPosition(126, 24, 2),
createPosition(130, 4, 8),
};
Position[] actual= getSemanticHighlightingPositions();
if (PRINT_POSITIONS) System.out.println(toString(actual));
@ -193,8 +199,8 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
createPosition(79, 27, 2),
createPosition(85, 15, 2),
createPosition(85, 66, 2),
createPosition(133, 14, 1),
createPosition(136, 9, 1),
createPosition(136, 14, 1),
createPosition(139, 9, 1),
};
if (PRINT_POSITIONS) System.out.println(toString(actual));
assertEqualPositions(expected, actual);
@ -241,13 +247,16 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
createPosition(85, 70, 5),
createPosition(88, 7, 9),
createPosition(92, 6, 8),
createPosition(96, 8, 8),
createPosition(106, 4, 14),
createPosition(110, 4, 14),
createPosition(115, 4, 14),
createPosition(116, 4, 9),
createPosition(118, 4, 8),
createPosition(126, 4, 8),
createPosition(94, 4, 8),
createPosition(94, 23, 8),
createPosition(95, 4, 8),
createPosition(98, 8, 8),
createPosition(108, 4, 14),
createPosition(112, 4, 14),
createPosition(117, 4, 14),
createPosition(118, 4, 9),
createPosition(120, 4, 8),
createPosition(129, 4, 8),
};
if (PRINT_POSITIONS) System.out.println(toString(actual));
assertEqualPositions(expected, actual);
@ -260,9 +269,9 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
createPosition(12, 5, 10),
createPosition(13, 12, 16),
createPosition(21, 16, 10),
createPosition(100, 8, 13),
createPosition(134, 4, 1),
createPosition(141, 10, 1),
createPosition(102, 8, 13),
createPosition(137, 4, 1),
createPosition(144, 10, 1),
};
if (PRINT_POSITIONS) System.out.println(toString(actual));
assertEqualPositions(expected, actual);
@ -276,11 +285,11 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
createPosition(13, 12, 16),
createPosition(21, 16, 10),
createPosition(32, 8, 10),
createPosition(100, 8, 13),
createPosition(101, 1, 16),
createPosition(128, 4, 11),
createPosition(134, 4, 1),
createPosition(141, 10, 1),
createPosition(102, 8, 13),
createPosition(103, 1, 16),
createPosition(131, 4, 11),
createPosition(137, 4, 1),
createPosition(144, 10, 1),
};
if (PRINT_POSITIONS) System.out.println(toString(actual));
assertEqualPositions(expected, actual);
@ -295,8 +304,8 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
createPosition(9, 4, 14),
createPosition(10, 11, 20),
createPosition(33, 15, 20),
createPosition(99, 8, 12),
createPosition(102, 8, 12),
createPosition(101, 8, 12),
createPosition(104, 8, 12),
};
if (PRINT_POSITIONS) System.out.println(toString(actual));
assertEqualPositions(expected, actual);
@ -309,7 +318,7 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
createPosition(0, 8, 3),
createPosition(1, 8, 14),
createPosition(2, 8, 11),
createPosition(140, 8, 5),
createPosition(143, 8, 5),
};
if (PRINT_POSITIONS) System.out.println(toString(actual));
assertEqualPositions(expected, actual);
@ -321,11 +330,11 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
Position[] expected= new Position[] {
createPosition(14, 4, 11),
createPosition(31, 8, 14),
createPosition(106, 0, 3),
createPosition(110, 0, 3),
createPosition(115, 0, 3),
createPosition(122, 4, 14),
createPosition(141, 0, 5),
createPosition(108, 0, 3),
createPosition(112, 0, 3),
createPosition(117, 0, 3),
createPosition(125, 4, 14),
createPosition(144, 0, 5),
};
if (PRINT_POSITIONS) System.out.println(toString(actual));
assertEqualPositions(expected, actual);
@ -338,7 +347,7 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
createPosition(41, 21, 10),
createPosition(56, 22, 11),
createPosition(71, 22, 11),
createPosition(96, 17, 6),
createPosition(98, 17, 6),
};
if (PRINT_POSITIONS) System.out.println(toString(actual));
assertEqualPositions(expected, actual);
@ -348,7 +357,7 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
setUpSemanticHighlighting(SemanticHighlightings.NAMESPACE);
Position[] actual= getSemanticHighlightingPositions();
Position[] expected= new Position[] {
createPosition(98, 10, 2),
createPosition(100, 10, 2),
};
if (PRINT_POSITIONS) System.out.println(toString(actual));
assertEqualPositions(expected, actual);
@ -358,8 +367,8 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
setUpSemanticHighlighting(SemanticHighlightings.LABEL);
Position[] actual= getSemanticHighlightingPositions();
Position[] expected= new Position[] {
createPosition(121, 0, 5),
createPosition(123, 46, 5),
createPosition(124, 0, 5),
createPosition(126, 46, 5),
};
if (PRINT_POSITIONS) System.out.println(toString(actual));
assertEqualPositions(expected, actual);
@ -382,7 +391,7 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
setUpSemanticHighlighting(SemanticHighlightings.PROBLEM);
Position[] actual= getSemanticHighlightingPositions();
Position[] expected= new Position[] {
createPosition(124, 4, 13),
createPosition(127, 4, 13),
};
if (PRINT_POSITIONS) System.out.println(toString(actual));
assertEqualPositions(expected, actual);
@ -392,8 +401,20 @@ public class SemanticHighlightingTest extends AbstractSemanticHighlightingTest {
setUpSemanticHighlighting(SemanticHighlightings.EXTERNAL_SDK);
Position[] actual= getSemanticHighlightingPositions();
Position[] expected= new Position[] {
createPosition(127, 13, 9),
createPosition(128, 4, 11),
createPosition(130, 13, 9),
createPosition(131, 4, 11),
};
if (PRINT_POSITIONS) System.out.println(toString(actual));
assertEqualPositions(expected, actual);
}
public void testOverloadedOperatorHighlighting() throws Exception {
setUpSemanticHighlighting(SemanticHighlightings.OVERLOADED_OPERATOR);
Position[] actual= getSemanticHighlightingPositions();
Position[] expected= new Position[] {
createPosition(123, 7, 1),
createPosition(123, 11, 1),
createPosition(123, 13, 1),
};
if (PRINT_POSITIONS) System.out.println(toString(actual));
assertEqualPositions(expected, actual);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2008 QNX Software Systems and others.
* Copyright (c) 2000, 2009 QNX Software Systems 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
@ -73,6 +73,7 @@ public final class CEditorMessages extends NLS {
public static String SemanticHighlighting_templateParameter;
public static String SemanticHighlighting_functionDeclaration;
public static String SemanticHighlighting_function;
public static String SemanticHighlighting_overloadedOperators;
public static String SemanticHighlighting_macroSubstitution;
public static String SemanticHighlighting_macroDefintion;
public static String SemanticHighlighting_typeDef;

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
@ -77,6 +77,7 @@ SemanticHighlighting_templateArguments= Template arguments
SemanticHighlighting_templateParameter= Template parameters
SemanticHighlighting_functionDeclaration= Function declarations
SemanticHighlighting_function= Functions
SemanticHighlighting_overloadedOperators= Overloaded Operators
SemanticHighlighting_macroSubstitution= Macro references
SemanticHighlighting_macroDefintion= Macro definitions
SemanticHighlighting_typeDef= Typedefs

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
@ -72,6 +72,8 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
shouldVisitStatements= true;
shouldVisitDeclarators= true;
shouldVisitNamespaces= true;
shouldVisitImplicitNames = true;
shouldVisitImplicitNameAlternates = true;
}
/** The semantic token */

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
@ -22,6 +22,7 @@ import org.eclipse.swt.graphics.RGB;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTProblem;
@ -57,6 +58,8 @@ import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator;
/**
* Semantic highlightings.
* Derived from JDT.
@ -176,6 +179,12 @@ public class SemanticHighlightings {
* A named preference part that controls the highlighting of external SDK.
*/
public static final String EXTERNAL_SDK="externalSDK"; //$NON-NLS-1$
/**
* A named preference part that controls the highlighting of operators that have been overloaded.
*/
public static final String OVERLOADED_OPERATOR="overloadedOperator"; //$NON-NLS-1$
/** Init debugging mode */
private static final boolean DEBUG= "true".equalsIgnoreCase(Platform.getDebugOption("org.eclipse.cdt.ui/debug/SemanticHighlighting")); //$NON-NLS-1$//$NON-NLS-2$
@ -574,6 +583,8 @@ public class SemanticHighlightings {
@Override
public boolean consumes(SemanticToken token) {
IASTNode node= token.getNode();
if (node instanceof IASTImplicitName)
return false;
if (node instanceof IASTName) {
IASTName name= (IASTName)node;
if (name instanceof ICPPASTQualifiedName && name.isReference()) {
@ -739,6 +750,8 @@ public class SemanticHighlightings {
@Override
public boolean consumes(SemanticToken token) {
IASTNode node= token.getNode();
if (node instanceof IASTImplicitName)
return false;
if (node instanceof IASTName) {
IASTName name= (IASTName)node;
if (name instanceof ICPPASTQualifiedName && name.isReference()) {
@ -1867,6 +1880,9 @@ public class SemanticHighlightings {
if (name instanceof ICPPASTQualifiedName) {
return false;
}
if (name instanceof IASTImplicitName) {
return false;
}
if (name.isReference()) {
IBinding binding= token.getBinding();
IIndex index= token.getRoot().getIndex();
@ -1906,6 +1922,82 @@ public class SemanticHighlightings {
}
}
/**
* Semantic highlighting for functions.
*/
private static final class OverloadedOperatorHighlighting extends SemanticHighlighting {
/*
* @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#getPreferenceKey()
*/
@Override
public String getPreferenceKey() {
return OVERLOADED_OPERATOR;
}
/*
* @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#getDefaultTextColor()
*/
@Override
public RGB getDefaultTextColor() {
return new RGB(200, 100, 0); // orange
}
/*
* @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#getDefaultTextStyleBold()
*/
@Override
public boolean isBoldByDefault() {
return false;
}
/*
* @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#isItalicByDefault()
*/
@Override
public boolean isItalicByDefault() {
return false;
}
/*
* @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#isEnabledByDefault()
*/
@Override
public boolean isEnabledByDefault() {
return true;
}
/*
* @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#getDisplayName()
*/
@Override
public String getDisplayName() {
return CEditorMessages.SemanticHighlighting_overloadedOperators;
}
/*
* @see org.eclipse.cdt.internal.ui.editor.SemanticHighlighting#consumes(org.eclipse.cdt.internal.ui.editor.SemanticToken)
*/
@Override
public boolean consumes(SemanticToken token) {
IASTNode node = token.getNode();
// so far we only have implicit names for overloaded operators and destructors, so this works
if(node instanceof IASTImplicitName) {
IASTImplicitName name = (IASTImplicitName) node;
IBinding binding = name.resolveBinding();
if(binding instanceof ICPPMethod && ((ICPPMethod)binding).isImplicit()) {
return false;
}
char[] chars = name.toCharArray();
if(chars[0] == '~' || OverloadableOperator.isNew(chars) || OverloadableOperator.isDelete(chars)) {
return false;
}
return true;
}
return false;
}
}
/**
* A named preference that controls the given semantic highlighting's color.
*
@ -1985,6 +2077,7 @@ public class SemanticHighlightings {
new LocalVariableHighlighting(),
new GlobalVariableHighlighting(),
new TemplateParameterHighlighting(), // before template arguments!
new OverloadedOperatorHighlighting(), // before both method and function
new MethodHighlighting(), // before types to get ctors
new EnumHighlighting(),
new MacroDefinitionHighlighting(),

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
@ -870,28 +870,30 @@ class CEditorColoringConfigurationBlock extends AbstractConfigurationBlock {
{ createHighlightedRange( 7, 6, 9, SemanticHighlightings.PARAMETER_VARIABLE) },
{ createHighlightedRange( 7, 22, 7, SemanticHighlightings.EXTERNAL_SDK), createHighlightedRange( 7, 22, 7, SemanticHighlightings.FUNCTION) },
{ createHighlightedRange( 7, 30, 6, SemanticHighlightings.GLOBAL_VARIABLE) },
{ createHighlightedRange( 8, 9, 9, SemanticHighlightings.PARAMETER_VARIABLE) },
{ createHighlightedRange(10, 6, 7, SemanticHighlightings.CLASS) },
{ createHighlightedRange(12, 7, 6, SemanticHighlightings.ENUM) },
{ createHighlightedRange(12, 16, 4, SemanticHighlightings.ENUMERATOR) },
{ createHighlightedRange(12, 22, 3, SemanticHighlightings.ENUMERATOR) },
{ createHighlightedRange(12, 27, 3, SemanticHighlightings.ENUMERATOR) },
{ createHighlightedRange(13, 14, 11, SemanticHighlightings.STATIC_FIELD), createHighlightedRange(13, 14, 11, SemanticHighlightings.FIELD) },
{ createHighlightedRange(14, 6, 5, SemanticHighlightings.FIELD) },
{ createHighlightedRange(15, 10, 6, SemanticHighlightings.ENUM) },
{ createHighlightedRange(15, 17, 7, SemanticHighlightings.METHOD_DECLARATION), createHighlightedRange(15, 17, 7, SemanticHighlightings.METHOD) },
{ createHighlightedRange(16, 7, 6, SemanticHighlightings.METHOD_DECLARATION), createHighlightedRange(16, 7, 6, SemanticHighlightings.METHOD) },
{ createHighlightedRange(16, 14, 6, SemanticHighlightings.ENUM) },
{ createHighlightedRange(16, 21, 1, SemanticHighlightings.PARAMETER_VARIABLE) },
{ createHighlightedRange(17, 8, 5, SemanticHighlightings.LOCAL_VARIABLE_DECLARATION) },
{ createHighlightedRange(17, 20, 5, SemanticHighlightings.MACRO_REFERENCE) },
{ createHighlightedRange(18, 0, 5, SemanticHighlightings.LABEL) },
{ createHighlightedRange(18, 7, 6, SemanticHighlightings.FUNCTION) },
{ createHighlightedRange(18, 14, 5, SemanticHighlightings.LOCAL_VARIABLE) },
{ createHighlightedRange(19, 4, 7, SemanticHighlightings.METHOD) },
{ createHighlightedRange(20, 4, 12, SemanticHighlightings.STATIC_METHOD_INVOCATION), createHighlightedRange(20, 4, 12, SemanticHighlightings.METHOD) },
{ createHighlightedRange(21, 4, 7, SemanticHighlightings.PROBLEM) },
{ createHighlightedRange(23, 14, 12, SemanticHighlightings.METHOD_DECLARATION), createHighlightedRange(23, 14, 12, SemanticHighlightings.METHOD) },
{ createHighlightedRange( 8, 2, 4, SemanticHighlightings.GLOBAL_VARIABLE) },
{ createHighlightedRange( 8, 7, 2, SemanticHighlightings.OVERLOADED_OPERATOR) },
{ createHighlightedRange( 9, 9, 9, SemanticHighlightings.PARAMETER_VARIABLE) },
{ createHighlightedRange(11, 6, 7, SemanticHighlightings.CLASS) },
{ createHighlightedRange(13, 7, 6, SemanticHighlightings.ENUM) },
{ createHighlightedRange(13, 16, 4, SemanticHighlightings.ENUMERATOR) },
{ createHighlightedRange(13, 22, 3, SemanticHighlightings.ENUMERATOR) },
{ createHighlightedRange(13, 27, 3, SemanticHighlightings.ENUMERATOR) },
{ createHighlightedRange(14, 14, 11, SemanticHighlightings.STATIC_FIELD), createHighlightedRange(13, 14, 11, SemanticHighlightings.FIELD) },
{ createHighlightedRange(15, 6, 5, SemanticHighlightings.FIELD) },
{ createHighlightedRange(16, 10, 6, SemanticHighlightings.ENUM) },
{ createHighlightedRange(16, 17, 7, SemanticHighlightings.METHOD_DECLARATION), createHighlightedRange(15, 17, 7, SemanticHighlightings.METHOD) },
{ createHighlightedRange(17, 7, 6, SemanticHighlightings.METHOD_DECLARATION), createHighlightedRange(16, 7, 6, SemanticHighlightings.METHOD) },
{ createHighlightedRange(17, 14, 6, SemanticHighlightings.ENUM) },
{ createHighlightedRange(17, 21, 1, SemanticHighlightings.PARAMETER_VARIABLE) },
{ createHighlightedRange(18, 8, 5, SemanticHighlightings.LOCAL_VARIABLE_DECLARATION) },
{ createHighlightedRange(18, 20, 5, SemanticHighlightings.MACRO_REFERENCE) },
{ createHighlightedRange(19, 0, 5, SemanticHighlightings.LABEL) },
{ createHighlightedRange(19, 7, 6, SemanticHighlightings.FUNCTION) },
{ createHighlightedRange(19, 14, 5, SemanticHighlightings.LOCAL_VARIABLE) },
{ createHighlightedRange(20, 4, 7, SemanticHighlightings.METHOD) },
{ createHighlightedRange(21, 4, 12, SemanticHighlightings.STATIC_METHOD_INVOCATION), createHighlightedRange(20, 4, 12, SemanticHighlightings.METHOD) },
{ createHighlightedRange(22, 4, 7, SemanticHighlightings.PROBLEM) },
{ createHighlightedRange(24, 14, 12, SemanticHighlightings.METHOD_DECLARATION), createHighlightedRange(23, 14, 12, SemanticHighlightings.METHOD) },
};
}

View file

@ -6,6 +6,7 @@ using namespace std;
typedef unsigned int uint;
int static myfunc(uint parameter) {
if (parameter == 0) fprintf(stdout, "zero\n");
cout << "hello\n";
return parameter - 1;
}
class MyClass {

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
@ -9,6 +9,7 @@
* IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
* Ed Swartz (Nokia)
* Mike Kucera (IBM)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search.actions;
@ -39,6 +40,8 @@ import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.ASTNameCollector;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTNodeSelector;
@ -65,6 +68,7 @@ import org.eclipse.cdt.core.model.util.CElementBaseLabels;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.model.ASTCache.ASTRunnable;
import org.eclipse.cdt.internal.core.model.ext.CElementHandleFactory;
import org.eclipse.cdt.internal.core.model.ext.ICElementHandle;
@ -150,8 +154,29 @@ public class OpenDeclarationsAction extends SelectionParseAction implements ASTR
int selectionLength = fTextSelection.getLength();
final IASTNodeSelector nodeSelector = ast.getNodeSelector(null);
IASTName searchName= nodeSelector.findEnclosingName(selectionStart, selectionLength);
if (searchName != null) { // just right, only one name selected
if (searchName == null) {
IASTName implicit = nodeSelector.findEnclosingImplicitName(selectionStart, selectionLength);
if(implicit != null) {
IASTImplicitNameOwner owner = (IASTImplicitNameOwner) implicit.getParent();
IASTImplicitName[] implicits = owner.getImplicitNames();
// there may be more than one name in the same spot
if(implicits.length > 0) {
List<IName> allNames = new ArrayList<IName>();
for(IASTImplicitName name : implicits) {
if(((ASTNode)name).getOffset() == ((ASTNode)implicit).getOffset()) {
IBinding binding = name.resolveBinding(); // guaranteed to resolve
IName[] declNames = findNames(fIndex, ast, KIND_OTHER, binding);
allNames.addAll(Arrays.asList(declNames));
}
}
if(navigateViaCElements(fWorkingCopy.getCProject(), fIndex, allNames.toArray(new IName[0])))
return Status.OK_STATUS;
}
}
}
else {
boolean found= false;
final IASTNode parent = searchName.getParent();
if (parent instanceof IASTPreprocessorIncludeStatement) {