Search in sources :

Example 1 with RPossibleCall

use of org.jetbrains.plugins.ruby.ruby.lang.psi.RPossibleCall in project intellij-plugins by JetBrains.

the class RubyMotionTypeProvider method createTypeForRef.

@Nullable
private static RType createTypeForRef(@NotNull RReference ref, @NotNull Module module) {
    final RPsiElement value = ref.getValue();
    // method name may be identifier on constant
    if (value instanceof RPossibleCall) {
        final String shortName = ((RPossibleCall) value).getPossibleCommand();
        final String sdkVersion = RubyMotionUtil.getInstance().getSdkVersion(module);
        final String[] frameworks = RubyMotionUtil.getInstance().getRequiredFrameworks(module);
        boolean isIdSelector = false;
        for (String framework : frameworks) {
            if (BridgeSupportLoader.getInstance().isIdSelector(shortName, sdkVersion, framework)) {
                isIdSelector = true;
                break;
            }
        }
        if (isIdSelector) {
            final Symbol callSymbol = ResolveUtil.resolveToSymbolWithCaching(ref.getReference());
            if (callSymbol instanceof FunctionSymbol) {
                final Function function = ((FunctionSymbol) callSymbol).getFunction();
                if (function.isId()) {
                    return RTypeUtil.createTypeSameAsReceiverInstance(ref);
                }
            }
        }
    }
    return null;
}
Also used : RPsiElement(org.jetbrains.plugins.ruby.ruby.lang.psi.RPsiElement) Function(org.jetbrains.plugins.ruby.motion.bridgesupport.Function) 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) RPossibleCall(org.jetbrains.plugins.ruby.ruby.lang.psi.RPossibleCall) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Nullable (org.jetbrains.annotations.Nullable)1 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 RPossibleCall (org.jetbrains.plugins.ruby.ruby.lang.psi.RPossibleCall)1 RPsiElement (org.jetbrains.plugins.ruby.ruby.lang.psi.RPsiElement)1