2 * Copyright 2000-2015 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.codeInsight.daemon.impl.quickfix;
18 import com.intellij.codeInsight.AnnotationUtil;
19 import com.intellij.codeInsight.daemon.quickFix.ExternalLibraryDescriptor;
20 import com.intellij.codeInsight.daemon.quickFix.ExternalLibraryResolver;
21 import com.intellij.openapi.application.PathManager;
22 import com.intellij.openapi.module.EffectiveLanguageLevelUtil;
23 import com.intellij.openapi.module.Module;
24 import com.intellij.openapi.util.io.FileUtil;
25 import com.intellij.pom.java.LanguageLevel;
26 import com.intellij.util.ThreeState;
27 import org.jetbrains.annotations.NotNull;
28 import org.jetbrains.annotations.Nullable;
31 import java.util.Collections;
32 import java.util.List;
37 public class JetBrainsAnnotationsExternalLibraryResolver extends ExternalLibraryResolver {
38 private static final ExternalLibraryDescriptor JAVA5 = new JetBrainsAnnotationsLibraryDescriptor() {
41 public List<String> getLibraryClassesRoots() {
42 return Collections.singletonList(FileUtil.toSystemIndependentName(new File(PathManager.getLibPath(), "annotations.jar").getAbsolutePath()));
45 private static final ExternalLibraryDescriptor JAVA8 = new JetBrainsAnnotationsLibraryDescriptor() {
48 public List<String> getLibraryClassesRoots() {
49 return Collections.singletonList(FileUtil.toSystemIndependentName(new File(PathManager.getHomePath(), "redist/annotations-java8.jar").getAbsolutePath()));
55 public ExternalClassResolveResult resolveClass(@NotNull String shortClassName, @NotNull ThreeState isAnnotation, @NotNull Module contextModule) {
56 if (AnnotationUtil.isJetbrainsAnnotation(shortClassName)) {
57 ExternalLibraryDescriptor libraryDescriptor = getAnnotationsLibraryDescriptor(contextModule);
58 return new ExternalClassResolveResult("org.jetbrains.annotations." + shortClassName, libraryDescriptor);
64 public static ExternalLibraryDescriptor getAnnotationsLibraryDescriptor(@NotNull Module contextModule) {
65 boolean java8 = EffectiveLanguageLevelUtil.getEffectiveLanguageLevel(contextModule).isAtLeast(LanguageLevel.JDK_1_8);
66 return java8 ? JAVA8 : JAVA5;
69 private static abstract class JetBrainsAnnotationsLibraryDescriptor extends ExternalLibraryDescriptor {
70 public JetBrainsAnnotationsLibraryDescriptor() {
71 super("com.intellij", "annotations", null);