J2K JavaClassImpl: convert code
This commit is contained in:
+75
-148
@@ -14,159 +14,86 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.load.java.structure.impl;
|
package org.jetbrains.kotlin.load.java.structure.impl
|
||||||
|
|
||||||
import com.intellij.psi.*;
|
import com.intellij.psi.PsiClass
|
||||||
import kotlin.collections.ArraysKt;
|
import com.intellij.psi.PsiTypeParameter
|
||||||
import kotlin.collections.CollectionsKt;
|
import org.jetbrains.kotlin.asJava.KtLightClassMarker
|
||||||
import kotlin.jvm.functions.Function1;
|
import org.jetbrains.kotlin.descriptors.Visibility
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.kotlin.load.java.structure.*
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.asJava.KtLightClassMarker;
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.descriptors.Visibility;
|
import org.jetbrains.kotlin.name.SpecialNames
|
||||||
import org.jetbrains.kotlin.load.java.structure.*;
|
|
||||||
import org.jetbrains.kotlin.name.FqName;
|
|
||||||
import org.jetbrains.kotlin.name.Name;
|
|
||||||
import org.jetbrains.kotlin.name.SpecialNames;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
class JavaClassImpl(psiClass: PsiClass) : JavaClassifierImpl<PsiClass>(psiClass), JavaClass, JavaAnnotationOwnerImpl, JavaModifierListOwnerImpl {
|
||||||
import java.util.List;
|
init {
|
||||||
|
assert(psiClass !is PsiTypeParameter) { "PsiTypeParameter should be wrapped in JavaTypeParameter, not JavaClass: use JavaClassifier.create()" }
|
||||||
import static org.jetbrains.kotlin.load.java.structure.impl.JavaElementCollectionFromPsiArrayUtil.*;
|
|
||||||
|
|
||||||
public class JavaClassImpl extends JavaClassifierImpl<PsiClass> implements JavaClass, JavaAnnotationOwnerImpl, JavaModifierListOwnerImpl {
|
|
||||||
public JavaClassImpl(@NotNull PsiClass psiClass) {
|
|
||||||
super(psiClass);
|
|
||||||
assert !(psiClass instanceof PsiTypeParameter)
|
|
||||||
: "PsiTypeParameter should be wrapped in JavaTypeParameter, not JavaClass: use JavaClassifier.create()";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override val innerClasses: Collection<JavaClass>
|
||||||
@NotNull
|
get() = classes(psi.innerClasses)
|
||||||
public Collection<JavaClass> getInnerClasses() {
|
|
||||||
return classes(getPsi().getInnerClasses());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
override val fqName: FqName?
|
||||||
@Nullable
|
get() {
|
||||||
public FqName getFqName() {
|
val qualifiedName = psi.qualifiedName
|
||||||
String qualifiedName = getPsi().getQualifiedName();
|
return if (qualifiedName == null) null else FqName(qualifiedName)
|
||||||
return qualifiedName == null ? null : new FqName(qualifiedName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Name getName() {
|
|
||||||
return SpecialNames.safeIdentifier(getPsi().getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isInterface() {
|
|
||||||
return getPsi().isInterface();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAnnotationType() {
|
|
||||||
return getPsi().isAnnotationType();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEnum() {
|
|
||||||
return getPsi().isEnum();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public JavaClassImpl getOuterClass() {
|
|
||||||
PsiClass outer = getPsi().getContainingClass();
|
|
||||||
return outer == null ? null : new JavaClassImpl(outer);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public List<JavaTypeParameter> getTypeParameters() {
|
|
||||||
return typeParameters(getPsi().getTypeParameters());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public Collection<JavaClassifierType> getSupertypes() {
|
|
||||||
return classifierTypes(getPsi().getSuperTypes());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public Collection<JavaMethod> getMethods() {
|
|
||||||
// We apply distinct here because PsiClass#getMethods() can return duplicate PSI methods, for example in Lombok (see KT-11778)
|
|
||||||
return CollectionsKt.distinct(methods(ArraysKt.filter(getPsi().getMethods(), new Function1<PsiMethod, Boolean>() {
|
|
||||||
@Override
|
|
||||||
public Boolean invoke(PsiMethod method) {
|
|
||||||
// Return type seems to be null for example for the 'clone' Groovy method generated by @AutoClone (see EA-73795)
|
|
||||||
return !method.isConstructor() && method.getReturnType() != null;
|
|
||||||
}
|
|
||||||
})));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public Collection<JavaField> getFields() {
|
|
||||||
// ex. Android plugin generates LightFields for resources started from '.' (.DS_Store file etc)
|
|
||||||
return fields(ArraysKt.filter(getPsi().getFields(), new Function1<PsiField, Boolean>() {
|
|
||||||
@Override
|
|
||||||
public Boolean invoke(PsiField field) {
|
|
||||||
String name = field.getName();
|
|
||||||
return name != null && Name.isValidIdentifier(name);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public Collection<JavaConstructor> getConstructors() {
|
|
||||||
return constructors(ArraysKt.filter(getPsi().getConstructors(), new Function1<PsiMethod, Boolean>() {
|
|
||||||
@Override
|
|
||||||
public Boolean invoke(PsiMethod method) {
|
|
||||||
// See for example org.jetbrains.plugins.scala.lang.psi.light.ScFunctionWrapper,
|
|
||||||
// which is present in getConstructors(), but its isConstructor() returns false
|
|
||||||
return method.isConstructor();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAbstract() {
|
|
||||||
return JavaElementUtil.isAbstract(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isStatic() {
|
|
||||||
return JavaElementUtil.isStatic(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isFinal() {
|
|
||||||
return JavaElementUtil.isFinal(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Visibility getVisibility() {
|
|
||||||
return JavaElementUtil.getVisibility(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public LightClassOriginKind getLightClassOriginKind() {
|
|
||||||
PsiClass psiClass = getPsi();
|
|
||||||
if (psiClass instanceof KtLightClassMarker) {
|
|
||||||
return ((KtLightClassMarker) psiClass).getOriginKind();
|
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
override val name: Name
|
||||||
@Override
|
get() = SpecialNames.safeIdentifier(psi.name)
|
||||||
public PsiAnnotationOwner getAnnotationOwnerPsi() {
|
|
||||||
return getPsi().getModifierList();
|
override val isInterface: Boolean
|
||||||
}
|
get() = psi.isInterface
|
||||||
|
|
||||||
|
override val isAnnotationType: Boolean
|
||||||
|
get() = psi.isAnnotationType
|
||||||
|
|
||||||
|
override val isEnum: Boolean
|
||||||
|
get() = psi.isEnum
|
||||||
|
|
||||||
|
override val outerClass: JavaClassImpl?
|
||||||
|
get() {
|
||||||
|
val outer = psi.containingClass
|
||||||
|
return if (outer == null) null else JavaClassImpl(outer)
|
||||||
|
}
|
||||||
|
|
||||||
|
override val typeParameters: List<JavaTypeParameter>
|
||||||
|
get() = typeParameters(psi.typeParameters)
|
||||||
|
|
||||||
|
override val supertypes: Collection<JavaClassifierType>
|
||||||
|
get() = classifierTypes(psi.superTypes)
|
||||||
|
|
||||||
|
override // We apply distinct here because PsiClass#getMethods() can return duplicate PSI methods, for example in Lombok (see KT-11778)
|
||||||
|
// Return type seems to be null for example for the 'clone' Groovy method generated by @AutoClone (see EA-73795)
|
||||||
|
val methods: Collection<JavaMethod>
|
||||||
|
get() = methods(psi.methods.filter { method -> !method.isConstructor && method.returnType != null }).distinct()
|
||||||
|
|
||||||
|
override // ex. Android plugin generates LightFields for resources started from '.' (.DS_Store file etc)
|
||||||
|
val fields: Collection<JavaField>
|
||||||
|
get() = fields(psi.fields.filter { field ->
|
||||||
|
val name = field.name
|
||||||
|
name != null && Name.isValidIdentifier(name)
|
||||||
|
})
|
||||||
|
|
||||||
|
override // See for example org.jetbrains.plugins.scala.lang.psi.light.ScFunctionWrapper,
|
||||||
|
// which is present in getConstructors(), but its isConstructor() returns false
|
||||||
|
val constructors: Collection<JavaConstructor>
|
||||||
|
get() = constructors(psi.constructors.filter { method -> method.isConstructor })
|
||||||
|
|
||||||
|
override val isAbstract: Boolean
|
||||||
|
get() = JavaElementUtil.isAbstract(this)
|
||||||
|
|
||||||
|
override val isStatic: Boolean
|
||||||
|
get() = JavaElementUtil.isStatic(this)
|
||||||
|
|
||||||
|
override val isFinal: Boolean
|
||||||
|
get() = JavaElementUtil.isFinal(this)
|
||||||
|
|
||||||
|
override val visibility: Visibility
|
||||||
|
get() = JavaElementUtil.getVisibility(this)
|
||||||
|
|
||||||
|
override val lightClassOriginKind: LightClassOriginKind?
|
||||||
|
get() = (psi as? KtLightClassMarker)?.originKind
|
||||||
|
|
||||||
|
override fun getAnnotationOwnerPsi() = psi.modifierList
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user