diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexProviderManagerTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexProviderManagerTest.java index c22e2f0b354..9f49a666e8e 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexProviderManagerTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexProviderManagerTest.java @@ -316,18 +316,19 @@ public class IndexProviderManagerTest extends IndexTestBase { public void testIndexFactoryConfigurationUsage() throws Exception { IIndex index; - ICProject cproject= CProjectHelper.createCCProject("IndexFactoryConfigurationUsageTest", IPDOMManager.ID_NO_INDEXER); - IProject project= cproject.getProject(); - - ICProjectDescription pd= core.getProjectDescription(project); - ICConfigurationDescription cfg1= newCfg(pd, "project", "config1"); - ICConfigurationDescription cfg2= newCfg(pd, "project", "config2"); - core.setProjectDescription(project, pd); - - index= CCorePlugin.getIndexManager().getIndex(cproject); - CCorePlugin.getIndexManager().joinIndexer(8000, NPM); - + ICProject cproject = null; try { + cproject = CProjectHelper.createCCProject("IndexFactoryConfigurationUsageTest", IPDOMManager.ID_NO_INDEXER); + IProject project= cproject.getProject(); + + ICProjectDescription pd= core.getProjectDescription(project); + ICConfigurationDescription cfg1= newCfg(pd, "project", "config1"); + ICConfigurationDescription cfg2= newCfg(pd, "project", "config2"); + core.setProjectDescription(project, pd); + + index= CCorePlugin.getIndexManager().getIndex(cproject); + CCorePlugin.getIndexManager().joinIndexer(8000, NPM); + DPT.reset(DP1); changeConfigRelations(project, ICProjectDescriptionPreferences.CONFIGS_LINK_SETTINGS_AND_ACTIVE); assertEquals(0, DPT.getProjectsTrace(DP1).size()); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameter.java index 035fb9c8c93..258594ffe32 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPTemplateParameter.java @@ -86,7 +86,6 @@ public class CPPTemplateParameter extends PlatformObject implements ICPPTemplate * @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#isGloballyQualified() */ public boolean isGloballyQualified() { - // TODO Auto-generated method stub return false; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index d0a93396a77..3c8d5c4a706 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -152,36 +152,36 @@ public class CPPSemantics { public static final char[] EMPTY_NAME_ARRAY = new char[0]; public static final String EMPTY_NAME = ""; //$NON-NLS-1$ public static final char[] OPERATOR_ = new char[] {'o','p','e','r','a','t','o','r',' '}; - public static final IType VOID_TYPE = new CPPBasicType( IBasicType.t_void, 0 ); + public static final IType VOID_TYPE = new CPPBasicType(IBasicType.t_void, 0); - static protected IBinding resolveBinding( IASTName name ){ + static protected IBinding resolveBinding(IASTName name) { //1: get some context info off of the name to figure out what kind of lookup we want - LookupData data = createLookupData( name, true ); + LookupData data = createLookupData(name, true); try { //2: lookup - lookup( data, name ); - } catch ( DOMException e1 ) { + lookup(data, name); + } catch (DOMException e1) { data.problem = (ProblemBinding) e1.getProblem(); } - if( data.problem != null ) + if (data.problem != null) return data.problem; //3: resolve ambiguities IBinding binding; try { - binding = resolveAmbiguities( data, name ); - } catch ( DOMException e2 ) { + binding = resolveAmbiguities(data, name); + } catch (DOMException e2) { binding = e2.getProblem(); } //4: post processing - binding = postResolution( binding, data ); + binding = postResolution(binding, data); return binding; } - protected static IBinding postResolution( IBinding binding, IASTName name) { - LookupData data = createLookupData( name, true ); + protected static IBinding postResolution(IBinding binding, IASTName name) { + LookupData data = createLookupData(name, true); return postResolution(binding, data); } @@ -191,300 +191,301 @@ public class CPPSemantics { * @param name * @return */ - private static IBinding postResolution( IBinding binding, LookupData data ) { - if( data.checkAssociatedScopes() ){ + private static IBinding postResolution(IBinding binding, LookupData data) { + if (data.checkAssociatedScopes()) { //3.4.2 argument dependent name lookup, aka Koenig lookup try { - IScope scope = (binding != null ) ? binding.getScope() : null; - if( scope == null || !(scope instanceof ICPPClassScope) ){ + IScope scope = (binding != null) ? binding.getScope() : null; + if (scope == null || !(scope instanceof ICPPClassScope)) { data.ignoreUsingDirectives = true; data.forceQualified = true; - for( int i = 0; i < data.associated.size(); i++ ){ - lookup( data, data.associated.keyAt(i) ); + for (int i = 0; i < data.associated.size(); i++) { + lookup(data, data.associated.keyAt(i)); } - binding = resolveAmbiguities( data, data.astName ); + binding = resolveAmbiguities(data, data.astName); } - } catch ( DOMException e ) { + } catch (DOMException e) { binding = e.getProblem(); } } - if( binding == null && data.checkClassContainingFriend() ){ + if (binding == null && data.checkClassContainingFriend()) { //3.4.1-10 if we don't find a name used in a friend declaration in the member declaration's class //we should look in the class granting friendship IASTNode parent = data.astName.getParent(); - while( parent != null && !(parent instanceof ICPPASTCompositeTypeSpecifier) ) + while (parent != null && !(parent instanceof ICPPASTCompositeTypeSpecifier)) parent = parent.getParent(); - if( parent instanceof ICPPASTCompositeTypeSpecifier ){ + if (parent instanceof ICPPASTCompositeTypeSpecifier) { IScope scope = ((ICPPASTCompositeTypeSpecifier)parent).getScope(); try { - lookup( data, scope ); - binding = resolveAmbiguities( data, data.astName ); - } catch( DOMException e ){ + lookup(data, scope); + binding = resolveAmbiguities(data, data.astName); + } catch (DOMException e) { binding = e.getProblem(); } } } - if( binding instanceof ICPPClassTemplate ){ + if (binding instanceof ICPPClassTemplate) { ASTNodeProperty prop = data.astName.getPropertyInParent(); - if( prop != ICPPASTQualifiedName.SEGMENT_NAME && prop != ICPPASTTemplateId.TEMPLATE_NAME && - binding instanceof ICPPInternalBinding){ + if (prop != ICPPASTQualifiedName.SEGMENT_NAME && prop != ICPPASTTemplateId.TEMPLATE_NAME && + binding instanceof ICPPInternalBinding) { try { IASTNode def = ((ICPPInternalBinding)binding).getDefinition(); - if( def != null ){ + if (def != null) { def = def.getParent(); IASTNode parent = data.astName.getParent(); - while( parent != null ){ - if( parent == def ){ - binding = CPPTemplates.instantiateWithinClassTemplate( (ICPPClassTemplate) binding ); + while (parent != null) { + if (parent == def) { + binding = CPPTemplates.instantiateWithinClassTemplate((ICPPClassTemplate) binding); break; } - if( parent instanceof ICPPASTNamespaceDefinition ) + if (parent instanceof ICPPASTNamespaceDefinition) break; parent = parent.getParent(); } } - } catch( DOMException e ) { + } catch (DOMException e) { } } } - if( binding instanceof ICPPClassType && data.considerConstructors ){ + if (binding instanceof ICPPClassType && data.considerConstructors) { ICPPClassType cls = (ICPPClassType) binding; - if( data.astName instanceof ICPPASTTemplateId && cls instanceof ICPPTemplateDefinition ){ + if (data.astName instanceof ICPPASTTemplateId && cls instanceof ICPPTemplateDefinition) { ICPPASTTemplateId id = (ICPPASTTemplateId) data.astName; - IType [] args = CPPTemplates.createTypeArray( id.getTemplateArguments() ); - IBinding inst = ((ICPPInternalTemplateInstantiator)cls).instantiate( args ); + IType[] args = CPPTemplates.createTypeArray(id.getTemplateArguments()); + IBinding inst = ((ICPPInternalTemplateInstantiator)cls).instantiate(args); cls = inst instanceof ICPPClassType ? (ICPPClassType)inst : cls; } - if( cls != null ){ + if (cls != null) { try { //force resolution of constructor bindings - IBinding [] ctors = cls.getConstructors(); - if( ctors.length > 0 && !(ctors[0] instanceof IProblemBinding) ){ + IBinding[] ctors = cls.getConstructors(); + if (ctors.length > 0 && !(ctors[0] instanceof IProblemBinding)) { //then use the class scope to resolve which one. - binding = ((ICPPClassScope)cls.getCompositeScope()).getBinding( data.astName, true ); + binding = ((ICPPClassScope)cls.getCompositeScope()).getBinding(data.astName, true); } - } catch ( DOMException e ) { + } catch (DOMException e) { binding = e.getProblem(); } } } IASTName name = data.astName; - if( name.getParent() instanceof ICPPASTTemplateId ){ - if( binding instanceof ICPPTemplateInstance ){ + if (name.getParent() instanceof ICPPASTTemplateId) { + if (binding instanceof ICPPTemplateInstance) { IBinding b = binding; binding = ((ICPPTemplateInstance)binding).getSpecializedBinding(); - name.setBinding( binding ); + name.setBinding(binding); name = (IASTName) name.getParent(); - name.setBinding( b ); + name.setBinding(b); } else { name = (IASTName) name.getParent(); } } - if( name.getParent() instanceof ICPPASTQualifiedName ){ - IASTName [] ns = ((ICPPASTQualifiedName)name.getParent()).getNames(); - if( name == ns [ ns.length - 1] ) + if (name.getParent() instanceof ICPPASTQualifiedName) { + IASTName[] ns = ((ICPPASTQualifiedName)name.getParent()).getNames(); + if (name == ns[ns.length - 1]) name = (IASTName) name.getParent(); } - if( binding != null ) { - if( name.getPropertyInParent() == IASTNamedTypeSpecifier.NAME && !( binding instanceof IType || binding instanceof ICPPConstructor) ){ + if (binding != null) { + if (name.getPropertyInParent() == IASTNamedTypeSpecifier.NAME && !(binding instanceof IType || binding instanceof ICPPConstructor)) { IASTNode parent = name.getParent().getParent(); - if( parent instanceof IASTTypeId && parent.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT ){ + if (parent instanceof IASTTypeId && parent.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) { //don't do a problem here } else { - binding = new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_INVALID_TYPE, data.name() ); + binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_INVALID_TYPE, data.name()); } } } - if( binding != null && !( binding instanceof IProblemBinding ) ){ - if( data.forDefinition() ){ - addDefinition( binding, data.astName ); + if (binding != null && !(binding instanceof IProblemBinding)) { + if (data.forDefinition()) { + addDefinition(binding, data.astName); } } // If we're still null... if (binding == null) { - if( name instanceof ICPPASTQualifiedName && data.forDefinition() ) - binding = new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_MEMBER_DECLARATION_NOT_FOUND, data.name() ); + if (name instanceof ICPPASTQualifiedName && data.forDefinition()) + binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_MEMBER_DECLARATION_NOT_FOUND, data.name()); else - binding = new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, data.name() ); + binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_NAME_NOT_FOUND, data.name()); } return binding; } - private static LookupData createLookupData( IASTName name, boolean considerAssociatedScopes ){ - LookupData data = new LookupData( name ); + private static LookupData createLookupData(IASTName name, boolean considerAssociatedScopes) { + LookupData data = new LookupData(name); IASTNode parent = name.getParent(); - if( name instanceof ICPPASTTemplateId ){ + if (name instanceof ICPPASTTemplateId) { data.templateArguments = ((ICPPASTTemplateId)name).getTemplateArguments(); } - if( parent instanceof ICPPASTTemplateId ) + if (parent instanceof ICPPASTTemplateId) parent = parent.getParent(); - if( parent instanceof ICPPASTQualifiedName ) + if (parent instanceof ICPPASTQualifiedName) parent = parent.getParent(); - if( parent instanceof IASTDeclarator && parent.getPropertyInParent() == IASTSimpleDeclaration.DECLARATOR ){ + if (parent instanceof IASTDeclarator && parent.getPropertyInParent() == IASTSimpleDeclaration.DECLARATOR) { IASTSimpleDeclaration simple = (IASTSimpleDeclaration) parent.getParent(); - if( simple.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef ) + if (simple.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef) data.forceQualified = true; } - if( parent instanceof ICPPASTFunctionDeclarator ){ + if (parent instanceof ICPPASTFunctionDeclarator) { data.functionParameters = ((ICPPASTFunctionDeclarator)parent).getParameters(); - } else if( parent instanceof IASTIdExpression ){ + } else if (parent instanceof IASTIdExpression) { ASTNodeProperty prop = parent.getPropertyInParent(); - if( prop == IASTFunctionCallExpression.FUNCTION_NAME ){ + if (prop == IASTFunctionCallExpression.FUNCTION_NAME) { parent = parent.getParent(); IASTExpression exp = ((IASTFunctionCallExpression)parent).getParameterExpression(); - if( exp instanceof IASTExpressionList ) - data.functionParameters = ((IASTExpressionList) exp ).getExpressions(); - else if( exp != null ) - data.functionParameters = new IASTExpression [] { exp }; + if (exp instanceof IASTExpressionList) + data.functionParameters = ((IASTExpressionList) exp).getExpressions(); + else if (exp != null) + data.functionParameters = new IASTExpression[] { exp }; else data.functionParameters = IASTExpression.EMPTY_EXPRESSION_ARRAY; } - } else if( parent instanceof ICPPASTFieldReference && parent.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME ){ + } else if (parent instanceof ICPPASTFieldReference && parent.getPropertyInParent() == IASTFunctionCallExpression.FUNCTION_NAME) { IASTExpression exp = ((IASTFunctionCallExpression)parent.getParent()).getParameterExpression(); - if( exp instanceof IASTExpressionList ) - data.functionParameters = ((IASTExpressionList) exp ).getExpressions(); - else if( exp != null ) - data.functionParameters = new IASTExpression [] { exp }; + if (exp instanceof IASTExpressionList) + data.functionParameters = ((IASTExpressionList) exp).getExpressions(); + else if (exp != null) + data.functionParameters = new IASTExpression[] { exp }; else data.functionParameters = IASTExpression.EMPTY_EXPRESSION_ARRAY; - } else if( parent instanceof ICPPASTNamedTypeSpecifier && parent.getParent() instanceof IASTTypeId ){ + } else if (parent instanceof ICPPASTNamedTypeSpecifier && parent.getParent() instanceof IASTTypeId) { IASTTypeId typeId = (IASTTypeId) parent.getParent(); - if( typeId.getParent() instanceof ICPPASTNewExpression ){ + if (typeId.getParent() instanceof ICPPASTNewExpression) { ICPPASTNewExpression newExp = (ICPPASTNewExpression) typeId.getParent(); IASTExpression init = newExp.getNewInitializer(); - if( init instanceof IASTExpressionList ) - data.functionParameters = ((IASTExpressionList) init ).getExpressions(); - else if( init != null ) - data.functionParameters = new IASTExpression [] { init }; + if (init instanceof IASTExpressionList) + data.functionParameters = ((IASTExpressionList) init).getExpressions(); + else if (init != null) + data.functionParameters = new IASTExpression[] { init }; else data.functionParameters = IASTExpression.EMPTY_EXPRESSION_ARRAY; } - } else if( parent instanceof ICPPASTConstructorChainInitializer ){ + } else if (parent instanceof ICPPASTConstructorChainInitializer) { ICPPASTConstructorChainInitializer ctorinit = (ICPPASTConstructorChainInitializer) parent; IASTExpression val = ctorinit.getInitializerValue(); - if( val instanceof IASTExpressionList ) - data.functionParameters = ((IASTExpressionList) val ).getExpressions(); - else if( val != null ) - data.functionParameters = new IASTExpression [] { val }; + if (val instanceof IASTExpressionList) + data.functionParameters = ((IASTExpressionList) val).getExpressions(); + else if (val != null) + data.functionParameters = new IASTExpression[] { val }; else data.functionParameters = IASTExpression.EMPTY_EXPRESSION_ARRAY; } - if( considerAssociatedScopes && !(name.getParent() instanceof ICPPASTQualifiedName) && data.functionCall() ){ - data.associated = getAssociatedScopes( data ); + if (considerAssociatedScopes && !(name.getParent() instanceof ICPPASTQualifiedName) && data.functionCall()) { + data.associated = getAssociatedScopes(data); } return data; } - static private ObjectSet getAssociatedScopes( LookupData data ) { - IType [] ps = getSourceParameterTypes( data.functionParameters ); + static private ObjectSet getAssociatedScopes(LookupData data) { + IType[] ps = getSourceParameterTypes(data.functionParameters); ObjectSet namespaces = new ObjectSet(2); ObjectSet classes = new ObjectSet(2); - for( int i = 0; i < ps.length; i++ ){ + for (int i = 0; i < ps.length; i++) { IType p = ps[i]; - p = getUltimateType( p, true ); + p = getUltimateType(p, true); try { - getAssociatedScopes( p, namespaces, classes, data.tu); - } catch ( DOMException e ) { + getAssociatedScopes(p, namespaces, classes, data.tu); + } catch (DOMException e) { } } return namespaces; } - static private void getAssociatedScopes( IType t, ObjectSet namespaces, ObjectSet classes, CPPASTTranslationUnit tu) throws DOMException{ + static private void getAssociatedScopes(IType t, ObjectSet namespaces, ObjectSet classes, CPPASTTranslationUnit tu) throws DOMException{ //3.4.2-2 - if(t instanceof ICPPClassType) { + if (t instanceof ICPPClassType) { ICPPClassType ct= (ICPPClassType) t; - if(!classes.containsKey(ct)) { + if (!classes.containsKey(ct)) { classes.put(ct); - IScope scope = getContainingNamespaceScope( (IBinding) t, tu); - if( scope != null ) - namespaces.put( scope ); + IScope scope = getContainingNamespaceScope((IBinding) t, tu); + if (scope != null) + namespaces.put(scope); ICPPClassType cls = (ICPPClassType) t; ICPPBase[] bases = cls.getBases(); - for( int i = 0; i < bases.length; i++ ){ - if( bases[i] instanceof IProblemBinding ) + for (int i = 0; i < bases.length; i++) { + if (bases[i] instanceof IProblemBinding) continue; IBinding b = bases[i].getBaseClass(); - if( b instanceof IType ) - getAssociatedScopes( (IType) b, namespaces, classes, tu); + if (b instanceof IType) + getAssociatedScopes((IType) b, namespaces, classes, tu); } } - } else if( t instanceof IEnumeration ){ - IScope scope = getContainingNamespaceScope( (IBinding) t, tu); - if(scope!=null) + } else if (t instanceof IEnumeration) { + IScope scope = getContainingNamespaceScope((IBinding) t, tu); + if (scope!=null) namespaces.put(scope); - } else if( t instanceof IFunctionType ){ + } else if (t instanceof IFunctionType) { IFunctionType ft = (IFunctionType) t; - getAssociatedScopes( getUltimateType( ft.getReturnType(), true ), namespaces, classes, tu); - IType [] ps = ft.getParameterTypes(); - for( int i = 0; i < ps.length; i++ ){ - getAssociatedScopes( getUltimateType( ps[i], true ), namespaces, classes, tu); + getAssociatedScopes(getUltimateType(ft.getReturnType(), true), namespaces, classes, tu); + IType[] ps = ft.getParameterTypes(); + for (int i = 0; i < ps.length; i++) { + getAssociatedScopes(getUltimateType(ps[i], true), namespaces, classes, tu); } - } else if( t instanceof ICPPPointerToMemberType ){ + } else if (t instanceof ICPPPointerToMemberType) { IBinding binding = ((ICPPPointerToMemberType)t).getMemberOfClass(); - if( binding instanceof IType ) - getAssociatedScopes( (IType)binding, namespaces, classes, tu); - getAssociatedScopes( getUltimateType( ((ICPPPointerToMemberType)t).getType(), true ), namespaces, classes, tu); + if (binding instanceof IType) + getAssociatedScopes((IType)binding, namespaces, classes, tu); + getAssociatedScopes(getUltimateType(((ICPPPointerToMemberType)t).getType(), true), namespaces, classes, tu); } return; } - static private ICPPNamespaceScope getContainingNamespaceScope( IBinding binding, CPPASTTranslationUnit tu) throws DOMException{ - if( binding == null ) return null; + static private ICPPNamespaceScope getContainingNamespaceScope(IBinding binding, CPPASTTranslationUnit tu) throws DOMException{ + if (binding == null) return null; IScope scope = binding.getScope(); - while( scope != null && !(scope instanceof ICPPNamespaceScope) ){ + while (scope != null && !(scope instanceof ICPPNamespaceScope)) { scope = getParentScope(scope, tu); } return (ICPPNamespaceScope) scope; } - static private ICPPScope getLookupScope( IASTName name ) throws DOMException{ + static private ICPPScope getLookupScope(IASTName name) throws DOMException{ IASTNode parent = name.getParent(); IScope scope = null; - if( parent instanceof ICPPASTBaseSpecifier ) { + if (parent instanceof ICPPASTBaseSpecifier) { ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) parent.getParent(); IASTName n = compSpec.getName(); - if( n instanceof ICPPASTQualifiedName ){ - IASTName [] ns = ((ICPPASTQualifiedName)n).getNames(); - n = ns[ ns.length - 1 ]; + if (n instanceof ICPPASTQualifiedName) { + IASTName[] ns = ((ICPPASTQualifiedName)n).getNames(); + n = ns[ns.length - 1]; } - scope = CPPVisitor.getContainingScope( n ); - } else if( parent instanceof ICPPASTConstructorChainInitializer ){ + scope = CPPVisitor.getContainingScope(n); + } else if (parent instanceof ICPPASTConstructorChainInitializer) { ICPPASTConstructorChainInitializer initializer = (ICPPASTConstructorChainInitializer) parent; IASTFunctionDeclarator dtor = (IASTFunctionDeclarator) initializer.getParent(); IBinding binding = dtor.getName().resolveBinding(); - if( !(binding instanceof IProblemBinding) ) + if (!(binding instanceof IProblemBinding)) scope = binding.getScope(); } else { - scope = CPPVisitor.getContainingScope( name ); + scope = CPPVisitor.getContainingScope(name); } - if( scope instanceof ICPPScope ) + if (scope instanceof ICPPScope) return (ICPPScope)scope; - else if( scope instanceof IProblemBinding ) - return new CPPScope.CPPScopeProblem( ((IProblemBinding)scope).getASTNode(), IProblemBinding.SEMANTIC_BAD_SCOPE, ((IProblemBinding)scope).getNameCharArray() ); - return new CPPScope.CPPScopeProblem( name, IProblemBinding.SEMANTIC_BAD_SCOPE, name.toCharArray() ); + else if (scope instanceof IProblemBinding) + return new CPPScope.CPPScopeProblem(((IProblemBinding)scope).getASTNode(), IProblemBinding.SEMANTIC_BAD_SCOPE, ((IProblemBinding)scope).getNameCharArray()); + return new CPPScope.CPPScopeProblem(name, IProblemBinding.SEMANTIC_BAD_SCOPE, name.toCharArray()); } - private static void mergeResults( LookupData data, Object results, boolean scoped ){ - if( !data.contentAssist ){ - if( results instanceof IBinding ){ - data.foundItems = ArrayUtil.append( Object.class, (Object[]) data.foundItems, results ); - } else if( results instanceof Object[] ){ - data.foundItems = ArrayUtil.addAll( Object.class, (Object[])data.foundItems, (Object[])results ); + + private static void mergeResults(LookupData data, Object results, boolean scoped) { + if (!data.contentAssist) { + if (results instanceof IBinding) { + data.foundItems = ArrayUtil.append(Object.class, (Object[]) data.foundItems, results); + } else if (results instanceof Object[]) { + data.foundItems = ArrayUtil.addAll(Object.class, (Object[])data.foundItems, (Object[])results); } } else { - data.foundItems = mergePrefixResults( (CharArrayObjectMap) data.foundItems, results, scoped ); + data.foundItems = mergePrefixResults((CharArrayObjectMap) data.foundItems, results, scoped); } } @@ -494,54 +495,56 @@ public class CPPSemantics { * @param scoped * @return */ - private static Object mergePrefixResults( CharArrayObjectMap dest, Object source, boolean scoped ){ - if( source == null ) return dest; - CharArrayObjectMap resultMap = ( dest != null ) ? dest : new CharArrayObjectMap(2); + private static Object mergePrefixResults(CharArrayObjectMap dest, Object source, boolean scoped) { + if (source == null) return dest; + CharArrayObjectMap resultMap = (dest != null) ? dest : new CharArrayObjectMap(2); CharArrayObjectMap map = null; - Object [] objs = null; - if( source instanceof CharArrayObjectMap ) + Object[] objs = null; + if (source instanceof CharArrayObjectMap) { map = (CharArrayObjectMap) source; - else{ + } else { if (source instanceof Object[]) - objs = ArrayUtil.trim( Object.class, (Object[]) source ); + objs = ArrayUtil.trim(Object.class, (Object[]) source); else objs = new Object[]{ source }; } - + int size = map != null ? map.size() : objs.length; int resultInitialSize = resultMap.size(); - for( int i = 0; i < size; i ++ ) { - char [] key = ( map != null ) ? map.keyAt(i) - : ( objs[i] instanceof IBinding) ? ((IBinding)objs[i]).getNameCharArray() - : ((IASTName)objs[i]).toCharArray(); - int idx = resultMap.lookup( key ); - if( idx == -1 ){ - resultMap.put( key, (map != null ) ? map.get( key ) : objs[i] ); - } else if( !scoped || idx >= resultInitialSize ) { - Object obj = resultMap.get( key ); - Object so = ( map != null ) ? map.get(key) : objs[i]; - if( obj instanceof Object [] ) { - if( so instanceof IBinding || so instanceof IASTName ) - obj = ArrayUtil.append( Object.class, (Object[]) obj, so ); + for (int i = 0; i < size; i ++) { + char[] key = (map != null) ? + map.keyAt(i) : + (objs[i] instanceof IBinding) ? + ((IBinding) objs[i]).getNameCharArray() : + ((IASTName) objs[i]).toCharArray(); + int idx = resultMap.lookup(key); + if (idx == -1) { + resultMap.put(key, (map != null) ? map.get(key) : objs[i]); + } else if (!scoped || idx >= resultInitialSize) { + Object obj = resultMap.get(key); + Object so = (map != null) ? map.get(key) : objs[i]; + if (obj instanceof Object[]) { + if (so instanceof IBinding || so instanceof IASTName) + obj = ArrayUtil.append(Object.class, (Object[]) obj, so); else - obj = ArrayUtil.addAll( Object.class, (Object[])obj, (Object[]) so ); + obj = ArrayUtil.addAll(Object.class, (Object[])obj, (Object[]) so); } else { - if( so instanceof IBinding || so instanceof IASTName ) - obj = new Object [] { obj, so }; + if (so instanceof IBinding || so instanceof IASTName) + obj = new Object[] { obj, so }; else { - Object [] temp = new Object [ ((Object[])so).length + 1 ]; + Object[] temp = new Object[((Object[])so).length + 1]; temp[0] = obj; - obj = ArrayUtil.addAll( Object.class, temp, (Object[]) so ); + obj = ArrayUtil.addAll(Object.class, temp, (Object[]) so); } } - resultMap.put( key, obj ); + resultMap.put(key, obj); } } return resultMap; } - static protected void lookup( LookupData data, Object start ) throws DOMException{ + static protected void lookup(LookupData data, Object start) throws DOMException{ IASTNode node = data.astName; IIndexFileSet fileSet= IIndexFileSet.EMPTY; @@ -555,55 +558,55 @@ public class CPPSemantics { } ICPPScope scope = null; - if( start instanceof ICPPScope ) + if (start instanceof ICPPScope) scope = (ICPPScope) start; - else if( start instanceof IASTName ) - scope = getLookupScope( (IASTName) start ); + else if (start instanceof IASTName) + scope = getLookupScope((IASTName) start); else return; boolean friendInLocalClass = false; - if( scope instanceof ICPPClassScope && data.forFriendship() ){ + if (scope instanceof ICPPClassScope && data.forFriendship()) { try { ICPPClassType cls = ((ICPPClassScope)scope).getClassType(); friendInLocalClass = !cls.isGloballyQualified(); - } catch ( DOMException e ){ + } catch (DOMException e) { } } - while( scope != null ){ + while (scope != null) { if (scope instanceof IIndexScope && data.tu != null) { scope= (ICPPScope) data.tu.mapToASTScope(((IIndexScope) scope)); } - IASTNode blockItem = CPPVisitor.getContainingBlockItem( node ); + IASTNode blockItem = CPPVisitor.getContainingBlockItem(node); - if( !data.usingDirectivesOnly ){ - if( ASTInternal.isFullyCached(scope) ){ + if (!data.usingDirectivesOnly) { + if (ASTInternal.isFullyCached(scope)) { if (!data.contentAssist && data.astName != null) { - IBinding binding = scope.getBinding( data.astName, true, fileSet ); - if( binding != null && - ( CPPSemantics.declaredBefore( binding, data.astName, isIndexBased ) || - (scope instanceof ICPPClassScope && data.checkWholeClassScope) ) ) + IBinding binding = scope.getBinding(data.astName, true, fileSet); + if (binding != null && + (CPPSemantics.declaredBefore(binding, data.astName, isIndexBased) || + (scope instanceof ICPPClassScope && data.checkWholeClassScope))) { - mergeResults( data, binding, true ); + mergeResults(data, binding, true); } } else if (data.astName != null) { - IBinding[] bindings = scope.getBindings( data.astName, true, data.prefixLookup, fileSet ); + IBinding[] bindings = scope.getBindings(data.astName, true, data.prefixLookup, fileSet); mergeResults(data, bindings, true); } } else if (data.astName != null) { IBinding[] b = null; if (!data.contentAssist) { - IBinding binding = scope.getBinding( data.astName, false, fileSet ); + IBinding binding = scope.getBinding(data.astName, false, fileSet); if (binding instanceof CPPImplicitFunction || binding instanceof CPPImplicitTypedef) - mergeResults( data, binding, true ); + mergeResults(data, binding, true); else if (binding != null) b = new IBinding[] { binding }; } else { - b = scope.getBindings( data.astName, false, data.prefixLookup, fileSet ); + b = scope.getBindings(data.astName, false, data.prefixLookup, fileSet); } - IASTName[] inScope = lookupInScope( data, scope, blockItem ); + IASTName[] inScope = lookupInScope(data, scope, blockItem); if (inScope != null) { if (data.contentAssist) { @@ -620,13 +623,13 @@ public class CPPSemantics { if (b != null && isFromIndex(b[0])) { mergeResults(data, b, true); } - } else if (b != null){ + } else if (b != null) { mergeResults(data, b, true); } } // store using-directives found in this block or namespace for later use. - if( (!data.hasResults() || !data.qualified() || data.contentAssist) && scope instanceof ICPPNamespaceScope ){ + if ((!data.hasResults() || !data.qualified() || data.contentAssist) && scope instanceof ICPPNamespaceScope) { final ICPPNamespaceScope blockScope= (ICPPNamespaceScope) scope; if (! (blockScope instanceof ICPPBlockScope)) { data.visited.put(blockScope); // namespace has been searched. @@ -635,11 +638,11 @@ public class CPPSemantics { } } ICPPUsingDirective[] uds= blockScope.getUsingDirectives(); - if( uds != null && uds.length > 0) { + if (uds != null && uds.length > 0) { HashSet handled= new HashSet(); - for( int i = 0; i < uds.length; i++ ){ + for (int i = 0; i < uds.length; i++) { final ICPPUsingDirective ud = uds[i]; - if( CPPSemantics.declaredBefore( ud, data.astName, false ) ){ + if (CPPSemantics.declaredBefore(ud, data.astName, false)) { storeUsingDirective(data, blockScope, ud, handled); } } @@ -648,47 +651,47 @@ public class CPPSemantics { } // lookup in nominated namespaces - if( !data.ignoreUsingDirectives && scope instanceof ICPPNamespaceScope && !(scope instanceof ICPPBlockScope)) { - if( !data.hasResults() || !data.qualified() || data.contentAssist) { + if (!data.ignoreUsingDirectives && scope instanceof ICPPNamespaceScope && !(scope instanceof ICPPBlockScope)) { + if (!data.hasResults() || !data.qualified() || data.contentAssist) { lookupInNominated(data, (ICPPNamespaceScope) scope); } } - if( (!data.contentAssist && (data.problem != null || data.hasResults())) || - ( friendInLocalClass && !(scope instanceof ICPPClassScope) ) ) + if ((!data.contentAssist && (data.problem != null || data.hasResults())) || + (friendInLocalClass && !(scope instanceof ICPPClassScope))) { return; } - if( !data.usingDirectivesOnly && scope instanceof ICPPClassScope ){ - mergeResults( data, lookupInParents( data, scope ), true ); + if (!data.usingDirectivesOnly && scope instanceof ICPPClassScope) { + mergeResults(data, lookupInParents(data, scope), true); } - if( !data.contentAssist && (data.problem != null || data.hasResults()) ) + if (!data.contentAssist && (data.problem != null || data.hasResults())) return; //if still not found, loop and check our containing scope - if( data.qualified() && !(scope instanceof ICPPTemplateScope) ) { - if( !data.usingDirectives.isEmpty() ) + if (data.qualified() && !(scope instanceof ICPPTemplateScope)) { + if (!data.usingDirectives.isEmpty()) data.usingDirectivesOnly = true; else break; } - if( blockItem != null ) + if (blockItem != null) node = blockItem; ICPPScope parentScope = (ICPPScope) getParentScope(scope, data.tu); - if( parentScope instanceof ICPPTemplateScope ){ + if (parentScope instanceof ICPPTemplateScope) { IASTNode parent = node.getParent(); - while( parent != null && !(parent instanceof ICPPASTTemplateDeclaration) ){ + while (parent != null && !(parent instanceof ICPPASTTemplateDeclaration)) { node = parent; parent = parent.getParent(); } - if( parent != null ){ + if (parent != null) { ICPPASTTemplateDeclaration templateDecl = (ICPPASTTemplateDeclaration) parent; ICPPTemplateScope templateScope = templateDecl.getScope(); - if( templateScope.getTemplateDefinition() == ((ICPPTemplateScope)parentScope).getTemplateDefinition() ){ + if (templateScope.getTemplateDefinition() == ((ICPPTemplateScope)parentScope).getTemplateDefinition()) { parentScope = templateScope; } } @@ -711,9 +714,9 @@ public class CPPSemantics { return parentScope; } - private static Object lookupInParents( LookupData data, ICPPScope lookIn ) throws DOMException{ - ICPPBase [] bases = null; - if( lookIn instanceof ICPPClassScope ){ + private static Object lookupInParents(LookupData data, ICPPScope lookIn) throws DOMException{ + ICPPBase[] bases = null; + if (lookIn instanceof ICPPClassScope) { ICPPClassType c = ((ICPPClassScope)lookIn).getClassType(); if (c != null) bases = c.getBases(); @@ -722,87 +725,87 @@ public class CPPSemantics { Object inherited = null; Object result = null; - if( bases == null || bases.length == 0 ) + if (bases == null || bases.length == 0) return null; //use data to detect circular inheritance - if( data.inheritanceChain == null ) - data.inheritanceChain = new ObjectSet( 2 ); + if (data.inheritanceChain == null) + data.inheritanceChain = new ObjectSet(2); - data.inheritanceChain.put( lookIn ); + data.inheritanceChain.put(lookIn); // workaround to fix 185828 - if(data.inheritanceChain.size() > CPPSemantics.MAX_INHERITANCE_DEPTH) { + if (data.inheritanceChain.size() > CPPSemantics.MAX_INHERITANCE_DEPTH) { return null; } int size = bases.length; - for( int i = 0; i < size; i++ ) + for (int i = 0; i < size; i++) { inherited = null; ICPPClassType cls = null; IBinding b = bases[i].getBaseClass(); - if( b instanceof ICPPClassType ) + if (b instanceof ICPPClassType) cls = (ICPPClassType) b; else continue; ICPPScope parent = (ICPPScope) cls.getCompositeScope(); - if( parent == null || parent instanceof CPPUnknownScope ) + if (parent == null || parent instanceof CPPUnknownScope) continue; - if( !bases[i].isVirtual() || !data.visited.containsKey( parent ) ){ - if( bases[i].isVirtual() ){ - data.visited.put( parent ); + if (!bases[i].isVirtual() || !data.visited.containsKey(parent)) { + if (bases[i].isVirtual()) { + data.visited.put(parent); } //if the inheritanceChain already contains the parent, then that //is circular inheritance - if( ! data.inheritanceChain.containsKey( parent ) ){ + if (! data.inheritanceChain.containsKey(parent)) { //is this name define in this scope? - if( ASTInternal.isFullyCached(parent)) { - if (data.astName != null && !data.contentAssist ) { - inherited = parent.getBinding( data.astName, true ); + if (ASTInternal.isFullyCached(parent)) { + if (data.astName != null && !data.contentAssist) { + inherited = parent.getBinding(data.astName, true); } else if (data.astName != null) { - inherited = parent.getBindings( data.astName, true, data.prefixLookup); + inherited = parent.getBindings(data.astName, true, data.prefixLookup); } } else - inherited = lookupInScope( data, parent, null ); + inherited = lookupInScope(data, parent, null); - if( inherited == null || data.contentAssist ){ - Object temp = lookupInParents( data, parent ); - if( inherited != null ){ - inherited = mergePrefixResults( null, inherited, true ); - inherited = mergePrefixResults( (CharArrayObjectMap)inherited, (CharArrayObjectMap)temp, true ); + if (inherited == null || data.contentAssist) { + Object temp = lookupInParents(data, parent); + if (inherited != null) { + inherited = mergePrefixResults(null, inherited, true); + inherited = mergePrefixResults((CharArrayObjectMap)inherited, (CharArrayObjectMap)temp, true); } else { inherited = temp; } } else { - visitVirtualBaseClasses( data, cls ); + visitVirtualBaseClasses(data, cls); } } else { - data.problem = new ProblemBinding( null, IProblemBinding.SEMANTIC_CIRCULAR_INHERITANCE, cls.getNameCharArray() ); + data.problem = new ProblemBinding(null, IProblemBinding.SEMANTIC_CIRCULAR_INHERITANCE, cls.getNameCharArray()); return null; } } - if( inherited != null ){ - if( result == null ){ + if (inherited != null) { + if (result == null) { result = inherited; - } else if( !data.contentAssist ) { - if( result instanceof Object [] ){ - Object [] r = (Object[]) result; - for( int j = 0; j < r.length && r[j] != null; j++ ) { - if( checkForAmbiguity( data, r[j], inherited ) ){ - data.problem = new ProblemBinding( data.astName, - IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name() ); + } else if (!data.contentAssist) { + if (result instanceof Object[]) { + Object[] r = (Object[]) result; + for (int j = 0; j < r.length && r[j] != null; j++) { + if (checkForAmbiguity(data, r[j], inherited)) { + data.problem = new ProblemBinding(data.astName, + IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name()); return null; } } } else { - if( checkForAmbiguity( data, result, inherited ) ){ - data.problem = new ProblemBinding( data.astName, - IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name() ); + if (checkForAmbiguity(data, result, inherited)) { + data.problem = new ProblemBinding(data.astName, + IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name()); return null; } } @@ -811,10 +814,10 @@ public class CPPSemantics { CharArrayObjectMap r = (CharArrayObjectMap) result; char[] key = null; int tempSize = temp.size(); - for( int ii = 0; ii < tempSize; ii++ ){ - key = temp.keyAt( ii ); - if( !r.containsKey( key ) ){ - r.put( key, temp.get(key) ); + for (int ii = 0; ii < tempSize; ii++) { + key = temp.keyAt(ii); + if (!r.containsKey(key)) { + r.put(key, temp.get(key)); } else { //TODO: prefixLookup ambiguity checking } @@ -823,83 +826,81 @@ public class CPPSemantics { } } - data.inheritanceChain.remove( lookIn ); + data.inheritanceChain.remove(lookIn); return result; } - public static void visitVirtualBaseClasses( LookupData data, ICPPClassType cls ) throws DOMException { - if( data.inheritanceChain == null ) + public static void visitVirtualBaseClasses(LookupData data, ICPPClassType cls) throws DOMException { + if (data.inheritanceChain == null) data.inheritanceChain = new ObjectSet(2); IScope scope = cls.getCompositeScope(); if (scope != null) - data.inheritanceChain.put( scope ); + data.inheritanceChain.put(scope); - ICPPBase [] bases = cls.getBases(); + ICPPBase[] bases = cls.getBases(); - for( int i = 0; i < bases.length; i++ ){ + for (int i = 0; i < bases.length; i++) { IBinding b = bases[i].getBaseClass(); if (b instanceof ICPPClassType) { IScope bScope = ((ICPPClassType)b).getCompositeScope(); - if( bases[i].isVirtual() ){ + if (bases[i].isVirtual()) { if (bScope != null) data.visited.put(bScope); - } else if ( bScope != null ) { - if ( !data.inheritanceChain.containsKey(bScope) ) - visitVirtualBaseClasses( data, (ICPPClassType) b ); + } else if (bScope != null) { + if (!data.inheritanceChain.containsKey(bScope)) + visitVirtualBaseClasses(data, (ICPPClassType) b); else - data.problem = new ProblemBinding( null, IProblemBinding.SEMANTIC_CIRCULAR_INHERITANCE, cls.getNameCharArray() ); + data.problem = new ProblemBinding(null, IProblemBinding.SEMANTIC_CIRCULAR_INHERITANCE, cls.getNameCharArray()); } } } if (scope != null) - data.inheritanceChain.remove( scope ); + data.inheritanceChain.remove(scope); } - private static boolean checkForAmbiguity( LookupData data, Object n, Object names ) throws DOMException{ - if( names instanceof Object[] ) { - names = ArrayUtil.trim( Object.class, (Object[]) names ); - if( ((Object[])names).length == 0 ) + private static boolean checkForAmbiguity(LookupData data, Object n, Object names) throws DOMException{ + if (names instanceof Object[]) { + names = ArrayUtil.trim(Object.class, (Object[]) names); + if (((Object[])names).length == 0) return false; } - IBinding binding = ( n instanceof IBinding) ? (IBinding)n : ((IASTName)n).resolveBinding(); - Object [] objs = ( names instanceof Object[] ) ? (Object[])names : null; - int idx = ( objs != null && objs.length > 0 ) ? 0 : -1; - Object o = ( idx != -1 ) ? objs[idx++] : names; - while( o != null ) { - IBinding b = ( o instanceof IBinding ) ? (IBinding) o : ((IASTName)o).resolveBinding(); + IBinding binding = (n instanceof IBinding) ? (IBinding)n : ((IASTName)n).resolveBinding(); + Object[] objs = (names instanceof Object[]) ? (Object[])names : null; + int idx = (objs != null && objs.length > 0) ? 0 : -1; + Object o = (idx != -1) ? objs[idx++] : names; + while (o != null) { + IBinding b = (o instanceof IBinding) ? (IBinding) o : ((IASTName)o).resolveBinding(); - if( b instanceof ICPPUsingDeclaration ){ - objs = ArrayUtil.append( Object.class, objs, ((ICPPUsingDeclaration)b).getDelegates() ); + if (b instanceof ICPPUsingDeclaration) { + objs = ArrayUtil.append(Object.class, objs, ((ICPPUsingDeclaration)b).getDelegates()); } else { - if( binding != b ) + if (binding != b) return true; boolean ok = false; //3.4.5-4 if the id-expression in a class member access is a qualified id... the result //is not required to be a unique base class... - if( binding instanceof ICPPClassType ){ + if (binding instanceof ICPPClassType) { IASTNode parent = data.astName.getParent(); - if( parent instanceof ICPPASTQualifiedName && - parent.getPropertyInParent() == IASTFieldReference.FIELD_NAME ) - { + if (parent instanceof ICPPASTQualifiedName && + parent.getPropertyInParent() == IASTFieldReference.FIELD_NAME) { ok = true; } } //it is not ambiguous if they are the same thing and it is static or an enumerator - if( binding instanceof IEnumerator || - (binding instanceof IFunction && ASTInternal.isStatic((IFunction) binding, false)) || - (binding instanceof IVariable && ((IVariable)binding).isStatic()) ) - { + if (binding instanceof IEnumerator || + (binding instanceof IFunction && ASTInternal.isStatic((IFunction) binding, false)) || + (binding instanceof IVariable && ((IVariable)binding).isStatic())) { ok = true; } - if( !ok ) + if (!ok) return true; } - if( idx > -1 && idx < objs.length ) + if (idx > -1 && idx < objs.length) o = objs[idx++]; else o = null; @@ -956,12 +957,12 @@ public class CPPSemantics { static private ICPPScope getCommonEnclosingScope(IScope s1, IScope s2, CPPASTTranslationUnit tu) throws DOMException { ObjectSet set = new ObjectSet(2); IScope parent= s1; - while( parent != null ){ - set.put( parent ); + while (parent != null) { + set.put(parent); parent= getParentScope(parent, tu); } parent= s2; - while(parent != null && !set.containsKey( parent ) ){ + while (parent != null && !set.containsKey(parent)) { parent = getParentScope(parent, tu); } return (ICPPScope) parent; @@ -975,50 +976,50 @@ public class CPPSemantics { * @return List of encountered using directives * @throws DOMException */ - public static IASTName[] lookupInScope( LookupData data, ICPPScope scope, IASTNode blockItem ) throws DOMException { - if(data == null) { + public static IASTName[] lookupInScope(LookupData data, ICPPScope scope, IASTNode blockItem) throws DOMException { + if (data == null) { data = new LookupData(); } final boolean isIndexBased= data.tu == null ? false : data.tu.getIndex() != null; Object possible = null; - IASTNode [] nodes = null; + IASTNode[] nodes = null; IASTNode parent = ASTInternal.getPhysicalNodeOfScope(scope); - IASTName [] namespaceDefs = null; + IASTName[] namespaceDefs = null; int namespaceIdx = -1; - if( data.associated.containsKey( scope ) ){ + if (data.associated.containsKey(scope)) { //we are looking in scope, remove it from the associated scopes list - data.associated.remove( scope ); + data.associated.remove(scope); } IASTName[] found = null; - if( parent instanceof IASTCompoundStatement ){ + if (parent instanceof IASTCompoundStatement) { IASTNode p = parent.getParent(); - if( p instanceof IASTFunctionDefinition ){ + if (p instanceof IASTFunctionDefinition) { ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) ((IASTFunctionDefinition)p).getDeclarator(); nodes = dtor.getParameters(); } - if( p instanceof ICPPASTCatchHandler ){ + if (p instanceof ICPPASTCatchHandler) { parent = p; - } else if( nodes == null || nodes.length == 0 ){ + } else if (nodes == null || nodes.length == 0) { IASTCompoundStatement compound = (IASTCompoundStatement) parent; nodes = compound.getStatements(); } - } else if ( parent instanceof IASTTranslationUnit ){ + } else if (parent instanceof IASTTranslationUnit) { IASTTranslationUnit translation = (IASTTranslationUnit) parent; nodes = translation.getDeclarations(); - } else if ( parent instanceof ICPPASTCompositeTypeSpecifier ){ + } else if (parent instanceof ICPPASTCompositeTypeSpecifier) { ICPPASTCompositeTypeSpecifier comp = (ICPPASTCompositeTypeSpecifier) parent; nodes = comp.getMembers(); //9-2 a class name is also inserted into the scope of the class itself IASTName n = comp.getName(); - if( nameMatches( data, n, scope) ) { - found = (IASTName[]) ArrayUtil.append( IASTName.class, found, n ); + if (nameMatches(data, n, scope)) { + found = (IASTName[]) ArrayUtil.append(IASTName.class, found, n); } - } else if ( parent instanceof ICPPASTNamespaceDefinition ){ + } else if (parent instanceof ICPPASTNamespaceDefinition) { //need binding because namespaces can be split CPPNamespace namespace = (CPPNamespace) ((ICPPASTNamespaceDefinition)parent).getName().resolveBinding(); namespaceDefs = namespace.getNamespaceDefinitions(); @@ -1027,26 +1028,26 @@ public class CPPSemantics { while (nodes.length == 0 && ++namespaceIdx < namespaceDefs.length) { nodes= ((ICPPASTNamespaceDefinition)namespaceDefs[namespaceIdx].getParent()).getDeclarations(); } - } else if( parent instanceof ICPPASTFunctionDeclarator ){ + } else if (parent instanceof ICPPASTFunctionDeclarator) { ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) parent; nodes = dtor.getParameters(); - } else if( parent instanceof ICPPASTTemplateDeclaration ){ + } else if (parent instanceof ICPPASTTemplateDeclaration) { ICPPASTTemplateDeclaration template = (ICPPASTTemplateDeclaration) parent; nodes = template.getTemplateParameters(); } int idx = -1; - boolean checkWholeClassScope = ( scope instanceof ICPPClassScope ) && data.checkWholeClassScope; - IASTNode item = ( nodes != null ? (nodes.length > 0 ? nodes[++idx] : null ) : parent ); - IASTNode [][] nodeStack = null; - int [] nodeIdxStack = null; + boolean checkWholeClassScope = (scope instanceof ICPPClassScope) && data.checkWholeClassScope; + IASTNode item = (nodes != null ? (nodes.length > 0 ? nodes[++idx] : null) : parent); + IASTNode[][] nodeStack = null; + int[] nodeIdxStack = null; int nodeStackPos = -1; - while( item != null ) { - if( item instanceof ICPPASTLinkageSpecification ){ - IASTDeclaration [] decls = ((ICPPASTLinkageSpecification)item).getDeclarations(); - if( decls != null && decls.length > 0 ){ - nodeStack = (IASTNode[][]) ArrayUtil.append( IASTNode[].class, nodeStack, nodes ); - nodeIdxStack = ArrayUtil.setInt( nodeIdxStack, ++nodeStackPos, idx ); + while (item != null) { + if (item instanceof ICPPASTLinkageSpecification) { + IASTDeclaration[] decls = ((ICPPASTLinkageSpecification)item).getDeclarations(); + if (decls != null && decls.length > 0) { + nodeStack = (IASTNode[][]) ArrayUtil.append(IASTNode[].class, nodeStack, nodes); + nodeIdxStack = ArrayUtil.setInt(nodeIdxStack, ++nodeStackPos, idx); nodes = ((ICPPASTLinkageSpecification)item).getDeclarations(); idx = 0; item = nodes[idx]; @@ -1054,45 +1055,42 @@ public class CPPSemantics { } } - if( item instanceof IASTDeclarationStatement ) + if (item instanceof IASTDeclarationStatement) item = ((IASTDeclarationStatement)item).getDeclaration(); - if( item instanceof ICPPASTUsingDirective ) { - if( scope instanceof ICPPNamespaceScope ) { + if (item instanceof ICPPASTUsingDirective) { + if (scope instanceof ICPPNamespaceScope) { final ICPPNamespaceScope nsscope = (ICPPNamespaceScope)scope; final ICPPASTUsingDirective usingDirective = (ICPPASTUsingDirective) item; nsscope.addUsingDirective(new CPPUsingDirective(usingDirective)); } } else if (item instanceof ICPPASTNamespaceDefinition && ((ICPPASTNamespaceDefinition)item).getName().toCharArray().length == 0) { - if( scope instanceof ICPPNamespaceScope ) { + if (scope instanceof ICPPNamespaceScope) { final ICPPNamespaceScope nsscope = (ICPPNamespaceScope)scope; final ICPPASTNamespaceDefinition nsdef= (ICPPASTNamespaceDefinition) item; nsscope.addUsingDirective(new CPPUsingDirective(nsdef)); } } else { //possible is IASTName or IASTName[] - possible = collectResult( data, scope, item, (item == parent) ); - if( possible != null ) { + possible = collectResult(data, scope, item, (item == parent)); + if (possible != null) { int jdx = -1; IASTName temp; - if( possible instanceof IASTName ) + if (possible instanceof IASTName) temp = (IASTName) possible; else temp = ((IASTName[])possible)[++jdx]; - while( temp != null ) { - - if( (checkWholeClassScope || declaredBefore( temp, data.astName, isIndexBased )) && - (item != blockItem || data.includeBlockItem( item )) ) - - { - if( data.considerConstructors || - !( temp.getParent() instanceof IASTDeclarator && - CPPVisitor.isConstructor( scope, (IASTDeclarator) temp.getParent() ) ) ) - { - found = (IASTName[]) ArrayUtil.append( IASTName.class, found, temp ); + + while (temp != null) { + if ((checkWholeClassScope || declaredBefore(temp, data.astName, isIndexBased)) && + (item != blockItem || data.includeBlockItem(item))) { + if (data.considerConstructors || + !(temp.getParent() instanceof IASTDeclarator && + CPPVisitor.isConstructor(scope, (IASTDeclarator) temp.getParent()))) { + found = (IASTName[]) ArrayUtil.append(IASTName.class, found, temp); } } - if( ++jdx > 0 && jdx < ((IASTName[])possible).length ) + if (++jdx > 0 && jdx < ((IASTName[])possible).length) temp = ((IASTName[])possible)[jdx]; else temp = null; @@ -1100,46 +1098,46 @@ public class CPPSemantics { } } - if( idx > -1 && ++idx < nodes.length ){ + if (idx > -1 && ++idx < nodes.length) { item = nodes[idx]; } else { item = null; - while( item == null ){ - if( namespaceIdx > -1 ) { + while (item == null) { + if (namespaceIdx > -1) { //check all definitions of this namespace - while( namespaceIdx > -1 && namespaceDefs.length > ++namespaceIdx ){ + while (namespaceIdx > -1 && namespaceDefs.length > ++namespaceIdx) { nodes = ((ICPPASTNamespaceDefinition)namespaceDefs[namespaceIdx].getParent()).getDeclarations(); - if( nodes.length > 0 ){ + if (nodes.length > 0) { idx = 0; item = nodes[0]; break; } } - } else if( parent instanceof IASTCompoundStatement && nodes instanceof IASTParameterDeclaration [] ){ + } else if (parent instanceof IASTCompoundStatement && nodes instanceof IASTParameterDeclaration[]) { //function body, we were looking at parameters, now check the body itself IASTCompoundStatement compound = (IASTCompoundStatement) parent; nodes = compound.getStatements(); - if( nodes.length > 0 ){ + if (nodes.length > 0) { idx = 0; item = nodes[0]; break; } - } else if( parent instanceof ICPPASTCatchHandler ){ + } else if (parent instanceof ICPPASTCatchHandler) { parent = ((ICPPASTCatchHandler)parent).getCatchBody(); - if( parent instanceof IASTCompoundStatement ){ + if (parent instanceof IASTCompoundStatement) { nodes = ((IASTCompoundStatement)parent).getStatements(); } - if( nodes.length > 0 ){ + if (nodes.length > 0) { idx = 0; item = nodes[0]; break; } } - if( item == null && nodeStackPos >= 0 ){ + if (item == null && nodeStackPos >= 0) { nodes = nodeStack[nodeStackPos]; nodeStack[nodeStackPos] = null; idx = nodeIdxStack[nodeStackPos--]; - if( ++idx >= nodes.length ) + if (++idx >= nodes.length) continue; item = nodes[idx]; @@ -1173,13 +1171,13 @@ public class CPPSemantics { if (ASTInternal.isFullyCached(nominated)) { IBinding[] bindings= nominated.getBindings(data.astName, true, data.prefixLookup); if (bindings != null && bindings.length > 0) { - mergeResults( data, bindings, true ); + mergeResults(data, bindings, true); found = true; } } else { - IASTName [] f = lookupInScope( data, nominated, null ); - if( f != null ) { - mergeResults( data, f, true ); + IASTName[] f = lookupInScope(data, nominated, null); + if (f != null) { + mergeResults(data, f, true); found = true; } } @@ -1203,82 +1201,82 @@ public class CPPSemantics { } } - static private Object collectResult( LookupData data, ICPPScope scope, IASTNode node, boolean checkAux ) throws DOMException{ + static private Object collectResult(LookupData data, ICPPScope scope, IASTNode node, boolean checkAux) throws DOMException{ IASTName resultName = null; - IASTName [] resultArray = null; + IASTName[] resultArray = null; IASTDeclaration declaration = null; - if( node instanceof ICPPASTTemplateDeclaration ) + if (node instanceof ICPPASTTemplateDeclaration) declaration = ((ICPPASTTemplateDeclaration)node).getDeclaration(); - else if( node instanceof IASTDeclaration ) + else if (node instanceof IASTDeclaration) declaration = (IASTDeclaration) node; - else if( node instanceof IASTDeclarationStatement ) + else if (node instanceof IASTDeclarationStatement) declaration = ((IASTDeclarationStatement)node).getDeclaration(); - else if( node instanceof ICPPASTCatchHandler ) + else if (node instanceof ICPPASTCatchHandler) declaration = ((ICPPASTCatchHandler)node).getDeclaration(); - else if( node instanceof ICPPASTForStatement && checkAux ) + else if (node instanceof ICPPASTForStatement && checkAux) { ICPPASTForStatement forStatement = (ICPPASTForStatement) node; - if( forStatement.getConditionDeclaration() == null ){ - if( forStatement.getInitializerStatement() instanceof IASTDeclarationStatement ) + if (forStatement.getConditionDeclaration() == null) { + if (forStatement.getInitializerStatement() instanceof IASTDeclarationStatement) declaration = ((IASTDeclarationStatement)forStatement.getInitializerStatement()).getDeclaration(); } else { - if( forStatement.getInitializerStatement() instanceof IASTDeclarationStatement ){ - Object o = collectResult( data, scope, forStatement.getInitializerStatement(), checkAux ); - if( o instanceof IASTName ) + if (forStatement.getInitializerStatement() instanceof IASTDeclarationStatement) { + Object o = collectResult(data, scope, forStatement.getInitializerStatement(), checkAux); + if (o instanceof IASTName) resultName = (IASTName) o; - else if( o instanceof IASTName[] ) + else if (o instanceof IASTName[]) resultArray = (IASTName[]) o; } declaration = forStatement.getConditionDeclaration(); } - } else if( node instanceof ICPPASTSwitchStatement ){ + } else if (node instanceof ICPPASTSwitchStatement) { declaration = ((ICPPASTSwitchStatement)node).getControllerDeclaration(); - } else if( node instanceof ICPPASTIfStatement ) { + } else if (node instanceof ICPPASTIfStatement) { declaration = ((ICPPASTIfStatement)node).getConditionDeclaration(); - } else if( node instanceof ICPPASTWhileStatement ){ + } else if (node instanceof ICPPASTWhileStatement) { declaration = ((ICPPASTWhileStatement)node).getConditionDeclaration(); - } else if( node instanceof IASTParameterDeclaration ){ + } else if (node instanceof IASTParameterDeclaration) { IASTParameterDeclaration parameterDeclaration = (IASTParameterDeclaration) node; IASTDeclarator dtor = parameterDeclaration.getDeclarator(); if (dtor != null) { // could be null when content assist in the declSpec - while( dtor.getNestedDeclarator() != null ) + while (dtor.getNestedDeclarator() != null) dtor = dtor.getNestedDeclarator(); IASTName declName = dtor.getName(); - ASTInternal.addName( scope, declName ); - if( !data.typesOnly && nameMatches( data, declName, scope ) ) { + ASTInternal.addName(scope, declName); + if (!data.typesOnly && nameMatches(data, declName, scope)) { return declName; } } - } else if( node instanceof ICPPASTTemplateParameter ){ - IASTName name = CPPTemplates.getTemplateParameterName( (ICPPASTTemplateParameter) node ); - ASTInternal.addName( scope, name ); - if( nameMatches( data, name, scope ) ) { + } else if (node instanceof ICPPASTTemplateParameter) { + IASTName name = CPPTemplates.getTemplateParameterName((ICPPASTTemplateParameter) node); + ASTInternal.addName(scope, name); + if (nameMatches(data, name, scope)) { return name; } } - if( declaration == null ) + if (declaration == null) return null; - if( declaration instanceof IASTSimpleDeclaration ){ + if (declaration instanceof IASTSimpleDeclaration) { IASTSimpleDeclaration simpleDeclaration = (IASTSimpleDeclaration) declaration; ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) simpleDeclaration.getDeclSpecifier(); - IASTDeclarator [] declarators = simpleDeclaration.getDeclarators(); - if( !declSpec.isFriend() ) { - for( int i = 0; i < declarators.length; i++ ){ + IASTDeclarator[] declarators = simpleDeclaration.getDeclarators(); + if (!declSpec.isFriend()) { + for (int i = 0; i < declarators.length; i++) { IASTDeclarator declarator = declarators[i]; - while( declarator.getNestedDeclarator() != null ) + while (declarator.getNestedDeclarator() != null) declarator = declarator.getNestedDeclarator(); IASTName declaratorName = declarator.getName(); - ASTInternal.addName( scope, declaratorName ); - if( !data.typesOnly || simpleDeclaration.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef ) { - if( nameMatches( data, declaratorName, scope ) ) { - if( resultName == null ) + ASTInternal.addName(scope, declaratorName); + if (!data.typesOnly || simpleDeclaration.getDeclSpecifier().getStorageClass() == IASTDeclSpecifier.sc_typedef) { + if (nameMatches(data, declaratorName, scope)) { + if (resultName == null) resultName = declaratorName; - else if( resultArray == null ) + else if (resultArray == null) resultArray = new IASTName[] { resultName, declaratorName }; else - resultArray = (IASTName[]) ArrayUtil.append( IASTName.class, resultArray, declaratorName ); + resultArray = (IASTName[]) ArrayUtil.append(IASTName.class, resultArray, declaratorName); } } } @@ -1287,118 +1285,118 @@ public class CPPSemantics { //decl spec IASTName specName = null; - if( declarators.length == 0 && declSpec instanceof IASTElaboratedTypeSpecifier ){ + if (declarators.length == 0 && declSpec instanceof IASTElaboratedTypeSpecifier) { specName = ((IASTElaboratedTypeSpecifier)declSpec).getName(); - } else if( declSpec instanceof ICPPASTCompositeTypeSpecifier ){ + } else if (declSpec instanceof ICPPASTCompositeTypeSpecifier) { ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) declSpec; specName = compSpec.getName(); //anonymous union? //GCC supports anonymous structs too - if( declarators.length == 0 && /*compSpec.getKey() == IASTCompositeTypeSpecifier.k_union &&*/ - specName.toCharArray().length == 0 ) + if (declarators.length == 0 && /*compSpec.getKey() == IASTCompositeTypeSpecifier.k_union &&*/ + specName.toCharArray().length == 0) { Object o = null; - IASTDeclaration [] decls = compSpec.getMembers(); - for ( int i = 0; i < decls.length; i++ ) { - o = collectResult( data, scope, decls[i], checkAux ); - if( o instanceof IASTName ){ - if( resultName == null ) + IASTDeclaration[] decls = compSpec.getMembers(); + for (int i = 0; i < decls.length; i++) { + o = collectResult(data, scope, decls[i], checkAux); + if (o instanceof IASTName) { + if (resultName == null) resultName = (IASTName) o; - else if( resultArray == null ) + else if (resultArray == null) resultArray = new IASTName[] { resultName, (IASTName) o }; else - resultArray = (IASTName[]) ArrayUtil.append( IASTName.class, resultArray, o ); - } else if( o instanceof IASTName [] ){ - IASTName [] oa = (IASTName[]) o; - if( resultName == null ){ + resultArray = (IASTName[]) ArrayUtil.append(IASTName.class, resultArray, o); + } else if (o instanceof IASTName[]) { + IASTName[] oa = (IASTName[]) o; + if (resultName == null) { resultName = oa[0]; resultArray = oa; - } else if( resultArray == null ){ - resultArray = new IASTName[ 1 + oa.length ]; + } else if (resultArray == null) { + resultArray = new IASTName[1 + oa.length]; resultArray[0] = resultName; - resultArray = (IASTName[]) ArrayUtil.addAll( IASTName.class, resultArray, oa ); + resultArray = (IASTName[]) ArrayUtil.addAll(IASTName.class, resultArray, oa); } else { - resultArray = (IASTName[]) ArrayUtil.addAll( IASTName.class, resultArray, oa ); + resultArray = (IASTName[]) ArrayUtil.addAll(IASTName.class, resultArray, oa); } } } } - } else if( declSpec instanceof IASTEnumerationSpecifier ){ + } else if (declSpec instanceof IASTEnumerationSpecifier) { IASTEnumerationSpecifier enumeration = (IASTEnumerationSpecifier) declSpec; specName = enumeration.getName(); //check enumerators too - IASTEnumerator [] list = enumeration.getEnumerators(); + IASTEnumerator[] list = enumeration.getEnumerators(); IASTName tempName; - for( int i = 0; i < list.length; i++ ) { + for (int i = 0; i < list.length; i++) { IASTEnumerator enumerator = list[i]; - if( enumerator == null ) break; + if (enumerator == null) break; tempName = enumerator.getName(); - ASTInternal.addName( scope, tempName ); - if( !data.typesOnly && nameMatches( data, tempName, scope ) ) { - if( resultName == null ) + ASTInternal.addName(scope, tempName); + if (!data.typesOnly && nameMatches(data, tempName, scope)) { + if (resultName == null) resultName = tempName; - else if( resultArray == null ) + else if (resultArray == null) resultArray = new IASTName[] { resultName, tempName }; else - resultArray = (IASTName[]) ArrayUtil.append( IASTName.class, resultArray, tempName ); + resultArray = (IASTName[]) ArrayUtil.append(IASTName.class, resultArray, tempName); } } } - if( specName != null ) { - ASTInternal.addName( scope, specName ); - if( nameMatches( data, specName, scope ) ) { - if( resultName == null ) + if (specName != null) { + ASTInternal.addName(scope, specName); + if (nameMatches(data, specName, scope)) { + if (resultName == null) resultName = specName; - else if( resultArray == null ) + else if (resultArray == null) resultArray = new IASTName[] { resultName, specName }; else - resultArray = (IASTName[]) ArrayUtil.append( IASTName.class, resultArray, specName ); + resultArray = (IASTName[]) ArrayUtil.append(IASTName.class, resultArray, specName); } } - } else if( declaration instanceof ICPPASTUsingDeclaration ){ + } else if (declaration instanceof ICPPASTUsingDeclaration) { ICPPASTUsingDeclaration using = (ICPPASTUsingDeclaration) declaration; IASTName name = using.getName(); - if( name instanceof ICPPASTQualifiedName ){ - IASTName [] ns = ((ICPPASTQualifiedName)name).getNames(); - name = ns[ ns.length - 1 ]; + if (name instanceof ICPPASTQualifiedName) { + IASTName[] ns = ((ICPPASTQualifiedName)name).getNames(); + name = ns[ns.length - 1]; } - ASTInternal.addName( scope, name ); - if( nameMatches( data, name, scope ) ) { + ASTInternal.addName(scope, name); + if (nameMatches(data, name, scope)) { return name; } - } else if( declaration instanceof ICPPASTNamespaceDefinition ){ + } else if (declaration instanceof ICPPASTNamespaceDefinition) { IASTName namespaceName = ((ICPPASTNamespaceDefinition) declaration).getName(); - ASTInternal.addName( scope, namespaceName ); - if( nameMatches( data, namespaceName, scope ) ) + ASTInternal.addName(scope, namespaceName); + if (nameMatches(data, namespaceName, scope)) return namespaceName; - } else if( declaration instanceof ICPPASTNamespaceAlias ){ + } else if (declaration instanceof ICPPASTNamespaceAlias) { IASTName alias = ((ICPPASTNamespaceAlias) declaration).getAlias(); - ASTInternal.addName( scope, alias ); - if( nameMatches( data, alias, scope ) ) + ASTInternal.addName(scope, alias); + if (nameMatches(data, alias, scope)) return alias; - } else if( declaration instanceof IASTFunctionDefinition ){ + } else if (declaration instanceof IASTFunctionDefinition) { IASTFunctionDefinition functionDef = (IASTFunctionDefinition) declaration; - if( ! ((ICPPASTDeclSpecifier) functionDef.getDeclSpecifier()).isFriend() ){ + if (! ((ICPPASTDeclSpecifier) functionDef.getDeclSpecifier()).isFriend()) { IASTFunctionDeclarator declarator = functionDef.getDeclarator(); //check the function itself IASTName declName = declarator.getName(); - ASTInternal.addName( scope, declName ); + ASTInternal.addName(scope, declName); - if( !data.typesOnly && nameMatches( data, declName, scope ) ) { + if (!data.typesOnly && nameMatches(data, declName, scope)) { return declName; } } } - if( resultArray != null ) + if (resultArray != null) return resultArray; return resultName; } - private static final boolean nameMatches( LookupData data, IASTName potential, IScope scope) throws DOMException{ - if( potential instanceof ICPPASTQualifiedName ){ + private static final boolean nameMatches(LookupData data, IASTName potential, IScope scope) throws DOMException{ + if (potential instanceof ICPPASTQualifiedName) { IASTNode phn= ASTInternal.getPhysicalNodeOfScope(scope); if (phn instanceof ICPPASTCompositeTypeSpecifier == false && phn instanceof ICPPASTNamespaceDefinition == false) return false; @@ -1413,67 +1411,67 @@ public class CPPSemantics { potential= qn[qn.length-1]; } char[] c = potential.toCharArray(); - char [] n = data.name(); + char[] n = data.name(); return (data.prefixLookup && CharArrayUtils.equals(c, 0, n.length, n, true)) || (!data.prefixLookup && CharArrayUtils.equals(c, n)); } - private static void addDefinition( IBinding binding, IASTName name ){ - if( binding instanceof IFunction ){ + private static void addDefinition(IBinding binding, IASTName name) { + if (binding instanceof IFunction) { IASTNode node = name.getParent(); - if( node instanceof ICPPASTQualifiedName ) + if (node instanceof ICPPASTQualifiedName) node = node.getParent(); - if( node instanceof ICPPASTFunctionDeclarator && node.getParent() instanceof IASTFunctionDefinition ){ - if( binding instanceof ICPPInternalBinding ) - ((ICPPInternalBinding)binding).addDefinition( node ); + if (node instanceof ICPPASTFunctionDeclarator && node.getParent() instanceof IASTFunctionDefinition) { + if (binding instanceof ICPPInternalBinding) + ((ICPPInternalBinding)binding).addDefinition(node); } } } - public static IBinding resolveAmbiguities( IASTName name, Object[] bindings ){ - bindings = ArrayUtil.trim( Object.class, bindings ); - if( bindings == null || bindings.length == 0 ) + public static IBinding resolveAmbiguities(IASTName name, Object[] bindings) { + bindings = ArrayUtil.trim(Object.class, bindings); + if (bindings == null || bindings.length == 0) return null; - else if( bindings.length == 1 ){ - if( bindings[0] instanceof IBinding ) + else if (bindings.length == 1) { + if (bindings[0] instanceof IBinding) return (IBinding) bindings[0]; - else if( bindings[0] instanceof IASTName && ((IASTName) bindings[0]).getBinding() != null ) - return ((IASTName) bindings[ 0 ]).getBinding(); + else if (bindings[0] instanceof IASTName && ((IASTName) bindings[0]).getBinding() != null) + return ((IASTName) bindings[0]).getBinding(); } - if( name.getPropertyInParent() != STRING_LOOKUP_PROPERTY ) { - LookupData data = createLookupData( name, false ); + if (name.getPropertyInParent() != STRING_LOOKUP_PROPERTY) { + LookupData data = createLookupData(name, false); data.foundItems = bindings; try { - return resolveAmbiguities( data, name ); - } catch ( DOMException e ) { + return resolveAmbiguities(data, name); + } catch (DOMException e) { return e.getProblem(); } } - IBinding [] result = null; - for ( int i = 0; i < bindings.length; i++ ) { - if( bindings[i] instanceof IASTName ) - result = (IBinding[]) ArrayUtil.append( IBinding.class, result, ((IASTName)bindings[i]).resolveBinding() ); - else if( bindings[i] instanceof IBinding ) - result = (IBinding[]) ArrayUtil.append( IBinding.class, result, bindings[i] ); + IBinding[] result = null; + for (int i = 0; i < bindings.length; i++) { + if (bindings[i] instanceof IASTName) + result = (IBinding[]) ArrayUtil.append(IBinding.class, result, ((IASTName)bindings[i]).resolveBinding()); + else if (bindings[i] instanceof IBinding) + result = (IBinding[]) ArrayUtil.append(IBinding.class, result, bindings[i]); } - return new CPPCompositeBinding( result ); + return new CPPCompositeBinding(result); } - static public boolean declaredBefore( Object obj, IASTNode node, boolean indexBased ){ - if( node == null ) return true; - if( node.getPropertyInParent() == STRING_LOOKUP_PROPERTY ) return true; + static public boolean declaredBefore(Object obj, IASTNode node, boolean indexBased) { + if (node == null) return true; + if (node.getPropertyInParent() == STRING_LOOKUP_PROPERTY) return true; final int pointOfRef= ((ASTNode) node).getOffset(); ASTNode nd = null; - if( obj instanceof ICPPSpecialization ){ + if (obj instanceof ICPPSpecialization) { obj = ((ICPPSpecialization)obj).getSpecializedBinding(); } int pointOfDecl= -1; - if( obj instanceof ICPPInternalBinding ){ + if (obj instanceof ICPPInternalBinding) { ICPPInternalBinding cpp = (ICPPInternalBinding) obj; // for bindings in global or namespace scope we don't know whether there is a // previous declaration in one of the skipped header files. For bindings that @@ -1491,58 +1489,58 @@ public class CPPSemantics { } } IASTNode[] n = cpp.getDeclarations(); - if( n != null && n.length > 0 ) { + if (n != null && n.length > 0) { nd = (ASTNode) n[0]; } ASTNode def = (ASTNode) cpp.getDefinition(); - if( def != null ){ - if( nd == null || def.getOffset() < nd.getOffset() ) + if (def != null) { + if (nd == null || def.getOffset() < nd.getOffset()) nd = def; } - if( nd == null ) + if (nd == null) return true; - } else if( obj instanceof ASTNode ){ + } else if (obj instanceof ASTNode) { nd = (ASTNode) obj; - } else if( obj instanceof ICPPUsingDirective) { + } else if (obj instanceof ICPPUsingDirective) { pointOfDecl= ((ICPPUsingDirective) obj).getPointOfDeclaration(); } - if( pointOfDecl < 0 && nd != null ){ + if (pointOfDecl < 0 && nd != null) { ASTNodeProperty prop = nd.getPropertyInParent(); //point of declaration for a name is immediately after its complete declarator and before its initializer - if( prop == IASTDeclarator.DECLARATOR_NAME || nd instanceof IASTDeclarator ){ + if (prop == IASTDeclarator.DECLARATOR_NAME || nd instanceof IASTDeclarator) { IASTDeclarator dtor = (IASTDeclarator)((nd instanceof IASTDeclarator) ? nd : nd.getParent()); - while( dtor.getParent() instanceof IASTDeclarator ) + while (dtor.getParent() instanceof IASTDeclarator) dtor = (IASTDeclarator) dtor.getParent(); IASTInitializer init = dtor.getInitializer(); - if( init != null ) + if (init != null) pointOfDecl = ((ASTNode)init).getOffset() - 1; else pointOfDecl = ((ASTNode)dtor).getOffset() + ((ASTNode)dtor).getLength(); } //point of declaration for an enumerator is immediately after it enumerator-definition - else if( prop == IASTEnumerator.ENUMERATOR_NAME) { + else if (prop == IASTEnumerator.ENUMERATOR_NAME) { IASTEnumerator enumtor = (IASTEnumerator) nd.getParent(); - if( enumtor.getValue() != null ){ + if (enumtor.getValue() != null) { ASTNode exp = (ASTNode) enumtor.getValue(); pointOfDecl = exp.getOffset() + exp.getLength(); } else { pointOfDecl = nd.getOffset() + nd.getLength(); } - } else if( prop == ICPPASTUsingDeclaration.NAME ){ + } else if (prop == ICPPASTUsingDeclaration.NAME) { nd = (ASTNode) nd.getParent(); pointOfDecl = nd.getOffset(); - } else if( prop == ICPPASTNamespaceAlias.ALIAS_NAME ){ + } else if (prop == ICPPASTNamespaceAlias.ALIAS_NAME) { nd = (ASTNode) nd.getParent(); pointOfDecl = nd.getOffset() + nd.getLength(); } else pointOfDecl = nd.getOffset() + nd.getLength(); } - return ( pointOfDecl < pointOfRef ); + return (pointOfDecl < pointOfRef); } - static private IBinding resolveAmbiguities( LookupData data, IASTName name ) throws DOMException { - if( !data.hasResults() || data.contentAssist ) + static private IBinding resolveAmbiguities(LookupData data, IASTName name) throws DOMException { + if (!data.hasResults() || data.contentAssist) return null; final boolean indexBased= data.tu == null ? false : data.tu.getIndex() != null; @@ -1553,12 +1551,12 @@ public class CPPSemantics { IBinding temp = null; boolean fnsFromAST= false; - Object [] items = (Object[]) data.foundItems; - for( int i = 0; i < items.length && items[i] != null; i++ ){ + Object[] items = (Object[]) data.foundItems; + for (int i = 0; i < items.length && items[i] != null; i++) { Object o = items[i]; - boolean declaredBefore = declaredBefore( o, name, indexBased ); + boolean declaredBefore = declaredBefore(o, name, indexBased); boolean checkResolvedNamesOnly= false; - if( !data.checkWholeClassScope && !declaredBefore) { + if (!data.checkWholeClassScope && !declaredBefore) { if (!name.isReference()) { checkResolvedNamesOnly= true; declaredBefore= true; @@ -1566,36 +1564,36 @@ public class CPPSemantics { else continue; } - if( o instanceof IASTName ){ + if (o instanceof IASTName) { IASTName on= (IASTName) o; temp = checkResolvedNamesOnly ? on.getBinding() : on.resolveBinding(); - if( temp == null ) + if (temp == null) continue; - } else if( o instanceof IBinding ){ + } else if (o instanceof IBinding) { temp = (IBinding) o; } else continue; - if( !( temp instanceof ICPPMember ) && !declaredBefore ) + if (!(temp instanceof ICPPMember) && !declaredBefore) continue; - if( temp instanceof ICPPUsingDeclaration ){ - IBinding [] bindings = ((ICPPUsingDeclaration) temp).getDelegates(); - mergeResults( data, bindings, false ); + if (temp instanceof ICPPUsingDeclaration) { + IBinding[] bindings = ((ICPPUsingDeclaration) temp).getDelegates(); + mergeResults(data, bindings, false); items = (Object[]) data.foundItems; continue; - } else if( temp instanceof CPPCompositeBinding ){ - IBinding [] bindings = ((CPPCompositeBinding)temp).getBindings(); - mergeResults( data, bindings, false ); + } else if (temp instanceof CPPCompositeBinding) { + IBinding[] bindings = ((CPPCompositeBinding)temp).getBindings(); + mergeResults(data, bindings, false); items = (Object[]) data.foundItems; continue; - } else if( temp instanceof IFunction ){ + } else if (temp instanceof IFunction) { IFunction function= (IFunction) temp; - if( function instanceof ICPPFunctionTemplate ){ - if( templateFns == ObjectSet.EMPTY_SET ) + if (function instanceof ICPPFunctionTemplate) { + if (templateFns == ObjectSet.EMPTY_SET) templateFns = new ObjectSet(2); templateFns.put(function); } else { - if( fns == ObjectSet.EMPTY_SET ) + if (fns == ObjectSet.EMPTY_SET) fns = new ObjectSet(2); if (isFromIndex(function)) { // accept bindings from index only, in case we have none in the AST @@ -1608,23 +1606,23 @@ public class CPPSemantics { fns.clear(); fnsFromAST= true; } - fns.put( function ); + fns.put(function); } } - } else if( temp instanceof IType ){ - if( type == null ){ + } else if (temp instanceof IType) { + if (type == null) { type = temp; - } else if( type instanceof ICPPClassTemplate && temp instanceof ICPPSpecialization && + } else if (type instanceof ICPPClassTemplate && temp instanceof ICPPSpecialization && ((IType) type).isSameType((IType) ((ICPPSpecialization)temp).getSpecializedBinding())) { //ok, stay with the template, the specialization, if applicable, will come out during instantiation - } else if( type != temp && !((IType)type).isSameType( (IType) temp )) { - return new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name() ); + } else if (type != temp && !((IType)type).isSameType((IType) temp)) { + return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name()); } } else { - if( obj == null) + if (obj == null) obj = temp; - else if ( obj == temp ) { + else if (obj == temp) { //ok, delegates are synonyms } else { @@ -1637,52 +1635,52 @@ public class CPPSemantics { obj= temp; } else - return new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name() ); + return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name()); } } } - if( data.forUsingDeclaration() ){ - IBinding [] bindings = null; - if( obj != null ){ - if( fns.size() > 0 ) return new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name() ); - // if( type == null ) return obj; - bindings = (IBinding[]) ArrayUtil.append( IBinding.class, bindings, obj ); - bindings = (IBinding[]) ArrayUtil.append( IBinding.class, bindings, type ); + if (data.forUsingDeclaration()) { + IBinding[] bindings = null; + if (obj != null) { + if (fns.size() > 0) return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name()); + // if (type == null) return obj; + bindings = (IBinding[]) ArrayUtil.append(IBinding.class, bindings, obj); + bindings = (IBinding[]) ArrayUtil.append(IBinding.class, bindings, type); } else { -// if( fns == null ) return type; - bindings = (IBinding[]) ArrayUtil.append( IBinding.class, bindings, type ); - bindings = (IBinding[]) ArrayUtil.addAll( IBinding.class, bindings, fns.keyArray() ); +// if (fns == null) return type; + bindings = (IBinding[]) ArrayUtil.append(IBinding.class, bindings, type); + bindings = (IBinding[]) ArrayUtil.addAll(IBinding.class, bindings, fns.keyArray()); } - bindings = (IBinding[]) ArrayUtil.trim( IBinding.class, bindings ); - ICPPUsingDeclaration composite = new CPPUsingDeclaration( data.astName, bindings ); + bindings = (IBinding[]) ArrayUtil.trim(IBinding.class, bindings); + ICPPUsingDeclaration composite = new CPPUsingDeclaration(data.astName, bindings); return composite; } int numTemplateFns = templateFns.size(); - if( numTemplateFns > 0 ){ - if( data.functionParameters != null && !data.forDefinition() ){ - IFunction [] fs = CPPTemplates.selectTemplateFunctions( templateFns, data.functionParameters, data.astName ); - if( fs != null && fs.length > 0){ - if( fns == ObjectSet.EMPTY_SET ) - fns = new ObjectSet( fs.length ); - fns.addAll( fs ); + if (numTemplateFns > 0) { + if (data.functionParameters != null && !data.forDefinition()) { + IFunction[] fs = CPPTemplates.selectTemplateFunctions(templateFns, data.functionParameters, data.astName); + if (fs != null && fs.length > 0) { + if (fns == ObjectSet.EMPTY_SET) + fns = new ObjectSet(fs.length); + fns.addAll(fs); } } else { - if( fns == ObjectSet.EMPTY_SET ) + if (fns == ObjectSet.EMPTY_SET) fns = templateFns; else - fns.addAll( templateFns ); + fns.addAll(templateFns); } } int numFns = fns.size(); - if( type != null ) { - if( data.typesOnly || (obj == null && numFns == 0 ) ) + if (type != null) { + if (data.typesOnly || (obj == null && numFns == 0)) return type; } - if( numFns > 0 ){ - if( obj != null ) - return new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name() ); + if (numFns > 0) { + if (obj != null) + return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name()); return resolveFunction(data, fns.keyArray(IFunction.class)); } @@ -1699,31 +1697,31 @@ public class CPPSemantics { return false; } - static private boolean functionHasParameters( IFunction function, IASTParameterDeclaration [] params ) throws DOMException{ + static private boolean functionHasParameters(IFunction function, IASTParameterDeclaration[] params) throws DOMException{ IFunctionType ftype = function.getType(); - if( params.length == 0 ){ + if (params.length == 0) { return ftype.getParameterTypes().length == 0; } IASTNode node = params[0].getParent(); - if( node instanceof ICPPASTFunctionDeclarator ){ - return isSameFunction( function, (IASTDeclarator) node ); + if (node instanceof ICPPASTFunctionDeclarator) { + return isSameFunction(function, (IASTDeclarator) node); } return false; } - static private void reduceToViable( LookupData data, IBinding[] functions ) throws DOMException{ - if( functions == null || functions.length == 0 ) + static private void reduceToViable(LookupData data, IBinding[] functions) throws DOMException{ + if (functions == null || functions.length == 0) return; - Object [] fParams = data.functionParameters; - int numParameters = ( fParams != null ) ? fParams.length : 0; + Object[] fParams = data.functionParameters; + int numParameters = (fParams != null) ? fParams.length : 0; int num; boolean def = data.forDefinition(); //Trim the list down to the set of viable functions IFunction function = null; int size = functions.length; - for( int i = 0; i < size && functions[i] != null; i++ ){ + for (int i = 0; i < size && functions[i] != null; i++) { function = (IFunction) functions[i]; if (function instanceof IProblemBinding) { functions[i]= null; @@ -1733,21 +1731,21 @@ public class CPPSemantics { //if there are m arguments in the list, all candidate functions having m parameters //are viable - if( num == numParameters ){ - if( def && !isMatchingFunctionDeclaration( function, data ) ){ + if (num == numParameters) { + if (def && !isMatchingFunctionDeclaration(function, data)) { functions[i] = null; } continue; } //check for void - else if( numParameters == 0 && num == 1 ){ + else if (numParameters == 0 && num == 1) { IParameter param = function.getParameters()[0]; IType t = param.getType(); - if( t instanceof IBasicType && ((IBasicType)t).getType() == IBasicType.t_void ) + if (t instanceof IBasicType && ((IBasicType)t).getType() == IBasicType.t_void) continue; } - if( def ){ + if (def) { //if this is for a definition, we had to match the number of parameters. functions[i] = null; continue; @@ -1755,8 +1753,8 @@ public class CPPSemantics { //A candidate function having fewer than m parameters is viable only if it has an //ellipsis in its parameter list. - if( num < numParameters ){ - if( function.takesVarArgs() ) + if (num < numParameters) { + if (function.takesVarArgs()) continue; //not enough parameters, remove it functions[i] = null; @@ -1764,9 +1762,9 @@ public class CPPSemantics { //a candidate function having more than m parameters is viable only if the (m+1)-st //parameter has a default argument else { - IParameter [] params = function.getParameters(); - for( int j = num - 1; j >= numParameters; j-- ){ - if( !((ICPPParameter)params[j]).hasDefaultValue()){ + IParameter[] params = function.getParameters(); + for (int j = num - 1; j >= numParameters; j--) { + if (!((ICPPParameter)params[j]).hasDefaultValue()) { functions[i] = null; break; } @@ -1774,116 +1772,116 @@ public class CPPSemantics { } } } - static private boolean isMatchingFunctionDeclaration( IFunction candidate, LookupData data ){ + static private boolean isMatchingFunctionDeclaration(IFunction candidate, LookupData data) { IASTName name = data.astName; - ICPPASTTemplateDeclaration decl = CPPTemplates.getTemplateDeclaration( name ); - if( decl != null && !(candidate instanceof ICPPTemplateDefinition) ) + ICPPASTTemplateDeclaration decl = CPPTemplates.getTemplateDeclaration(name); + if (decl != null && !(candidate instanceof ICPPTemplateDefinition)) return false; - if( candidate instanceof ICPPTemplateDefinition && decl instanceof ICPPASTTemplateSpecialization ){ - ICPPFunctionTemplate fn = CPPTemplates.resolveTemplateFunctions( new Object [] { candidate }, data.astName ); - return ( fn != null && !(fn instanceof IProblemBinding ) ); + if (candidate instanceof ICPPTemplateDefinition && decl instanceof ICPPASTTemplateSpecialization) { + ICPPFunctionTemplate fn = CPPTemplates.resolveTemplateFunctions(new Object[] { candidate }, data.astName); + return (fn != null && !(fn instanceof IProblemBinding)); } try { IASTNode node = data.astName.getParent(); - while( node instanceof IASTName ) + while (node instanceof IASTName) node = node.getParent(); - if( !(node instanceof ICPPASTFunctionDeclarator) ) + if (!(node instanceof ICPPASTFunctionDeclarator)) return false; ICPPASTFunctionDeclarator dtor = (ICPPASTFunctionDeclarator) node; ICPPFunctionType ftype = (ICPPFunctionType) candidate.getType(); - if( dtor.isConst() != ftype.isConst() || dtor.isVolatile() != ftype.isVolatile() ) + if (dtor.isConst() != ftype.isConst() || dtor.isVolatile() != ftype.isVolatile()) return false; - return functionHasParameters( candidate, (IASTParameterDeclaration[]) data.functionParameters ); + return functionHasParameters(candidate, (IASTParameterDeclaration[]) data.functionParameters); } catch (DOMException e) { } return false; } - static private IType[] getSourceParameterTypes( Object [] params ){ - if( params instanceof IType[] ){ + static private IType[] getSourceParameterTypes(Object[] params) { + if (params instanceof IType[]) { return (IType[]) params; } - if( params == null || params.length == 0 ) + if (params == null || params.length == 0) return new IType[] { VOID_TYPE }; - if( params instanceof IASTExpression [] ){ - IASTExpression [] exps = (IASTExpression[]) params; - IType [] result = new IType[ exps.length ]; - for ( int i = 0; i < exps.length; i++ ) { - result[i] = CPPVisitor.getExpressionType( exps[i] ); + if (params instanceof IASTExpression[]) { + IASTExpression[] exps = (IASTExpression[]) params; + IType[] result = new IType[exps.length]; + for (int i = 0; i < exps.length; i++) { + result[i] = CPPVisitor.getExpressionType(exps[i]); } return result; - } else if( params instanceof IASTParameterDeclaration[] ){ - IASTParameterDeclaration [] decls = (IASTParameterDeclaration[]) params; - IType [] result = new IType[ decls.length ]; - for ( int i = 0; i < params.length; i++ ) { - result[i] = CPPVisitor.createType( decls[i].getDeclarator() ); + } else if (params instanceof IASTParameterDeclaration[]) { + IASTParameterDeclaration[] decls = (IASTParameterDeclaration[]) params; + IType[] result = new IType[decls.length]; + for (int i = 0; i < params.length; i++) { + result[i] = CPPVisitor.createType(decls[i].getDeclarator()); } return result; } return null; } - static private IType [] getTargetParameterTypes( IFunction fn ) throws DOMException{ - IParameter [] params = fn.getParameters(); + static private IType[] getTargetParameterTypes(IFunction fn) throws DOMException{ + IParameter[] params = fn.getParameters(); - boolean useImplicit = ( fn instanceof ICPPMethod && !(fn instanceof ICPPConstructor) ); - IType [] result = new IType[ useImplicit ? params.length + 1 : params.length ]; + boolean useImplicit = (fn instanceof ICPPMethod && !(fn instanceof ICPPConstructor)); + IType[] result = new IType[useImplicit ? params.length + 1 : params.length]; - if( useImplicit ){ + if (useImplicit) { ICPPFunctionType ftype = (ICPPFunctionType) ((ICPPFunction)fn).getType(); if (ftype != null) { IScope scope = fn.getScope(); - if( scope instanceof ICPPTemplateScope ) + if (scope instanceof ICPPTemplateScope) scope = scope.getParent(); ICPPClassType cls = null; - if( scope instanceof ICPPClassScope ){ + if (scope instanceof ICPPClassScope) { cls = ((ICPPClassScope)scope).getClassType(); } else { - cls = new CPPClassType.CPPClassTypeProblem(ASTInternal.getPhysicalNodeOfScope(scope), IProblemBinding.SEMANTIC_BAD_SCOPE, fn.getNameCharArray() ); + cls = new CPPClassType.CPPClassTypeProblem(ASTInternal.getPhysicalNodeOfScope(scope), IProblemBinding.SEMANTIC_BAD_SCOPE, fn.getNameCharArray()); } - if( cls instanceof ICPPClassTemplate ){ - IBinding within = CPPTemplates.instantiateWithinClassTemplate( (ICPPClassTemplate) cls ); + if (cls instanceof ICPPClassTemplate) { + IBinding within = CPPTemplates.instantiateWithinClassTemplate((ICPPClassTemplate) cls); if (within instanceof ICPPClassType) cls = (ICPPClassType)within; } IType implicitType = cls; - if( ftype.isConst() || ftype.isVolatile() ){ - implicitType = new CPPQualifierType( implicitType, ftype.isConst(), ftype.isVolatile() ); + if (ftype.isConst() || ftype.isVolatile()) { + implicitType = new CPPQualifierType(implicitType, ftype.isConst(), ftype.isVolatile()); } - implicitType = new CPPReferenceType( implicitType ); + implicitType = new CPPReferenceType(implicitType); result[0] = implicitType; } } - for( int i = 0; i < params.length; i++ ) - result = (IType[]) ArrayUtil.append( IType.class, result, params[i].getType() ); + for (int i = 0; i < params.length; i++) + result = (IType[]) ArrayUtil.append(IType.class, result, params[i].getType()); return result; } static IBinding resolveFunction(LookupData data, IFunction[] fns) throws DOMException { fns= (IFunction[]) ArrayUtil.trim(IFunction.class, fns); - if( fns == null || fns.length == 0 ) + if (fns == null || fns.length == 0) return null; - if( data.forUsingDeclaration() ){ - return new CPPUsingDeclaration( data.astName, fns ); + if (data.forUsingDeclaration()) { + return new CPPUsingDeclaration(data.astName, fns); } //we don't have any arguments with which to resolve the function - if( data.functionParameters == null ){ - return resolveTargetedFunction( data, fns ); + if (data.functionParameters == null) { + return resolveTargetedFunction(data, fns); } //reduce our set of candidate functions to only those who have the right number of parameters - reduceToViable( data, fns ); + reduceToViable(data, fns); - if( data.forDefinition() || data.forExplicitInstantiation() ){ + if (data.forDefinition() || data.forExplicitInstantiation()) { for (int i = 0; i < fns.length; i++) { - if( fns[i] != null ){ + if (fns[i] != null) { return fns[i]; } } @@ -1892,8 +1890,8 @@ public class CPPSemantics { IFunction bestFn = null; //the best function IFunction currFn = null; //the function currently under consideration - Cost [] bestFnCost = null; //the cost of the best function - Cost [] currFnCost = null; //the cost for the current function + Cost[] bestFnCost = null; //the cost of the best function + Cost[] currFnCost = null; //the cost for the current function IASTExpression sourceExp; IType source = null; //parameter we are called with @@ -1908,12 +1906,12 @@ public class CPPSemantics { boolean currHasAmbiguousParam = false; //currFn has an ambiguous parameter conversion (ok if not bestFn) boolean bestHasAmbiguousParam = false; //bestFn has an ambiguous parameter conversion (not ok, ambiguous) - final IType[] sourceParameters = getSourceParameterTypes( data.functionParameters ); //the parameters the function is being called with - final boolean sourceVoid = ( data.functionParameters == null || data.functionParameters.length == 0 ); + final IType[] sourceParameters = getSourceParameterTypes(data.functionParameters); //the parameters the function is being called with + final boolean sourceVoid = (data.functionParameters == null || data.functionParameters.length == 0); final IType impliedObjectType = data.getImpliedObjectArgument(); // loop over all functions - function_loop: for( int fnIdx = 0; fnIdx < fns.length; fnIdx++ ){ + function_loop: for (int fnIdx = 0; fnIdx < fns.length; fnIdx++) { currFn= fns[fnIdx]; if (currFn == null || bestFn == currFn) { continue; @@ -1962,13 +1960,13 @@ public class CPPSemantics { cost = new Cost(source, null); cost.rank = Cost.ELLIPSIS_CONVERSION; } else if (source.isSameType(target) || (sourceVoid && j == useImplicitObj)) { - cost = new Cost( source, target ); + cost = new Cost(source, target); cost.rank = Cost.IDENTITY_RANK; //exact match, no cost } else { cost= Conversions.checkImplicitConversionSequence(!data.forUserDefinedConversion, sourceExp, source, target, isImpliedObject); } - currFnCost[ j ] = cost; + currFnCost[j] = cost; } @@ -1977,10 +1975,10 @@ public class CPPSemantics { //In order for this function to be better than the previous best, it must //have at least one parameter match that is better that the corresponding //match for the other function, and none that are worse. - int len = ( bestFnCost == null || currFnCost.length < bestFnCost.length ) ? currFnCost.length : bestFnCost.length; - for( int j = 1; j <= len; j++ ){ - Cost currCost = currFnCost[ currFnCost.length - j ]; - if( currCost.rank < 0 ){ + int len = (bestFnCost == null || currFnCost.length < bestFnCost.length) ? currFnCost.length : bestFnCost.length; + for (int j = 1; j <= len; j++) { + Cost currCost = currFnCost[currFnCost.length - j]; + if (currCost.rank < 0) { hasWorse = true; hasBetter = false; break; @@ -1988,11 +1986,11 @@ public class CPPSemantics { //an ambiguity in the user defined conversion sequence is only a problem //if this function turns out to be the best. - currHasAmbiguousParam = ( currCost.userDefined == 1 ); - if( bestFnCost != null ){ - comparison = currCost.compare( bestFnCost[ bestFnCost.length - j ] ); - hasWorse |= ( comparison < 0 ); - hasBetter |= ( comparison > 0 ); + currHasAmbiguousParam = (currCost.userDefined == 1); + if (bestFnCost != null) { + comparison = currCost.compare(bestFnCost[bestFnCost.length - j]); + hasWorse |= (comparison < 0); + hasBetter |= (comparison > 0); } else { hasBetter = true; } @@ -2001,39 +1999,38 @@ public class CPPSemantics { //If function has a parameter match that is better than the current best, //and another that is worse (or everything was just as good, neither better nor worse). //then this is an ambiguity (unless we find something better than both later) - ambiguous |= ( hasWorse && hasBetter ) || ( !hasWorse && !hasBetter ); + ambiguous |= (hasWorse && hasBetter) || (!hasWorse && !hasBetter); - if( !hasWorse ){ + if (!hasWorse) { //if they are both template functions, we can order them that way boolean bestIsTemplate = (bestFn instanceof ICPPSpecialization && ((ICPPSpecialization)bestFn).getSpecializedBinding() instanceof ICPPFunctionTemplate); boolean currIsTemplate = (currFn instanceof ICPPSpecialization && ((ICPPSpecialization)currFn).getSpecializedBinding() instanceof ICPPFunctionTemplate); - if( bestIsTemplate && currIsTemplate ) - { - ICPPFunctionTemplate t1 = (ICPPFunctionTemplate) ((ICPPSpecialization)bestFn).getSpecializedBinding(); - ICPPFunctionTemplate t2 = (ICPPFunctionTemplate) ((ICPPSpecialization)currFn).getSpecializedBinding(); - int order = CPPTemplates.orderTemplateFunctions( t1, t2); - if ( order < 0 ){ - hasBetter = true; - } else if( order > 0 ){ - ambiguous = false; - } + if (bestIsTemplate && currIsTemplate) { + ICPPFunctionTemplate t1 = (ICPPFunctionTemplate) ((ICPPSpecialization)bestFn).getSpecializedBinding(); + ICPPFunctionTemplate t2 = (ICPPFunctionTemplate) ((ICPPSpecialization)currFn).getSpecializedBinding(); + int order = CPPTemplates.orderTemplateFunctions(t1, t2); + if (order < 0) { + hasBetter = true; + } else if (order > 0) { + ambiguous = false; + } } //we prefer normal functions over template functions, unless we specified template arguments - else if( bestIsTemplate && !currIsTemplate ){ - if( data.preferTemplateFunctions() ) + else if (bestIsTemplate && !currIsTemplate) { + if (data.preferTemplateFunctions()) ambiguous = false; else hasBetter = true; - } else if( !bestIsTemplate && currIsTemplate ){ - if( data.preferTemplateFunctions() ) + } else if (!bestIsTemplate && currIsTemplate) { + if (data.preferTemplateFunctions()) hasBetter = true; else ambiguous = false; } - if( hasBetter ){ + if (hasBetter) { //the new best function. ambiguous = false; bestFnCost = currFnCost; @@ -2044,9 +2041,8 @@ public class CPPSemantics { } } - - if( ambiguous || bestHasAmbiguousParam ){ - return new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name() ); + if (ambiguous || bestHasAmbiguousParam) { + return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name()); } return bestFn; @@ -2058,177 +2054,178 @@ public class CPPSemantics { * @param fns * @return */ - private static IBinding resolveTargetedFunction( LookupData data, IBinding[] fns ) { - if( fns.length == 1 ) + private static IBinding resolveTargetedFunction(LookupData data, IBinding[] fns) { + if (fns.length == 1) return fns[0]; - if( data.forAssociatedScopes ){ - return new CPPCompositeBinding( fns ); + if (data.forAssociatedScopes) { + return new CPPCompositeBinding(fns); } IBinding result = null; - Object o = getTargetType( data ); + Object o = getTargetType(data); IType type, types[] = null; int idx = -1; - if( o instanceof IType [] ){ + if (o instanceof IType[]) { types = (IType[]) o; - type = types[ ++idx ]; - } else + type = types[++idx]; + } else { type = (IType) o; + } - while( type != null ){ - type = getUltimateType( type, false ); - if( type == null || !( type instanceof IFunctionType ) ) - return new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name() ); + while (type != null) { + type = getUltimateType(type, false); + if (type == null || !(type instanceof IFunctionType)) + return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name()); - for( int i = 0; i < fns.length; i++ ){ + for (int i = 0; i < fns.length; i++) { IFunction fn = (IFunction) fns[i]; IType ft = null; try { ft = fn.getType(); - } catch ( DOMException e ) { + } catch (DOMException e) { ft = e.getProblem(); } - if( type.isSameType( ft ) ){ - if( result == null ) + if (type.isSameType(ft)) { + if (result == null) result = fn; else - return new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name() ); + return new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name()); } } - if( idx > 0 && ++idx < types.length ){ + if (idx > 0 && ++idx < types.length) { type = types[idx]; } else { type = null; } } - return ( result != null ) ? result : new ProblemBinding( data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name() ); + return (result != null) ? result : new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_AMBIGUOUS_LOOKUP, data.name()); } - private static Object getTargetType( LookupData data ){ + private static Object getTargetType(LookupData data) { IASTName name = data.astName; - if( name.getPropertyInParent() == ICPPASTQualifiedName.SEGMENT_NAME ) + if (name.getPropertyInParent() == ICPPASTQualifiedName.SEGMENT_NAME) name = (IASTName) name.getParent(); - if( name.getPropertyInParent() != IASTIdExpression.ID_NAME ) + if (name.getPropertyInParent() != IASTIdExpression.ID_NAME) return null; IASTIdExpression idExp = (IASTIdExpression) name.getParent(); IASTNode node = idExp; ASTNodeProperty prop = null; - while( node != null ){ + while (node != null) { prop = node.getPropertyInParent(); //target is an object or reference being initialized - if( prop == IASTDeclarator.INITIALIZER ){ + if (prop == IASTDeclarator.INITIALIZER) { IASTDeclarator dtor = (IASTDeclarator) node.getParent(); - return CPPVisitor.createType( dtor ); - } else if( prop == IASTInitializerExpression.INITIALIZER_EXPRESSION ){ + return CPPVisitor.createType(dtor); + } else if (prop == IASTInitializerExpression.INITIALIZER_EXPRESSION) { IASTInitializerExpression initExp = (IASTInitializerExpression) node.getParent(); - if( initExp.getParent() instanceof IASTDeclarator ){ + if (initExp.getParent() instanceof IASTDeclarator) { IASTDeclarator dtor = (IASTDeclarator) initExp.getParent(); - return CPPVisitor.createType( dtor ); + return CPPVisitor.createType(dtor); } return null; } //target is the left side of an assignment - else if( prop == IASTBinaryExpression.OPERAND_TWO && - ((IASTBinaryExpression)node.getParent()).getOperator() == IASTBinaryExpression.op_assign ) + else if (prop == IASTBinaryExpression.OPERAND_TWO && + ((IASTBinaryExpression)node.getParent()).getOperator() == IASTBinaryExpression.op_assign) { IASTBinaryExpression binaryExp = (IASTBinaryExpression) node.getParent(); IASTExpression exp = binaryExp.getOperand1(); - return CPPVisitor.getExpressionType( exp ); + return CPPVisitor.getExpressionType(exp); } //target is a parameter of a function - else if( prop == IASTFunctionCallExpression.PARAMETERS || - (prop == IASTExpressionList.NESTED_EXPRESSION && node.getParent().getPropertyInParent() == IASTFunctionCallExpression.PARAMETERS ) ) + else if (prop == IASTFunctionCallExpression.PARAMETERS || + (prop == IASTExpressionList.NESTED_EXPRESSION && node.getParent().getPropertyInParent() == IASTFunctionCallExpression.PARAMETERS)) { //if this function call refers to an overloaded function, there is more than one possiblity //for the target type IASTFunctionCallExpression fnCall = null; int idx = -1; - if( prop == IASTFunctionCallExpression.PARAMETERS ){ + if (prop == IASTFunctionCallExpression.PARAMETERS) { fnCall = (IASTFunctionCallExpression) node.getParent(); idx = 0; } else { IASTExpressionList list = (IASTExpressionList) node.getParent(); fnCall = (IASTFunctionCallExpression) list.getParent(); - IASTExpression [] exps = list.getExpressions(); - for( int i = 0; i < exps.length; i++ ){ - if( exps[i] == node ){ + IASTExpression[] exps = list.getExpressions(); + for (int i = 0; i < exps.length; i++) { + if (exps[i] == node) { idx = i; break; } } } - IFunctionType [] types = getPossibleFunctions( fnCall ); - if( types == null ) return null; - IType [] result = null; - for( int i = 0; i < types.length && types[i] != null; i++ ){ - IType [] pts = null; + IFunctionType[] types = getPossibleFunctions(fnCall); + if (types == null) return null; + IType[] result = null; + for (int i = 0; i < types.length && types[i] != null; i++) { + IType[] pts = null; try { pts = types[i].getParameterTypes(); - } catch ( DOMException e ) { + } catch (DOMException e) { continue; } - if( pts.length > idx ) - result = (IType[]) ArrayUtil.append( IType.class, result, pts[idx] ); + if (pts.length > idx) + result = (IType[]) ArrayUtil.append(IType.class, result, pts[idx]); } return result; } //target is an explicit type conversion - else if( prop == IASTCastExpression.OPERAND ) + else if (prop == IASTCastExpression.OPERAND) { IASTCastExpression cast = (IASTCastExpression) node.getParent(); - return CPPVisitor.createType( cast.getTypeId().getAbstractDeclarator() ); + return CPPVisitor.createType(cast.getTypeId().getAbstractDeclarator()); } //target is a template non-type parameter (14.3.2-5) - else if( prop == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT ){ + else if (prop == ICPPASTTemplateId.TEMPLATE_ID_ARGUMENT) { ICPPASTTemplateId id = (ICPPASTTemplateId) node.getParent(); - IASTNode [] args = id.getTemplateArguments(); + IASTNode[] args = id.getTemplateArguments(); int i = 0; - for ( ; i < args.length; i++ ) { - if( args[i] == node ){ + for (; i < args.length; i++) { + if (args[i] == node) { break; } } ICPPTemplateDefinition template = (ICPPTemplateDefinition) id.getTemplateName().resolveBinding(); - if( template != null ){ + if (template != null) { try { - ICPPTemplateParameter [] ps = template.getTemplateParameters(); - if( i < args.length && i < ps.length && ps[i] instanceof ICPPTemplateNonTypeParameter ){ + ICPPTemplateParameter[] ps = template.getTemplateParameters(); + if (i < args.length && i < ps.length && ps[i] instanceof ICPPTemplateNonTypeParameter) { return ((ICPPTemplateNonTypeParameter)ps[i]).getType(); } - } catch ( DOMException e ) { + } catch (DOMException e) { return null; } } } //target is the return value of a function, operator or conversion - else if( prop == IASTReturnStatement.RETURNVALUE ) + else if (prop == IASTReturnStatement.RETURNVALUE) { - while( !( node instanceof IASTFunctionDefinition ) ){ + while (!(node instanceof IASTFunctionDefinition)) { node = node.getParent(); } IASTDeclarator dtor = ((IASTFunctionDefinition)node).getDeclarator(); - while( dtor.getNestedDeclarator() != null ) + while (dtor.getNestedDeclarator() != null) dtor = dtor.getNestedDeclarator(); IBinding binding = dtor.getName().resolveBinding(); - if( binding instanceof IFunction ){ + if (binding instanceof IFunction) { try { IFunctionType ft = ((IFunction)binding).getType(); return ft.getReturnType(); - } catch ( DOMException e ) { + } catch (DOMException e) { } } } - else if( prop == IASTUnaryExpression.OPERAND ){ + else if (prop == IASTUnaryExpression.OPERAND) { IASTUnaryExpression parent = (IASTUnaryExpression) node.getParent(); - if( parent.getOperator() == IASTUnaryExpression.op_bracketedPrimary || + if (parent.getOperator() == IASTUnaryExpression.op_bracketedPrimary || parent.getOperator() == IASTUnaryExpression.op_amper) { node = parent; @@ -2240,84 +2237,84 @@ public class CPPSemantics { return null; } - static private IFunctionType [] getPossibleFunctions( IASTFunctionCallExpression call ){ - IFunctionType [] result = null; + static private IFunctionType[] getPossibleFunctions(IASTFunctionCallExpression call) { + IFunctionType[] result = null; IASTExpression exp = call.getFunctionNameExpression(); - if( exp instanceof IASTIdExpression ){ + if (exp instanceof IASTIdExpression) { IASTIdExpression idExp = (IASTIdExpression) exp; IASTName name = idExp.getName(); - LookupData data = createLookupData( name, false ); + LookupData data = createLookupData(name, false); try { - lookup( data, name ); - } catch ( DOMException e1 ) { + lookup(data, name); + } catch (DOMException e1) { return null; } final boolean isIndexBased= data.tu == null ? false : data.tu.getIndex() != null; - if( data.hasResults() ){ - Object [] items = (Object[]) data.foundItems; + if (data.hasResults()) { + Object[] items = (Object[]) data.foundItems; IBinding temp = null; - for( int i = 0; i < items.length; i++ ){ + for (int i = 0; i < items.length; i++) { Object o = items[i]; - if( o == null ) break; - if( o instanceof IASTName ) + if (o == null) break; + if (o instanceof IASTName) temp = ((IASTName) o).resolveBinding(); - else if( o instanceof IBinding ){ + else if (o instanceof IBinding) { temp = (IBinding) o; - if( !declaredBefore( temp, name, isIndexBased ) ) + if (!declaredBefore(temp, name, isIndexBased)) continue; } else continue; try { - if( temp instanceof IFunction ){ - result = (IFunctionType[]) ArrayUtil.append( IFunctionType.class, result, ((IFunction)temp).getType() ); - } else if( temp instanceof IVariable ){ - IType type = getUltimateType( ((IVariable) temp).getType(), false ); - if( type instanceof IFunctionType ) - result = (IFunctionType[]) ArrayUtil.append( IFunctionType.class, result, type ); + if (temp instanceof IFunction) { + result = (IFunctionType[]) ArrayUtil.append(IFunctionType.class, result, ((IFunction)temp).getType()); + } else if (temp instanceof IVariable) { + IType type = getUltimateType(((IVariable) temp).getType(), false); + if (type instanceof IFunctionType) + result = (IFunctionType[]) ArrayUtil.append(IFunctionType.class, result, type); } - } catch( DOMException e ){ + } catch (DOMException e) { } } } } else { - IType type = CPPVisitor.getExpressionType( exp ); - type = getUltimateType( type, false ); - if( type instanceof IFunctionType ){ + IType type = CPPVisitor.getExpressionType(exp); + type = getUltimateType(type, false); + if (type instanceof IFunctionType) { result = new IFunctionType[] { (IFunctionType) type }; } } return result; } - public static ICPPFunction findOperator( IASTExpression exp, ICPPClassType cls ){ + public static ICPPFunction findOperator(IASTExpression exp, ICPPClassType cls) { IScope scope = null; try { scope = cls.getCompositeScope(); } catch (DOMException e1) { return null; } - if( scope == null ) + if (scope == null) return null; CPPASTName astName = new CPPASTName(); - astName.setParent( exp ); - astName.setPropertyInParent( STRING_LOOKUP_PROPERTY ); + astName.setParent(exp); + astName.setPropertyInParent(STRING_LOOKUP_PROPERTY); LookupData data = null; - if( exp instanceof IASTUnaryExpression) { - astName.setName( OverloadableOperator.STAR.toCharArray() ); - data = new LookupData( astName ); + if (exp instanceof IASTUnaryExpression) { + astName.setName(OverloadableOperator.STAR.toCharArray()); + data = new LookupData(astName); data.forceQualified = true; data.functionParameters = IASTExpression.EMPTY_EXPRESSION_ARRAY; - } else if( exp instanceof IASTArraySubscriptExpression ){ - astName.setName( OverloadableOperator.BRACKET.toCharArray() ); - data = new LookupData( astName ); + } else if (exp instanceof IASTArraySubscriptExpression) { + astName.setName(OverloadableOperator.BRACKET.toCharArray()); + data = new LookupData(astName); data.forceQualified = true; - data.functionParameters = new IASTExpression [] { ((IASTArraySubscriptExpression)exp).getSubscriptExpression() }; - } else if( exp instanceof IASTFieldReference ){ - astName.setName( OverloadableOperator.ARROW.toCharArray() ); - data = new LookupData( astName ); + data.functionParameters = new IASTExpression[] { ((IASTArraySubscriptExpression)exp).getSubscriptExpression() }; + } else if (exp instanceof IASTFieldReference) { + astName.setName(OverloadableOperator.ARROW.toCharArray()); + data = new LookupData(astName); data.forceQualified = true; data.functionParameters = IASTExpression.EMPTY_EXPRESSION_ARRAY; } else { @@ -2325,26 +2322,26 @@ public class CPPSemantics { } try { - lookup( data, scope ); - IBinding binding = resolveAmbiguities( data, astName ); - if( binding instanceof ICPPFunction ) + lookup(data, scope); + IBinding binding = resolveAmbiguities(data, astName); + if (binding instanceof ICPPFunction) return (ICPPFunction) binding; - } catch( DOMException e ){ + } catch (DOMException e) { } return null; } - public static IBinding[] findBindings( IScope scope, String name, boolean qualified ) throws DOMException{ - return findBindings( scope, name.toCharArray(), qualified ); + public static IBinding[] findBindings(IScope scope, String name, boolean qualified) throws DOMException{ + return findBindings(scope, name.toCharArray(), qualified); } - public static IBinding[] findBindings( IScope scope, char[] name, boolean qualified ) throws DOMException{ + public static IBinding[] findBindings(IScope scope, char[] name, boolean qualified) throws DOMException{ CPPASTName astName = new CPPASTName(); - astName.setName( name ); - astName.setParent( ASTInternal.getPhysicalNodeOfScope(scope)); - astName.setPropertyInParent( STRING_LOOKUP_PROPERTY ); + astName.setName(name); + astName.setParent(ASTInternal.getPhysicalNodeOfScope(scope)); + astName.setPropertyInParent(STRING_LOOKUP_PROPERTY); - LookupData data = new LookupData( astName ); + LookupData data = new LookupData(astName); data.forceQualified = qualified; return standardLookup(data, scope); } @@ -2359,74 +2356,75 @@ public class CPPSemantics { } - private static IBinding [] contentAssistLookup( LookupData data, Object start ){ + private static IBinding[] contentAssistLookup(LookupData data, Object start) { try { - lookup( data, start ); - } catch ( DOMException e ) { + lookup(data, start); + } catch (DOMException e) { } CharArrayObjectMap map = (CharArrayObjectMap) data.foundItems; - IBinding [] result = null; - if( !map.isEmpty() ){ - char [] key = null; + IBinding[] result = null; + if (!map.isEmpty()) { + char[] key = null; Object obj = null; int size = map.size(); - for( int i = 0; i < size; i++ ) { - key = map.keyAt( i ); - obj = map.get( key ); - if( obj instanceof IBinding ) - result = (IBinding[]) ArrayUtil.append( IBinding.class, result, obj ); - else if( obj instanceof IASTName ) { + for (int i = 0; i < size; i++) { + key = map.keyAt(i); + obj = map.get(key); + if (obj instanceof IBinding) + result = (IBinding[]) ArrayUtil.append(IBinding.class, result, obj); + else if (obj instanceof IASTName) { IBinding binding = ((IASTName) obj).resolveBinding(); - if( binding != null && !(binding instanceof IProblemBinding)) - result = (IBinding[]) ArrayUtil.append( IBinding.class, result, binding ); - } else if( obj instanceof Object [] ) { + if (binding != null && !(binding instanceof IProblemBinding)) + result = (IBinding[]) ArrayUtil.append(IBinding.class, result, binding); + } else if (obj instanceof Object[]) { Object[] objs = (Object[]) obj; for (int j = 0; j < objs.length && objs[j] != null; j++) { Object item = objs[j]; - if( item instanceof IBinding ) - result = (IBinding[]) ArrayUtil.append( IBinding.class, result, item ); - else if( item instanceof IASTName ) { + if (item instanceof IBinding) + result = (IBinding[]) ArrayUtil.append(IBinding.class, result, item); + else if (item instanceof IASTName) { IBinding binding = ((IASTName) item).resolveBinding(); - if( binding != null && !(binding instanceof IProblemBinding)) - result = (IBinding[]) ArrayUtil.append( IBinding.class, result, binding ); + if (binding != null && !(binding instanceof IProblemBinding)) + result = (IBinding[]) ArrayUtil.append(IBinding.class, result, binding); } } } } } - return (IBinding[]) ArrayUtil.trim( IBinding.class, result ); + return (IBinding[]) ArrayUtil.trim(IBinding.class, result); } - private static IBinding [] standardLookup( LookupData data, Object start ) { + private static IBinding[] standardLookup(LookupData data, Object start) { try { - lookup( data, start ); + lookup(data, start); } catch (DOMException e) { - return new IBinding [] { e.getProblem() }; + return new IBinding[] { e.getProblem() }; } - Object [] items = (Object[]) data.foundItems; - if( items == null ) + Object[] items = (Object[]) data.foundItems; + if (items == null) return new IBinding[0]; ObjectSet set = new ObjectSet(items.length); IBinding binding = null; - for( int i = 0; i < items.length; i++ ){ - if( items[i] instanceof IASTName ) + for (int i = 0; i < items.length; i++) { + if (items[i] instanceof IASTName) binding = ((IASTName) items[i]).resolveBinding(); - else if( items[i] instanceof IBinding ) + else if (items[i] instanceof IBinding) binding = (IBinding) items[i]; else binding = null; - if( binding != null ) - if( binding instanceof ICPPUsingDeclaration ){ - set.addAll( ((ICPPUsingDeclaration)binding).getDelegates() ); - } else if( binding instanceof CPPCompositeBinding ){ - set.addAll( ((CPPCompositeBinding)binding).getBindings() ); + if (binding != null) { + if (binding instanceof ICPPUsingDeclaration) { + set.addAll(((ICPPUsingDeclaration)binding).getDelegates()); + } else if (binding instanceof CPPCompositeBinding) { + set.addAll(((CPPCompositeBinding)binding).getBindings()); } else { - set.put( binding ); + set.put(binding); } + } } return set.keyArray(IBinding.class); @@ -2434,19 +2432,19 @@ public class CPPSemantics { public static boolean isSameFunction(IFunction function, IASTDeclarator declarator) { IASTName name = declarator.getName(); - ICPPASTTemplateDeclaration templateDecl = CPPTemplates.getTemplateDeclaration( name ); + ICPPASTTemplateDeclaration templateDecl = CPPTemplates.getTemplateDeclaration(name); - boolean fnIsTemplate = ( function instanceof ICPPFunctionTemplate ); - boolean dtorIsTemplate = ( templateDecl != null ); - if( fnIsTemplate && dtorIsTemplate ){ - return CPPTemplates.isSameTemplate( (ICPPTemplateDefinition)function, name ); - } else if( fnIsTemplate ^ dtorIsTemplate ){ + boolean fnIsTemplate = (function instanceof ICPPFunctionTemplate); + boolean dtorIsTemplate = (templateDecl != null); + if (fnIsTemplate && dtorIsTemplate) { + return CPPTemplates.isSameTemplate((ICPPTemplateDefinition)function, name); + } else if (fnIsTemplate ^ dtorIsTemplate) { return false; } IType type = null; try { type = function.getType(); - return type.isSameType( CPPVisitor.createType( declarator ) ); + return type.isSameType(CPPVisitor.createType(declarator)); } catch (DOMException e) { } return false; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java index 4c13f45b5ee..8d062ab1918 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMBinding.java @@ -36,7 +36,6 @@ import org.eclipse.core.runtime.CoreException; /** * @author Doug Schaefer - * */ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmentBinding { public static final PDOMBinding[] EMPTY_PDOMBINDING_ARRAY = {}; @@ -72,7 +71,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen * * @param pdom * @param record - * @return + * @return true if the binding is orphaned. * @throws CoreException */ public static boolean isOrphaned(PDOM pdom, int record) throws CoreException { @@ -189,10 +188,10 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen public IIndexScope getParent() { try { IBinding parent = getParentBinding(); - if(parent instanceof IIndexScope) { + if (parent instanceof IIndexScope) { return (IIndexScope) parent; } - } catch(CoreException ce) { + } catch (CoreException ce) { CCorePlugin.log(ce); } return null; @@ -201,10 +200,10 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen public final IIndexScope getScope() { try { IBinding parent = getParentBinding(); - if(parent instanceof IIndexScope) { + if (parent instanceof IIndexScope) { return (IIndexScope) parent; } - } catch(CoreException ce) { + } catch (CoreException ce) { CCorePlugin.log(ce); } return null; @@ -233,7 +232,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen public String toString() { try { return getName() + " " + getConstantNameForValue(getLinkageImpl(), getNodeType()); //$NON-NLS-1$ - } catch(CoreException ce) { + } catch (CoreException ce) { return getName() + " " + getNodeType(); //$NON-NLS-1$ } } @@ -242,7 +241,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen * For debug purposes only. * @param linkage * @param value - * @return + * @return String representation of value. */ protected static String getConstantNameForValue(PDOMLinkage linkage, int value) { Class c= linkage.getClass(); @@ -250,16 +249,16 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen for (int i = 0; i < fields.length; i++) { try { fields[i].setAccessible(true); - if((fields[i].getModifiers() & Modifier.STATIC) != 0) { - if(int.class.equals(fields[i].getType())) { + if ((fields[i].getModifiers() & Modifier.STATIC) != 0) { + if (int.class.equals(fields[i].getType())) { int fvalue= fields[i].getInt(null); - if(fvalue == value) + if (fvalue == value) return fields[i].getName(); } } - } catch(IllegalAccessException iae) { + } catch (IllegalAccessException iae) { continue; - } catch(IllegalArgumentException iae) { + } catch (IllegalArgumentException iae) { continue; } } @@ -269,7 +268,9 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen /** * Convenience method to shorten subclass file length */ - protected final void fail() { throw new PDOMNotImplementedError(); } + protected final void fail() { + throw new PDOMNotImplementedError("in " + getClass().getCanonicalName()); //$NON-NLS-1$ + } public PDOMName getScopeName() { try { @@ -294,7 +295,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen node = node.getParentNode(); } return result.toArray(new String[result.size()]); - } catch(CoreException ce) { + } catch (CoreException ce) { CCorePlugin.log(ce); return null; } @@ -305,7 +306,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen } public boolean hasDefinition() throws CoreException { - return getFirstDefinition()!=null; + return getFirstDefinition() != null; } /** @@ -332,7 +333,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen do { IString s0 = b0.getDBName(), s1 = b1.getDBName(); cmp = s0.compare(s1, true); - if(cmp==0) { + if (cmp == 0) { int l1= b0.getLocalToFileRec(); int l2= b1.getLocalToFileRec(); if (l1 != l2) { @@ -340,13 +341,13 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen } b0 = (PDOMBinding) b0.getParentBinding(); b1 = (PDOMBinding) b1.getParentBinding(); - if(b0==null || b1==null) { - cmp = b0==b1 ? 0 : (b0==null ? -1 : 1); + if (b0 == null || b1 == null) { + cmp = b0 == b1 ? 0 : (b0 == null ? -1 : 1); } } - } while(cmp==0 && b1!=null && b0!=null); + } while(cmp == 0 && b1 != null && b0 != null); return cmp; - } catch(CoreException ce) { + } catch (CoreException ce) { CCorePlugin.log(ce); return -1; } @@ -356,7 +357,7 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen * Compares two PDOMBinding objects in accordance with * {@link IIndexFragmentBindingComparator#compare(IIndexFragmentBinding, IIndexFragmentBinding)} * @param other - * @return + * @return comparison result, -1, 0, or 1. */ public int pdomCompareTo(PDOMBinding other) { int cmp = comparePDOMBindingQNs(this, other); @@ -412,7 +413,8 @@ public abstract class PDOMBinding extends PDOMNamedNode implements IIndexFragmen return getBindings(name, resolve, prefix, null); } - public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefix, IIndexFileSet fileSet) throws DOMException { + public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefix, IIndexFileSet fileSet) + throws DOMException { return null; } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPBinding.java index 20048b41655..5bb1dcce617 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPBinding.java @@ -75,6 +75,6 @@ abstract class PDOMCPPBinding extends PDOMBinding implements ICPPBinding { } public boolean isGloballyQualified() throws DOMException { - throw new PDOMNotImplementedError("In " + getClass().getCanonicalName()); //$NON-NLS-1$ + throw new PDOMNotImplementedError("in " + getClass().getCanonicalName()); //$NON-NLS-1$ } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPDeferredClassInstance.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPDeferredClassInstance.java index 044a8702af9..57f055252d3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPDeferredClassInstance.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPDeferredClassInstance.java @@ -39,7 +39,6 @@ import org.eclipse.core.runtime.CoreException; /** * @author Bryan Wilkinson - * */ class PDOMCPPDeferredClassInstance extends PDOMCPPInstance implements ICPPClassType, IPDOMMemberOwner, IIndexType, ICPPDeferredTemplateInstance, ICPPInternalDeferredClassInstance { @@ -84,7 +83,7 @@ class PDOMCPPDeferredClassInstance extends PDOMCPPInstance implements } public boolean isSameType(IType type) { - if( type instanceof PDOMNode ) { + if (type instanceof PDOMNode) { PDOMNode node = (PDOMNode) type; if (node.getPDOM() == getPDOM() && node.getRecord() == getRecord()) { return true; @@ -94,12 +93,13 @@ class PDOMCPPDeferredClassInstance extends PDOMCPPInstance implements ICPPClassTemplate classTemplate = (ICPPClassTemplate) getTemplateDefinition(); //allow some fuzziness here. - if( type instanceof ICPPDeferredTemplateInstance && type instanceof ICPPClassType ){ + if (type instanceof ICPPDeferredTemplateInstance && type instanceof ICPPClassType) { ICPPClassTemplate typeClass = (ICPPClassTemplate) ((ICPPDeferredTemplateInstance)type).getSpecializedBinding(); - return (typeClass == classTemplate ); - } else if( type instanceof ICPPClassTemplate && classTemplate == type ){ + return typeClass == classTemplate; + } else if (type instanceof ICPPClassTemplate && classTemplate == type) { return true; - } else if( type instanceof ICPPTemplateInstance && ((ICPPTemplateInstance)type).getTemplateDefinition() == classTemplate ){ + } else if (type instanceof ICPPTemplateInstance && + ((ICPPTemplateInstance)type).getTemplateDefinition() == classTemplate) { return true; } return false; @@ -111,18 +111,18 @@ class PDOMCPPDeferredClassInstance extends PDOMCPPInstance implements /** * @param argMap - * @return + * @return This class instance re-instantiated with resolved template arguments. */ public IType instantiate(ObjectMap argMap) { IType[] arguments = getArguments(); - IType [] newArgs = new IType[ arguments.length ]; + IType[] newArgs = new IType[arguments.length]; int size = arguments.length; - for( int i = 0; i < size; i++ ){ - newArgs[i] = CPPTemplates.instantiateType( arguments[i], argMap ); + for (int i = 0; i < size; i++) { + newArgs[i] = CPPTemplates.instantiateType(arguments[i], argMap); } - return (IType) ((ICPPInternalTemplateInstantiator)getTemplateDefinition()).instantiate( newArgs ); + return (IType) ((ICPPInternalTemplateInstantiator) getTemplateDefinition()).instantiate(newArgs); } public void addMember(PDOMNode member) throws CoreException {