IDEA-159094 Filter exception breakpoints by catch location - new properties

This commit is contained in:
Egor.Ushakov
2016-07-27 19:46:55 +03:00
parent cffe2378fa
commit 01b311300f
4 changed files with 72 additions and 12 deletions
@@ -335,9 +335,9 @@ public abstract class Breakpoint<P extends JavaBreakpointProperties> 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<P extends JavaBreakpointProperties> 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<P extends JavaBreakpointProperties> 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;
}
@@ -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<JavaExceptionBreakpointPrope
}
}
@Override
public boolean evaluateCondition(EvaluationContextImpl context, LocatableEvent event) throws EvaluateException {
if (getProperties().isCatchFiltersEnabled() && event instanceof ExceptionEvent) {
Location location = ((ExceptionEvent)event).catchLocation();
if (location != null && !typeMatchesClassFilters(location.declaringType().name(),
getProperties().getCatchClassFilters(),
getProperties().getCatchClassExclusionFilters())) {
return false;
}
}
return super.evaluateCondition(context, event);
}
public boolean isValid() {
return true;
}
@@ -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 JavaBreakpointProperties<T extends JavaBreakpointProperties> 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;
}
@@ -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;
}
}