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.JavaAnnotationOwner;
|
||||
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.JavaModifierListOwnerImpl;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -35,18 +35,25 @@ public class PsiBasedExternalAnnotationResolver implements ExternalAnnotationRes
|
||||
@Nullable
|
||||
@Override
|
||||
public JavaAnnotation findExternalAnnotation(@NotNull JavaAnnotationOwner owner, @NotNull FqName fqName) {
|
||||
PsiAnnotation psiAnnotation = findExternalAnnotation(((JavaAnnotationOwnerImpl) owner).getPsi(), fqName);
|
||||
return psiAnnotation == null ? null : new JavaAnnotationImpl(psiAnnotation);
|
||||
if (owner instanceof JavaModifierListOwnerImpl) {
|
||||
JavaModifierListOwnerImpl modifierListOwner = (JavaModifierListOwnerImpl) owner;
|
||||
PsiAnnotation psiAnnotation = findExternalAnnotation(modifierListOwner.getPsi(), fqName);
|
||||
return psiAnnotation == null ? null : new JavaAnnotationImpl(psiAnnotation);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<JavaAnnotation> findExternalAnnotations(@NotNull JavaAnnotationOwner owner) {
|
||||
PsiModifierListOwner psiOwner = ((JavaAnnotationOwnerImpl) owner).getPsi();
|
||||
PsiAnnotation[] annotations = ExternalAnnotationsManager.getInstance(psiOwner.getProject()).findExternalAnnotations(psiOwner);
|
||||
return annotations == null
|
||||
? Collections.<JavaAnnotation>emptyList()
|
||||
: JavaElementCollectionFromPsiArrayUtil.annotations(annotations);
|
||||
if (owner instanceof JavaModifierListOwnerImpl) {
|
||||
PsiModifierListOwner psiOwner = ((JavaModifierListOwnerImpl) owner).getPsi();
|
||||
PsiAnnotation[] annotations = ExternalAnnotationsManager.getInstance(psiOwner.getProject()).findExternalAnnotations(psiOwner);
|
||||
return annotations == null
|
||||
? Collections.<JavaAnnotation>emptyList()
|
||||
: JavaElementCollectionFromPsiArrayUtil.annotations(annotations);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+4
-4
@@ -16,11 +16,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.load.java.structure.impl;
|
||||
|
||||
import com.intellij.psi.PsiModifierListOwner;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import com.intellij.psi.PsiAnnotationOwner;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaAnnotationOwner;
|
||||
|
||||
public interface JavaAnnotationOwnerImpl extends JavaAnnotationOwner {
|
||||
@NotNull
|
||||
PsiModifierListOwner getPsi();
|
||||
@Nullable
|
||||
PsiAnnotationOwner getAnnotationOwnerPsi();
|
||||
}
|
||||
|
||||
-12
@@ -146,18 +146,6 @@ public class JavaClassImpl extends JavaClassifierImpl<PsiClass> implements JavaC
|
||||
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
|
||||
@NotNull
|
||||
public JavaClassifierType getDefaultType() {
|
||||
|
||||
+25
-1
@@ -16,16 +16,28 @@
|
||||
|
||||
package org.jetbrains.kotlin.load.java.structure.impl;
|
||||
|
||||
import com.intellij.psi.PsiAnnotationOwner;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiTypeParameter;
|
||||
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.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) {
|
||||
super(psiClass);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiAnnotationOwner getAnnotationOwnerPsi() {
|
||||
return getPsi().getModifierList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
/* package */ static JavaClassifier create(@NotNull PsiClass psiClass) {
|
||||
if (psiClass instanceof PsiTypeParameter) {
|
||||
@@ -35,4 +47,16 @@ public abstract class JavaClassifierImpl<Psi extends PsiClass> extends JavaEleme
|
||||
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;
|
||||
|
||||
import com.intellij.psi.PsiAnnotation;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.psi.PsiModifierList;
|
||||
import com.intellij.psi.PsiModifierListOwner;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities;
|
||||
@@ -66,18 +63,18 @@ import static org.jetbrains.kotlin.load.java.structure.impl.JavaElementCollectio
|
||||
|
||||
@NotNull
|
||||
public static Collection<JavaAnnotation> getAnnotations(@NotNull JavaAnnotationOwnerImpl owner) {
|
||||
PsiModifierList modifierList = owner.getPsi().getModifierList();
|
||||
if (modifierList != null) {
|
||||
return annotations(modifierList.getAnnotations());
|
||||
PsiAnnotationOwner annotationOwnerPsi = owner.getAnnotationOwnerPsi();
|
||||
if (annotationOwnerPsi != null) {
|
||||
return annotations(annotationOwnerPsi.getAnnotations());
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JavaAnnotation findAnnotation(@NotNull JavaAnnotationOwnerImpl owner, @NotNull FqName fqName) {
|
||||
PsiModifierList modifierList = owner.getPsi().getModifierList();
|
||||
if (modifierList != null) {
|
||||
PsiAnnotation psiAnnotation = modifierList.findAnnotation(fqName.asString());
|
||||
PsiAnnotationOwner annotationOwnerPsi = owner.getAnnotationOwnerPsi();
|
||||
if (annotationOwnerPsi != null) {
|
||||
PsiAnnotation psiAnnotation = annotationOwnerPsi.findAnnotation(fqName.asString());
|
||||
return psiAnnotation == null ? null : new JavaAnnotationImpl(psiAnnotation);
|
||||
}
|
||||
return null;
|
||||
|
||||
+7
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.load.java.structure.impl;
|
||||
|
||||
import com.intellij.psi.PsiAnnotationOwner;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMember;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -35,6 +36,12 @@ public abstract class JavaMemberImpl<Psi extends PsiMember> extends JavaElementI
|
||||
super(psiMember);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiAnnotationOwner getAnnotationOwnerPsi() {
|
||||
return getPsi().getModifierList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Name getName() {
|
||||
|
||||
+24
-1
@@ -19,10 +19,14 @@ package org.jetbrains.kotlin.load.java.structure.impl;
|
||||
import com.intellij.psi.*;
|
||||
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.JavaArrayType;
|
||||
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;
|
||||
|
||||
public JavaTypeImpl(@NotNull Psi psiType) {
|
||||
@@ -34,6 +38,12 @@ public abstract class JavaTypeImpl<Psi extends PsiType> implements JavaType {
|
||||
return psiType;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiAnnotationOwner getAnnotationOwnerPsi() {
|
||||
return getPsi();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JavaTypeImpl<?> create(@NotNull PsiType psiType) {
|
||||
return psiType.accept(new PsiTypeVisitor<JavaTypeImpl<?>>() {
|
||||
@@ -75,6 +85,19 @@ public abstract class JavaTypeImpl<Psi extends PsiType> implements JavaType {
|
||||
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
|
||||
public int hashCode() {
|
||||
return getPsi().hashCode();
|
||||
|
||||
+32
-1
@@ -16,10 +16,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.load.java.structure.impl;
|
||||
|
||||
import com.intellij.psi.PsiAnnotationOwner;
|
||||
import com.intellij.psi.PsiParameter;
|
||||
import com.intellij.psi.impl.compiled.ClsParameterImpl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
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.JavaType;
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaValueParameter;
|
||||
@@ -28,11 +31,39 @@ import org.jetbrains.kotlin.name.Name;
|
||||
|
||||
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) {
|
||||
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
|
||||
@Override
|
||||
public Collection<JavaAnnotation> getAnnotations() {
|
||||
|
||||
Reference in New Issue
Block a user