use of com.sun.jdi.Method in project intellij-community by JetBrains.
the class PositionManagerImpl method getSourcePosition.
@Nullable
public SourcePosition getSourcePosition(final Location location) throws NoDataException {
DebuggerManagerThreadImpl.assertIsManagerThread();
if (location == null) {
return null;
}
Project project = getDebugProcess().getProject();
PsiFile psiFile = getPsiFileByLocation(project, location);
if (psiFile == null) {
return null;
}
LOG.assertTrue(myDebugProcess != null);
int lineNumber = DebuggerUtilsEx.getLineNumber(location, true);
String qName = location.declaringType().name();
// replace file with alternative
String altFileUrl = DebuggerUtilsEx.getAlternativeSourceUrl(qName, project);
if (altFileUrl != null) {
VirtualFile altFile = VirtualFileManager.getInstance().findFileByUrl(altFileUrl);
if (altFile != null) {
PsiFile altPsiFile = psiFile.getManager().findFile(altFile);
if (altPsiFile != null) {
psiFile = altPsiFile;
}
}
}
SourcePosition sourcePosition = null;
if (lineNumber > -1) {
sourcePosition = calcLineMappedSourcePosition(psiFile, lineNumber);
}
final Method method = DebuggerUtilsEx.getMethod(location);
if (sourcePosition == null && (psiFile instanceof PsiCompiledElement || lineNumber < 0)) {
if (method != null && method.name() != null && method.signature() != null) {
PsiClass psiClass = findPsiClassByName(qName, null);
PsiMethod compiledMethod = findMethod(psiClass != null ? psiClass : psiFile, qName, method.name(), method.signature());
if (compiledMethod != null) {
sourcePosition = SourcePosition.createFromElement(compiledMethod);
if (lineNumber >= 0) {
sourcePosition = new ClsSourcePosition(sourcePosition, lineNumber);
}
}
} else {
return SourcePosition.createFromLine(psiFile, -1);
}
}
if (sourcePosition == null) {
sourcePosition = SourcePosition.createFromLine(psiFile, lineNumber);
}
int lambdaOrdinal = -1;
if (DebuggerUtilsEx.isLambda(method)) {
Set<Method> lambdas = ContainerUtil.map2SetNotNull(locationsOfLine(location.declaringType(), sourcePosition), location1 -> {
Method method1 = location1.method();
if (DebuggerUtilsEx.isLambda(method1)) {
return method1;
}
return null;
});
if (lambdas.size() > 1) {
ArrayList<Method> lambdasList = new ArrayList<>(lambdas);
lambdasList.sort(DebuggerUtilsEx.LAMBDA_ORDINAL_COMPARATOR);
lambdaOrdinal = lambdasList.indexOf(method);
}
}
return new JavaSourcePosition(sourcePosition, location.declaringType(), method, lambdaOrdinal);
}
use of com.sun.jdi.Method in project intellij-community by JetBrains.
the class PositionManagerImpl method findNested.
@Nullable
private ReferenceType findNested(final ReferenceType fromClass, final int currentDepth, final PsiClass classToFind, final int requiredDepth, final SourcePosition position) {
ApplicationManager.getApplication().assertReadAccessAllowed();
final VirtualMachineProxyImpl vmProxy = myDebugProcess.getVirtualMachineProxy();
if (fromClass.isPrepared()) {
if (currentDepth < requiredDepth) {
final List<ReferenceType> nestedTypes = vmProxy.nestedTypes(fromClass);
for (ReferenceType nested : nestedTypes) {
final ReferenceType found = findNested(nested, currentDepth + 1, classToFind, requiredDepth, position);
if (found != null) {
return found;
}
}
return null;
}
int rangeBegin = Integer.MAX_VALUE;
int rangeEnd = Integer.MIN_VALUE;
for (Location location : DebuggerUtilsEx.allLineLocations(fromClass)) {
final int lnumber = DebuggerUtilsEx.getLineNumber(location, false);
if (lnumber <= 1) {
// such locations are hardly correspond to real lines in code, so skipping them too
continue;
}
final Method method = DebuggerUtilsEx.getMethod(location);
if (method == null || DebuggerUtils.isSynthetic(method) || method.isBridge()) {
// do not take into account synthetic stuff
continue;
}
int locationLine = lnumber - 1;
PsiFile psiFile = position.getFile().getOriginalFile();
if (psiFile instanceof PsiCompiledFile) {
locationLine = DebuggerUtilsEx.bytecodeToSourceLine(psiFile, locationLine);
if (locationLine < 0)
continue;
}
rangeBegin = Math.min(rangeBegin, locationLine);
rangeEnd = Math.max(rangeEnd, locationLine);
}
final int positionLine = position.getLine();
if (positionLine >= rangeBegin && positionLine <= rangeEnd) {
// First offsets belong to parent class, and offsets inside te substring "new Runnable(){" belong to anonymous runnable.
if (!classToFind.isValid()) {
return null;
}
Set<PsiClass> lineClasses = getLineClasses(position.getFile(), rangeEnd);
if (lineClasses.size() > 1) {
// if there's more than one class on the line - try to match by name
for (PsiClass aClass : lineClasses) {
if (classToFind.equals(aClass)) {
return fromClass;
}
}
} else if (!lineClasses.isEmpty()) {
return classToFind.equals(lineClasses.iterator().next()) ? fromClass : null;
}
return null;
}
}
return null;
}
use of com.sun.jdi.Method in project intellij-community by JetBrains.
the class RequestHint method getNextStepDepth.
public int getNextStepDepth(final SuspendContextImpl context) {
try {
final StackFrameProxyImpl frameProxy = context.getFrameProxy();
// smart step feature stop check
if (myMethodFilter != null && frameProxy != null && !(myMethodFilter instanceof BreakpointStepMethodFilter) && myMethodFilter.locationMatches(context.getDebugProcess(), frameProxy.location()) && !isTheSameFrame(context)) {
myTargetMethodMatched = true;
return myMethodFilter.onReached(context, this);
}
if ((myDepth == StepRequest.STEP_OVER || myDepth == StepRequest.STEP_INTO) && myPosition != null) {
SourcePosition locationPosition = ContextUtil.getSourcePosition(context);
if (locationPosition != null) {
Integer resultDepth = ApplicationManager.getApplication().runReadAction(new Computable<Integer>() {
public Integer compute() {
if (myPosition.getFile().equals(locationPosition.getFile()) && isTheSameFrame(context) && !mySteppedOut) {
return isOnTheSameLine(locationPosition) ? myDepth : STOP;
}
return null;
}
});
if (resultDepth != null) {
return resultDepth.intValue();
}
}
}
// Now check filters
final DebuggerSettings settings = DebuggerSettings.getInstance();
if ((myMethodFilter != null || (settings.SKIP_SYNTHETIC_METHODS && !myIgnoreFilters)) && frameProxy != null) {
final Location location = frameProxy.location();
if (location != null) {
if (DebuggerUtils.isSynthetic(location.method())) {
return myDepth;
}
}
}
if (!myIgnoreFilters) {
if (settings.SKIP_GETTERS) {
boolean isGetter = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
public Boolean compute() {
PsiElement contextElement = ContextUtil.getContextElement(context);
return contextElement != null && DebuggerUtils.isInsideSimpleGetter(contextElement);
}
}).booleanValue();
if (isGetter) {
return StepRequest.STEP_OUT;
}
}
if (frameProxy != null) {
if (settings.SKIP_CONSTRUCTORS) {
final Location location = frameProxy.location();
if (location != null) {
final Method method = location.method();
if (method != null && method.isConstructor()) {
return StepRequest.STEP_OUT;
}
}
}
if (settings.SKIP_CLASSLOADERS) {
final Location location = frameProxy.location();
if (location != null && DebuggerUtilsEx.isAssignableFrom("java.lang.ClassLoader", location.declaringType())) {
return StepRequest.STEP_OUT;
}
}
}
for (ExtraSteppingFilter filter : ExtraSteppingFilter.EP_NAME.getExtensions()) {
try {
if (filter.isApplicable(context))
return filter.getStepRequestDepth(context);
} catch (Exception | AssertionError e) {
LOG.error(e);
}
}
}
// smart step feature
if (myMethodFilter != null && !mySteppedOut) {
return StepRequest.STEP_OUT;
}
} catch (VMDisconnectedException ignored) {
} catch (EvaluateException e) {
LOG.error(e);
}
return STOP;
}
use of com.sun.jdi.Method in project intellij-community by JetBrains.
the class UnBoxingEvaluator method convertToPrimitive.
private static Value convertToPrimitive(EvaluationContextImpl context, ObjectReference value, final String conversionMethodName, String conversionMethodSignature) throws EvaluateException {
final DebugProcessImpl process = context.getDebugProcess();
final ClassType wrapperClass = (ClassType) value.referenceType();
Method method = wrapperClass.concreteMethodByName(conversionMethodName, conversionMethodSignature);
if (method == null) {
throw new EvaluateException("Cannot convert to primitive value of type " + value.type() + ": Unable to find method " + conversionMethodName + conversionMethodSignature);
}
return process.invokeMethod(context, value, method, Collections.emptyList());
}
use of com.sun.jdi.Method in project intellij-community by JetBrains.
the class ForceEarlyReturnAction method actionPerformed.
public void actionPerformed(@NotNull AnActionEvent e) {
final Project project = e.getProject();
final JavaStackFrame stackFrame = PopFrameAction.getStackFrame(e);
if (stackFrame == null || project == null) {
return;
}
final DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(e.getDataContext());
final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess();
if (debugProcess == null) {
return;
}
final StackFrameProxyImpl proxy = stackFrame.getStackFrameProxy();
final ThreadReferenceProxyImpl thread = proxy.threadProxy();
debugProcess.getManagerThread().schedule(new DebuggerContextCommandImpl(debuggerContext, thread) {
@Override
public void threadAction() {
Method method;
try {
method = proxy.location().method();
} catch (EvaluateException e) {
showError(project, DebuggerBundle.message("error.early.return", e.getLocalizedMessage()));
return;
}
if ("void".equals(method.returnTypeName())) {
forceEarlyReturnWithFinally(thread.getVirtualMachine().mirrorOfVoid(), stackFrame, debugProcess, null);
} else {
ApplicationManager.getApplication().invokeLater(() -> new ReturnExpressionDialog(project, debugProcess.getXdebugProcess().getEditorsProvider(), debugProcess, stackFrame).show());
}
}
});
}
Aggregations