Search in sources :

Example 1 with ParamDefLeaf

use of org.jetbrains.plugins.ruby.ruby.codeInsight.paramDefs.matcher.ParamDefLeaf in project intellij-plugins by JetBrains.

the class RubyMotionParamdefsProvider method buildExpression.

private static ParamDefExpression buildExpression(final Map<String, Collection<Function>> functions) {
    boolean hadOneArg = false;
    boolean hadMoreArg = false;
    for (Collection<Function> collection : functions.values()) {
        for (Function function : collection) {
            hadOneArg |= function.getArguments().size() == 1;
            hadMoreArg |= function.getArguments().size() > 1;
        }
    }
    if (hadOneArg && !hadMoreArg) {
        return new ParamDefLeaf(SelectorKeysProvider.METHOD_REF_PARAM);
    }
    final ParamDefHash hash = new ParamDefHash(false, true, null);
    final SelectorKeysProvider provider = new SelectorKeysProvider(functions);
    hash.addKey(provider, new ParamDefLeaf(AnyParamDef.getInstance()));
    return new ParamDefSeq(new ParamDefLeaf(hadOneArg ? SelectorKeysProvider.METHOD_REF_PARAM : AnyParamDef.getInstance()), hash);
}
Also used : Function(org.jetbrains.plugins.ruby.motion.bridgesupport.Function) ParamDefSeq(org.jetbrains.plugins.ruby.ruby.codeInsight.paramDefs.matcher.ParamDefSeq) ParamDefLeaf(org.jetbrains.plugins.ruby.ruby.codeInsight.paramDefs.matcher.ParamDefLeaf) ParamDefHash(org.jetbrains.plugins.ruby.ruby.codeInsight.paramDefs.matcher.ParamDefHash)

Example 2 with ParamDefLeaf

use of org.jetbrains.plugins.ruby.ruby.codeInsight.paramDefs.matcher.ParamDefLeaf 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)

Aggregations

Function (org.jetbrains.plugins.ruby.motion.bridgesupport.Function)2 ParamDefLeaf (org.jetbrains.plugins.ruby.ruby.codeInsight.paramDefs.matcher.ParamDefLeaf)2 Pair (com.intellij.openapi.util.Pair)1 Nullable (org.jetbrains.annotations.Nullable)1 ParamDefHash (org.jetbrains.plugins.ruby.ruby.codeInsight.paramDefs.matcher.ParamDefHash)1 ParamDefSeq (org.jetbrains.plugins.ruby.ruby.codeInsight.paramDefs.matcher.ParamDefSeq)1