mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
Fix for 222398: [Model Builder] problem with inlined qualified member declaration
and fix handling of multiple namespace definitions
This commit is contained in:
parent
7bce911157
commit
f66dfa5d9a
6 changed files with 140 additions and 26 deletions
|
@ -58,6 +58,7 @@ public class AllCoreTests {
|
|||
suite.addTest(PathSettingsContainerTests.suite());
|
||||
suite.addTest(ASTCacheTests.suite());
|
||||
suite.addTest(AsmModelBuilderTest.suite());
|
||||
suite.addTest(CModelBuilderBugsTest.suite());
|
||||
return suite;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 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:
|
||||
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.model.tests;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.INamespace;
|
||||
import org.eclipse.cdt.core.model.IStructure;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.core.testplugin.CTestPlugin;
|
||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||
|
||||
/**
|
||||
* Tests for C model builder bugs.
|
||||
*/
|
||||
public class CModelBuilderBugsTest extends BaseTestCase {
|
||||
|
||||
public static Test suite() {
|
||||
return suite(CModelBuilderBugsTest.class, "_");
|
||||
}
|
||||
|
||||
private ICProject fCProject;
|
||||
private ITranslationUnit fTU;
|
||||
|
||||
public CModelBuilderBugsTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
fCProject= CProjectHelper.createCProject(getName(), null, IPDOMManager.ID_FAST_INDEXER);
|
||||
assertNotNull(fCProject);
|
||||
CProjectHelper.importSourcesFromPlugin(fCProject, CTestPlugin.getDefault().getBundle(), "/resources/cmodel");
|
||||
fTU= (ITranslationUnit) CProjectHelper.findElement(fCProject, "CModelBuilderTest.cpp");
|
||||
assertNotNull(fTU);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
CProjectHelper.delete(fCProject);
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testModelBuilderBug222398() throws Exception {
|
||||
IStructure clazz= (IStructure) fTU.getElement("Test");
|
||||
assertNotNull(clazz);
|
||||
ICElement[] methods= clazz.getChildren();
|
||||
assertEquals(2, methods.length);
|
||||
assertEquals("inlined", methods[0].getElementName());
|
||||
assertEquals("decl", methods[1].getElementName());
|
||||
|
||||
INamespace ns= (INamespace) fTU.getElement("nsTest");
|
||||
ICElement[] functions= ns.getChildren();
|
||||
assertEquals(2, functions.length);
|
||||
assertEquals("inlined", functions[0].getElementName());
|
||||
assertEquals("decl", functions[1].getElementName());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2008 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
|
||||
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
/*
|
||||
* Created on Jun 17, 2003
|
||||
|
@ -153,7 +154,7 @@ public class ITemplateTests extends IntegratedCModelTest {
|
|||
// actually, none of the two are function templates, but method templates
|
||||
String[] myExpectedValues = {
|
||||
// "nonVector<T>::first",
|
||||
"Foo::fum",
|
||||
// "Foo::fum",
|
||||
};
|
||||
assertEquals(myExpectedValues.length, arrayElements.size());
|
||||
// This test is no correct there is no guaranty on the order
|
||||
|
@ -169,11 +170,9 @@ public class ITemplateTests extends IntegratedCModelTest {
|
|||
{
|
||||
// Check the template method
|
||||
List arrayElements = tu.getChildrenOfType(ICElement.C_TEMPLATE_METHOD);
|
||||
// actually, both of the two are method templates, but Foo is not resolved
|
||||
// to a cpp class
|
||||
String[] myExpectedValues = {
|
||||
"nonVector<T>::first",
|
||||
// "Foo::fum",
|
||||
"Foo::fum",
|
||||
};
|
||||
assertEquals(myExpectedValues.length, arrayElements.size());
|
||||
// This test is no correct there is no guaranty on the order
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
class Test {
|
||||
void Test::inlined() {}; // wrong label in outline: Test::inlined(): void
|
||||
void Test::decl(); // label in outline (ok): decl(): void
|
||||
};
|
||||
namespace nsTest {
|
||||
void nsTest::inlined() {}; // wrong label in outline: nsTest::inlined(): void
|
||||
void nsTest::decl(); // label in outline (ok): decl(): void
|
||||
}
|
||||
namespace nsTest {
|
||||
void nsTest::inlined2() {}; // wrong label in outline: nsTest::inlined(): void
|
||||
void nsTest::decl2(); // label in outline (ok): decl(): void
|
||||
}
|
|
@ -91,9 +91,11 @@ import org.eclipse.core.runtime.OperationCanceledException;
|
|||
public class CModelBuilder2 implements IContributedModelBuilder {
|
||||
|
||||
private final TranslationUnit fTranslationUnit;
|
||||
private final IProgressMonitor fProgressMonitor;
|
||||
|
||||
private ASTAccessVisibility fCurrentVisibility;
|
||||
private Stack<ASTAccessVisibility> fVisibilityStack;
|
||||
private IProgressMonitor fProgressMonitor;
|
||||
private Set<Namespace> fAllNamespaces;
|
||||
|
||||
/**
|
||||
* Create a model builder for the given translation unit.
|
||||
|
@ -182,6 +184,7 @@ public class CModelBuilder2 implements IContributedModelBuilder {
|
|||
*/
|
||||
private void buildModel(IASTTranslationUnit ast) throws CModelException, DOMException {
|
||||
fVisibilityStack= new Stack<ASTAccessVisibility>();
|
||||
fAllNamespaces= new HashSet<Namespace>();
|
||||
|
||||
// includes
|
||||
final IASTPreprocessorIncludeStatement[] includeDirectives= ast.getIncludeDirectives();
|
||||
|
@ -489,15 +492,20 @@ public class CModelBuilder2 implements IContributedModelBuilder {
|
|||
// create element
|
||||
final String type= Keywords.NAMESPACE;
|
||||
final IASTName name= declaration.getName();
|
||||
String nsName= ASTStringUtil.getQualifiedName(name);
|
||||
final Namespace element= new Namespace (parent, nsName);
|
||||
final String nsName= ASTStringUtil.getQualifiedName(name);
|
||||
final Namespace element= new Namespace(parent, nsName);
|
||||
// if there is a duplicate namespace, also set the index
|
||||
if (!fAllNamespaces.add(element)) {
|
||||
element.setIndex(fAllNamespaces.size());
|
||||
fAllNamespaces.add(element);
|
||||
}
|
||||
// add to parent
|
||||
parent.addChild(element);
|
||||
// set positions
|
||||
if (name != null && nsName.length() > 0) {
|
||||
setIdentifierPosition(element, name);
|
||||
} else {
|
||||
final IASTFileLocation nsLocation= getMinFileLocation(declaration.getNodeLocations());
|
||||
final IASTFileLocation nsLocation= declaration.getFileLocation();
|
||||
if (nsLocation != null) {
|
||||
element.setIdPos(nsLocation.getNodeOffset(), type.length());
|
||||
}
|
||||
|
@ -506,6 +514,8 @@ public class CModelBuilder2 implements IContributedModelBuilder {
|
|||
|
||||
element.setTypeName(type);
|
||||
|
||||
final Set<Namespace> savedNamespaces= fAllNamespaces;
|
||||
fAllNamespaces= new HashSet<Namespace>();
|
||||
IASTDeclaration[] nsDeclarations= declaration.getDeclarations();
|
||||
for (int i= 0; i < nsDeclarations.length; i++) {
|
||||
IASTDeclaration nsDeclaration= nsDeclarations[i];
|
||||
|
@ -513,6 +523,7 @@ public class CModelBuilder2 implements IContributedModelBuilder {
|
|||
createDeclaration(element, nsDeclaration);
|
||||
}
|
||||
}
|
||||
fAllNamespaces= savedNamespaces;
|
||||
}
|
||||
|
||||
private StructureDeclaration createElaboratedTypeDeclaration(Parent parent, IASTElaboratedTypeSpecifier elaboratedTypeSpecifier, boolean isTemplate) throws CModelException{
|
||||
|
@ -853,16 +864,22 @@ public class CModelBuilder2 implements IContributedModelBuilder {
|
|||
}
|
||||
if (!isMethod) {
|
||||
scope= CPPVisitor.getContainingScope(simpleName);
|
||||
isMethod= scope instanceof ICPPClassScope;
|
||||
isMethod= scope instanceof ICPPClassScope || simpleName.resolveBinding() instanceof ICPPMethod;
|
||||
}
|
||||
}
|
||||
if (isMethod) {
|
||||
// method
|
||||
final MethodDeclaration methodElement;
|
||||
if (isTemplate) {
|
||||
methodElement= new MethodTemplate(parent, ASTStringUtil.getQualifiedName(name));
|
||||
final String methodName;
|
||||
if (parent instanceof IStructure) {
|
||||
methodName= ASTStringUtil.getSimpleName(name);
|
||||
} else {
|
||||
methodElement= new Method(parent, ASTStringUtil.getQualifiedName(name));
|
||||
methodName= ASTStringUtil.getQualifiedName(name);
|
||||
}
|
||||
if (isTemplate) {
|
||||
methodElement= new MethodTemplate(parent, methodName);
|
||||
} else {
|
||||
methodElement= new Method(parent, methodName);
|
||||
}
|
||||
element= methodElement;
|
||||
// establish identity attributes before getElementInfo()
|
||||
|
@ -909,10 +926,10 @@ public class CModelBuilder2 implements IContributedModelBuilder {
|
|||
} else {
|
||||
if (isTemplate) {
|
||||
// template function
|
||||
element= new FunctionTemplate(parent, ASTStringUtil.getQualifiedName(name));
|
||||
element= new FunctionTemplate(parent, ASTStringUtil.getSimpleName(name));
|
||||
} else {
|
||||
// function
|
||||
element= new Function(parent, ASTStringUtil.getQualifiedName(name));
|
||||
element= new Function(parent, ASTStringUtil.getSimpleName(name));
|
||||
}
|
||||
element.setParameterTypes(parameterTypes);
|
||||
element.setReturnType(returnType);
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002, 2005 IBM Corporation and others.
|
||||
* Copyright (c) 2002, 2008 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
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Rational Software - Initial API and implementation
|
||||
* Rational Software - Initial API and implementation
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.model;
|
||||
|
||||
|
@ -17,6 +18,7 @@ import org.eclipse.cdt.core.model.INamespace;
|
|||
public class Namespace extends SourceManipulation implements INamespace{
|
||||
|
||||
String typeName = ""; //$NON-NLS-1$
|
||||
int fIndex;
|
||||
public Namespace(ICElement parent, String name) {
|
||||
super(parent, name, ICElement.C_NAMESPACE);
|
||||
}
|
||||
|
@ -37,14 +39,27 @@ public class Namespace extends SourceManipulation implements INamespace{
|
|||
this.typeName = typeName;
|
||||
}
|
||||
|
||||
// /* (non-Javadoc)
|
||||
// * @see java.lang.Object#equals(java.lang.Object)
|
||||
// */
|
||||
// public boolean equals(Object other) {
|
||||
// return (super.equals(other)
|
||||
// && (this.getStartPos() == ((Namespace)other).getStartPos())
|
||||
// && (this.getLength() == ((Namespace)other).getLength())
|
||||
// );
|
||||
// }
|
||||
/**
|
||||
* Set the index of this namespace, in case the same namespace is referenced
|
||||
* multiple times.
|
||||
*
|
||||
* @param index
|
||||
*/
|
||||
public void setIndex(int index) {
|
||||
fIndex= index;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.cdt.internal.core.model.CElement#equals(java.lang.Object)
|
||||
*/
|
||||
public boolean equals(Object other) {
|
||||
if (other instanceof INamespace && equals(this, (INamespace) other)) {
|
||||
if (other instanceof Namespace) {
|
||||
return fIndex == ((Namespace)other).fIndex;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue