public String getName(DebugProcessImpl process) throws EvaluateException { List<ReferenceType> allClasses = process.getPositionManager().getAllClasses(mySourcePosition); if (!allClasses.isEmpty()) { return allClasses.get(0).name(); } throw EvaluateExceptionUtil.createEvaluateException( DebuggerBundle.message("error.class.not.loaded", getDisplayName(process))); }
protected void createOrWaitPrepare( final DebugProcessImpl debugProcess, final SourcePosition classPosition) { debugProcess.getRequestsManager().callbackOnPrepareClasses(this, classPosition); List list = debugProcess.getPositionManager().getAllClasses(classPosition); for (final Object aList : list) { ReferenceType refType = (ReferenceType) aList; if (refType.isPrepared()) { processClassPrepare(debugProcess, refType); } } }
@Nullable public static String getSourcePositionPackageDisplayName( DebugProcessImpl debugProcess, @Nullable SourcePosition position) { if (position == null) { return null; } final PsiFile positionFile = position.getFile(); if (positionFile instanceof JspFile) { final PsiDirectory dir = positionFile.getContainingDirectory(); return dir != null ? dir.getVirtualFile().getPresentableUrl() : null; } final PsiClass psiClass = getClassAt(position); if (psiClass != null) { PsiClass toplevel = PsiUtil.getTopLevelClass(psiClass); if (toplevel != null) { String qName = toplevel.getQualifiedName(); if (qName != null) { int i = qName.lastIndexOf('.'); return i > 0 ? qName.substring(0, i) : ""; } } } if (positionFile instanceof PsiClassOwner) { String name = ((PsiClassOwner) positionFile).getPackageName(); if (!StringUtil.isEmpty(name)) { return name; } } if (debugProcess != null && debugProcess.isAttached()) { List<ReferenceType> allClasses = debugProcess.getPositionManager().getAllClasses(position); if (!allClasses.isEmpty()) { final String className = allClasses.get(0).name(); int dotIndex = className.lastIndexOf('.'); if (dotIndex >= 0) { return className.substring(0, dotIndex); } } } return ""; }
@Nullable public static String getSourcePositionClassDisplayName( DebugProcessImpl debugProcess, @Nullable SourcePosition position) { if (position == null) { return null; } final PsiFile positionFile = position.getFile(); if (positionFile instanceof JspFile) { return positionFile.getName(); } final PsiClass psiClass = getClassAt(position); if (psiClass != null) { final String qName = psiClass.getQualifiedName(); if (qName != null) { return qName; } } if (debugProcess != null && debugProcess.isAttached()) { List<ReferenceType> allClasses = debugProcess.getPositionManager().getAllClasses(position); if (!allClasses.isEmpty()) { return allClasses.get(0).name(); } } if (psiClass == null) { if (positionFile instanceof PsiClassOwner) { return positionFile.getName(); } return DebuggerBundle.message( "string.file.line.position", positionFile.getName(), position.getLine()); } return calcClassDisplayName(psiClass); }
public void reloadClasses(final Map<String, HotSwapFile> modifiedClasses) { DebuggerManagerThreadImpl.assertIsManagerThread(); if (modifiedClasses == null || modifiedClasses.size() == 0) { myProgress.addMessage( myDebuggerSession, MessageCategory.INFORMATION, DebuggerBundle.message("status.hotswap.loaded.classes.up.to.date")); return; } final DebugProcessImpl debugProcess = getDebugProcess(); final VirtualMachineProxyImpl virtualMachineProxy = debugProcess.getVirtualMachineProxy(); final Project project = debugProcess.getProject(); final BreakpointManager breakpointManager = (DebuggerManagerEx.getInstanceEx(project)).getBreakpointManager(); breakpointManager.disableBreakpoints(debugProcess); // virtualMachineProxy.suspend(); try { RedefineProcessor redefineProcessor = new RedefineProcessor(virtualMachineProxy); int processedEntriesCount = 0; for (final Map.Entry<String, HotSwapFile> entry : modifiedClasses.entrySet()) { // stop if process is finished already if (debugProcess.isDetached() || debugProcess.isDetaching()) { break; } if (redefineProcessor.getProcessedClassesCount() == 0 && myProgress.isCancelled()) { // once at least one class has been actually reloaded, do not interrupt the whole process break; } processedEntriesCount++; final String qualifiedName = entry.getKey(); if (qualifiedName != null) { myProgress.setText(qualifiedName); myProgress.setFraction(processedEntriesCount / (double) modifiedClasses.size()); } try { redefineProcessor.processClass(qualifiedName, entry.getValue().file); } catch (IOException e) { reportProblem(qualifiedName, e); } } if (redefineProcessor.getProcessedClassesCount() == 0 && myProgress.isCancelled()) { // once at least one class has been actually reloaded, do not interrupt the whole process return; } redefineProcessor.processPending(); myProgress.setFraction(1); final int partiallyRedefinedClassesCount = redefineProcessor.getPartiallyRedefinedClassesCount(); if (partiallyRedefinedClassesCount == 0) { myProgress.addMessage( myDebuggerSession, MessageCategory.INFORMATION, DebuggerBundle.message( "status.classes.reloaded", redefineProcessor.getProcessedClassesCount())); } else { final String message = DebuggerBundle.message( "status.classes.not.all.versions.reloaded", partiallyRedefinedClassesCount, redefineProcessor.getProcessedClassesCount()); myProgress.addMessage(myDebuggerSession, MessageCategory.WARNING, message); } LOG.debug("classes reloaded"); } catch (Throwable e) { processException(e); } debugProcess.getPositionManager().clearCache(); DebuggerContextImpl context = myDebuggerSession.getContextManager().getContext(); SuspendContextImpl suspendContext = context.getSuspendContext(); if (suspendContext != null) { XExecutionStack stack = suspendContext.getActiveExecutionStack(); if (stack != null) { ((JavaExecutionStack) stack).initTopFrame(); } } final Semaphore waitSemaphore = new Semaphore(); waitSemaphore.down(); //noinspection SSBasedInspection SwingUtilities.invokeLater( () -> { try { if (!project.isDisposed()) { breakpointManager.reloadBreakpoints(); debugProcess.getRequestsManager().clearWarnings(); if (LOG.isDebugEnabled()) { LOG.debug("requests updated"); LOG.debug("time stamp set"); } myDebuggerSession.refresh(false); XDebugSession session = myDebuggerSession.getXDebugSession(); if (session != null) { session.rebuildViews(); } } } catch (Throwable e) { LOG.error(e); } finally { waitSemaphore.up(); } }); waitSemaphore.waitFor(); if (!project.isDisposed()) { try { breakpointManager.enableBreakpoints(debugProcess); } catch (Exception e) { processException(e); } } }