use of com.intellij.codeInsight.codeFragment.CodeFragment in project intellij-community by JetBrains.
the class PyCodeFragmentTest method check.
private void check(final PyFile myFile, final int beginMarker, final int endMarker, final String result) {
final PsiElement startElement = myFile.findElementAt(beginMarker);
final PsiElement endElement = myFile.findElementAt(endMarker - BEGIN_MARKER.length());
PsiElement context = PsiTreeUtil.findCommonParent(startElement, endElement);
if (!(context instanceof ScopeOwner)) {
context = PsiTreeUtil.getParentOfType(context, ScopeOwner.class);
}
final StringBuffer buffer = new StringBuffer();
try {
final CodeFragment fragment = PyCodeFragmentUtil.createCodeFragment((ScopeOwner) context, startElement, endElement);
if (fragment.isReturnInstructionInside()) {
buffer.append("Return instruction inside found").append("\n");
}
buffer.append("In:\n");
for (String inputVariable : new TreeSet<>(fragment.getInputVariables())) {
buffer.append(inputVariable).append('\n');
}
buffer.append("Out:\n");
for (String outputVariable : new TreeSet<>(fragment.getOutputVariables())) {
buffer.append(outputVariable).append('\n');
}
} catch (CannotCreateCodeFragmentException e) {
assertEquals(result.trim(), e.getMessage());
return;
}
assertEquals(result.trim(), buffer.toString().trim());
}
Aggregations