diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java index fc93f4483d5..64d4dcf10eb 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java @@ -5,6 +5,7 @@ package org.eclipse.cdt.core.model; * All Rights Reserved. */ +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.internal.core.model.CModelManager; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; @@ -18,6 +19,8 @@ public class CoreModel { private static CoreModel cmodel = null; private static CModelManager manager = null; + + public final static String CORE_MODEL_ID = CCorePlugin.PLUGIN_ID + ".coremodel"; /** * Creates an ICElement form and IPath. @@ -126,6 +129,34 @@ public class CoreModel { return manager.hasCCNature(project); } + /** + * Return the the binaryParser of the Project. + */ + public static IBinaryParser getBinaryParser(IProject project) { + return manager.getBinaryParser(project); + } + + /** + * Return all the known binaryParsers formats. + */ + public static String[] getBinaryParserFormats() { + return CCorePlugin.getDefault().getBinaryParserFormats(); + } + + /** + * Save the binary parser for the project. + */ + public static void setBinaryParser(IProject project, String format) { + manager.setBinaryParser(project, format); + } + + /** + * Return the BinaryParser corresponding to this format. + */ + public static IBinaryParser getBinaryParser(String format) { + return CCorePlugin.getDefault().getBinaryParser(format); + } + /** * Return the singleton. */ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java index a4e8349cf9f..f0ca9a76e5d 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java @@ -13,6 +13,7 @@ import java.util.Iterator; import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CProjectNature; import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ElementChangedEvent; import org.eclipse.cdt.core.model.IArchive; import org.eclipse.cdt.core.model.IBinary; @@ -41,12 +42,19 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.QualifiedName; public class CModelManager implements IResourceChangeListener { private HashMap fParsedResources = new HashMap(); + final static String BINARY_PARSER= "binaryparser"; + + static QualifiedName binaryParserKey = new QualifiedName(CoreModel.CORE_MODEL_ID, BINARY_PARSER); + + private static HashMap fParsers = new HashMap(); private static IBinaryParser defaultBinaryParser = new ElfParser(); + //private static IBinaryParser defaultBinaryParser = new PEParser(); /** * Used to convert IResourceDeltas into IJavaElementDeltas. @@ -341,11 +349,39 @@ public class CModelManager implements IResourceChangeListener { } public static IBinaryParser getBinaryParser(IProject project) { + // It is in the property of the project of the cdtproject // For now the default is Elf. - // It is in the porperty of the project of the cdtproject - return defaultBinaryParser; + IBinaryParser parser = (IBinaryParser)fParsers.get(project); + if (parser == null) { + String format = null; + // FIXME: Ask the .cdtproject second. + try { + if (project != null) { + format = project.getPersistentProperty(binaryParserKey); + } + } catch (CoreException e) { + } + if (format != null && format.length() > 0) { + parser = CoreModel.getDefault().getBinaryParser(format); + } + if (parser == null) { + parser = defaultBinaryParser; + } + fParsers.put(project, parser); + } + return parser; } + public static void setBinaryParser(IProject project, String format) { + try { + if (project != null) { + project.setPersistentProperty(binaryParserKey, format); + fParsers.remove(project); + } + } catch (CoreException e) { + } + } + public static boolean isSharedLib(IFile file) { try { IBinaryParser parser = getBinaryParser(file.getProject());