diff --git a/platform/core-api/src/com/intellij/psi/tree/IReparseableElementType.java b/platform/core-api/src/com/intellij/psi/tree/IReparseableElementType.java index 5a1636d9b4b5..c5772976887c 100644 --- a/platform/core-api/src/com/intellij/psi/tree/IReparseableElementType.java +++ b/platform/core-api/src/com/intellij/psi/tree/IReparseableElementType.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -19,9 +19,11 @@ */ package com.intellij.psi.tree; +import com.intellij.lang.ASTNode; import com.intellij.lang.Language; import com.intellij.openapi.project.Project; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.Nullable; public class IReparseableElementType extends ILazyParseableElementType { public IReparseableElementType(@NonNls String debugName) { @@ -43,10 +45,33 @@ public class IReparseableElementType extends ILazyParseableElementType { * * @param buffer the content to parse. * @param fileLanguage language of the file - * @param project the project containing the content. @return true if the content is valid, false if not + * @param project the project containing the content. + * @return true if the content is valid, false if not */ public boolean isParsable(CharSequence buffer, Language fileLanguage, final Project project) { return false; } + + /** + * The same as {@link this#isParsable(CharSequence, com.intellij.lang.Language, com.intellij.openapi.project.Project)} + * but with parent ASTNode of the old node. + * + * Override this method only if you really understand what are doing. + * In other cases override {@link this#isParsable(CharSequence, com.intellij.lang.Language, com.intellij.openapi.project.Project)} + * + * Known valid use-case: + * Indent-based languages. You should know about parent indent in order to decide if block is reparsable with given text. + * Because if indent of some line became equals to parent indent then the block should have another parent or block is not block anymore. + * So it cannot be reparsed and whole file or parent block should be reparsed. + * + * @param parent parent node of old (or collapsed) reparsable node. + * @param buffer the content to parse. + * @param fileLanguage language of the file + * @param project the project containing the content. + * @return true if the content is valid, false if not + */ + public boolean isParsable(@Nullable ASTNode parent, CharSequence buffer, Language fileLanguage, final Project project) { + return isParsable(buffer, fileLanguage, project); + } } diff --git a/platform/core-impl/src/com/intellij/psi/impl/source/text/BlockSupportImpl.java b/platform/core-impl/src/com/intellij/psi/impl/source/text/BlockSupportImpl.java index 695e948cce32..b5070410025f 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/source/text/BlockSupportImpl.java +++ b/platform/core-impl/src/com/intellij/psi/impl/source/text/BlockSupportImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -112,7 +112,7 @@ public class BlockSupportImpl extends BlockSupport { CharSequence newTextStr = newFileText.subSequence(start, end); - if (reparseable.isParsable(newTextStr, baseLanguage, project)) { + if (reparseable.isParsable(node.getTreeParent(), newTextStr, baseLanguage, project)) { ASTNode chameleon = reparseable.createNode(newTextStr); if (chameleon != null) { DummyHolder holder = DummyHolderFactory.createHolder(fileImpl.getManager(), null, node.getPsi(), charTable);