NPE
[fedora-idea.git] / java / openapi / src / com / intellij / openapi / module / LanguageLevelUtil.java
blob2b52e0c05863f5f00b3b7bdcc5c91ebe06c0e708
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.
16 package com.intellij.openapi.module;
18 import com.intellij.openapi.application.ApplicationManager;
19 import com.intellij.openapi.roots.LanguageLevelModuleExtension;
20 import com.intellij.openapi.roots.LanguageLevelProjectExtension;
21 import com.intellij.openapi.vfs.VirtualFile;
22 import com.intellij.pom.java.LanguageLevel;
23 import org.jetbrains.annotations.NotNull;
25 /**
26 * @author yole
28 public class LanguageLevelUtil {
29 private LanguageLevelUtil() {
32 @NotNull
33 public static LanguageLevel getEffectiveLanguageLevel(@NotNull final Module module) {
34 ApplicationManager.getApplication().assertReadAccessAllowed();
35 LanguageLevel level = LanguageLevelModuleExtension.getInstance(module).getLanguageLevel();
36 if (level != null) return level;
37 return LanguageLevelProjectExtension.getInstance(module.getProject()).getLanguageLevel();
40 @NotNull
41 public static LanguageLevel getLanguageLevelForFile(final VirtualFile file) {
42 if (file == null) return LanguageLevel.HIGHEST;
44 if (file.isDirectory()) {
45 final LanguageLevel ll = file.getUserData(LanguageLevel.KEY);
46 return ll != null ? ll : LanguageLevel.HIGHEST;
49 return getLanguageLevelForFile(file.getParent());