1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-12 18:55:38 +02:00

Hooked up the PDOM to the prefix lookup for content assist.

This commit is contained in:
Doug Schaefer 2005-10-18 04:30:05 +00:00
parent cb04187d5b
commit 84a0ef841b
7 changed files with 29 additions and 37 deletions

View file

@ -24,9 +24,11 @@ import org.eclipse.core.runtime.CoreException;
*/ */
public interface IPDOM { public interface IPDOM {
public IBinding resolveBinding(IASTName name) throws CoreException; public IBinding resolveBinding(IASTName name);
public IASTName[] getDeclarations(IBinding binding) throws CoreException; public IBinding[] resolvePrefix(IASTName name);
public IASTName[] getDeclarations(IBinding binding);
public void delete() throws CoreException; public void delete() throws CoreException;

View file

@ -45,7 +45,6 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTPreprocessorSelectionResult;
import org.eclipse.cdt.internal.core.dom.parser.IRequiresLocationInformation; import org.eclipse.cdt.internal.core.dom.parser.IRequiresLocationInformation;
import org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver; import org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver;
import org.eclipse.cdt.internal.core.parser.scanner2.InvalidPreprocessorNodeException; import org.eclipse.cdt.internal.core.parser.scanner2.InvalidPreprocessorNodeException;
import org.eclipse.core.runtime.CoreException;
/** /**
* @author jcamelon * @author jcamelon
@ -120,13 +119,8 @@ public class CASTTranslationUnit extends CASTNode implements
return resolver.getDeclarations( (IMacroBinding)binding ); return resolver.getDeclarations( (IMacroBinding)binding );
} }
IASTName[] names = CVisitor.getDeclarations(this, binding); IASTName[] names = CVisitor.getDeclarations(this, binding);
if (names.length == 0 && pdom != null) { if (names.length == 0 && pdom != null)
try { names = pdom.getDeclarations(binding);
names = pdom.getDeclarations(binding);
} catch (CoreException e) {
names = new IASTName[0];
}
}
return names; return names;
} }

View file

@ -94,7 +94,6 @@ import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.core.parser.util.ObjectSet; import org.eclipse.cdt.core.parser.util.ObjectSet;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.core.runtime.CoreException;
/** /**
* Created on Nov 5, 2004 * Created on Nov 5, 2004
@ -1303,14 +1302,9 @@ public class CVisitor {
IASTTranslationUnit tu = (IASTTranslationUnit)blockItem; IASTTranslationUnit tu = (IASTTranslationUnit)blockItem;
IPDOM pdom = tu.getPDOM(); IPDOM pdom = tu.getPDOM();
binding = null; binding = null;
if (pdom != null) { if (pdom != null)
try { binding = pdom.resolveBinding(name);
binding = pdom.resolveBinding(name);
} catch (CoreException e) {
// didn't work, null out the binding
binding = null;
}
}
if (binding == null) if (binding == null)
return externalBinding( (IASTTranslationUnit) blockItem, name ); return externalBinding( (IASTTranslationUnit) blockItem, name );
else else
@ -1911,6 +1905,11 @@ public class CVisitor {
} catch ( DOMException e ) { } catch ( DOMException e ) {
} }
} }
IPDOM pdom = name.getTranslationUnit().getPDOM();
if (pdom != null)
result = (IBinding[])ArrayUtil.addAll(IBinding.class, result, pdom.resolvePrefix(name));
return (IBinding[]) ArrayUtil.trim( IBinding.class, result ); return (IBinding[]) ArrayUtil.trim( IBinding.class, result );
} }

View file

@ -55,7 +55,7 @@ public class CPPASTName extends CPPASTNode implements IASTName {
} }
public IBinding[] resolvePrefix() { public IBinding[] resolvePrefix() {
return CPPSemantics.prefixLookup(this); return CPPSemantics.prefixLookup(this);
} }
public void setBinding(IBinding binding) { public void setBinding(IBinding binding) {

View file

@ -61,7 +61,6 @@ import org.eclipse.cdt.internal.core.dom.parser.IRequiresLocationInformation;
import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider.CPPBuiltinParameter; import org.eclipse.cdt.internal.core.dom.parser.GCCBuiltinSymbolProvider.CPPBuiltinParameter;
import org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver; import org.eclipse.cdt.internal.core.parser.scanner2.ILocationResolver;
import org.eclipse.cdt.internal.core.parser.scanner2.InvalidPreprocessorNodeException; import org.eclipse.cdt.internal.core.parser.scanner2.InvalidPreprocessorNodeException;
import org.eclipse.core.runtime.CoreException;
/** /**
* @author jcamelon * @author jcamelon
@ -179,13 +178,8 @@ public class CPPASTTranslationUnit extends CPPASTNode implements
return resolver.getDeclarations( (IMacroBinding)b ); return resolver.getDeclarations( (IMacroBinding)b );
} }
IASTName[] names = CPPVisitor.getDeclarations( this, b ); IASTName[] names = CPPVisitor.getDeclarations( this, b );
if (names.length == 0 && pdom != null) { if (names.length == 0 && pdom != null)
try { names = pdom.getDeclarations(b);
names = pdom.getDeclarations(b);
} catch (CoreException e) {
names = new IASTName[0];
}
}
return names; return names;
} }

View file

@ -125,7 +125,6 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil.ArrayWrapper;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.core.runtime.CoreException;
/** /**
* @author aniefer * @author aniefer
@ -748,13 +747,9 @@ public class CPPSemantics {
if( binding == null ){ if( binding == null ){
// Let's try the pdom // Let's try the pdom
IPDOM pdom = name.getTranslationUnit().getPDOM(); IPDOM pdom = name.getTranslationUnit().getPDOM();
if (pdom != null) { if (pdom != null)
try { binding = pdom.resolveBinding(name);
binding = pdom.resolveBinding(name);
} catch (CoreException e) {
binding = null;
}
}
// If we're still null... // If we're still null...
if (binding == null) { if (binding == null) {
if( name instanceof ICPPASTQualifiedName && data.forDefinition() ) if( name instanceof ICPPASTQualifiedName && data.forDefinition() )
@ -3236,6 +3231,7 @@ public class CPPSemantics {
return (IBinding[]) set.keyArray( IBinding.class ); return (IBinding[]) set.keyArray( IBinding.class );
} }
public static IBinding [] prefixLookup( IASTName name ){ public static IBinding [] prefixLookup( IASTName name ){
LookupData data = createLookupData( name, true ); LookupData data = createLookupData( name, true );
data.prefixLookup = true; data.prefixLookup = true;
@ -3275,6 +3271,11 @@ public class CPPSemantics {
} }
} }
} }
IPDOM pdom = name.getTranslationUnit().getPDOM();
if (pdom != null)
result = (IBinding[])ArrayUtil.addAll(IBinding.class, result, pdom.resolvePrefix(name));
return (IBinding[]) ArrayUtil.trim( IBinding.class, result ); return (IBinding[]) ArrayUtil.trim( IBinding.class, result );
} }

View file

@ -228,8 +228,10 @@ public class InternalASTServiceProvider implements IASTServiceProvider {
// Run the parse and return the completion node // Run the parse and return the completion node
parser.parse(); parser.parse();
ASTCompletionNode node = parser.getCompletionNode(); ASTCompletionNode node = parser.getCompletionNode();
if (node != null) if (node != null) {
node.getTranslationUnit().setPDOM(PDOM.getPDOM(project));
node.count = scanner.getCount(); node.count = scanner.getCount();
}
return node; return node;
} }