Merge branch 'master' of git.labs.intellij.net:idea/community

Conflicts:
	platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleManagerImpl.java
This commit is contained in:
Dmitry Trofimov
2010-11-11 21:36:40 +03:00
613 changed files with 194624 additions and 191225 deletions
@@ -1,154 +1,156 @@
/*
* Copyright 2000-2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.debugger.actions;
import com.intellij.debugger.DebuggerManagerEx;
import com.intellij.debugger.SourcePosition;
import com.intellij.debugger.engine.RequestHint;
import com.intellij.debugger.engine.SuspendContextImpl;
import com.intellij.debugger.impl.DebuggerContextImpl;
import com.intellij.debugger.impl.DebuggerSession;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.TextEditor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.ListPopup;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.util.containers.OrderedSet;
import com.intellij.util.text.CharArrayUtil;
import com.intellij.xdebugger.impl.actions.DebuggerActionHandler;
import com.intellij.xdebugger.impl.ui.DebuggerUIUtil;
import gnu.trove.TObjectHashingStrategy;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
public class SmartStepIntoActionHandler extends DebuggerActionHandler {
public void perform(@NotNull final Project project, final AnActionEvent event) {
final DebuggerContextImpl debuggerContext = (DebuggerManagerEx.getInstanceEx(project)).getContext();
doStep(project, debuggerContext.getSourcePosition(), debuggerContext.getDebuggerSession());
}
private static void doStep(final @NotNull Project project, final @Nullable SourcePosition position, final @NotNull DebuggerSession session) {
final VirtualFile file = position != null ? position.getFile().getVirtualFile() : null;
final FileEditor fileEditor = file != null? FileEditorManager.getInstance(project).getSelectedEditor(file) : null;
if (fileEditor instanceof TextEditor) {
final List<PsiMethod> methods = findReferencedMethods(position);
if (methods.size() > 0) {
if (methods.size() == 1) {
session.stepInto(true, createSmartStepFilter(methods.get(0)));
}
else {
final PsiMethodListPopupStep popupStep = new PsiMethodListPopupStep(methods, new PsiMethodListPopupStep.OnChooseRunnable() {
public void execute(PsiMethod chosenMethod) {
session.stepInto(true, createSmartStepFilter(chosenMethod));
}
});
final ListPopup popup = JBPopupFactory.getInstance().createListPopup(popupStep);
final RelativePoint point = DebuggerUIUtil.calcPopupLocation(((TextEditor)fileEditor).getEditor(), position.getLine());
popup.show(point);
}
return;
}
}
session.stepInto(true, null);
}
@Nullable
private static RequestHint.SmartStepFilter createSmartStepFilter(final PsiMethod method) {
return new RequestHint.SmartStepFilter(method);
}
private static List<PsiMethod> findReferencedMethods(final SourcePosition position) {
final int line = position.getLine();
if (line < 0) {
return Collections.emptyList(); // the document has been changed
}
final PsiFile file = position.getFile();
final VirtualFile vFile = file.getVirtualFile();
if (vFile == null) {
// the file is not physical
return Collections.emptyList();
}
final Document doc = FileDocumentManager.getInstance().getDocument(vFile);
final int startOffset = doc.getLineStartOffset(line);
final TextRange lineRange = new TextRange(startOffset, doc.getLineEndOffset(line));
final int offset = CharArrayUtil.shiftForward(doc.getCharsSequence(), startOffset, " \t");
PsiElement element = file.findElementAt(offset);
if (element != null && !(element instanceof PsiCompiledElement)) {
do {
final PsiElement parent = element.getParent();
if (parent == null || (parent.getTextOffset() < lineRange.getStartOffset())) {
break;
}
element = parent;
}
while(true);
//noinspection unchecked
final List<PsiMethod> methods = new OrderedSet<PsiMethod>(TObjectHashingStrategy.CANONICAL);
final PsiElementVisitor methodCollector = new JavaRecursiveElementWalkingVisitor() {
@Override public void visitAnonymousClass(PsiAnonymousClass aClass) { /*skip annonymous classes*/ }
@Override public void visitStatement(PsiStatement statement) {
if (lineRange.intersects(statement.getTextRange())) {
super.visitStatement(statement);
}
}
@Override public void visitCallExpression(final PsiCallExpression expression) {
final PsiMethod psiMethod = expression.resolveMethod();
if (psiMethod != null) {
methods.add(psiMethod);
}
super.visitCallExpression(expression);
}
};
element.accept(methodCollector);
for (PsiElement sibling = element.getNextSibling(); sibling != null; sibling = sibling.getNextSibling()) {
if (!lineRange.intersects(sibling.getTextRange())) {
break;
}
sibling.accept(methodCollector);
}
return methods;
}
return Collections.emptyList();
}
public boolean isEnabled(@NotNull final Project project, final AnActionEvent event) {
final DebuggerContextImpl context = (DebuggerManagerEx.getInstanceEx(project)).getContext();
DebuggerSession debuggerSession = context.getDebuggerSession();
final boolean isPaused = debuggerSession != null && debuggerSession.isPaused();
final SuspendContextImpl suspendContext = context.getSuspendContext();
final boolean hasCurrentThread = suspendContext != null && suspendContext.getThread() != null;
return isPaused && hasCurrentThread;
}
}
/*
* Copyright 2000-2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.debugger.actions;
import com.intellij.debugger.DebuggerManagerEx;
import com.intellij.debugger.SourcePosition;
import com.intellij.debugger.engine.RequestHint;
import com.intellij.debugger.engine.SuspendContextImpl;
import com.intellij.debugger.impl.DebuggerContextImpl;
import com.intellij.debugger.impl.DebuggerSession;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.TextEditor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.ListPopup;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.util.containers.OrderedSet;
import com.intellij.util.text.CharArrayUtil;
import com.intellij.xdebugger.impl.actions.DebuggerActionHandler;
import com.intellij.xdebugger.impl.ui.DebuggerUIUtil;
import gnu.trove.TObjectHashingStrategy;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
public class SmartStepIntoActionHandler extends DebuggerActionHandler {
public void perform(@NotNull final Project project, final AnActionEvent event) {
final DebuggerContextImpl debuggerContext = (DebuggerManagerEx.getInstanceEx(project)).getContext();
doStep(project, debuggerContext.getSourcePosition(), debuggerContext.getDebuggerSession());
}
private static void doStep(final @NotNull Project project, final @Nullable SourcePosition position, final @NotNull DebuggerSession session) {
final VirtualFile file = position != null ? position.getFile().getVirtualFile() : null;
final FileEditor fileEditor = file != null? FileEditorManager.getInstance(project).getSelectedEditor(file) : null;
if (fileEditor instanceof TextEditor) {
final List<PsiMethod> methods = findReferencedMethods(position);
if (methods.size() > 0) {
if (methods.size() == 1) {
session.stepInto(true, createSmartStepFilter(methods.get(0)));
}
else {
final PsiMethodListPopupStep popupStep = new PsiMethodListPopupStep(methods, new PsiMethodListPopupStep.OnChooseRunnable() {
public void execute(PsiMethod chosenMethod) {
session.stepInto(true, createSmartStepFilter(chosenMethod));
}
});
final ListPopup popup = JBPopupFactory.getInstance().createListPopup(popupStep);
final RelativePoint point = DebuggerUIUtil.calcPopupLocation(((TextEditor)fileEditor).getEditor(), position.getLine());
popup.show(point);
}
return;
}
}
session.stepInto(true, null);
}
@Nullable
private static RequestHint.SmartStepFilter createSmartStepFilter(final PsiMethod method) {
return new RequestHint.SmartStepFilter(method);
}
private static List<PsiMethod> findReferencedMethods(final SourcePosition position) {
final int line = position.getLine();
if (line < 0) {
return Collections.emptyList(); // the document has been changed
}
final PsiFile file = position.getFile();
final VirtualFile vFile = file.getVirtualFile();
if (vFile == null) {
// the file is not physical
return Collections.emptyList();
}
final Document doc = FileDocumentManager.getInstance().getDocument(vFile);
if (line >= doc.getLineCount()) {
return Collections.emptyList(); // the document has been changed
}
final int startOffset = doc.getLineStartOffset(line);
final TextRange lineRange = new TextRange(startOffset, doc.getLineEndOffset(line));
final int offset = CharArrayUtil.shiftForward(doc.getCharsSequence(), startOffset, " \t");
PsiElement element = file.findElementAt(offset);
if (element != null && !(element instanceof PsiCompiledElement)) {
do {
final PsiElement parent = element.getParent();
if (parent == null || (parent.getTextOffset() < lineRange.getStartOffset())) {
break;
}
element = parent;
}
while(true);
//noinspection unchecked
final List<PsiMethod> methods = new OrderedSet<PsiMethod>(TObjectHashingStrategy.CANONICAL);
final PsiElementVisitor methodCollector = new JavaRecursiveElementWalkingVisitor() {
@Override public void visitAnonymousClass(PsiAnonymousClass aClass) { /*skip annonymous classes*/ }
@Override public void visitStatement(PsiStatement statement) {
if (lineRange.intersects(statement.getTextRange())) {
super.visitStatement(statement);
}
}
@Override public void visitCallExpression(final PsiCallExpression expression) {
final PsiMethod psiMethod = expression.resolveMethod();
if (psiMethod != null) {
methods.add(psiMethod);
}
super.visitCallExpression(expression);
}
};
element.accept(methodCollector);
for (PsiElement sibling = element.getNextSibling(); sibling != null; sibling = sibling.getNextSibling()) {
if (!lineRange.intersects(sibling.getTextRange())) {
break;
}
sibling.accept(methodCollector);
}
return methods;
}
return Collections.emptyList();
}
public boolean isEnabled(@NotNull final Project project, final AnActionEvent event) {
final DebuggerContextImpl context = (DebuggerManagerEx.getInstanceEx(project)).getContext();
DebuggerSession debuggerSession = context.getDebuggerSession();
final boolean isPaused = debuggerSession != null && debuggerSession.isPaused();
final SuspendContextImpl suspendContext = context.getSuspendContext();
final boolean hasCurrentThread = suspendContext != null && suspendContext.getThread() != null;
return isPaused && hasCurrentThread;
}
}
@@ -1,144 +1,144 @@
/*
* Copyright 2000-2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.debugger.ui;
import com.intellij.debugger.impl.DebuggerSession;
import com.intellij.debugger.settings.DebuggerSettings;
import com.intellij.debugger.DebuggerBundle;
import com.intellij.ide.util.ElementsChooser;
import com.intellij.openapi.project.Project;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.util.ui.OptionsDialog;
import com.intellij.util.ui.UIUtil;
import com.intellij.CommonBundle;
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.util.List;
/**
* User: lex
* Date: Oct 6, 2003
* Time: 5:58:17 PM
*/
public class RunHotswapDialog extends OptionsDialog {
private final JPanel myPanel;
private final ElementsChooser<SessionItem> myElementsChooser;
public RunHotswapDialog(Project project, java.util.List<DebuggerSession> sessions) {
super(project);
myPanel = new JPanel(new BorderLayout());
final List<SessionItem> items = new ArrayList<SessionItem>(sessions.size());
for (DebuggerSession session : sessions) {
items.add(new SessionItem(session));
}
Collections.sort(items, new Comparator<SessionItem>() {
public int compare(SessionItem debuggerSession, SessionItem debuggerSession1) {
return debuggerSession.getSession().getSessionName().compareTo(debuggerSession1.getSession().getSessionName());
}
});
myElementsChooser = new ElementsChooser<SessionItem>(items, true);
myPanel.setBorder(IdeBorderFactory.createEmptyBorder(10, 0, 5, 0));
//myElementsChooser.setBorder(IdeBorderFactory.createEmptyBorder(5, 0, 0, 0));
if (sessions.size() > 0) {
myElementsChooser.selectElements(items.subList(0, 1));
}
myPanel.add(myElementsChooser, BorderLayout.CENTER);
//myPanel.add(new JLabel("Choose debug sessions to reload classes:"), BorderLayout.NORTH);
if(sessions.size() == 1) {
setTitle(DebuggerBundle.message("hotswap.dialog.title.with.session", sessions.get(0).getSessionName()));
myPanel.setVisible(false);
}
else {
setTitle(DebuggerBundle.message("hotswap.dialog.title"));
}
setButtonsAlignment(SwingUtilities.CENTER);
this.init();
}
protected boolean isToBeShown() {
return DebuggerSettings.RUN_HOTSWAP_ASK.equals(DebuggerSettings.getInstance().RUN_HOTSWAP_AFTER_COMPILE);
}
protected void setToBeShown(boolean value, boolean onOk) {
if (value) {
DebuggerSettings.getInstance().RUN_HOTSWAP_AFTER_COMPILE = DebuggerSettings.RUN_HOTSWAP_ASK;
}
else {
if (onOk) {
DebuggerSettings.getInstance().RUN_HOTSWAP_AFTER_COMPILE = DebuggerSettings.RUN_HOTSWAP_ALWAYS;
}
else {
DebuggerSettings.getInstance().RUN_HOTSWAP_AFTER_COMPILE = DebuggerSettings.RUN_HOTSWAP_NEVER;
}
}
}
protected boolean shouldSaveOptionsOnCancel() {
return true;
}
protected Action[] createActions(){
setOKButtonText(CommonBundle.getYesButtonText());
setCancelButtonText(CommonBundle.getNoButtonText());
return new Action[]{getOKAction(), getCancelAction()};
}
protected JComponent createNorthPanel() {
JLabel label = new JLabel(DebuggerBundle.message("hotswap.dialog.run.prompt"));
JPanel panel = new JPanel(new BorderLayout());
panel.add(label, BorderLayout.CENTER);
Icon icon = UIUtil.getOptionPanelQuestionIcon();
if (icon != null) {
label.setIcon(icon);
label.setIconTextGap(7);
}
return panel;
}
protected JComponent createCenterPanel() {
return myPanel;
}
public Collection<DebuggerSession> getSessionsToReload() {
final List<SessionItem> markedElements = myElementsChooser.getMarkedElements();
final List<DebuggerSession> sessions = new ArrayList<DebuggerSession>(markedElements.size());
for (SessionItem item : markedElements) {
sessions.add(item.getSession());
}
return sessions;
}
private static class SessionItem {
private final DebuggerSession mySession;
public SessionItem(DebuggerSession session) {
mySession = session;
}
public DebuggerSession getSession() {
return mySession;
}
public String toString() {
return mySession.getSessionName();
}
}
}
/*
* Copyright 2000-2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.debugger.ui;
import com.intellij.debugger.impl.DebuggerSession;
import com.intellij.debugger.settings.DebuggerSettings;
import com.intellij.debugger.DebuggerBundle;
import com.intellij.ide.util.ElementsChooser;
import com.intellij.openapi.project.Project;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.util.ui.OptionsDialog;
import com.intellij.util.ui.UIUtil;
import com.intellij.CommonBundle;
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.util.List;
/**
* User: lex
* Date: Oct 6, 2003
* Time: 5:58:17 PM
*/
public class RunHotswapDialog extends OptionsDialog {
private final JPanel myPanel;
private final ElementsChooser<SessionItem> myElementsChooser;
public RunHotswapDialog(Project project, java.util.List<DebuggerSession> sessions) {
super(project);
myPanel = new JPanel(new BorderLayout());
final List<SessionItem> items = new ArrayList<SessionItem>(sessions.size());
for (DebuggerSession session : sessions) {
items.add(new SessionItem(session));
}
Collections.sort(items, new Comparator<SessionItem>() {
public int compare(SessionItem debuggerSession, SessionItem debuggerSession1) {
return debuggerSession.getSession().getSessionName().compareTo(debuggerSession1.getSession().getSessionName());
}
});
myElementsChooser = new ElementsChooser<SessionItem>(items, true);
myPanel.setBorder(IdeBorderFactory.createEmptyBorder(10, 0, 5, 0));
//myElementsChooser.setBorder(IdeBorderFactory.createEmptyBorder(5, 0, 0, 0));
if (sessions.size() > 0) {
myElementsChooser.selectElements(items.subList(0, 1));
}
myPanel.add(myElementsChooser, BorderLayout.CENTER);
//myPanel.add(new JLabel("Choose debug sessions to reload classes:"), BorderLayout.NORTH);
if(sessions.size() == 1) {
setTitle(DebuggerBundle.message("hotswap.dialog.title.with.session", sessions.get(0).getSessionName()));
myPanel.setVisible(false);
}
else {
setTitle(DebuggerBundle.message("hotswap.dialog.title"));
}
setButtonsAlignment(SwingUtilities.CENTER);
this.init();
}
protected boolean isToBeShown() {
return DebuggerSettings.RUN_HOTSWAP_ASK.equals(DebuggerSettings.getInstance().RUN_HOTSWAP_AFTER_COMPILE);
}
protected void setToBeShown(boolean value, boolean onOk) {
if (value) {
DebuggerSettings.getInstance().RUN_HOTSWAP_AFTER_COMPILE = DebuggerSettings.RUN_HOTSWAP_ASK;
}
else {
if (onOk) {
DebuggerSettings.getInstance().RUN_HOTSWAP_AFTER_COMPILE = DebuggerSettings.RUN_HOTSWAP_ALWAYS;
}
else {
DebuggerSettings.getInstance().RUN_HOTSWAP_AFTER_COMPILE = DebuggerSettings.RUN_HOTSWAP_NEVER;
}
}
}
protected boolean shouldSaveOptionsOnCancel() {
return true;
}
protected Action[] createActions(){
setOKButtonText(CommonBundle.getYesButtonText());
setCancelButtonText(CommonBundle.getNoButtonText());
return new Action[]{getOKAction(), getCancelAction()};
}
protected JComponent createNorthPanel() {
JLabel label = new JLabel(DebuggerBundle.message("hotswap.dialog.run.prompt"));
JPanel panel = new JPanel(new BorderLayout());
panel.add(label, BorderLayout.CENTER);
Icon icon = UIUtil.getQuestionIcon();
if (icon != null) {
label.setIcon(icon);
label.setIconTextGap(7);
}
return panel;
}
protected JComponent createCenterPanel() {
return myPanel;
}
public Collection<DebuggerSession> getSessionsToReload() {
final List<SessionItem> markedElements = myElementsChooser.getMarkedElements();
final List<DebuggerSession> sessions = new ArrayList<DebuggerSession>(markedElements.size());
for (SessionItem item : markedElements) {
sessions.add(item.getSession());
}
return sessions;
}
private static class SessionItem {
private final DebuggerSession mySession;
public SessionItem(DebuggerSession session) {
mySession = session;
}
public DebuggerSession getSession() {
return mySession;
}
public String toString() {
return mySession.getSessionName();
}
}
}
@@ -1,136 +1,137 @@
/*
* Copyright 2000-2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.debugger.ui.impl;
import com.intellij.debugger.impl.DebuggerContextImpl;
import com.intellij.debugger.impl.DebuggerContextListener;
import com.intellij.debugger.impl.DebuggerStateManager;
import com.intellij.debugger.ui.DebuggerView;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.ShortcutSet;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.util.Alarm;
import com.sun.jdi.VMDisconnectedException;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
public abstract class UpdatableDebuggerView extends JPanel implements DebuggerView {
private final Project myProject;
private final DebuggerStateManager myStateManager;
protected final Alarm myRebuildAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD);
protected volatile boolean myRefreshNeeded = true;
protected final java.util.List<Disposable> myDisposables = new ArrayList<Disposable>();
private boolean myUpdateEnabled;
protected UpdatableDebuggerView(final Project project, final DebuggerStateManager stateManager) {
setLayout(new BorderLayout());
myProject = project;
myStateManager = stateManager;
final DebuggerContextListener contextListener = new DebuggerContextListener() {
public void changeEvent(DebuggerContextImpl newContext, int event) {
UpdatableDebuggerView.this.changeEvent(newContext, event);
}
};
myStateManager.addListener(contextListener);
registerDisposable(new Disposable() {
public void dispose() {
myStateManager.removeListener(contextListener);
}
});
}
protected void changeEvent(final DebuggerContextImpl newContext, final int event) {
if (newContext.getDebuggerSession() != null) {
rebuildIfVisible(event);
}
}
protected final boolean isUpdateEnabled() {
return myUpdateEnabled;
}
public final void setUpdateEnabled(final boolean enabled) {
myUpdateEnabled = enabled;
}
public final boolean isRefreshNeeded() {
return myRefreshNeeded;
}
public final void rebuildIfVisible(final int event) {
if(isUpdateEnabled()) {
myRefreshNeeded = false;
myRebuildAlarm.cancelAllRequests();
myRebuildAlarm.addRequest(new Runnable() {
public void run() {
try {
rebuild(event);
}
catch (VMDisconnectedException e) {
// ignored
}
}
}, 100);
}
else {
myRefreshNeeded = true;
}
}
protected abstract void rebuild(int event);
protected final void registerDisposable(Disposable disposable) {
myDisposables.add(disposable);
}
public DebuggerContextImpl getContext() {
return myStateManager.getContext();
}
protected final Project getProject() {
return myProject;
}
public DebuggerStateManager getContextManager() {
return myStateManager;
}
public void dispose() {
Disposer.dispose(myRebuildAlarm);
for (Disposable disposable : myDisposables) {
Disposer.dispose(disposable);
}
myDisposables.clear();
}
protected void overrideShortcut(final JComponent forComponent, final String actionId, final ShortcutSet shortcutSet) {
final AnAction action = ActionManager.getInstance().getAction(actionId);
action.registerCustomShortcutSet(shortcutSet, forComponent);
registerDisposable(new Disposable() {
public void dispose() {
action.unregisterCustomShortcutSet(forComponent);
}
});
}
}
/*
* Copyright 2000-2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.debugger.ui.impl;
import com.intellij.debugger.impl.DebuggerContextImpl;
import com.intellij.debugger.impl.DebuggerContextListener;
import com.intellij.debugger.impl.DebuggerStateManager;
import com.intellij.debugger.ui.DebuggerView;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.ShortcutSet;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.util.Alarm;
import com.sun.jdi.VMDisconnectedException;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
public abstract class UpdatableDebuggerView extends JPanel implements DebuggerView {
private final Project myProject;
private final DebuggerStateManager myStateManager;
protected final Alarm myRebuildAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD);
protected volatile boolean myRefreshNeeded = true;
protected final java.util.List<Disposable> myDisposables = new ArrayList<Disposable>();
private boolean myUpdateEnabled;
protected UpdatableDebuggerView(final Project project, final DebuggerStateManager stateManager) {
setLayout(new BorderLayout());
myProject = project;
myStateManager = stateManager;
final DebuggerContextListener contextListener = new DebuggerContextListener() {
public void changeEvent(DebuggerContextImpl newContext, int event) {
UpdatableDebuggerView.this.changeEvent(newContext, event);
}
};
myStateManager.addListener(contextListener);
registerDisposable(new Disposable() {
public void dispose() {
myStateManager.removeListener(contextListener);
}
});
}
protected void changeEvent(final DebuggerContextImpl newContext, final int event) {
if (newContext.getDebuggerSession() != null) {
rebuildIfVisible(event);
}
}
protected final boolean isUpdateEnabled() {
return myUpdateEnabled;
}
public final void setUpdateEnabled(final boolean enabled) {
myUpdateEnabled = enabled;
}
public final boolean isRefreshNeeded() {
return myRefreshNeeded;
}
public final void rebuildIfVisible(final int event) {
if(isUpdateEnabled()) {
myRefreshNeeded = false;
myRebuildAlarm.cancelAllRequests();
myRebuildAlarm.addRequest(new Runnable() {
public void run() {
try {
rebuild(event);
}
catch (VMDisconnectedException e) {
// ignored
}
}
}, 100, ModalityState.NON_MODAL);
}
else {
myRefreshNeeded = true;
}
}
protected abstract void rebuild(int event);
protected final void registerDisposable(Disposable disposable) {
myDisposables.add(disposable);
}
public DebuggerContextImpl getContext() {
return myStateManager.getContext();
}
protected final Project getProject() {
return myProject;
}
public DebuggerStateManager getContextManager() {
return myStateManager;
}
public void dispose() {
Disposer.dispose(myRebuildAlarm);
for (Disposable disposable : myDisposables) {
Disposer.dispose(disposable);
}
myDisposables.clear();
}
protected void overrideShortcut(final JComponent forComponent, final String actionId, final ShortcutSet shortcutSet) {
final AnAction action = ActionManager.getInstance().getAction(actionId);
action.registerCustomShortcutSet(shortcutSet, forComponent);
registerDisposable(new Disposable() {
public void dispose() {
action.unregisterCustomShortcutSet(forComponent);
}
});
}
}
File diff suppressed because it is too large Load Diff
@@ -1,269 +1,279 @@
/*
* Copyright 2000-2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.debugger.ui.tree.render;
import com.intellij.debugger.DebuggerBundle;
import com.intellij.debugger.DebuggerContext;
import com.intellij.debugger.engine.DebuggerManagerThreadImpl;
import com.intellij.debugger.engine.DebuggerUtils;
import com.intellij.debugger.engine.evaluation.EvaluateException;
import com.intellij.debugger.engine.evaluation.EvaluationContext;
import com.intellij.debugger.ui.impl.watch.FieldDescriptorImpl;
import com.intellij.debugger.ui.impl.watch.MessageDescriptor;
import com.intellij.debugger.ui.impl.watch.NodeManagerImpl;
import com.intellij.debugger.ui.impl.watch.ValueDescriptorImpl;
import com.intellij.debugger.ui.tree.*;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.DefaultJDOMExternalizer;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiElementFactory;
import com.intellij.psi.PsiExpression;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.StringBuilderSpinAllocator;
import com.sun.jdi.*;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* User: lex
* Date: Sep 17, 2003
* Time: 2:04:00 PM
*/
public class ClassRenderer extends NodeRendererImpl{
private static final Logger LOG = Logger.getInstance("#com.intellij.debugger.ui.tree.render.ClassRenderer");
public static final @NonNls String UNIQUE_ID = "ClassRenderer";
public boolean SORT_ASCENDING = false;
public boolean SHOW_SYNTHETICS = true;
public boolean SHOW_STATIC = false;
public boolean SHOW_STATIC_FINAL = false;
public boolean SHOW_DECLARED_TYPE = false;
public boolean SHOW_OBJECT_ID = true;
public ClassRenderer() {
myProperties.setEnabled(true);
}
public String getUniqueId() {
return UNIQUE_ID;
}
public boolean isEnabled() {
return myProperties.isEnabled();
}
public void setEnabled(boolean enabled) {
myProperties.setEnabled(enabled);
}
public ClassRenderer clone() {
return (ClassRenderer) super.clone();
}
public String calcLabel(ValueDescriptor descriptor, EvaluationContext evaluationContext, DescriptorLabelListener labelListener) throws EvaluateException {
return calcLabel(descriptor);
}
protected static String calcLabel(ValueDescriptor descriptor) {
final ValueDescriptorImpl valueDescriptor = (ValueDescriptorImpl)descriptor;
final Value value = valueDescriptor.getValue();
if (value instanceof ObjectReference) {
final StringBuilder buf = StringBuilderSpinAllocator.alloc();
try {
if (value instanceof StringReference) {
buf.append('\"');
buf.append(((StringReference)value).value());
buf.append('\"');
}
else if (value instanceof ClassObjectReference) {
ReferenceType type = ((ClassObjectReference)value).reflectedType();
buf.append((type != null)?type.name():"{...}");
}
else {
final ObjectReference objRef = (ObjectReference)value;
final Type type = objRef.type();
if (type instanceof ClassType && ((ClassType)type).isEnum()) {
final String name = getEnumConstantName(objRef, (ClassType)type);
if (name != null) {
buf.append(name);
}
else {
buf.append(type.name());
}
}
else {
buf.append(ValueDescriptorImpl.getIdLabel(objRef));
}
}
return buf.toString();
}
finally {
StringBuilderSpinAllocator.dispose(buf);
}
}
else if(value == null) {
//noinspection HardCodedStringLiteral
return "null";
}
else {
return DebuggerBundle.message("label.undefined");
}
}
public void buildChildren(final Value value, final ChildrenBuilder builder, final EvaluationContext evaluationContext) {
DebuggerManagerThreadImpl.assertIsManagerThread();
final ValueDescriptorImpl parentDescriptor = (ValueDescriptorImpl)builder.getParentDescriptor();
final NodeManager nodeManager = builder.getNodeManager();
final NodeDescriptorFactory nodeDescriptorFactory = builder.getDescriptorManager();
List<DebuggerTreeNode> children = new ArrayList<DebuggerTreeNode>();
if (value instanceof ObjectReference) {
final ObjectReference objRef = (ObjectReference)value;
final ReferenceType refType = objRef.referenceType();
// default ObjectReference processing
final List<Field> fields = refType.allFields();
if (fields.size() > 0) {
for (final Field field : fields) {
if (!shouldDisplay(evaluationContext, objRef, field)) {
continue;
}
children.add(nodeManager.createNode(nodeDescriptorFactory.getFieldDescriptor(parentDescriptor, objRef, field), evaluationContext));
}
if(SORT_ASCENDING) {
Collections.sort(children, NodeManagerImpl.getNodeComparator());
}
}
else {
children.add(nodeManager.createMessageNode(MessageDescriptor.CLASS_HAS_NO_FIELDS.getLabel()));
}
}
builder.setChildren(children);
}
private boolean shouldDisplay(EvaluationContext context, @NotNull ObjectReference objInstance, @NotNull Field field) {
final boolean isSynthetic = DebuggerUtils.isSynthetic(field);
if (!SHOW_SYNTHETICS && isSynthetic) {
return false;
}
if (isSynthetic) {
if (objInstance.equals(context.getThisObject()) && StringUtil.startsWith(field.name(), FieldDescriptorImpl.OUTER_LOCAL_VAR_FIELD_PREFIX)) {
return false;
}
}
if(!SHOW_STATIC && field.isStatic()) {
return false;
}
if(!SHOW_STATIC_FINAL && field.isStatic() && field.isFinal()) {
return false;
}
return true;
}
public void readExternal(Element element) throws InvalidDataException {
super.readExternal(element);
DefaultJDOMExternalizer.readExternal(this, element);
}
public void writeExternal(Element element) throws WriteExternalException {
super.writeExternal(element);
DefaultJDOMExternalizer.writeExternal(this, element);
}
public PsiExpression getChildValueExpression(DebuggerTreeNode node, DebuggerContext context) throws EvaluateException {
FieldDescriptor fieldDescriptor = (FieldDescriptor)node.getDescriptor();
PsiElementFactory elementFactory = JavaPsiFacade.getInstance(node.getProject()).getElementFactory();
try {
return elementFactory.createExpressionFromText(fieldDescriptor.getField().name(), DebuggerUtils.findClass(
fieldDescriptor.getObject().referenceType().name(), context.getProject(), context.getDebugProcess().getSearchScope())
);
}
catch (IncorrectOperationException e) {
throw new EvaluateException(DebuggerBundle.message("error.invalid.field.name", fieldDescriptor.getField().name()), null);
}
}
private static boolean valueExpandable(Value value) {
try {
if(value instanceof ArrayReference) {
return ((ArrayReference)value).length() > 0;
}
else if(value instanceof ObjectReference) {
return ((ObjectReference)value).referenceType().allFields().size() > 0;
}
}
catch (ObjectCollectedException e) {
return true;
}
return false;
}
public boolean isExpandable(Value value, EvaluationContext evaluationContext, NodeDescriptor parentDescriptor) {
DebuggerManagerThreadImpl.assertIsManagerThread();
return valueExpandable(value);
}
public boolean isApplicable(Type type) {
return type instanceof ReferenceType && !(type instanceof ArrayType);
}
public @NonNls String getName() {
return "Object";
}
public void setName(String text) {
LOG.assertTrue(false);
}
@Nullable
public static String getEnumConstantName(final ObjectReference objRef, ClassType classType) {
do {
if (!classType.isPrepared()) {
return null;
}
classType = classType.superclass();
if (classType == null) {
return null;
}
}
while (!("java.lang.Enum".equals(classType.name())));
//noinspection HardCodedStringLiteral
final Field field = classType.fieldByName("name");
if (field == null) {
return null;
}
final Value value = objRef.getValue(field);
if (!(value instanceof StringReference)) {
return null;
}
return ((StringReference)value).value();
}
}
/*
* Copyright 2000-2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.debugger.ui.tree.render;
import com.intellij.debugger.DebuggerBundle;
import com.intellij.debugger.DebuggerContext;
import com.intellij.debugger.engine.DebuggerManagerThreadImpl;
import com.intellij.debugger.engine.DebuggerUtils;
import com.intellij.debugger.engine.evaluation.EvaluateException;
import com.intellij.debugger.engine.evaluation.EvaluationContext;
import com.intellij.debugger.engine.jdi.StackFrameProxy;
import com.intellij.debugger.ui.impl.watch.FieldDescriptorImpl;
import com.intellij.debugger.ui.impl.watch.MessageDescriptor;
import com.intellij.debugger.ui.impl.watch.NodeManagerImpl;
import com.intellij.debugger.ui.impl.watch.ValueDescriptorImpl;
import com.intellij.debugger.ui.tree.*;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.DefaultJDOMExternalizer;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiElementFactory;
import com.intellij.psi.PsiExpression;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.StringBuilderSpinAllocator;
import com.sun.jdi.*;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* User: lex
* Date: Sep 17, 2003
* Time: 2:04:00 PM
*/
public class ClassRenderer extends NodeRendererImpl{
private static final Logger LOG = Logger.getInstance("#com.intellij.debugger.ui.tree.render.ClassRenderer");
public static final @NonNls String UNIQUE_ID = "ClassRenderer";
public boolean SORT_ASCENDING = false;
public boolean SHOW_SYNTHETICS = true;
public boolean SHOW_STATIC = false;
public boolean SHOW_STATIC_FINAL = false;
public boolean SHOW_DECLARED_TYPE = false;
public boolean SHOW_OBJECT_ID = true;
public ClassRenderer() {
myProperties.setEnabled(true);
}
public String getUniqueId() {
return UNIQUE_ID;
}
public boolean isEnabled() {
return myProperties.isEnabled();
}
public void setEnabled(boolean enabled) {
myProperties.setEnabled(enabled);
}
public ClassRenderer clone() {
return (ClassRenderer) super.clone();
}
public String calcLabel(ValueDescriptor descriptor, EvaluationContext evaluationContext, DescriptorLabelListener labelListener) throws EvaluateException {
return calcLabel(descriptor);
}
protected static String calcLabel(ValueDescriptor descriptor) {
final ValueDescriptorImpl valueDescriptor = (ValueDescriptorImpl)descriptor;
final Value value = valueDescriptor.getValue();
if (value instanceof ObjectReference) {
final StringBuilder buf = StringBuilderSpinAllocator.alloc();
try {
if (value instanceof StringReference) {
buf.append('\"');
buf.append(((StringReference)value).value());
buf.append('\"');
}
else if (value instanceof ClassObjectReference) {
ReferenceType type = ((ClassObjectReference)value).reflectedType();
buf.append((type != null)?type.name():"{...}");
}
else {
final ObjectReference objRef = (ObjectReference)value;
final Type type = objRef.type();
if (type instanceof ClassType && ((ClassType)type).isEnum()) {
final String name = getEnumConstantName(objRef, (ClassType)type);
if (name != null) {
buf.append(name);
}
else {
buf.append(type.name());
}
}
else {
buf.append(ValueDescriptorImpl.getIdLabel(objRef));
}
}
return buf.toString();
}
finally {
StringBuilderSpinAllocator.dispose(buf);
}
}
else if(value == null) {
//noinspection HardCodedStringLiteral
return "null";
}
else {
return DebuggerBundle.message("label.undefined");
}
}
public void buildChildren(final Value value, final ChildrenBuilder builder, final EvaluationContext evaluationContext) {
DebuggerManagerThreadImpl.assertIsManagerThread();
final ValueDescriptorImpl parentDescriptor = (ValueDescriptorImpl)builder.getParentDescriptor();
final NodeManager nodeManager = builder.getNodeManager();
final NodeDescriptorFactory nodeDescriptorFactory = builder.getDescriptorManager();
List<DebuggerTreeNode> children = new ArrayList<DebuggerTreeNode>();
if (value instanceof ObjectReference) {
final ObjectReference objRef = (ObjectReference)value;
final ReferenceType refType = objRef.referenceType();
// default ObjectReference processing
final List<Field> fields = refType.allFields();
if (fields.size() > 0) {
for (final Field field : fields) {
if (!shouldDisplay(evaluationContext, objRef, field)) {
continue;
}
children.add(nodeManager.createNode(nodeDescriptorFactory.getFieldDescriptor(parentDescriptor, objRef, field), evaluationContext));
}
if(SORT_ASCENDING) {
Collections.sort(children, NodeManagerImpl.getNodeComparator());
}
}
else {
children.add(nodeManager.createMessageNode(MessageDescriptor.CLASS_HAS_NO_FIELDS.getLabel()));
}
}
builder.setChildren(children);
}
private boolean shouldDisplay(EvaluationContext context, @NotNull ObjectReference objInstance, @NotNull Field field) {
final boolean isSynthetic = DebuggerUtils.isSynthetic(field);
if (!SHOW_SYNTHETICS && isSynthetic) {
return false;
}
if (isSynthetic) {
try {
final StackFrameProxy frameProxy = context.getFrameProxy();
if (frameProxy != null) {
final Location location = frameProxy.location();
if (location != null && objInstance.equals(context.getThisObject()) && Comparing.equal(objInstance.referenceType(), location.declaringType()) && StringUtil.startsWith(field.name(), FieldDescriptorImpl.OUTER_LOCAL_VAR_FIELD_PREFIX)) {
return false;
}
}
}
catch (EvaluateException ignored) {
}
}
if(!SHOW_STATIC && field.isStatic()) {
return false;
}
if(!SHOW_STATIC_FINAL && field.isStatic() && field.isFinal()) {
return false;
}
return true;
}
public void readExternal(Element element) throws InvalidDataException {
super.readExternal(element);
DefaultJDOMExternalizer.readExternal(this, element);
}
public void writeExternal(Element element) throws WriteExternalException {
super.writeExternal(element);
DefaultJDOMExternalizer.writeExternal(this, element);
}
public PsiExpression getChildValueExpression(DebuggerTreeNode node, DebuggerContext context) throws EvaluateException {
FieldDescriptor fieldDescriptor = (FieldDescriptor)node.getDescriptor();
PsiElementFactory elementFactory = JavaPsiFacade.getInstance(node.getProject()).getElementFactory();
try {
return elementFactory.createExpressionFromText(fieldDescriptor.getField().name(), DebuggerUtils.findClass(
fieldDescriptor.getObject().referenceType().name(), context.getProject(), context.getDebugProcess().getSearchScope())
);
}
catch (IncorrectOperationException e) {
throw new EvaluateException(DebuggerBundle.message("error.invalid.field.name", fieldDescriptor.getField().name()), null);
}
}
private static boolean valueExpandable(Value value) {
try {
if(value instanceof ArrayReference) {
return ((ArrayReference)value).length() > 0;
}
else if(value instanceof ObjectReference) {
return ((ObjectReference)value).referenceType().allFields().size() > 0;
}
}
catch (ObjectCollectedException e) {
return true;
}
return false;
}
public boolean isExpandable(Value value, EvaluationContext evaluationContext, NodeDescriptor parentDescriptor) {
DebuggerManagerThreadImpl.assertIsManagerThread();
return valueExpandable(value);
}
public boolean isApplicable(Type type) {
return type instanceof ReferenceType && !(type instanceof ArrayType);
}
public @NonNls String getName() {
return "Object";
}
public void setName(String text) {
LOG.assertTrue(false);
}
@Nullable
public static String getEnumConstantName(final ObjectReference objRef, ClassType classType) {
do {
if (!classType.isPrepared()) {
return null;
}
classType = classType.superclass();
if (classType == null) {
return null;
}
}
while (!("java.lang.Enum".equals(classType.name())));
//noinspection HardCodedStringLiteral
final Field field = classType.fieldByName("name");
if (field == null) {
return null;
}
final Value value = objRef.getValue(field);
if (!(value instanceof StringReference)) {
return null;
}
return ((StringReference)value).value();
}
}
@@ -1,56 +1,69 @@
/*
* Copyright 2000-2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.debugger.engine.evaluation;
import com.intellij.openapi.diagnostic.Logger;
import com.sun.jdi.InvocationException;
import com.sun.jdi.ObjectReference;
import org.jetbrains.annotations.Nullable;
public class EvaluateException extends Exception {
private static final Logger LOG = Logger.getInstance("#com.intellij.debugger.engine.evaluation.EvaluateException");
private ObjectReference myTargetException;
public EvaluateException(final String message) {
super(message);
if (LOG.isDebugEnabled()) {
LOG.debug(message);
}
}
public EvaluateException(String msg, Throwable th) {
super(msg, th);
if (th instanceof EvaluateException) {
myTargetException = ((EvaluateException)th).getExceptionFromTargetVM();
}
else if(th instanceof InvocationException){
InvocationException invocationException = (InvocationException) th;
myTargetException = invocationException.exception();
}
if (LOG.isDebugEnabled()) {
LOG.debug(msg);
}
}
@Nullable
public ObjectReference getExceptionFromTargetVM() {
return myTargetException;
}
public void setTargetException(final ObjectReference targetException) {
myTargetException = targetException;
}
/*
* Copyright 2000-2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.debugger.engine.evaluation;
import com.intellij.openapi.diagnostic.Logger;
import com.sun.jdi.InvocationException;
import com.sun.jdi.ObjectReference;
import org.jetbrains.annotations.Nullable;
public class EvaluateException extends Exception {
private static final Logger LOG = Logger.getInstance("#com.intellij.debugger.engine.evaluation.EvaluateException");
private ObjectReference myTargetException;
public EvaluateException(final String message) {
super(message);
if (LOG.isDebugEnabled()) {
LOG.debug(message);
}
}
public EvaluateException(String msg, Throwable th) {
super(msg, th);
if (th instanceof EvaluateException) {
myTargetException = ((EvaluateException)th).getExceptionFromTargetVM();
}
else if(th instanceof InvocationException){
InvocationException invocationException = (InvocationException) th;
myTargetException = invocationException.exception();
}
if (LOG.isDebugEnabled()) {
LOG.debug(msg);
}
}
@Nullable
public ObjectReference getExceptionFromTargetVM() {
return myTargetException;
}
public void setTargetException(final ObjectReference targetException) {
myTargetException = targetException;
}
public String getMessage() {
final String errorMessage = super.getMessage();
if (errorMessage != null) {
return errorMessage;
}
final Throwable cause = getCause();
final String causeMessage = cause != null? cause.getMessage() : null;
if (causeMessage != null) {
return causeMessage;
}
return "unknown error";
}
}