mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-150258 Debugger: couldn't set line breakpoint in static initializer at line with lambda
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -67,8 +67,7 @@ public class JavaSmartStepIntoHandler extends JvmSmartStepIntoHandler {
|
||||
}
|
||||
TextRange curLineRange = DocumentUtil.getLineTextRange(doc, line);
|
||||
PsiElement element = position.getElementAt();
|
||||
PsiParameterListOwner method = DebuggerUtilsEx.getContainingMethod(element);
|
||||
PsiElement body = method != null ? method.getBody() : null;
|
||||
PsiElement body = DebuggerUtilsEx.getBody(DebuggerUtilsEx.getContainingMethod(element));
|
||||
final TextRange lineRange = (body != null) ? curLineRange.intersection(body.getTextRange()) : curLineRange;
|
||||
|
||||
if (lineRange == null || lineRange.isEmpty()) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -73,7 +73,7 @@ public class BasicStepMethodFilter implements NamedMethodFilter {
|
||||
lambdaMatched = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
|
||||
@Override
|
||||
public Boolean compute() {
|
||||
PsiParameterListOwner psiMethod = DebuggerUtilsEx.getContainingMethod(process.getPositionManager().getSourcePosition(location));
|
||||
PsiElement psiMethod = DebuggerUtilsEx.getContainingMethod(process.getPositionManager().getSourcePosition(location));
|
||||
if (psiMethod instanceof PsiLambdaExpression) {
|
||||
PsiType type = ((PsiLambdaExpression)psiMethod).getFunctionalInterfaceType();
|
||||
PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(type);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -230,14 +230,14 @@ public class PositionManagerImpl implements PositionManager, MultiRequestPositio
|
||||
if (name != null && !name.equals(myExpectedClassName)) {
|
||||
return null;
|
||||
}
|
||||
PsiParameterListOwner method = DebuggerUtilsEx.getContainingMethod(element);
|
||||
PsiElement method = DebuggerUtilsEx.getContainingMethod(element);
|
||||
if (!StringUtil.isEmpty(myExpectedMethodName)) {
|
||||
if (method == null) {
|
||||
return null;
|
||||
}
|
||||
else if (((method instanceof PsiMethod && myExpectedMethodName.equals(((PsiMethod)method).getName())) ||
|
||||
(method instanceof PsiLambdaExpression && LambdaMethodFilter.isLambdaName(myExpectedMethodName))) &&
|
||||
insideBody(element, method.getBody())) {
|
||||
insideBody(element, DebuggerUtilsEx.getBody(method))) {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -845,6 +845,25 @@ public abstract class DebuggerUtilsEx extends DebuggerUtils {
|
||||
return lambdas;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiElement getBody(PsiElement method) {
|
||||
if (method instanceof PsiParameterListOwner) {
|
||||
return ((PsiParameterListOwner)method).getBody();
|
||||
}
|
||||
else if (method instanceof PsiClassInitializer) {
|
||||
return ((PsiClassInitializer)method).getBody();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PsiParameter[] getParameters(PsiElement method) {
|
||||
if (method instanceof PsiParameterListOwner) {
|
||||
return ((PsiParameterListOwner)method).getParameterList().getParameters();
|
||||
}
|
||||
return PsiParameter.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
public static boolean intersects(@NotNull TextRange range, @NotNull PsiElement elem) {
|
||||
TextRange elemRange = elem.getTextRange();
|
||||
return elemRange != null && elemRange.intersects(range);
|
||||
@@ -888,12 +907,12 @@ public abstract class DebuggerUtilsEx extends DebuggerUtils {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiParameterListOwner getContainingMethod(@Nullable PsiElement elem) {
|
||||
return PsiTreeUtil.getContextOfType(elem, PsiMethod.class, PsiLambdaExpression.class);
|
||||
public static PsiElement getContainingMethod(@Nullable PsiElement elem) {
|
||||
return PsiTreeUtil.getContextOfType(elem, PsiMethod.class, PsiLambdaExpression.class, PsiClassInitializer.class);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiParameterListOwner getContainingMethod(@Nullable SourcePosition position) {
|
||||
public static PsiElement getContainingMethod(@Nullable SourcePosition position) {
|
||||
if (position == null) return null;
|
||||
return getContainingMethod(position.getElementAt());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -323,18 +323,15 @@ public class LocalVariablesUtil {
|
||||
SourcePosition position = ContextUtil.getSourcePosition(context);
|
||||
if (position != null) {
|
||||
PsiElement element = position.getElementAt();
|
||||
PsiParameterListOwner method = DebuggerUtilsEx.getContainingMethod(element);
|
||||
PsiElement method = DebuggerUtilsEx.getContainingMethod(element);
|
||||
if (method != null) {
|
||||
PsiParameterList params = method.getParameterList();
|
||||
MultiMap<Integer, String> res = new MultiMap<Integer, String>();
|
||||
int psiFirstLocalsSlot = getFirstLocalsSlot(method);
|
||||
int slot = Math.max(0, firstLocalsSlot - psiFirstLocalsSlot);
|
||||
for (int i = 0; i < params.getParametersCount(); i++) {
|
||||
PsiParameter parameter = params.getParameters()[i];
|
||||
int slot = Math.max(0, firstLocalsSlot - getFirstLocalsSlot(method));
|
||||
for (PsiParameter parameter : DebuggerUtilsEx.getParameters(method)) {
|
||||
res.putValue(slot, parameter.getName());
|
||||
slot += getTypeSlotSize(parameter.getType());
|
||||
}
|
||||
PsiElement body = method.getBody();
|
||||
PsiElement body = DebuggerUtilsEx.getBody(method);
|
||||
if (body != null) {
|
||||
try {
|
||||
body.accept(new LocalVariableNameFinder(firstLocalsSlot, res, element));
|
||||
@@ -481,13 +478,12 @@ public class LocalVariablesUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static int getFirstLocalsSlot(PsiParameterListOwner method) {
|
||||
private static int getFirstLocalsSlot(PsiElement method) {
|
||||
int startSlot = 0;
|
||||
if (method instanceof PsiModifierListOwner) {
|
||||
startSlot = ((PsiModifierListOwner)method).hasModifierProperty(PsiModifier.STATIC) ? 0 : 1;
|
||||
}
|
||||
PsiParameterList params = method.getParameterList();
|
||||
for (PsiParameter parameter : params.getParameters()) {
|
||||
for (PsiParameter parameter : DebuggerUtilsEx.getParameters(method)) {
|
||||
startSlot += getTypeSlotSize(parameter.getType());
|
||||
}
|
||||
return startSlot;
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -123,7 +123,7 @@ public class JavaLineBreakpointType extends JavaLineBreakpointTypeBase<JavaLineB
|
||||
List<JavaBreakpointVariant> res = new SmartList<JavaBreakpointVariant>();
|
||||
res.add(new JavaBreakpointVariant(position)); //all
|
||||
|
||||
if (startMethod instanceof PsiMethod) {
|
||||
if (!(startMethod instanceof PsiLambdaExpression)) {
|
||||
res.add(new ExactJavaBreakpointVariant(position, startMethod, -1)); // base method
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user