Search in sources :

Example 1 with RMethod

use of org.jetbrains.plugins.ruby.ruby.lang.psi.controlStructures.methods.RMethod in project intellij-plugins by JetBrains.

the class RubyMotionTypeProvider method createTypeForMethodParameter.

private static RType createTypeForMethodParameter(RExpression expression, @Nullable Module module) {
    final RMethod method = PsiTreeUtil.getParentOfType(expression, RMethod.class);
    final Symbol symbol = SymbolUtil.getSymbolByContainer(method);
    if (symbol == null)
        return null;
    List<RArgument> arguments = method.getArguments();
    final String rubyName = method.getName();
    final String objCName = calculateObjCName(rubyName, arguments);
    final String sdkVersion = RubyMotionUtil.getInstance().getSdkVersion(module);
    final String[] frameworks = RubyMotionUtil.getInstance().getRequiredFrameworks(module);
    boolean isSelector = false;
    for (String framework : frameworks) {
        if (BridgeSupportLoader.getInstance().isSelector(objCName, sdkVersion, framework)) {
            isSelector = true;
            break;
        }
    }
    if (!isSelector)
        return null;
    Symbol classSymbol = symbol.getParentSymbol();
    while (classSymbol != null && classSymbol instanceof ClassModuleSymbol) {
        classSymbol = ((ClassModuleSymbol) classSymbol).getSuperClassSymbol(expression);
    }
    if (classSymbol instanceof MotionClassSymbol) {
        final List<Symbol> candidates = classSymbol.getChildren().getSymbolsByNameAndTypes(rubyName, symbol.getType().asSet(), expression);
        for (Symbol candidate : candidates) {
            final Function function = ((FunctionSymbol) candidate).getFunction();
            if (objCName.equals(function.getName())) {
                int argIndex = 0;
                while (argIndex < arguments.size() && !arguments.get(argIndex).getName().equals(expression.getName())) argIndex++;
                if (argIndex < arguments.size()) {
                    return MotionSymbolUtil.getTypeByName(module, function.getArguments().get(argIndex).second);
                }
            }
        }
    }
    return null;
}
Also used : FunctionSymbol(org.jetbrains.plugins.ruby.motion.symbols.FunctionSymbol) MotionClassSymbol(org.jetbrains.plugins.ruby.motion.symbols.MotionClassSymbol) ConstantSymbol(org.jetbrains.plugins.ruby.motion.symbols.ConstantSymbol) ClassModuleSymbol(org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.v2.ClassModuleSymbol) FunctionSymbol(org.jetbrains.plugins.ruby.motion.symbols.FunctionSymbol) Symbol(org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.structure.Symbol) RArgument(org.jetbrains.plugins.ruby.ruby.lang.psi.controlStructures.methods.RArgument) MotionClassSymbol(org.jetbrains.plugins.ruby.motion.symbols.MotionClassSymbol) Function(org.jetbrains.plugins.ruby.motion.bridgesupport.Function) RMethod(org.jetbrains.plugins.ruby.ruby.lang.psi.controlStructures.methods.RMethod) ClassModuleSymbol(org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.v2.ClassModuleSymbol)

Aggregations

Function (org.jetbrains.plugins.ruby.motion.bridgesupport.Function)1 ConstantSymbol (org.jetbrains.plugins.ruby.motion.symbols.ConstantSymbol)1 FunctionSymbol (org.jetbrains.plugins.ruby.motion.symbols.FunctionSymbol)1 MotionClassSymbol (org.jetbrains.plugins.ruby.motion.symbols.MotionClassSymbol)1 Symbol (org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.structure.Symbol)1 ClassModuleSymbol (org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.v2.ClassModuleSymbol)1 RArgument (org.jetbrains.plugins.ruby.ruby.lang.psi.controlStructures.methods.RArgument)1 RMethod (org.jetbrains.plugins.ruby.ruby.lang.psi.controlStructures.methods.RMethod)1