From 00dc5866e68c7ca27a07b838592eab52d48d43d5 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 15 Mar 2013 15:49:06 +0100 Subject: [PATCH] A parameter is actually nullable --- .../com/intellij/psi/PsiElementFactory.java | 21 ++++++++++---- .../psi/impl/PsiElementFactoryImpl.java | 16 +++++------ .../impl/source/PsiImmediateClassType.java | 28 +++++++++++-------- 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/java/java-psi-api/src/com/intellij/psi/PsiElementFactory.java b/java/java-psi-api/src/com/intellij/psi/PsiElementFactory.java index 27eeb0a2663f..3838dc1ef1ff 100644 --- a/java/java-psi-api/src/com/intellij/psi/PsiElementFactory.java +++ b/java/java-psi-api/src/com/intellij/psi/PsiElementFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -43,7 +43,7 @@ public interface PsiElementFactory extends PsiJavaParserFacade, JVMElementFactor return ServiceManager.getService(project, PsiElementFactory.class); } } - + /** * Creates an empty class with the specified name. * @@ -164,12 +164,21 @@ public interface PsiElementFactory extends PsiJavaParserFacade, JVMElementFactor */ @NotNull PsiClassType createType(@NotNull PsiClass resolve, @NotNull PsiSubstitutor substitutor); - /* - additional languageLevel parameter to memorize language level for allowing/prohibiting boxing/unboxing + /** + * Creates a class type for the specified class, using the specified substitutor + * to replace generic type parameters on the class. + * + * @param resolve the class for which the class type is created. + * @param substitutor the substitutor to use. + * @param languageLevel to memorize language level for allowing/prohibiting boxing/unboxing. + * @return the class type instance. */ - @NotNull PsiClassType createType(@NotNull PsiClass resolve, @NotNull PsiSubstitutor substitutor, @NotNull LanguageLevel languageLevel); + @NotNull PsiClassType createType(@NotNull PsiClass resolve, @NotNull PsiSubstitutor substitutor, @Nullable LanguageLevel languageLevel); - @NotNull PsiClassType createType(@NotNull PsiClass resolve, @NotNull PsiSubstitutor substitutor, @NotNull LanguageLevel languageLevel, @NotNull PsiAnnotation[] annotations); + @NotNull PsiClassType createType(@NotNull PsiClass resolve, + @NotNull PsiSubstitutor substitutor, + @Nullable LanguageLevel languageLevel, + @NotNull PsiAnnotation[] annotations); /** * Creates a class type for the specified reference pointing to a class. diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java index d8c271f1818e..f7a6d2ed0b24 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -89,24 +89,22 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps @NotNull @Override - public PsiClassType createType(@NotNull final PsiClass resolve, @NotNull final PsiSubstitutor substitutor) { + public PsiClassType createType(@NotNull PsiClass resolve, @NotNull PsiSubstitutor substitutor) { return new PsiImmediateClassType(resolve, substitutor); } @NotNull @Override - public PsiClassType createType(@NotNull final PsiClass resolve, - @NotNull final PsiSubstitutor substitutor, - @NotNull final LanguageLevel languageLevel) { + public PsiClassType createType(@NotNull PsiClass resolve, @NotNull PsiSubstitutor substitutor, @Nullable LanguageLevel languageLevel) { return new PsiImmediateClassType(resolve, substitutor, languageLevel); } @NotNull @Override - public PsiClassType createType(@NotNull final PsiClass resolve, - @NotNull final PsiSubstitutor substitutor, - @NotNull final LanguageLevel languageLevel, - @NotNull final PsiAnnotation[] annotations) { + public PsiClassType createType(@NotNull PsiClass resolve, + @NotNull PsiSubstitutor substitutor, + @Nullable LanguageLevel languageLevel, + @NotNull PsiAnnotation[] annotations) { return new PsiImmediateClassType(resolve, substitutor, languageLevel, annotations); } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImmediateClassType.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImmediateClassType.java index 5844bd796ae5..aca43a457751 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImmediateClassType.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiImmediateClassType.java @@ -21,6 +21,7 @@ import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.util.PsiUtil; import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -74,15 +75,18 @@ public class PsiImmediateClassType extends PsiClassType { }; public PsiImmediateClassType(@NotNull PsiClass aClass, @NotNull PsiSubstitutor substitutor) { - this (aClass, substitutor, null); + this(aClass, substitutor, null, PsiAnnotation.EMPTY_ARRAY); } - public PsiImmediateClassType(@NotNull PsiClass aClass, @NotNull PsiSubstitutor substitutor, final LanguageLevel languageLevel) { - this(aClass, substitutor,languageLevel, PsiAnnotation.EMPTY_ARRAY); + public PsiImmediateClassType(@NotNull PsiClass aClass, @NotNull PsiSubstitutor substitutor, @Nullable LanguageLevel languageLevel) { + this(aClass, substitutor, languageLevel, PsiAnnotation.EMPTY_ARRAY); } - public PsiImmediateClassType(@NotNull PsiClass aClass, @NotNull PsiSubstitutor substitutor, LanguageLevel languageLevel, @NotNull PsiAnnotation[] annotations) { - super(languageLevel,annotations); + public PsiImmediateClassType(@NotNull PsiClass aClass, + @NotNull PsiSubstitutor substitutor, + @Nullable LanguageLevel languageLevel, + @NotNull PsiAnnotation[] annotations) { + super(languageLevel, annotations); myClass = aClass; myManager = aClass.getManager(); mySubstitutor = substitutor; @@ -131,7 +135,7 @@ public class PsiImmediateClassType extends PsiClassType { @Override public String getPresentableText() { if (myPresentableText == null) { - final StringBuilder buffer = new StringBuilder(); + StringBuilder buffer = new StringBuilder(); buildText(myClass, mySubstitutor, buffer, false, false); myPresentableText = buffer.toString(); } @@ -142,7 +146,7 @@ public class PsiImmediateClassType extends PsiClassType { public String getCanonicalText() { if (myCanonicalText == null) { assert mySubstitutor.isValid(); - final StringBuilder buffer = new StringBuilder(); + StringBuilder buffer = new StringBuilder(); buildText(myClass, mySubstitutor, buffer, true, false); myCanonicalText = buffer.toString(); } @@ -152,7 +156,7 @@ public class PsiImmediateClassType extends PsiClassType { @Override public String getInternalCanonicalText() { if (myInternalCanonicalText == null) { - final StringBuilder buffer = new StringBuilder(); + StringBuilder buffer = new StringBuilder(); buildText(myClass, mySubstitutor, buffer, true, true); myInternalCanonicalText = buffer.toString(); } @@ -173,6 +177,11 @@ public class PsiImmediateClassType extends PsiClassType { } return; } + + if (canonical == internal) { + buffer.append(getAnnotationsTextPrefix()); + } + PsiClass enclosingClass = null; if (!aClass.hasModifierProperty(PsiModifier.STATIC)) { final PsiElement parent = aClass.getParent(); @@ -180,9 +189,6 @@ public class PsiImmediateClassType extends PsiClassType { enclosingClass = (PsiClass)parent; } } - if (canonical == internal) { - buffer.append(getAnnotationsTextPrefix()); - } if (enclosingClass != null) { buildText(enclosingClass, substitutor, buffer, canonical, false); buffer.append('.');