Extract JavaConstructor out of JavaMethod
Will be useful in reflection-backed implementation of Java structure, where Constructor is not a Method and doesn't even inherit from it
This commit is contained in:
+7
-7
@@ -30,7 +30,7 @@ import org.jetbrains.jet.lang.descriptors.impl.ValueParameterDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.ExternalAnnotationResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaMember;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
@@ -56,7 +56,7 @@ public class AlternativeMethodSignatureData extends ElementAlternativeSignatureD
|
||||
|
||||
public AlternativeMethodSignatureData(
|
||||
@NotNull ExternalAnnotationResolver externalAnnotationResolver,
|
||||
@NotNull JavaMethod method,
|
||||
@NotNull JavaMember methodOrConstructor,
|
||||
@Nullable JetType receiverType,
|
||||
@NotNull Project project,
|
||||
@NotNull List<ValueParameterDescriptor> valueParameters,
|
||||
@@ -64,7 +64,7 @@ public class AlternativeMethodSignatureData extends ElementAlternativeSignatureD
|
||||
@NotNull List<TypeParameterDescriptor> methodTypeParameters,
|
||||
boolean hasSuperMethods
|
||||
) {
|
||||
String signature = SignaturesUtil.getKotlinSignature(externalAnnotationResolver, method);
|
||||
String signature = SignaturesUtil.getKotlinSignature(externalAnnotationResolver, methodOrConstructor);
|
||||
|
||||
if (signature == null) {
|
||||
setAnnotated(false);
|
||||
@@ -83,7 +83,7 @@ public class AlternativeMethodSignatureData extends ElementAlternativeSignatureD
|
||||
|
||||
try {
|
||||
checkForSyntaxErrors(altFunDeclaration);
|
||||
checkEqualFunctionNames(altFunDeclaration, method);
|
||||
checkEqualFunctionNames(altFunDeclaration, methodOrConstructor);
|
||||
|
||||
computeTypeParameters(methodTypeParameters);
|
||||
computeValueParameters(valueParameters);
|
||||
@@ -290,10 +290,10 @@ public class AlternativeMethodSignatureData extends ElementAlternativeSignatureD
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void checkEqualFunctionNames(@NotNull PsiNamedElement namedElement, @NotNull JavaMethod method) {
|
||||
if (!ComparatorUtil.equalsNullable(method.getName().asString(), namedElement.getName())) {
|
||||
private static void checkEqualFunctionNames(@NotNull PsiNamedElement namedElement, @NotNull JavaMember methodOrConstructor) {
|
||||
if (!ComparatorUtil.equalsNullable(methodOrConstructor.getName().asString(), namedElement.getName())) {
|
||||
throw new AlternativeSignatureMismatchException("Function names mismatch, original: %s, alternative: %s",
|
||||
method.getName().asString(), namedElement.getName());
|
||||
methodOrConstructor.getName().asString(), namedElement.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-3
@@ -28,7 +28,9 @@ import org.jetbrains.jet.lang.resolve.java.JavaBindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.kotlinSignature.AlternativeFieldSignatureData;
|
||||
import org.jetbrains.jet.lang.resolve.java.kotlinSignature.AlternativeMethodSignatureData;
|
||||
import org.jetbrains.jet.lang.resolve.java.kotlinSignature.SignaturesPropagationData;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaConstructor;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaField;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaMember;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
@@ -76,7 +78,7 @@ public class TraceBasedExternalSignatureResolver implements ExternalSignatureRes
|
||||
@Override
|
||||
@NotNull
|
||||
public AlternativeMethodSignature resolveAlternativeMethodSignature(
|
||||
@NotNull JavaMethod method,
|
||||
@NotNull JavaMember methodOrConstructor,
|
||||
boolean hasSuperMethods,
|
||||
@Nullable JetType returnType,
|
||||
@Nullable JetType receiverType,
|
||||
@@ -84,9 +86,12 @@ public class TraceBasedExternalSignatureResolver implements ExternalSignatureRes
|
||||
@NotNull List<TypeParameterDescriptor> typeParameters,
|
||||
boolean hasStableParameterNames
|
||||
) {
|
||||
assert methodOrConstructor instanceof JavaMethod || methodOrConstructor instanceof JavaConstructor :
|
||||
"Not a method or a constructor: " + methodOrConstructor.getName();
|
||||
|
||||
AlternativeMethodSignatureData data =
|
||||
new AlternativeMethodSignatureData(externalAnnotationResolver, method, receiverType, project, valueParameters, returnType,
|
||||
typeParameters, hasSuperMethods);
|
||||
new AlternativeMethodSignatureData(externalAnnotationResolver, methodOrConstructor, receiverType, project, valueParameters,
|
||||
returnType, typeParameters, hasSuperMethods);
|
||||
|
||||
if (data.isAnnotated() && !data.hasErrors()) {
|
||||
return new AlternativeMethodSignature(data.getReturnType(), receiverType, data.getValueParameters(), data.getTypeParameters(),
|
||||
|
||||
+16
-4
@@ -19,6 +19,8 @@ package org.jetbrains.jet.lang.resolve.java.structure.impl;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.PsiSubstitutorImpl;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import kotlin.Function1;
|
||||
import kotlin.KotlinPackage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.Visibility;
|
||||
@@ -101,13 +103,23 @@ public class JavaClassImpl extends JavaClassifierImpl<PsiClass> implements JavaC
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<JavaMethod> getMethods() {
|
||||
return methods(getPsi().getMethods());
|
||||
return methods(KotlinPackage.filter(getPsi().getMethods(), new Function1<PsiMethod, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(PsiMethod method) {
|
||||
return !method.isConstructor();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<JavaMethod> getAllMethods() {
|
||||
return methods(getPsi().getAllMethods());
|
||||
return methods(KotlinPackage.filter(getPsi().getAllMethods(), new Function1<PsiMethod, Boolean>() {
|
||||
@Override
|
||||
public Boolean invoke(PsiMethod method) {
|
||||
return !method.isConstructor();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -124,8 +136,8 @@ public class JavaClassImpl extends JavaClassifierImpl<PsiClass> implements JavaC
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<JavaMethod> getConstructors() {
|
||||
return methods(getPsi().getConstructors());
|
||||
public Collection<JavaConstructor> getConstructors() {
|
||||
return constructors(getPsi().getConstructors());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.java.structure.impl;
|
||||
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaConstructor;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaTypeParameter;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaValueParameter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.java.structure.impl.JavaElementCollectionFromPsiArrayUtil.typeParameters;
|
||||
import static org.jetbrains.jet.lang.resolve.java.structure.impl.JavaElementCollectionFromPsiArrayUtil.valueParameters;
|
||||
|
||||
public class JavaConstructorImpl extends JavaMemberImpl<PsiMethod> implements JavaConstructor {
|
||||
public JavaConstructorImpl(@NotNull PsiMethod psiMethod) {
|
||||
super(psiMethod);
|
||||
assert psiMethod.isConstructor() :
|
||||
"PsiMethod which is not a constructor should not be wrapped in JavaConstructorImpl: " + psiMethod.getName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JavaValueParameter> getValueParameters() {
|
||||
return valueParameters(getPsi().getParameterList().getParameters());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JavaTypeParameter> getTypeParameters() {
|
||||
return typeParameters(getPsi().getTypeParameters());
|
||||
}
|
||||
}
|
||||
+18
@@ -62,6 +62,14 @@ public class JavaElementCollectionFromPsiArrayUtil {
|
||||
}
|
||||
};
|
||||
|
||||
private static final Factory<PsiMethod, JavaConstructor> CONSTRUCTORS = new Factory<PsiMethod, JavaConstructor>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public JavaConstructor create(@NotNull PsiMethod psiMethod) {
|
||||
return new JavaConstructorImpl(psiMethod);
|
||||
}
|
||||
};
|
||||
|
||||
private static final Factory<PsiField, JavaField> FIELDS = new Factory<PsiField, JavaField>() {
|
||||
@NotNull
|
||||
@Override
|
||||
@@ -165,6 +173,16 @@ public class JavaElementCollectionFromPsiArrayUtil {
|
||||
return convert(methods, Factories.METHODS);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Collection<JavaMethod> methods(@NotNull Iterable<PsiMethod> methods) {
|
||||
return convert(methods, Factories.METHODS);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Collection<JavaConstructor> constructors(@NotNull PsiMethod[] methods) {
|
||||
return convert(methods, Factories.CONSTRUCTORS);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Collection<JavaField> fields(@NotNull PsiField[] fields) {
|
||||
return convert(fields, Factories.FIELDS);
|
||||
|
||||
+2
-6
@@ -35,6 +35,8 @@ import static org.jetbrains.jet.lang.resolve.java.structure.impl.JavaElementColl
|
||||
public class JavaMethodImpl extends JavaMemberImpl<PsiMethod> implements JavaMethod {
|
||||
public JavaMethodImpl(@NotNull PsiMethod psiMethod) {
|
||||
super(psiMethod);
|
||||
assert !psiMethod.isConstructor() :
|
||||
"PsiMethod which is a constructor should be wrapped in JavaConstructorImpl: " + psiMethod.getName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -72,10 +74,4 @@ public class JavaMethodImpl extends JavaMemberImpl<PsiMethod> implements JavaMet
|
||||
public boolean isVararg() {
|
||||
return getPsi().isVarArgs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConstructor() {
|
||||
// TODO: class JavaConstructor extends JavaMethod
|
||||
return getPsi().isConstructor();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -54,7 +54,8 @@ public class JavaTypeParameterImpl extends JavaClassifierImpl<PsiTypeParameter>
|
||||
PsiTypeParameterListOwner owner = getPsi().getOwner();
|
||||
// TODO: a separate factory for such things
|
||||
if (owner instanceof PsiMethod) {
|
||||
return new JavaMethodImpl((PsiMethod) owner);
|
||||
PsiMethod psiMethod = (PsiMethod) owner;
|
||||
return psiMethod.isConstructor() ? new JavaConstructorImpl(psiMethod) : new JavaMethodImpl(psiMethod);
|
||||
}
|
||||
else if (owner instanceof PsiClass) {
|
||||
return new JavaClassImpl((PsiClass) owner);
|
||||
|
||||
+4
-5
@@ -29,12 +29,11 @@ public class JavaDescriptorResolver(public val packageFragmentProvider: LazyJava
|
||||
}
|
||||
|
||||
public fun JavaDescriptorResolver.resolveMethod(method: JavaMethod): FunctionDescriptor? {
|
||||
val functions = if (method.isConstructor())
|
||||
resolveClass(method.getContainingClass())?.getConstructors()
|
||||
else
|
||||
getContainingScope(method)?.getFunctions(method.getName())
|
||||
return getContainingScope(method)?.getFunctions(method.getName())?.findByJavaElement(method)
|
||||
}
|
||||
|
||||
return functions?.findByJavaElement(method)
|
||||
public fun JavaDescriptorResolver.resolveConstructor(constructor: JavaConstructor): ConstructorDescriptor? {
|
||||
return resolveClass(constructor.getContainingClass())?.getConstructors()?.findByJavaElement(constructor)
|
||||
}
|
||||
|
||||
public fun JavaDescriptorResolver.resolveField(field: JavaField): PropertyDescriptor? {
|
||||
|
||||
+4
-7
@@ -18,11 +18,9 @@ package org.jetbrains.jet.lang.resolve.java.lazy.descriptors
|
||||
|
||||
import org.jetbrains.jet.lang.descriptors.*
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaClass
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.*
|
||||
import org.jetbrains.jet.lang.resolve.java.lazy.LazyJavaResolverContextWithTypes
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ValueParameterDescriptorImpl
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaArrayType
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.TypeUsage
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ConstructorDescriptorImpl
|
||||
import java.util.Collections
|
||||
@@ -54,9 +52,8 @@ public class LazyJavaClassMemberScope(
|
||||
}
|
||||
|
||||
internal val _constructors = c.storageManager.createLazyValue {
|
||||
jClass.getConstructors().flatMap {
|
||||
jCtor ->
|
||||
val constructor = resolveConstructor(jCtor, getContainingDeclaration())
|
||||
jClass.getConstructors().flatMap { ctor ->
|
||||
val constructor = resolveConstructor(ctor, getContainingDeclaration())
|
||||
val samAdapter = resolveSamAdapter(constructor)
|
||||
if (samAdapter != null) {
|
||||
samAdapter.setReturnType(containingDeclaration.getDefaultType())
|
||||
@@ -116,7 +113,7 @@ public class LazyJavaClassMemberScope(
|
||||
else null
|
||||
}
|
||||
|
||||
private fun resolveConstructor(constructor: JavaMethod, classDescriptor: ClassDescriptor): JavaConstructorDescriptor {
|
||||
private fun resolveConstructor(constructor: JavaConstructor, classDescriptor: ClassDescriptor): JavaConstructorDescriptor {
|
||||
val constructorDescriptor = JavaConstructorDescriptor.createJavaConstructor(
|
||||
classDescriptor, Annotations.EMPTY, /* isPrimary = */ false, c.sourceElementFactory.source(constructor)
|
||||
)
|
||||
|
||||
+4
-10
@@ -20,7 +20,6 @@ import org.jetbrains.jet.lang.resolve.name.Name
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaClass
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils
|
||||
import org.jetbrains.jet.lang.descriptors.Visibilities
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaField
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaMember
|
||||
import org.jetbrains.jet.utils.valuesToMap
|
||||
@@ -44,20 +43,15 @@ object EMPTY_MEMBER_INDEX : MemberIndex {
|
||||
open class ClassMemberIndex(val jClass: JavaClass, val memberFilter: (JavaMember) -> Boolean) : MemberIndex {
|
||||
private val methodFilter = {
|
||||
(m: JavaMethod) ->
|
||||
memberFilter(m) &&
|
||||
!m.isConstructor() &&
|
||||
!DescriptorResolverUtils.isObjectMethodInInterface(m)
|
||||
memberFilter(m) && !DescriptorResolverUtils.isObjectMethodInInterface(m)
|
||||
}
|
||||
|
||||
private val methods = jClass.getMethods().stream().filter(methodFilter).groupBy { m -> m.getName() }
|
||||
private val fields = jClass.getFields().stream().filter(memberFilter).valuesToMap { m -> m.getName() }
|
||||
|
||||
override fun findMethodsByName(name: Name): Collection<JavaMethod> {
|
||||
return methods[name] ?: listOf()
|
||||
}
|
||||
|
||||
override fun getAllMethodNames(): Collection<Name> = jClass.getAllMethods().iterator().filter(methodFilter).map { m -> m.getName() }.toList()
|
||||
override fun findMethodsByName(name: Name): Collection<JavaMethod> = methods[name] ?: listOf()
|
||||
override fun getAllMethodNames(): Collection<Name> = jClass.getAllMethods().stream().filter(methodFilter).map { m -> m.getName() }.toList()
|
||||
|
||||
override fun findFieldByName(name: Name): JavaField? = fields[name]
|
||||
override fun getAllFieldNames() = jClass.getAllFields().stream().filter(memberFilter).map { m -> m.getName() }.toList()
|
||||
}
|
||||
}
|
||||
|
||||
+4
-15
@@ -16,28 +16,19 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.java.lazy.types
|
||||
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaType
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.*
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaWildcardType
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.TypeUsage.*
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.*
|
||||
import org.jetbrains.jet.lang.types.Variance.*
|
||||
import org.jetbrains.jet.lang.types.*
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaPrimitiveType
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaArrayType
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaClassifierType
|
||||
import org.jetbrains.jet.lang.resolve.java.mapping.JavaToKotlinClassMap
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaTypeParameter
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaClass
|
||||
import org.jetbrains.kotlin.util.sure
|
||||
import org.jetbrains.jet.utils.*
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaAnnotationOwner
|
||||
import org.jetbrains.jet.lang.resolve.java.lazy.*
|
||||
import org.jetbrains.jet.storage.*
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod
|
||||
import java.util.HashSet
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker
|
||||
|
||||
@@ -132,17 +123,15 @@ class LazyJavaTypeResolver(
|
||||
}
|
||||
|
||||
private fun isConstructorTypeParameter(): Boolean {
|
||||
val cl = classifier()
|
||||
if (cl !is JavaTypeParameter) return false
|
||||
val owner = cl.getOwner()
|
||||
return owner is JavaMethod && owner.isConstructor()
|
||||
val classifier = classifier()
|
||||
return classifier is JavaTypeParameter && classifier.getOwner() is JavaConstructor
|
||||
}
|
||||
|
||||
// We do not memoize the results of this method, because it would consume much memory, and the real gain is little:
|
||||
// the case this method accounts for is very rare, not point in optimizing it
|
||||
private fun getConstructorTypeParameterSubstitute(): JetType {
|
||||
// If a Java-constructor declares its own type parameters, we have no way of directly expressing them in Kotlin,
|
||||
// so we replace thwm by intersections of their upper bounds
|
||||
// so we replace them by intersections of their upper bounds
|
||||
val supertypesJet = HashSet<JetType>()
|
||||
for (supertype in (classifier() as JavaTypeParameter).getUpperBounds()) {
|
||||
supertypesJet.add(transformJavaType(supertype, UPPER_BOUND.toAttributes()))
|
||||
|
||||
+2
-1
@@ -20,6 +20,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaField;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaMember;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
@@ -136,7 +137,7 @@ public interface ExternalSignatureResolver {
|
||||
|
||||
@NotNull
|
||||
AlternativeMethodSignature resolveAlternativeMethodSignature(
|
||||
@NotNull JavaMethod method,
|
||||
@NotNull JavaMember methodOrConstructor,
|
||||
boolean hasSuperMethods,
|
||||
@Nullable JetType returnType,
|
||||
@Nullable JetType receiverType,
|
||||
|
||||
+1
-3
@@ -375,9 +375,7 @@ public class SingleAbstractMethodUtils {
|
||||
@NotNull JavaMethod method2,
|
||||
@NotNull JavaTypeSubstitutor substitutor2
|
||||
) {
|
||||
if (method1.isConstructor() != method2.isConstructor()) return false;
|
||||
if (!method1.isConstructor() && !method1.getName().equals(method2.getName())) return false;
|
||||
|
||||
if (!method1.getName().equals(method2.getName())) return false;
|
||||
if (method1.isVararg() != method2.isVararg()) return false;
|
||||
|
||||
Collection<JavaValueParameter> parameters1 = method1.getValueParameters();
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ public interface JavaClass extends JavaClassifier, JavaTypeParameterListOwner, J
|
||||
Collection<JavaField> getAllFields();
|
||||
|
||||
@NotNull
|
||||
Collection<JavaMethod> getConstructors();
|
||||
Collection<JavaConstructor> getConstructors();
|
||||
|
||||
@NotNull
|
||||
JavaClassifierType getDefaultType();
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.java.structure;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface JavaConstructor extends JavaMember, JavaTypeParameterListOwner {
|
||||
@NotNull
|
||||
List<JavaValueParameter> getValueParameters();
|
||||
}
|
||||
-2
@@ -31,6 +31,4 @@ public interface JavaMethod extends JavaMember, JavaTypeParameterListOwner {
|
||||
JavaType getReturnType();
|
||||
|
||||
boolean isVararg();
|
||||
|
||||
boolean isConstructor();
|
||||
}
|
||||
|
||||
+12
-5
@@ -38,6 +38,7 @@ import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaPackage;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaConstructorImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaFieldImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaMethodImpl;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
@@ -149,11 +150,17 @@ public class KotlinSignatureAnnotationIntention extends BaseIntentionAction impl
|
||||
|
||||
if (analyzableAnnotationOwner instanceof PsiMethod) {
|
||||
PsiMethod psiMethod = (PsiMethod) analyzableAnnotationOwner;
|
||||
FunctionDescriptor functionDescriptor = JavaPackage.resolveMethod(javaDescriptorResolver, new JavaMethodImpl(psiMethod));
|
||||
assert functionDescriptor != null : "Couldn't find function descriptor for " + renderMember(analyzableAnnotationOwner);
|
||||
return functionDescriptor instanceof ConstructorDescriptor
|
||||
? getDefaultConstructorAnnotation((ConstructorDescriptor) functionDescriptor)
|
||||
: RENDERER.render(functionDescriptor);
|
||||
if (psiMethod.isConstructor()) {
|
||||
ConstructorDescriptor constructorDescriptor =
|
||||
JavaPackage.resolveConstructor(javaDescriptorResolver, new JavaConstructorImpl(psiMethod));
|
||||
assert constructorDescriptor != null: "Couldn't find constructor descriptor for " + renderMember(psiMethod);
|
||||
return getDefaultConstructorAnnotation(constructorDescriptor);
|
||||
}
|
||||
else {
|
||||
FunctionDescriptor functionDescriptor = JavaPackage.resolveMethod(javaDescriptorResolver, new JavaMethodImpl(psiMethod));
|
||||
assert functionDescriptor != null: "Couldn't find function descriptor for " + renderMember(psiMethod);
|
||||
return RENDERER.render(functionDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
if (analyzableAnnotationOwner instanceof PsiField) {
|
||||
|
||||
+8
-1
@@ -40,6 +40,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaBindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaPackage;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaConstructorImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaFieldImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaMethodImpl;
|
||||
import org.jetbrains.jet.plugin.JetIcons;
|
||||
@@ -118,7 +119,13 @@ public class KotlinSignatureInJavaMarkerProvider implements LineMarkerProvider {
|
||||
@NotNull PsiModifierListOwner member
|
||||
) {
|
||||
if (member instanceof PsiMethod) {
|
||||
return JavaPackage.resolveMethod(javaDescriptorResolver, new JavaMethodImpl((PsiMethod) member));
|
||||
PsiMethod method = (PsiMethod) member;
|
||||
if (method.isConstructor()) {
|
||||
return JavaPackage.resolveConstructor(javaDescriptorResolver, new JavaConstructorImpl(method));
|
||||
}
|
||||
else {
|
||||
return JavaPackage.resolveMethod(javaDescriptorResolver, new JavaMethodImpl(method));
|
||||
}
|
||||
}
|
||||
else if (member instanceof PsiField) {
|
||||
return JavaPackage.resolveField(javaDescriptorResolver, new JavaFieldImpl((PsiField) member));
|
||||
|
||||
Reference in New Issue
Block a user