Merge remote-tracking branch 'origin/master'

This commit is contained in:
Ekaterina Tuzova
2014-08-04 15:39:08 +04:00
7 changed files with 81 additions and 237 deletions
@@ -322,10 +322,15 @@ public class DebugProcessEvents extends DebugProcessImpl {
myDebugProcessDispatcher.getMulticaster().processAttached(this);
// breakpoints should be initialized after all processAttached listeners work
XDebugSession session = getSession().getXDebugSession();
if (session != null) {
session.initBreakpoints();
}
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
XDebugSession session = getSession().getXDebugSession();
if (session != null) {
session.initBreakpoints();
}
}
});
final String addressDisplayName = DebuggerBundle.getAddressDisplayName(getConnection());
final String transportName = DebuggerBundle.getTransportName(getConnection());
@@ -459,13 +464,18 @@ public class DebugProcessEvents extends DebugProcessImpl {
if (requestHit && requestor instanceof Breakpoint) {
// if requestor is a breakpoint and this breakpoint was hit, no matter its suspend policy
XDebugSession session = getSession().getXDebugSession();
if (session != null) {
XBreakpoint breakpoint = ((Breakpoint)requestor).getXBreakpoint();
if (breakpoint != null) {
((XDebugSessionImpl)session).processDependencies(breakpoint);
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
XDebugSession session = getSession().getXDebugSession();
if (session != null) {
XBreakpoint breakpoint = ((Breakpoint)requestor).getXBreakpoint();
if (breakpoint != null) {
((XDebugSessionImpl)session).processDependencies(breakpoint);
}
}
}
}
});
}
if(!requestHit || resumePreferred) {
@@ -49,13 +49,17 @@ public class JavaBreakpointHandler extends XBreakpointHandler {
if (javaBreakpoint != null) {
final Breakpoint bpt = javaBreakpoint;
BreakpointManager.addBreakpoint(bpt);
// must use invoke to stay in the current request,
// otherwise dependent breakpoints do not get enabled on not-suspending parents hit
myProcess.getManagerThread().invoke(new DebuggerCommandImpl() {
// use schedule not to block initBreakpoints
myProcess.getManagerThread().schedule(new DebuggerCommandImpl() {
@Override
protected void action() throws Exception {
bpt.createRequest(myProcess);
}
@Override
public Priority getPriority() {
return Priority.HIGH;
}
});
}
}
@@ -64,12 +68,17 @@ public class JavaBreakpointHandler extends XBreakpointHandler {
public void unregisterBreakpoint(@NotNull final XBreakpoint breakpoint, boolean temporary) {
final Breakpoint javaBreakpoint = BreakpointManager.getJavaBreakpoint(breakpoint);
if (javaBreakpoint != null) {
// must use invoke to stay in the current request, see comment in registerBreakpoint
myProcess.getManagerThread().invoke(new DebuggerCommandImpl() {
// use schedule not to block initBreakpoints
myProcess.getManagerThread().schedule(new DebuggerCommandImpl() {
@Override
protected void action() throws Exception {
javaBreakpoint.delete();
}
@Override
public Priority getPriority() {
return Priority.HIGH;
}
});
}
}
@@ -15,6 +15,7 @@
*/
package com.intellij.debugger.engine;
import com.intellij.debugger.engine.events.DebuggerCommandImpl;
import com.intellij.debugger.jdi.ThreadReferenceProxyImpl;
import com.intellij.openapi.diagnostic.Logger;
import com.sun.jdi.InternalException;
@@ -296,7 +297,7 @@ public class SuspendManagerImpl implements SuspendManager {
}
}
private void processVote(SuspendContextImpl suspendContext) {
private void processVote(final SuspendContextImpl suspendContext) {
LOG.assertTrue(suspendContext.myVotesToVote > 0);
suspendContext.myVotesToVote--;
@@ -305,7 +306,18 @@ public class SuspendManagerImpl implements SuspendManager {
}
if(suspendContext.myVotesToVote == 0) {
if(suspendContext.myIsVotedForResume) {
resume(suspendContext);
// resume in a separate request to allow other requests be processed (e.g. dependent bpts enable)
myDebugProcess.getManagerThread().schedule(new DebuggerCommandImpl() {
@Override
protected void action() throws Exception {
resume(suspendContext);
}
@Override
public Priority getPriority() {
return Priority.HIGH;
}
});
}
else {
if (LOG.isDebugEnabled()) {
@@ -33,6 +33,7 @@ import com.intellij.debugger.requests.ClassPrepareRequestor;
import com.intellij.debugger.settings.DebuggerSettings;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.JDOMExternalizerUtil;
import com.intellij.openapi.util.Key;
@@ -98,12 +99,17 @@ public abstract class Breakpoint<P extends JavaBreakpointProperties> implements
*/
public abstract void createRequest(DebugProcessImpl debugProcess);
protected boolean shouldCreateRequest(DebugProcessImpl debugProcess) {
JavaDebugProcess process = debugProcess.getXdebugProcess();
return process != null
&& debugProcess.isAttached()
&& ((XDebugSessionImpl)process.getSession()).isBreakpointActive(myXBreakpoint)
&& debugProcess.getRequestsManager().findRequests(this).isEmpty();
protected boolean shouldCreateRequest(final DebugProcessImpl debugProcess) {
return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
JavaDebugProcess process = debugProcess.getXdebugProcess();
return process != null
&& debugProcess.isAttached()
&& ((XDebugSessionImpl)process.getSession()).isBreakpointActive(myXBreakpoint)
&& debugProcess.getRequestsManager().findRequests(Breakpoint.this).isEmpty();
}
});
}
/**
@@ -91,7 +91,7 @@ public class XDebugSessionImpl implements XDebugSession {
private XDebugProcess myDebugProcess;
private final Map<XBreakpoint<?>, CustomizedBreakpointPresentation> myRegisteredBreakpoints =
new THashMap<XBreakpoint<?>, CustomizedBreakpointPresentation>();
private final Set<XBreakpoint<?>> myInactiveSlaveBreakpoints = Collections.synchronizedSet(new SmartHashSet<XBreakpoint<?>>());
private final Set<XBreakpoint<?>> myInactiveSlaveBreakpoints = new SmartHashSet<XBreakpoint<?>>();
private boolean myBreakpointsDisabled;
private final XDebuggerManagerImpl myDebuggerManager;
private MyBreakpointListener myBreakpointListener;
@@ -289,21 +289,19 @@ public class XDebugSessionImpl implements XDebugSession {
@Override
public void initBreakpoints() {
ApplicationManager.getApplication().assertReadAccessAllowed();
LOG.assertTrue(!breakpointsInitialized);
breakpointsInitialized = true;
XBreakpointManagerImpl breakpointManager = myDebuggerManager.getBreakpointManager();
XDependentBreakpointManager dependentBreakpointManager = breakpointManager.getDependentBreakpointManager();
disableSlaveBreakpoints(dependentBreakpointManager);
processAllBreakpoints(true, false);
// listeners have to be applied before processing all existing breakpoints,
// otherwise we may not process breakpoints added during the processing
myBreakpointListener = new MyBreakpointListener();
breakpointManager.addBreakpointListener(myBreakpointListener);
myDependentBreakpointListener = new MyDependentBreakpointListener();
dependentBreakpointManager.addListener(myDependentBreakpointListener);
processAllBreakpoints(true, false);
}
@Override
@@ -371,12 +369,7 @@ public class XDebugSessionImpl implements XDebugSession {
private <B extends XBreakpoint<?>> void processBreakpoints(final XBreakpointHandler<B> handler,
boolean register,
final boolean temporary) {
Collection<? extends B> breakpoints = ApplicationManager.getApplication().runReadAction(new Computable<Collection<? extends B>>() {
@Override
public Collection<? extends B> compute() {
return myDebuggerManager.getBreakpointManager().getBreakpoints(handler.getBreakpointTypeClass());
}
});
Collection<? extends B> breakpoints = myDebuggerManager.getBreakpointManager().getBreakpoints(handler.getBreakpointTypeClass());
for (B b : breakpoints) {
handleBreakpoint(handler, b, register, temporary);
}
@@ -426,6 +419,7 @@ public class XDebugSessionImpl implements XDebugSession {
}
public boolean isBreakpointActive(final XBreakpoint<?> b) {
ApplicationManager.getApplication().assertReadAccessAllowed();
return !areBreakpointsMuted() && b.isEnabled() && !myInactiveSlaveBreakpoints.contains(b);
}
@@ -451,6 +445,7 @@ public class XDebugSessionImpl implements XDebugSession {
@Override
public void setBreakpointMuted(boolean muted) {
ApplicationManager.getApplication().assertReadAccessAllowed();
if (areBreakpointsMuted() == muted) return;
mySessionData.setBreakpointsMuted(muted);
processAllBreakpoints(!muted, muted);
@@ -240,15 +240,14 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta
@NotNull
public <B extends XBreakpoint<?>> Collection<? extends B> getBreakpoints(@NotNull final XBreakpointType<B,?> type) {
ApplicationManager.getApplication().assertReadAccessAllowed();
Collection<? extends XBreakpointBase<?,?,?>> breakpoints = myBreakpoints.get(type);
Collection<? extends B> regular = breakpoints != null ? Collections.unmodifiableCollection((Collection<? extends B>)breakpoints) : Collections.<B>emptyList();
final XBreakpointBase<?, ?, ?> defaultBreakpoint = myDefaultBreakpoints.get(type);
if (defaultBreakpoint == null) return regular;
List<B> result = new ArrayList<B>();
B defaultBreakpoint = getDefaultBreakpoint(type);
if (defaultBreakpoint != null) {
result.add(defaultBreakpoint);
}
Collection<XBreakpointBase<?, ?, ?>> breakpoints = myBreakpoints.get(type);
if (breakpoints != null) {
result.addAll((Collection<? extends B>)breakpoints);
}
result.add((B)defaultBreakpoint);
result.addAll(regular);
return result;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2014 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,33 +15,19 @@
*/
package com.intellij.uiDesigner.propertyInspector.editors;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.ui.ListSpeedSearch;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.ui.components.JBList;
import com.intellij.ui.ColorChooser;
import com.intellij.ui.JBColor;
import com.intellij.uiDesigner.UIDesignerBundle;
import com.intellij.uiDesigner.lw.ColorDescriptor;
import com.intellij.uiDesigner.propertyInspector.InplaceContext;
import com.intellij.uiDesigner.propertyInspector.PropertyEditor;
import com.intellij.uiDesigner.propertyInspector.renderers.ColorRenderer;
import com.intellij.uiDesigner.radComponents.RadComponent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.colorchooser.AbstractColorChooserPanel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.plaf.ColorChooserUI;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.*;
import java.util.List;
/**
* @author yole
@@ -50,7 +36,6 @@ public class ColorEditor extends PropertyEditor<ColorDescriptor> {
private final String myPropertyName;
private final TextFieldWithBrowseButton myTextField = new TextFieldWithBrowseButton();
private ColorDescriptor myValue;
private Project myProject;
public ColorEditor(String propertyName) {
myPropertyName = propertyName;
@@ -58,11 +43,10 @@ public class ColorEditor extends PropertyEditor<ColorDescriptor> {
myTextField.getTextField().setEditable(false);
myTextField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MyColorChooserDialog dialog = new MyColorChooserDialog(myProject);
dialog.setSelectedValue(myValue);
dialog.show();
if (dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
myValue = dialog.getSelectedValue();
String title = UIDesignerBundle.message("color.chooser.title", myPropertyName);
Color color = ColorChooser.chooseColor(myTextField, title , myValue.getColor());
if (color != null) {
myValue = new ColorDescriptor(color);
updateTextField();
}
}
@@ -74,8 +58,7 @@ public class ColorEditor extends PropertyEditor<ColorDescriptor> {
}
public JComponent getComponent(RadComponent component, ColorDescriptor value, InplaceContext inplaceContext) {
myValue = value != null ? value : new ColorDescriptor(new Color(0));
myProject = component.getProject();
myValue = value != null ? value : new ColorDescriptor(JBColor.BLACK);
updateTextField();
return myTextField;
}
@@ -87,174 +70,4 @@ public class ColorEditor extends PropertyEditor<ColorDescriptor> {
public void updateUI() {
SwingUtilities.updateComponentTreeUI(myTextField);
}
private static class ColorDescriptorWrapper extends Color {
private final ColorDescriptor myDescriptor;
public ColorDescriptorWrapper(ColorDescriptor descriptor) {
super(descriptor.getResolvedColor() == null ? 0 : descriptor.getResolvedColor().getRGB());
myDescriptor = descriptor;
}
public ColorDescriptor getDescriptor() {
return myDescriptor;
}
}
private class MyColorChooserDialog extends DialogWrapper {
private JColorChooser myColorChooser;
private MyDescriptorChooserPanel mySwingChooserPanel;
private MyDescriptorChooserPanel mySystemChooserPanel;
private MyDescriptorChooserPanel myAWTChooserPanel;
public MyColorChooserDialog(Project project) {
super(project, false);
setTitle(UIDesignerBundle.message("color.chooser.title", myPropertyName));
init();
}
protected JComponent createCenterPanel() {
myColorChooser = new JColorChooser();
mySwingChooserPanel = new MyDescriptorChooserPanel(UIDesignerBundle.message("color.chooser.swing.palette"), collectSwingColorDescriptors());
myColorChooser.addChooserPanel(mySwingChooserPanel);
mySystemChooserPanel = new MyDescriptorChooserPanel(UIDesignerBundle.message("color.chooser.system.palette"),
collectColorFields(SystemColor.class, true));
myColorChooser.addChooserPanel(mySystemChooserPanel);
myAWTChooserPanel = new MyDescriptorChooserPanel(UIDesignerBundle.message("color.chooser.awt.palette"),
collectColorFields(Color.class, false));
myColorChooser.addChooserPanel(myAWTChooserPanel);
return myColorChooser;
}
private void selectTabForColor(@Nullable final ColorDescriptor value) {
String tabName;
if (value == null || value.getSwingColor() != null) {
tabName = mySwingChooserPanel.getDisplayName();
}
else if (value.getSystemColor() != null) {
tabName = mySystemChooserPanel.getDisplayName();
}
else if (value.getAWTColor() != null) {
tabName = myAWTChooserPanel.getDisplayName();
}
else {
return;
}
final ColorChooserUI ui = myColorChooser.getUI();
try {
final Field field = ui.getClass().getDeclaredField("tabbedPane");
field.setAccessible(true);
JTabbedPane tabbedPane = (JTabbedPane) field.get(ui);
for(int i=0; i<tabbedPane.getTabCount(); i++) {
if (tabbedPane.getTitleAt(i).equals(tabName)) {
tabbedPane.setSelectedIndex(i);
break;
}
}
}
catch (NoSuchFieldException e) {
// ignore
}
catch (IllegalAccessException e) {
// ignore
}
}
private List<ColorDescriptor> collectSwingColorDescriptors() {
ArrayList<ColorDescriptor> result = new ArrayList<ColorDescriptor>();
UIDefaults defaults = UIManager.getDefaults();
Enumeration e = defaults.keys ();
while(e.hasMoreElements()) {
Object key = e.nextElement();
Object value = defaults.get(key);
if (key instanceof String && value instanceof Color) {
result.add(ColorDescriptor.fromSwingColor((String) key));
}
}
return result;
}
private List<ColorDescriptor> collectColorFields(final Class aClass, final boolean isSystem) {
ArrayList<ColorDescriptor> result = new ArrayList<ColorDescriptor>();
Field[] colorFields = aClass.getDeclaredFields();
for(Field field: colorFields) {
if ((field.getModifiers() & Modifier.STATIC) != 0 &&
Color.class.isAssignableFrom(field.getType()) &&
Character.isLowerCase(field.getName().charAt(0))) {
final ColorDescriptor color = isSystem
? ColorDescriptor.fromSystemColor(field.getName())
: ColorDescriptor.fromAWTColor(field.getName());
result.add(color);
}
}
return result;
}
public void setSelectedValue(@NotNull final ColorDescriptor value) {
myColorChooser.setColor(new ColorDescriptorWrapper(value));
selectTabForColor(value);
}
public ColorDescriptor getSelectedValue() {
final Color color = myColorChooser.getColor();
if (color instanceof ColorDescriptorWrapper) {
return ((ColorDescriptorWrapper) color).getDescriptor();
}
return new ColorDescriptor(color);
}
}
private static class MyDescriptorChooserPanel extends AbstractColorChooserPanel {
private final String myDisplayName;
private final ColorDescriptor[] myColorDescriptors;
private JList myDescriptorList;
public MyDescriptorChooserPanel(final String displayName, List<ColorDescriptor> colorDescriptorList) {
myDisplayName = displayName;
Collections.sort(colorDescriptorList, new Comparator<ColorDescriptor>() {
public int compare(final ColorDescriptor o1, final ColorDescriptor o2) {
return o1.toString().compareTo(o2.toString());
}
});
myColorDescriptors = colorDescriptorList.toArray(new ColorDescriptor[colorDescriptorList.size()]);
}
public void updateChooser() {
myDescriptorList.setSelectedValue(getColorFromModel(), true);
}
protected void buildChooser() {
setLayout(new BorderLayout());
myDescriptorList = new JBList(myColorDescriptors);
myDescriptorList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
myDescriptorList.setVisibleRowCount(15);
myDescriptorList.setCellRenderer(new ColorRenderer());
myDescriptorList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
ColorDescriptor descriptor = (ColorDescriptor)myDescriptorList.getSelectedValue();
getColorSelectionModel().setSelectedColor(new ColorDescriptorWrapper(descriptor));
}
});
new ListSpeedSearch(myDescriptorList);
add(ScrollPaneFactory.createScrollPane(myDescriptorList), BorderLayout.CENTER);
}
public String getDisplayName() {
return myDisplayName;
}
@Nullable
public Icon getSmallDisplayIcon() {
return null;
}
@Nullable
public Icon getLargeDisplayIcon() {
return null;
}
}
}