From 01b311300fc1ce3e5c1330326bd41e2da71f977a Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Wed, 27 Jul 2016 19:19:15 +0300 Subject: [PATCH] IDEA-159094 Filter exception breakpoints by catch location - new properties --- .../debugger/ui/breakpoints/Breakpoint.java | 14 +++--- .../ui/breakpoints/ExceptionBreakpoint.java | 21 ++++++++- .../properties/JavaBreakpointProperties.java | 4 +- .../JavaExceptionBreakpointProperties.java | 45 ++++++++++++++++++- 4 files changed, 72 insertions(+), 12 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 00e713335250..085669d3bf42 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 @@ -335,9 +335,9 @@ public abstract class Breakpoint

implements } } - if (isClassFiltersEnabled()) { - String typeName = calculateEventClass(context, event); - if (!typeMatchesClassFilters(typeName)) return false; + if (isClassFiltersEnabled() && + !typeMatchesClassFilters(calculateEventClass(context, event), getClassFilters(), getClassExclusionFilters())) { + return false; } if (!isConditionEnabled() || getCondition().getText().isEmpty()) { @@ -394,12 +394,12 @@ public abstract class Breakpoint

implements return event.location().declaringType().name(); } - private boolean typeMatchesClassFilters(@Nullable String typeName) { + protected static boolean typeMatchesClassFilters(@Nullable String typeName, ClassFilter[] includeFilters, ClassFilter[] exludeFilters) { if (typeName == null) { return true; } boolean matches = false, hasEnabled = false; - for (ClassFilter classFilter : getClassFilters()) { + for (ClassFilter classFilter : includeFilters) { if (classFilter.isEnabled()) { hasEnabled = true; if (classFilter.matches(typeName)) { @@ -408,10 +408,10 @@ public abstract class Breakpoint

implements } } } - if(hasEnabled && !matches) { + if (hasEnabled && !matches) { return false; } - for (ClassFilter classFilter : getClassExclusionFilters()) { + for (ClassFilter classFilter : exludeFilters) { if (classFilter.isEnabled() && classFilter.matches(typeName)) { return false; } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpoint.java index f1d600a63e21..357b54ea99bf 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/ExceptionBreakpoint.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. @@ -25,6 +25,7 @@ import com.intellij.debugger.DebuggerManagerEx; import com.intellij.debugger.SourcePosition; import com.intellij.debugger.engine.*; import com.intellij.debugger.engine.evaluation.EvaluateException; +import com.intellij.debugger.engine.evaluation.EvaluationContextImpl; import com.intellij.debugger.impl.DebuggerUtilsEx; import com.intellij.icons.AllIcons; import com.intellij.openapi.application.ApplicationManager; @@ -34,7 +35,10 @@ import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.JDOMExternalizerUtil; import com.intellij.openapi.util.Key; -import com.intellij.psi.*; +import com.intellij.psi.CommonClassNames; +import com.intellij.psi.JavaPsiFacade; +import com.intellij.psi.PsiClass; +import com.intellij.psi.PsiElement; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.xdebugger.breakpoints.XBreakpoint; import com.sun.jdi.AbsentInformationException; @@ -202,6 +206,19 @@ public class ExceptionBreakpoint extends Breakpoint extend return changed; } - private static boolean filtersEqual(Object[] a, Object[] b) { + protected static boolean filtersEqual(Object[] a, Object[] b) { if ((a == null || a.length == 0) && (b == null || b.length == 0)) { return true; } diff --git a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaExceptionBreakpointProperties.java b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaExceptionBreakpointProperties.java index e3b893e926ee..7c52508a6dac 100644 --- a/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaExceptionBreakpointProperties.java +++ b/java/debugger/impl/src/org/jetbrains/java/debugger/breakpoints/properties/JavaExceptionBreakpointProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 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. @@ -15,7 +15,11 @@ */ package org.jetbrains.java.debugger.breakpoints.properties; +import com.intellij.ui.classFilter.ClassFilter; +import com.intellij.util.xmlb.annotations.AbstractCollection; import com.intellij.util.xmlb.annotations.Attribute; +import com.intellij.util.xmlb.annotations.OptionTag; +import com.intellij.util.xmlb.annotations.Tag; import org.jetbrains.annotations.Nullable; /** @@ -31,6 +35,10 @@ public class JavaExceptionBreakpointProperties extends JavaBreakpointProperties< @Attribute("package") public String myPackageName; + private boolean myCatchFiltersEnabled = false; + private ClassFilter[] myCatchClassFilters; + private ClassFilter[] myCatchClassExclusionFilters; + public JavaExceptionBreakpointProperties(String qualifiedName, String packageName) { myQualifiedName = qualifiedName; myPackageName = packageName; @@ -54,4 +62,39 @@ public class JavaExceptionBreakpointProperties extends JavaBreakpointProperties< myQualifiedName = state.myQualifiedName; myPackageName = state.myPackageName; } + + @OptionTag("catch-filters-enabled") + public boolean isCatchFiltersEnabled() { + return myCatchFiltersEnabled; + } + + public boolean setCatchFiltersEnabled(boolean enabled) { + boolean changed = myCatchFiltersEnabled != enabled; + myCatchFiltersEnabled = enabled; + return changed; + } + + @Tag("catch-class-filters") + @AbstractCollection(surroundWithTag = false) + public final ClassFilter[] getCatchClassFilters() { + return myCatchClassFilters != null ? myCatchClassFilters : ClassFilter.EMPTY_ARRAY; + } + + public final boolean setCatchClassFilters(ClassFilter[] classFilters) { + boolean changed = !filtersEqual(myCatchClassFilters, classFilters); + myCatchClassFilters = classFilters; + return changed; + } + + @Tag("catch-class-exclusion-filters") + @AbstractCollection(surroundWithTag = false) + public ClassFilter[] getCatchClassExclusionFilters() { + return myCatchClassExclusionFilters != null ? myCatchClassExclusionFilters : ClassFilter.EMPTY_ARRAY; + } + + public boolean setCatchClassExclusionFilters(ClassFilter[] classExclusionFilters) { + boolean changed = !filtersEqual(myCatchClassExclusionFilters, classExclusionFilters); + myCatchClassExclusionFilters = classExclusionFilters; + return changed; + } }