1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix for 192866: Include at wrong position in Outline

This commit is contained in:
Anton Leherbauer 2007-06-18 12:54:31 +00:00
parent 38595a611f
commit f5841dcac0
4 changed files with 124 additions and 25 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -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;
}
}

View file

@ -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;
}
}