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 };
}
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;
}
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));
}
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;
}
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;
}
Aggregations