mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
improved binaryconfig use
This commit is contained in:
parent
a17fa3fe67
commit
d9ad522e13
7 changed files with 197 additions and 179 deletions
|
@ -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
|
||||
|
||||
Fix for PR 69604 [Templates] Instantiating template with deferred template instance
|
||||
|
|
|
@ -8,26 +8,39 @@
|
|||
* Contributors:
|
||||
* 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
|
||||
*/
|
||||
public class BinaryParserConfig {
|
||||
|
||||
IBinaryParser parser;
|
||||
String id;
|
||||
private IBinaryParser parser;
|
||||
private final String id;
|
||||
private final ICExtensionReference ref;
|
||||
|
||||
public BinaryParserConfig(IBinaryParser parser, String id) {
|
||||
this.parser = parser;
|
||||
this.id = id;
|
||||
this.ref = null;
|
||||
}
|
||||
|
||||
public BinaryParserConfig(ICExtensionReference ref) {
|
||||
this.ref = ref;
|
||||
this.id = ref.getID();
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public IBinaryParser getBinaryParser() {
|
||||
public IBinaryParser getBinaryParser() throws CoreException {
|
||||
if (parser == null) {
|
||||
parser = (IBinaryParser)ref.createExtension();
|
||||
}
|
||||
return parser;
|
||||
}
|
||||
}
|
|
@ -17,7 +17,6 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.BinaryParserConfig;
|
||||
import org.eclipse.cdt.core.CCProjectNature;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
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.ICDescriptor;
|
||||
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.IBinaryFile;
|
||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
|
||||
|
@ -505,31 +505,51 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
|
|||
}
|
||||
|
||||
public BinaryParserConfig[] getBinaryParser(IProject project) {
|
||||
try {
|
||||
BinaryParserConfig[] parsers = (BinaryParserConfig[])binaryParsersMap.get(project);
|
||||
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) {
|
||||
binaryParsersMap.put(project, parsers);
|
||||
return parsers;
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
IBinaryParser nullParser = new NullBinaryParser();
|
||||
BinaryParserConfig config = new BinaryParserConfig(nullParser, ""); //$NON-NLS-1$
|
||||
BinaryParserConfig[] configs = new BinaryParserConfig[] {config};
|
||||
return configs;
|
||||
return new BinaryParserConfig[0];
|
||||
}
|
||||
|
||||
public IBinaryFile createBinaryFile(IFile file) {
|
||||
BinaryParserConfig[] parsers = getBinaryParser(file.getProject());
|
||||
int hints = 0;
|
||||
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) {
|
||||
hints = parser.getHintBufferSize();
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
}
|
||||
byte[] bytes = new byte[hints];
|
||||
if (hints > 0) {
|
||||
|
@ -553,17 +573,17 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
|
|||
|
||||
for (int i = 0; i < parsers.length; i++) {
|
||||
try {
|
||||
IBinaryFile bin = parsers[i].getBinaryParser().getBinary(bytes, location);
|
||||
if (bin != null) {
|
||||
return bin;
|
||||
IBinaryParser parser = parsers[i].getBinaryParser();
|
||||
IBinaryFile binFile = parser.getBinary(bytes, location);
|
||||
if (binFile != null) {
|
||||
return binFile;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
//
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: this is a temporary hack until, the CDescriptor manager is
|
||||
* in place and could fire deltas of Parser change.
|
||||
|
@ -715,22 +735,21 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
|
|||
if (cdesc != null) {
|
||||
IProject project = cdesc.getProject();
|
||||
try {
|
||||
String[] newIds = CCorePlugin.getDefault().getBinaryParserIds(project);
|
||||
ICExtensionReference[] newExts = CCorePlugin.getDefault().getBinaryParserExtensions(project);
|
||||
BinaryParserConfig[] currentConfigs = getBinaryParser(project);
|
||||
// anything added/removed
|
||||
if (newIds.length != currentConfigs.length) {
|
||||
if (newExts.length != currentConfigs.length) {
|
||||
resetBinaryParser(project);
|
||||
} else { // may reorder
|
||||
for (int i = 0; i < newIds.length; i++) {
|
||||
String id = newIds[i];
|
||||
if (!id.equals(currentConfigs[i].getId())) {
|
||||
for (int i = 0; i < newExts.length; i++) {
|
||||
if (!newExts[i].getID().equals(currentConfigs[i].getId())) {
|
||||
resetBinaryParser(project);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} 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
|
||||
Platform.run(new ISafeRunnable() {
|
||||
|
||||
public void handleException(Throwable exception) {
|
||||
//CCorePlugin.log(exception, "Exception occurred in listener of C element change notification"); //$NON-NLS-1$
|
||||
CCorePlugin.log(exception);
|
||||
|
|
|
@ -19,10 +19,10 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.BinaryParserConfig;
|
||||
import org.eclipse.cdt.core.CCProjectNature;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
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.IBinaryFile;
|
||||
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++) {
|
||||
IBinaryFile bin;
|
||||
try {
|
||||
bin = binConfigs[i].getBinaryParser().getBinary(entry.getFullLibraryPath());
|
||||
IBinaryParser parser = binConfigs[i].getBinaryParser();
|
||||
bin = parser.getBinary(entry.getFullLibraryPath());
|
||||
if (bin != null) {
|
||||
if (bin.getType() == IBinaryFile.ARCHIVE) {
|
||||
lib = new LibraryReferenceArchive(cproject, entry, (IBinaryArchive)bin);
|
||||
|
@ -211,7 +212,8 @@ public class CProject extends Openable implements ICProject {
|
|||
}
|
||||
break;
|
||||
}
|
||||
} catch (IOException e1) {
|
||||
} catch (IOException e) {
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -467,8 +467,8 @@ public class CCorePlugin extends Plugin {
|
|||
return getConsole(null);
|
||||
}
|
||||
|
||||
public BinaryParserConfig[] getBinaryParserConfigs(IProject project) throws CoreException {
|
||||
BinaryParserConfig configs[] = null;
|
||||
public ICExtensionReference[] getBinaryParserExtensions(IProject project) throws CoreException {
|
||||
ICExtensionReference ext[] = new ICExtensionReference[0];
|
||||
if (project != null) {
|
||||
try {
|
||||
ICDescriptor cdesc = getCProjectDescription(project);
|
||||
|
@ -476,57 +476,15 @@ public class CCorePlugin extends Plugin {
|
|||
if (cextensions.length > 0) {
|
||||
ArrayList list = new ArrayList(cextensions.length);
|
||||
for (int i = 0; i < cextensions.length; i++) {
|
||||
IBinaryParser parser = null;
|
||||
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);
|
||||
list.add(cextensions[i]);
|
||||
}
|
||||
}
|
||||
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);
|
||||
ext = (ICExtensionReference[])list.toArray(ext);
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
if (ids == null) {
|
||||
ids = new String[] {DEFAULT_BINARY_PARSER_UNIQ_ID};
|
||||
}
|
||||
return ids;
|
||||
return ext;
|
||||
}
|
||||
|
||||
public IBinaryParser[] getBinaryParser(IProject project) throws CoreException {
|
||||
|
|
|
@ -12,6 +12,7 @@ package org.eclipse.cdt.core;
|
|||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
import org.eclipse.core.runtime.IExecutableExtension;
|
||||
|
||||
public interface ICExtensionReference {
|
||||
|
||||
|
@ -40,6 +41,12 @@ public interface ICExtensionReference {
|
|||
*/
|
||||
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
|
||||
* identified by the <run> attribute of the cextension.
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
* Copyright (c) 2000, 2004 QNX Software Systems and others. All rights
|
||||
* reserved. This program and the accompanying materials are made available
|
||||
* under the terms of the Common Public License v1.0 which accompanies this
|
||||
* distribution, and is available at http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
* Contributors: QNX Software Systems - Initial API and implementation
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core;
|
||||
|
||||
import org.eclipse.cdt.core.CDescriptorEvent;
|
||||
import org.eclipse.cdt.core.ICDescriptor;
|
||||
import org.eclipse.cdt.core.ICExtension;
|
||||
import org.eclipse.cdt.core.ICExtensionReference;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -36,6 +35,10 @@ public class CExtensionReference implements ICExtensionReference {
|
|||
return fId;
|
||||
}
|
||||
|
||||
public ICDescriptor getCDescriptor() {
|
||||
return fDescriptor;
|
||||
}
|
||||
|
||||
private CExtensionInfo getInfo() {
|
||||
return fDescriptor.getInfo(this);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue