annotation modification tracker
[fedora-idea.git] / platform / lang-impl / src / com / intellij / psi / impl / PsiModificationTrackerImpl.java
blobfcf036795d8d2073beb78356d9611f5dc022162a
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * Created by IntelliJ IDEA.
19 * User: mike
20 * Date: Jul 18, 2002
21 * Time: 5:57:57 PM
22 * To change template for new class use
23 * Code Style | Class Templates options (Tools | IDE Options).
25 package com.intellij.psi.impl;
27 import com.intellij.ProjectTopics;
28 import com.intellij.openapi.project.DumbService;
29 import com.intellij.openapi.project.Project;
30 import com.intellij.openapi.application.ApplicationManager;
31 import com.intellij.psi.PsiDirectory;
32 import com.intellij.psi.util.PsiModificationTracker;
33 import com.intellij.util.messages.MessageBus;
35 public class PsiModificationTrackerImpl implements PsiModificationTracker, PsiTreeChangePreprocessor {
36 private volatile long myModificationCount = 0;
37 private volatile long myOutOfCodeBlockModificationCount = 0;
38 private volatile long myJavaStructureModificationCount = 0;
39 private volatile long myAnnotationModificationCount = 0;
40 private final Listener myPublisher;
42 public PsiModificationTrackerImpl(Project project) {
43 final MessageBus bus = project.getMessageBus();
44 myPublisher = bus.syncPublisher(ProjectTopics.MODIFICATION_TRACKER);
45 bus.connect().subscribe(DumbService.DUMB_MODE, new DumbService.DumbModeListener() {
47 public void enteredDumbMode() {
48 ApplicationManager.getApplication().runWriteAction(new Runnable() {
49 public void run() {
50 incCounter();
52 });
55 public void exitDumbMode() {
56 enteredDumbMode();
58 });
61 public void incCounter(){
62 myModificationCount++;
63 myJavaStructureModificationCount++;
64 incOutOfCodeBlockModificationCounter();
67 public void incOutOfCodeBlockModificationCounter() {
68 myOutOfCodeBlockModificationCount++;
69 myPublisher.modificationCountChanged();
72 public void incAnnotationModificationCounter() {
73 myAnnotationModificationCount++;
76 public void treeChanged(PsiTreeChangeEventImpl event) {
77 myModificationCount++;
78 if (event.getParent() instanceof PsiDirectory) {
79 incOutOfCodeBlockModificationCounter();
82 myPublisher.modificationCountChanged();
85 public long getModificationCount() {
86 return myModificationCount;
89 public long getOutOfCodeBlockModificationCount() {
90 return myOutOfCodeBlockModificationCount;
93 public long getJavaStructureModificationCount() {
94 return myJavaStructureModificationCount;
97 public long getAnnotationModificationCount() {
98 return myAnnotationModificationCount;