use of com.intellij.psi.JavaCodeFragment in project smali by JesusFreke.
the class SmaliCodeFragmentFactory method createPresentationCodeFragment.
@Override
public JavaCodeFragment createPresentationCodeFragment(TextWithImports item, PsiElement context, Project project) {
context = wrapContext(project, context);
JavaCodeFragment fragment = super.createPresentationCodeFragment(item, context, project);
List<LazyValue> lazyValues = context.getUserData(SMALI_LAZY_VALUES_KEY);
if (lazyValues != null) {
fragment.putUserData(SMALI_LAZY_VALUES_KEY, lazyValues);
}
return fragment;
}
use of com.intellij.psi.JavaCodeFragment in project smali by JesusFreke.
the class SmaliCodeFragmentFactoryTest method assertCompletionContains.
private void assertCompletionContains(String completionText, PsiElement context, String[] expectedItems, String[] disallowedItems) {
SmaliCodeFragmentFactory codeFragmentFactory = new SmaliCodeFragmentFactory();
JavaCodeFragment fragment = codeFragmentFactory.createCodeFragment(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, completionText), context, getProject());
Editor editor = createEditor(fragment.getVirtualFile());
editor.getCaretModel().moveToOffset(completionText.length());
new CodeCompletionHandlerBase(CompletionType.BASIC).invokeCompletion(getProject(), editor);
List<LookupElement> elements = LookupManager.getInstance(getProject()).getActiveLookup().getItems();
HashSet expectedSet = Sets.newHashSet(expectedItems);
HashSet disallowedSet = Sets.newHashSet(disallowedItems);
for (LookupElement element : elements) {
expectedSet.remove(element.toString());
Assert.assertFalse(disallowedSet.contains(element.toString()));
}
Assert.assertTrue(expectedSet.size() == 0);
}
use of com.intellij.psi.JavaCodeFragment in project intellij-community by JetBrains.
the class JavaExtractor method getDiffer.
@NotNull
@Override
public Differ getDiffer(final Project project, PsiFile psiFile, CodeStyleSettings settings) {
return new DifferBase(project, psiFile, settings) {
@Override
public String reformattedText() {
JavaCodeFragment file = JavaCodeFragmentFactory.getInstance(project).createCodeBlockCodeFragment(myOrigText, myFile, false);
WriteCommandAction.runWriteCommandAction(myProject, "CodeStyleSettings extractor", "CodeStyleSettings extractor", () -> {
ASTNode treeElement = SourceTreeToPsiMap.psiToTreeNotNull(file);
SourceTreeToPsiMap.treeElementToPsi(new CodeFormatterFacade(mySettings, file.getLanguage()).processElement(treeElement));
}, file);
return file.getText();
}
};
}
use of com.intellij.psi.JavaCodeFragment in project intellij-community by JetBrains.
the class CodeFragmentFactoryContextWrapper method wrapContext.
private PsiElement wrapContext(Project project, final PsiElement originalContext) {
if (project.isDefault())
return originalContext;
//TODO [egor] : does not work for anything other than java anyway, see IDEA-132677
if (!(myDelegate instanceof DefaultCodeFragmentFactory)) {
return originalContext;
}
PsiElement context = originalContext;
XDebugSession session = XDebuggerManager.getInstance(project).getCurrentSession();
if (session != null) {
XValueMarkers<?, ?> markers = ((XDebugSessionImpl) session).getValueMarkers();
Map<?, ValueMarkup> markupMap = markers != null ? markers.getAllMarkers() : null;
//final Map<ObjectReference, ValueMarkup> markupMap = ValueDescriptorImpl.getMarkupMap(process);
if (!ContainerUtil.isEmpty(markupMap)) {
final Pair<String, Map<String, ObjectReference>> markupVariables = createMarkupVariablesText(markupMap);
int offset = markupVariables.getFirst().length() - 1;
final TextWithImportsImpl textWithImports = new TextWithImportsImpl(CodeFragmentKind.CODE_BLOCK, markupVariables.getFirst(), "", myDelegate.getFileType());
final JavaCodeFragment codeFragment = myDelegate.createCodeFragment(textWithImports, context, project);
codeFragment.accept(new JavaRecursiveElementVisitor() {
public void visitLocalVariable(PsiLocalVariable variable) {
final String name = variable.getName();
variable.putUserData(LABEL_VARIABLE_VALUE_KEY, markupVariables.getSecond().get(name));
}
});
final PsiElement newContext = codeFragment.findElementAt(offset);
if (newContext != null) {
context = newContext;
}
}
}
return context;
}
Aggregations