diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/EvaluatorBuilderImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/EvaluatorBuilderImpl.java index f3b7427520c2..da7c37b380b7 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/EvaluatorBuilderImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/evaluation/expression/EvaluatorBuilderImpl.java @@ -143,7 +143,7 @@ public class EvaluatorBuilderImpl implements EvaluatorBuilder { throwEvaluateException(DebuggerBundle.message("evaluation.error.unknown.expression.type", lExpression.getText())); } - if(!TypeConversionUtil.areTypesAssignmentCompatible(lType, rExpression)) { + if(!TypeConversionUtil.areTypesAssignmentCompatible(lType, rExpression) && rExpression.getType() != null) { throwEvaluateException(DebuggerBundle.message("evaluation.error.incompatible.types", expression.getOperationSign().getText())); } lExpression.accept(this); diff --git a/java/idea-ui/src/com/intellij/ide/util/importProject/FrameworkDetectionInWizardContext.java b/java/idea-ui/src/com/intellij/ide/util/importProject/FrameworkDetectionInWizardContext.java index a92af56900da..d8c14a28050e 100644 --- a/java/idea-ui/src/com/intellij/ide/util/importProject/FrameworkDetectionInWizardContext.java +++ b/java/idea-ui/src/com/intellij/ide/util/importProject/FrameworkDetectionInWizardContext.java @@ -17,6 +17,7 @@ package com.intellij.ide.util.importProject; import com.intellij.facet.Facet; import com.intellij.facet.FacetConfiguration; +import com.intellij.facet.FacetType; import com.intellij.framework.detection.DetectedFrameworkDescription; import com.intellij.framework.detection.FacetBasedFrameworkDetector; import com.intellij.framework.detection.impl.FrameworkDetectionContextBase; @@ -54,8 +55,14 @@ public abstract class FrameworkDetectionInWizardContext extends FrameworkDetecti } final List result = new ArrayList(); + final FacetType facetType = detector.getFacetType(); for (ModuleDescriptor module : filesByModule.keySet()) { - final List>> pairs = detector.createConfigurations(filesByModule.get(module), Collections.emptyList()); + if (!facetType.isSuitableModuleType(module.getModuleType())) { + continue; + } + + final List>> pairs = + detector.createConfigurations(filesByModule.get(module), Collections.emptyList()); for (Pair> pair : pairs) { result.add(new FacetBasedDetectedFrameworkDescriptionInWizard(module, detector, pair.getFirst(), new HashSet(pair.getSecond()))); diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceConstantHandler.java b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceConstantHandler.java index 79d56cd01fff..d51b1eaacc9e 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceConstantHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceConstantHandler.java @@ -117,7 +117,7 @@ public class IntroduceConstantHandler extends BaseExpressionToFieldHandler { final AbstractInplaceIntroducer activeIntroducer = AbstractInplaceIntroducer.getActiveIntroducer(editor); if (activeIntroducer != null) { - if (!(activeIntroducer instanceof InplaceIntroduceConstantPopup)/* || !activeIntroducer.startsOnTheSameElement(expr, localVariable)*/) { + if (!(activeIntroducer instanceof InplaceIntroduceConstantPopup) || !activeIntroducer.startsOnTheSameElement(expr, localVariable)) { AbstractInplaceIntroducer.unableToStartWarning(project, editor, activeIntroducer); return null; } diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldHandler.java b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldHandler.java index 8a57998a6462..cfa320ba476c 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/IntroduceFieldHandler.java @@ -86,7 +86,7 @@ public class IntroduceFieldHandler extends BaseExpressionToFieldHandler { String enteredName = null; boolean replaceAll = false; if (activeIntroducer != null) { - if (!(activeIntroducer instanceof InplaceIntroduceFieldPopup)/* || !activeIntroducer.startsOnTheSameElement(expr, localVariable)*/) { + if (!(activeIntroducer instanceof InplaceIntroduceFieldPopup) || !activeIntroducer.startsOnTheSameElement(expr, localVariable)) { AbstractInplaceIntroducer.unableToStartWarning(project, editor, activeIntroducer); return null; } diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java index 4b6d928c8cfb..877de83b4027 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/IntroduceParameterHandler.java @@ -388,7 +388,7 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase { final AbstractInplaceIntroducer activeIntroducer = AbstractInplaceIntroducer.getActiveIntroducer(myEditor); if (activeIntroducer != null) { - if (!(activeIntroducer instanceof InplaceIntroduceParameterPopup) /*|| !activeIntroducer.startsOnTheSameElement(myExpr, myLocalVar)*/) { + if (!(activeIntroducer instanceof InplaceIntroduceParameterPopup) || !activeIntroducer.startsOnTheSameElement(myExpr, myLocalVar)) { AbstractInplaceIntroducer.unableToStartWarning(myProject, myEditor, activeIntroducer); return; } diff --git a/platform/bootstrap/src/com/intellij/idea/Main.java b/platform/bootstrap/src/com/intellij/idea/Main.java index aade22a072d8..d3c4d42876f3 100644 --- a/platform/bootstrap/src/com/intellij/idea/Main.java +++ b/platform/bootstrap/src/com/intellij/idea/Main.java @@ -39,19 +39,24 @@ public class Main { } public static void main(final String[] args) { - if (installPatch()) { + /// preload class before installing the patch to prevent class loader problems + Restarter.isSupported(); + if (installPatch()) { boolean restarted = false; + int restartCode = 0; try { restarted = Restarter.restart(); + restartCode = Restarter.getRestartCode(); } - catch (Restarter.CannotRestartException e) { - // noinspection CallToPrintStackTrace + catch (Throwable e) { + // can be either CannotRestartException + // or something like class/method not found if they has been changed during update + + //noinspection CallToPrintStackTrace e.printStackTrace(); } - final int restartCode = Restarter.getRestartCode(); - if (!restarted && restartCode == 0) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); @@ -65,10 +70,11 @@ public class Main { JOptionPane.INFORMATION_MESSAGE); } + final int finalRestartCode = restartCode; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - System.exit(restartCode); + System.exit(finalRestartCode); } }); diff --git a/platform/lang-api/src/com/intellij/codeInspection/ui/SingleIntegerFieldOptionsPanel.java b/platform/lang-api/src/com/intellij/codeInspection/ui/SingleIntegerFieldOptionsPanel.java index 298930fbaa95..d83e96b78f7f 100644 --- a/platform/lang-api/src/com/intellij/codeInspection/ui/SingleIntegerFieldOptionsPanel.java +++ b/platform/lang-api/src/com/intellij/codeInspection/ui/SingleIntegerFieldOptionsPanel.java @@ -19,12 +19,15 @@ import com.intellij.codeInspection.InspectionProfileEntry; import com.intellij.ui.DocumentAdapter; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import javax.swing.JFormattedTextField; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.event.DocumentEvent; +import javax.swing.text.DefaultFormatterFactory; import javax.swing.text.Document; +import javax.swing.text.NumberFormatter; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.text.NumberFormat; @@ -63,28 +66,43 @@ public class SingleIntegerFieldOptionsPanel extends JPanel { add(valueField, constraints); } - public static JFormattedTextField createIntegerFieldTrackingValue(final InspectionProfileEntry owner, - final String property, + public static JFormattedTextField createIntegerFieldTrackingValue(@NotNull InspectionProfileEntry owner, + @NotNull String property, int integerFieldColumns) { - final NumberFormat formatter = NumberFormat.getIntegerInstance(); - formatter.setParseIntegerOnly(true); - final JFormattedTextField valueField = - new JFormattedTextField(formatter); - valueField.setValue(getPropertyValue(owner, property)); + JFormattedTextField valueField = new JFormattedTextField(); valueField.setColumns(integerFieldColumns); - final Document document = valueField.getDocument(); + setupIntegerFieldTrackingValue(valueField, owner, property); + return valueField; + } + + /** + * Sets integer number format to JFormattedTextField instance, + * sets value of JFormattedTextField instance to object's field value, + * synchronizes object's field value with the value of JFormattedTextField instance. + * + * @param textField JFormattedTextField instance + * @param owner an object whose field is synchronized with {@code textField} + * @param property object's field name for synchronization + */ + public static void setupIntegerFieldTrackingValue(final JFormattedTextField textField, + final InspectionProfileEntry owner, + final String property) { + NumberFormat formatter = NumberFormat.getIntegerInstance(); + formatter.setParseIntegerOnly(true); + textField.setFormatterFactory(new DefaultFormatterFactory(new NumberFormatter(formatter))); + textField.setValue(getPropertyValue(owner, property)); + final Document document = textField.getDocument(); document.addDocumentListener(new DocumentAdapter() { public void textChanged(DocumentEvent e) { try { - valueField.commitEdit(); + textField.commitEdit(); setPropertyValue(owner, property, - ((Number) valueField.getValue()).intValue()); + ((Number) textField.getValue()).intValue()); } catch (ParseException e1) { // No luck this time } } }); - return valueField; } private static void setPropertyValue(InspectionProfileEntry owner, @@ -104,4 +122,4 @@ public class SingleIntegerFieldOptionsPanel extends JPanel { return 0; } } -} \ No newline at end of file +} diff --git a/platform/lang-impl/src/com/intellij/execution/actions/StopAction.java b/platform/lang-impl/src/com/intellij/execution/actions/StopAction.java index 8ea7976017db..ddfa286e16e3 100644 --- a/platform/lang-impl/src/com/intellij/execution/actions/StopAction.java +++ b/platform/lang-impl/src/com/intellij/execution/actions/StopAction.java @@ -130,7 +130,7 @@ public class StopAction extends DumbAwareAction implements AnAction.TransparentU if (!processHandler.isProcessTerminating()) { enable = true; } - else if (processHandler instanceof KillableProcess && ((KillableProcess)processHandler).canKillSoftly()) { + else if (processHandler instanceof KillableProcess && ((KillableProcess)processHandler).canKillProcess()) { enable = true; icon = KILL_PROCESS_ICON; description = "Kill process"; diff --git a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/actions/FavoritesAutoScrollToSourceAction.java b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/actions/FavoritesAutoScrollToSourceAction.java index 53410de2b0d2..8fcf90a9704a 100644 --- a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/actions/FavoritesAutoScrollToSourceAction.java +++ b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/actions/FavoritesAutoScrollToSourceAction.java @@ -30,7 +30,7 @@ public class FavoritesAutoScrollToSourceAction extends FavoritesToolbarButtonAct public FavoritesAutoScrollToSourceAction(Project project, AutoScrollToSourceHandler autoScrollToSourceHandler, FavoritesViewTreeBuilder builder) { - super(project, builder, UIBundle.message("autoscroll.to.source.action.name"), IconLoader.getIcon("/general/autoScrollToSource.png")); + super(project, builder, UIBundle.message("autoscroll.to.source.action.name"), IconLoader.getIcon("/general/autoscrollToSource.png")); myAutoScrollToSourceHandler = autoScrollToSourceHandler; } diff --git a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/actions/SendToFavoritesAction.java b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/actions/SendToFavoritesAction.java index d949b4b769a8..5f9c1834e59a 100644 --- a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/actions/SendToFavoritesAction.java +++ b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/actions/SendToFavoritesAction.java @@ -75,7 +75,11 @@ public class SendToFavoritesAction extends AnAction{ public void doSend(final FavoritesManager favoritesManager, final FavoritesTreeNodeDescriptor[] roots, final String listName) { for (FavoritesTreeNodeDescriptor root : roots) { final AbstractTreeNode rootElement = root.getElement(); - favoritesManager.removeRoot(listName, rootElement.getValue()); + String name = listName; + if (name == null) { + name = root.getFavoritesRoot().getName(); + } + favoritesManager.removeRoot(name, rootElement.getValue()); favoritesManager.addRoots(toName, Collections.singletonList(rootElement)); } } diff --git a/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java b/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java index aa951b9d1b80..4b8099ec1c62 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java +++ b/platform/lang-impl/src/com/intellij/refactoring/introduce/inplace/AbstractInplaceIntroducer.java @@ -40,6 +40,7 @@ import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.TextRange; import com.intellij.psi.*; +import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.refactoring.RefactoringBundle; @@ -77,7 +78,7 @@ public abstract class AbstractInplaceIntroducer extends VariableInp } - private void showBalloon() { + protected void showBalloon() { final JComponent component = getComponent(); if (component == null) return; if (ApplicationManager.getApplication().isHeadlessEnvironment()) return; diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/MemberInplaceRenamer.java b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/MemberInplaceRenamer.java index 7acf9f07a0e9..bad2b38d93ff 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/MemberInplaceRenamer.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/MemberInplaceRenamer.java @@ -237,21 +237,6 @@ public class MemberInplaceRenamer extends VariableInplaceRenamer { }, RENAME_TITLE, null); } - @Override - protected void restoreStateBeforeDialogWouldBeShown() { - PsiNamedElement variable = getVariable(); - final TemplateState state = TemplateManagerImpl.getTemplateState(InjectedLanguageUtil.getTopLevelEditor(myEditor)); - assert state != null; - final String commandName = RefactoringBundle - .message("renaming.0.1.to.2", UsageViewUtil.getType(variable), UsageViewUtil.getDescriptiveName(variable), variable.getName()); - Runnable runnable = new Runnable() { - public void run() { - state.gotoEnd(true); - } - }; - CommandProcessor.getInstance().executeCommand(myProject, runnable, commandName, null); - } - @Override protected String getNewName(String newName, ResolveSnapshotProvider.ResolveSnapshot snapshot) { return newName; diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java index dfc63772e0b0..27a46867dd8a 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/inplace/VariableInplaceRenamer.java @@ -84,6 +84,7 @@ import com.intellij.refactoring.util.CommonRefactoringUtil; import com.intellij.refactoring.util.TextOccurrencesUtil; import com.intellij.ui.components.JBList; import com.intellij.usageView.UsageInfo; +import com.intellij.usageView.UsageViewUtil; import com.intellij.util.PairProcessor; import com.intellij.util.containers.MultiMap; import com.intellij.util.containers.Stack; @@ -169,10 +170,6 @@ public class VariableInplaceRenamer { } } - while (!ourRenamersStack.isEmpty()) { - ourRenamersStack.peek().finish(); - } - PsiElement scope = checkLocalScope(); if (scope == null) { @@ -422,7 +419,7 @@ public class VariableInplaceRenamer { return true; } - private void navigateToAlreadyStarted(Document oldDocument, int exitCode) { + protected void navigateToAlreadyStarted(Document oldDocument, int exitCode) { final PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(oldDocument); if (file != null) { final VirtualFile virtualFile = file.getVirtualFile(); @@ -458,6 +455,18 @@ public class VariableInplaceRenamer { } protected void restoreStateBeforeDialogWouldBeShown() { + PsiNamedElement variable = getVariable(); + final TemplateState state = TemplateManagerImpl.getTemplateState(InjectedLanguageUtil.getTopLevelEditor(myEditor)); + assert state != null; + final String commandName = RefactoringBundle + .message("renaming.0.1.to.2", UsageViewUtil.getType(variable), UsageViewUtil.getDescriptiveName(variable), + variable.getName()); + Runnable runnable = new Runnable() { + public void run() { + state.gotoEnd(true); + } + }; + CommandProcessor.getInstance().executeCommand(myProject, runnable, commandName, null); } @Nullable diff --git a/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ComboBoxAction.java b/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ComboBoxAction.java index 2f0fc8c0b051..a8843a37dfdf 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ComboBoxAction.java +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/ex/ComboBoxAction.java @@ -299,7 +299,11 @@ public abstract class ComboBoxAction extends AnAction implements CustomComponent g2.setColor(UIUtil.getControlColor()); final int w = getWidth(); final int h = getHeight(); - g2.setPaint(new GradientPaint(0,0, new Gray(250, 180), 0, h, new Gray(220, 180))); + if (getModel().isArmed() && getModel().isPressed()) { + g2.setPaint(new GradientPaint(0,0, new Gray(220, 180), 0, h, new Gray(180, 180))); + } else { + g2.setPaint(new GradientPaint(0,0, new Gray(250, 180), 0, h, new Gray(220, 180))); + } g2.fillRect(2, 0, w-2, h); if (!myMouseInside) { g2.setPaint(new GradientPaint(0,0, Gray._180, 0, h, Gray._150)); diff --git a/platform/platform-api/src/com/intellij/ui/ScreenUtil.java b/platform/platform-api/src/com/intellij/ui/ScreenUtil.java index ccc45ec01f37..2ded3ab17f65 100644 --- a/platform/platform-api/src/com/intellij/ui/ScreenUtil.java +++ b/platform/platform-api/src/com/intellij/ui/ScreenUtil.java @@ -31,8 +31,7 @@ public class ScreenUtil { @Nullable private static final Map> ourInsetsCache; static { final boolean useCache = (SystemInfo.isLinux || SystemInfo.isSolaris) - && !GraphicsEnvironment.isHeadless() - && SystemInfo.JAVA_RUNTIME_VERSION.startsWith("1.7"); + && !GraphicsEnvironment.isHeadless(); ourInsetsCache = useCache ? new WeakHashMap>() : null; } diff --git a/platform/platform-impl/src/com/intellij/execution/KillableProcess.java b/platform/platform-impl/src/com/intellij/execution/KillableProcess.java index 7710bf277cb1..041e61fb955e 100644 --- a/platform/platform-impl/src/com/intellij/execution/KillableProcess.java +++ b/platform/platform-impl/src/com/intellij/execution/KillableProcess.java @@ -19,7 +19,7 @@ package com.intellij.execution; * @author nik */ public interface KillableProcess { - boolean canKillSoftly(); + boolean canKillProcess(); void killProcess(); } diff --git a/platform/platform-impl/src/com/intellij/execution/process/KillableColoredProcessHandler.java b/platform/platform-impl/src/com/intellij/execution/process/KillableColoredProcessHandler.java index bcd005c6d6cd..1bebb4a56c9d 100644 --- a/platform/platform-impl/src/com/intellij/execution/process/KillableColoredProcessHandler.java +++ b/platform/platform-impl/src/com/intellij/execution/process/KillableColoredProcessHandler.java @@ -39,14 +39,14 @@ public class KillableColoredProcessHandler extends ColoredProcessHandler impleme } @Override - public boolean canKillSoftly() { + public boolean canKillProcess() { // soft-kill works on Unix systems return SystemInfo.isUnix; } @Override protected void doDestroyProcess() { - if (!canKillSoftly()) { + if (!canKillProcess()) { // if soft kill isn't supported - use default implementation super.doDestroyProcess(); return; diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/encapsulation/ReturnOfDateFieldInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/encapsulation/ReturnOfDateFieldInspection.java index d0835ae28908..601b285a53b0 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/encapsulation/ReturnOfDateFieldInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/encapsulation/ReturnOfDateFieldInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2010 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2011 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +15,14 @@ */ package com.siyeh.ig.encapsulation; +import com.intellij.codeInspection.ProblemDescriptor; +import com.intellij.openapi.project.Project; import com.intellij.psi.*; +import com.intellij.util.IncorrectOperationException; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; +import com.siyeh.ig.InspectionGadgetsFix; import com.siyeh.ig.psiutils.TypeUtils; import org.jetbrains.annotations.NotNull; @@ -27,16 +31,49 @@ public class ReturnOfDateFieldInspection extends BaseInspection { @Override @NotNull public String getDisplayName() { - return InspectionGadgetsBundle.message( - "return.date.calendar.field.display.name"); + return InspectionGadgetsBundle.message("return.date.calendar.field.display.name"); } @Override @NotNull public String buildErrorString(Object... infos) { final String type = (String)infos[0]; - return InspectionGadgetsBundle.message( - "return.date.calendar.field.problem.descriptor", type); + return InspectionGadgetsBundle.message("return.date.calendar.field.problem.descriptor", type); + } + + @Override + protected InspectionGadgetsFix buildFix(Object... infos) { + return new ReturnOfDateFieldFix((String)infos[0]); + } + + private static class ReturnOfDateFieldFix extends InspectionGadgetsFix { + + private final String myType; + + public ReturnOfDateFieldFix(String type) { + myType = type; + } + + @NotNull + @Override + public String getName() { + return "Return clone of '" + myType + '\''; + } + + @Override + protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException { + final PsiElement element = descriptor.getPsiElement(); + if (!(element instanceof PsiReferenceExpression)) { + return; + } + final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)element; + final String type = + TypeUtils.expressionHasTypeOrSubtype(referenceExpression, CommonClassNames.JAVA_UTIL_DATE, CommonClassNames.JAVA_UTIL_CALENDAR); + if (type == null) { + return; + } + replaceExpression(referenceExpression, '(' + type + ')' + referenceExpression.getText() + ".clone()"); + } } @Override @@ -44,26 +81,22 @@ public class ReturnOfDateFieldInspection extends BaseInspection { return new ReturnOfDateFieldVisitor(); } - private static class ReturnOfDateFieldVisitor - extends BaseInspectionVisitor { + private static class ReturnOfDateFieldVisitor extends BaseInspectionVisitor { @Override - public void visitReturnStatement( - @NotNull PsiReturnStatement statement) { + public void visitReturnStatement(@NotNull PsiReturnStatement statement) { super.visitReturnStatement(statement); final PsiExpression returnValue = statement.getReturnValue(); if (!(returnValue instanceof PsiReferenceExpression)) { return; } - final PsiReferenceExpression fieldReference = - (PsiReferenceExpression)returnValue; + final PsiReferenceExpression fieldReference = (PsiReferenceExpression)returnValue; final PsiElement element = fieldReference.resolve(); if (!(element instanceof PsiField)) { return; } final String type = TypeUtils.expressionHasTypeOrSubtype( - returnValue, CommonClassNames.JAVA_UTIL_DATE, - CommonClassNames.JAVA_UTIL_CALENDAR); + returnValue, CommonClassNames.JAVA_UTIL_DATE, CommonClassNames.JAVA_UTIL_CALENDAR); if (type == null) { return; } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/debugger/GroovyCodeFragmentFactory.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/debugger/GroovyCodeFragmentFactory.java index acb5fddf1d03..93958df592ed 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/debugger/GroovyCodeFragmentFactory.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/debugger/GroovyCodeFragmentFactory.java @@ -50,6 +50,7 @@ import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.ClosureSyntheticPara import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil; import java.util.*; +import java.util.regex.Pattern; /** * @author ven @@ -93,9 +94,29 @@ public class GroovyCodeFragmentFactory implements CodeFragmentFactory { javaText.append("groovy.lang.MetaClass |mc;\n"); javaText.append("java.lang.Class |clazz;\n"); + if (!isStatic) { - javaText.append("|clazz = this.getClass();\n"); - javaText.append("|mc = this.getMetaClass();\n"); + javaText.append("java.lang.Object |thiz0;\n"); + + PsiElement originalContext = context.getContainingFile().getContext(); + String fileName = originalContext == null ? null : originalContext.getContainingFile().getOriginalFile().getName(); + + if (fileName == null) { + javaText.append("|thiz0 = this;\n"); + } + else { + String s = StringUtil.escapeStringCharacters(Pattern.quote(fileName)); + javaText.append("if (java.util.Arrays.toString(new Exception().getStackTrace()).matches(\"[^,]+\\\\$\\\\$[A-Za-z0-9]{8}\\\\.[^,]+\\\\(" + s + ":\\\\d+\\\\), .+com\\\\.springsource\\\\.loaded\\\\..+\")) {\n"); + javaText.append(" |thiz0 = thiz;\n"); + javaText.append(" } else {\n"); + javaText.append(" |thiz0 = this.getClass();\n"); + javaText.append(" }\n"); + } + } + + if (!isStatic) { + javaText.append("|clazz = |thiz0.getClass();\n"); + javaText.append("|mc = |thiz0.getMetaClass();\n"); } else { assert contextClass != null; javaText.append("|clazz = java.lang.Class.forName(\"").append(contextClass.getQualifiedName()).append("\");\n"); @@ -118,7 +139,7 @@ public class GroovyCodeFragmentFactory implements CodeFragmentFactory { javaText.append("groovy.lang.ExpandoMetaClass |emc = new groovy.lang.ExpandoMetaClass(|clazz);\n"); if (!isStatic) { javaText.append("|emc.setProperty(\"").append(EVAL_NAME).append("\", |closure);\n"); - javaText.append("this.setMetaClass(|emc);\n"); + javaText.append("|thiz0.setMetaClass(|emc);\n"); } else { javaText.append("|emc.getProperty(\"static\").setProperty(\"").append(EVAL_NAME).append("\", |closure);\n"); javaText.append("groovy.lang.GroovySystem.getMetaClassRegistry().setMetaClass(|clazz, |emc);\n"); @@ -126,8 +147,8 @@ public class GroovyCodeFragmentFactory implements CodeFragmentFactory { javaText.append("|emc.initialize();\n"); javaText.append(unwrapVals(values)); if (!isStatic) { - javaText.append("java.lang.Object |res = ((groovy.lang.MetaClassImpl)|emc).invokeMethod(this, \"").append(EVAL_NAME).append("\", |resVals);\n"); - javaText.append("this.setMetaClass(|mc);"); //try/finally is not supported + javaText.append("java.lang.Object |res = ((groovy.lang.MetaClassImpl)|emc).invokeMethod(|thiz0, \"").append(EVAL_NAME).append("\", |resVals);\n"); + javaText.append("|thiz0.setMetaClass(|mc);"); //try/finally is not supported } else { javaText.append("java.lang.Object |res = ((groovy.lang.MetaClassImpl)|emc).invokeStaticMethod(|clazz, \"").append(EVAL_NAME).append("\", |resVals);\n"); javaText.append("groovy.lang.GroovySystem.getMetaClassRegistry().setMetaClass(|clazz, |mc);\n");