From f5841dcac03eae2f91ca3e5db41cd87ccc0dbcb9 Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Mon, 18 Jun 2007 12:54:31 +0000 Subject: [PATCH] Fix for 192866: Include at wrong position in Outline --- .../internal/core/model/CModelBuilder2.java | 12 +++- .../cdt/internal/core/model/Include.java | 18 +++++- .../ui/editor/LexicalSortingAction.java | 63 +++++++++++++++---- .../ui/text/COutlineInformationControl.java | 56 ++++++++++++++--- 4 files changed, 124 insertions(+), 25 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder2.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelBuilder2.java index 2614a4155c8..37db7bdd9a3 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 @@ -13,7 +13,9 @@ package org.eclipse.cdt.internal.core.model; import java.util.Collections; import java.util.Comparator; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.Stack; import org.eclipse.cdt.core.CCorePlugin; @@ -286,10 +288,11 @@ public class CModelBuilder2 implements IContributedModelBuilder { // includes final IASTPreprocessorIncludeStatement[] includeDirectives= ast.getIncludeDirectives(); + Set allIncludes= new HashSet(); for (int i= 0; i < includeDirectives.length; i++) { IASTPreprocessorIncludeStatement includeDirective= includeDirectives[i]; if (isLocalToFile(includeDirective)) { - createInclusion(fTranslationUnit, includeDirective); + createInclusion(fTranslationUnit, includeDirective, allIncludes); } } // macros @@ -357,13 +360,18 @@ public class CModelBuilder2 implements IContributedModelBuilder { return fTranslationUnitFileName.equals(node.getContainingFilename()); } - private Include createInclusion(Parent parent, IASTPreprocessorIncludeStatement inclusion) throws CModelException{ + private Include createInclusion(Parent parent, IASTPreprocessorIncludeStatement inclusion, Set allIncludes) throws CModelException{ // create element final IASTName name= inclusion.getName(); Include element= new Include(parent, ASTStringUtil.getSimpleName(name), inclusion.isSystemInclude()); element.setFullPathName(inclusion.getPath()); element.setActive(inclusion.isActive()); element.setResolved(inclusion.isResolved()); + // if there is a duplicate include, also set the index + if (!allIncludes.add(element)) { + element.setIndex(allIncludes.size()); + allIncludes.add(element); + } // add to parent parent.addChild(element); // set positions diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Include.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Include.java index e639721494c..b2c989452c9 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Include.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Include.java @@ -21,6 +21,7 @@ public class Include extends SourceManipulation implements IInclude { private String fullPath; private boolean fIsActive= true; private boolean fIsResolved= true; + private int fIndex= 0; public Include(ICElement parent, String name, boolean isStandard) { super(parent, name, ICElement.C_INCLUDE); @@ -79,12 +80,25 @@ public class Include extends SourceManipulation implements IInclude { return fIsResolved; } + /** + * Set the index of this include, in case the same include is referenced + * multiple times. + * + * @param index + */ + public void setIndex(int index) { + fIndex= index; + } + /* * @see org.eclipse.cdt.internal.core.model.CElement#equals(java.lang.Object) */ public boolean equals(Object other) { - if (other instanceof IInclude) { - return equals(this, (IInclude) other); + if (other instanceof IInclude && equals(this, (IInclude) other)) { + if (other instanceof Include) { + return fIndex == ((Include)other).fIndex; + } + return true; } return false; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/LexicalSortingAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/LexicalSortingAction.java index 0117e40b2ee..7f64adb4406 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/LexicalSortingAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/LexicalSortingAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 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 @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * QNX Software System + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.ui.editor; @@ -15,11 +16,12 @@ import org.eclipse.jface.action.Action; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.ViewerSorter; - import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.internal.ui.CPluginImages; +import org.eclipse.cdt.ui.CElementGrouping; import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.internal.ui.CPluginImages; + public class LexicalSortingAction extends Action { @@ -69,19 +71,56 @@ public class LexicalSortingAction extends Action { if (obj instanceof ICElement) { ICElement elem= (ICElement)obj; switch (elem.getElementType()) { - case ICElement.C_MACRO: return 1; - case ICElement.C_INCLUDE: return 2; + case ICElement.C_MACRO: + return 2; + case ICElement.C_INCLUDE: + return 3; + case ICElement.C_USING: + return 4; - case ICElement.C_CLASS: return 3; - case ICElement.C_STRUCT: return 4; - case ICElement.C_UNION: return 5; + case ICElement.C_TYPEDEF: + return 10; + case ICElement.C_CLASS: + case ICElement.C_CLASS_DECLARATION: + case ICElement.C_TEMPLATE_CLASS: + case ICElement.C_TEMPLATE_CLASS_DECLARATION: + return 11; + case ICElement.C_STRUCT: + case ICElement.C_STRUCT_DECLARATION: + case ICElement.C_TEMPLATE_STRUCT: + case ICElement.C_TEMPLATE_STRUCT_DECLARATION: + return 12; + case ICElement.C_UNION: + case ICElement.C_UNION_DECLARATION: + case ICElement.C_TEMPLATE_UNION: + case ICElement.C_TEMPLATE_UNION_DECLARATION: + return 13; + case ICElement.C_ENUMERATION: + return 14; - case ICElement.C_FIELD: return 6; - case ICElement.C_FUNCTION: return 7; + case ICElement.C_VARIABLE: + case ICElement.C_VARIABLE_DECLARATION: + return 20; + case ICElement.C_FIELD: + return 21; + case ICElement.C_FUNCTION: + case ICElement.C_FUNCTION_DECLARATION: + case ICElement.C_TEMPLATE_FUNCTION: + case ICElement.C_TEMPLATE_FUNCTION_DECLARATION: + return 22; + case ICElement.C_METHOD: + case ICElement.C_METHOD_DECLARATION: + case ICElement.C_TEMPLATE_METHOD: + case ICElement.C_TEMPLATE_METHOD_DECLARATION: + return 23; + + case ICElement.C_NAMESPACE: + return 30; } - + } else if (obj instanceof CElementGrouping) { + return 0; } - return 0; + return 100; } } 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 f8c2762038a..663a8b8fbbb 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 @@ -29,6 +29,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.ui.CElementGrouping; import org.eclipse.cdt.internal.ui.CPluginImages; import org.eclipse.cdt.internal.ui.ICHelpContextIds; @@ -130,19 +131,56 @@ public class COutlineInformationControl extends AbstractInformationControl { if (obj instanceof ICElement) { ICElement elem= (ICElement)obj; switch (elem.getElementType()) { - case ICElement.C_MACRO: return 1; - case ICElement.C_INCLUDE: return 2; + case ICElement.C_MACRO: + return 2; + case ICElement.C_INCLUDE: + return 3; + case ICElement.C_USING: + return 4; - case ICElement.C_CLASS: return 3; - case ICElement.C_STRUCT: return 4; - case ICElement.C_UNION: return 5; + case ICElement.C_TYPEDEF: + return 10; + case ICElement.C_CLASS: + case ICElement.C_CLASS_DECLARATION: + case ICElement.C_TEMPLATE_CLASS: + case ICElement.C_TEMPLATE_CLASS_DECLARATION: + return 11; + case ICElement.C_STRUCT: + case ICElement.C_STRUCT_DECLARATION: + case ICElement.C_TEMPLATE_STRUCT: + case ICElement.C_TEMPLATE_STRUCT_DECLARATION: + return 12; + case ICElement.C_UNION: + case ICElement.C_UNION_DECLARATION: + case ICElement.C_TEMPLATE_UNION: + case ICElement.C_TEMPLATE_UNION_DECLARATION: + return 13; + case ICElement.C_ENUMERATION: + return 14; - case ICElement.C_FIELD: return 6; - case ICElement.C_FUNCTION: return 7; + case ICElement.C_VARIABLE: + case ICElement.C_VARIABLE_DECLARATION: + return 20; + case ICElement.C_FIELD: + return 21; + case ICElement.C_FUNCTION: + case ICElement.C_FUNCTION_DECLARATION: + case ICElement.C_TEMPLATE_FUNCTION: + case ICElement.C_TEMPLATE_FUNCTION_DECLARATION: + return 22; + case ICElement.C_METHOD: + case ICElement.C_METHOD_DECLARATION: + case ICElement.C_TEMPLATE_METHOD: + case ICElement.C_TEMPLATE_METHOD_DECLARATION: + return 23; + + case ICElement.C_NAMESPACE: + return 30; } - + } else if (obj instanceof CElementGrouping) { + return 0; } - return 0; + return 100; } }