Skip to content

Commit

Permalink
Fix for #1202: add new filter for generated lambda stack frame
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Nov 22, 2020
1 parent 80ee474 commit e0aab74
Showing 1 changed file with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2019 the original author or authors.
* Copyright 2009-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,9 @@
*/
package org.codehaus.groovy.eclipse.debug.ui;

import java.util.Arrays;
import java.util.regex.Pattern;

import org.codehaus.groovy.eclipse.GroovyPlugin;
import org.codehaus.groovy.eclipse.core.preferences.PreferenceConstants;
import org.eclipse.core.runtime.CoreException;
Expand All @@ -34,16 +37,16 @@ class GroovyJavaStackFrameLabelProvider extends JavaStackFrameLabelProvider impl

private boolean enabled;
private String[] filters;
private final IPreferenceStore preferenceStore;
private final IPreferenceStore preferenceStore = GroovyPlugin.getDefault().getPreferenceStore();
private static final Pattern LAMBDA_FILTER = Pattern.compile("\\${2}Lambda\\$\\d+(?:\\.|/0x)[0-9a-f]{8,16}$");

GroovyJavaStackFrameLabelProvider() {
preferenceStore = GroovyPlugin.getDefault().getPreferenceStore();
computeEnabled();
computeFilters();
}

@Override
public void propertyChange(PropertyChangeEvent event) {
public void propertyChange(final PropertyChangeEvent event) {
switch (event.getProperty()) {
case PreferenceConstants.GROOVY_DEBUG_FILTER_STACK:
computeEnabled();
Expand All @@ -55,12 +58,12 @@ public void propertyChange(PropertyChangeEvent event) {
}

@Override
protected void retrieveLabel(ILabelUpdate update) throws CoreException {
protected void retrieveLabel(final ILabelUpdate update) throws CoreException {
super.retrieveLabel(update);
if (enabled && !update.isCanceled()) {
Object element = update.getElement();
if (element instanceof IJavaStackFrame) {
if (isFiltered(((IJavaStackFrame) element).getDeclaringTypeName())) {
if (isFiltered(((IJavaStackFrame) element).getReceivingTypeName())) {
try {
RGB mutedColor = JFaceResources.getColorRegistry().getRGB(JFacePreferences.DECORATIONS_COLOR);
update.setForeground(mutedColor, 0);
Expand Down Expand Up @@ -89,13 +92,8 @@ private void computeFilters() {
}
}

private boolean isFiltered(String qualifiedName) {
for (String filter : filters) {
if (qualifiedName.startsWith(filter)) {
return true;
}
}
return false;
private boolean isFiltered(final String qualifiedName) {
return Arrays.stream(filters).anyMatch(qualifiedName::startsWith) || LAMBDA_FILTER.matcher(qualifiedName).find();
}

void connect() {
Expand Down

0 comments on commit e0aab74

Please sign in to comment.