From 68bf987af0e82e0a920cc7f6e65214097835ab1b Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sun, 25 Jan 2009 05:15:42 +0000 Subject: [PATCH] Bug 262307. --- .../cdt/internal/core/pdom/dom/PDOMMacro.java | 38 +++++++++---------- .../core/pdom/dom/PDOMMacroReferenceName.java | 36 +++++++----------- .../cdt/internal/core/pdom/dom/PDOMName.java | 32 ++++++---------- 3 files changed, 41 insertions(+), 65 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java index b60f8e7035b..78df7d78504 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacro.java @@ -12,7 +12,6 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom; -import java.net.URI; import java.util.ArrayList; import java.util.List; @@ -25,6 +24,7 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorUndefStatement; import org.eclipse.cdt.core.dom.ast.IMacroBinding; import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexMacro; +import org.eclipse.cdt.core.index.IndexLocationFactory; import org.eclipse.cdt.core.parser.Keywords; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.index.IIndexBindingConstants; @@ -39,11 +39,10 @@ import org.eclipse.cdt.internal.core.pdom.db.IString; import org.eclipse.core.runtime.CoreException; /** - * Represents macro definitions. They are stored with the file and with a PDOMMacroContainer. The latter also - * contains the references to all macros with the same name. + * Represents macro definitions. They are stored with the file and with a PDOMMacroContainer. + * The latter also contains the references to all macros with the same name. */ public class PDOMMacro implements IIndexMacro, IPDOMBinding, IASTFileLocation { - private static final int CONTAINER = 0; private static final int FILE = 4; private static final int PARAMETERS= 8; @@ -71,8 +70,8 @@ public class PDOMMacro implements IIndexMacro, IPDOMBinding, IASTFileLocation { fRecord = record; } - - public PDOMMacro(PDOM pdom, PDOMMacroContainer container, IASTPreprocessorMacroDefinition macro, PDOMFile file) throws CoreException { + public PDOMMacro(PDOM pdom, PDOMMacroContainer container, IASTPreprocessorMacroDefinition macro, + PDOMFile file) throws CoreException { this(pdom, container, file, macro.getName()); final IASTName name = macro.getName(); @@ -91,11 +90,13 @@ public class PDOMMacro implements IIndexMacro, IPDOMBinding, IASTFileLocation { } } - public PDOMMacro(PDOM pdom, PDOMMacroContainer container, IASTPreprocessorUndefStatement undef, PDOMFile file) throws CoreException { + public PDOMMacro(PDOM pdom, PDOMMacroContainer container, IASTPreprocessorUndefStatement undef, + PDOMFile file) throws CoreException { this(pdom, container, file, undef.getMacroName()); } - private PDOMMacro(PDOM pdom, PDOMMacroContainer container, PDOMFile file, IASTName name) throws CoreException { + private PDOMMacro(PDOM pdom, PDOMMacroContainer container, PDOMFile file, IASTName name) + throws CoreException { final Database db= pdom.getDB(); fPDOM = pdom; fRecord = db.malloc(RECORD_SIZE); @@ -251,10 +252,9 @@ public class PDOMMacro implements IIndexMacro, IPDOMBinding, IASTFileLocation { public char[] getNameCharArray() { try { return getContainer().getNameCharArray(); - } - catch (CoreException e) { + } catch (CoreException e) { CCorePlugin.log(e); - return new char[]{' '}; + return new char[] {' '}; } } @@ -274,16 +274,13 @@ public class PDOMMacro implements IIndexMacro, IPDOMBinding, IASTFileLocation { public String getFileName() { try { PDOMFile file = getFile(); - if(file!=null) { - /* - * We need to spec. what this method can return to know - * how to implement this. Existing implmentations return - * the absolute path, so here we attempt to do the same. - */ - URI uri = file.getLocation().getURI(); - if ("file".equals(uri.getScheme())) //$NON-NLS-1$ - return uri.getSchemeSpecificPart(); + if (file == null) { + return null; } + // We need to spec. what this method can return to know + // how to implement this. Existing implementations return + // the absolute path, so here we attempt to do the same. + return IndexLocationFactory.getAbsolutePath(file.getLocation()).toOSString(); } catch (CoreException e) { CCorePlugin.log(e); } @@ -409,7 +406,6 @@ public class PDOMMacro implements IIndexMacro, IPDOMBinding, IASTFileLocation { public void accept(IPDOMVisitor visitor) { } - public int getId() { return fRecord; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroReferenceName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroReferenceName.java index 144066b3759..367bfcf0e1a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroReferenceName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroReferenceName.java @@ -11,28 +11,23 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom; -import java.io.File; -import java.net.URI; - import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTName; -import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexName; +import org.eclipse.cdt.core.index.IndexLocationFactory; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.index.IIndexFragment; import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding; import org.eclipse.cdt.internal.core.index.IIndexFragmentName; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.db.Database; -import org.eclipse.core.filesystem.EFS; import org.eclipse.core.runtime.CoreException; /** * Represents declarations, definitions and references to bindings, except for macros. */ public final class PDOMMacroReferenceName implements IIndexFragmentName, IASTFileLocation { - private final PDOM pdom; private final int record; @@ -46,7 +41,8 @@ public final class PDOMMacroReferenceName implements IIndexFragmentName, IASTFil private static final int RECORD_SIZE = 26; - public PDOMMacroReferenceName(PDOM pdom, IASTName name, PDOMFile file, PDOMMacroContainer container) throws CoreException { + public PDOMMacroReferenceName(PDOM pdom, IASTName name, PDOMFile file, + PDOMMacroContainer container) throws CoreException { this.pdom = pdom; Database db = pdom.getDB(); record = db.malloc(RECORD_SIZE); @@ -109,7 +105,7 @@ public final class PDOMMacroReferenceName implements IIndexFragmentName, IASTFil setNameField(CONTAINER_NEXT_OFFSET, name); } - public IIndexFile getFile() throws CoreException { + public PDOMFile getFile() throws CoreException { int filerec = pdom.getDB().getInt(record + FILE_REC_OFFSET); return filerec != 0 ? new PDOMFile(pdom, filerec) : null; } @@ -178,20 +174,14 @@ public final class PDOMMacroReferenceName implements IIndexFragmentName, IASTFil public String getFileName() { try { - PDOMFile file = (PDOMFile) getFile(); - if(file!=null) { - /* - * We need to spec. what this method can return to know - * how to implement this. Existing implmentations return - * the absolute path, so here we attempt to do the same. - */ - URI uri = file.getLocation().getURI(); - if ("file".equals(uri.getScheme())) //$NON-NLS-1$ - return uri.getSchemeSpecificPart(); - File f = EFS.getStore(uri).toLocalFile(0, null); - if( f != null ) - return f.getAbsolutePath(); + PDOMFile file = getFile(); + if (file == null) { + return null; } + // We need to spec. what this method can return to know + // how to implement this. Existing implementations return + // the absolute path, so here we attempt to do the same. + return IndexLocationFactory.getAbsolutePath(file.getLocation()).toOSString(); } catch (CoreException e) { CCorePlugin.log(e); } @@ -232,9 +222,9 @@ public final class PDOMMacroReferenceName implements IIndexFragmentName, IASTFil // Delete from the binding chain PDOMMacroReferenceName prevName = getPrevInContainer(); PDOMMacroReferenceName nextName = getNextInContainer(); - if (prevName != null) + if (prevName != null) { prevName.setNextInContainer(nextName); - else { + } else { getContainer().setFirstReference(nextName); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMName.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMName.java index 310d39fbaa4..88c3937d472 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMName.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMName.java @@ -11,28 +11,24 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom.dom; -import java.io.File; -import java.net.URI; import java.util.ArrayList; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTName; -import org.eclipse.cdt.core.index.IIndexFile; import org.eclipse.cdt.core.index.IIndexName; +import org.eclipse.cdt.core.index.IndexLocationFactory; import org.eclipse.cdt.core.parser.util.CharArrayUtils; import org.eclipse.cdt.internal.core.index.IIndexFragment; import org.eclipse.cdt.internal.core.index.IIndexFragmentName; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.db.Database; -import org.eclipse.core.filesystem.EFS; import org.eclipse.core.runtime.CoreException; /** * @author Doug Schaefer */ public final class PDOMName implements IIndexFragmentName, IASTFileLocation { - private final PDOM pdom; private final int record; @@ -160,7 +156,7 @@ public final class PDOMName implements IIndexFragmentName, IASTFileLocation { setNameField(BINDING_NEXT_OFFSET, name); } - public IIndexFile getFile() throws CoreException { + public PDOMFile getFile() throws CoreException { int filerec = pdom.getDB().getInt(record + FILE_REC_OFFSET); return filerec != 0 ? new PDOMFile(pdom, filerec) : null; } @@ -285,20 +281,14 @@ public final class PDOMName implements IIndexFragmentName, IASTFileLocation { public String getFileName() { try { - PDOMFile file = (PDOMFile) getFile(); - if (file != null) { - /* - * We need to spec. what this method can return to know - * how to implement this. Existing implementations return - * the absolute path, so here we attempt to do the same. - */ - URI uri = file.getLocation().getURI(); - if ("file".equals(uri.getScheme())) //$NON-NLS-1$ - return uri.getSchemeSpecificPart(); - File f = EFS.getStore(uri).toLocalFile(0, null); - if (f != null) - return f.getAbsolutePath(); + PDOMFile file = getFile(); + if (file == null) { + return null; } + // We need to spec. what this method can return to know + // how to implement this. Existing implementations return + // the absolute path, so here we attempt to do the same. + return IndexLocationFactory.getAbsolutePath(file.getLocation()).toOSString(); } catch (CoreException e) { CCorePlugin.log(e); } @@ -339,9 +329,9 @@ public final class PDOMName implements IIndexFragmentName, IASTFileLocation { // Delete from the binding chain PDOMName prevName = getPrevInBinding(); PDOMName nextName = getNextInBinding(); - if (prevName != null) + if (prevName != null) { prevName.setNextInBinding(nextName); - else { + } else { switch (getFlags(DECL_DEF_REF_MASK)) { case IS_DECLARATION: getBinding().setFirstDeclaration(nextName);