use of org.jetbrains.plugins.ruby.ruby.lang.psi.RPsiElement in project intellij-plugins by JetBrains.
the class MotionDebuggerTypesHelper method resolveToDeclaration.
@Override
public PsiElement resolveToDeclaration(XSourcePosition position, LLValue var) {
final String name = var.getName();
final VirtualFile file = position.getFile();
final int offset = position.getOffset();
final PsiFile psiFile = PsiManager.getInstance(myProcess.getProject()).findFile(file);
if (psiFile == null)
return null;
final PsiElement element = RubyPsiUtil.getSignificantLeafToTheRight(psiFile.findElementAt(offset));
final RContainer container = element != null ? RubyPsiUtil.getParentContainerOrSelf(element) : null;
if (container == null)
return null;
ScopeVariable variable = null;
for (ScopeVariable scopeVariable : container.getScope().getAllDeclaredVariables()) {
if (name.equals(scopeVariable.getName())) {
variable = scopeVariable;
break;
}
}
if (variable == null)
return null;
final RPsiElement item = ContainerUtil.getFirstItem(variable.getDeclarations());
if (item == null)
return null;
return item;
}
use of org.jetbrains.plugins.ruby.ruby.lang.psi.RPsiElement in project intellij-plugins by JetBrains.
the class RubyMotionTypeProvider method calculateObjCName.
private static String calculateObjCName(final String methodName, final List<RArgument> arguments) {
final StringBuilder objCNameBuilder = new StringBuilder(methodName).append(":");
for (RArgument argument : arguments) {
if (argument instanceof RNamedArgument) {
final RPsiElement nameIdentifier = ((RNamedArgument) argument).getNameIdentifier();
assert nameIdentifier != null;
objCNameBuilder.append(nameIdentifier.getName()).append(":");
}
}
return objCNameBuilder.toString();
}
use of org.jetbrains.plugins.ruby.ruby.lang.psi.RPsiElement in project intellij-plugins by JetBrains.
the class RubyMotionUtilImpl method doCalculateSdkAndFrameworks.
private Trinity<String, String[], ProjectType> doCalculateSdkAndFrameworks(RFile file) {
final ProjectType projectType = calculateProjectType(file);
final Ref<String> sdkVersion = new Ref<>(getDefaultSdkVersion(projectType));
final Set<String> frameworks = new HashSet<>();
Collections.addAll(frameworks, projectType == ProjectType.OSX ? DEFAULT_OSX_FRAMEWORKS : projectType == ProjectType.ANDROID ? DEFAULT_ANDROID_FRAMEWORKS : DEFAULT_IOS_FRAMEWORKS);
final RubyPsiInterpreter interpreter = new RubyPsiInterpreter(true);
final PsiCallable callable = new PsiCallable() {
@Override
public void processCall(RCallArguments arguments) {
final String command = arguments.getCommand();
RAssignmentExpression assign = RAssignmentExpressionNavigator.getAssignmentByLeftPart(arguments.getCallElement());
assign = assign == null ? RSelfAssignmentExpressionNavigator.getSelfAssignmentByLeftPart(arguments.getCallElement()) : assign;
RBinaryExpression shift = assign == null ? RShiftExpressionNavigator.getShiftExpressionByLeftPart(arguments.getCallElement()) : null;
final RPsiElement value = assign != null ? assign.getValue() : shift != null ? shift.getRightOperand() : null;
if (value == null) {
return;
}
final IElementType type = assign != null ? assign.getOperationType() : shift.getOperationType();
if ("sdk_version".equals(command)) {
sdkVersion.set(TextUtil.removeQuoting(value.getText()));
} else if ("frameworks".equals(command)) {
if (value instanceof RArray) {
final String[] array = TextUtil.arrayToString((RArray) value).split(", ");
if (type == RubyTokenTypes.tASSGN) {
frameworks.clear();
Collections.addAll(frameworks, array);
} else if (type == RubyTokenTypes.tMINUS_OP_ASGN) {
for (String s : array) {
frameworks.remove(s);
}
} else {
Collections.addAll(frameworks, array);
}
} else {
frameworks.add(TextUtil.removeQuoting(value.getText()));
}
}
}
};
interpreter.registerCallable(new PsiCallable() {
@Override
public void processCall(RCallArguments arguments) {
arguments.interpretBlock(callable);
}
}, "Motion::Project::App.setup");
interpreter.interpret(file, callable);
return Trinity.create(sdkVersion.get(), ArrayUtil.toStringArray(frameworks), projectType);
}
use of org.jetbrains.plugins.ruby.ruby.lang.psi.RPsiElement 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;
}
use of org.jetbrains.plugins.ruby.ruby.lang.psi.RPsiElement in project intellij-plugins by JetBrains.
the class SelectorKeysProvider method determineArgNumberAndPath.
private static Pair<Integer, List<String>> determineArgNumberAndPath(ParamContext context) {
final RPsiElement element = context.getValueElement();
final PsiElement parent = element.getParent();
final PsiElement argument = parent instanceof RAssoc ? parent : element;
final RListOfExpressions expressions = RListOfExpressionsNavigator.getByPsiElement(argument);
if (expressions == null)
return Pair.create(-1, null);
final List<String> path = new ArrayList<>();
for (int i = 1; i < expressions.getElements().size(); i++) {
PsiElement arg = expressions.getElements().get(i);
if (arg == argument)
return Pair.create(i, path);
if (arg instanceof RAssoc) {
path.add(((RAssoc) arg).getKeyText());
}
}
return Pair.create(-1, null);
}
Aggregations