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);
|
||||
|
||||
Reference in New Issue
Block a user