mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote branch 'origin/master'
This commit is contained in:
+1
-1
@@ -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);
|
||||
|
||||
+8
-1
@@ -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<DetectedFrameworkDescription> result = new ArrayList<DetectedFrameworkDescription>();
|
||||
final FacetType<F,C> facetType = detector.getFacetType();
|
||||
for (ModuleDescriptor module : filesByModule.keySet()) {
|
||||
final List<Pair<C,Collection<VirtualFile>>> pairs = detector.createConfigurations(filesByModule.get(module), Collections.<C>emptyList());
|
||||
if (!facetType.isSuitableModuleType(module.getModuleType())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final List<Pair<C, Collection<VirtualFile>>> pairs =
|
||||
detector.createConfigurations(filesByModule.get(module), Collections.<C>emptyList());
|
||||
for (Pair<C, Collection<VirtualFile>> pair : pairs) {
|
||||
result.add(new FacetBasedDetectedFrameworkDescriptionInWizard<F, C>(module, detector, pair.getFirst(),
|
||||
new HashSet<VirtualFile>(pair.getSecond())));
|
||||
|
||||
+1
-1
@@ -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;
|
||||
}
|
||||
|
||||
+1
-1
@@ -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;
|
||||
}
|
||||
|
||||
+1
-1
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
+30
-12
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
|
||||
+1
-1
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
+5
-4
@@ -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<V extends PsiNameIdentifierOwner
|
||||
|
||||
private DocumentAdapter myDocumentAdapter;
|
||||
protected final JPanel myWholePanel;
|
||||
//private boolean myFinished = false;
|
||||
private boolean myFinished = false;
|
||||
|
||||
public AbstractInplaceIntroducer(Project project,
|
||||
Editor editor,
|
||||
@@ -325,7 +326,7 @@ public abstract class AbstractInplaceIntroducer<V extends PsiNameIdentifierOwner
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
// myFinished = true;
|
||||
myFinished = true;
|
||||
final TemplateState templateState = TemplateManagerImpl.getTemplateState(myEditor);
|
||||
if (templateState != null) {
|
||||
myEditor.putUserData(ACTIVE_INTRODUCE, null);
|
||||
@@ -552,7 +553,7 @@ public abstract class AbstractInplaceIntroducer<V extends PsiNameIdentifierOwner
|
||||
}
|
||||
}
|
||||
|
||||
/*@Override
|
||||
@Override
|
||||
protected void restoreStateBeforeDialogWouldBeShown() {
|
||||
stopIntroduce(InjectedLanguageUtil.getTopLevelEditor(myEditor));
|
||||
}
|
||||
@@ -582,7 +583,7 @@ public abstract class AbstractInplaceIntroducer<V extends PsiNameIdentifierOwner
|
||||
}
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
public static void unableToStartWarning(Project project, Editor editor, AbstractInplaceIntroducer introducer) {
|
||||
String message = RefactoringBundle
|
||||
.getCannotRefactorMessage(introducer.getCommandName() + " is not finished yet. Unable to start a refactoring");
|
||||
|
||||
+1
-1
@@ -141,7 +141,7 @@ public class InplaceVariableIntroducer<E extends PsiElement> extends VariableInp
|
||||
|
||||
}
|
||||
|
||||
private void showBalloon() {
|
||||
protected void showBalloon() {
|
||||
final JComponent component = getComponent();
|
||||
if (component == null) return;
|
||||
if (ApplicationManager.getApplication().isHeadlessEnvironment()) return;
|
||||
|
||||
-15
@@ -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;
|
||||
|
||||
+14
-5
@@ -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
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -31,8 +31,7 @@ public class ScreenUtil {
|
||||
@Nullable private static final Map<GraphicsConfiguration, Pair<Insets, Long>> ourInsetsCache;
|
||||
static {
|
||||
final boolean useCache = (SystemInfo.isLinux || SystemInfo.isSolaris)
|
||||
&& !GraphicsEnvironment.isHeadless()
|
||||
&& SystemInfo.JAVA_RUNTIME_VERSION.startsWith("1.7");
|
||||
&& !GraphicsEnvironment.isHeadless();
|
||||
ourInsetsCache = useCache ? new WeakHashMap<GraphicsConfiguration, Pair<Insets, Long>>() : null;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ package com.intellij.execution;
|
||||
* @author nik
|
||||
*/
|
||||
public interface KillableProcess {
|
||||
boolean canKillSoftly();
|
||||
boolean canKillProcess();
|
||||
|
||||
void killProcess();
|
||||
}
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
+46
-13
@@ -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;
|
||||
}
|
||||
|
||||
+26
-5
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user