mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
pretty rendering for breakpoints in groovy code
This commit is contained in:
@@ -21,14 +21,12 @@ import com.intellij.debugger.engine.jdi.StackFrameProxy;
|
||||
import com.intellij.debugger.jdi.LocalVariableProxyImpl;
|
||||
import com.intellij.debugger.jdi.StackFrameProxyImpl;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.project.IndexNotReadyException;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.StringBuilderSpinAllocator;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.sun.jdi.Location;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -139,72 +137,7 @@ public class ContextUtil {
|
||||
|
||||
@Nullable
|
||||
public static PsiElement getContextElement(final SourcePosition position) {
|
||||
if(position == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return getContextElementInText(position.getFile(), position.getLine());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiElement getContextElementInText(PsiFile psiFile, int lineNumber) {
|
||||
if(lineNumber < 0) {
|
||||
return psiFile;
|
||||
}
|
||||
|
||||
final Document document = PsiDocumentManager.getInstance(psiFile.getProject()).getDocument(psiFile);
|
||||
if (document == null) {
|
||||
return null;
|
||||
}
|
||||
if (lineNumber >= document.getLineCount()) {
|
||||
return psiFile;
|
||||
}
|
||||
int startOffset = document.getLineStartOffset(lineNumber);
|
||||
if(startOffset == -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PsiElement element;
|
||||
|
||||
PsiElement rootElement = psiFile;
|
||||
|
||||
List<PsiFile> allFiles = psiFile.getViewProvider().getAllFiles();
|
||||
if (allFiles.size() > 1) { // jsp & gsp
|
||||
PsiClassOwner owner = ContainerUtil.findInstance(allFiles, PsiClassOwner.class);
|
||||
if (owner != null) {
|
||||
PsiClass[] classes = owner.getClasses();
|
||||
if (classes.length == 1 && classes[0] instanceof SyntheticElement) {
|
||||
rootElement = classes[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//final PsiElement rootElement = JspPsiUtil.isInJspFile(psiFile) ? (JspPsiUtil.getJspFile(psiFile)).getJavaClass() : psiFile;
|
||||
|
||||
while(true) {
|
||||
final CharSequence charsSequence = document.getCharsSequence();
|
||||
for (; startOffset < charsSequence.length(); startOffset++) {
|
||||
char c = charsSequence.charAt(startOffset);
|
||||
if (c != ' ' && c != '\t') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
element = rootElement.findElementAt(startOffset);
|
||||
|
||||
if(element instanceof PsiComment) {
|
||||
startOffset = element.getTextRange().getEndOffset() + 1;
|
||||
}
|
||||
else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (element != null && element.getParent() instanceof PsiForStatement) {
|
||||
return ((PsiForStatement)element.getParent()).getInitialization();
|
||||
}
|
||||
else {
|
||||
return element;
|
||||
}
|
||||
return position == null ? null :position.getElementAt();
|
||||
}
|
||||
|
||||
public static boolean isJspImplicit(PsiElement element) {
|
||||
|
||||
@@ -331,7 +331,7 @@ public class JVMNameUtil {
|
||||
}
|
||||
final PsiFile positionFile = position.getFile();
|
||||
if (positionFile instanceof JspFile) {
|
||||
return positionFile.getName() + ":" + position.getLine();
|
||||
return positionFile.getName();
|
||||
}
|
||||
|
||||
final PsiClass psiClass = getClassAt(position);
|
||||
@@ -350,6 +350,10 @@ public class JVMNameUtil {
|
||||
}
|
||||
}
|
||||
if (psiClass == null) {
|
||||
if (positionFile instanceof PsiClassOwner) {
|
||||
return positionFile.getName();
|
||||
}
|
||||
|
||||
return DebuggerBundle.message("string.file.line.position", positionFile.getName(), position.getLine());
|
||||
}
|
||||
return calcClassDisplayName(psiClass);
|
||||
|
||||
@@ -284,10 +284,11 @@ public class LineBreakpoint extends BreakpointWithHighlighter {
|
||||
if (hasClassInfo || hasMethodInfo) {
|
||||
final StringBuilder info = StringBuilderSpinAllocator.alloc();
|
||||
try {
|
||||
boolean isFile = getSourcePosition().getFile().getName().equals(className);
|
||||
String packageName = null;
|
||||
if (hasClassInfo) {
|
||||
final int dotIndex = className.lastIndexOf(".");
|
||||
if (dotIndex >= 0) {
|
||||
if (dotIndex >= 0 && !isFile) {
|
||||
info.append(className.substring(dotIndex + 1));
|
||||
packageName = className.substring(0, dotIndex);
|
||||
}
|
||||
@@ -296,7 +297,10 @@ public class LineBreakpoint extends BreakpointWithHighlighter {
|
||||
}
|
||||
}
|
||||
if(hasMethodInfo) {
|
||||
if (hasClassInfo) {
|
||||
if (isFile) {
|
||||
info.append(":");
|
||||
}
|
||||
else if (hasClassInfo) {
|
||||
info.append(".");
|
||||
}
|
||||
info.append(myMethodName);
|
||||
@@ -319,7 +323,7 @@ public class LineBreakpoint extends BreakpointWithHighlighter {
|
||||
if (file instanceof JspFile) {
|
||||
return null;
|
||||
}
|
||||
if (file instanceof PsiJavaFile) {
|
||||
if (file instanceof PsiClassOwner) {
|
||||
return ApplicationManager.getApplication().runReadAction(new Computable<String>() {
|
||||
public String compute() {
|
||||
final PsiMethod method = DebuggerUtilsEx.findPsiMethod(file, offset);
|
||||
|
||||
Reference in New Issue
Block a user