Search in sources :

Example 1 with Symbol

use of org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.structure.Symbol in project intellij-plugins by JetBrains.

the class MotionSymbolUtil method createStructFieldSymbols.

public static Symbol[] createStructFieldSymbols(final Module module, Symbol parent, Struct struct, String name) {
    final String typeName = struct.getFieldType(name);
    final RType type = getTypeByName(module, typeName);
    final RTypedSyntheticSymbol reader = new RTypedSyntheticSymbol(module.getProject(), name, Type.FIELD_READER, parent, type, 0);
    final RTypedSyntheticSymbol writer = new RTypedSyntheticSymbol(module.getProject(), name + "=", Type.FIELD_WRITER, parent, type, 1);
    return new Symbol[] { reader, writer };
}
Also used : Symbol(org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.structure.Symbol) RTypedSyntheticSymbol(org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.structure.RTypedSyntheticSymbol) RType(org.jetbrains.plugins.ruby.ruby.codeInsight.types.RType) RTypedSyntheticSymbol(org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.structure.RTypedSyntheticSymbol)

Example 2 with Symbol

use of org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.structure.Symbol in project intellij-plugins by JetBrains.

the class MotionSymbolUtil method doGetTypeByName.

@NotNull
private static RType doGetTypeByName(@Nullable Module module, String typeName) {
    if (module == null) {
        return REmptyType.INSTANCE;
    }
    final Project project = module.getProject();
    if (typeName.endsWith("*")) {
        final RType type = doGetTypeByName(module, dereferencePointerType(typeName));
        if (type != REmptyType.INSTANCE || "void".equals(dereferencePointerType(typeName))) {
            return new RArrayType(project, type);
        }
    }
    final RType primitiveType = getPrimitiveType(project, typeName);
    if (primitiveType != null) {
        return primitiveType;
    }
    final Collection<Framework> frameworks = ((RubyMotionUtilImpl) RubyMotionUtil.getInstance()).getFrameworks(module);
    if (!typeName.endsWith("*")) {
        final Symbol symbol = RubyMotionSymbolProvider.findClassOrStruct(module, frameworks, FQN.Builder.fromString(typeName).asList());
        return symbol instanceof StructSymbol || (symbol != null && RubyMotionUtil.getInstance().isAndroid(module)) ? new RSymbolTypeImpl(symbol, Context.INSTANCE) : REmptyType.INSTANCE;
    }
    typeName = dereferencePointerType(typeName);
    final Symbol symbol = RubyMotionSymbolProvider.findClassOrStruct(module, frameworks, Collections.singletonList(typeName));
    return symbol != null ? new RSymbolTypeImpl(symbol, Context.INSTANCE) : REmptyType.INSTANCE;
}
Also used : RubyMotionUtilImpl(org.jetbrains.plugins.ruby.motion.RubyMotionUtilImpl) Project(com.intellij.openapi.project.Project) Symbol(org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.structure.Symbol) RTypedSyntheticSymbol(org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.structure.RTypedSyntheticSymbol) RType(org.jetbrains.plugins.ruby.ruby.codeInsight.types.RType) RArrayType(org.jetbrains.plugins.ruby.ruby.codeInsight.types.collections.RArrayType) RSymbolTypeImpl(org.jetbrains.plugins.ruby.ruby.codeInsight.types.impl.RSymbolTypeImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with Symbol

use of org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.structure.Symbol 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 4 with Symbol

use of org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.structure.Symbol 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 5 with Symbol

use of org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.structure.Symbol in project intellij-plugins by JetBrains.

the class RubyMotionSymbolProvider method findSymbol.

@Override
public Symbol findSymbol(@NotNull Symbol anchor, @NotNull FQN fqn, TypeSet types, @Nullable PsiElement invocationPoint) {
    if (!RubyMotionUtil.getInstance().hasMacRubySupport(invocationPoint))
        return null;
    final Module module = getModule(invocationPoint);
    if (module == null)
        return null;
    final Collection<Framework> frameworks = ((RubyMotionUtilImpl) RubyMotionUtil.getInstance()).getFrameworks(module);
    final List<String> nameAsList = fqn.asList();
    if (nameAsList.isEmpty()) {
        return null;
    }
    final String name = nameAsList.get(0);
    if (name.isEmpty())
        return null;
    if (types.contains(Type.CLASS)) {
        Symbol result = findClassOrStruct(module, frameworks, nameAsList);
        if (result != null) {
            return result;
        }
    }
    if (types.contains(Type.CLASS_METHOD)) {
        for (Framework framework : frameworks) {
            Function function = framework.getFunction(name);
            final String original = framework.getOriginalFunctionName(name);
            if (original != null) {
                function = framework.getFunction(original);
            }
            if (function != null) {
                return MotionSymbolUtil.createFunctionSymbol(module, null, function);
            }
        }
    }
    if (types.contains(Type.CONSTANT)) {
        for (Framework framework : frameworks) {
            Constant constant = findConstant(name, framework);
            if (constant != null) {
                return MotionSymbolUtil.createConstantSymbol(module, constant);
            }
        }
    }
    return null;
}
Also used : Symbol(org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.structure.Symbol) RModule(org.jetbrains.plugins.ruby.ruby.lang.psi.controlStructures.modules.RModule) Module(com.intellij.openapi.module.Module)

Aggregations

Symbol (org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.structure.Symbol)11 FunctionSymbol (org.jetbrains.plugins.ruby.motion.symbols.FunctionSymbol)5 MotionClassSymbol (org.jetbrains.plugins.ruby.motion.symbols.MotionClassSymbol)4 Nullable (org.jetbrains.annotations.Nullable)3 Function (org.jetbrains.plugins.ruby.motion.bridgesupport.Function)3 RModule (org.jetbrains.plugins.ruby.ruby.lang.psi.controlStructures.modules.RModule)3 Module (com.intellij.openapi.module.Module)2 ConstantSymbol (org.jetbrains.plugins.ruby.motion.symbols.ConstantSymbol)2 RTypedSyntheticSymbol (org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.structure.RTypedSyntheticSymbol)2 ClassModuleSymbol (org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.v2.ClassModuleSymbol)2 RType (org.jetbrains.plugins.ruby.ruby.codeInsight.types.RType)2 ClassMember (com.intellij.codeInsight.generation.ClassMember)1 MemberChooserObjectBase (com.intellij.codeInsight.generation.MemberChooserObjectBase)1 Project (com.intellij.openapi.project.Project)1 PsiElement (com.intellij.psi.PsiElement)1 PsiReference (com.intellij.psi.PsiReference)1 CocoaDocumentationManagerImpl (com.jetbrains.cidr.CocoaDocumentationManagerImpl)1 NotNull (org.jetbrains.annotations.NotNull)1 RubyMotionUtilImpl (org.jetbrains.plugins.ruby.motion.RubyMotionUtilImpl)1 MotionSymbol (org.jetbrains.plugins.ruby.motion.symbols.MotionSymbol)1