mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract XDebuggerEditorsProviderBase, init JavaBreakpointType (is not registered, so, not in action now)
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package org.jetbrains.java.debugger;
|
||||
|
||||
import com.intellij.ide.highlighter.JavaFileType;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.JavaCodeFragmentFactory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.xdebugger.evaluation.XDebuggerEditorsProviderBase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class JavaDebuggerEditorsProvider extends XDebuggerEditorsProviderBase {
|
||||
@NotNull
|
||||
@Override
|
||||
public FileType getFileType() {
|
||||
return JavaFileType.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PsiFile createExpressionCodeFragment(@NotNull Project project, @NotNull String text, @Nullable PsiElement context, boolean isPhysical) {
|
||||
return JavaCodeFragmentFactory.getInstance(project).createExpressionCodeFragment(text, context, null, isPhysical);
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package org.jetbrains.java.debugger.breakpoints;
|
||||
|
||||
import com.intellij.debugger.DebuggerBundle;
|
||||
import com.intellij.ide.highlighter.JavaFileType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.xdebugger.XDebuggerUtil;
|
||||
import com.intellij.xdebugger.breakpoints.XBreakpointProperties;
|
||||
import com.intellij.xdebugger.breakpoints.XLineBreakpoint;
|
||||
import com.intellij.xdebugger.breakpoints.XLineBreakpointType;
|
||||
import com.intellij.xdebugger.breakpoints.ui.XBreakpointGroupingRule;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class JavaBreakpointType extends XLineBreakpointType<XBreakpointProperties> {
|
||||
public JavaBreakpointType() {
|
||||
super("java", DebuggerBundle.message("java.breakpoint.title"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPutAt(@NotNull final VirtualFile file, final int line, @NotNull Project project) {
|
||||
return file.getFileType() == JavaFileType.INSTANCE;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public XBreakpointProperties createBreakpointProperties(@NotNull VirtualFile file, int line) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<XBreakpointGroupingRule<XLineBreakpoint<XBreakpointProperties>, ?>> getGroupingRules() {
|
||||
return XDebuggerUtil.getInstance().getGroupingByFileRuleAsList();
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package com.intellij.xdebugger.evaluation;
|
||||
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.xdebugger.XSourcePosition;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class XDebuggerEditorsProviderBase extends XDebuggerEditorsProvider {
|
||||
@NotNull
|
||||
@Override
|
||||
public final Document createDocument(@NotNull Project project, @NotNull String text, @Nullable XSourcePosition sourcePosition, @NotNull EvaluationMode mode) {
|
||||
PsiElement context = null;
|
||||
if (sourcePosition != null) {
|
||||
context = getContextElement(sourcePosition.getFile(), sourcePosition.getOffset(), project);
|
||||
}
|
||||
|
||||
PsiFile codeFragment = createExpressionCodeFragment(project, text, context, true);
|
||||
Document document = PsiDocumentManager.getInstance(project).getDocument(codeFragment);
|
||||
assert document != null;
|
||||
return document;
|
||||
}
|
||||
|
||||
protected abstract PsiFile createExpressionCodeFragment(@NotNull Project project, @NotNull String text, @Nullable PsiElement context, boolean isPhysical);
|
||||
|
||||
protected PsiElement getContextElement(@NotNull VirtualFile virtualFile, int offset, @NotNull Project project) {
|
||||
return doGetContextElement(virtualFile, offset, project);
|
||||
}
|
||||
|
||||
public static PsiElement doGetContextElement(@NotNull VirtualFile virtualFile, int offset, @NotNull Project project) {
|
||||
Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
|
||||
PsiFile file = PsiManager.getInstance(project).findFile(virtualFile);
|
||||
if (file == null || document == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (offset < 0) {
|
||||
offset = 0;
|
||||
}
|
||||
if (offset > document.getTextLength()) {
|
||||
offset = document.getTextLength();
|
||||
}
|
||||
int startOffset = offset;
|
||||
|
||||
int lineEndOffset = document.getLineEndOffset(document.getLineNumber(offset));
|
||||
PsiElement result = null;
|
||||
do {
|
||||
PsiElement element = file.findElementAt(offset);
|
||||
if (!(element instanceof PsiWhiteSpace) && !(element instanceof PsiComment)) {
|
||||
result = element;
|
||||
break;
|
||||
}
|
||||
|
||||
offset = element.getTextRange().getEndOffset() + 1;
|
||||
}
|
||||
while (offset < lineEndOffset);
|
||||
|
||||
if (result == null) {
|
||||
result = file.findElementAt(startOffset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -445,3 +445,5 @@ error.corrupt.debug.info=Debug info might be corrupt: {0}
|
||||
action.kill.process.text=Kill Process
|
||||
action.kill.process.description=Forcibly terminate debugged application
|
||||
evaluation.error.unknown.method.return.type=Cannot resolve method return type: {0}
|
||||
|
||||
java.breakpoint.title=Java Line Breakpoints
|
||||
|
||||
Reference in New Issue
Block a user