private ITypeBinding getDeclaredType(Expression expr) { IVariableBinding var = TreeUtil.getVariableBinding(expr); if (var != null) { return var.getVariableDeclaration().getType(); } switch (expr.getKind()) { case CLASS_INSTANCE_CREATION: return typeEnv.resolveIOSType("id"); case FUNCTION_INVOCATION: { ITypeBinding returnType = ((FunctionInvocation) expr).getFunctionBinding().getReturnType(); if (returnType.isTypeVariable()) { return typeEnv.resolveIOSType("id"); } return returnType; } case METHOD_INVOCATION: { MethodInvocation invocation = (MethodInvocation) expr; IMethodBinding method = invocation.getMethodBinding(); // Object receiving the message, or null if it's a method in this class. Expression receiver = invocation.getExpression(); ITypeBinding receiverType = receiver != null ? receiver.getTypeBinding() : method.getDeclaringClass(); return getDeclaredReturnType(method, receiverType); } case PARENTHESIZED_EXPRESSION: return getDeclaredType(((ParenthesizedExpression) expr).getExpression()); case SUPER_METHOD_INVOCATION: { SuperMethodInvocation invocation = (SuperMethodInvocation) expr; IMethodBinding method = invocation.getMethodBinding(); if (invocation.getQualifier() != null) { // For a qualified super invocation, the statement generator will look // up the IMP using instanceMethodForSelector. if (!method.getReturnType().isPrimitive()) { return typeEnv.resolveIOSType("id"); } else { return null; } } return getDeclaredReturnType( method, TreeUtil.getOwningType(invocation).getTypeBinding().getSuperclass()); } default: return null; } }
private void possibleStaticImportFound(Name name) { if (fStaticImports == null || fASTRoot == null) { return; } while (name.isQualifiedName()) { name = ((QualifiedName) name).getQualifier(); } if (!isAffected(name)) { return; } IBinding binding = name.resolveBinding(); SimpleName simpleName = (SimpleName) name; if (binding == null || binding instanceof ITypeBinding || !Modifier.isStatic(binding.getModifiers()) || simpleName.isDeclaration()) { return; } if (binding instanceof IVariableBinding) { IVariableBinding varBinding = (IVariableBinding) binding; if (varBinding.isField()) { varBinding = varBinding.getVariableDeclaration(); ITypeBinding declaringClass = varBinding.getDeclaringClass(); if (declaringClass != null && !declaringClass.isLocal()) { if (new ScopeAnalyzer(fASTRoot) .isDeclaredInScope( varBinding, simpleName, ScopeAnalyzer.VARIABLES | ScopeAnalyzer.CHECK_VISIBILITY)) return; fStaticImports.add(simpleName); } } } else if (binding instanceof IMethodBinding) { IMethodBinding methodBinding = ((IMethodBinding) binding).getMethodDeclaration(); ITypeBinding declaringClass = methodBinding.getDeclaringClass(); if (declaringClass != null && !declaringClass.isLocal()) { if (new ScopeAnalyzer(fASTRoot) .isDeclaredInScope( methodBinding, simpleName, ScopeAnalyzer.METHODS | ScopeAnalyzer.CHECK_VISIBILITY)) return; fStaticImports.add(simpleName); } } }