update copyrights
[fedora-idea.git] / platform / lang-impl / src / com / intellij / codeInsight / daemon / impl / CodeFoldingPass.java
blobf79bb68ef46784d9c8ec8b2f258334cba490367b
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.
17 package com.intellij.codeInsight.daemon.impl;
19 import com.intellij.codeHighlighting.TextEditorHighlightingPass;
20 import com.intellij.codeInsight.folding.CodeFoldingManager;
21 import com.intellij.openapi.editor.Editor;
22 import com.intellij.openapi.progress.ProgressIndicator;
23 import com.intellij.openapi.project.DumbAware;
24 import com.intellij.openapi.project.Project;
25 import com.intellij.openapi.project.IndexNotReadyException;
26 import com.intellij.openapi.util.Key;
27 import com.intellij.psi.PsiFile;
28 import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
29 import org.jetbrains.annotations.NotNull;
31 class CodeFoldingPass extends TextEditorHighlightingPass implements DumbAware {
32 private static final Key<Boolean> THE_FIRST_TIME = Key.create("FirstFoldingPass");
33 private Runnable myRunnable;
34 private final Editor myEditor;
35 private final PsiFile myFile;
37 CodeFoldingPass(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
38 super(project, editor.getDocument(), false);
39 myEditor = editor;
40 myFile = file;
43 public void doCollectInformation(ProgressIndicator progress) {
44 final boolean firstTime = myFile.getUserData(THE_FIRST_TIME) == null || myEditor.getUserData(THE_FIRST_TIME) == null;
45 Runnable runnable = CodeFoldingManager.getInstance(myProject).updateFoldRegionsAsync(myEditor, firstTime);
46 synchronized (this) {
47 myRunnable = runnable;
51 public void doApplyInformationToEditor() {
52 Runnable runnable;
53 synchronized (this) {
54 runnable = myRunnable;
56 if (runnable != null){
57 try {
58 runnable.run();
60 catch (IndexNotReadyException e) {
64 if (InjectedLanguageUtil.getTopLevelFile(myFile) == myFile) {
65 myFile.putUserData(THE_FIRST_TIME, Boolean.FALSE);
66 myEditor.putUserData(THE_FIRST_TIME, Boolean.FALSE);