diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java index 86e12da2147f..2e13cdc49563 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceConstantPopup.java @@ -116,7 +116,7 @@ public class InplaceIntroduceConstantPopup { } myOccurenceManager = occurenceManager; - myExprMarker = expr != null ? myEditor.getDocument().createRangeMarker(expr.getTextRange()) : null; + myExprMarker = expr != null && expr.isPhysical() ? myEditor.getDocument().createRangeMarker(expr.getTextRange()) : null; myExprText = expr != null ? expr.getText() : null; myLocalName = localVariable != null ? localVariable.getName() : null; @@ -255,7 +255,7 @@ public class InplaceIntroduceConstantPopup { super(myProject, new TypeExpression(myProject, myTypeSelectorManager.getTypesForAll()), myEditor, field, false, myTypeSelectorManager.getTypesForAll().length > 1, - myExpr != null ? myEditor.getDocument().createRangeMarker(myExpr.getTextRange()) : null, InplaceIntroduceConstantPopup.this.getOccurrenceMarkers()); + myExpr != null && myExpr.isPhysical() ? myEditor.getDocument().createRangeMarker(myExpr.getTextRange()) : null, InplaceIntroduceConstantPopup.this.getOccurrenceMarkers()); myDefaultParameterTypePointer = SmartTypePointerManager.getInstance(myProject).createSmartTypePointer(myTypeSelectorManager.getDefaultType()); @@ -269,7 +269,7 @@ public class InplaceIntroduceConstantPopup { @Override protected PsiExpression getExpr() { - return myExpr; + return myExpr != null && myExpr.isValid() && myExpr.isPhysical() ? myExpr : null; } @Override @@ -392,9 +392,12 @@ public class InplaceIntroduceConstantPopup { public void run() { final PsiFile containingFile = myParentClass.getContainingFile(); final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(myProject); - myExpr = restoreExpression(containingFile, psiField, elementFactory, getExprMarker(), myExprText); - if (myExpr != null) { - myExprMarker = myEditor.getDocument().createRangeMarker(myExpr.getTextRange()); + final RangeMarker exprMarker = getExprMarker(); + if (exprMarker != null) { + myExpr = restoreExpression(containingFile, psiField, elementFactory, exprMarker, myExprText); + if (myExpr != null && myExpr.isPhysical()) { + myExprMarker = myEditor.getDocument().createRangeMarker(myExpr.getTextRange()); + } } final List occurrenceMarkers = getOccurrenceMarkers(); for (int i = 0, occurrenceMarkersSize = occurrenceMarkers.size(); i < occurrenceMarkersSize; i++) { diff --git a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java index 848db6a5cee2..dda9a4e4aecf 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceField/InplaceIntroduceFieldPopup.java @@ -95,7 +95,7 @@ public class InplaceIntroduceFieldPopup { myInitializerExpression = initializerExpression; myExprText = myInitializerExpression != null ? myInitializerExpression.getText() : null; myLocalName = localVariable != null ? localVariable.getName() : null; - myExprMarker = myInitializerExpression != null ? editor.getDocument().createRangeMarker(myInitializerExpression.getTextRange()) : null; + myExprMarker = myInitializerExpression != null && myInitializerExpression.isPhysical() ? editor.getDocument().createRangeMarker(myInitializerExpression.getTextRange()) : null; myTypeSelectorManager = typeSelectorManager; myAnchorElement = anchorElement; myAnchorElementIfAll = anchorElementIfAll; @@ -233,7 +233,7 @@ public class InplaceIntroduceFieldPopup { super(myProject, new TypeExpression(myProject, myTypeSelectorManager.getTypesForAll()), myEditor, psiVariable, false, myTypeSelectorManager.getTypesForAll().length > 1, - myInitializerExpression != null ? myEditor.getDocument().createRangeMarker(myInitializerExpression.getTextRange()) : null, InplaceIntroduceFieldPopup.this.getOccurrenceMarkers()); + myInitializerExpression != null && myInitializerExpression.isPhysical() ? myEditor.getDocument().createRangeMarker(myInitializerExpression.getTextRange()) : null, InplaceIntroduceFieldPopup.this.getOccurrenceMarkers()); myDefaultParameterTypePointer = SmartTypePointerManager.getInstance(myProject).createSmartTypePointer(myTypeSelectorManager.getDefaultType()); myFieldRangeStart = myEditor.getDocument().createRangeMarker(psiVariable.getTextRange()); @@ -246,7 +246,7 @@ public class InplaceIntroduceFieldPopup { @Override protected PsiExpression getExpr() { - return myInitializerExpression; + return myInitializerExpression != null && myInitializerExpression.isValid() && myInitializerExpression.isPhysical() ? myInitializerExpression : null; } @Override @@ -354,9 +354,11 @@ public class InplaceIntroduceFieldPopup { public void run() { final PsiFile containingFile = myParentClass.getContainingFile(); final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(myProject); - myInitializerExpression = restoreExpression(containingFile, psiField, elementFactory, getExprMarker(), myExprText); - if (myInitializerExpression != null) { - myExprMarker = myEditor.getDocument().createRangeMarker(myInitializerExpression.getTextRange()); + if (getExprMarker() != null) { + myInitializerExpression = restoreExpression(containingFile, psiField, elementFactory, getExprMarker(), myExprText); + if (myInitializerExpression != null) { + myExprMarker = myEditor.getDocument().createRangeMarker(myInitializerExpression.getTextRange()); + } } final List occurrenceMarkers = getOccurrenceMarkers(); for (int i = 0, occurrenceMarkersSize = occurrenceMarkers.size(); i < occurrenceMarkersSize; i++) {