From dc819c7a8b0759750a9512621846484c35e7d740 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Tue, 25 Oct 2016 15:21:15 +0300 Subject: [PATCH] cleanup --- .../debugger/ui/breakpoints/Breakpoint.java | 49 +++++++------------ .../BreakpointWithHighlighter.java | 15 +++--- .../ui/breakpoints/FieldBreakpoint.java | 15 +++--- .../ui/breakpoints/LineBreakpoint.java | 5 +- .../ui/breakpoints/RunToCursorBreakpoint.java | 4 +- 5 files changed, 36 insertions(+), 52 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java index 43b214584b65..46e48aae7e79 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/Breakpoint.java @@ -75,7 +75,6 @@ public abstract class Breakpoint

implements protected final Project myProject; @NonNls private static final String LOG_MESSAGE_OPTION_NAME = "LOG_MESSAGE"; - public static final Breakpoint[] EMPTY_ARRAY = new Breakpoint[0]; protected boolean myCachedVerifiedState = false; protected Breakpoint(@NotNull Project project, XBreakpoint

xBreakpoint) { @@ -209,33 +208,29 @@ public abstract class Breakpoint

implements } @Override - public boolean processLocatableEvent(final SuspendContextCommandImpl action, final LocatableEvent event) throws EventProcessingException { - final SuspendContextImpl context = action.getSuspendContext(); - if(!isValid()) { + public boolean processLocatableEvent(SuspendContextCommandImpl action, LocatableEvent event) throws EventProcessingException { + SuspendContextImpl context = action.getSuspendContext(); + if (!isValid()) { context.getDebugProcess().getRequestsManager().deleteRequest(this); return false; } - final String[] title = {DebuggerBundle.message("title.error.evaluating.breakpoint.condition") }; + String title = DebuggerBundle.message("title.error.evaluating.breakpoint.condition"); try { - final StackFrameProxyImpl frameProxy = context.getThread().frame(0); + StackFrameProxyImpl frameProxy = context.getThread().frame(0); if (frameProxy == null) { // might be if the thread has been collected return false; } - final EvaluationContextImpl evaluationContext = new EvaluationContextImpl( - action.getSuspendContext(), - frameProxy, - getThisObject(context, event) - ); + EvaluationContextImpl evaluationContext = new EvaluationContextImpl(context, frameProxy, getThisObject(context, event)); - if(!evaluateCondition(evaluationContext, event)) { + if (!evaluateCondition(evaluationContext, event)) { return false; } - title[0] = DebuggerBundle.message("title.error.evaluating.breakpoint.action"); + title = DebuggerBundle.message("title.error.evaluating.breakpoint.action"); runAction(evaluationContext, event); } catch (final EvaluateException ex) { @@ -244,42 +239,37 @@ public abstract class Breakpoint

implements return false; } - throw new EventProcessingException(title[0], ex.getMessage(), ex); + throw new EventProcessingException(title, ex.getMessage(), ex); } return true; } - private void runAction(final EvaluationContextImpl context, LocatableEvent event) { - final DebugProcessImpl debugProcess = context.getDebugProcess(); + private void runAction(EvaluationContextImpl context, LocatableEvent event) { + DebugProcessImpl debugProcess = context.getDebugProcess(); if (isLogEnabled() || isLogExpressionEnabled()) { - final StringBuilder buf = StringBuilderSpinAllocator.alloc(); + StringBuilder buf = StringBuilderSpinAllocator.alloc(); try { if (myXBreakpoint.isLogMessage()) { - buf.append(getEventMessage(event)); - buf.append("\n"); + buf.append(getEventMessage(event)).append("\n"); } if (isLogExpressionEnabled()) { if (!debugProcess.isAttached()) { return; } - final TextWithImports expressionToEvaluate = getLogMessage(); try { SourcePosition position = ContextUtil.getSourcePosition(context); PsiElement element = ContextUtil.getContextElement(context, position); ExpressionEvaluator evaluator = DebuggerInvocationUtil.commitAndRunReadAction(myProject, () -> - createExpressionEvaluator(myProject, element, position, expressionToEvaluate, this::createLogMessageCodeFragment)); + createExpressionEvaluator(myProject, element, position, getLogMessage(), this::createLogMessageCodeFragment)); Value eval = evaluator.evaluate(context); buf.append(eval instanceof VoidValue ? "void" : DebuggerUtils.getValueAsString(context, eval)); } catch (EvaluateException e) { - buf.append(DebuggerBundle.message("error.unable.to.evaluate.expression")); - buf.append(" \""); - buf.append(expressionToEvaluate); - buf.append("\""); - buf.append(" : "); - buf.append(e.getMessage()); + buf.append(DebuggerBundle.message("error.unable.to.evaluate.expression")) + .append(" \"").append(getLogMessage()).append("\"") + .append(" : ").append(e.getMessage()); } buf.append("\n"); } @@ -304,7 +294,7 @@ public abstract class Breakpoint

implements } public boolean evaluateCondition(final EvaluationContextImpl context, LocatableEvent event) throws EvaluateException { - final DebugProcessImpl debugProcess = context.getDebugProcess(); + DebugProcessImpl debugProcess = context.getDebugProcess(); if (isCountFilterEnabled()) { debugProcess.getVirtualMachineProxy().suspend(); debugProcess.getRequestsManager().deleteRequest(this); @@ -504,8 +494,7 @@ public abstract class Breakpoint

implements } protected boolean isLogExpressionEnabled() { - XExpression expression = myXBreakpoint.getLogExpressionObject(); - if (XDebuggerUtilImpl.isEmptyExpression(expression)) { + if (XDebuggerUtilImpl.isEmptyExpression(myXBreakpoint.getLogExpressionObject())) { return false; } return !getLogMessage().isEmpty(); diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointWithHighlighter.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointWithHighlighter.java index 24728d7db543..a03210e0a493 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointWithHighlighter.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointWithHighlighter.java @@ -310,14 +310,13 @@ public abstract class BreakpointWithHighlighter

{ + DebuggerInvocationUtil.swingInvokeLater(myProject, () -> { if (!isValid()) { return; } - DebuggerContextImpl context = DebuggerManagerEx.getInstanceEx(project).getContext(); - final DebugProcessImpl debugProcess = context.getDebugProcess(); + DebuggerContextImpl context = DebuggerManagerEx.getInstanceEx(myProject).getContext(); + DebugProcessImpl debugProcess = context.getDebugProcess(); if (debugProcess == null || !debugProcess.isAttached()) { updateCaches(null); updateGutter(); @@ -327,11 +326,11 @@ public abstract class BreakpointWithHighlighter

{ - if (!project.isDisposed()) { + if (!myProject.isDisposed()) { updateCaches(debugProcess); } }); - DebuggerInvocationUtil.swingInvokeLater(project, BreakpointWithHighlighter.this::updateGutter); + DebuggerInvocationUtil.swingInvokeLater(myProject, BreakpointWithHighlighter.this::updateGutter); } }); } @@ -386,9 +385,9 @@ public abstract class BreakpointWithHighlighter

() { - @Override - public PsiField compute() { - final PsiClass psiClass = getPsiClassAt(sourcePosition); - return psiClass != null ? psiClass.findFieldByName(getFieldName(), true) : null; - } + PsiField field = ApplicationManager.getApplication().runReadAction((Computable)() -> { + PsiClass psiClass = getPsiClassAt(sourcePosition); + return psiClass != null ? psiClass.findFieldByName(getFieldName(), true) : null; }); if (field != null) { return field; } } catch (IndexNotReadyException ignored) {} - return PositionUtil.getPsiElementAt(getProject(), PsiField.class, sourcePosition); + return PositionUtil.getPsiElementAt(myProject, PsiField.class, sourcePosition); } @Override protected void reload(PsiFile psiFile) { super.reload(psiFile); - PsiField field = PositionUtil.getPsiElementAt(getProject(), PsiField.class, getSourcePosition()); - if(field != null) { + PsiField field = PositionUtil.getPsiElementAt(myProject, PsiField.class, getSourcePosition()); + if (field != null) { setFieldName(field.getName()); PsiClass psiClass = field.getContainingClass(); if (psiClass != null) { diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/LineBreakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/LineBreakpoint.java index ea6527a7d1b0..9f8c3c41c39c 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/LineBreakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/LineBreakpoint.java @@ -239,12 +239,11 @@ public class LineBreakpoint

extends Breakpoi if (LOG.isDebugEnabled()) { final GlobalSearchScope scope = debugProcess.getSearchScope(); final boolean contains = scope.contains(breakpointFile); - final Project project = getProject(); List files = ContainerUtil.map( - JavaFullClassNameIndex.getInstance().get(className.hashCode(), project, scope), + JavaFullClassNameIndex.getInstance().get(className.hashCode(), myProject, scope), aClass -> aClass.getContainingFile().getVirtualFile()); List allFiles = ContainerUtil.map( - JavaFullClassNameIndex.getInstance().get(className.hashCode(), project, new EverythingGlobalScope(project)), + JavaFullClassNameIndex.getInstance().get(className.hashCode(), myProject, new EverythingGlobalScope(myProject)), aClass -> aClass.getContainingFile().getVirtualFile()); final VirtualFile contentRoot = fileIndex.getContentRootForFile(breakpointFile); final Module module = fileIndex.getModuleForFile(breakpointFile); diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/RunToCursorBreakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/RunToCursorBreakpoint.java index 9cdb1aa44988..a72db29c1da9 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/RunToCursorBreakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/RunToCursorBreakpoint.java @@ -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. @@ -133,7 +133,7 @@ public class RunToCursorBreakpoint extends LineBreakpoint type : XDebuggerUtil.getInstance().getLineBreakpointTypes()) { - if (type instanceof JavaLineBreakpointType && type.canPutAt(file, line, getProject())) { + if (type instanceof JavaLineBreakpointType && type.canPutAt(file, line, myProject)) { return ((JavaLineBreakpointType)type); } }