diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaWithCastSurrounder.java b/java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaWithCastSurrounder.java index 55e893884f5a..90263c4eda55 100644 --- a/java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaWithCastSurrounder.java +++ b/java/java-impl/src/com/intellij/codeInsight/generation/surroundWith/JavaWithCastSurrounder.java @@ -40,6 +40,7 @@ class JavaWithCastSurrounder extends JavaExpressionSurrounder { } public TextRange surroundExpression(final Project project, final Editor editor, PsiExpression expr) throws IncorrectOperationException { + assert expr.isValid(); PsiType[] types = GuessManager.getInstance(project).guessTypeToCast(expr); final Template template = generateTemplate(project, expr.getText(), types); TextRange range = expr.getTextRange(); diff --git a/java/java-impl/src/com/intellij/codeInsight/guess/impl/GuessManagerImpl.java b/java/java-impl/src/com/intellij/codeInsight/guess/impl/GuessManagerImpl.java index 54b0ba98adfa..98bebf4b31b3 100644 --- a/java/java-impl/src/com/intellij/codeInsight/guess/impl/GuessManagerImpl.java +++ b/java/java-impl/src/com/intellij/codeInsight/guess/impl/GuessManagerImpl.java @@ -162,6 +162,7 @@ public class GuessManagerImpl extends GuessManager { } private static Map getAllTypeCasts(PsiExpression forPlace) { + assert forPlace.isValid(); final int start = forPlace.getTextRange().getStartOffset(); final Map allCasts = new THashMap(ExpressionTypeMemoryState.EXPRESSION_HASHING_STRATEGY); getTopmostBlock(forPlace).accept(new JavaRecursiveElementWalkingVisitor() { @@ -198,6 +199,7 @@ public class GuessManagerImpl extends GuessManager { } private static PsiElement getTopmostBlock(PsiElement scope) { + assert scope.isValid(); PsiElement lastScope = scope; while (true) { final PsiCodeBlock lastCodeBlock = PsiTreeUtil.getParentOfType(lastScope, PsiCodeBlock.class, true); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/generation/surroundWith/SurroundWithHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/generation/surroundWith/SurroundWithHandler.java index 04b6707755d7..f13b6a4bded8 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/generation/surroundWith/SurroundWithHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/generation/surroundWith/SurroundWithHandler.java @@ -114,6 +114,9 @@ public class SurroundWithHandler implements CodeInsightActionHandler{ for (SurroundDescriptor descriptor : surroundDescriptors) { final PsiElement[] elements = descriptor.getElementsToSurround(file, startOffset, endOffset); if (elements.length > 0) { + for (PsiElement element : elements) { + assert element.isValid() : descriptor; + } List applicable = buildSurroundActions(project, editor, file, descriptor.getSurrounders(), elements); if (applicable != null) { return applicable;