1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 01:45:33 +02:00

improved binaryconfig use

This commit is contained in:
David Inglis 2004-10-14 20:08:28 +00:00
parent a17fa3fe67
commit d9ad522e13
7 changed files with 197 additions and 179 deletions

View file

@ -1,3 +1,18 @@
2004-10-14 David Inglis
Move BinaryConfig into internal.model was no need to be public, also fixed it to
be lazy when creating parser interface.
* model/org/eclipse/cdt/internal/core/model/CModelManager.java
* model/org/eclipse/cdt/internal/core/model/CProject.java
* src/org/eclipse/cdt/core/BinaryParserConfig.java
* src/org/eclipse/cdt/core/CCorePlugin.java
* src/org/eclipse/cdt/core/ICExtensionReference.java
* src/org/eclipse/cdt/internal/core/CExtensionReference.java
Removed
* model/org/eclipse/cdt/internal/core/model/BinaryParserConfig.java
2004-10-12 Vladimir Hirsl 2004-10-12 Vladimir Hirsl
Fix for PR 69604 [Templates] Instantiating template with deferred template instance Fix for PR 69604 [Templates] Instantiating template with deferred template instance

View file

@ -8,26 +8,39 @@
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core; package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.core.ICExtensionReference;
import org.eclipse.core.runtime.CoreException;
/* /*
* BinaryParserConfig * BinaryParserConfig
*/ */
public class BinaryParserConfig { public class BinaryParserConfig {
private IBinaryParser parser;
IBinaryParser parser; private final String id;
String id; private final ICExtensionReference ref;
public BinaryParserConfig(IBinaryParser parser, String id) { public BinaryParserConfig(IBinaryParser parser, String id) {
this.parser = parser; this.parser = parser;
this.id = id; this.id = id;
this.ref = null;
}
public BinaryParserConfig(ICExtensionReference ref) {
this.ref = ref;
this.id = ref.getID();
} }
public String getId() { public String getId() {
return id; return id;
} }
public IBinaryParser getBinaryParser() { public IBinaryParser getBinaryParser() throws CoreException {
if (parser == null) {
parser = (IBinaryParser)ref.createExtension();
}
return parser; return parser;
} }
} }

View file

@ -17,7 +17,6 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.BinaryParserConfig;
import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CDescriptorEvent; import org.eclipse.cdt.core.CDescriptorEvent;
@ -25,6 +24,7 @@ import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.IBinaryParser; import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.core.ICDescriptor; import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.ICDescriptorListener; import org.eclipse.cdt.core.ICDescriptorListener;
import org.eclipse.cdt.core.ICExtensionReference;
import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive; import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
@ -505,31 +505,51 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
} }
public BinaryParserConfig[] getBinaryParser(IProject project) { public BinaryParserConfig[] getBinaryParser(IProject project) {
try {
BinaryParserConfig[] parsers = (BinaryParserConfig[])binaryParsersMap.get(project); BinaryParserConfig[] parsers = (BinaryParserConfig[])binaryParsersMap.get(project);
if (parsers == null) { if (parsers == null) {
parsers = CCorePlugin.getDefault().getBinaryParserConfigs(project); try {
ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(project, false);
if (cdesc != null) {
ICExtensionReference[] cextensions = cdesc.get(CCorePlugin.BINARY_PARSER_UNIQ_ID, true);
if (cextensions.length > 0) {
ArrayList list = new ArrayList(cextensions.length);
for (int i = 0; i < cextensions.length; i++) {
BinaryParserConfig config = new BinaryParserConfig(cextensions[i]);
list.add(config);
}
parsers = new BinaryParserConfig[list.size()];
list.toArray(parsers);
}
}
} catch (CoreException e) {
}
if (parsers == null) {
try {
BinaryParserConfig config = new BinaryParserConfig(CCorePlugin.getDefault().getDefaultBinaryParser(), CCorePlugin.DEFAULT_BINARY_PARSER_UNIQ_ID);
parsers = new BinaryParserConfig[]{config};
} catch (CoreException e1) {
}
}
} }
if (parsers != null) { if (parsers != null) {
binaryParsersMap.put(project, parsers); binaryParsersMap.put(project, parsers);
return parsers; return parsers;
} }
} catch (CoreException e) { return new BinaryParserConfig[0];
}
IBinaryParser nullParser = new NullBinaryParser();
BinaryParserConfig config = new BinaryParserConfig(nullParser, ""); //$NON-NLS-1$
BinaryParserConfig[] configs = new BinaryParserConfig[] {config};
return configs;
} }
public IBinaryFile createBinaryFile(IFile file) { public IBinaryFile createBinaryFile(IFile file) {
BinaryParserConfig[] parsers = getBinaryParser(file.getProject()); BinaryParserConfig[] parsers = getBinaryParser(file.getProject());
int hints = 0; int hints = 0;
for (int i = 0; i < parsers.length; i++) { for (int i = 0; i < parsers.length; i++) {
IBinaryParser parser = parsers[i].getBinaryParser(); IBinaryParser parser = null;
try {
parser = parsers[i].getBinaryParser();
if (parser.getHintBufferSize() > hints) { if (parser.getHintBufferSize() > hints) {
hints = parser.getHintBufferSize(); hints = parser.getHintBufferSize();
} }
} catch (CoreException e) {
}
} }
byte[] bytes = new byte[hints]; byte[] bytes = new byte[hints];
if (hints > 0) { if (hints > 0) {
@ -553,17 +573,17 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
for (int i = 0; i < parsers.length; i++) { for (int i = 0; i < parsers.length; i++) {
try { try {
IBinaryFile bin = parsers[i].getBinaryParser().getBinary(bytes, location); IBinaryParser parser = parsers[i].getBinaryParser();
if (bin != null) { IBinaryFile binFile = parser.getBinary(bytes, location);
return bin; if (binFile != null) {
return binFile;
} }
} catch (IOException e) { } catch (IOException e) {
// } catch (CoreException e) {
} }
} }
return null; return null;
} }
/** /**
* TODO: this is a temporary hack until, the CDescriptor manager is * TODO: this is a temporary hack until, the CDescriptor manager is
* in place and could fire deltas of Parser change. * in place and could fire deltas of Parser change.
@ -715,22 +735,21 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
if (cdesc != null) { if (cdesc != null) {
IProject project = cdesc.getProject(); IProject project = cdesc.getProject();
try { try {
String[] newIds = CCorePlugin.getDefault().getBinaryParserIds(project); ICExtensionReference[] newExts = CCorePlugin.getDefault().getBinaryParserExtensions(project);
BinaryParserConfig[] currentConfigs = getBinaryParser(project); BinaryParserConfig[] currentConfigs = getBinaryParser(project);
// anything added/removed // anything added/removed
if (newIds.length != currentConfigs.length) { if (newExts.length != currentConfigs.length) {
resetBinaryParser(project); resetBinaryParser(project);
} else { // may reorder } else { // may reorder
for (int i = 0; i < newIds.length; i++) { for (int i = 0; i < newExts.length; i++) {
String id = newIds[i]; if (!newExts[i].getID().equals(currentConfigs[i].getId())) {
if (!id.equals(currentConfigs[i].getId())) {
resetBinaryParser(project); resetBinaryParser(project);
break; break;
} }
} }
} }
} catch (CoreException e) { } catch (CoreException e) {
// resetBinaryParser(project);
} }
} }
} }
@ -844,6 +863,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
} }
// wrap callbacks with Safe runnable for subsequent listeners to be called when some are causing grief // wrap callbacks with Safe runnable for subsequent listeners to be called when some are causing grief
Platform.run(new ISafeRunnable() { Platform.run(new ISafeRunnable() {
public void handleException(Throwable exception) { public void handleException(Throwable exception) {
//CCorePlugin.log(exception, "Exception occurred in listener of C element change notification"); //$NON-NLS-1$ //CCorePlugin.log(exception, "Exception occurred in listener of C element change notification"); //$NON-NLS-1$
CCorePlugin.log(exception); CCorePlugin.log(exception);

View file

@ -19,10 +19,10 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.BinaryParserConfig;
import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CProjectNature; import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive; import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
@ -202,7 +202,8 @@ public class CProject extends Openable implements ICProject {
for (int i = 0; i < binConfigs.length; i++) { for (int i = 0; i < binConfigs.length; i++) {
IBinaryFile bin; IBinaryFile bin;
try { try {
bin = binConfigs[i].getBinaryParser().getBinary(entry.getFullLibraryPath()); IBinaryParser parser = binConfigs[i].getBinaryParser();
bin = parser.getBinary(entry.getFullLibraryPath());
if (bin != null) { if (bin != null) {
if (bin.getType() == IBinaryFile.ARCHIVE) { if (bin.getType() == IBinaryFile.ARCHIVE) {
lib = new LibraryReferenceArchive(cproject, entry, (IBinaryArchive)bin); lib = new LibraryReferenceArchive(cproject, entry, (IBinaryArchive)bin);
@ -211,7 +212,8 @@ public class CProject extends Openable implements ICProject {
} }
break; break;
} }
} catch (IOException e1) { } catch (IOException e) {
} catch (CoreException e) {
} }
} }
} }

View file

@ -467,8 +467,8 @@ public class CCorePlugin extends Plugin {
return getConsole(null); return getConsole(null);
} }
public BinaryParserConfig[] getBinaryParserConfigs(IProject project) throws CoreException { public ICExtensionReference[] getBinaryParserExtensions(IProject project) throws CoreException {
BinaryParserConfig configs[] = null; ICExtensionReference ext[] = new ICExtensionReference[0];
if (project != null) { if (project != null) {
try { try {
ICDescriptor cdesc = getCProjectDescription(project); ICDescriptor cdesc = getCProjectDescription(project);
@ -476,57 +476,15 @@ public class CCorePlugin extends Plugin {
if (cextensions.length > 0) { if (cextensions.length > 0) {
ArrayList list = new ArrayList(cextensions.length); ArrayList list = new ArrayList(cextensions.length);
for (int i = 0; i < cextensions.length; i++) { for (int i = 0; i < cextensions.length; i++) {
IBinaryParser parser = null; list.add(cextensions[i]);
try {
parser = (IBinaryParser) cextensions[i].createExtension();
BinaryParserConfig config = new BinaryParserConfig(parser, cextensions[i].getID());
list.add(config);
} catch (CoreException e) {
Status s = new Status(IStatus.WARNING, PLUGIN_ID, -1, "Binary Parser failure", e); //$NON-NLS-1$
log(s);
} catch (ClassCastException e) {
log(e);
} }
} ext = (ICExtensionReference[])list.toArray(ext);
configs = new BinaryParserConfig[list.size()];
list.toArray(configs);
}
} catch (CoreException e) {
// ignore
}
}
if (configs == null) {
IBinaryParser parser = getDefaultBinaryParser();
if (parser != null) {
BinaryParserConfig config = new BinaryParserConfig(parser, DEFAULT_BINARY_PARSER_UNIQ_ID);
configs = new BinaryParserConfig[] {config};
}
}
return configs;
}
public String[] getBinaryParserIds(IProject project) throws CoreException {
String ids[] = null;
if (project != null) {
try {
ICDescriptor cdesc = getCProjectDescription(project);
ICExtensionReference[] cextensions = cdesc.get(BINARY_PARSER_UNIQ_ID, true);
if (cextensions.length > 0) {
ArrayList list = new ArrayList(cextensions.length);
for (int i = 0; i < cextensions.length; i++) {
list.add(cextensions[i].getID());
}
ids = new String[list.size()];
list.toArray(ids);
} }
} catch (CoreException e) { } catch (CoreException e) {
log(e); log(e);
} }
} }
if (ids == null) { return ext;
ids = new String[] {DEFAULT_BINARY_PARSER_UNIQ_ID};
}
return ids;
} }
public IBinaryParser[] getBinaryParser(IProject project) throws CoreException { public IBinaryParser[] getBinaryParser(IProject project) throws CoreException {

View file

@ -12,6 +12,7 @@ package org.eclipse.cdt.core;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExecutableExtension;
public interface ICExtensionReference { public interface ICExtensionReference {
@ -40,6 +41,12 @@ public interface ICExtensionReference {
*/ */
public String getExtensionData(String key); public String getExtensionData(String key);
/**
* Returns the project descriptor which this extension reference belongs to.
* @return the ICDescriptor
*/
public ICDescriptor getCDescriptor();
/** /**
* Creates and returns a new instance of the cextension executable * Creates and returns a new instance of the cextension executable
* identified by the &lt;run&gt; attribute of the cextension. * identified by the &lt;run&gt; attribute of the cextension.

View file

@ -1,16 +1,15 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2000, 2004 QNX Software Systems and others. * Copyright (c) 2000, 2004 QNX Software Systems and others. All rights
* All rights reserved. This program and the accompanying materials * reserved. This program and the accompanying materials are made available
* are made available under the terms of the Common Public License v1.0 * under the terms of the Common Public License v1.0 which accompanies this
* which accompanies this distribution, and is available at * distribution, and is available at http://www.eclipse.org/legal/cpl-v10.html
* http://www.eclipse.org/legal/cpl-v10.html
* *
* Contributors: * Contributors: QNX Software Systems - Initial API and implementation
* QNX Software Systems - Initial API and implementation ******************************************************************************/
*******************************************************************************/
package org.eclipse.cdt.internal.core; package org.eclipse.cdt.internal.core;
import org.eclipse.cdt.core.CDescriptorEvent; import org.eclipse.cdt.core.CDescriptorEvent;
import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.ICExtension; import org.eclipse.cdt.core.ICExtension;
import org.eclipse.cdt.core.ICExtensionReference; import org.eclipse.cdt.core.ICExtensionReference;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -36,6 +35,10 @@ public class CExtensionReference implements ICExtensionReference {
return fId; return fId;
} }
public ICDescriptor getCDescriptor() {
return fDescriptor;
}
private CExtensionInfo getInfo() { private CExtensionInfo getInfo() {
return fDescriptor.getInfo(this); return fDescriptor.getInfo(this);
} }