From 07042165fa149e5a26ed1c7f9be9e9b27ccb06df Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 22 Apr 2016 17:12:06 +0200 Subject: [PATCH] [java] introduces PsiType.annotate() --- .../src/com/intellij/psi/PsiArrayType.java | 24 +++++++++++-------- .../src/com/intellij/psi/PsiEllipsisType.java | 21 +++++++++------- .../com/intellij/psi/PsiPrimitiveType.java | 22 ++++++++++------- .../src/com/intellij/psi/PsiType.java | 5 ++++ .../src/com/intellij/psi/PsiWildcardType.java | 17 ++++++------- .../impl/source/PsiClassReferenceType.java | 14 +++++++---- .../impl/source/PsiImmediateClassType.java | 19 ++++++++++----- 7 files changed, 77 insertions(+), 45 deletions(-) diff --git a/java/java-psi-api/src/com/intellij/psi/PsiArrayType.java b/java/java-psi-api/src/com/intellij/psi/PsiArrayType.java index 71292309cfc4..d8f7e29c11b7 100644 --- a/java/java-psi-api/src/com/intellij/psi/PsiArrayType.java +++ b/java/java-psi-api/src/com/intellij/psi/PsiArrayType.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -26,24 +26,26 @@ import org.jetbrains.annotations.NotNull; public class PsiArrayType extends PsiType.Stub { private final PsiType myComponentType; - /** - * Creates an array type with the specified component type. - * - * @param componentType the type of the array component. - */ public PsiArrayType(@NotNull PsiType componentType) { - this(componentType, PsiAnnotation.EMPTY_ARRAY); + this(componentType, TypeAnnotationProvider.EMPTY); } public PsiArrayType(@NotNull PsiType componentType, @NotNull PsiAnnotation[] annotations) { super(annotations); myComponentType = componentType; } - public PsiArrayType(@NotNull PsiType componentType, @NotNull TypeAnnotationProvider annotations) { - super(annotations); + + public PsiArrayType(@NotNull PsiType componentType, @NotNull TypeAnnotationProvider provider) { + super(provider); myComponentType = componentType; } + @NotNull + @Override + public PsiArrayType annotate(@NotNull TypeAnnotationProvider provider) { + return new PsiArrayType(myComponentType, provider); + } + @NotNull @Override public String getPresentableText() { @@ -117,13 +119,15 @@ public class PsiArrayType extends PsiType.Stub { return myComponentType; } + @Override public boolean equals(Object obj) { return obj instanceof PsiArrayType && (this instanceof PsiEllipsisType == obj instanceof PsiEllipsisType) && myComponentType.equals(((PsiArrayType)obj).getComponentType()); } + @Override public int hashCode() { return myComponentType.hashCode() * 3; } -} +} \ No newline at end of file diff --git a/java/java-psi-api/src/com/intellij/psi/PsiEllipsisType.java b/java/java-psi-api/src/com/intellij/psi/PsiEllipsisType.java index b00ece6a7798..639bbeb46211 100644 --- a/java/java-psi-api/src/com/intellij/psi/PsiEllipsisType.java +++ b/java/java-psi-api/src/com/intellij/psi/PsiEllipsisType.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -23,11 +23,6 @@ import org.jetbrains.annotations.NotNull; * @author ven */ public class PsiEllipsisType extends PsiArrayType { - /** - * Creates an ellipsis type instance with the specified component type. - * - * @param componentType the type of the varargs array component. - */ public PsiEllipsisType(@NotNull PsiType componentType) { super(componentType); } @@ -35,8 +30,15 @@ public class PsiEllipsisType extends PsiArrayType { public PsiEllipsisType(@NotNull PsiType componentType, @NotNull PsiAnnotation[] annotations) { super(componentType, annotations); } - public PsiEllipsisType(@NotNull PsiType componentType, @NotNull TypeAnnotationProvider annotations) { - super(componentType, annotations); + + public PsiEllipsisType(@NotNull PsiType componentType, @NotNull TypeAnnotationProvider provider) { + super(componentType, provider); + } + + @NotNull + @Override + public PsiEllipsisType annotate(@NotNull TypeAnnotationProvider provider) { + return new PsiEllipsisType(getComponentType(), provider); } @NotNull @@ -82,7 +84,8 @@ public class PsiEllipsisType extends PsiArrayType { return visitor.visitEllipsisType(this); } + @Override public int hashCode() { return super.hashCode() * 5; } -} +} \ No newline at end of file diff --git a/java/java-psi-api/src/com/intellij/psi/PsiPrimitiveType.java b/java/java-psi-api/src/com/intellij/psi/PsiPrimitiveType.java index 82854ddffb85..231744cdddef 100644 --- a/java/java-psi-api/src/com/intellij/psi/PsiPrimitiveType.java +++ b/java/java-psi-api/src/com/intellij/psi/PsiPrimitiveType.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 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,7 +19,6 @@ import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.util.PsiUtil; import gnu.trove.THashMap; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -36,23 +35,30 @@ public class PsiPrimitiveType extends PsiType.Stub { private final String myName; - PsiPrimitiveType(@NonNls @NotNull String name, @NonNls String boxedName) { - this(name, PsiAnnotation.EMPTY_ARRAY); + PsiPrimitiveType(@NotNull String name, String boxedName) { + this(name, TypeAnnotationProvider.EMPTY); if (boxedName != null) { ourQNameToUnboxed.put(boxedName, this); ourUnboxedToQName.put(this, boxedName); } } - public PsiPrimitiveType(@NonNls @NotNull String name, @NotNull PsiAnnotation[] annotations) { + public PsiPrimitiveType(@NotNull String name, @NotNull PsiAnnotation[] annotations) { super(annotations); myName = name; } - public PsiPrimitiveType(@NonNls @NotNull String name, @NotNull TypeAnnotationProvider annotations) { - super(annotations); + + public PsiPrimitiveType(@NotNull String name, @NotNull TypeAnnotationProvider provider) { + super(provider); myName = name; } + @NotNull + @Override + public PsiPrimitiveType annotate(@NotNull TypeAnnotationProvider provider) { + return new PsiPrimitiveType(myName, provider); + } + @NotNull @Override public String getPresentableText() { @@ -187,4 +193,4 @@ public class PsiPrimitiveType extends PsiType.Stub { public boolean equals(Object obj) { return obj instanceof PsiPrimitiveType && myName.equals(((PsiPrimitiveType)obj).myName); } -} +} \ No newline at end of file diff --git a/java/java-psi-api/src/com/intellij/psi/PsiType.java b/java/java-psi-api/src/com/intellij/psi/PsiType.java index 3c59fd2633e9..2b8f63b4ddbc 100644 --- a/java/java-psi-api/src/com/intellij/psi/PsiType.java +++ b/java/java-psi-api/src/com/intellij/psi/PsiType.java @@ -72,6 +72,11 @@ public abstract class PsiType implements PsiAnnotationOwner { myAnnotationProvider = annotations; } + @NotNull + public PsiType annotate(@NotNull TypeAnnotationProvider provider) { + throw new UnsupportedOperationException("Not implemented for " + getClass()); + } + /** * Creates array type with this type as a component. */ diff --git a/java/java-psi-api/src/com/intellij/psi/PsiWildcardType.java b/java/java-psi-api/src/com/intellij/psi/PsiWildcardType.java index f5c199de6642..76d6914ed612 100644 --- a/java/java-psi-api/src/com/intellij/psi/PsiWildcardType.java +++ b/java/java-psi-api/src/com/intellij/psi/PsiWildcardType.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -31,7 +31,7 @@ public class PsiWildcardType extends PsiType.Stub { public static final String EXTENDS_PREFIX = "? extends "; public static final String SUPER_PREFIX = "? super "; - private static final Logger LOG = Logger.getInstance("#com.intellij.psi.PsiWildcardType"); + private static final Logger LOG = Logger.getInstance(PsiWildcardType.class); private static final Key UNBOUNDED_WILDCARD = new Key("UNBOUNDED_WILDCARD"); private final PsiManager myManager; @@ -39,14 +39,14 @@ public class PsiWildcardType extends PsiType.Stub { private final PsiType myBound; private PsiWildcardType(@NotNull PsiManager manager, boolean isExtending, @Nullable PsiType bound) { - super(PsiAnnotation.EMPTY_ARRAY); + super(TypeAnnotationProvider.EMPTY); myManager = manager; myIsExtending = isExtending; myBound = bound; } - private PsiWildcardType(@NotNull PsiWildcardType type, @NotNull TypeAnnotationProvider annotations) { - super(annotations); + private PsiWildcardType(@NotNull PsiWildcardType type, @NotNull TypeAnnotationProvider provider) { + super(provider); myManager = type.myManager; myIsExtending = type.myIsExtending; myBound = type.myBound; @@ -87,8 +87,9 @@ public class PsiWildcardType extends PsiType.Stub { } @NotNull - public PsiWildcardType annotate(@NotNull final TypeAnnotationProvider annotations) { - return new PsiWildcardType(this, annotations); + @Override + public PsiWildcardType annotate(@NotNull TypeAnnotationProvider provider) { + return new PsiWildcardType(this, provider); } @NotNull @@ -261,4 +262,4 @@ public class PsiWildcardType extends PsiType.Stub { public PsiType getSuperBound() { return myBound == null || myIsExtending ? NULL : myBound; } -} +} \ No newline at end of file diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiClassReferenceType.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiClassReferenceType.java index c4cf9db93b6c..a03c7956aca1 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiClassReferenceType.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiClassReferenceType.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -42,8 +42,8 @@ public class PsiClassReferenceType extends PsiClassType.Stub { myReference = reference; } - public PsiClassReferenceType(@NotNull PsiJavaCodeReferenceElement reference, LanguageLevel level, @NotNull TypeAnnotationProvider annotations) { - super(level, annotations); + public PsiClassReferenceType(@NotNull PsiJavaCodeReferenceElement reference, LanguageLevel level, @NotNull TypeAnnotationProvider provider) { + super(level, provider); myReference = reference; } @@ -58,6 +58,12 @@ public class PsiClassReferenceType extends PsiClassType.Stub { return result == null ? PsiAnnotation.EMPTY_ARRAY : result.toArray(new PsiAnnotation[result.size()]); } + @NotNull + @Override + public PsiClassReferenceType annotate(@NotNull TypeAnnotationProvider provider) { + return new PsiClassReferenceType(myReference, myLanguageLevel, provider); + } + @Override public boolean isValid() { return myReference.isValid(); @@ -222,4 +228,4 @@ public class PsiClassReferenceType extends PsiClassType.Stub { public PsiJavaCodeReferenceElement getReference() { return myReference; } -} +} \ No newline at end of file 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 15823d067a90..9c26c187b6b3 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 @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -79,11 +79,11 @@ public class PsiImmediateClassType extends PsiClassType.Stub { }; public PsiImmediateClassType(@NotNull PsiClass aClass, @NotNull PsiSubstitutor substitutor) { - this(aClass, substitutor, null, PsiAnnotation.EMPTY_ARRAY); + this(aClass, substitutor, null, TypeAnnotationProvider.EMPTY); } public PsiImmediateClassType(@NotNull PsiClass aClass, @NotNull PsiSubstitutor substitutor, @Nullable LanguageLevel level) { - this(aClass, substitutor, level, PsiAnnotation.EMPTY_ARRAY); + this(aClass, substitutor, level, TypeAnnotationProvider.EMPTY); } public PsiImmediateClassType(@NotNull PsiClass aClass, @@ -96,17 +96,24 @@ public class PsiImmediateClassType extends PsiClassType.Stub { mySubstitutor = substitutor; assert substitutor.isValid(); } + public PsiImmediateClassType(@NotNull PsiClass aClass, @NotNull PsiSubstitutor substitutor, @Nullable LanguageLevel level, - @NotNull TypeAnnotationProvider annotations) { - super(level, annotations); + @NotNull TypeAnnotationProvider provider) { + super(level, provider); myClass = aClass; myManager = aClass.getManager(); mySubstitutor = substitutor; assert substitutor.isValid(); } + @NotNull + @Override + public PsiImmediateClassType annotate(@NotNull TypeAnnotationProvider provider) { + return new PsiImmediateClassType(myClass, mySubstitutor, myLanguageLevel, provider); + } + @Override public PsiClass resolve() { return myClass; @@ -313,4 +320,4 @@ public class PsiImmediateClassType extends PsiClassType.Stub { public PsiClassType setLanguageLevel(@NotNull LanguageLevel level) { return level.equals(myLanguageLevel) ? this : new PsiImmediateClassType(myClass, mySubstitutor, level, getAnnotationProvider()); } -} +} \ No newline at end of file