Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Leherbauer2008-03-14 10:25:46 +0000
committerAnton Leherbauer2008-03-14 10:25:46 +0000
commitf66dfa5d9af9c89d4022ccbe241d7913acc9ea12 (patch)
tree16b5c8b62657c976f87672cac1590cea34ca87c1 /core/org.eclipse.cdt.core/model/org
parent7bce911157b74fac683622df8df63d06edb9d87c (diff)
downloadorg.eclipse.cdt-f66dfa5d9af9c89d4022ccbe241d7913acc9ea12.tar.gz
org.eclipse.cdt-f66dfa5d9af9c89d4022ccbe241d7913acc9ea12.tar.xz
org.eclipse.cdt-f66dfa5d9af9c89d4022ccbe241d7913acc9ea12.zip
Fix for 222398: [Model Builder] problem with inlined qualified member declaration
and fix handling of multiple namespace definitions
Diffstat (limited to 'core/org.eclipse.cdt.core/model/org')
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder2.java35
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Namespace.java37
2 files changed, 52 insertions, 20 deletions
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 effc6869ffe..037eba13b40 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
@@ -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;
+ final String methodName;
+ if (parent instanceof IStructure) {
+ methodName= ASTStringUtil.getSimpleName(name);
+ } else {
+ methodName= ASTStringUtil.getQualifiedName(name);
+ }
if (isTemplate) {
- methodElement= new MethodTemplate(parent, ASTStringUtil.getQualifiedName(name));
+ methodElement= new MethodTemplate(parent, methodName);
} else {
- methodElement= new Method(parent, ASTStringUtil.getQualifiedName(name));
+ 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);
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Namespace.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Namespace.java
index ca5045760e7..11f2586374e 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Namespace.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Namespace.java
@@ -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;
+ }
}

Back to the top