mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] introduces PsiType.annotate()
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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<PsiWildcardType> UNBOUNDED_WILDCARD = new Key<PsiWildcardType>("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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user