use of org.jetbrains.plugins.ruby.motion.symbols.FunctionSymbol 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));
}
use of org.jetbrains.plugins.ruby.motion.symbols.FunctionSymbol 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;
}
use of org.jetbrains.plugins.ruby.motion.symbols.FunctionSymbol 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;
}
use of org.jetbrains.plugins.ruby.motion.symbols.FunctionSymbol in project intellij-plugins by JetBrains.
the class RubyMotionLightFixtureTestCase method checkResolveToObjC.
protected void checkResolveToObjC(final String signature, final String fqn) {
final PsiReference ref = findReferenceBySignature(signature);
final Symbol symbol = RubyTestUtil.resolveToSymbol(ref);
TestCase.assertTrue(symbol instanceof MotionClassSymbol || symbol instanceof FunctionSymbol);
TestCase.assertEquals(fqn, symbol.getFQNWithNesting().getFullPath());
}
use of org.jetbrains.plugins.ruby.motion.symbols.FunctionSymbol 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;
}
Aggregations