1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Support search for references off #undef statement (fixes a NPE).

This commit is contained in:
Markus Schorn 2008-04-29 08:43:11 +00:00
parent a27ec4031f
commit 066875bdab
4 changed files with 28 additions and 15 deletions

View file

@ -34,6 +34,7 @@ import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
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;
@ -364,6 +365,11 @@ public class PDOM extends PlatformObject implements IPDOM {
if (linkage != null) { if (linkage != null) {
return findBindingInLinkage(linkage, binding); return findBindingInLinkage(linkage, binding);
} }
} else if (name.getPropertyInParent() == IASTPreprocessorStatement.MACRO_NAME) {
PDOMLinkage linkage= adaptLinkage(name.getLinkage());
if (linkage != null) {
return linkage.findMacroContainer(name.toCharArray());
}
} }
return null; return null;
} }

View file

@ -8,7 +8,6 @@
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom; package org.eclipse.cdt.internal.core.pdom.dom;
import org.eclipse.cdt.core.dom.ILinkage; import org.eclipse.cdt.core.dom.ILinkage;
@ -159,6 +158,11 @@ public class PDOMASTAdapter {
public boolean isPartOfTranslationUnitFile() { public boolean isPartOfTranslationUnitFile() {
return fLocation.getFileName().equals(fDelegate.getTranslationUnit().getFilePath()); return fLocation.getFileName().equals(fDelegate.getTranslationUnit().getFilePath());
} }
@Override
public String toString() {
return fDelegate.toString();
}
} }
private static class AnonymousEnumeration implements IEnumeration { private static class AnonymousEnumeration implements IEnumeration {
@ -319,7 +323,7 @@ public class PDOMASTAdapter {
} }
} }
private static class AnonymousCPPEnumeration extends AnonymousCPPBinding implements IEnumeration, ICPPBinding { private static class AnonymousCPPEnumeration extends AnonymousCPPBinding implements IEnumeration {
public AnonymousCPPEnumeration(char[] name, IEnumeration delegate) { public AnonymousCPPEnumeration(char[] name, IEnumeration delegate) {
super(name, (ICPPBinding) delegate); super(name, (ICPPBinding) delegate);
} }

View file

@ -307,7 +307,8 @@ public class PDOMFile implements IIndexFragmentFile {
return null; return null;
} }
try { try {
if (binding instanceof IMacroBinding) { if (binding instanceof IMacroBinding
|| (binding == null && name.getPropertyInParent() == IASTPreprocessorStatement.MACRO_NAME)) {
return createPDOMMacroReferenceName(linkage, name); return createPDOMMacroReferenceName(linkage, name);
} }
PDOMBinding pdomBinding = linkage.addBinding(name); PDOMBinding pdomBinding = linkage.addBinding(name);

View file

@ -60,6 +60,7 @@ public class PDOMSearchTextSelectionQuery extends PDOMSearchQuery {
searchText= searchName.toString(); searchText= searchName.toString();
IBinding binding= searchName.resolveBinding(); IBinding binding= searchName.resolveBinding();
if (binding instanceof IProblemBinding == false) { if (binding instanceof IProblemBinding == false) {
if (binding != null) {
IScope scope= null; IScope scope= null;
try { try {
scope = binding.getScope(); scope = binding.getScope();
@ -67,12 +68,13 @@ public class PDOMSearchTextSelectionQuery extends PDOMSearchQuery {
} }
if (scope instanceof ICPPBlockScope || scope instanceof ICFunctionScope) { if (scope instanceof ICPPBlockScope || scope instanceof ICFunctionScope) {
createLocalMatches(ast, binding); createLocalMatches(ast, binding);
return Status.OK_STATUS;
}
} }
else {
binding = index.findBinding(searchName); binding = index.findBinding(searchName);
if (binding != null) { if (binding != null) {
createMatches(index, binding); createMatches(index, binding);
} return Status.OK_STATUS;
} }
} }
} }