diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/CodeFragmentFactoryContextWrapper.java b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/CodeFragmentFactoryContextWrapper.java index 974837765663..7d166e39485c 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/CodeFragmentFactoryContextWrapper.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/CodeFragmentFactoryContextWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,10 +22,7 @@ import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.JavaCodeFragment; -import com.intellij.psi.JavaRecursiveElementVisitor; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiLocalVariable; +import com.intellij.psi.*; import com.intellij.psi.search.DelegatingGlobalSearchScope; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.util.StringBuilderSpinAllocator; @@ -104,21 +101,19 @@ public class CodeFragmentFactoryContextWrapper extends CodeFragmentFactory { if (session != null) { XValueMarkers markers = ((XDebugSessionImpl)session).getValueMarkers(); Map markupMap = markers != null ? markers.getAllMarkers() : null; - //final Map markupMap = ValueDescriptorImpl.getMarkupMap(process); if (!ContainerUtil.isEmpty(markupMap)) { - final Pair> 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; + Pair> markupVariables = createMarkupVariablesText(markupMap); + String text = markupVariables.getFirst(); + if (!StringUtil.isEmpty(text)) { + PsiCodeBlock codeFragment = + JavaPsiFacade.getInstance(project).getElementFactory().createCodeBlockFromText("{" + text + "}", context); + codeFragment.accept(new JavaRecursiveElementVisitor() { + public void visitLocalVariable(PsiLocalVariable variable) { + final String name = variable.getName(); + variable.putUserData(LABEL_VARIABLE_VALUE_KEY, markupVariables.getSecond().get(name)); + } + }); + context = codeFragment; } } } @@ -149,7 +144,6 @@ public class CodeFragmentFactoryContextWrapper extends CodeFragmentFactory { //it.remove(); } } - buffer.append(" "); return Pair.create(buffer.toString(), reverseMap); } finally {