diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java index ac9f1e5c402..53764ebfda2 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java @@ -50,8 +50,10 @@ import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.index.IIndex; @@ -2152,4 +2154,27 @@ public class IndexBugsTests extends BaseTestCase { index.releaseReadLock(); } } + + // template void f(T t) throw (T) {} + public void testFunctionTemplateWithThrowsException_293021() throws Exception { + waitForIndexer(); + String testData = getContentsForTest(1)[0].toString(); + IFile f= TestSourceReader.createFile(fCProject.getProject(), "testFunctionTemplateWithThrowsException_293021.cpp", testData); + final IIndexManager indexManager = CCorePlugin.getIndexManager(); + waitUntilFileIsIndexed(f, 4000); + IIndex index= indexManager.getIndex(fCProject); + index.acquireReadLock(); + try { + IIndexFile file= index.getFile(ILinkage.CPP_LINKAGE_ID, IndexLocationFactory.getWorkspaceIFL(f)); + int idx= testData.indexOf("f("); + IIndexName[] names = file.findNames(idx, idx+1); + assertEquals(1, names.length); + ICPPFunctionTemplate ft= (ICPPFunctionTemplate) index.findBinding(names[0]); + final IType[] espec = ft.getExceptionSpecification(); + ICPPTemplateParameter par= (ICPPTemplateParameter) espec[0]; + assertEquals(ft, par.getOwner()); + } finally { + index.releaseReadLock(); + } + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java index ecf2bf200f8..fc34af57e57 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 QNX Software Systems and others. + * Copyright (c) 2000, 2009 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -746,7 +746,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange SafeRunner.run(new ISafeRunnable() { public void handleException(Throwable exception) { - IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, IStatus.ERROR, + IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, "Exception occurred in container initializer: " + initializer, exception); //$NON-NLS-1$ CCorePlugin.log(status); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java index 77381bb446f..1e56bd13d00 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Util.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URI; + import com.ibm.icu.text.MessageFormat; import org.eclipse.cdt.core.CCorePlugin; @@ -190,7 +191,7 @@ public class Util implements ICLogConstants { * Add a log entry */ public static void log(Throwable e, String message, LogConst logType) { - IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, IStatus.ERROR, message,e); + IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, message,e); Util.log(status, logType); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java index 6081a0a07d9..306997f8461 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.cdt.internal.core.pdom; +import java.lang.reflect.InvocationTargetException; import java.net.URI; import java.util.ArrayList; import java.util.Arrays; @@ -805,13 +806,20 @@ public abstract class AbstractIndexerTask extends PDOMWriter { */ if (e instanceof CoreException) { s=((CoreException)e).getStatus(); - if( s != null && s.getCode() == CCorePlugin.STATUS_PDOM_TOO_LARGE ) { - throw (CoreException)e; + if (s != null && s.getCode() == CCorePlugin.STATUS_PDOM_TOO_LARGE) { + if (CCorePlugin.PLUGIN_ID.equals(s.getPlugin())) + throw (CoreException) e; } } if (e instanceof CoreException) { s= ((CoreException) e).getStatus(); - if (s.getException() == null) { + Throwable exception = s.getException(); + if (exception instanceof OutOfMemoryError || exception instanceof StackOverflowError) { + // mask errors in order to avoid dialog from platform + e= new InvocationTargetException(exception); + exception= null; + } + if (exception == null) { s= new Status(s.getSeverity(), s.getPlugin(), s.getCode(), s.getMessage(), e); } } else { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java index 37b8f47d812..b883124ba06 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMFile.java @@ -310,8 +310,10 @@ public class PDOMFile implements IIndexFragmentFile { return result; } } catch (CoreException e) { - if( e.getStatus() != null && e.getStatus().getCode() == CCorePlugin.STATUS_PDOM_TOO_LARGE ) { - throw e; + final IStatus status = e.getStatus(); + if (status != null && status.getCode() == CCorePlugin.STATUS_PDOM_TOO_LARGE) { + if (CCorePlugin.PLUGIN_ID.equals(status.getPlugin())) + throw e; } CCorePlugin.log(e); } @@ -643,6 +645,6 @@ public class PDOMFile implements IIndexFragmentFile { // required because we cannot reference CCorePlugin in order for StandaloneIndexer to work private static IStatus createStatus(String msg) { - return new Status(IStatus.ERROR, "org.eclipse.cdt.core", IStatus.ERROR, msg, null); //$NON-NLS-1$ + return new Status(IStatus.ERROR, "org.eclipse.cdt.core", msg, null); //$NON-NLS-1$ } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunction.java index 8850265569f..6b0df955c37 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunction.java @@ -87,19 +87,19 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl Database db = getDB(); Integer sigHash = IndexCPPSignatureUtil.getSignatureHash(function); getDB().putInt(record + SIGNATURE_HASH, sigHash != null ? sigHash.intValue() : 0); + db.putByte(record + ANNOTATION, PDOMCPPAnnotation.encodeAnnotation(function)); if (setTypes) { - initData(function.getType(), function.getParameters()); + initData(function.getType(), function.getParameters(), extractExceptionSpec(function)); } - db.putByte(record + ANNOTATION, PDOMCPPAnnotation.encodeAnnotation(function)); - storeExceptionSpec(db, function); } - public void initData(ICPPFunctionType ftype, IParameter[] params) { + public void initData(ICPPFunctionType ftype, IParameter[] params, IType[] exceptionSpec) { PDOMCPPFunctionType pft; try { pft = setType(ftype); - setParameters(pft, params); + setParameters(pft, params); + storeExceptionSpec(exceptionSpec); } catch (CoreException e) { CCorePlugin.log(e); } @@ -135,25 +135,32 @@ class PDOMCPPFunction extends PDOMCPPBinding implements ICPPFunction, IPDOMOverl annotation= newAnnotation; long oldRec = db.getRecPtr(record+EXCEPTION_SPEC); - storeExceptionSpec(db, func); + storeExceptionSpec(extractExceptionSpec(func)); if (oldRec != 0) { PDOMCPPTypeList.clearTypes(this, oldRec); } } } - private void storeExceptionSpec(final Database db, ICPPFunction binding) throws CoreException { - long typelist= 0; - try { - if (binding instanceof ICPPMethod && ((ICPPMethod) binding).isImplicit()) { - // don't store the exception specification, computed it on demand. - } else { - typelist = PDOMCPPTypeList.putTypes(this, binding.getExceptionSpecification()); + private void storeExceptionSpec(IType[] exceptionSpec) throws CoreException { + long typelist= PDOMCPPTypeList.putTypes(this, exceptionSpec); + getDB().putRecPtr(record + EXCEPTION_SPEC, typelist); + } + + IType[] extractExceptionSpec(ICPPFunction binding) { + IType[] exceptionSpec; + if (binding instanceof ICPPMethod && ((ICPPMethod) binding).isImplicit()) { + // don't store the exception specification, compute it on demand. + exceptionSpec= null; + } else { + try{ + exceptionSpec= binding.getExceptionSpecification(); + } catch (DOMException e) { + // ignore problems in the exception specification. + exceptionSpec= null; } - } catch (DOMException e) { - // ignore problems in the exception specification. } - db.putRecPtr(record + EXCEPTION_SPEC, typelist); + return exceptionSpec; } private void setParameters(PDOMCPPFunctionType pft, IParameter[] params) throws CoreException { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java index 19989deb07f..ebfb52c4d42 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPLinkage.java @@ -175,6 +175,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { private final ICPPTemplateParameter[] fOriginalTemplateParameters; private final ICPPFunctionType fOriginalFunctionType; private final IParameter[] fOriginalParameters; + private final IType[] fOriginalExceptionSpec; public ConfigureFunctionTemplate(ICPPFunctionTemplate original, PDOMCPPFunctionTemplate template) throws DOMException { fTemplate = template; @@ -182,6 +183,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { fOriginalTemplateParameters= original.getTemplateParameters(); fOriginalFunctionType= original.getType(); fOriginalParameters= original.getParameters(); + fOriginalExceptionSpec= template.extractExceptionSpec(original); postProcesses.add(this); } @@ -191,8 +193,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants { if (tp != null) tp.configure(fOriginalTemplateParameters[i]); } - - fTemplate.initData(fOriginalFunctionType, fOriginalParameters); + fTemplate.initData(fOriginalFunctionType, fOriginalParameters, fOriginalExceptionSpec); } } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java index b3627d36a99..4b8ca81b02e 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java @@ -1243,7 +1243,7 @@ public class CCorePlugin extends Plugin { * @noreference This method is not intended to be referenced by clients. */ public static IStatus createStatus(String msg, Throwable e) { - return new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, msg, e); + return new Status(IStatus.ERROR, PLUGIN_ID, msg, e); } /** diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/FileStorage.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/FileStorage.java index 13e43f91203..02db0cf968d 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/FileStorage.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/FileStorage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 QNX Software Systems and others. + * Copyright (c) 2000, 2009 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,18 +11,17 @@ package org.eclipse.cdt.core.resources; -import java.io.InputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; - -import org.eclipse.core.resources.IStorage; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.PlatformObject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.IStatus; +import java.io.InputStream; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.core.resources.IStorage; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.PlatformObject; +import org.eclipse.core.runtime.Status; /** * @@ -38,7 +37,7 @@ public class FileStorage extends PlatformObject implements IStorage { return new FileInputStream(path.toFile()); } catch (FileNotFoundException e) { throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, - IStatus.ERROR, e.toString(), e)); + e.toString(), e)); } } return in; diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/PathEntryVariableResolver.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/PathEntryVariableResolver.java index b2889bcc244..ed7c48f3d44 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/PathEntryVariableResolver.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/PathEntryVariableResolver.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 QNX Software Systems and others. + * Copyright (c) 2000, 2009 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,10 +8,8 @@ * Contributors: * QNX Software Systems - Initial API and implementation *******************************************************************************/ - package org.eclipse.cdt.internal.core; - import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.resources.IPathEntryVariableManager; import org.eclipse.core.runtime.CoreException; @@ -30,7 +28,7 @@ public class PathEntryVariableResolver implements IDynamicVariableResolver { public String resolveValue(IDynamicVariable variable, String argument) throws CoreException { if (argument == null) { - throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, IStatus.ERROR, CCorePlugin.getResourceString("PathEntryVariableResolver.0"), null)); //$NON-NLS-1$ + throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, CCorePlugin.getResourceString("PathEntryVariableResolver.0"), null)); //$NON-NLS-1$ } IPathEntryVariableManager manager = CCorePlugin.getDefault().getPathEntryVariableManager(); IPath path = manager.getValue(argument);