Search in sources :

Example 6 with Function

use of org.jetbrains.plugins.ruby.motion.bridgesupport.Function in project intellij-plugins by JetBrains.

the class RubyMotionParamdefsProvider method loadAvailableSelectors.

private static void loadAvailableSelectors(Framework framework, Map<String, Map<String, Collection<Function>>> mergedFunctions) {
    final String version = framework.getVersion();
    for (Class clazz : framework.getClasses()) {
        for (Function function : clazz.getFunctions()) {
            if (!canHaveParamdef(function))
                continue;
            final String name = clazz.getName() + "." + MotionSymbolUtil.getSelectorNames(function).get(0);
            Map<String, Collection<Function>> allFunctions = mergedFunctions.get(name);
            if (allFunctions == null) {
                allFunctions = new HashMap<>();
                mergedFunctions.put(name, allFunctions);
            }
            Collection<Function> frameworkFunctions = allFunctions.get(version);
            if (frameworkFunctions == null) {
                frameworkFunctions = new ArrayList<>();
                allFunctions.put(version, frameworkFunctions);
            }
            frameworkFunctions.add(function);
        }
    }
}
Also used : Function(org.jetbrains.plugins.ruby.motion.bridgesupport.Function) Collection(java.util.Collection) Class(org.jetbrains.plugins.ruby.motion.bridgesupport.Class)

Example 7 with Function

use of org.jetbrains.plugins.ruby.motion.bridgesupport.Function 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)

Example 8 with Function

use of org.jetbrains.plugins.ruby.motion.bridgesupport.Function in project intellij-plugins by JetBrains.

the class RubyMotionOverriddenMethodGenerator method createMemberToOverride.

@Nullable
@Override
public ClassMember createMemberToOverride(final Symbol methodSymbol) {
    if (methodSymbol instanceof FunctionSymbol) {
        final FunctionSymbol symbol = (FunctionSymbol) methodSymbol;
        final Function function = symbol.getFunction();
        if (!function.isClassMethod() && symbol.getParentSymbol() != null) {
            return new FunctionMember(symbol);
        }
    }
    return null;
}
Also used : Function(org.jetbrains.plugins.ruby.motion.bridgesupport.Function) FunctionSymbol(org.jetbrains.plugins.ruby.motion.symbols.FunctionSymbol) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with Function

use of org.jetbrains.plugins.ruby.motion.bridgesupport.Function in project intellij-plugins by JetBrains.

the class SelectorKeysProvider method getValue.

@Nullable
@Override
public ParamDefExpression getValue(ParamContext context, String text) {
    final Collection<Function> functions = getFunctions(context);
    if (functions == null)
        return null;
    final Pair<Integer, List<String>> pair = determineArgNumberAndPath(context);
    final int argument = pair.first;
    if (argument < 1)
        return null;
    for (Function function : functions) {
        final List<Pair<String, String>> arguments = function.getArguments();
        final String[] namedArguments = function.getName().split(":");
        if (pathMatches(argument, namedArguments, pair.second) && "SEL".equals(arguments.get(argument).second)) {
            return new ParamDefLeaf(METHOD_REF_PARAM);
        }
    }
    return null;
}
Also used : Function(org.jetbrains.plugins.ruby.motion.bridgesupport.Function) ParamDefLeaf(org.jetbrains.plugins.ruby.ruby.codeInsight.paramDefs.matcher.ParamDefLeaf) Pair(com.intellij.openapi.util.Pair) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with Function

use of org.jetbrains.plugins.ruby.motion.bridgesupport.Function in project intellij-plugins by JetBrains.

the class SelectorKeysProvider method getKeys.

@NotNull
@Override
public List<String> getKeys(ParamContext context) {
    final Collection<Function> functions = getFunctions(context);
    if (functions == null)
        return Collections.emptyList();
    final Pair<Integer, List<String>> pair = determineArgNumberAndPath(context);
    final int argument = pair.first;
    if (argument < 1)
        return Collections.emptyList();
    final List<String> result = new ArrayList<>();
    for (Function function : functions) {
        final String[] namedArguments = function.getName().split(":");
        if (pathMatches(argument, namedArguments, pair.second)) {
            result.add(namedArguments[argument]);
        }
    }
    return result;
}
Also used : Function(org.jetbrains.plugins.ruby.motion.bridgesupport.Function) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Function (org.jetbrains.plugins.ruby.motion.bridgesupport.Function)11 FunctionSymbol (org.jetbrains.plugins.ruby.motion.symbols.FunctionSymbol)5 Nullable (org.jetbrains.annotations.Nullable)4 Symbol (org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.structure.Symbol)3 NotNull (org.jetbrains.annotations.NotNull)2 Class (org.jetbrains.plugins.ruby.motion.bridgesupport.Class)2 ConstantSymbol (org.jetbrains.plugins.ruby.motion.symbols.ConstantSymbol)2 MotionClassSymbol (org.jetbrains.plugins.ruby.motion.symbols.MotionClassSymbol)2 ParamDefLeaf (org.jetbrains.plugins.ruby.ruby.codeInsight.paramDefs.matcher.ParamDefLeaf)2 ClassModuleSymbol (org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.v2.ClassModuleSymbol)2 Module (com.intellij.openapi.module.Module)1 Pair (com.intellij.openapi.util.Pair)1 PsiElement (com.intellij.psi.PsiElement)1 Collection (java.util.Collection)1 RubyLookupElement (org.jetbrains.plugins.ruby.ruby.codeInsight.completion.RubyLookupElement)1 ParamDefHash (org.jetbrains.plugins.ruby.ruby.codeInsight.paramDefs.matcher.ParamDefHash)1 ParamDefSeq (org.jetbrains.plugins.ruby.ruby.codeInsight.paramDefs.matcher.ParamDefSeq)1 SymbolPsiProcessor (org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.v2.SymbolPsiProcessor)1 RPossibleCall (org.jetbrains.plugins.ruby.ruby.lang.psi.RPossibleCall)1 RPsiElement (org.jetbrains.plugins.ruby.ruby.lang.psi.RPsiElement)1