Extend block support API

This commit is contained in:
Alexander Zolotov
2013-12-23 18:11:18 +04:00
parent 107e9ae442
commit 60a5c6086f
2 changed files with 29 additions and 4 deletions
@@ -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);
}
}
@@ -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);