Fix deprecated API usages

This commit is contained in:
Roman Shevchenko
2012-05-11 22:03:34 +04:00
parent c6c028883b
commit 73f8db9d5f
11 changed files with 27 additions and 23 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,6 +39,7 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.util.Pair;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.ArrayUtil;
@@ -118,7 +119,7 @@ public class DataFlowInspection extends BaseLocalInspectionTool {
binary.getLOperand().replace(qualifier);
List<LocalQuickFix> fixes = new SmartList<LocalQuickFix>();
if (PsiUtil.getLanguageLevel(qualifier).hasAssertKeyword()) {
if (PsiUtil.getLanguageLevel(qualifier).isAtLeast(LanguageLevel.JDK_1_4)) {
fixes.add(new AddAssertStatementFix(binary));
}
SurroundWithIfFix ifFix = new SurroundWithIfFix(qualifier);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,9 +34,7 @@ public class JavaHighlightingLexer extends LayeredLexer {
registerSelfStoppingLayer(new StringLiteralLexer('\'', JavaTokenType.STRING_LITERAL),
new IElementType[]{JavaTokenType.CHARACTER_LITERAL}, IElementType.EMPTY_ARRAY);
LayeredLexer docLexer = new LayeredLexer(new JavaDocLexer(languageLevel.hasEnumKeywordAndAutoboxing()));
LayeredLexer docLexer = new LayeredLexer(new JavaDocLexer(languageLevel.isAtLeast(LanguageLevel.JDK_1_5)));
HtmlHighlightingLexer lexer = new HtmlHighlightingLexer();
lexer.setHasNoEmbeddments(true);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -53,7 +53,7 @@ public class ValueDocTagInfo implements JavadocTagInfo {
public String checkTagValue(PsiDocTagValue value) {
boolean hasReference = (value != null && value.getFirstChild() != null);
if (hasReference) {
if (!PsiUtil.getLanguageLevel(value).hasEnumKeywordAndAutoboxing()) {
if (!PsiUtil.isLanguageLevel5OrHigher(value)) {
return JavaErrorMessages.message("javadoc.value.tag.jdk15.required");
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -82,7 +82,7 @@ public class JavaClassReferenceSet {
if (ch == LT || ch == COMMA) {
if (!allowGenericsCalculated) {
allowGenerics = !isStaticImport && PsiUtil.getLanguageLevel(element).hasEnumKeywordAndAutoboxing();
allowGenerics = !isStaticImport && PsiUtil.isLanguageLevel5OrHigher(element);
allowGenericsCalculated = true;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,6 +30,7 @@ import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Comparing;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.codeStyle.SuggestedNameInfo;
@@ -265,7 +266,7 @@ class IntroduceConstantDialog extends DialogWrapper {
final PsiManager psiManager = PsiManager.getInstance(myProject);
if ((myTypeSelectorManager.isSuggestedType("java.lang.String") || (myLocalVariable != null && AnnotationUtil.isAnnotated(myLocalVariable, AnnotationUtil.NON_NLS, false)))&&
LanguageLevelProjectExtension.getInstance(psiManager.getProject()).getLanguageLevel().hasEnumKeywordAndAutoboxing() &&
LanguageLevelProjectExtension.getInstance(psiManager.getProject()).getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_5) &&
JavaPsiFacade.getInstance(psiManager.getProject()).findClass(AnnotationUtil.NON_NLS, myParentClass.getResolveScope()) != null) {
final PropertiesComponent component = PropertiesComponent.getInstance(myProject);
myCbNonNls.setSelected(component.isTrueValue(NONNLS_SELECTED_PROPERTY));
@@ -40,16 +40,19 @@ public enum LanguageLevel {
}
/** @deprecated (to remove in IDEA 13) */
@SuppressWarnings("UnusedDeclaration")
public int getIndex() {
return ordinal() + 3; // solely for backward compatibility
}
/** @deprecated (to remove in IDEA 13) */
@SuppressWarnings("UnusedDeclaration")
public boolean hasAssertKeyword() {
return isAtLeast(JDK_1_4);
}
/** @deprecated use {@linkplain com.intellij.psi.util.PsiUtil#isLanguageLevel5OrHigher(com.intellij.psi.PsiElement)} (to remove in IDEA 13) */
@SuppressWarnings("UnusedDeclaration")
public boolean hasEnumKeywordAndAutoboxing() {
return isAtLeast(JDK_1_5);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -104,7 +104,7 @@ public class PsiPrimitiveType extends PsiType {
@Nullable
public static PsiPrimitiveType getUnboxedType(PsiType type) {
if (!(type instanceof PsiClassType)) return null;
if (!((PsiClassType)type).getLanguageLevel().hasEnumKeywordAndAutoboxing()) return null;
if (!((PsiClassType)type).getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_5)) return null;
final PsiClass psiClass = ((PsiClassType)type).resolve();
if (psiClass == null) return null;
return ourQNameToUnboxed.get(psiClass.getQualifiedName());
@@ -124,7 +124,7 @@ public class PsiPrimitiveType extends PsiType {
@Nullable
public PsiClassType getBoxedType(PsiElement context) {
LanguageLevel languageLevel = PsiUtil.getLanguageLevel(context);
if (!languageLevel.hasEnumKeywordAndAutoboxing()) return null;
if (!languageLevel.isAtLeast(LanguageLevel.JDK_1_5)) return null;
final String boxedQName = getBoxedTypeName();
//[ven]previous call returns null for NULL, VOID
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -780,7 +780,7 @@ public class TypeConversionUtil {
private static final Key<CachedValue<Set<String>>> POSSIBLE_BOXED_HOLDER_TYPES = Key.create("Types that may be possibly assigned from primitive ones");
private static boolean isBoxable(final PsiClassType left, final PsiPrimitiveType right) {
if (!left.getLanguageLevel().hasEnumKeywordAndAutoboxing()) return false;
if (!left.getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_5)) return false;
final PsiClass psiClass = left.resolve();
if (psiClass == null) return false;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -202,7 +202,7 @@ public class JavaLanguageInjectionSupport extends AbstractLanguageInjectionSuppo
static boolean doAddLanguageAnnotation(final Project project, final PsiModifierListOwner modifierListOwner,
final String languageId) {
if (modifierListOwner.getModifierList() == null || !PsiUtil.getLanguageLevel(modifierListOwner).hasEnumKeywordAndAutoboxing()) return false;
if (modifierListOwner.getModifierList() == null || !PsiUtil.isLanguageLevel5OrHigher(modifierListOwner)) return false;
if (!OrderEntryFix.ensureAnnotationsJarInPath(ModuleUtil.findModuleForPsiElement(modifierListOwner), AnnotationUtil.LANGUAGE)) return false;
new WriteCommandAction(project, modifierListOwner.getContainingFile()) {
protected void run(final Result result) throws Throwable {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -449,7 +449,7 @@ public class I18nInspection extends BaseLocalInspectionTool {
final Project project = expression.getManager().getProject();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
if (PsiUtil.getLanguageLevel(expression).hasEnumKeywordAndAutoboxing()) {
if (PsiUtil.isLanguageLevel5OrHigher(expression)) {
for (PsiModifierListOwner element : nonNlsTargets) {
if (!AnnotationUtil.isAnnotated(element, AnnotationUtil.NLS, true)) {
if (!element.getManager().isInProject(element) || facade.findClass(AnnotationUtil.NON_NLS, element.getResolveScope()) != null) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.CodeInsightUtilBase;
import com.intellij.codeInspection.*;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.util.PsiElementFilter;
@@ -95,7 +96,7 @@ public class JUnitConvertTool extends BaseJavaLocalInspectionTool {
convertJUnitConstructor(method);
}
else {
if (!javaFile.getLanguageLevel().hasEnumKeywordAndAutoboxing()) {
if (!javaFile.getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_5)) {
addMethodJavadoc(factory, method);
}
else {