foo(int)
+ * @since 5.1
+ */
+ public final static int M_SIMPLE_NAME= 1 << 1;
+
/**
* Method names contain thrown exceptions.
* e.g. foo throw( IOException )
@@ -82,6 +89,13 @@ public class CElementBaseLabels {
*/
public final static int TEMPLATE_PARAMETERS= 1 << 7;
+ /**
+ * Static field names without qualifier.
+ * e.g. fHello
+ * @since 5.1
+ */
+ public final static int F_SIMPLE_NAME= 1 << 8;
+
/**
* Field names contain the declared type (appended)
* e.g. fHello: int
@@ -349,7 +363,11 @@ public class CElementBaseLabels {
}
}
- buf.append( method.getElementName() );
+ if (getFlag(flags, M_SIMPLE_NAME)) {
+ buf.append(getSimpleName(method.getElementName()));
+ } else {
+ buf.append(method.getElementName());
+ }
//template parameters
if (method instanceof ITemplate) {
@@ -413,6 +431,20 @@ public class CElementBaseLabels {
}
}
+ /**
+ * Strip any qualifier from the given name.
+ *
+ * @param elementName
+ * @return a "simple" name
+ */
+ private static String getSimpleName(String elementName) {
+ int idx = elementName.indexOf("::"); //$NON-NLS-1$
+ if (idx >= 0) {
+ return elementName.substring(idx+2);
+ }
+ return elementName;
+ }
+
private static void getTemplateParameters(ITemplate template, int flags, StringBuffer buf) {
if (getFlag(flags, TEMPLATE_PARAMETERS)) {
String[] types = template.getTemplateParameterTypes();
@@ -452,7 +484,11 @@ public class CElementBaseLabels {
}
}
- buf.append( field.getElementName() );
+ if (getFlag(flags, F_SIMPLE_NAME)) {
+ buf.append(getSimpleName(field.getElementName()));
+ } else {
+ buf.append(field.getElementName());
+ }
if( getFlag( flags, F_APP_TYPE_SIGNATURE ) && field.exists()) {
buf.append( DECL_STRING );
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder2.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder2.java
index 4fad7fbcd5c..0f796abe767 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder2.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder2.java
@@ -72,6 +72,7 @@ import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IContributedModelBuilder;
+import org.eclipse.cdt.core.model.INamespace;
import org.eclipse.cdt.core.model.IProblemRequestor;
import org.eclipse.cdt.core.model.IStructure;
import org.eclipse.cdt.core.model.ITranslationUnit;
@@ -812,7 +813,7 @@ public class CModelBuilder2 implements IContributedModelBuilder {
final IASTDeclSpecifier declSpecifier= functionDeclaration.getDeclSpecifier();
- final String functionName= ASTStringUtil.getSimpleName(name);
+ final String simpleName= ASTStringUtil.getSimpleName(name);
final String[] parameterTypes= ASTStringUtil.getParameterSignatureArray(declarator);
final String returnType= ASTStringUtil.getReturnTypeString(declSpecifier, declarator);
@@ -822,12 +823,12 @@ public class CModelBuilder2 implements IContributedModelBuilder {
if (declarator instanceof ICPPASTFunctionDeclarator) {
final ICPPASTFunctionDeclarator cppFunctionDeclarator= (ICPPASTFunctionDeclarator)declarator;
- final IASTName simpleName;
+ final IASTName simpleAstName;
if (name instanceof ICPPASTQualifiedName) {
final ICPPASTQualifiedName quName= (ICPPASTQualifiedName)name;
- simpleName= quName.getLastName();
+ simpleAstName= quName.getLastName();
} else {
- simpleName= name;
+ simpleAstName= name;
}
IScope scope= null;
// try to avoid expensive resolution of scope and binding
@@ -843,8 +844,8 @@ public class CModelBuilder2 implements IContributedModelBuilder {
}
}
if (!isMethod) {
- scope= CPPVisitor.getContainingScope(simpleName);
- isMethod= scope instanceof ICPPClassScope || simpleName.resolveBinding() instanceof ICPPMethod;
+ scope= CPPVisitor.getContainingScope(simpleAstName);
+ isMethod= scope instanceof ICPPClassScope || simpleAstName.resolveBinding() instanceof ICPPMethod;
}
}
if (isMethod) {
@@ -870,7 +871,7 @@ public class CModelBuilder2 implements IContributedModelBuilder {
info= methodInfo;
ICPPMethod methodBinding= null;
if (scope != null) {
- final IBinding binding= simpleName.resolveBinding();
+ final IBinding binding= simpleAstName.resolveBinding();
if (binding instanceof ICPPMethod) {
methodBinding= (ICPPMethod)binding;
}
@@ -897,19 +898,34 @@ public class CModelBuilder2 implements IContributedModelBuilder {
final boolean isConstructor;
if (scope != null) {
isConstructor= CPPVisitor.isConstructor(scope, declarator);
+ } else if (parent instanceof IStructure) {
+ isConstructor= parent.getElementName().equals(simpleName);
+ } else if (name instanceof ICPPASTQualifiedName) {
+ final ICPPASTQualifiedName quName= (ICPPASTQualifiedName)name;
+ final IASTName[] names= quName.getNames();
+ isConstructor= names.length >= 2 && simpleName.equals(ASTStringUtil.getSimpleName(names[names.length-2]));
} else {
- isConstructor= parent.getElementName().equals(functionName);
+ isConstructor= false;
}
methodElement.setConstructor(isConstructor);
- methodElement.setDestructor(functionName.charAt(0) == '~');
+ methodElement.setDestructor(simpleName.charAt(0) == '~');
}
} else {
+ String functionName= ASTStringUtil.getQualifiedName(name);
+ // strip namespace qualifier if parent is same namespace
+ if (name instanceof ICPPASTQualifiedName && parent instanceof INamespace) {
+ final ICPPASTQualifiedName quName= (ICPPASTQualifiedName)name;
+ final IASTName[] names= quName.getNames();
+ if (names.length >= 2 && parent.getElementName().equals(ASTStringUtil.getSimpleName(names[names.length-2]))) {
+ functionName= simpleName;
+ }
+ }
if (isTemplate) {
// template function
- element= new FunctionTemplate(parent, ASTStringUtil.getSimpleName(name));
+ element= new FunctionTemplate(parent, functionName);
} else {
// function
- element= new Function(parent, ASTStringUtil.getSimpleName(name));
+ element= new Function(parent, functionName);
}
element.setParameterTypes(parameterTypes);
element.setReturnType(returnType);
@@ -918,6 +934,7 @@ public class CModelBuilder2 implements IContributedModelBuilder {
}
} else {
+ final String functionName= ASTStringUtil.getQualifiedName(name);
element= new Function(parent, functionName);
element.setParameterTypes(parameterTypes);
element.setReturnType(returnType);
@@ -1205,7 +1222,7 @@ public class CModelBuilder2 implements IContributedModelBuilder {
* @return the scope or null
*/
private static IScope getScope(IASTName astName) {
- IBinding binding= astName.getBinding();
+ IBinding binding= astName.resolveBinding();
if (binding != null) {
try {
return binding.getScope();
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/AutomatedSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/AutomatedSuite.java
index 26869e31473..6e44a45fdda 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/AutomatedSuite.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/AutomatedSuite.java
@@ -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
@@ -19,6 +19,7 @@ import org.eclipse.cdt.ui.tests.buildconsole.BuildConsoleTests;
import org.eclipse.cdt.ui.tests.callhierarchy.CallHierarchyTestSuite;
import org.eclipse.cdt.ui.tests.chelp.CHelpTest;
import org.eclipse.cdt.ui.tests.includebrowser.IncludeBrowserTestSuite;
+import org.eclipse.cdt.ui.tests.outline.OutlineTestSuite;
import org.eclipse.cdt.ui.tests.quickfix.AssistQuickFixTest;
import org.eclipse.cdt.ui.tests.refactoring.RefactoringTestSuite;
import org.eclipse.cdt.ui.tests.search.SearchTestSuite;
@@ -51,6 +52,9 @@ public class AutomatedSuite extends TestSuite {
// tests from package org.eclipse.cdt.ui.tests.text
addTest(TextTestSuite.suite());
+ // tests from package org.eclipse.cdt.ui.tests.outline
+ addTest(OutlineTestSuite.suite());
+
// tests for package org.eclipse.cdt.ui.tests.viewsupport
addTest(ViewSupportTestSuite.suite());
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/outline/BasicOutlineTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/outline/BasicOutlineTest.java
new file mode 100644
index 00000000000..c9c2db95c52
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/outline/BasicOutlineTest.java
@@ -0,0 +1,280 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Wind River Systems, Inc. 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.tests.outline;
+
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.IPageLayout;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.IDE;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.dom.IPDOMManager;
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.testplugin.CProjectHelper;
+import org.eclipse.cdt.ui.PreferenceConstants;
+import org.eclipse.cdt.ui.tests.BaseUITestCase;
+import org.eclipse.cdt.ui.tests.text.EditorTestHelper;
+
+import org.eclipse.cdt.internal.ui.editor.CEditor;
+
+/**
+ * Basic outline view tests.
+ */
+public class BasicOutlineTest extends BaseUITestCase {
+
+ private static final int INDEXER_WAIT_TIME = 10000;
+
+ public static TestSuite suite() {
+ return suite(BasicOutlineTest.class);
+ }
+
+ private ICProject fCProject;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ restoreAllParts();
+ fCProject = CProjectHelper.createCCProject(getName()+System.currentTimeMillis(), "bin", IPDOMManager.ID_FAST_INDEXER);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ closeAllEditors();
+ PreferenceConstants.getPreferenceStore().setToDefault(PreferenceConstants.OUTLINE_GROUP_MEMBERS);
+ PreferenceConstants.getPreferenceStore().setToDefault(PreferenceConstants.OUTLINE_GROUP_NAMESPACES);
+ if(fCProject != null) {
+ CProjectHelper.delete(fCProject);
+ }
+ super.tearDown();
+ }
+
+ protected CEditor openEditor(IFile file) throws PartInitException {
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ CEditor editor= (CEditor) IDE.openEditor(page, file);
+ EditorTestHelper.joinReconciler(EditorTestHelper.getSourceViewer(editor), 100, 1000, 10);
+ runEventQueue(500);
+ return editor;
+ }
+
+ protected ICProject getProject() {
+ return fCProject;
+ }
+
+ private void waitForIndexer(IProject project, IFile source) throws Exception, CoreException {
+ waitForIndexer(CCorePlugin.getIndexManager().getIndex(fCProject), source, INDEXER_WAIT_TIME);
+ }
+
+ private void checkTreeItems(TreeItem[] items, String... labels) {
+ assertEquals(items.length, labels.length);
+ int i=0;
+ for (TreeItem treeItem : items) {
+ assertEquals(labels[i++], treeItem.getText());
+ }
+ }
+
+ //#include "user.h"
+ //#include