mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Use generics.
This commit is contained in:
parent
7cdbcfc0f9
commit
2d4cd87741
1 changed files with 21 additions and 24 deletions
|
@ -51,48 +51,47 @@ public class CPPFunctionScope extends CPPScope implements ICPPFunctionScope {
|
||||||
super(physicalNode);
|
super(physicalNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#addBinding(org.eclipse.cdt.core.dom.ast.IBinding)
|
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#addBinding(org.eclipse.cdt.core.dom.ast.IBinding)
|
||||||
*/
|
*/
|
||||||
public void addBinding(IBinding binding) {
|
public void addBinding(IBinding binding) {
|
||||||
//3.3.4 only labels have function scope
|
//3.3.4 only labels have function scope
|
||||||
if( !( binding instanceof ILabel ) )
|
if (!(binding instanceof ILabel))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( labels == CharArrayObjectMap.EMPTY_MAP )
|
if (labels == CharArrayObjectMap.EMPTY_MAP)
|
||||||
labels = new CharArrayObjectMap( 2 );
|
labels = new CharArrayObjectMap(2);
|
||||||
|
|
||||||
labels.put( binding.getNameCharArray(), binding );
|
labels.put(binding.getNameCharArray(), binding);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#getBinding(int, char[])
|
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#getBinding(int, char[])
|
||||||
*/
|
*/
|
||||||
public IBinding getBinding( IASTName name ) {
|
public IBinding getBinding(IASTName name) {
|
||||||
return (IBinding) labels.get( name.toCharArray() );
|
return (IBinding) labels.get(name.toCharArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
|
* @see org.eclipse.cdt.core.dom.ast.IScope#find(java.lang.String)
|
||||||
*/
|
*/
|
||||||
public IBinding[] find(String name) throws DOMException {
|
public IBinding[] find(String name) throws DOMException {
|
||||||
char [] n = name.toCharArray();
|
char[] n = name.toCharArray();
|
||||||
List bindings = new ArrayList();
|
List<IBinding> bindings = new ArrayList<IBinding>();
|
||||||
|
|
||||||
for (int i = 0; i < labels.size(); i++) {
|
for (int i = 0; i < labels.size(); i++) {
|
||||||
char[] key = labels.keyAt(i);
|
char[] key = labels.keyAt(i);
|
||||||
if (CharArrayUtils.equals(key, n)) {
|
if (CharArrayUtils.equals(key, n)) {
|
||||||
bindings.add(labels.get(key));
|
bindings.add((IBinding) labels.get(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IBinding[] additional = super.find( name );
|
IBinding[] additional = super.find(name);
|
||||||
for (int i = 0; i < additional.length; i++) {
|
for (int i = 0; i < additional.length; i++) {
|
||||||
bindings.add(additional[i]);
|
bindings.add(additional[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (IBinding[]) bindings.toArray(new IBinding[bindings.size()]);
|
return bindings.toArray(new IBinding[bindings.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IScope getParent() throws DOMException {
|
public IScope getParent() throws DOMException {
|
||||||
|
@ -100,48 +99,46 @@ public class CPPFunctionScope extends CPPScope implements ICPPFunctionScope {
|
||||||
//could loop since resolving functions requires resolving their parameter types
|
//could loop since resolving functions requires resolving their parameter types
|
||||||
IASTFunctionDeclarator fdtor = (IASTFunctionDeclarator) getPhysicalNode();
|
IASTFunctionDeclarator fdtor = (IASTFunctionDeclarator) getPhysicalNode();
|
||||||
IASTName name = fdtor.getName();
|
IASTName name = fdtor.getName();
|
||||||
if( name instanceof ICPPASTQualifiedName ){
|
if (name instanceof ICPPASTQualifiedName) {
|
||||||
ICPPASTQualifiedName qual = (ICPPASTQualifiedName) name;
|
ICPPASTQualifiedName qual = (ICPPASTQualifiedName) name;
|
||||||
IASTName [] ns = qual.getNames();
|
IASTName[] ns = qual.getNames();
|
||||||
if( ns.length > 1){
|
if (ns.length > 1) {
|
||||||
IBinding binding = ns[ ns.length - 2 ].resolveBinding();
|
IBinding binding = ns[ ns.length - 2 ].resolveBinding();
|
||||||
if (binding == null)
|
if (binding == null)
|
||||||
return null;
|
return null;
|
||||||
else if( binding instanceof ICPPClassType )
|
else if (binding instanceof ICPPClassType)
|
||||||
return ((ICPPClassType)binding).getCompositeScope();
|
return ((ICPPClassType)binding).getCompositeScope();
|
||||||
else if( binding instanceof ICPPNamespace )
|
else if (binding instanceof ICPPNamespace)
|
||||||
return ((ICPPNamespace)binding).getNamespaceScope();
|
return ((ICPPNamespace)binding).getNamespaceScope();
|
||||||
return binding.getScope();
|
return binding.getScope();
|
||||||
} else if( qual.isFullyQualified() ){
|
} else if (qual.isFullyQualified()) {
|
||||||
return qual.getTranslationUnit().getScope();
|
return qual.getTranslationUnit().getScope();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return CPPVisitor.getContainingScope( name );
|
return CPPVisitor.getContainingScope(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionScope#getBodyScope()
|
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionScope#getBodyScope()
|
||||||
*/
|
*/
|
||||||
public IScope getBodyScope() {
|
public IScope getBodyScope() {
|
||||||
IASTFunctionDeclarator fnDtor = (IASTFunctionDeclarator) getPhysicalNode();
|
IASTFunctionDeclarator fnDtor = (IASTFunctionDeclarator) getPhysicalNode();
|
||||||
IASTNode parent = fnDtor.getParent();
|
IASTNode parent = fnDtor.getParent();
|
||||||
if( parent instanceof IASTFunctionDefinition ){
|
if (parent instanceof IASTFunctionDefinition) {
|
||||||
IASTStatement body = ((IASTFunctionDefinition)parent).getBody();
|
IASTStatement body = ((IASTFunctionDefinition)parent).getBody();
|
||||||
if( body instanceof IASTCompoundStatement )
|
if (body instanceof IASTCompoundStatement)
|
||||||
return ((IASTCompoundStatement)body).getScope();
|
return ((IASTCompoundStatement)body).getScope();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#getScopeName()
|
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPScope#getScopeName()
|
||||||
*/
|
*/
|
||||||
public IName getScopeName() {
|
public IName getScopeName() {
|
||||||
IASTNode node = getPhysicalNode();
|
IASTNode node = getPhysicalNode();
|
||||||
if( node instanceof ICPPASTFunctionDeclarator ){
|
if (node instanceof ICPPASTFunctionDeclarator) {
|
||||||
return ((ICPPASTFunctionDeclarator)node).getName();
|
return ((ICPPASTFunctionDeclarator)node).getName();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Add table
Reference in a new issue