Search in sources :

Example 1 with Function

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

the class RubyMotionCompletionProvider method createLookupItem.

private static LookupElement createLookupItem(@NotNull final FunctionSymbol symbol, final boolean bold, final boolean isInsertHandlerCanBeApplied) {
    final Symbol parent = symbol.getParentSymbol();
    if (parent == null || !isInsertHandlerCanBeApplied)
        return null;
    final Function function = symbol.getFunction();
    if (function.getArguments().size() < 2 || !function.getName().contains(":"))
        return null;
    return new RubyLookupElement(function.getName(), "", parent.getFQNWithNesting().getFullPath(), bold, AllIcons.Nodes.Method, null, new SelectorInsertHandler(function));
}
Also used : Function(org.jetbrains.plugins.ruby.motion.bridgesupport.Function) FunctionSymbol(org.jetbrains.plugins.ruby.motion.symbols.FunctionSymbol) Symbol(org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.structure.Symbol) RubyLookupElement(org.jetbrains.plugins.ruby.ruby.codeInsight.completion.RubyLookupElement)

Example 2 with Function

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

Example 3 with Function

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

the class RubyMotionUtilImpl method patchObjCDoc.

private static String patchObjCDoc(String html, MotionSymbol symbol) {
    if (symbol instanceof FunctionSymbol) {
        final FunctionSymbol fSymbol = (FunctionSymbol) symbol;
        final Function function = fSymbol.getFunction();
        final List<Pair<String, String>> arguments = function.getArguments();
        if (arguments.size() > 0) {
            for (Pair<String, String> argument : arguments) {
                html = html.replace("<code>" + argument.first + ":</code>", SPACE + SPACE + "<code>" + argument.first + "</code>: (" + getPresentableObjCType(fSymbol.getModule(), argument.second) + ") ");
            }
        }
    }
    // remove links
    html = html.replaceAll("<a href=[^>]*>", "");
    html = html.replaceAll("</a>", "");
    // remove declaration
    html = html.replaceAll("<p><b>Declaration:</b> <PRE>[^>]*</PRE></p>", "");
    html = html.replaceAll("<p><b>Declared In:</b> [^>]*</p>", "");
    return html;
}
Also used : Function(org.jetbrains.plugins.ruby.motion.bridgesupport.Function) FunctionSymbol(org.jetbrains.plugins.ruby.motion.symbols.FunctionSymbol)

Example 4 with Function

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

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

the class SelectorKeysProvider method getFunctions.

@Nullable
private Collection<Function> getFunctions(ParamContext context) {
    final Module module = context.getModule();
    if (module == null)
        return null;
    final String version = RubyMotionUtil.getInstance().getSdkVersion(module);
    final Collection<Function> functions = mySelectors.get(version);
    if (functions == null)
        return null;
    return functions;
}
Also used : Function(org.jetbrains.plugins.ruby.motion.bridgesupport.Function) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

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