Search in sources :

Example 6 with Symbol

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

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

the class RubyMotionSymbolProvider method createSymbolByContainer.

@Override
public Symbol createSymbolByContainer(@NotNull RContainer container, @NotNull FQN fqn, @Nullable Symbol parent) {
    if (!RubyMotionUtil.getInstance().hasMacRubySupport(container))
        return null;
    final Module module = getModule(container);
    if (module == null)
        return null;
    final Symbol motionSymbol = getCachedSpecificSymbol(container, container);
    if (motionSymbol != null) {
        return motionSymbol;
    }
    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)

Example 8 with Symbol

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

the class RubyMotionSymbolProvider method getSpecificSymbol.

@Nullable
@Override
protected Symbol getSpecificSymbol(PsiElement element, RContainer context) {
    if (context instanceof RClass || context instanceof RModule) {
        final boolean isObject = CoreTypes.Object.equals(context.getFQN().getFullPath());
        final RubyMotionSymbol symbol = isObject ? new RubyMotionSymbol((RFile) context.getContainingFile()) : null;
        final Symbol nsObject = SymbolUtil.findSymbol(element.getProject(), Type.CLASS, getParentName(context), element);
        final List<Symbol> includes = isObject ? Collections.singletonList(symbol) : Collections.emptyList();
        return new MotionEnabledClassModuleSymbol(context, includes, Collections.emptyList(), Collections.singletonList(nsObject));
    }
    return null;
}
Also used : RModule(org.jetbrains.plugins.ruby.ruby.lang.psi.controlStructures.modules.RModule) RClass(org.jetbrains.plugins.ruby.ruby.lang.psi.controlStructures.classes.RClass) Symbol(org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.structure.Symbol) RFile(org.jetbrains.plugins.ruby.ruby.lang.psi.RFile) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with Symbol

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

the class RubyMotionUtilImpl method getMotionDoc.

@Nullable
public String getMotionDoc(PsiElement targetElement, @Nullable Symbol targetSymbol) {
    String descriptionText;
    final MotionSymbol motionSymbol = (MotionSymbol) targetSymbol;
    CocoaDocumentationManagerImpl.DocTokenType type = motionSymbol.getInfoType();
    CocoaDocumentationManagerImpl manager = (CocoaDocumentationManagerImpl) CocoaDocumentationManager.getInstance(targetSymbol.getProject());
    final Symbol parent = targetSymbol.getParentSymbol();
    final String parentName = parent != null ? parent.getName() : null;
    final CocoaDocumentationManagerImpl.DocumentationBean info = manager.getTokenInfo(targetElement, motionSymbol.getInfoName(), Collections.singletonList(Pair.create(parentName, type)));
    descriptionText = info != null ? patchObjCDoc(info.html, motionSymbol) : null;
    return descriptionText;
}
Also used : MotionSymbol(org.jetbrains.plugins.ruby.motion.symbols.MotionSymbol) CocoaDocumentationManagerImpl(com.jetbrains.cidr.CocoaDocumentationManagerImpl) MotionClassSymbol(org.jetbrains.plugins.ruby.motion.symbols.MotionClassSymbol) MotionSymbol(org.jetbrains.plugins.ruby.motion.symbols.MotionSymbol) FunctionSymbol(org.jetbrains.plugins.ruby.motion.symbols.FunctionSymbol) Symbol(org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.structure.Symbol) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with Symbol

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

the class RubyMotionOverrideTest method doTest.

private void doTest(@NotNull final String name, @NotNull final String result) throws Exception {
    final Symbol controller = SymbolUtil.findSymbol(getProject(), Type.CLASS, "TestController", null);
    assertNotNull(controller);
    final List<ClassMember> list = RubyOverrideHandler.createOverrideMembers(controller, myFixture.getFile());
    final StringBuilder namesInClass = new StringBuilder();
    for (ClassMember classMember : list) {
        MemberChooserObjectBase methodMember = (MemberChooserObjectBase) classMember;
        if (name.equals(methodMember.getText())) {
            final PsiElement element = OverriddenMethodGenerator.generate(classMember, LanguageLevel.RUBY19);
            assertNotNull(element);
            namesInClass.append(element.getText()).append("\n");
        }
    }
    assertEquals(result, namesInClass.toString().trim());
}
Also used : MemberChooserObjectBase(com.intellij.codeInsight.generation.MemberChooserObjectBase) Symbol(org.jetbrains.plugins.ruby.ruby.codeInsight.symbols.structure.Symbol) ClassMember(com.intellij.codeInsight.generation.ClassMember) PsiElement(com.intellij.psi.PsiElement)

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