From e9eb7ef7e61bb6bbea17ee25aa648a353da6edd7 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Fri, 7 Apr 2006 19:18:26 +0000 Subject: [PATCH] The IndexView now skips linkages in the hierarchy if there is only one in a project (i.e. not a multi-language project). Also fixed a bug with paths in the GCCLanguage and warnings in GPPLanguage. --- .../cdt/core/dom/ast/gnu/c/GCCLanguage.java | 12 +++++----- .../cdt/core/dom/ast/gnu/cpp/GPPLanguage.java | 6 ++--- .../cdt/internal/ui/indexview/IndexView.java | 22 +++++++++++++------ 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/c/GCCLanguage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/c/GCCLanguage.java index ae62b76d3bc..3b83236daa1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/c/GCCLanguage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/c/GCCLanguage.java @@ -92,20 +92,22 @@ public class GCCLanguage extends PlatformObject implements ILanguage { fileCreator = SavedCodeReaderFactory.getInstance(); CodeReader reader; + IFile rfile = (IFile)file.getResource(); if (file instanceof IWorkingCopy) { // get the working copy contents - IFile rfile = (IFile)file.getResource(); reader = new CodeReader(rfile.getLocation().toOSString(), file.getContents()); } else { - String path = file.getPath().toOSString(); + String path + = rfile != null + ? rfile.getLocation().toOSString() + : file.getPath().toOSString(); reader = fileCreator.createCodeReaderForTranslationUnit(path); if (reader == null) return null; } - - IScannerExtensionConfiguration scannerExtensionConfiguration = - scannerExtensionConfiguration = C_GNU_SCANNER_EXTENSION; + IScannerExtensionConfiguration scannerExtensionConfiguration + = C_GNU_SCANNER_EXTENSION; IScanner scanner = new DOMScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE, ParserLanguage.C, ParserFactory.createDefaultLogService(), scannerExtensionConfiguration, fileCreator ); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java index d81cd965d4d..e490d91926a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java @@ -90,8 +90,8 @@ public class GPPLanguage extends PlatformObject implements ILanguage { else fileCreator = SavedCodeReaderFactory.getInstance(); - IFile rfile = (IFile)file.getResource(); CodeReader reader; + IFile rfile = (IFile)file.getResource(); if (file instanceof IWorkingCopy) { // get the working copy contents reader = new CodeReader(rfile.getLocation().toOSString(), file.getContents()); @@ -105,8 +105,8 @@ public class GPPLanguage extends PlatformObject implements ILanguage { return null; } - IScannerExtensionConfiguration scannerExtensionConfiguration = - scannerExtensionConfiguration = CPP_GNU_SCANNER_EXTENSION; + IScannerExtensionConfiguration scannerExtensionConfiguration + = CPP_GNU_SCANNER_EXTENSION; IScanner scanner = new DOMScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE, ParserLanguage.CPP, ParserFactory.createDefaultLogService(), scannerExtensionConfiguration, fileCreator ); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/IndexView.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/IndexView.java index 6cee8196b15..e294e209353 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/IndexView.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/indexview/IndexView.java @@ -12,7 +12,6 @@ package org.eclipse.cdt.internal.ui.indexview; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.IPDOM; import org.eclipse.cdt.core.dom.IPDOMNode; import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.core.dom.ast.IASTFileLocation; @@ -29,10 +28,8 @@ import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage; -import org.eclipse.cdt.internal.core.pdom.dom.PDOMMemberOwner; import org.eclipse.cdt.internal.core.pdom.dom.PDOMName; import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode; -import org.eclipse.cdt.internal.core.pdom.dom.cpp.PDOMCPPNamespace; import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.core.resources.ResourcesPlugin; @@ -48,7 +45,6 @@ import org.eclipse.jface.action.Separator; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; @@ -104,7 +100,7 @@ public class IndexView extends ViewPart implements PDOM.IListener { * editor (if option enabled) */ void handleSelectionChanged(SelectionChangedEvent event) { - final IStructuredSelection selection = (IStructuredSelection) event.getSelection(); +// final IStructuredSelection selection = (IStructuredSelection) event.getSelection(); // updateStatusLine(selection); // updateActionBars(selection); if (isLinking) { @@ -187,8 +183,13 @@ public class IndexView extends ViewPart implements PDOM.IListener { if (parentElement instanceof ICProject) { PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM((ICProject)parentElement); int n = 0; - for (PDOMLinkage linkage = pdom.getFirstLinkage(); linkage != null; linkage = linkage.getNextLinkage()) + PDOMLinkage firstLinkage = pdom.getFirstLinkage(); + for (PDOMLinkage linkage = firstLinkage; linkage != null; linkage = linkage.getNextLinkage()) ++n; + if (n == 1) { + // Skip linkages in hierarchy if there is only one + return getChildren(firstLinkage); + } PDOMLinkage[] linkages = new PDOMLinkage[n]; int i = 0; for (PDOMLinkage linkage = pdom.getFirstLinkage(); linkage != null; linkage = linkage.getNextLinkage()) @@ -218,7 +219,14 @@ public class IndexView extends ViewPart implements PDOM.IListener { try { if (element instanceof ICProject) { PDOM pdom = (PDOM)CCorePlugin.getPDOMManager().getPDOM((ICProject)element); - return pdom.getFirstLinkage() != null; + PDOMLinkage firstLinkage = pdom.getFirstLinkage(); + if (firstLinkage == null) + return false; + else if (firstLinkage.getNextLinkage() == null) + // Skipping linkages if only one + return hasChildren(firstLinkage); + else + return true; } else if (element instanceof IPDOMNode) { HasChildren hasChildren = new HasChildren(); try {