Type annotations supported in Java elements
Reflection-related implementations are pending
This commit is contained in:
committed by
Denis Zharkov
parent
694af022c8
commit
31f4ff749c
+15
-8
@@ -24,8 +24,8 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.jetbrains.kotlin.load.java.structure.JavaAnnotation;
|
import org.jetbrains.kotlin.load.java.structure.JavaAnnotation;
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaAnnotationOwner;
|
import org.jetbrains.kotlin.load.java.structure.JavaAnnotationOwner;
|
||||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaAnnotationImpl;
|
import org.jetbrains.kotlin.load.java.structure.impl.JavaAnnotationImpl;
|
||||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaAnnotationOwnerImpl;
|
|
||||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaElementCollectionFromPsiArrayUtil;
|
import org.jetbrains.kotlin.load.java.structure.impl.JavaElementCollectionFromPsiArrayUtil;
|
||||||
|
import org.jetbrains.kotlin.load.java.structure.impl.JavaModifierListOwnerImpl;
|
||||||
import org.jetbrains.kotlin.name.FqName;
|
import org.jetbrains.kotlin.name.FqName;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -35,18 +35,25 @@ public class PsiBasedExternalAnnotationResolver implements ExternalAnnotationRes
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public JavaAnnotation findExternalAnnotation(@NotNull JavaAnnotationOwner owner, @NotNull FqName fqName) {
|
public JavaAnnotation findExternalAnnotation(@NotNull JavaAnnotationOwner owner, @NotNull FqName fqName) {
|
||||||
PsiAnnotation psiAnnotation = findExternalAnnotation(((JavaAnnotationOwnerImpl) owner).getPsi(), fqName);
|
if (owner instanceof JavaModifierListOwnerImpl) {
|
||||||
return psiAnnotation == null ? null : new JavaAnnotationImpl(psiAnnotation);
|
JavaModifierListOwnerImpl modifierListOwner = (JavaModifierListOwnerImpl) owner;
|
||||||
|
PsiAnnotation psiAnnotation = findExternalAnnotation(modifierListOwner.getPsi(), fqName);
|
||||||
|
return psiAnnotation == null ? null : new JavaAnnotationImpl(psiAnnotation);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<JavaAnnotation> findExternalAnnotations(@NotNull JavaAnnotationOwner owner) {
|
public Collection<JavaAnnotation> findExternalAnnotations(@NotNull JavaAnnotationOwner owner) {
|
||||||
PsiModifierListOwner psiOwner = ((JavaAnnotationOwnerImpl) owner).getPsi();
|
if (owner instanceof JavaModifierListOwnerImpl) {
|
||||||
PsiAnnotation[] annotations = ExternalAnnotationsManager.getInstance(psiOwner.getProject()).findExternalAnnotations(psiOwner);
|
PsiModifierListOwner psiOwner = ((JavaModifierListOwnerImpl) owner).getPsi();
|
||||||
return annotations == null
|
PsiAnnotation[] annotations = ExternalAnnotationsManager.getInstance(psiOwner.getProject()).findExternalAnnotations(psiOwner);
|
||||||
? Collections.<JavaAnnotation>emptyList()
|
return annotations == null
|
||||||
: JavaElementCollectionFromPsiArrayUtil.annotations(annotations);
|
? Collections.<JavaAnnotation>emptyList()
|
||||||
|
: JavaElementCollectionFromPsiArrayUtil.annotations(annotations);
|
||||||
|
}
|
||||||
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
+4
-4
@@ -16,11 +16,11 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.load.java.structure.impl;
|
package org.jetbrains.kotlin.load.java.structure.impl;
|
||||||
|
|
||||||
import com.intellij.psi.PsiModifierListOwner;
|
import com.intellij.psi.PsiAnnotationOwner;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaAnnotationOwner;
|
import org.jetbrains.kotlin.load.java.structure.JavaAnnotationOwner;
|
||||||
|
|
||||||
public interface JavaAnnotationOwnerImpl extends JavaAnnotationOwner {
|
public interface JavaAnnotationOwnerImpl extends JavaAnnotationOwner {
|
||||||
@NotNull
|
@Nullable
|
||||||
PsiModifierListOwner getPsi();
|
PsiAnnotationOwner getAnnotationOwnerPsi();
|
||||||
}
|
}
|
||||||
|
|||||||
-12
@@ -146,18 +146,6 @@ public class JavaClassImpl extends JavaClassifierImpl<PsiClass> implements JavaC
|
|||||||
return JavaElementUtil.getVisibility(this);
|
return JavaElementUtil.getVisibility(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Collection<JavaAnnotation> getAnnotations() {
|
|
||||||
return JavaElementUtil.getAnnotations(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public JavaAnnotation findAnnotation(@NotNull FqName fqName) {
|
|
||||||
return JavaElementUtil.findAnnotation(this, fqName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public JavaClassifierType getDefaultType() {
|
public JavaClassifierType getDefaultType() {
|
||||||
|
|||||||
+25
-1
@@ -16,16 +16,28 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.load.java.structure.impl;
|
package org.jetbrains.kotlin.load.java.structure.impl;
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiAnnotationOwner;
|
||||||
import com.intellij.psi.PsiClass;
|
import com.intellij.psi.PsiClass;
|
||||||
import com.intellij.psi.PsiTypeParameter;
|
import com.intellij.psi.PsiTypeParameter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.kotlin.load.java.structure.JavaAnnotation;
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaClassifier;
|
import org.jetbrains.kotlin.load.java.structure.JavaClassifier;
|
||||||
|
import org.jetbrains.kotlin.name.FqName;
|
||||||
|
|
||||||
public abstract class JavaClassifierImpl<Psi extends PsiClass> extends JavaElementImpl<Psi> implements JavaClassifier {
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public abstract class JavaClassifierImpl<Psi extends PsiClass> extends JavaElementImpl<Psi> implements JavaClassifier, JavaAnnotationOwnerImpl {
|
||||||
protected JavaClassifierImpl(@NotNull Psi psiClass) {
|
protected JavaClassifierImpl(@NotNull Psi psiClass) {
|
||||||
super(psiClass);
|
super(psiClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public PsiAnnotationOwner getAnnotationOwnerPsi() {
|
||||||
|
return getPsi().getModifierList();
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
/* package */ static JavaClassifier create(@NotNull PsiClass psiClass) {
|
/* package */ static JavaClassifier create(@NotNull PsiClass psiClass) {
|
||||||
if (psiClass instanceof PsiTypeParameter) {
|
if (psiClass instanceof PsiTypeParameter) {
|
||||||
@@ -35,4 +47,16 @@ public abstract class JavaClassifierImpl<Psi extends PsiClass> extends JavaEleme
|
|||||||
return new JavaClassImpl(psiClass);
|
return new JavaClassImpl(psiClass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Collection<JavaAnnotation> getAnnotations() {
|
||||||
|
return JavaElementUtil.getAnnotations(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public JavaAnnotation findAnnotation(@NotNull FqName fqName) {
|
||||||
|
return JavaElementUtil.findAnnotation(this, fqName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-10
@@ -16,10 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.load.java.structure.impl;
|
package org.jetbrains.kotlin.load.java.structure.impl;
|
||||||
|
|
||||||
import com.intellij.psi.PsiAnnotation;
|
import com.intellij.psi.*;
|
||||||
import com.intellij.psi.PsiModifier;
|
|
||||||
import com.intellij.psi.PsiModifierList;
|
|
||||||
import com.intellij.psi.PsiModifierListOwner;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.descriptors.Visibilities;
|
import org.jetbrains.kotlin.descriptors.Visibilities;
|
||||||
@@ -66,18 +63,18 @@ import static org.jetbrains.kotlin.load.java.structure.impl.JavaElementCollectio
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Collection<JavaAnnotation> getAnnotations(@NotNull JavaAnnotationOwnerImpl owner) {
|
public static Collection<JavaAnnotation> getAnnotations(@NotNull JavaAnnotationOwnerImpl owner) {
|
||||||
PsiModifierList modifierList = owner.getPsi().getModifierList();
|
PsiAnnotationOwner annotationOwnerPsi = owner.getAnnotationOwnerPsi();
|
||||||
if (modifierList != null) {
|
if (annotationOwnerPsi != null) {
|
||||||
return annotations(modifierList.getAnnotations());
|
return annotations(annotationOwnerPsi.getAnnotations());
|
||||||
}
|
}
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static JavaAnnotation findAnnotation(@NotNull JavaAnnotationOwnerImpl owner, @NotNull FqName fqName) {
|
public static JavaAnnotation findAnnotation(@NotNull JavaAnnotationOwnerImpl owner, @NotNull FqName fqName) {
|
||||||
PsiModifierList modifierList = owner.getPsi().getModifierList();
|
PsiAnnotationOwner annotationOwnerPsi = owner.getAnnotationOwnerPsi();
|
||||||
if (modifierList != null) {
|
if (annotationOwnerPsi != null) {
|
||||||
PsiAnnotation psiAnnotation = modifierList.findAnnotation(fqName.asString());
|
PsiAnnotation psiAnnotation = annotationOwnerPsi.findAnnotation(fqName.asString());
|
||||||
return psiAnnotation == null ? null : new JavaAnnotationImpl(psiAnnotation);
|
return psiAnnotation == null ? null : new JavaAnnotationImpl(psiAnnotation);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
+7
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.load.java.structure.impl;
|
package org.jetbrains.kotlin.load.java.structure.impl;
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiAnnotationOwner;
|
||||||
import com.intellij.psi.PsiClass;
|
import com.intellij.psi.PsiClass;
|
||||||
import com.intellij.psi.PsiMember;
|
import com.intellij.psi.PsiMember;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -35,6 +36,12 @@ public abstract class JavaMemberImpl<Psi extends PsiMember> extends JavaElementI
|
|||||||
super(psiMember);
|
super(psiMember);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public PsiAnnotationOwner getAnnotationOwnerPsi() {
|
||||||
|
return getPsi().getModifierList();
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Name getName() {
|
public Name getName() {
|
||||||
|
|||||||
+24
-1
@@ -19,10 +19,14 @@ package org.jetbrains.kotlin.load.java.structure.impl;
|
|||||||
import com.intellij.psi.*;
|
import com.intellij.psi.*;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.kotlin.load.java.structure.JavaAnnotation;
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaArrayType;
|
import org.jetbrains.kotlin.load.java.structure.JavaArrayType;
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaType;
|
import org.jetbrains.kotlin.load.java.structure.JavaType;
|
||||||
|
import org.jetbrains.kotlin.name.FqName;
|
||||||
|
|
||||||
public abstract class JavaTypeImpl<Psi extends PsiType> implements JavaType {
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public abstract class JavaTypeImpl<Psi extends PsiType> implements JavaType, JavaAnnotationOwnerImpl {
|
||||||
private final Psi psiType;
|
private final Psi psiType;
|
||||||
|
|
||||||
public JavaTypeImpl(@NotNull Psi psiType) {
|
public JavaTypeImpl(@NotNull Psi psiType) {
|
||||||
@@ -34,6 +38,12 @@ public abstract class JavaTypeImpl<Psi extends PsiType> implements JavaType {
|
|||||||
return psiType;
|
return psiType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public PsiAnnotationOwner getAnnotationOwnerPsi() {
|
||||||
|
return getPsi();
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JavaTypeImpl<?> create(@NotNull PsiType psiType) {
|
public static JavaTypeImpl<?> create(@NotNull PsiType psiType) {
|
||||||
return psiType.accept(new PsiTypeVisitor<JavaTypeImpl<?>>() {
|
return psiType.accept(new PsiTypeVisitor<JavaTypeImpl<?>>() {
|
||||||
@@ -75,6 +85,19 @@ public abstract class JavaTypeImpl<Psi extends PsiType> implements JavaType {
|
|||||||
return new JavaArrayTypeImpl(getPsi().createArrayType());
|
return new JavaArrayTypeImpl(getPsi().createArrayType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Collection<JavaAnnotation> getAnnotations() {
|
||||||
|
return JavaElementUtil.getAnnotations(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public JavaAnnotation findAnnotation(@NotNull FqName fqName) {
|
||||||
|
return JavaElementUtil.findAnnotation(this, fqName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return getPsi().hashCode();
|
return getPsi().hashCode();
|
||||||
|
|||||||
+32
-1
@@ -16,10 +16,13 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.load.java.structure.impl;
|
package org.jetbrains.kotlin.load.java.structure.impl;
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiAnnotationOwner;
|
||||||
import com.intellij.psi.PsiParameter;
|
import com.intellij.psi.PsiParameter;
|
||||||
import com.intellij.psi.impl.compiled.ClsParameterImpl;
|
import com.intellij.psi.impl.compiled.ClsParameterImpl;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.kotlin.descriptors.Visibilities;
|
||||||
|
import org.jetbrains.kotlin.descriptors.Visibility;
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaAnnotation;
|
import org.jetbrains.kotlin.load.java.structure.JavaAnnotation;
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaType;
|
import org.jetbrains.kotlin.load.java.structure.JavaType;
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaValueParameter;
|
import org.jetbrains.kotlin.load.java.structure.JavaValueParameter;
|
||||||
@@ -28,11 +31,39 @@ import org.jetbrains.kotlin.name.Name;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
public class JavaValueParameterImpl extends JavaElementImpl<PsiParameter> implements JavaValueParameter, JavaAnnotationOwnerImpl {
|
public class JavaValueParameterImpl extends JavaElementImpl<PsiParameter>
|
||||||
|
implements JavaValueParameter, JavaAnnotationOwnerImpl, JavaModifierListOwnerImpl {
|
||||||
public JavaValueParameterImpl(@NotNull PsiParameter psiParameter) {
|
public JavaValueParameterImpl(@NotNull PsiParameter psiParameter) {
|
||||||
super(psiParameter);
|
super(psiParameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public PsiAnnotationOwner getAnnotationOwnerPsi() {
|
||||||
|
return getPsi().getModifierList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAbstract() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isStatic() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFinal() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Visibility getVisibility() {
|
||||||
|
return Visibilities.LOCAL;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<JavaAnnotation> getAnnotations() {
|
public Collection<JavaAnnotation> getAnnotations() {
|
||||||
|
|||||||
+1
-1
@@ -23,7 +23,7 @@ import org.jetbrains.annotations.ReadOnly;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface JavaClassifierType extends JavaType {
|
public interface JavaClassifierType extends JavaType, JavaAnnotationOwner {
|
||||||
@Nullable
|
@Nullable
|
||||||
JavaClassifier getClassifier();
|
JavaClassifier getClassifier();
|
||||||
|
|
||||||
|
|||||||
+10
-4
@@ -16,10 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.load.java.structure.reflect
|
package org.jetbrains.kotlin.load.java.structure.reflect
|
||||||
|
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaClassifier
|
import org.jetbrains.kotlin.load.java.structure.*
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaClassifierType
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaType
|
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaTypeSubstitutor
|
|
||||||
import java.lang.reflect.ParameterizedType
|
import java.lang.reflect.ParameterizedType
|
||||||
import java.lang.reflect.Type
|
import java.lang.reflect.Type
|
||||||
import java.lang.reflect.TypeVariable
|
import java.lang.reflect.TypeVariable
|
||||||
@@ -48,4 +46,12 @@ public class ReflectJavaClassifierType(public override val type: Type) : Reflect
|
|||||||
override fun getTypeArguments(): List<JavaType> {
|
override fun getTypeArguments(): List<JavaType> {
|
||||||
return (type as? ParameterizedType)?.getActualTypeArguments()?.map { ReflectJavaType.create(it) } ?: listOf()
|
return (type as? ParameterizedType)?.getActualTypeArguments()?.map { ReflectJavaType.create(it) } ?: listOf()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getAnnotations(): Collection<JavaAnnotation> {
|
||||||
|
return emptyList() // TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun findAnnotation(fqName: FqName): JavaAnnotation? {
|
||||||
|
return null // TODO
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user