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(false);
39 private static final ExternalLibraryDescriptor JAVA8 = new JetBrainsAnnotationsLibraryDescriptor(true);
43 public ExternalClassResolveResult resolveClass(@NotNull String shortClassName, @NotNull ThreeState isAnnotation, @NotNull Module contextModule) {
44 if (AnnotationUtil.isJetbrainsAnnotation(shortClassName)) {
45 ExternalLibraryDescriptor libraryDescriptor = getAnnotationsLibraryDescriptor(contextModule);
46 return new ExternalClassResolveResult("org.jetbrains.annotations." + shortClassName, libraryDescriptor);
52 public static ExternalLibraryDescriptor getAnnotationsLibraryDescriptor(@NotNull Module contextModule) {
53 boolean java8 = EffectiveLanguageLevelUtil.getEffectiveLanguageLevel(contextModule).isAtLeast(LanguageLevel.JDK_1_8);
54 return java8 ? JAVA8 : JAVA5;
57 private static class JetBrainsAnnotationsLibraryDescriptor extends ExternalLibraryDescriptor {
58 private boolean myJava8;
60 public JetBrainsAnnotationsLibraryDescriptor(boolean java8) {
61 super("com.intellij", "annotations", null);
67 public List<String> getLibraryClassesRoots() {
70 paths = Collections.singletonList(FileUtil.toSystemIndependentName(new File(PathManager.getHomePath(), "redist/annotations-java8.jar").getAbsolutePath()));
73 paths = Collections.singletonList(FileUtil.toSystemIndependentName(new File(PathManager.getLibPath(), "annotations.jar").getAbsolutePath()));