1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Code streamlining.

This commit is contained in:
Sergey Prigogin 2014-08-19 17:00:37 -07:00
parent 344cd17bc9
commit 9bc12f31aa

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006, 2010 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
@ -8,6 +8,7 @@
* Contributors: * Contributors:
* Doug Schaefer (QNX) - Initial API and implementation * Doug Schaefer (QNX) - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp; package org.eclipse.cdt.internal.core.pdom.dom.cpp;
@ -67,38 +68,29 @@ class PDOMCPPNamespaceAlias extends PDOMCPPBinding implements ICPPNamespaceAlias
@Override @Override
public ICPPNamespaceScope getNamespaceScope() { public ICPPNamespaceScope getNamespaceScope() {
return getNamespaceScope(this, 20); // avoid an infinite loop. // Avoid an infinite loop.
} ICPPNamespaceAlias ns= this;
for (int i = 0; i < 20; i++) {
private ICPPNamespaceScope getNamespaceScope(PDOMCPPNamespaceAlias alias, final int maxDepth) { IBinding binding= ns.getBinding();
IBinding binding= alias.getBinding(); if (binding instanceof ICPPNamespaceScope)
if (binding instanceof ICPPNamespaceScope) { return (ICPPNamespaceScope) binding;
return (ICPPNamespaceScope) binding; if (!(binding instanceof ICPPNamespaceAlias))
} break;
ns= (ICPPNamespaceAlias) binding;
if (maxDepth <= 0) {
return null;
}
if (binding instanceof PDOMCPPNamespaceAlias) {
return getNamespaceScope((PDOMCPPNamespaceAlias) binding, maxDepth-1);
} }
return null; return null;
} }
@Override @Override
public IBinding[] getMemberBindings() { public IBinding[] getMemberBindings() {
ICPPNamespace ns= this; ICPPNamespace ns= this;
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
if (ns instanceof ICPPNamespaceAlias) { IBinding b= ((ICPPNamespaceAlias) ns).getBinding();
IBinding b= ((ICPPNamespaceAlias) ns).getBinding(); if (!(b instanceof ICPPNamespace))
if (b instanceof ICPPNamespace) { return IBinding.EMPTY_BINDING_ARRAY;
ns= (ICPPNamespace) b; ns= (ICPPNamespace) b;
} else { if (!(ns instanceof ICPPNamespaceAlias))
return IBinding.EMPTY_BINDING_ARRAY;
}
} else {
break; break;
}
} }
return ns.getMemberBindings(); return ns.getMemberBindings();
} }
@ -106,7 +98,7 @@ class PDOMCPPNamespaceAlias extends PDOMCPPBinding implements ICPPNamespaceAlias
@Override @Override
public IBinding getBinding() { public IBinding getBinding() {
try { try {
return (IBinding) PDOMNode.load(getPDOM(), getPDOM().getDB().getRecPtr(record + NAMESPACE_BINDING)); return (IBinding) PDOMNode.load(getPDOM(), getDB().getRecPtr(record + NAMESPACE_BINDING));
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(e); CCorePlugin.log(e);
} }