mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
minor refactoring to avoid NPEs
This commit is contained in:
@@ -110,7 +110,7 @@ public class JumpToObjectAction extends DebuggerAction{
|
||||
SourcePosition position = debugProcess.getPositionManager().getSourcePosition(location);
|
||||
// adjust position for non-anonymous classes
|
||||
if (clsType.name().indexOf('$') < 0) {
|
||||
final PsiClass classAt = position != null? JVMNameUtil.getClassAt(position) : null;
|
||||
final PsiClass classAt = JVMNameUtil.getClassAt(position);
|
||||
if (classAt != null) {
|
||||
final SourcePosition classPosition = SourcePosition.createFromElement(classAt);
|
||||
if (classPosition != null) {
|
||||
|
||||
@@ -259,9 +259,6 @@ public class JVMNameUtil {
|
||||
|
||||
@Nullable
|
||||
public static JVMName getContextClassJVMQualifiedName(@Nullable SourcePosition pos) {
|
||||
if (pos == null) {
|
||||
return null;
|
||||
}
|
||||
final PsiClass psiClass = getClassAt(pos);
|
||||
if (psiClass == null) {
|
||||
return null;
|
||||
@@ -319,13 +316,16 @@ public class JVMNameUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiClass getClassAt(SourcePosition position) {
|
||||
public static PsiClass getClassAt(@Nullable SourcePosition position) {
|
||||
if (position == null) {
|
||||
return null;
|
||||
}
|
||||
final PsiElement element = position.getElementAt();
|
||||
return (element != null) ? PsiTreeUtil.getParentOfType(element, PsiClass.class, false) : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getSourcePositionClassDisplayName(DebugProcessImpl debugProcess, SourcePosition position) {
|
||||
public static String getSourcePositionClassDisplayName(DebugProcessImpl debugProcess, @Nullable SourcePosition position) {
|
||||
if (position == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -391,7 +391,7 @@ public class JVMNameUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getSourcePositionPackageDisplayName(DebugProcessImpl debugProcess, SourcePosition position) {
|
||||
public static String getSourcePositionPackageDisplayName(DebugProcessImpl debugProcess, @Nullable SourcePosition position) {
|
||||
if (position == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -240,8 +240,8 @@ public class PositionHighlighter {
|
||||
if (breakpoint instanceof BreakpointWithHighlighter) {
|
||||
if (((BreakpointWithHighlighter)breakpoint).isVisible() && breakpoint.isValid()) {
|
||||
breakpoint.reload();
|
||||
final SourcePosition sourcePosition = ((BreakpointWithHighlighter)breakpoint).getSourcePosition();
|
||||
if (sourcePosition == null || sourcePosition.getLine() != lineIndex) {
|
||||
int bptLine = ((BreakpointWithHighlighter)breakpoint).getLineIndex();
|
||||
if (bptLine < 0 || bptLine != lineIndex) {
|
||||
eventsOutOfLine.add(eventDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +91,7 @@ public abstract class Breakpoint<P extends JavaBreakpointProperties> implements
|
||||
return myXBreakpoint.getProperties();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public abstract PsiClass getPsiClass();
|
||||
/**
|
||||
* Request for creating all needed JPDA requests in the specified VM
|
||||
@@ -474,6 +475,7 @@ public abstract class Breakpoint<P extends JavaBreakpointProperties> implements
|
||||
// myLogMessage = logMessage;
|
||||
//}
|
||||
|
||||
@Nullable
|
||||
public abstract PsiElement getEvaluationElement();
|
||||
|
||||
protected TextWithImports getLogMessage() {
|
||||
|
||||
+7
-2
@@ -418,7 +418,7 @@ public abstract class BreakpointWithHighlighter<P extends JavaBreakpointProperti
|
||||
return getPsiClassAt(sourcePosition);
|
||||
}
|
||||
|
||||
protected static PsiClass getPsiClassAt(final SourcePosition sourcePosition) {
|
||||
protected static PsiClass getPsiClassAt(@Nullable final SourcePosition sourcePosition) {
|
||||
return ApplicationManager.getApplication().runReadAction(new Computable<PsiClass>() {
|
||||
@Nullable
|
||||
@Override
|
||||
@@ -507,10 +507,15 @@ public abstract class BreakpointWithHighlighter<P extends JavaBreakpointProperti
|
||||
}
|
||||
|
||||
public int getLineIndex() {
|
||||
final SourcePosition sourcePosition = getSourcePosition();
|
||||
XSourcePosition sourcePosition = myXBreakpoint.getSourcePosition();
|
||||
return sourcePosition != null ? sourcePosition.getLine() : -1;
|
||||
}
|
||||
|
||||
protected String getFileName() {
|
||||
XSourcePosition sourcePosition = myXBreakpoint.getSourcePosition();
|
||||
return sourcePosition != null ? sourcePosition.getFile().getName() : "";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected static RangeHighlighter createHighlighter(@NotNull Project project, @NotNull Document document, int lineIndex) {
|
||||
if (lineIndex < 0 || lineIndex >= document.getLineCount()) {
|
||||
|
||||
@@ -218,7 +218,7 @@ public class FieldBreakpoint extends BreakpointWithHighlighter<JavaFieldBreakpoi
|
||||
locationFileName = location.sourceName();
|
||||
}
|
||||
catch (AbsentInformationException e) {
|
||||
locationFileName = getSourcePosition().getFile().getName();
|
||||
locationFileName = getFileName();
|
||||
}
|
||||
final int locationLine = location.lineNumber();
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ import com.intellij.util.Processor;
|
||||
import com.intellij.util.StringBuilderSpinAllocator;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.xdebugger.XDebuggerUtil;
|
||||
import com.intellij.xdebugger.XSourcePosition;
|
||||
import com.intellij.xdebugger.breakpoints.XBreakpoint;
|
||||
import com.sun.jdi.*;
|
||||
import com.sun.jdi.event.LocatableEvent;
|
||||
@@ -123,7 +124,7 @@ public class LineBreakpoint extends BreakpointWithHighlighter {
|
||||
@Override
|
||||
protected void reload(PsiFile file) {
|
||||
super.reload(file);
|
||||
final SourcePosition position = getSourcePosition();
|
||||
XSourcePosition position = myXBreakpoint.getSourcePosition();
|
||||
if (position != null) {
|
||||
int offset = position.getOffset();
|
||||
myOwnerMethodName = findOwnerMethod(file, offset);
|
||||
@@ -419,7 +420,7 @@ public class LineBreakpoint extends BreakpointWithHighlighter {
|
||||
sourceName = location.sourceName();
|
||||
}
|
||||
catch (AbsentInformationException e) {
|
||||
sourceName = getSourcePosition().getFile().getName();
|
||||
sourceName = getFileName();
|
||||
}
|
||||
|
||||
final boolean printFullTrace = Registry.is("debugger.breakpoint.message.full.trace");
|
||||
|
||||
@@ -184,7 +184,7 @@ public class MethodBreakpoint extends BreakpointWithHighlighter<JavaMethodBreakp
|
||||
locationFileName = location.sourceName();
|
||||
}
|
||||
catch (AbsentInformationException e) {
|
||||
locationFileName = getSourcePosition().getFile().getName();
|
||||
locationFileName = getFileName();
|
||||
}
|
||||
final int locationLine = location.lineNumber();
|
||||
if (event instanceof MethodEntryEvent) {
|
||||
|
||||
+2
-1
@@ -32,7 +32,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
*/
|
||||
public class RunToCursorBreakpoint extends LineBreakpoint {
|
||||
private final boolean myRestoreBreakpoints;
|
||||
private final SourcePosition myCustomPosition;
|
||||
@NotNull
|
||||
protected final SourcePosition myCustomPosition;
|
||||
private String mySuspendPolicy;
|
||||
|
||||
protected RunToCursorBreakpoint(@NotNull Project project, @NotNull SourcePosition pos, boolean restoreBreakpoints) {
|
||||
|
||||
@@ -48,17 +48,16 @@ public class StepIntoBreakpoint extends RunToCursorBreakpoint {
|
||||
protected void createRequestForPreparedClass(DebugProcessImpl debugProcess, ReferenceType classType) {
|
||||
try {
|
||||
final CompoundPositionManager positionManager = debugProcess.getPositionManager();
|
||||
final SourcePosition startPosition = getSourcePosition();
|
||||
List<Location> locations = positionManager.locationsOfLine(classType, startPosition);
|
||||
List<Location> locations = positionManager.locationsOfLine(classType, myCustomPosition);
|
||||
|
||||
if (locations.isEmpty()) {
|
||||
// sometimes first statements are mapped to some weird line number, or there are no executable instructions at first statement's line
|
||||
// so if lambda or method body spans for more than one lines, try get some locations from these lines
|
||||
final int lastLine = myFilter.getLastStatementLine();
|
||||
if (lastLine >= 0) {
|
||||
int nextLine = startPosition.getLine() + 1;
|
||||
int nextLine = myCustomPosition.getLine() + 1;
|
||||
while (nextLine <= lastLine && locations.isEmpty()) {
|
||||
locations = positionManager.locationsOfLine(classType, SourcePosition.createFromLine(startPosition.getFile(), nextLine++));
|
||||
locations = positionManager.locationsOfLine(classType, SourcePosition.createFromLine(myCustomPosition.getFile(), nextLine++));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,9 +109,7 @@ public class FieldDescriptorImpl extends ValueDescriptorImpl implements FieldDes
|
||||
// important: use the last location to be sure the position will be within the anonymous class
|
||||
final Location lastLocation = locations.get(locations.size() - 1);
|
||||
final SourcePosition position = debugProcess.getPositionManager().getSourcePosition(lastLocation);
|
||||
if (position != null) {
|
||||
aClass = JVMNameUtil.getClassAt(position);
|
||||
}
|
||||
aClass = JVMNameUtil.getClassAt(position);
|
||||
}
|
||||
}
|
||||
catch (AbsentInformationException ignored) {
|
||||
|
||||
Reference in New Issue
Block a user