1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Bug 450009 - NPE in CPPSemantics.getContainingNamespaceScope called from

IndexUI.findSpecializations
This commit is contained in:
Sergey Prigogin 2014-11-04 15:00:31 -08:00
parent 8997a49ef1
commit 2c8b0701cc
8 changed files with 28 additions and 20 deletions

View file

@ -817,7 +817,7 @@ public class CPPSemantics {
if (binding == null) if (binding == null)
return null; return null;
IScope scope = binding.getScope(); IScope scope = binding.getScope();
if (scope instanceof IIndexScope) { if (scope instanceof IIndexScope && tu != null) {
scope= tu.mapToASTScope((IIndexScope) scope); scope= tu.mapToASTScope((IIndexScope) scope);
} }
while (scope != null && !(scope instanceof ICPPNamespaceScope)) { while (scope != null && !(scope instanceof ICPPNamespaceScope)) {

View file

@ -20,6 +20,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
@ -109,7 +110,8 @@ public class CHQueries {
private static void findCalledBy1(IIndex index, IBinding callee, boolean includeOrdinaryCalls, private static void findCalledBy1(IIndex index, IBinding callee, boolean includeOrdinaryCalls,
ICProject project, CalledByResult result) throws CoreException { ICProject project, CalledByResult result) throws CoreException {
findCalledBy2(index, callee, includeOrdinaryCalls, project, result); findCalledBy2(index, callee, includeOrdinaryCalls, project, result);
List<? extends IBinding> specializations = IndexUI.findSpecializations(index, callee); IASTNode point= null; // Instantiation of dependent expressions may not work.
List<? extends IBinding> specializations = IndexUI.findSpecializations(index, callee, point);
for (IBinding spec : specializations) { for (IBinding spec : specializations) {
findCalledBy2(index, spec, includeOrdinaryCalls, project, result); findCalledBy2(index, spec, includeOrdinaryCalls, project, result);
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006, 2009 QNX Software Systems and others. * Copyright (c) 2006, 2014 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -18,6 +18,7 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
@ -52,7 +53,8 @@ public class IndexViewSearchQuery extends CSearchQuery {
public IStatus runWithIndex(IIndex index, IProgressMonitor monitor) throws OperationCanceledException { public IStatus runWithIndex(IIndex index, IProgressMonitor monitor) throws OperationCanceledException {
try { try {
if (CCoreInternals.getPDOMManager().getPDOM(fProject).getLastWriteAccess() == fLastWrite) { if (CCoreInternals.getPDOMManager().getPDOM(fProject).getLastWriteAccess() == fLastWrite) {
createMatches(index, fBinding); IASTNode point= null; // Instantiation of dependent expressions may not work.
createMatches(index, fBinding, point);
} }
return Status.OK_STATUS; return Status.OK_STATUS;
} catch (CoreException e) { } catch (CoreException e) {

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006, 2009 QNX Software Systems and others. * Copyright (c) 2006, 2014 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -18,6 +18,7 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
@ -46,7 +47,8 @@ public class CSearchElementQuery extends CSearchQuery {
IBinding binding= IndexUI.elementToBinding(index, (ICElement) element); IBinding binding= IndexUI.elementToBinding(index, (ICElement) element);
if (binding != null) { if (binding != null) {
label= labelForBinding(index, binding, label); label= labelForBinding(index, binding, label);
createMatches(index, binding); IASTNode point= null; // Instantiation of dependent expressions may not work.
createMatches(index, binding, point);
} }
} }
return Status.OK_STATUS; return Status.OK_STATUS;

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006, 2011 QNX Software Systems and others. * Copyright (c) 2006, 2014 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -24,6 +24,7 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IEnumerator; import org.eclipse.cdt.core.dom.ast.IEnumerator;
@ -184,7 +185,8 @@ public class CSearchPatternQuery extends CSearchQuery {
matchedBindings.add(indexBinding); matchedBindings.add(indexBinding);
} }
} }
createMatches(index, matchedBindings.toArray(new IIndexBinding[matchedBindings.size()])); IASTNode point= null; // Instantiation of dependent expressions may not work.
createMatches(index, matchedBindings.toArray(new IIndexBinding[matchedBindings.size()]), point);
} catch (CoreException e) { } catch (CoreException e) {
return e.getStatus(); return e.getStatus();
} }

View file

@ -340,11 +340,11 @@ public abstract class CSearchQuery implements ISearchQuery {
} }
} }
protected void createMatches(IIndex index, IBinding binding) throws CoreException { protected void createMatches(IIndex index, IBinding binding, IASTNode point) throws CoreException {
createMatches(index, new IBinding[] { binding }); createMatches(index, new IBinding[] { binding }, point);
} }
protected void createMatches(IIndex index, IBinding[] bindings) throws CoreException { protected void createMatches(IIndex index, IBinding[] bindings, IASTNode point) throws CoreException {
if (bindings == null) if (bindings == null)
return; return;
List<IIndexName> names= new ArrayList<>(); List<IIndexName> names= new ArrayList<>();
@ -360,7 +360,7 @@ public abstract class CSearchQuery implements ISearchQuery {
if ((flags & FIND_REFERENCES) != 0) { if ((flags & FIND_REFERENCES) != 0) {
for (IBinding binding : bindings) { for (IBinding binding : bindings) {
if (binding != null) { if (binding != null) {
List<? extends IBinding> specializations = IndexUI.findSpecializations(index, binding); List<? extends IBinding> specializations = IndexUI.findSpecializations(index, binding, point);
for (IBinding spec : specializations) { for (IBinding spec : specializations) {
if (spec != null && handled.add(spec)) { if (spec != null && handled.add(spec)) {
createMatches1(index, spec, names); createMatches1(index, spec, names);
@ -369,7 +369,6 @@ public abstract class CSearchQuery implements ISearchQuery {
if (binding instanceof ICPPMethod) { if (binding instanceof ICPPMethod) {
ICPPMethod m= (ICPPMethod) binding; ICPPMethod m= (ICPPMethod) binding;
IASTNode point = null; // Instantiation of dependent expressions may not work.
ICPPMethod[] msInBases = ClassTypeHelper.findOverridden(m, point); ICPPMethod[] msInBases = ClassTypeHelper.findOverridden(m, point);
if (msInBases.length > 0) { if (msInBases.length > 0) {
if (polymorphicNames == null) { if (polymorphicNames == null) {

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006, 2009 QNX Software Systems and others. * Copyright (c) 2006, 2014 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -43,7 +43,8 @@ public class CSearchTextSelectionQuery extends CSearchQuery {
private ITextSelection selection; private ITextSelection selection;
private String label; private String label;
public CSearchTextSelectionQuery(ICElement[] scope, ITranslationUnit tu, ITextSelection selection, int flags) { public CSearchTextSelectionQuery(ICElement[] scope, ITranslationUnit tu, ITextSelection selection,
int flags) {
super(scope, flags | IIndex.SEARCH_ACROSS_LANGUAGE_BOUNDARIES); super(scope, flags | IIndex.SEARCH_ACROSS_LANGUAGE_BOUNDARIES);
this.tu = tu; this.tu = tu;
this.selection = selection; this.selection = selection;
@ -76,7 +77,7 @@ public class CSearchTextSelectionQuery extends CSearchQuery {
binding= CPPTemplates.findDeclarationForSpecialization(binding); binding= CPPTemplates.findDeclarationForSpecialization(binding);
if (binding != null) { if (binding != null) {
label= labelForBinding(index, binding, label); label= labelForBinding(index, binding, label);
createMatches(index, binding); createMatches(index, binding, searchName);
return Status.OK_STATUS; return Status.OK_STATUS;
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007, 2013 Wind River Systems, Inc. and others. * Copyright (c) 2007, 2014 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -497,7 +497,8 @@ public class IndexUI {
/** /**
* Searches for all specializations that depend on the definition of the given binding. * Searches for all specializations that depend on the definition of the given binding.
*/ */
public static List<? extends IBinding> findSpecializations(IIndex index, IBinding binding) throws CoreException { public static List<? extends IBinding> findSpecializations(IIndex index, IBinding binding, IASTNode point)
throws CoreException {
List<IBinding> result= null; List<IBinding> result= null;
// Check for instances of the given binding. // Check for instances of the given binding.
@ -515,8 +516,7 @@ public class IndexUI {
// Check for specializations of the owner. // Check for specializations of the owner.
IBinding owner = binding.getOwner(); IBinding owner = binding.getOwner();
if (owner != null) { if (owner != null) {
IASTNode point= null; // Instantiation of dependent expressions may not work. List<? extends IBinding> specializations = findSpecializations(index, owner, point);
List<? extends IBinding> specializations = findSpecializations(index, owner);
for (IBinding specOwner : specializations) { for (IBinding specOwner : specializations) {
if (specOwner instanceof ICPPClassSpecialization) { if (specOwner instanceof ICPPClassSpecialization) {
// Add the specialized member. // Add the specialized member.