[alefas] extensible OutOfCodeBlock modification tracking

This commit is contained in:
peter
2011-02-04 14:39:48 +01:00
parent 786760317b
commit 1e8caec1c2
4 changed files with 42 additions and 10 deletions
@@ -670,23 +670,22 @@ public class JavaPsiFacadeImpl extends JavaPsiFacadeEx implements Disposable {
if (element instanceof PsiFileSystemItem) {
return false;
}
if (element == null || element.getParent() == null) return true;
while(true){
if (element instanceof PsiFile || element instanceof PsiDirectory || element == null){
PsiElement parent = element;
while (true) {
if (parent instanceof PsiFile || parent instanceof PsiDirectory || parent == null) {
return false;
}
PsiElement pparent = element.getParent();
if (element instanceof PsiClass) return false; // anonymous or local class
if (element instanceof PsiCodeBlock){
if (pparent instanceof PsiMethod || pparent instanceof PsiClassInitializer){
if (parent instanceof PsiClass) return false; // anonymous or local class
if (parent instanceof PsiModifiableCodeBlock) {
if (!((PsiModifiableCodeBlock)parent).shouldChangeModificationCount(element)) {
return true;
}
}
element = pparent;
parent = parent.getParent();
}
}
}
}
@@ -221,4 +221,9 @@ public class PsiCodeBlockImpl extends LazyParseablePsiElement implements PsiCode
}
return true;
}
public boolean shouldChangeModificationCount(PsiElement place) {
PsiElement pparent = getParent();
return !(pparent instanceof PsiMethod || pparent instanceof PsiClassInitializer);
}
}
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.Nullable;
/**
* Represents a Java code block, usually surrounded by curly braces.
*/
public interface PsiCodeBlock extends PsiElement {
public interface PsiCodeBlock extends PsiElement, PsiModifiableCodeBlock {
/**
* The empty array of PSI code blocks which can be reused to avoid unnecessary allocations.
*/
@@ -0,0 +1,28 @@
/*
* Copyright 2000-2011 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.psi;
/**
* Represents psi element, which can be modified without caches reset.
* @see com.intellij.psi.util.PsiModificationTracker#getOutOfCodeBlockModificationCount()
*/
public interface PsiModifiableCodeBlock {
/**
* @param place where change was detected
* @return false if specific caches could be saved after the change
*/
boolean shouldChangeModificationCount(PsiElement place);
}