From 1bc986271c2c1883c5231ec5620ab5aa3aa04a36 Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Fri, 20 Apr 2007 14:47:16 +0000 Subject: [PATCH] Fix for 176229: Move CElementLabels to non-UI and public place (Patch by Gerhard Schaber ) --- .../core/model/util/CElementBaseLabels.java | 849 ++++++++++++++++++ .../core/model/CoreModelMessages.properties | 5 + .../cdt/internal/ui/CUIMessages.properties | 6 +- .../internal/ui/actions/OpenActionUtil.java | 5 +- .../ui/callhierarchy/CHHistoryAction.java | 12 +- .../ui/callhierarchy/CHLabelProvider.java | 6 +- .../internal/ui/callhierarchy/CHViewPart.java | 5 +- .../ui/callhierarchy/CallHierarchyUI.java | 4 +- .../ui/editor/CContentOutlinePage.java | 4 +- .../ui/includebrowser/IBHistoryAction.java | 4 +- .../includebrowser/IBHistoryListAction.java | 4 +- .../ui/text/COutlineInformationControl.java | 4 +- .../ui/typehierarchy/THHistoryAction.java | 10 +- .../ui/typehierarchy/THLabelProvider.java | 6 +- .../internal/ui/typehierarchy/THViewPart.java | 11 +- .../AppearanceAwareLabelProvider.java | 4 +- .../ui/viewsupport/CElementLabels.java | 729 +-------------- .../ui/viewsupport/CUILabelProvider.java | 5 +- .../ui/viewsupport/StatusBarUpdater.java | 12 +- .../eclipse/cdt/ui/CElementLabelProvider.java | 12 +- 20 files changed, 915 insertions(+), 782 deletions(-) create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/util/CElementBaseLabels.java diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/util/CElementBaseLabels.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/util/CElementBaseLabels.java new file mode 100644 index 00000000000..865833ded52 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/util/CElementBaseLabels.java @@ -0,0 +1,849 @@ +/******************************************************************************* + * Copyright (c) 2003, 2007 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: + * IBM Corp. - Rational Software - initial implementation + * Markus Schorn (Wind River Systems) + * Gerhard Schaber (Wind River Systems) + *******************************************************************************/ +/* + * Created on Jun 24, 2003 + */ +package org.eclipse.cdt.core.model.util; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IPath; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.IBinary; +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.internal.core.model.CoreModelMessages; + +/** + * Creates labels for ICElement objects. + * @author aniefer + */ +public class CElementBaseLabels { + + /** + * Method names contain parameter types. + * e.g. foo(int) + */ + public final static int M_PARAMETER_TYPES= 1 << 0; + + /** + * Method names contain thrown exceptions. + * e.g. foo throw( IOException ) + */ + public final static int M_EXCEPTIONS= 1 << 2; + + /** + * Method names contain return type (appended) + * e.g. foo : int + */ + public final static int M_APP_RETURNTYPE= 1 << 3; + + /** + * Method names contain return type (appended) + * e.g. int foo + */ + public final static int M_PRE_RETURNTYPE= 1 << 4; + + /** + * Method names are fully qualified. + * e.g. ClassName::size + */ + public final static int M_FULLY_QUALIFIED= 1 << 5; + + /** + * Method names are post qualified. + * e.g. size - ClassName + */ + public final static int M_POST_QUALIFIED= 1 << 6; + + /** + * Templates are qualified with template parameters. + * e.g. ClassName + */ + public final static int TEMPLATE_PARAMETERS= 1 << 7; + + /** + * Field names contain the declared type (appended) + * e.g. fHello: int + */ + public final static int F_APP_TYPE_SIGNATURE= 1 << 9; + + /** + * Field names contain the declared type (prepended) + * e.g. int fHello + */ + public final static int F_PRE_TYPE_SIGNATURE= 1 << 10; + + /** + * Fields names are fully qualified. + * e.g. ClassName::fField + */ + public final static int F_FULLY_QUALIFIED= 1 << 11; + + /** + * Fields names are post qualified. + * e.g. fField - ClassName + */ + public final static int F_POST_QUALIFIED= 1 << 12; + + /** + * Type names are fully qualified. + * e.g. namespace::ClassName + */ + public final static int T_FULLY_QUALIFIED= 1 << 13; + + /** + * Append base class specifications to type names. + * e.g. MyClass : public BaseClass + */ + public final static int T_INHERITANCE= 1 << 16; + + /** + * Translation unit names contain the full path. + * e.g. /MyProject/src/ClassName.cpp + */ + public final static int TU_QUALIFIED= 1 << 20; + + /** + * Translation unit names are post qualified with their path. + * e.g. ClassName.cpp - /MyProject/src + */ + public final static int TU_POST_QUALIFIED= 1 << 21; + + /** + * Source roots contain the project name (prepended). + * e.g. MyProject/src + */ + public final static int ROOT_QUALIFIED= 1 << 25; + + /** + * Source roots contain the project name (appended). + * e.g. src - MyProject + */ + public final static int ROOT_POST_QUALIFIED= 1 << 26; + + /** + * Add source root path. + * e.g. func() - MyProject/src + * Option only applies to getElementLabel + */ + public final static int APPEND_ROOT_PATH= 1 << 27; + + /** + * Prepend source root path. + * e.g. MyProject/src - func() + * Option only applies to getElementLabel + */ + public final static int PREPEND_ROOT_PATH= 1 << 28; + + /** + * Post qualify container project. For example + * folder - MyProject if the folder is in project MyProject. + */ + public final static int PROJECT_POST_QUALIFIED= 1 << 30; + + /** + * Post qualify symbols with file. + * e.g. func() - /proj/folder/file.cpp + */ + public final static int MF_POST_FILE_QUALIFIED= 1 << 31; + + /** + * Qualify all elements + */ + public final static int ALL_FULLY_QUALIFIED= F_FULLY_QUALIFIED | M_FULLY_QUALIFIED | T_FULLY_QUALIFIED | TU_QUALIFIED | ROOT_QUALIFIED; + + /** + * Post qualify all elements + */ + 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) + */ + public final static int ALL_DEFAULT= M_PARAMETER_TYPES; + + /** + * Default qualify options (All except Root) + */ + public final static int DEFAULT_QUALIFIED= F_FULLY_QUALIFIED | M_FULLY_QUALIFIED | T_FULLY_QUALIFIED | TU_QUALIFIED; + + /** + * Default post qualify options (All except Root) + */ + public final static int DEFAULT_POST_QUALIFIED= F_POST_QUALIFIED | M_POST_QUALIFIED | TU_POST_QUALIFIED; + + /** + * Separator for appending qualifiers + */ + public final static String CONCAT_STRING= CoreModelMessages.getString("CElementLabels.concat_string"); // " - "; //$NON-NLS-1$ + + /** + * Separator for parameters, base classes, exceptions, etc. + */ + public final static String COMMA_STRING = CoreModelMessages.getString("CElementLabels.comma_string"); // ", "; //$NON-NLS-1$ + + /** + * Separator for appending (return) type + */ + public final static String DECL_STRING = CoreModelMessages.getString("CElementLabels.declseparator_string"); // " "; // use for return type //$NON-NLS-1$ + + /** + * Returns the label for an element. + * @param element any element (IMethodDeclaration, IField, ITypeDef, IVariableDeclaration, etc.) + * @param flags any of the flags (M_*, F_*, ROOT_*, etc.) defined in this class + * @return the label + */ + public static String getElementLabel(ICElement element, int flags) { + StringBuffer buf= new StringBuffer(60); + getElementLabel(element, flags, buf); + return buf.toString(); + } + + /** + * Appends the label for an element to a StringBuffer. + * @param element any element (IMethodDeclaration, IField, ITypeDef, IVariableDeclaration, etc.) + * @param flags any of the flags (M_*, F_*, ROOT_*, etc.) defined in this class + * @param buf the buffer to append the label + */ + public static void getElementLabel(ICElement element, int flags, StringBuffer buf) { + int type= element.getElementType(); + ISourceRoot root= null; + + if (type != ICElement.C_MODEL && type != ICElement.C_PROJECT && !(type == ICElement.C_CCONTAINER && element instanceof ISourceRoot)) + root= getSourceRoot(element); + if (root != null && getFlag(flags, PREPEND_ROOT_PATH)) { + getSourceRootLabel(root, ROOT_QUALIFIED, buf); + buf.append(CONCAT_STRING); + } + switch (type) { + case ICElement.C_METHOD : + case ICElement.C_METHOD_DECLARATION: + case ICElement.C_TEMPLATE_METHOD: + case ICElement.C_TEMPLATE_METHOD_DECLARATION: + getMethodLabel( (IMethodDeclaration) element, flags, buf ); + break; + case ICElement.C_FUNCTION: + case ICElement.C_FUNCTION_DECLARATION: + case ICElement.C_TEMPLATE_FUNCTION: + case ICElement.C_TEMPLATE_FUNCTION_DECLARATION: + getFunctionLabel( (IFunctionDeclaration) element, flags, buf); + break; + case ICElement.C_FIELD : + getFieldLabel( (IField) element, flags, buf ); + break; + case ICElement.C_VARIABLE: + case ICElement.C_VARIABLE_DECLARATION: + getVariableLabel( (IVariableDeclaration) element, flags, buf); + break; + case ICElement.C_CLASS: + case ICElement.C_STRUCT: + case ICElement.C_UNION: + case ICElement.C_ENUMERATION: + case ICElement.C_TEMPLATE_CLASS: + case ICElement.C_TEMPLATE_STRUCT: + case ICElement.C_TEMPLATE_UNION: + case ICElement.C_TEMPLATE_CLASS_DECLARATION: + case ICElement.C_TEMPLATE_STRUCT_DECLARATION: + 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; + case ICElement.C_CCONTAINER: + ICContainer container = (ICContainer) element; + if (container instanceof ISourceRoot) + getSourceRootLabel((ISourceRoot) container, flags, buf); + else + getContainerLabel(container, flags, buf); + break; + case ICElement.C_PROJECT: + case ICElement.C_MODEL: + buf.append(element.getElementName()); + break; + default: + buf.append(element.getElementName()); + } + + if (root != null && getFlag(flags, APPEND_ROOT_PATH)) { + buf.append(CONCAT_STRING); + getSourceRootLabel(root, ROOT_QUALIFIED, buf); + } + + if (element instanceof IBinary) { + IBinary bin = (IBinary)element; + buf.append(" - [" + bin.getCPU() + "/" + (bin.isLittleEndian() ? "le" : "be") + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ + } + + } + + /** + * Appends the label for a method declaration to a StringBuffer. + * @param method a method declaration + * @param flags any of the M_* flags, and MF_POST_FILE_QUALIFIED + * @param buf the buffer to append the label + */ + public static void getMethodLabel( IMethodDeclaration method, int flags, StringBuffer buf ) { + try { + //return type + if( getFlag( flags, M_PRE_RETURNTYPE ) && method.exists() && !method.isConstructor() ) { + buf.append( method.getReturnType() ); + buf.append( ' ' ); + } + + //qualification + if( getFlag( flags, M_FULLY_QUALIFIED ) ){ + ICElement parent = method.getParent(); + if (parent != null && parent.exists() && !(parent instanceof ITranslationUnit)) { + getTypeLabel( parent, T_FULLY_QUALIFIED, buf ); + buf.append( "::" ); //$NON-NLS-1$ + } + } + + buf.append( method.getElementName() ); + + //template parameters + if (method instanceof ITemplate) { + getTemplateParameters((ITemplate)method, flags, buf); + } + + //parameters + if( getFlag( flags, M_PARAMETER_TYPES ) ) { + buf.append('('); + + String[] types = method.getParameterTypes(); + + for (int i= 0; i < types.length; i++) { + if (i > 0) { + buf.append( COMMA_STRING ); + } + + if (types != null) { + buf.append( types[i] ); + } + } + buf.append(')'); + } + + //exceptions + if( getFlag( flags, M_EXCEPTIONS ) && method.exists() ){ + String [] types = method.getExceptions(); + if (types.length > 0) { + buf.append(" throw( "); //$NON-NLS-1$ + for (int i= 0; i < types.length; i++) { + if (i > 0) { + buf.append(COMMA_STRING); + } + buf.append( types[i] ); + } + buf.append( " )" ); //$NON-NLS-1$ + } + } + + if( getFlag( flags, M_APP_RETURNTYPE ) && method.exists() && !method.isConstructor() && !method.isDestructor()) { + final String typeName= method.getReturnType(); + if (typeName != null && typeName.length() > 0) { + buf.append( DECL_STRING ); + buf.append(typeName); + } + } + + // post qualification + if( getFlag(flags, M_POST_QUALIFIED)) { + buf.append( CONCAT_STRING ); + getTypeLabel( method.getParent(), T_FULLY_QUALIFIED, buf ); + } + if( getFlag(flags, MF_POST_FILE_QUALIFIED)) { + IPath path= method.getPath(); + if (path != null) { + buf.append( CONCAT_STRING ); + buf.append(path.toString()); + } + } + } catch (CModelException e) { + CCorePlugin.log(e); + } + } + + private static void getTemplateParameters(ITemplate template, int flags, StringBuffer buf) { + if (getFlag(flags, TEMPLATE_PARAMETERS)) { + String[] types = template.getTemplateParameterTypes(); + buf.append('<'); + if (types != null) { + for (int i= 0; i < types.length; i++) { + if (i > 0) { + buf.append( ',' ); + } + buf.append( types[i] ); + } + } + buf.append('>'); + } + } + + /** + * Appends the label for a field to a StringBuffer. + * @param field a field + * @param flags any of the F_* flags, and MF_POST_FILE_QUALIFIED + * @param buf the buffer to append the label + */ + public static void getFieldLabel(IField field, int flags, StringBuffer buf ) { + try { + //return type + if( getFlag( flags, F_PRE_TYPE_SIGNATURE ) && field.exists()) { + buf.append( field.getTypeName() ); + buf.append( ' ' ); + } + + //qualification + if( getFlag( flags, F_FULLY_QUALIFIED ) ){ + ICElement parent = field.getParent(); + if (parent != null && parent.exists()) { + getTypeLabel( parent, T_FULLY_QUALIFIED, buf ); + buf.append( "::" ); //$NON-NLS-1$ + } + } + + buf.append( field.getElementName() ); + + if( getFlag( flags, F_APP_TYPE_SIGNATURE ) && field.exists()) { + buf.append( DECL_STRING ); + buf.append( field.getTypeName() ); + } + + // post qualification + if( getFlag(flags, F_POST_QUALIFIED)) { + buf.append( CONCAT_STRING ); + getTypeLabel( field.getParent(), T_FULLY_QUALIFIED, buf ); + } + if( getFlag(flags, MF_POST_FILE_QUALIFIED)) { + IPath path= field.getPath(); + if (path != null) { + buf.append( CONCAT_STRING ); + buf.append(path.toString()); + } + } + } catch (CModelException e) { + CCorePlugin.log(e); + } + } + + /** + * Appends the label for a variable declaration to a StringBuffer. + * @param var a variable declaration + * @param flags any of the F_* flags, and MF_POST_FILE_QUALIFIED + * @param buf the buffer to append the label + */ + public static void getVariableLabel(IVariableDeclaration var, int flags, StringBuffer buf ) { + try { + //return type + if( getFlag( flags, F_PRE_TYPE_SIGNATURE ) && var.exists()) { + buf.append( var.getTypeName() ); + buf.append( ' ' ); + } + + //qualification + if( getFlag( flags, F_FULLY_QUALIFIED ) ){ + ICElement parent = var.getParent(); + if (parent != null && parent.exists() && parent.getElementType() == ICElement.C_NAMESPACE) { + getTypeLabel( parent, T_FULLY_QUALIFIED, buf ); + buf.append( "::" ); //$NON-NLS-1$ + } + } + + buf.append( var.getElementName() ); + + if( getFlag( flags, F_APP_TYPE_SIGNATURE ) && var.exists()) { + buf.append( DECL_STRING ); + buf.append( var.getTypeName() ); + } + + // post qualification + if( getFlag(flags, F_POST_QUALIFIED)) { + ICElement parent = var.getParent(); + if (parent != null && parent.exists() && parent.getElementType() == ICElement.C_NAMESPACE) { + buf.append( CONCAT_STRING ); + getTypeLabel( var.getParent(), T_FULLY_QUALIFIED, buf ); + } + } + if( getFlag(flags, MF_POST_FILE_QUALIFIED)) { + IPath path= var.getPath(); + if (path != null) { + buf.append( CONCAT_STRING ); + buf.append(path.toString()); + } + } + } catch (CModelException e) { + CCorePlugin.log(e); + } + } + + /** + * Appends the label for a function declaration to a StringBuffer. + * @param func a function declaration + * @param flags any of the M_* flags, and MF_POST_FILE_QUALIFIED + * @param buf the buffer to append the label + */ + public static void getFunctionLabel(IFunctionDeclaration func, int flags, StringBuffer buf) { + //return type + if( getFlag( flags, M_PRE_RETURNTYPE ) && func.exists()) { + buf.append( func.getReturnType() ); + buf.append( ' ' ); + } + + //qualification + if( getFlag( flags, M_FULLY_QUALIFIED ) ){ + ICElement parent = func.getParent(); + if (parent != null && parent.exists() && parent.getElementType() == ICElement.C_NAMESPACE) { + getTypeLabel( parent, T_FULLY_QUALIFIED, buf ); + buf.append( "::" ); //$NON-NLS-1$ + } + } + + buf.append( func.getElementName() ); + + //template parameters + if (func instanceof ITemplate) { + getTemplateParameters((ITemplate)func, flags, buf); + } + + //parameters + if( getFlag( flags, M_PARAMETER_TYPES ) ) { + buf.append('('); + + String[] types = func.getParameterTypes(); + + for (int i= 0; i < types.length; i++) { + if (i > 0) { + buf.append( COMMA_STRING ); + } + + if (types != null) { + buf.append( types[i] ); + } + } + buf.append(')'); + } + + //exceptions + if( getFlag( flags, M_EXCEPTIONS ) && func.exists() ){ + String [] types = func.getExceptions(); + if (types.length > 0) { + buf.append(" throw( "); //$NON-NLS-1$ + for (int i= 0; i < types.length; i++) { + if (i > 0) { + buf.append(COMMA_STRING); + } + buf.append( types[i] ); + } + buf.append( " )" ); //$NON-NLS-1$ + } + } + + if( getFlag( flags, M_APP_RETURNTYPE ) && func.exists()) { + String typeName= func.getReturnType(); + if (typeName != null && typeName.length() > 0) { + buf.append( DECL_STRING ); + buf.append(typeName); + } + } + + // post qualification + if( getFlag(flags, M_POST_QUALIFIED)) { + ICElement parent = func.getParent(); + if (parent != null && parent.exists() && parent.getElementType() == ICElement.C_NAMESPACE) { + buf.append( CONCAT_STRING ); + getTypeLabel( func.getParent(), T_FULLY_QUALIFIED, buf ); + } + } + if( getFlag(flags, MF_POST_FILE_QUALIFIED)) { + IPath path= func.getPath(); + if (path != null) { + buf.append( CONCAT_STRING ); + buf.append(path.toString()); + } + } + } + + /** + * Appends the label for a type definition to a StringBuffer. + * @param typedef a type definition + * @param flags any of the F_* flags, and MF_POST_FILE_QUALIFIED + * @param buf the buffer to append the label + */ + 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()) { + String typeName= typedef.getTypeName(); + if (typeName != null && typeName.length() > 0) { + buf.append( DECL_STRING ); + buf.append(typeName); + } + } + + // 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. + * @param root a source root + * @param flags any of the ROOT_* flags, and PROJECT_POST_QUALIFIED + * @param buf the buffer to append the label + */ + public static void getSourceRootLabel(ISourceRoot root, int flags, StringBuffer buf) { + getFolderLabel(root, flags, buf); + } + + /** + * Appends the label for a container to a StringBuffer. + * @param container a container + * @param flags any of the ROOT_* flags, and PROJECT_POST_QUALIFIED + * @param buf the buffer to append the label + */ + public static void getContainerLabel(ICContainer container, int flags, StringBuffer buf) { + getFolderLabel(container, flags, buf); + } + + private static void getFolderLabel(ICContainer container, int flags, StringBuffer buf) { + IResource resource= container.getResource(); + boolean rootQualified= getFlag(flags, ROOT_QUALIFIED); + boolean referencedQualified= getFlag(flags, PROJECT_POST_QUALIFIED) + && (container instanceof ISourceRoot && isReferenced((ISourceRoot)container)) + && resource != null; + if (rootQualified) { + buf.append(container.getPath().makeRelative().toString()); + } else { + buf.append(container.getElementName()); + if (referencedQualified) { + buf.append(CONCAT_STRING); + buf.append(resource.getProject().getName()); + } else if (getFlag(flags, ROOT_POST_QUALIFIED)) { + buf.append(CONCAT_STRING); + buf.append(container.getParent().getElementName()); + } + } + } + + /** + * Appends the label for a translation unit to a StringBuffer. + * @param tu a translation unit + * @param flags any of the TU_* flags + * @param buf the buffer to append the label + */ + public static void getTranslationUnitLabel(ITranslationUnit tu, int flags, StringBuffer buf) { + IResource r= tu.getResource(); + IPath path; + if (r != null) { + path= r.getFullPath().makeRelative(); + } + else { + path= tu.getPath(); + } + + if (path == null) { + buf.append(tu.getElementName()); + } + else { + if (getFlag(flags, TU_QUALIFIED)) { + buf.append(path.toString()); + } + else if (getFlag(flags, TU_POST_QUALIFIED)) { + buf.append(path.lastSegment()); + buf.append(CONCAT_STRING); + buf.append(path.removeLastSegments(1)); + } + else { + buf.append(path.lastSegment()); + } + } + } + + /** + * Appends the label for a type to a StringBuffer. + * @param elem a type + * @param flags any of the T_* flags, and MF_POST_FILE_QUALIFIED + * @param buf the buffer to append the label + */ + public static void getTypeLabel(ICElement elem, int flags, StringBuffer buf) { + if (getFlag(flags, T_FULLY_QUALIFIED)) { + ICElement parent= elem.getParent(); + boolean isQualifier= true; + if (parent != null && parent.exists()) { + switch (parent.getElementType()) { + case ICElement.C_ARCHIVE: + case ICElement.C_BINARY: + case ICElement.C_CCONTAINER: + case ICElement.C_MODEL: + case ICElement.C_PROJECT: + case ICElement.C_UNIT: + case ICElement.C_VCONTAINER: + isQualifier= false; + break; + } + } + // types cannot be qualified in plain c + if (isQualifier && !isCLanguage(parent)) { + int qflags= flags & ~MF_POST_FILE_QUALIFIED; + getTypeLabel(parent, qflags, buf); + buf.append("::"); //$NON-NLS-1$ + } + } + + String typeName= elem.getElementName(); + if (typeName.length() == 0) { // anonymous + typeName = CoreModelMessages.getString("CElementLabels.anonymous"); //$NON-NLS-1$ + } + 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); + } + + if( getFlag(flags, MF_POST_FILE_QUALIFIED)) { + IPath path= elem.getPath(); + if (path != null) { + buf.append( CONCAT_STRING ); + buf.append(path.toString()); + } + } + } + + private static boolean isCLanguage(ICElement elem) { + while (elem != null) { + elem= elem.getParent(); + if (elem instanceof ITranslationUnit) { + return ((ITranslationUnit) elem).isCLanguage(); + } + } + return false; + } + + /** + * 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; + } + + + /** + * Returns the source root of ICElement. If the given + * element is already a source root, the element itself is returned. + * @see org.eclipse.cdt.internal.corext.util.CModelUtil + */ + public static ISourceRoot getSourceRoot(ICElement element) { + ICElement root = element; + while (root != null) { + if (root instanceof ISourceRoot) + return (ISourceRoot)root; + ICElement parent = root.getAncestor(ICElement.C_CCONTAINER); + if (parent == root) + return null; + root = parent; + } + return null; + } + + /** + * Returns true if the given source root is + * referenced. This means it is own by a different project but is referenced + * by the root's parent. Returns false if the given root + * doesn't have an underlying resource. + * @see org.eclipse.cdt.internal.corext.util.CModelUtil + */ + public static boolean isReferenced(ISourceRoot root) { + IResource resource= root.getResource(); + if (resource != null) { + IProject project= resource.getProject(); + IProject container= root.getCProject().getProject(); + return !container.equals(project); + } + return false; + } +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CoreModelMessages.properties b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CoreModelMessages.properties index 25d3ac4c517..289157f1de3 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CoreModelMessages.properties +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CoreModelMessages.properties @@ -79,5 +79,10 @@ PathEntryManager.6=Referenced project is not a C/C++ project PathEntryManager.1=Workspace include path inaccessible ({0}) PathEntryManager.7=Workspace library path inaccessible ({0}) +CElementLabels.anonymous=(anon) +CElementLabels.concat_string=\ -\ +CElementLabels.comma_string=,\ +CElementLabels.declseparator_string=\ :\ + CProjectDescriptionManager.startRcChangeHandling=Initiating resource change handling.. CProjectDescriptionManager.serializing=Serialing CDT Project settings.. diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CUIMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CUIMessages.properties index 0a80d9eb39b..244e9300f21 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CUIMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CUIMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2002, 2006 IBM Corporation and others. +# Copyright (c) 2002, 2007 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 @@ -81,10 +81,6 @@ CTagsIndexerBlock.indexIncludes=Index include paths StatusBarUpdater.num_elements_selected={0} items selected -CElementLabels.anonymous=(anon) -CElementLabels.concat_string=\ -\ -CElementLabels.comma_string=,\ -CElementLabels.declseparator_string=\ :\ CHelpConfigurationPropertyPage.buttonLabels.CheckAll=Check All CHelpConfigurationPropertyPage.buttonLabels.UncheckAll=Uncheck All CHelpConfigurationPropertyPage.HelpBooks=Help books diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/OpenActionUtil.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/OpenActionUtil.java index b1cc659a209..7823ccf1bbe 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/OpenActionUtil.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/OpenActionUtil.java @@ -17,8 +17,9 @@ import java.util.List; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ISourceReference; +import org.eclipse.cdt.core.model.util.CElementBaseLabels; + import org.eclipse.cdt.internal.ui.util.EditorUtility; -import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels; import org.eclipse.cdt.internal.ui.viewsupport.CUILabelProvider; import org.eclipse.cdt.ui.CElementLabelProvider; @@ -76,7 +77,7 @@ public class OpenActionUtil { /** * Shows a dialog for resolving an ambigous C element. - * @see CElementLabels + * @see CElementBaseLabels * @param elements an array of ambigous elements. * @param shell parent shell for showing the dialog * @param title title of the dialog diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHHistoryAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHHistoryAction.java index 7e2ca095cb7..bb6355a3410 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHHistoryAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHHistoryAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2007 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 @@ -15,9 +15,9 @@ import org.eclipse.jface.action.Action; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.util.CElementBaseLabels; import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider; -import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels; /** @@ -25,9 +25,9 @@ import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels; */ public class CHHistoryAction extends Action { final static int LABEL_OPTIONS= - CElementLabels.M_PARAMETER_TYPES | - CElementLabels.ALL_FULLY_QUALIFIED | - CElementLabels.MF_POST_FILE_QUALIFIED; + CElementBaseLabels.M_PARAMETER_TYPES | + CElementBaseLabels.ALL_FULLY_QUALIFIED | + CElementBaseLabels.MF_POST_FILE_QUALIFIED; private CHViewPart fViewPart; private ICElement fElement; @@ -37,7 +37,7 @@ public class CHHistoryAction extends Action { fViewPart= viewPart; fElement= element; - String elementName= CElementLabels.getElementLabel(element, LABEL_OPTIONS); + String elementName= CElementBaseLabels.getElementLabel(element, LABEL_OPTIONS); setText(elementName); setImageDescriptor(getImageDescriptor(element)); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHLabelProvider.java index 08093eee4c3..5e93ea5a10c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHLabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHLabelProvider.java @@ -24,17 +24,17 @@ import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Display; import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.util.CElementBaseLabels; import org.eclipse.cdt.ui.CElementImageDescriptor; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider; -import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels; import org.eclipse.cdt.internal.ui.viewsupport.CUILabelProvider; import org.eclipse.cdt.internal.ui.viewsupport.ImageImageDescriptor; public class CHLabelProvider extends LabelProvider implements IColorProvider { - private final static int LABEL_OPTIONS_SIMPLE= CElementLabels.ALL_FULLY_QUALIFIED | CElementLabels.M_PARAMETER_TYPES; - private final static int LABEL_OPTIONS_SHOW_FILES= LABEL_OPTIONS_SIMPLE | CElementLabels.MF_POST_FILE_QUALIFIED; + private final static int LABEL_OPTIONS_SIMPLE= CElementBaseLabels.ALL_FULLY_QUALIFIED | CElementBaseLabels.M_PARAMETER_TYPES; + private final static int LABEL_OPTIONS_SHOW_FILES= LABEL_OPTIONS_SIMPLE | CElementBaseLabels.MF_POST_FILE_QUALIFIED; private CUILabelProvider fCLabelProvider= new CUILabelProvider(LABEL_OPTIONS_SIMPLE, 0); private CHContentProvider fContentProvider; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHViewPart.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHViewPart.java index ecafd09cc80..d944e34ee03 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHViewPart.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHViewPart.java @@ -63,6 +63,7 @@ import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.IFunction; import org.eclipse.cdt.core.model.IMethod; import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.core.model.util.CElementBaseLabels; import org.eclipse.cdt.refactoring.actions.CRefactoringActionGroup; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.actions.OpenViewActionGroup; @@ -618,7 +619,7 @@ public class CHViewPart extends ViewPart { String format, scope, label; // label - label= CElementLabels.getElementLabel(elem, CHHistoryAction.LABEL_OPTIONS); + label= CElementBaseLabels.getElementLabel(elem, CHHistoryAction.LABEL_OPTIONS); // scope IWorkingSet workingSet= fWorkingSetFilterUI.getWorkingSet(); @@ -681,7 +682,7 @@ public class CHViewPart extends ViewPart { final ICElement element= node.getRepresentedDeclaration(); if (element != null) { String label= Messages.format(CHMessages.CHViewPart_FocusOn_label, - CElementLabels.getTextLabel(element, CElementLabels.ALL_FULLY_QUALIFIED | CElementLabels.M_PARAMETER_TYPES)); + CElementLabels.getTextLabel(element, CElementBaseLabels.ALL_FULLY_QUALIFIED | CElementBaseLabels.M_PARAMETER_TYPES)); menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, new Action(label) { public void run() { setInput(element); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CallHierarchyUI.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CallHierarchyUI.java index 8349bc98e57..3c3eaf2db2c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CallHierarchyUI.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CallHierarchyUI.java @@ -35,11 +35,11 @@ import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndexManager; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.util.CElementBaseLabels; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.internal.ui.actions.OpenActionUtil; import org.eclipse.cdt.internal.ui.util.ExceptionHandler; -import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels; import org.eclipse.cdt.internal.ui.viewsupport.IndexUI; public class CallHierarchyUI { @@ -82,7 +82,7 @@ public class CallHierarchyUI { } elem = OpenActionUtil.selectCElement(input, window.getShell(), CHMessages.CallHierarchyUI_label, CHMessages.CallHierarchyUI_selectMessage, - CElementLabels.ALL_DEFAULT | CElementLabels.MF_POST_FILE_QUALIFIED, 0); + CElementBaseLabels.ALL_DEFAULT | CElementBaseLabels.MF_POST_FILE_QUALIFIED, 0); break; } if (elem != null) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java index 46d385a6b8e..fbd443c5b9d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java @@ -54,6 +54,7 @@ import org.eclipse.ui.views.navigator.LocalSelectionTransfer; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.core.model.util.CElementBaseLabels; import org.eclipse.cdt.refactoring.actions.CRefactoringActionGroup; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.PreferenceConstants; @@ -75,11 +76,10 @@ import org.eclipse.cdt.internal.ui.dnd.TransferDropTargetListener; import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup; import org.eclipse.cdt.internal.ui.util.ProblemTreeViewer; import org.eclipse.cdt.internal.ui.viewsupport.AppearanceAwareLabelProvider; -import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels; import org.eclipse.cdt.internal.ui.viewsupport.DecoratingCLabelProvider; public class CContentOutlinePage extends Page implements IContentOutlinePage, ISelectionChangedListener { - private static final int TEXT_FLAGS = AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS | CElementLabels.F_APP_TYPE_SIGNATURE | CElementLabels.M_APP_RETURNTYPE; + private static final int TEXT_FLAGS = AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS | CElementBaseLabels.F_APP_TYPE_SIGNATURE | CElementBaseLabels.M_APP_RETURNTYPE; private static final int IMAGE_FLAGS = AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS; private CEditor fEditor; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBHistoryAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBHistoryAction.java index 12b1a3aa0d3..9d72a660351 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBHistoryAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBHistoryAction.java @@ -15,9 +15,9 @@ import org.eclipse.jface.action.Action; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.core.model.util.CElementBaseLabels; import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider; -import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels; /** @@ -33,7 +33,7 @@ public class IBHistoryAction extends Action { fViewPart= viewPart; fElement= element; - String elementName= CElementLabels.getElementLabel(element, CElementLabels.ALL_POST_QUALIFIED); + String elementName= CElementBaseLabels.getElementLabel(element, CElementBaseLabels.ALL_POST_QUALIFIED); setText(elementName); setImageDescriptor(getImageDescriptor(element)); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBHistoryListAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBHistoryListAction.java index 6119899dd44..cd42b312088 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBHistoryListAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBHistoryListAction.java @@ -27,10 +27,10 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.core.model.util.CElementBaseLabels; import org.eclipse.cdt.internal.ui.dialogs.StatusInfo; import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider; -import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels; import org.eclipse.cdt.internal.ui.viewsupport.CUILabelProvider; import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField; import org.eclipse.cdt.internal.ui.wizards.dialogfields.IListAdapter; @@ -66,7 +66,7 @@ public class IBHistoryListAction extends Action { } }; - CUILabelProvider labelProvider= new CUILabelProvider(CElementLabels.APPEND_ROOT_PATH, CElementImageProvider.OVERLAY_ICONS); + CUILabelProvider labelProvider= new CUILabelProvider(CElementBaseLabels.APPEND_ROOT_PATH, CElementImageProvider.OVERLAY_ICONS); fHistoryList= new ListDialogField(adapter, buttonLabels, labelProvider); fHistoryList.setLabelText(IBMessages.IBHistoryListAction_HistoryList_label); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/COutlineInformationControl.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/COutlineInformationControl.java index 0ad4a400b8c..f8c2762038a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/COutlineInformationControl.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/COutlineInformationControl.java @@ -28,6 +28,7 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.core.model.util.CElementBaseLabels; import org.eclipse.cdt.internal.ui.CPluginImages; import org.eclipse.cdt.internal.ui.ICHelpContextIds; @@ -35,7 +36,6 @@ import org.eclipse.cdt.internal.ui.actions.ActionMessages; import org.eclipse.cdt.internal.ui.editor.CContentOutlinerProvider; import org.eclipse.cdt.internal.ui.util.ProblemTreeViewer; import org.eclipse.cdt.internal.ui.viewsupport.AppearanceAwareLabelProvider; -import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels; import org.eclipse.cdt.internal.ui.viewsupport.DecoratingCLabelProvider; /** @@ -46,7 +46,7 @@ import org.eclipse.cdt.internal.ui.viewsupport.DecoratingCLabelProvider; */ public class COutlineInformationControl extends AbstractInformationControl { - private static final int TEXT_FLAGS = AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS | CElementLabels.F_APP_TYPE_SIGNATURE | CElementLabels.M_APP_RETURNTYPE; + private static final int TEXT_FLAGS = AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS | CElementBaseLabels.F_APP_TYPE_SIGNATURE | CElementBaseLabels.M_APP_RETURNTYPE; private static final int IMAGE_FLAGS = AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS; private ICElement fInput = null; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/THHistoryAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/THHistoryAction.java index 37fd5ae0701..eba799e00af 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/THHistoryAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/THHistoryAction.java @@ -15,9 +15,9 @@ import org.eclipse.jface.action.Action; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.util.CElementBaseLabels; import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider; -import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels; /** @@ -25,9 +25,9 @@ import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels; */ public class THHistoryAction extends Action { final static int LABEL_OPTIONS= - CElementLabels.M_PARAMETER_TYPES | - CElementLabels.ALL_FULLY_QUALIFIED | - CElementLabels.MF_POST_FILE_QUALIFIED; + CElementBaseLabels.M_PARAMETER_TYPES | + CElementBaseLabels.ALL_FULLY_QUALIFIED | + CElementBaseLabels.MF_POST_FILE_QUALIFIED; private THViewPart fViewPart; private ICElement fElement; @@ -37,7 +37,7 @@ public class THHistoryAction extends Action { fViewPart= hierarchyView; fElement= element; - String elementName= CElementLabels.getElementLabel(element, LABEL_OPTIONS); + String elementName= CElementBaseLabels.getElementLabel(element, LABEL_OPTIONS); setText(elementName); setImageDescriptor(getImageDescriptor(element)); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/THLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/THLabelProvider.java index 0925f46e0c5..ab4adbe0abe 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/THLabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/THLabelProvider.java @@ -24,16 +24,16 @@ import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Display; import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.util.CElementBaseLabels; import org.eclipse.cdt.ui.CElementImageDescriptor; import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider; -import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels; import org.eclipse.cdt.internal.ui.viewsupport.CUILabelProvider; import org.eclipse.cdt.internal.ui.viewsupport.ImageImageDescriptor; public class THLabelProvider extends LabelProvider implements IColorProvider { - private final static int LABEL_OPTIONS_SIMPLE= CElementLabels.ALL_FULLY_QUALIFIED | CElementLabels.M_PARAMETER_TYPES; - private final static int LABEL_OPTIONS_SHOW_FILES= LABEL_OPTIONS_SIMPLE | CElementLabels.MF_POST_FILE_QUALIFIED; + private final static int LABEL_OPTIONS_SIMPLE= CElementBaseLabels.ALL_FULLY_QUALIFIED | CElementBaseLabels.M_PARAMETER_TYPES; + private final static int LABEL_OPTIONS_SHOW_FILES= LABEL_OPTIONS_SIMPLE | CElementBaseLabels.MF_POST_FILE_QUALIFIED; private CUILabelProvider fCLabelProvider= new CUILabelProvider(LABEL_OPTIONS_SIMPLE, 0); private THHierarchyModel fModel; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/THViewPart.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/THViewPart.java index 5821a856ca5..6afca3a9ab2 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/THViewPart.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/THViewPart.java @@ -77,6 +77,7 @@ import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.IDeclaration; import org.eclipse.cdt.core.model.IMember; import org.eclipse.cdt.core.model.IMethodDeclaration; +import org.eclipse.cdt.core.model.util.CElementBaseLabels; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.refactoring.actions.CRefactoringActionGroup; import org.eclipse.cdt.ui.CUIPlugin; @@ -117,8 +118,8 @@ public class THViewPart extends ViewPart implements ITHModelPresenter { private static final int ORIENTATION_SINGLE = 3; // options for label provider - private static final int MEMBER_LABEL_OPTIONS_SIMPLE = CElementLabels.M_PARAMETER_TYPES; - private static final int MEMBER_LABEL_OPTIONS_QUALIFIED = MEMBER_LABEL_OPTIONS_SIMPLE | CElementLabels.ALL_POST_QUALIFIED; + private static final int MEMBER_LABEL_OPTIONS_SIMPLE = CElementBaseLabels.M_PARAMETER_TYPES; + private static final int MEMBER_LABEL_OPTIONS_QUALIFIED = MEMBER_LABEL_OPTIONS_SIMPLE | CElementBaseLabels.ALL_POST_QUALIFIED; private static final int MEMBER_ICON_OPTIONS = CElementImageProvider.OVERLAY_ICONS; // state information @@ -378,7 +379,7 @@ public class THViewPart extends ViewPart implements ITHModelPresenter { if (hierarchyView && !elem.equals(fModel.getInput())) { String label= MessageFormat.format(Messages.THViewPart_FocusOn, new Object[] { - CElementLabels.getTextLabel(elem, CElementLabels.ALL_FULLY_QUALIFIED | CElementLabels.M_PARAMETER_TYPES) + CElementLabels.getTextLabel(elem, CElementBaseLabels.ALL_FULLY_QUALIFIED | CElementBaseLabels.M_PARAMETER_TYPES) }); menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, new Action(label) { public void run() { @@ -816,7 +817,7 @@ public class THViewPart extends ViewPart implements ITHModelPresenter { String label; // label - label= CElementLabels.getElementLabel(elem, 0); + label= CElementBaseLabels.getElementLabel(elem, 0); // scope IWorkingSet workingSet= fWorkingSetFilterUI.getWorkingSet(); @@ -834,7 +835,7 @@ public class THViewPart extends ViewPart implements ITHModelPresenter { if (node != null) { elem= node.getElement(); if (elem != null) { - label= CElementLabels.getElementLabel(elem, 0); + label= CElementBaseLabels.getElementLabel(elem, 0); image= fHierarchyLabelProvider.getImage(elem); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/AppearanceAwareLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/AppearanceAwareLabelProvider.java index 36d8400b3af..91370945b69 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/AppearanceAwareLabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/AppearanceAwareLabelProvider.java @@ -15,13 +15,15 @@ package org.eclipse.cdt.internal.ui.viewsupport; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.cdt.core.model.util.CElementBaseLabels; + /** * CUILabelProvider that respects settings from the Appearance preference page. * Triggers a viewer update when a preference changes (currently none). */ public class AppearanceAwareLabelProvider extends CUILabelProvider implements IPropertyChangeListener { - public final static int DEFAULT_TEXTFLAGS= CElementLabels.M_PARAMETER_TYPES | CElementLabels.PROJECT_POST_QUALIFIED; + public final static int DEFAULT_TEXTFLAGS= CElementBaseLabels.M_PARAMETER_TYPES | CElementBaseLabels.PROJECT_POST_QUALIFIED; public final static int DEFAULT_IMAGEFLAGS= CElementImageProvider.OVERLAY_ICONS; private int fTextFlagMask; 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 f30df5ef4e2..52abdcaa81c 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 @@ -14,194 +14,16 @@ */ package org.eclipse.cdt.internal.ui.viewsupport; -import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IPath; import org.eclipse.ui.model.IWorkbenchAdapter; -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.IBinary; -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; - -import org.eclipse.cdt.internal.ui.CUIMessages; +import org.eclipse.cdt.core.model.util.CElementBaseLabels; /** * @author aniefer - * */ -public class CElementLabels { - - /** - * Method names contain parameter types. - * e.g. foo(int) - */ - public final static int M_PARAMETER_TYPES= 1 << 0; - - /** - * Method names contain thrown exceptions. - * e.g. foo throw( IOException ) - */ - public final static int M_EXCEPTIONS= 1 << 2; - - /** - * Method names contain return type (appended) - * e.g. foo : int - */ - public final static int M_APP_RETURNTYPE= 1 << 3; - - /** - * Method names contain return type (appended) - * e.g. int foo - */ - public final static int M_PRE_RETURNTYPE= 1 << 4; - - /** - * Method names are fully qualified. - * e.g. ClassName::size - */ - public final static int M_FULLY_QUALIFIED= 1 << 5; - - /** - * Method names are post qualified. - * e.g. size - ClassName - */ - public final static int M_POST_QUALIFIED= 1 << 6; - - /** - * Templates are qualified with template parameters. - * e.g. ClassName - */ - public final static int TEMPLATE_PARAMETERS= 1 << 7; - - /** - * Field names contain the declared type (appended) - * e.g. fHello: int - */ - public final static int F_APP_TYPE_SIGNATURE= 1 << 9; - - /** - * Field names contain the declared type (prepended) - * e.g. int fHello - */ - public final static int F_PRE_TYPE_SIGNATURE= 1 << 10; - - /** - * Fields names are fully qualified. - * e.g. ClassName::fField - */ - public final static int F_FULLY_QUALIFIED= 1 << 11; - - /** - * Fields names are post qualified. - * e.g. fField - ClassName - */ - public final static int F_POST_QUALIFIED= 1 << 12; - - /** - * Type names are fully qualified. - * e.g. namespace::ClassName - */ - public final static int T_FULLY_QUALIFIED= 1 << 13; - - /** - * Append base class specifications to type names. - * e.g. MyClass : public BaseClass - */ - public final static int T_INHERITANCE= 1 << 16; - - /** - * Translation unit names contain the full path. - * e.g. /MyProject/src/ClassName.cpp - */ - public final static int TU_QUALIFIED= 1 << 20; - - /** - * Translation unit names are post qualified with their path. - * e.g. ClassName.cpp - /MyProject/src - */ - public final static int TU_POST_QUALIFIED= 1 << 21; - - /** - * Source roots contain the project name (prepended). - * e.g. MyProject/src - */ - public final static int ROOT_QUALIFIED= 1 << 25; - - /** - * Source roots contain the project name (appended). - * e.g. src - MyProject - */ - public final static int ROOT_POST_QUALIFIED= 1 << 26; - - /** - * Add source root path. - * e.g. func() - MyProject/src - * Option only applies to getElementLabel - */ - public final static int APPEND_ROOT_PATH= 1 << 27; - - /** - * Prepend source root path. - * e.g. MyProject/src - func() - * Option only applies to getElementLabel - */ - public final static int PREPEND_ROOT_PATH= 1 << 28; - - /** - * Post qualify container project. For example - * folder - MyProject if the folder is in project MyProject. - */ - public final static int PROJECT_POST_QUALIFIED= 1 << 30; - - /** - * Post qualify symbols with file. - * e.g. func() - /proj/folder/file.cpp - */ - public final static int MF_POST_FILE_QUALIFIED= 1 << 31; - - /** - * Qualify all elements - */ - public final static int ALL_FULLY_QUALIFIED= F_FULLY_QUALIFIED | M_FULLY_QUALIFIED | T_FULLY_QUALIFIED | TU_QUALIFIED | ROOT_QUALIFIED; - - /** - * Post qualify all elements - */ - 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) - */ - public final static int ALL_DEFAULT= M_PARAMETER_TYPES; - - /** - * Default qualify options (All except Root) - */ - public final static int DEFAULT_QUALIFIED= F_FULLY_QUALIFIED | M_FULLY_QUALIFIED | T_FULLY_QUALIFIED | TU_QUALIFIED; - - /** - * Default post qualify options (All except Root) - */ - 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 COMMA_STRING = CUIMessages.getString("CElementLabels.comma_string"); // ", "; //$NON-NLS-1$ - public final static String DECL_STRING = CUIMessages.getString("CElementLabels.declseparator_string"); // " "; // use for return type //$NON-NLS-1$ +public class CElementLabels extends CElementBaseLabels { public static String getTextLabel(Object obj, int flags) { if (obj instanceof ICElement) { @@ -214,551 +36,4 @@ public class CElementLabels { } return ""; //$NON-NLS-1$ } - - public static String getElementLabel(ICElement element, int flags) { - StringBuffer buf= new StringBuffer(60); - getElementLabel(element, flags, buf); - return buf.toString(); - } - - public static void getElementLabel(ICElement element, int flags, StringBuffer buf) { - int type= element.getElementType(); - ISourceRoot root= null; - - if (type != ICElement.C_MODEL && type != ICElement.C_PROJECT && !(type == ICElement.C_CCONTAINER && element instanceof ISourceRoot)) - root= CModelUtil.getSourceRoot(element); - if (root != null && getFlag(flags, PREPEND_ROOT_PATH)) { - getSourceRootLabel(root, ROOT_QUALIFIED, buf); - buf.append(CONCAT_STRING); - } - switch (type) { - case ICElement.C_METHOD : - case ICElement.C_METHOD_DECLARATION: - case ICElement.C_TEMPLATE_METHOD: - case ICElement.C_TEMPLATE_METHOD_DECLARATION: - getMethodLabel( (IMethodDeclaration) element, flags, buf ); - break; - case ICElement.C_FUNCTION: - case ICElement.C_FUNCTION_DECLARATION: - case ICElement.C_TEMPLATE_FUNCTION: - case ICElement.C_TEMPLATE_FUNCTION_DECLARATION: - getFunctionLabel( (IFunctionDeclaration) element, flags, buf); - break; - case ICElement.C_FIELD : - getFieldLabel( (IField) element, flags, buf ); - break; - case ICElement.C_VARIABLE: - case ICElement.C_VARIABLE_DECLARATION: - getVariableLabel( (IVariableDeclaration) element, flags, buf); - break; - case ICElement.C_CLASS: - case ICElement.C_STRUCT: - case ICElement.C_UNION: - case ICElement.C_ENUMERATION: - case ICElement.C_TEMPLATE_CLASS: - case ICElement.C_TEMPLATE_STRUCT: - case ICElement.C_TEMPLATE_UNION: - case ICElement.C_TEMPLATE_CLASS_DECLARATION: - case ICElement.C_TEMPLATE_STRUCT_DECLARATION: - 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; - case ICElement.C_CCONTAINER: - ICContainer container = (ICContainer) element; - if (container instanceof ISourceRoot) - getSourceRootLabel((ISourceRoot) container, flags, buf); - else - getContainerLabel(container, flags, buf); - break; - case ICElement.C_PROJECT: - case ICElement.C_MODEL: - buf.append(element.getElementName()); - break; - default: - buf.append(element.getElementName()); - } - - if (root != null && getFlag(flags, APPEND_ROOT_PATH)) { - buf.append(CONCAT_STRING); - getSourceRootLabel(root, ROOT_QUALIFIED, buf); - } - - if (element instanceof IBinary) { - IBinary bin = (IBinary)element; - buf.append(" - [" + bin.getCPU() + "/" + (bin.isLittleEndian() ? "le" : "be") + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ - } - - } - - public static void getMethodLabel( IMethodDeclaration method, int flags, StringBuffer buf ) { - try { - //return type - if( getFlag( flags, M_PRE_RETURNTYPE ) && method.exists() && !method.isConstructor() ) { - buf.append( method.getReturnType() ); - buf.append( ' ' ); - } - - //qualification - if( getFlag( flags, M_FULLY_QUALIFIED ) ){ - ICElement parent = method.getParent(); - if (parent != null && parent.exists() && !(parent instanceof ITranslationUnit)) { - getTypeLabel( parent, T_FULLY_QUALIFIED, buf ); - buf.append( "::" ); //$NON-NLS-1$ - } - } - - buf.append( method.getElementName() ); - - //template parameters - if (method instanceof ITemplate) { - getTemplateParameters((ITemplate)method, flags, buf); - } - - //parameters - if( getFlag( flags, M_PARAMETER_TYPES ) ) { - buf.append('('); - - String[] types = method.getParameterTypes(); - - for (int i= 0; i < types.length; i++) { - if (i > 0) { - buf.append( COMMA_STRING ); - } - - if (types != null) { - buf.append( types[i] ); - } - } - buf.append(')'); - } - - //exceptions - if( getFlag( flags, M_EXCEPTIONS ) && method.exists() ){ - String [] types = method.getExceptions(); - if (types.length > 0) { - buf.append(" throw( "); //$NON-NLS-1$ - for (int i= 0; i < types.length; i++) { - if (i > 0) { - buf.append(COMMA_STRING); - } - buf.append( types[i] ); - } - buf.append( " )" ); //$NON-NLS-1$ - } - } - - if( getFlag( flags, M_APP_RETURNTYPE ) && method.exists() && !method.isConstructor() && !method.isDestructor()) { - final String typeName= method.getReturnType(); - if (typeName != null && typeName.length() > 0) { - buf.append( DECL_STRING ); - buf.append(typeName); - } - } - - // post qualification - if( getFlag(flags, M_POST_QUALIFIED)) { - buf.append( CONCAT_STRING ); - getTypeLabel( method.getParent(), T_FULLY_QUALIFIED, buf ); - } - if( getFlag(flags, MF_POST_FILE_QUALIFIED)) { - IPath path= method.getPath(); - if (path != null) { - buf.append( CONCAT_STRING ); - buf.append(path.toString()); - } - } - } catch (CModelException e) { - CUIPlugin.getDefault().log(e); - } - } - - private static void getTemplateParameters(ITemplate template, int flags, StringBuffer buf) { - if (getFlag(flags, TEMPLATE_PARAMETERS)) { - String[] types = template.getTemplateParameterTypes(); - buf.append('<'); - if (types != null) { - for (int i= 0; i < types.length; i++) { - if (i > 0) { - buf.append( ',' ); - } - buf.append( types[i] ); - } - } - buf.append('>'); - } - } - - public static void getFieldLabel(IField field, int flags, StringBuffer buf ) { - try { - //return type - if( getFlag( flags, F_PRE_TYPE_SIGNATURE ) && field.exists()) { - buf.append( field.getTypeName() ); - buf.append( ' ' ); - } - - //qualification - if( getFlag( flags, F_FULLY_QUALIFIED ) ){ - ICElement parent = field.getParent(); - if (parent != null && parent.exists()) { - getTypeLabel( parent, T_FULLY_QUALIFIED, buf ); - buf.append( "::" ); //$NON-NLS-1$ - } - } - - buf.append( field.getElementName() ); - - if( getFlag( flags, F_APP_TYPE_SIGNATURE ) && field.exists()) { - buf.append( DECL_STRING ); - buf.append( field.getTypeName() ); - } - - // post qualification - if( getFlag(flags, F_POST_QUALIFIED)) { - buf.append( CONCAT_STRING ); - getTypeLabel( field.getParent(), T_FULLY_QUALIFIED, buf ); - } - if( getFlag(flags, MF_POST_FILE_QUALIFIED)) { - IPath path= field.getPath(); - if (path != null) { - buf.append( CONCAT_STRING ); - buf.append(path.toString()); - } - } - } catch (CModelException e) { - CUIPlugin.getDefault().log(e); - } - } - - public static void getVariableLabel(IVariableDeclaration var, int flags, StringBuffer buf ) { - try { - //return type - if( getFlag( flags, F_PRE_TYPE_SIGNATURE ) && var.exists()) { - buf.append( var.getTypeName() ); - buf.append( ' ' ); - } - - //qualification - if( getFlag( flags, F_FULLY_QUALIFIED ) ){ - ICElement parent = var.getParent(); - if (parent != null && parent.exists() && parent.getElementType() == ICElement.C_NAMESPACE) { - getTypeLabel( parent, T_FULLY_QUALIFIED, buf ); - buf.append( "::" ); //$NON-NLS-1$ - } - } - - buf.append( var.getElementName() ); - - if( getFlag( flags, F_APP_TYPE_SIGNATURE ) && var.exists()) { - buf.append( DECL_STRING ); - buf.append( var.getTypeName() ); - } - - // post qualification - if( getFlag(flags, F_POST_QUALIFIED)) { - ICElement parent = var.getParent(); - if (parent != null && parent.exists() && parent.getElementType() == ICElement.C_NAMESPACE) { - buf.append( CONCAT_STRING ); - getTypeLabel( var.getParent(), T_FULLY_QUALIFIED, buf ); - } - } - if( getFlag(flags, MF_POST_FILE_QUALIFIED)) { - IPath path= var.getPath(); - if (path != null) { - buf.append( CONCAT_STRING ); - buf.append(path.toString()); - } - } - } catch (CModelException e) { - CUIPlugin.getDefault().log(e); - } - } - - public static void getFunctionLabel(IFunctionDeclaration func, int flags, StringBuffer buf) { - //return type - if( getFlag( flags, M_PRE_RETURNTYPE ) && func.exists()) { - buf.append( func.getReturnType() ); - buf.append( ' ' ); - } - - //qualification - if( getFlag( flags, M_FULLY_QUALIFIED ) ){ - ICElement parent = func.getParent(); - if (parent != null && parent.exists() && parent.getElementType() == ICElement.C_NAMESPACE) { - getTypeLabel( parent, T_FULLY_QUALIFIED, buf ); - buf.append( "::" ); //$NON-NLS-1$ - } - } - - buf.append( func.getElementName() ); - - //template parameters - if (func instanceof ITemplate) { - getTemplateParameters((ITemplate)func, flags, buf); - } - - //parameters - if( getFlag( flags, M_PARAMETER_TYPES ) ) { - buf.append('('); - - String[] types = func.getParameterTypes(); - - for (int i= 0; i < types.length; i++) { - if (i > 0) { - buf.append( COMMA_STRING ); - } - - if (types != null) { - buf.append( types[i] ); - } - } - buf.append(')'); - } - - //exceptions - if( getFlag( flags, M_EXCEPTIONS ) && func.exists() ){ - String [] types = func.getExceptions(); - if (types.length > 0) { - buf.append(" throw( "); //$NON-NLS-1$ - for (int i= 0; i < types.length; i++) { - if (i > 0) { - buf.append(COMMA_STRING); - } - buf.append( types[i] ); - } - buf.append( " )" ); //$NON-NLS-1$ - } - } - - if( getFlag( flags, M_APP_RETURNTYPE ) && func.exists()) { - String typeName= func.getReturnType(); - if (typeName != null && typeName.length() > 0) { - buf.append( DECL_STRING ); - buf.append(typeName); - } - } - - // post qualification - if( getFlag(flags, M_POST_QUALIFIED)) { - ICElement parent = func.getParent(); - if (parent != null && parent.exists() && parent.getElementType() == ICElement.C_NAMESPACE) { - buf.append( CONCAT_STRING ); - getTypeLabel( func.getParent(), T_FULLY_QUALIFIED, buf ); - } - } - if( getFlag(flags, MF_POST_FILE_QUALIFIED)) { - IPath path= func.getPath(); - if (path != null) { - buf.append( CONCAT_STRING ); - buf.append(path.toString()); - } - } - } - - 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()) { - String typeName= typedef.getTypeName(); - if (typeName != null && typeName.length() > 0) { - buf.append( DECL_STRING ); - buf.append(typeName); - } - } - - // 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. - */ - public static void getSourceRootLabel(ISourceRoot root, int flags, StringBuffer buf) { - getFolderLabel(root, flags, buf); - } - - /** - * Appends the label for a container to a StringBuffer. Considers the ROOT_* flags. - */ - public static void getContainerLabel(ICContainer container, int flags, StringBuffer buf) { - getFolderLabel(container, flags, buf); - } - - private static void getFolderLabel(ICContainer container, int flags, StringBuffer buf) { - IResource resource= container.getResource(); - boolean rootQualified= getFlag(flags, ROOT_QUALIFIED); - boolean referencedQualified= getFlag(flags, PROJECT_POST_QUALIFIED) - && (container instanceof ISourceRoot && CModelUtil.isReferenced((ISourceRoot)container)) - && resource != null; - if (rootQualified) { - buf.append(container.getPath().makeRelative().toString()); - } else { - buf.append(container.getElementName()); - if (referencedQualified) { - buf.append(CONCAT_STRING); - buf.append(resource.getProject().getName()); - } else if (getFlag(flags, ROOT_POST_QUALIFIED)) { - buf.append(CONCAT_STRING); - buf.append(container.getParent().getElementName()); - } - } - } - - /** - * Appends the label for a translation unit to a StringBuffer. Considers the CU_* flags. - */ - public static void getTranslationUnitLabel(ITranslationUnit tu, int flags, StringBuffer buf) { - IResource r= tu.getResource(); - IPath path; - if (r != null) { - path= r.getFullPath().makeRelative(); - } - else { - path= tu.getPath(); - } - - if (path == null) { - buf.append(tu.getElementName()); - } - else { - if (getFlag(flags, TU_QUALIFIED)) { - buf.append(path.toString()); - } - else if (getFlag(flags, TU_POST_QUALIFIED)) { - buf.append(path.lastSegment()); - buf.append(CONCAT_STRING); - buf.append(path.removeLastSegments(1)); - } - else { - buf.append(path.lastSegment()); - } - } - } - - /** - * Appends the label for a type to a StringBuffer. Considers the T_* flags. - */ - public static void getTypeLabel(ICElement elem, int flags, StringBuffer buf) { - if (getFlag(flags, T_FULLY_QUALIFIED)) { - ICElement parent= elem.getParent(); - boolean isQualifier= true; - if (parent != null && parent.exists()) { - switch (parent.getElementType()) { - case ICElement.C_ARCHIVE: - case ICElement.C_BINARY: - case ICElement.C_CCONTAINER: - case ICElement.C_MODEL: - case ICElement.C_PROJECT: - case ICElement.C_UNIT: - case ICElement.C_VCONTAINER: - isQualifier= false; - break; - } - } - // types cannot be qualified in plain c - if (isQualifier && !isCLanguage(parent)) { - int qflags= flags & ~MF_POST_FILE_QUALIFIED; - getTypeLabel(parent, qflags, buf); - buf.append("::"); //$NON-NLS-1$ - } - } - - String typeName= elem.getElementName(); - if (typeName.length() == 0) { // anonymous - typeName = CUIMessages.getString("CElementLabels.anonymous"); //$NON-NLS-1$ - } - 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); - } - - if( getFlag(flags, MF_POST_FILE_QUALIFIED)) { - IPath path= elem.getPath(); - if (path != null) { - buf.append( CONCAT_STRING ); - buf.append(path.toString()); - } - } - } - - private static boolean isCLanguage(ICElement elem) { - while (elem != null) { - elem= elem.getParent(); - if (elem instanceof ITranslationUnit) { - return ((ITranslationUnit) elem).isCLanguage(); - } - } - return false; - } - - /** - * 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; - } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CUILabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CUILabelProvider.java index 0b0513e5f1a..0bd40a53224 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CUILabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/CUILabelProvider.java @@ -24,6 +24,7 @@ import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Display; import org.eclipse.cdt.core.model.IInclude; +import org.eclipse.cdt.core.model.util.CElementBaseLabels; import org.eclipse.cdt.ui.CUIPlugin; public class CUILabelProvider extends LabelProvider implements IColorProvider { @@ -41,11 +42,11 @@ public class CUILabelProvider extends LabelProvider implements IColorProvider { * Creates a new label provider with default flags. */ public CUILabelProvider() { - this(CElementLabels.M_PARAMETER_TYPES, CElementImageProvider.OVERLAY_ICONS); + this(CElementBaseLabels.M_PARAMETER_TYPES, CElementImageProvider.OVERLAY_ICONS); } /** - * @param textFlags Flags defined in CElementLabels. + * @param textFlags Flags defined in CElementBaseLabels. * @param imageFlags Flags defined in CElementImageProvider. */ public CUILabelProvider(int textFlags, int imageFlags) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/StatusBarUpdater.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/StatusBarUpdater.java index 8a2bf2f21c6..4b95f018fdd 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/StatusBarUpdater.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/StatusBarUpdater.java @@ -12,6 +12,8 @@ package org.eclipse.cdt.internal.ui.viewsupport; import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.util.CElementBaseLabels; + import org.eclipse.cdt.internal.ui.CUIMessages; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IResource; @@ -27,9 +29,9 @@ import org.eclipse.jface.viewers.SelectionChangedEvent; */ public class StatusBarUpdater implements ISelectionChangedListener { - private final int LABEL_FLAGS= CElementLabels.DEFAULT_QUALIFIED | CElementLabels.ROOT_POST_QUALIFIED | CElementLabels.APPEND_ROOT_PATH | - CElementLabels.M_PARAMETER_TYPES | CElementLabels.M_APP_RETURNTYPE | CElementLabels.M_EXCEPTIONS | - CElementLabels.F_APP_TYPE_SIGNATURE; + private final int LABEL_FLAGS= CElementBaseLabels.DEFAULT_QUALIFIED | CElementBaseLabels.ROOT_POST_QUALIFIED | CElementBaseLabels.APPEND_ROOT_PATH | + CElementBaseLabels.M_PARAMETER_TYPES | CElementBaseLabels.M_APP_RETURNTYPE | CElementBaseLabels.M_EXCEPTIONS | + CElementBaseLabels.F_APP_TYPE_SIGNATURE; private IStatusLineManager fStatusLineManager; @@ -65,13 +67,13 @@ public class StatusBarUpdater implements ISelectionChangedListener { } private String formatCElementMessage(ICElement element) { - return CElementLabels.getElementLabel(element, LABEL_FLAGS); + return CElementBaseLabels.getElementLabel(element, LABEL_FLAGS); } private String formatResourceMessage(IResource element) { IContainer parent= element.getParent(); if (parent != null && parent.getType() != IResource.ROOT) - return element.getName() + CElementLabels.CONCAT_STRING + parent.getFullPath().makeRelative().toString(); + return element.getName() + CElementBaseLabels.CONCAT_STRING + parent.getFullPath().makeRelative().toString(); return element.getName(); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementLabelProvider.java index 3c14585c9af..dd282ebb3ba 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementLabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementLabelProvider.java @@ -17,9 +17,9 @@ import org.eclipse.swt.graphics.Image; import org.eclipse.ui.model.WorkbenchLabelProvider; import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.util.CElementBaseLabels; import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider; -import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels; import org.eclipse.cdt.internal.ui.viewsupport.CUILabelProvider; /** @@ -99,7 +99,7 @@ public class CElementLabelProvider extends LabelProvider { fImageLabelProvider= new CElementImageProvider(); fFlags = flags; - fCElementLabelProvider= new CUILabelProvider(getTextFlags() | CElementLabels.TEMPLATE_PARAMETERS, getImageFlags()); + fCElementLabelProvider= new CUILabelProvider(getTextFlags() | CElementBaseLabels.TEMPLATE_PARAMETERS, getImageFlags()); } public String getText(Object element) { @@ -154,16 +154,16 @@ public class CElementLabelProvider extends LabelProvider { public int getTextFlags() { fTextFlags = 0; if (getFlag(SHOW_RETURN_TYPE)) { - fTextFlags |= CElementLabels.M_APP_RETURNTYPE; + fTextFlags |= CElementBaseLabels.M_APP_RETURNTYPE; } if (getFlag(SHOW_PARAMETERS)) { - fTextFlags |= CElementLabels.M_PARAMETER_TYPES; + fTextFlags |= CElementBaseLabels.M_PARAMETER_TYPES; } if (getFlag(SHOW_EXCEPTION)) { - fTextFlags |= CElementLabels.M_EXCEPTIONS; + fTextFlags |= CElementBaseLabels.M_EXCEPTIONS; } if (getFlag(SHOW_POST_QUALIFIED)) { - fTextFlags |= CElementLabels.M_POST_QUALIFIED; + fTextFlags |= CElementBaseLabels.M_POST_QUALIFIED; } return fTextFlags; }