1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-12 18:55:38 +02:00

Fix for Bug 88421 - outline view should display more information for: variables, classes and functions

This commit is contained in:
Anton Leherbauer 2006-12-12 13:35:08 +00:00
parent 11719658ed
commit b786f3c0e9
6 changed files with 126 additions and 15 deletions

View file

@ -393,7 +393,15 @@ public class CModelElementsTests extends TestCase {
fail("field visibility should be public!"); fail("field visibility should be public!");
// struct no name // 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 ("")); assertEquals(struct2.getElementName(), new String (""));
checkElementOffset(struct2); checkElementOffset(struct2);
checkLineNumbers(struct2, 101, 103); checkLineNumbers(struct2, 101, 103);

View file

@ -398,7 +398,15 @@ public class StructuralCModelElementsTests extends TestCase {
fail("field visibility should be public!"); //$NON-NLS-1$ fail("field visibility should be public!"); //$NON-NLS-1$
// struct no name // 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$ assertEquals(struct2.getElementName(), new String ("")); //$NON-NLS-1$
checkElementOffset(struct2); checkElementOffset(struct2);
checkLineNumbers(struct2, 101, 103); checkLineNumbers(struct2, 101, 103);

View file

@ -13,7 +13,7 @@ package org.eclipse.cdt.core.model;
/** /**
* Represents a field declared in a type. * 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 * Returns the type of the typedef item
* @return String * @return String

View file

@ -485,7 +485,8 @@ public class ASTStringUtil {
// break; // break;
// } // }
if (declSpecifier instanceof IASTCompositeTypeSpecifier) { if (declSpecifier instanceof IASTCompositeTypeSpecifier) {
final int key= ((IASTCompositeTypeSpecifier)declSpecifier).getKey(); final IASTCompositeTypeSpecifier compositeTypeSpec= (IASTCompositeTypeSpecifier)declSpecifier;
final int key= compositeTypeSpec.getKey();
switch (key) { switch (key) {
case IASTCompositeTypeSpecifier.k_struct: case IASTCompositeTypeSpecifier.k_struct:
buffer.append(Keywords.STRUCT).append(' '); buffer.append(Keywords.STRUCT).append(' ');
@ -498,6 +499,7 @@ public class ASTStringUtil {
break; break;
default: default:
} }
appendQualifiedNameString(buffer, compositeTypeSpec.getName());
} else if (declSpecifier instanceof IASTElaboratedTypeSpecifier) { } else if (declSpecifier instanceof IASTElaboratedTypeSpecifier) {
final IASTElaboratedTypeSpecifier elaboratedTypeSpec= (IASTElaboratedTypeSpecifier)declSpecifier; final IASTElaboratedTypeSpecifier elaboratedTypeSpec= (IASTElaboratedTypeSpecifier)declSpecifier;
switch (elaboratedTypeSpec.getKind()) { switch (elaboratedTypeSpec.getKind()) {

View file

@ -69,6 +69,7 @@ import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IContributedModelBuilder; 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.IProblemRequestor;
import org.eclipse.cdt.core.model.IStructure; import org.eclipse.cdt.core.model.IStructure;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
@ -515,7 +516,7 @@ public class CModelBuilder2 implements IContributedModelBuilder {
for (int i= 0; i < declarators.length; i++) { for (int i= 0; i < declarators.length; i++) {
final IASTDeclarator declarator= declarators[i]; final IASTDeclarator declarator= declarators[i];
final CElement element= createSimpleDeclaration(parent, declSpecifier, declarator, isTemplate); 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); setBodyPosition((SourceManipulation)element, declarator);
} }
elements[i]= element; 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 { private CElement createSimpleDeclaration(Parent parent, IASTDeclSpecifier declSpecifier, IASTDeclarator declarator, boolean isTemplate) throws CModelException, DOMException {
if (declSpecifier instanceof IASTCompositeTypeSpecifier) { if (declSpecifier instanceof IASTCompositeTypeSpecifier) {
final CElement compositeType= createCompositeType(parent, (IASTCompositeTypeSpecifier)declSpecifier, isTemplate);
if (declarator != null) { 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; return compositeType;
} else if (declSpecifier instanceof IASTElaboratedTypeSpecifier) { } else if (declSpecifier instanceof IASTElaboratedTypeSpecifier) {
if (declarator == null) { if (declarator == null) {
@ -816,8 +824,11 @@ public class CModelBuilder2 implements IContributedModelBuilder {
} else { } else {
setIdentifierPosition(element, declSpecifier); setIdentifierPosition(element, declSpecifier);
} }
setBodyPosition(element, declSpecifier.getParent()); if (declSpecifier instanceof IASTCompositeTypeSpecifier) {
setBodyPosition(element, astTypedefName);
} else {
setBodyPosition(element, declSpecifier.getParent());
}
return element; return element;
} }
@ -874,7 +885,11 @@ public class CModelBuilder2 implements IContributedModelBuilder {
// set positions // set positions
setIdentifierPosition(element, astVariableName); setIdentifierPosition(element, astVariableName);
if (!isTemplate) { if (!isTemplate) {
setBodyPosition(element, specifier.getParent()); if (specifier instanceof IASTCompositeTypeSpecifier) {
setBodyPosition(element, astVariableName);
} else {
setBodyPosition(element, specifier.getParent());
}
} }
return element; return element;
} }

View file

@ -25,11 +25,14 @@ import org.eclipse.cdt.core.model.ICContainer;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IField; import org.eclipse.cdt.core.model.IField;
import org.eclipse.cdt.core.model.IFunctionDeclaration; 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.IMethodDeclaration;
import org.eclipse.cdt.core.model.ISourceRoot; import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.cdt.core.model.ITemplate; import org.eclipse.cdt.core.model.ITemplate;
import org.eclipse.cdt.core.model.ITranslationUnit; 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.model.IVariableDeclaration;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.corext.util.CModelUtil; import org.eclipse.cdt.internal.corext.util.CModelUtil;
@ -115,10 +118,10 @@ public class CElementLabels {
public final static int T_FULLY_QUALIFIED= 1 << 13; public final static int T_FULLY_QUALIFIED= 1 << 13;
/** /**
* Type names are post qualified. * Append base class specifications to type names.
* e.g. <code>InnerClass - OuterClass</code> * e.g. <code>MyClass : public BaseClass</code>
*/ */
public final static int T_POST_QUALIFIED= 1 << 15; public final static int T_INHERITANCE= 1 << 16;
/** /**
* Translation unit names contain the full path. * Translation unit names contain the full path.
@ -178,7 +181,7 @@ public class CElementLabels {
/** /**
* Post qualify all elements * 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) * Default options (M_PARAMETER_TYPES enabled)
@ -193,7 +196,7 @@ public class CElementLabels {
/** /**
* Default post qualify options (All except Root) * 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$ 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: case ICElement.C_TEMPLATE_UNION_DECLARATION:
getTypeLabel( element, flags, buf ); getTypeLabel( element, flags, buf );
break; break;
case ICElement.C_TYPEDEF:
getTypeDefLabel((ITypeDef)element, flags, buf);
break;
case ICElement.C_UNIT: case ICElement.C_UNIT:
getTranslationUnitLabel((ITranslationUnit) element, flags, buf); getTranslationUnitLabel((ITranslationUnit) element, flags, buf);
break; 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. * Appends the label for a source root to a StringBuffer. Considers the ROOT_* flags.
*/ */
@ -645,12 +691,44 @@ public class CElementLabels {
} }
buf.append(typeName); 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 //template parameters
if (elem instanceof ITemplate) { if (elem instanceof ITemplate) {
getTemplateParameters((ITemplate)elem, flags, buf); getTemplateParameters((ITemplate)elem, flags, buf);
} }
} }
/**
* Convert an <code>ASTAccessVisibility</code> 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) { private static boolean getFlag(int flags, int flag) {
return (flags & flag) != 0; return (flags & flag) != 0;
} }