From 0d0465f61140bde0a37bb92d6f1f132acb099b7c Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sat, 11 Apr 2009 23:41:02 +0000 Subject: [PATCH] Added a method that returns a complete include name. Intended for use by Add Include. --- .../eclipse/cdt/core/index/IIndexInclude.java | 13 ++++++-- .../internal/core/pdom/dom/PDOMInclude.java | 30 +++++++++++-------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexInclude.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexInclude.java index 5cb449d4d17..1cc4cd9f632 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexInclude.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/index/IIndexInclude.java @@ -8,6 +8,7 @@ * Contributors: * Markus Schorn - initial API and implementation * Andrew Ferguson (Symbian) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.core.index; @@ -57,8 +58,16 @@ public interface IIndexInclude { String getName() throws CoreException; /** - * Returns the character offset of the name of the include in its source file. The name does - * not include the enclosing quotes or angle brackets. + * Returns the name of the include. The name does not include the enclosing quotes + * or angle brackets. E.g.: for '' 'sys/types.h' will be returned. + * @throws CoreException + * @since 5.1 + */ + String getFullName() throws CoreException; + + /** + * Returns the character offset of the name of the include in its source file. + * The name does not include the enclosing quotes or angle brackets. * @throws CoreException */ int getNameOffset() throws CoreException; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMInclude.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMInclude.java index 3034d9cfd9f..5d3adc0da5f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMInclude.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMInclude.java @@ -6,8 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * QNX - Initial API and implementation - * Markus Schorn (Wind River Systems) + * QNX - Initial API and implementation + * Markus Schorn (Wind River Systems) + * Sergey Prigogin (Google) *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom; @@ -26,7 +27,6 @@ import org.eclipse.core.runtime.CoreException; /** * @author Doug Schaefer - * */ public class PDOMInclude implements IIndexFragmentInclude { @@ -49,7 +49,7 @@ public class PDOMInclude implements IIndexFragmentInclude { private final int record; // cached fields - private String fName= null; + private String fName; public PDOMInclude(PDOMLinkage pdom, int record) { this.linkage = pdom; @@ -95,8 +95,7 @@ public class PDOMInclude implements IIndexFragmentInclude { if (isResolved()) { // Remove us from the includedBy chain removeThisFromIncludedByChain(); - } - else { + } else { getNameForUnresolved().delete(); } @@ -107,10 +106,11 @@ public class PDOMInclude implements IIndexFragmentInclude { private void removeThisFromIncludedByChain() throws CoreException { PDOMInclude prevInclude = getPrevInIncludedBy(); PDOMInclude nextInclude = getNextInIncludedBy(); - if (prevInclude != null) + if (prevInclude != null) { prevInclude.setNextInIncludedBy(nextInclude); - else + } else { ((PDOMFile) getIncludes()).setFirstIncludedBy(nextInclude); + } if (nextInclude != null) nextInclude.setPrevInIncludedBy(prevInclude); @@ -136,8 +136,7 @@ public class PDOMInclude implements IIndexFragmentInclude { int rec= 0; if (includes == null) { rec= linkage.getDB().newString(name).getRecord(); - } - else { + } else { rec= includes.getRecord(); } linkage.getDB().putInt(record + INCLUDES_FILE_OR_NAME, rec); @@ -240,6 +239,13 @@ public class PDOMInclude implements IIndexFragmentInclude { } public String getName() throws CoreException { + if (fName == null) { + computeName(); + } + return fName.substring(fName.lastIndexOf('/') + 1); + } + + public String getFullName() throws CoreException { if (fName == null) { computeName(); } @@ -249,11 +255,9 @@ public class PDOMInclude implements IIndexFragmentInclude { private void computeName() throws CoreException { if (isResolved()) { fName= getIncludes().getLocation().getURI().getPath(); - } - else { + } else { fName= getNameForUnresolved().getString(); } - fName= fName.substring(fName.lastIndexOf('/')+1); } public void convertToUnresolved() throws CoreException {