use of com.intellij.psi.JavaCodeFragmentFactory in project intellij-community by JetBrains.
the class ExtractMethodObject4DebuggerTest method doTest.
private void doTest(String evaluatedText, String expectedCallSite, String expectedClass, boolean codeBlock) throws Exception {
final String testName = getTestName(false);
configureByFile("/refactoring/extractMethodObject4Debugger/" + testName + ".java");
final int offset = getEditor().getCaretModel().getOffset();
final PsiElement context = getFile().findElementAt(offset);
final JavaCodeFragmentFactory fragmentFactory = JavaCodeFragmentFactory.getInstance(getProject());
final JavaCodeFragment fragment = codeBlock ? fragmentFactory.createCodeBlockCodeFragment(evaluatedText, context, false) : fragmentFactory.createExpressionCodeFragment(evaluatedText, context, null, false);
final ExtractLightMethodObjectHandler.ExtractedData extractedData = ExtractLightMethodObjectHandler.extractLightMethodObject(getProject(), context, fragment, "test");
assertNotNull(extractedData);
assertEquals(expectedCallSite, extractedData.getGeneratedCallText());
final PsiClass innerClass = extractedData.getGeneratedInnerClass();
assertEquals(expectedClass, innerClass.getText());
}
use of com.intellij.psi.JavaCodeFragmentFactory in project intellij-community by JetBrains.
the class JavaFormatterTest method testFormatCodeFragment.
public void testFormatCodeFragment() throws Exception {
final JavaCodeFragmentFactory factory = JavaCodeFragmentFactory.getInstance(getProject());
final PsiCodeFragment fragment = factory.createCodeBlockCodeFragment("a=1;int b=2;", null, true);
final PsiElement[] result = new PsiElement[1];
CommandProcessor.getInstance().executeCommand(getProject(), () -> WriteCommandAction.runWriteCommandAction(null, () -> {
try {
result[0] = CodeStyleManager.getInstance(getProject()).reformat(fragment);
} catch (IncorrectOperationException e) {
fail(e.getLocalizedMessage());
}
}), null, null);
assertEquals("a = 1;\n" + "int b = 2;", result[0].getText());
}
Aggregations