use of com.jetbrains.python.psi.impl.PyExpressionCodeFragmentImpl in project intellij-community by JetBrains.
the class PyConsoleSpecificOptionsPanel method createDocument.
@NotNull
public static Document createDocument(@NotNull final Project project, @NotNull String text) {
text = text.trim();
final PyExpressionCodeFragmentImpl fragment = new PyExpressionCodeFragmentImpl(project, "start_script.py", text, true);
return PsiDocumentManager.getInstance(project).getDocument(fragment);
}
use of com.jetbrains.python.psi.impl.PyExpressionCodeFragmentImpl in project intellij-community by JetBrains.
the class PyDebuggerEditorsProvider method createDocument.
@NotNull
@Override
public Document createDocument(@NotNull final Project project, @NotNull String text, @Nullable final XSourcePosition sourcePosition, @NotNull EvaluationMode mode) {
text = text.trim();
final PyExpressionCodeFragmentImpl fragment = new PyExpressionCodeFragmentImpl(project, "fragment.py", text, true);
// Bind to context
final PsiElement element = getContextElement(project, sourcePosition);
fragment.setContext(element);
return PsiDocumentManager.getInstance(project).getDocument(fragment);
}
use of com.jetbrains.python.psi.impl.PyExpressionCodeFragmentImpl in project intellij-community by JetBrains.
the class NumpyDocStringTypeProvider method getNominalType.
/**
* Converts literal into type, e.g. -1 -> int, 'fro' -> str
*/
@Nullable
private static PyType getNominalType(@NotNull PsiElement anchor, @NotNull String typeString) {
final PyExpressionCodeFragmentImpl codeFragment = new PyExpressionCodeFragmentImpl(anchor.getProject(), "dummy.py", typeString, false);
final PsiElement element = codeFragment.getFirstChild();
if (element instanceof PyExpressionStatement) {
final PyExpression expression = ((PyExpressionStatement) element).getExpression();
final PyBuiltinCache builtinCache = PyBuiltinCache.getInstance(anchor);
if (expression instanceof PyStringLiteralExpression) {
return builtinCache.getStrType();
}
if (expression instanceof PyNumericLiteralExpression) {
return builtinCache.getIntType();
}
}
return null;
}
use of com.jetbrains.python.psi.impl.PyExpressionCodeFragmentImpl in project intellij-community by JetBrains.
the class PyUnresolvedReferencesInspectionTest method doEvaluateExpressionTest.
protected void doEvaluateExpressionTest(@NotNull VirtualFile mainFile, @NotNull String expression, int lineNumber) {
PsiElement element = PyDebuggerEditorsProvider.getContextElement(myFixture.getProject(), XSourcePositionImpl.create(mainFile, lineNumber));
final PyExpressionCodeFragmentImpl fragment = new PyExpressionCodeFragmentImpl(myFixture.getProject(), "fragment.py", expression, true);
fragment.setContext(element);
myFixture.configureFromExistingVirtualFile(fragment.getVirtualFile());
myFixture.enableInspections(getInspectionClass());
myFixture.checkHighlighting(isWarning(), isInfo(), isWeakWarning());
}
use of com.jetbrains.python.psi.impl.PyExpressionCodeFragmentImpl in project intellij-community by JetBrains.
the class PyTypingTypeProvider method getStringBasedType.
@Nullable
private static Ref<PyType> getStringBasedType(@NotNull String contents, @NotNull PsiElement anchor, @NotNull Context context) {
final Project project = anchor.getProject();
final PyExpressionCodeFragmentImpl codeFragment = new PyExpressionCodeFragmentImpl(project, "dummy.py", contents, false);
codeFragment.setContext(anchor.getContainingFile());
final PsiElement element = codeFragment.getFirstChild();
if (element instanceof PyExpressionStatement) {
final PyExpression expr = ((PyExpressionStatement) element).getExpression();
if (expr instanceof PyTupleExpression) {
final PyTupleExpression tupleExpr = (PyTupleExpression) expr;
final List<PyType> elementTypes = ContainerUtil.map(tupleExpr.getElements(), elementExpr -> Ref.deref(getType(elementExpr, context)));
return Ref.create(PyTupleType.create(anchor, elementTypes));
}
return getType(expr, context);
}
return null;
}
Aggregations