diff --git a/build/conf/nsis/idea.nsi b/build/conf/nsis/idea.nsi index 421e83fafdde..2b5bd492af2f 100644 --- a/build/conf/nsis/idea.nsi +++ b/build/conf/nsis/idea.nsi @@ -467,17 +467,6 @@ FunctionEnd Function uninstallOldVersion - ;check if the uninstalled application is running -remove_previous_installation: - ;prepare a copy of launcher - CopyFiles "$3\bin\${PRODUCT_EXE_FILE}" "$3\bin\${PRODUCT_EXE_FILE}_copy" - ClearErrors - ;copy launcher to itself - CopyFiles "$3\bin\${PRODUCT_EXE_FILE}_copy" "$3\bin\${PRODUCT_EXE_FILE}" - Delete "$3\bin\${PRODUCT_EXE_FILE}_copy" - IfErrors 0 +3 - MessageBox MB_OKCANCEL|MB_ICONQUESTION|MB_TOPMOST "$(application_running)" IDOK remove_previous_installation IDCANCEL complete - goto complete ; uninstallation mode !insertmacro INSTALLOPTIONS_READ $9 "UninstallOldVersions.ini" "Field 2" "State" ${If} $9 == "1" @@ -1035,8 +1024,38 @@ complete: ${UnStrRep} $2 $2 "/" "\" FunctionEnd +Function un.isIDEInUse + IfFileExists $R0 0 done + CopyFiles $R0 "$R0_copy" + ClearErrors + Delete $R0" + IfFileExists $R0 done + CopyFiles "$R0_copy" $R0 +done: + Delete "$R0_copy" +FunctionEnd + + +Function un.checkIfIDEInUse +remove_previous_installation: + StrCpy $R0 "$INSTDIR\IdeaWin32.dll" + Call un.isIDEInUse + IfErrors remove_dialog 0 + StrCpy $R0 "$INSTDIR\IdeaWin64.dll" + Call un.isIDEInUse + IfErrors remove_dialog done +remove_dialog: + MessageBox MB_OKCANCEL|MB_ICONQUESTION|MB_TOPMOST "$(application_running)" IDOK remove_previous_installation IDCANCEL cancel +cancel: + StrCpy $R0 "cancel" +done: +FunctionEnd + Section "Uninstall" + ;check if the uninstalled application is running + Call un.checkIfIDEInUse + StrCmp $R0 "cancel" end_of_uninstall 0 ; Uninstaller is in the \bin directory, we need upper level dir StrCpy $productDir $INSTDIR StrCpy $INSTDIR $INSTDIR\.. diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessEvents.java b/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessEvents.java index 185898e6fbec..6da59a74e04d 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessEvents.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessEvents.java @@ -186,7 +186,7 @@ public class DebugProcessEvents extends DebugProcessImpl { // check if there is already one request with policy SUSPEND_ALL for (SuspendContextImpl context : getSuspendManager().getEventContexts()) { if (context.getSuspendPolicy() == EventRequest.SUSPEND_ALL) { - if (isResumeOnlyCurrentThread() && locatableEvent != null) { + if (isResumeOnlyCurrentThread() && locatableEvent != null && !context.isEvaluating()) { // if step event is present - switch context getSuspendManager().resume(context); //((SuspendManagerImpl)getSuspendManager()).popContext(context); diff --git a/java/java-impl/src/com/intellij/codeInspection/sameParameterValue/SameParameterValueInspection.java b/java/java-impl/src/com/intellij/codeInspection/sameParameterValue/SameParameterValueInspection.java index bcfea46a569c..d9bd3099459b 100644 --- a/java/java-impl/src/com/intellij/codeInspection/sameParameterValue/SameParameterValueInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/sameParameterValue/SameParameterValueInspection.java @@ -69,7 +69,7 @@ public class SameParameterValueInspection extends SameParameterValueInspectionBa @Override @NotNull public String getFamilyName() { - return getName(); + return InspectionsBundle.message("inspection.same.parameter.fix.family.name"); } @Override diff --git a/java/java-impl/src/com/intellij/psi/filters/types/AssignableFromFilter.java b/java/java-impl/src/com/intellij/psi/filters/types/AssignableFromFilter.java index e791c926fd58..23309bd687c0 100644 --- a/java/java-impl/src/com/intellij/psi/filters/types/AssignableFromFilter.java +++ b/java/java-impl/src/com/intellij/psi/filters/types/AssignableFromFilter.java @@ -119,7 +119,8 @@ public class AssignableFromFilter implements ElementFilter{ expectedType, false, PsiUtil.getLanguageLevel(place)); - if (substitutionForParameter != PsiType.NULL && !(substitutionForParameter instanceof PsiIntersectionType)) { + if (substitutionForParameter != PsiType.NULL && !(substitutionForParameter instanceof PsiIntersectionType) && + PsiUtil.resolveClassInClassTypeOnly(substitutionForParameter) != parameter) { return true; } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/PsiGraphInferenceHelper.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/PsiGraphInferenceHelper.java index 4dbbcbc64b4d..0d27f4719162 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/PsiGraphInferenceHelper.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/PsiGraphInferenceHelper.java @@ -117,7 +117,9 @@ public class PsiGraphInferenceHelper implements PsiInferenceHelper { leftTypes = new PsiType[] {arg}; rightTypes = new PsiType[]{param}; } - final InferenceSession inferenceSession = new InferenceSession(new PsiTypeParameter[]{typeParam}, leftTypes, rightTypes, PsiSubstitutor.EMPTY, myManager, null); + final PsiTypeParameterListOwner owner = typeParam.getOwner(); + final PsiTypeParameter[] typeParams = owner != null ? owner.getTypeParameters() : new PsiTypeParameter[] {typeParam}; + final InferenceSession inferenceSession = new InferenceSession(typeParams, leftTypes, rightTypes, PsiSubstitutor.EMPTY, myManager, null); if (inferenceSession.isProperType(inferenceSession.substituteWithInferenceVariables(param)) && inferenceSession.isProperType(inferenceSession.substituteWithInferenceVariables(arg))) { boolean proceed = false; diff --git a/java/java-tests/testData/codeInsight/completion/smartType/OnlyCompatibleTypes.java b/java/java-tests/testData/codeInsight/completion/smartType/OnlyCompatibleTypes.java new file mode 100644 index 000000000000..e10ac9709676 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/smartType/OnlyCompatibleTypes.java @@ -0,0 +1,13 @@ +class A { + { + Func2 f = gex + } + + Func1 get1() {} + Func2 get2() {} + +} + + +interface Func1 {} +interface Func2 {} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartType18CompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartType18CompletionTest.java index 372dadf4c287..8db77fabc563 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartType18CompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartType18CompletionTest.java @@ -175,4 +175,9 @@ public void testConvertToObjectStream() { } checkResultByFile("/" + getTestName(false) + "-out.java"); } + + public void testOnlyCompatibleTypes() { + configureByTestName(); + assertOrderedEquals(myFixture.getLookupElementStrings(), "get2"); + } } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java index 5a4d3b4a41a2..4daca42f2236 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java @@ -1232,4 +1232,9 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase { private CommonCodeStyleSettings getCodeStyleSettings() { return CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE); } + + public void testOnlyCompatibleTypes() { + configureByTestName(); + assertOrderedEquals(myFixture.getLookupElementStrings(), "get2"); + } } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java index 05fee7392616..0ecc43093349 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java @@ -71,7 +71,6 @@ import javax.swing.*; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.MutableTreeNode; import javax.swing.tree.TreePath; import java.awt.*; import java.awt.event.InputEvent; @@ -399,16 +398,16 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren TreePath pathSelected = myTree.getSelectionModel().getLeadSelectionPath(); if (pathSelected != null) { final InspectionTreeNode node = (InspectionTreeNode)pathSelected.getLastPathComponent(); - if (node instanceof RefElementNode) { - final RefElementNode refElementNode = (RefElementNode)node; - final RefEntity refSelected = refElementNode.getElement(); - showInRightPanel(refSelected); - } - else if (node instanceof ProblemDescriptionNode) { + if (node instanceof ProblemDescriptionNode) { final ProblemDescriptionNode problemNode = (ProblemDescriptionNode)node; showInRightPanel(problemNode.getElement()); } - else if (node instanceof InspectionNode || node instanceof InspectionPackageNode || node instanceof InspectionModuleNode) { + else if (node instanceof InspectionPackageNode || + node instanceof InspectionModuleNode || + node instanceof RefElementNode) { + showInRightPanel(node.getContainingFileLocalEntity()); + } + else if (node instanceof InspectionNode) { showInRightPanel(null); } else if (node instanceof InspectionRootNode || node instanceof InspectionGroupNode || node instanceof InspectionSeverityGroupNode) { @@ -499,7 +498,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren myPreviewEditor.getCaretModel().moveToOffset(finalSelectedElement.getTextOffset()); myPreviewEditor.getScrollingModel().scrollToCaret(ScrollType.CENTER); } - }, ModalityState.NON_MODAL); + }, ModalityState.any()); } return myPreviewEditor.getComponent(); } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeNode.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeNode.java index 3e3532631f45..574902b3c16e 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeNode.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeNode.java @@ -16,6 +16,7 @@ package com.intellij.codeInspection.ui; +import com.intellij.codeInspection.reference.RefEntity; import com.intellij.openapi.vcs.FileStatus; import org.jetbrains.annotations.Nullable; @@ -109,4 +110,17 @@ public abstract class InspectionTreeNode extends DefaultMutableTreeNode { } } + public RefEntity getContainingFileLocalEntity() { + final Enumeration children = children(); + RefEntity current = null; + while (children.hasMoreElements()) { + InspectionTreeNode child = (InspectionTreeNode)children.nextElement(); + final RefEntity entity = child.getContainingFileLocalEntity(); + if (entity == null || current != null) { + return null; + } + current = entity; + } + return current; + } } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/RefElementNode.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/RefElementNode.java index 1e8c5d44126e..809705237f49 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/RefElementNode.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/RefElementNode.java @@ -18,6 +18,7 @@ package com.intellij.codeInspection.ui; import com.intellij.codeInspection.CommonProblemDescriptor; import com.intellij.codeInspection.InspectionsBundle; +import com.intellij.codeInspection.reference.RefDirectory; import com.intellij.codeInspection.reference.RefElement; import com.intellij.codeInspection.reference.RefEntity; import com.intellij.openapi.util.Computable; @@ -124,4 +125,11 @@ public class RefElementNode extends InspectionTreeNode { return mySingleDescriptor; } + @Override + public RefEntity getContainingFileLocalEntity() { + final RefEntity element = getElement(); + return element instanceof RefElement && !(element instanceof RefDirectory) + ? element + : super.getContainingFileLocalEntity(); + } } diff --git a/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java b/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java index 7471a1657789..c7fb3d8659f6 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java +++ b/platform/lang-impl/src/com/intellij/refactoring/BaseRefactoringProcessor.java @@ -543,7 +543,7 @@ public abstract class BaseRefactoringProcessor implements Runnable { return; } if (ApplicationManager.getApplication().isWriteAccessAllowed()) { - LOG.info(new Exception()); + LOG.error(new Exception()); DumbService.getInstance(myProject).smartInvokeLater(new Runnable() { @Override public void run() { diff --git a/platform/platform-impl/src/com/intellij/platform/DirectoryProjectGenerator.java b/platform/platform-impl/src/com/intellij/platform/DirectoryProjectGenerator.java index f26b0375428c..b21e9d1580cb 100644 --- a/platform/platform-impl/src/com/intellij/platform/DirectoryProjectGenerator.java +++ b/platform/platform-impl/src/com/intellij/platform/DirectoryProjectGenerator.java @@ -37,9 +37,6 @@ public interface DirectoryProjectGenerator { @Nls String getName(); - @Nullable - T showGenerationSettings(final VirtualFile baseDir) throws ProcessCanceledException; - /** * @return 16x16 icon or null, if no icon is available */ diff --git a/platform/platform-impl/src/com/intellij/platform/WebProjectGenerator.java b/platform/platform-impl/src/com/intellij/platform/WebProjectGenerator.java index 94f09af302cb..0a555fad5a53 100644 --- a/platform/platform-impl/src/com/intellij/platform/WebProjectGenerator.java +++ b/platform/platform-impl/src/com/intellij/platform/WebProjectGenerator.java @@ -57,18 +57,6 @@ public abstract class WebProjectGenerator implements DirectoryProjectGenerato return null; } - @Override - @NotNull - public final T showGenerationSettings(VirtualFile baseDir) throws ProcessCanceledException { - GeneratorPeer peer = createPeer(); - DialogWrapper dialog = new MyDialogWrapper(peer); - dialog.show(); - if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) { - throw new ProcessCanceledException(); - } - return peer.getSettings(); - } - @Override public abstract void generateProject(@NotNull Project project, @NotNull VirtualFile baseDir, @NotNull T settings, @NotNull Module module); diff --git a/platform/platform-resources-en/src/messages/InspectionsBundle.properties b/platform/platform-resources-en/src/messages/InspectionsBundle.properties index 6b2d9c573a00..69cd502c5e81 100644 --- a/platform/platform-resources-en/src/messages/InspectionsBundle.properties +++ b/platform/platform-resources-en/src/messages/InspectionsBundle.properties @@ -672,6 +672,7 @@ unused.library.roots.problem.descriptor=Unused roots {0} from library ''{1}'' unused.library.backward.analysis.job.description=Perform backward analysis inspection.duplicates.option.report.propertykey.expressions=&Ignore @PropertyKey expressions inspection.same.parameter.fix.name=Inline value ''{1}'' for parameter ''{0}'' +inspection.same.parameter.fix.family.name=Inline parameter as constant value fix.all.inspection.problems.in.file=Fix all ''{0}'' problems in file cleanup.in.file=Cleanup code cleanup.in.scope=Cleanup code on... diff --git a/platform/script-debugger/debugger-ui/src/SuspendContextBase.kt b/platform/script-debugger/debugger-ui/src/SuspendContextBase.kt index b063933f007f..6f1834382413 100644 --- a/platform/script-debugger/debugger-ui/src/SuspendContextBase.kt +++ b/platform/script-debugger/debugger-ui/src/SuspendContextBase.kt @@ -63,7 +63,7 @@ open class ExecutionStackView(val suspendContext: SuspendContext<*>, private val viewSupport: DebuggerViewSupport, private val topFrameScript: Script?, private val topFrameSourceInfo: SourceInfo? = null, - displayName: String = MAIN_LOOP_NAME) : XExecutionStack(displayName, AllIcons.Debugger.ThreadAtBreakpoint) { + displayName: String = "") : XExecutionStack(displayName, AllIcons.Debugger.ThreadAtBreakpoint) { private var topCallFrameView: CallFrameView? = null override fun getTopFrame(): CallFrameView? { diff --git a/platform/util/src/com/intellij/util/ui/ColorIcon.java b/platform/util/src/com/intellij/util/ui/ColorIcon.java index dbce4d0b7798..323a0a1433fb 100644 --- a/platform/util/src/com/intellij/util/ui/ColorIcon.java +++ b/platform/util/src/com/intellij/util/ui/ColorIcon.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -18,6 +18,7 @@ package com.intellij.util.ui; import com.intellij.ui.Gray; import org.jetbrains.annotations.NotNull; +import javax.swing.*; import java.awt.*; /** @@ -27,7 +28,7 @@ public class ColorIcon extends EmptyIcon { private final Color myColor; private boolean myBorder; private int myColorSize; - + private ColorIcon myScaledCache; public ColorIcon(int size, int colorSize, @NotNull Color color, final boolean border) { super(size, size); @@ -53,18 +54,36 @@ public class ColorIcon extends EmptyIcon { final int iconWidth = getIconWidth(); final int iconHeight = getIconHeight(); g.setColor(getIconColor()); + + final int size = getColorSize(); + final int x = i + (iconWidth - size) / 2; + final int y = j + (iconHeight - size) / 2; - final int x = i + (iconWidth - myColorSize) / 2; - final int y = j + (iconHeight - myColorSize) / 2; - - g.fillRect(x, y, myColorSize, myColorSize); + g.fillRect(x, y, size, size); if (myBorder) { g.setColor(Gray.x00.withAlpha(40)); - g.drawRect(x, y, myColorSize, myColorSize); + g.drawRect(x, y, size, size); } } + protected int getColorSize() { + return scale == 1f ? myColorSize : (int)(myColorSize * scale); + } + + @Override + public Icon scale(float scaleFactor) { + if (scale == scaleFactor) { + return this; + } + if (myScaledCache != null && myScaledCache.scale == scaleFactor) { + return myScaledCache; + } + myScaledCache = new ColorIcon(getIconWidth(), myColorSize, myColor, myBorder); + myScaledCache.scale = scaleFactor; + return myScaledCache; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/platform/util/src/com/intellij/util/ui/EmptyIcon.java b/platform/util/src/com/intellij/util/ui/EmptyIcon.java index 8ff79ab1015c..2d08af300fdf 100644 --- a/platform/util/src/com/intellij/util/ui/EmptyIcon.java +++ b/platform/util/src/com/intellij/util/ui/EmptyIcon.java @@ -41,7 +41,7 @@ public class EmptyIcon implements Icon, ScalableIcon { private final int width; private final int height; - private float scale = 1f; + protected float scale = 1f; public static Icon create(int size) { Icon icon = cache.get(size); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/OptionalGetWithoutIsPresentInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/OptionalGetWithoutIsPresentInspection.java index 5be18f7f4096..6c3822dc1b7d 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/OptionalGetWithoutIsPresentInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/OptionalGetWithoutIsPresentInspection.java @@ -88,13 +88,20 @@ public class OptionalGetWithoutIsPresentInspection extends BaseInspection { final PsiIfStatement ifStatement = (PsiIfStatement)sibling; final PsiExpression condition = ifStatement.getCondition(); if (condition != null) { - if (!ControlFlowUtils.statementMayCompleteNormally(ifStatement.getThenBranch())) { + final PsiElement target = optionalReference.resolve(); + if (!(target instanceof PsiVariable)) { + return true; + } + final PsiVariable variable = (PsiVariable)target; + final PsiStatement thenBranch = ifStatement.getThenBranch(); + if (!ControlFlowUtils.statementMayCompleteNormally(thenBranch) || VariableAccessUtils.variableIsAssigned(variable, thenBranch)) { checker.negate = true; if (checker.checkExpression(condition)) { return true; } } - else if (!ControlFlowUtils.statementMayCompleteNormally(ifStatement.getElseBranch())) { + final PsiStatement elseBranch = ifStatement.getElseBranch(); + if (!ControlFlowUtils.statementMayCompleteNormally(elseBranch) || VariableAccessUtils.variableIsAssigned(variable, elseBranch)) { checker.negate = false; if (checker.checkExpression(condition)) { return true; diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/optional_get_without_is_present/OptionalGetWithoutIsPresent.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/optional_get_without_is_present/OptionalGetWithoutIsPresent.java index 641210bd6a56..0c1e79aac2b9 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/optional_get_without_is_present/OptionalGetWithoutIsPresent.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/optional_get_without_is_present/OptionalGetWithoutIsPresent.java @@ -50,4 +50,14 @@ class OptionalWithoutIsPresent { org.testng.Assert.assertTrue(o3.isPresent()); System.out.println(o3.get()); } + + public static String demo() { + Optional holder = Optional.empty(); + + if (! holder.isPresent()) { + holder = Optional.of("hello world"); + } + + return holder.get(); + } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/OptionalGetWithoutIsPresentInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/OptionalGetWithoutIsPresentInspectionTest.java index 49592dc51e33..81156b9ba0f7 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/OptionalGetWithoutIsPresentInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/OptionalGetWithoutIsPresentInspectionTest.java @@ -79,6 +79,9 @@ public class OptionalGetWithoutIsPresentInspectionTest extends LightInspectionTe " public static Optional empty() {" + " return new Optional<>();" + " }" + + " public static Optional of(T value) {" + + " return new Optional<>(value);" + + " }" + "}", "package java.util;" + diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/field/GrInplaceFieldIntroducer.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/field/GrInplaceFieldIntroducer.java index 3f463677f5d3..d6057ad9bd5c 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/field/GrInplaceFieldIntroducer.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/field/GrInplaceFieldIntroducer.java @@ -259,17 +259,17 @@ public class GrInplaceFieldIntroducer extends GrAbstractInplaceIntroducer result = EnumSet.noneOf(GrIntroduceFieldSettings.Init.class); - if (context.getExpression() != null || - context.getVar() != null && context.getVar().getInitializerGroovy() != null || - context.getStringPart() != null) { - result.add(GrIntroduceFieldSettings.Init.FIELD_DECLARATION); - } - if (!(context.getScope() instanceof GroovyScriptClass || context.getScope() instanceof GroovyFileBase)) { + if (context.getExpression() != null || + context.getVar() != null && context.getVar().getInitializerGroovy() != null || + context.getStringPart() != null) { + result.add(GrIntroduceFieldSettings.Init.FIELD_DECLARATION); + } result.add(GrIntroduceFieldSettings.Init.CONSTRUCTOR); } PsiElement scope = context.getScope(); + if (scope instanceof GroovyScriptClass) scope = scope.getContainingFile(); if (replaceAllOccurrences || context.getExpression() != null) { PsiElement[] occurrences = replaceAllOccurrences ? context.getOccurrences() : new PsiElement[]{context.getExpression()}; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/field/GrIntroduceFieldProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/field/GrIntroduceFieldProcessor.java index 35d3fab209f0..2dc0dd2746a5 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/field/GrIntroduceFieldProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/introduce/field/GrIntroduceFieldProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -366,7 +366,7 @@ public class GrIntroduceFieldProcessor { private static GrReferenceExpression createRefExpression(@NotNull GrVariable field, @NotNull PsiElement place, @NotNull PsiClass containingClass) { - final String qname = containingClass.getQualifiedName(); + final String qname = containingClass instanceof GroovyScriptClass ? null : containingClass.getQualifiedName(); final String prefix = qname != null ? qname + "." : ""; final String refText; if (field.hasModifierProperty(PsiModifier.STATIC)) { diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduce/field/GrIntroduceFieldTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduce/field/GrIntroduceFieldTest.groovy index 3d6bbb3bd25c..66f347466df3 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduce/field/GrIntroduceFieldTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/introduce/field/GrIntroduceFieldTest.groovy @@ -544,6 +544,24 @@ class TestClass { ''', false, false, false, CONSTRUCTOR } + void 'test introduce field in script with invalid class name'() { + myFixture.configureByText "abcd-efgh.groovy", '''\ +def aaa = "foo" +def bbb = "bar" +println(aaa + bbb) +''' + performRefactoring(null, false, false, false, CUR_METHOD, false) + myFixture.checkResult '''\ +import groovy.transform.Field + +@Field f +def aaa = "foo" +def bbb = "bar" +f = aaa + bbb +println(f) +''' + } + void 'test cannot initialize in current method when introducing from field initializer'() { doTestInitInTarget ''' class A { @@ -596,6 +614,34 @@ class A { ''', EnumSet.of(CONSTRUCTOR, FIELD_DECLARATION, CUR_METHOD), ReplaceChoice.NO } + void 'test can initialize script field in current method only'() { + doTestInitInTarget ''' +def a = 1 +def b = 2 +println(a + b) +''', EnumSet.of(CUR_METHOD) + + doTestInitInTarget ''' +def a = 1 +def b = 2 +println(a + b) +''', EnumSet.of(CUR_METHOD), ReplaceChoice.NO + + doTestInitInTarget ''' +def a = 1 +def b = 2 +def c = a + b +println(a + b) +''', EnumSet.of(CUR_METHOD) + + doTestInitInTarget ''' +def a = 1 +def b = 2 +def c = a + b +println(a + b) +''', EnumSet.of(CUR_METHOD), ReplaceChoice.NO + } + private void doTest(final boolean isStatic, final boolean removeLocal, final boolean declareFinal, @@ -620,7 +666,6 @@ class A { myFixture.checkResult(textAfter); } - private void performRefactoring(String selectedType, boolean isStatic, boolean removeLocal, boolean declareFinal, GrIntroduceFieldSettings.Init initIn, boolean replaceAll) { final PsiType type = selectedType == null ? null : JavaPsiFacade.getElementFactory(project).createTypeFromText(selectedType, myFixture.file) def accessToken = WriteAction.start() diff --git a/python/educational-core/src/com/jetbrains/edu/EduAnswerPlaceholderPainter.java b/python/educational-core/src/com/jetbrains/edu/EduAnswerPlaceholderPainter.java index 137062810ec9..da2972c440c3 100644 --- a/python/educational-core/src/com/jetbrains/edu/EduAnswerPlaceholderPainter.java +++ b/python/educational-core/src/com/jetbrains/edu/EduAnswerPlaceholderPainter.java @@ -51,7 +51,7 @@ public class EduAnswerPlaceholderPainter { public static void createGuardedBlock(Editor editor, List blocks, int start, int end) { RangeHighlighter rh = editor.getMarkupModel() - .addRangeHighlighter(start, end, HighlighterLayer.LAST + 1, null, HighlighterTargetArea.EXACT_RANGE); + .addRangeHighlighter(start, end, PLACEHOLDERS_LAYER, null, HighlighterTargetArea.EXACT_RANGE); blocks.add(rh); } diff --git a/python/educational-python/course-creator-python/src/com/jetbrains/edu/coursecreator/PyCCProjectGenerator.java b/python/educational-python/course-creator-python/src/com/jetbrains/edu/coursecreator/PyCCProjectGenerator.java index a8c0082f9d99..29f60e14a0bd 100644 --- a/python/educational-python/course-creator-python/src/com/jetbrains/edu/coursecreator/PyCCProjectGenerator.java +++ b/python/educational-python/course-creator-python/src/com/jetbrains/edu/coursecreator/PyCCProjectGenerator.java @@ -39,12 +39,6 @@ public class PyCCProjectGenerator extends PythonProjectGenerator implements Dire return "Course creation"; } - @Nullable - @Override - public Object showGenerationSettings(VirtualFile baseDir) throws ProcessCanceledException { - return null; - } - @Nullable @Override public Icon getLogo() { diff --git a/python/educational-python/student-python/src/com/jetbrains/edu/learning/PyStudyDirectoryProjectGenerator.java b/python/educational-python/student-python/src/com/jetbrains/edu/learning/PyStudyDirectoryProjectGenerator.java index 37eb89c49bef..d4d95ad5e5d1 100644 --- a/python/educational-python/student-python/src/com/jetbrains/edu/learning/PyStudyDirectoryProjectGenerator.java +++ b/python/educational-python/student-python/src/com/jetbrains/edu/learning/PyStudyDirectoryProjectGenerator.java @@ -49,12 +49,6 @@ public class PyStudyDirectoryProjectGenerator extends PythonProjectGenerator imp return "Educational"; } - @Nullable - @Override - public Object showGenerationSettings(VirtualFile baseDir) throws ProcessCanceledException { - return null; - } - @Nullable @Override public Icon getLogo() { diff --git a/python/ide/src/com/jetbrains/python/newProject/PythonBaseProjectGenerator.java b/python/ide/src/com/jetbrains/python/newProject/PythonBaseProjectGenerator.java index 138c242761ce..c1a33744b475 100644 --- a/python/ide/src/com/jetbrains/python/newProject/PythonBaseProjectGenerator.java +++ b/python/ide/src/com/jetbrains/python/newProject/PythonBaseProjectGenerator.java @@ -42,12 +42,6 @@ public class PythonBaseProjectGenerator extends PythonProjectGenerator implement return "Pure Python"; } - @Nullable - @Override - public Object showGenerationSettings(VirtualFile baseDir) throws ProcessCanceledException { - return null; - } - @Override @Nullable public JComponent getSettingsPanel(File baseDir) throws ProcessCanceledException {