diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java
index addb4d18cff..ec3d8a0cb30 100644
--- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java
+++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java
@@ -393,7 +393,15 @@ public class CModelElementsTests extends TestCase {
fail("field visibility should be public!");
// struct no name
- IStructure struct2 = (IStructure) nsStructs.get(1);
+ IStructure struct2;
+ if (IParent.class.isAssignableFrom(ITypeDef.class)) {
+ // nested in typedef decl
+ List nsTypeDefs = namespace.getChildrenOfType(ICElement.C_TYPEDEF);
+ ITypeDef td2 = (ITypeDef) nsTypeDefs.get(1);
+ struct2 = (IStructure) td2.getChildren()[0];
+ } else {
+ struct2 = (IStructure) nsStructs.get(1);
+ }
assertEquals(struct2.getElementName(), new String (""));
checkElementOffset(struct2);
checkLineNumbers(struct2, 101, 103);
diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/StructuralCModelElementsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/StructuralCModelElementsTests.java
index 9bfb110edb7..6b6533c651b 100644
--- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/StructuralCModelElementsTests.java
+++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/StructuralCModelElementsTests.java
@@ -398,7 +398,15 @@ public class StructuralCModelElementsTests extends TestCase {
fail("field visibility should be public!"); //$NON-NLS-1$
// struct no name
- IStructure struct2 = (IStructure) nsStructs.get(1);
+ IStructure struct2;
+ if (IParent.class.isAssignableFrom(ITypeDef.class)) {
+ // nested in typedef decl
+ List nsTypeDefs = namespace.getChildrenOfType(ICElement.C_TYPEDEF);
+ ITypeDef td2 = (ITypeDef) nsTypeDefs.get(1);
+ struct2 = (IStructure) td2.getChildren()[0];
+ } else {
+ struct2 = (IStructure) nsStructs.get(1);
+ }
assertEquals(struct2.getElementName(), new String ("")); //$NON-NLS-1$
checkElementOffset(struct2);
checkLineNumbers(struct2, 101, 103);
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITypeDef.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITypeDef.java
index 26b256cafb4..dbe2d5bea99 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITypeDef.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITypeDef.java
@@ -13,7 +13,7 @@ package org.eclipse.cdt.core.model;
/**
* Represents a field declared in a type.
*/
-public interface ITypeDef extends ICElement, ISourceManipulation, ISourceReference {
+public interface ITypeDef extends ICElement, ISourceManipulation, ISourceReference, IParent {
/**
* Returns the type of the typedef item
* @return String
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTStringUtil.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTStringUtil.java
index 03c7d470db0..76b3c83a4e5 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTStringUtil.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTStringUtil.java
@@ -485,7 +485,8 @@ public class ASTStringUtil {
// break;
// }
if (declSpecifier instanceof IASTCompositeTypeSpecifier) {
- final int key= ((IASTCompositeTypeSpecifier)declSpecifier).getKey();
+ final IASTCompositeTypeSpecifier compositeTypeSpec= (IASTCompositeTypeSpecifier)declSpecifier;
+ final int key= compositeTypeSpec.getKey();
switch (key) {
case IASTCompositeTypeSpecifier.k_struct:
buffer.append(Keywords.STRUCT).append(' ');
@@ -498,6 +499,7 @@ public class ASTStringUtil {
break;
default:
}
+ appendQualifiedNameString(buffer, compositeTypeSpec.getName());
} else if (declSpecifier instanceof IASTElaboratedTypeSpecifier) {
final IASTElaboratedTypeSpecifier elaboratedTypeSpec= (IASTElaboratedTypeSpecifier)declSpecifier;
switch (elaboratedTypeSpec.getKind()) {
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 20adeee67d6..e4b0a09bf93 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
@@ -69,6 +69,7 @@ import org.eclipse.cdt.core.index.IIndex;
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.IParent;
import org.eclipse.cdt.core.model.IProblemRequestor;
import org.eclipse.cdt.core.model.IStructure;
import org.eclipse.cdt.core.model.ITranslationUnit;
@@ -515,7 +516,7 @@ public class CModelBuilder2 implements IContributedModelBuilder {
for (int i= 0; i < declarators.length; i++) {
final IASTDeclarator declarator= declarators[i];
final CElement element= createSimpleDeclaration(parent, declSpecifier, declarator, isTemplate);
- if (!isTemplate && element instanceof SourceManipulation && i > 0) {
+ if (!isTemplate && element instanceof SourceManipulation && declarators.length > 1) {
setBodyPosition((SourceManipulation)element, declarator);
}
elements[i]= element;
@@ -530,10 +531,17 @@ public class CModelBuilder2 implements IContributedModelBuilder {
private CElement createSimpleDeclaration(Parent parent, IASTDeclSpecifier declSpecifier, IASTDeclarator declarator, boolean isTemplate) throws CModelException, DOMException {
if (declSpecifier instanceof IASTCompositeTypeSpecifier) {
- final CElement compositeType= createCompositeType(parent, (IASTCompositeTypeSpecifier)declSpecifier, isTemplate);
if (declarator != null) {
- return createTypedefOrFunctionOrVariable(parent, declSpecifier, declarator, isTemplate);
+ // create type nested
+ CElement element= createTypedefOrFunctionOrVariable(parent, declSpecifier, declarator, isTemplate);
+ if (element instanceof IParent) {
+ parent= (Parent)element;
+ if (!isTemplate) {
+ setBodyPosition((SourceManipulation)element, declSpecifier.getParent());
+ }
+ }
}
+ final CElement compositeType= createCompositeType(parent, (IASTCompositeTypeSpecifier)declSpecifier, isTemplate);
return compositeType;
} else if (declSpecifier instanceof IASTElaboratedTypeSpecifier) {
if (declarator == null) {
@@ -816,8 +824,11 @@ public class CModelBuilder2 implements IContributedModelBuilder {
} else {
setIdentifierPosition(element, declSpecifier);
}
- setBodyPosition(element, declSpecifier.getParent());
-
+ if (declSpecifier instanceof IASTCompositeTypeSpecifier) {
+ setBodyPosition(element, astTypedefName);
+ } else {
+ setBodyPosition(element, declSpecifier.getParent());
+ }
return element;
}
@@ -874,7 +885,11 @@ public class CModelBuilder2 implements IContributedModelBuilder {
// set positions
setIdentifierPosition(element, astVariableName);
if (!isTemplate) {
- setBodyPosition(element, specifier.getParent());
+ if (specifier instanceof IASTCompositeTypeSpecifier) {
+ setBodyPosition(element, astVariableName);
+ } else {
+ setBodyPosition(element, specifier.getParent());
+ }
}
return element;
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CElementLabels.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CElementLabels.java
index feab7c203f6..a74a2f11671 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CElementLabels.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CElementLabels.java
@@ -25,11 +25,14 @@ import org.eclipse.cdt.core.model.ICContainer;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IField;
import org.eclipse.cdt.core.model.IFunctionDeclaration;
+import org.eclipse.cdt.core.model.IInheritance;
import org.eclipse.cdt.core.model.IMethodDeclaration;
import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.cdt.core.model.ITemplate;
import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.cdt.core.model.ITypeDef;
import org.eclipse.cdt.core.model.IVariableDeclaration;
+import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.corext.util.CModelUtil;
@@ -115,10 +118,10 @@ public class CElementLabels {
public final static int T_FULLY_QUALIFIED= 1 << 13;
/**
- * Type names are post qualified.
- * e.g. InnerClass - OuterClass
+ * Append base class specifications to type names.
+ * e.g. MyClass : public BaseClass
*/
- public final static int T_POST_QUALIFIED= 1 << 15;
+ public final static int T_INHERITANCE= 1 << 16;
/**
* Translation unit names contain the full path.
@@ -178,7 +181,7 @@ public class CElementLabels {
/**
* Post qualify all elements
*/
- public final static int ALL_POST_QUALIFIED= F_POST_QUALIFIED | M_POST_QUALIFIED | T_POST_QUALIFIED | TU_POST_QUALIFIED | ROOT_POST_QUALIFIED;
+ public final static int ALL_POST_QUALIFIED= F_POST_QUALIFIED | M_POST_QUALIFIED | TU_POST_QUALIFIED | ROOT_POST_QUALIFIED;
/**
* Default options (M_PARAMETER_TYPES enabled)
@@ -193,7 +196,7 @@ public class CElementLabels {
/**
* Default post qualify options (All except Root)
*/
- public final static int DEFAULT_POST_QUALIFIED= F_POST_QUALIFIED | M_POST_QUALIFIED | T_POST_QUALIFIED | TU_POST_QUALIFIED;
+ public final static int DEFAULT_POST_QUALIFIED= F_POST_QUALIFIED | M_POST_QUALIFIED | TU_POST_QUALIFIED;
public final static String CONCAT_STRING= CUIMessages.getString("CElementLabels.concat_string"); // " - "; //$NON-NLS-1$
@@ -260,6 +263,9 @@ public class CElementLabels {
case ICElement.C_TEMPLATE_UNION_DECLARATION:
getTypeLabel( element, flags, buf );
break;
+ case ICElement.C_TYPEDEF:
+ getTypeDefLabel((ITypeDef)element, flags, buf);
+ break;
case ICElement.C_UNIT:
getTranslationUnitLabel((ITranslationUnit) element, flags, buf);
break;
@@ -548,6 +554,46 @@ public class CElementLabels {
}
}
+ public static void getTypeDefLabel(ITypeDef typedef, int flags, StringBuffer buf ) {
+ // type
+ if( getFlag( flags, F_PRE_TYPE_SIGNATURE ) && typedef.exists()) {
+ buf.append( typedef.getTypeName() );
+ buf.append( ' ' );
+ }
+
+ //qualification
+ if( getFlag( flags, F_FULLY_QUALIFIED ) ){
+ ICElement parent = typedef.getParent();
+ if (parent != null && parent.exists() && parent.getElementType() == ICElement.C_NAMESPACE) {
+ getTypeLabel( parent, T_FULLY_QUALIFIED, buf );
+ buf.append( "::" ); //$NON-NLS-1$
+ }
+ }
+
+ buf.append( typedef.getElementName() );
+
+ if( getFlag( flags, F_APP_TYPE_SIGNATURE ) && typedef.exists()) {
+ buf.append( DECL_STRING );
+ buf.append( typedef.getTypeName() );
+ }
+
+ // post qualification
+ if( getFlag(flags, F_POST_QUALIFIED)) {
+ ICElement parent = typedef.getParent();
+ if (parent != null && parent.exists() && parent.getElementType() == ICElement.C_NAMESPACE) {
+ buf.append( CONCAT_STRING );
+ getTypeLabel( typedef.getParent(), T_FULLY_QUALIFIED, buf );
+ }
+ }
+ if( getFlag(flags, MF_POST_FILE_QUALIFIED)) {
+ IPath path= typedef.getPath();
+ if (path != null) {
+ buf.append( CONCAT_STRING );
+ buf.append(path.toString());
+ }
+ }
+ }
+
/**
* Appends the label for a source root to a StringBuffer. Considers the ROOT_* flags.
*/
@@ -645,12 +691,44 @@ public class CElementLabels {
}
buf.append(typeName);
+ if (/*getFlag(flags, T_INHERITANCE) && */elem instanceof IInheritance) {
+ IInheritance inheritance= (IInheritance)elem;
+ String[] superclassNames= inheritance.getSuperClassesNames();
+ if (superclassNames != null && superclassNames.length > 0) {
+ buf.append(DECL_STRING);
+ for (int i = 0; i < superclassNames.length; i++) {
+ if (i> 0) {
+ buf.append(COMMA_STRING);
+ }
+ String superclass = superclassNames[i];
+ String visibility = getVisibility(inheritance.getSuperClassAccess(superclass));
+ buf.append(visibility).append(' ').append(superclass);
+ }
+ }
+ }
+
//template parameters
if (elem instanceof ITemplate) {
getTemplateParameters((ITemplate)elem, flags, buf);
}
}
+ /**
+ * Convert an ASTAccessVisibility
into its string representation.
+ *
+ * @param access
+ * @return "public", "protected" or "private"
+ */
+ private static String getVisibility(ASTAccessVisibility access) {
+ if (access == ASTAccessVisibility.PUBLIC) {
+ return "public"; //$NON-NLS-1$
+ }
+ if (access == ASTAccessVisibility.PROTECTED) {
+ return "protected"; //$NON-NLS-1$
+ }
+ return "private"; //$NON-NLS-1$
+ }
+
private static boolean getFlag(int flags, int flag) {
return (flags & flag) != 0;
}