1 package com
.intellij
.openapi
.roots
.impl
;
3 import com
.intellij
.openapi
.fileTypes
.StdFileTypes
;
4 import com
.intellij
.openapi
.module
.LanguageLevelUtil
;
5 import com
.intellij
.openapi
.module
.Module
;
6 import com
.intellij
.openapi
.project
.Project
;
7 import com
.intellij
.openapi
.util
.Key
;
8 import com
.intellij
.openapi
.vfs
.VirtualFile
;
9 import com
.intellij
.openapi
.vfs
.newvfs
.FileAttribute
;
10 import com
.intellij
.pom
.java
.LanguageLevel
;
11 import com
.intellij
.util
.indexing
.FileBasedIndex
;
12 import com
.intellij
.util
.messages
.MessageBus
;
14 import java
.io
.DataInputStream
;
15 import java
.io
.DataOutputStream
;
16 import java
.io
.IOException
;
18 import org
.jetbrains
.annotations
.NotNull
;
21 * @author Gregory.Shrago
23 public class JavaLanguageLevelPusher
implements FilePropertyPusher
<LanguageLevel
> {
25 public static void pushLanguageLevel(final Project project
) {
26 PushedFilePropertiesUpdater
.getInstance(project
).pushAll(new JavaLanguageLevelPusher());
29 public void initExtra(Project project
, MessageBus bus
, Engine languageLevelUpdater
) {
34 public Key
<LanguageLevel
> getFileDataKey() {
35 return LanguageLevel
.KEY
;
38 public boolean pushDirectoriesOnly() {
42 public LanguageLevel
getDefaultValue() {
43 return LanguageLevel
.HIGHEST
;
46 public LanguageLevel
getImmediateValue(Project project
, VirtualFile file
) {
50 public LanguageLevel
getImmediateValue(Module module
) {
51 return LanguageLevelUtil
.getEffectiveLanguageLevel(module
);
54 public boolean acceptsFile(VirtualFile file
) {
58 private static final FileAttribute PERSISTENCE
= new FileAttribute("language_level_persistence", 1);
60 public void persistAttribute(VirtualFile fileOrDir
, LanguageLevel level
) throws IOException
{
61 final DataInputStream iStream
= PERSISTENCE
.readAttribute(fileOrDir
);
62 if (iStream
!= null) {
64 final int oldLevelOrdinal
= iStream
.readInt();
65 if (oldLevelOrdinal
== level
.ordinal()) return;
72 final DataOutputStream oStream
= PERSISTENCE
.writeAttribute(fileOrDir
);
73 oStream
.writeInt(level
.ordinal());
76 for (VirtualFile child
: fileOrDir
.getChildren()) {
77 if (!child
.isDirectory() && StdFileTypes
.JAVA
.equals(child
.getFileType())) {
78 FileBasedIndex
.getInstance().requestReindex(child
);