Extract interface out of JavaMethod

This commit is contained in:
Alexander Udalov
2013-08-19 14:38:27 +04:00
parent 37beb9e50f
commit 49a19705d1
6 changed files with 95 additions and 48 deletions
@@ -40,6 +40,7 @@ import org.jetbrains.jet.lang.resolve.java.jetAsJava.JetClsMethod;
import org.jetbrains.jet.lang.resolve.java.mapping.JavaToKotlinClassMap;
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.JavaMethodImpl;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
import org.jetbrains.jet.lang.resolve.name.Name;
@@ -288,7 +289,7 @@ public class SignaturesPropagationData {
fun.getValueParameters().size() + (fun.getReceiverParameter() != null ? 1 : 0) == parameterCount) {
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(bindingContext, fun);
if (declaration instanceof PsiMethod) {
result.put(fqName, Pair.create(fun, new JavaMethod((PsiMethod) declaration)));
result.put(fqName, Pair.<FunctionDescriptor, JavaMethod>create(fun, new JavaMethodImpl((PsiMethod) declaration)));
} // else declaration is null or JetNamedFunction: both cases are processed later
}
}
@@ -245,7 +245,7 @@ public class PsiBasedMethodSignatureChecker implements MethodSignatureChecker {
}
for (HierarchicalMethodSignature superSignature : method.getPsi().getHierarchicalMethodSignature().getSuperSignatures()) {
JavaMethod superMethod = new JavaMethod(superSignature.getMethod());
JavaMethod superMethod = new JavaMethodImpl(superSignature.getMethod());
if (superSignature.isRaw() || typeParameterIsErased(method, superMethod) || hasRawTypesInSignature(superMethod)) {
return true;
}
@@ -54,7 +54,7 @@ public class JavaElementCollectionFromPsiArrayUtil {
if (methods.length == 0) return Collections.emptyList();
List<JavaMethod> result = new ArrayList<JavaMethod>(methods.length);
for (PsiMethod psiMethod : methods) {
result.add(new JavaMethod(psiMethod));
result.add(new JavaMethodImpl(psiMethod));
}
return result;
}
@@ -16,63 +16,26 @@
package org.jetbrains.jet.lang.resolve.java.structure;
import com.intellij.psi.PsiAnnotationMethod;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.Collection;
import static org.jetbrains.jet.lang.resolve.java.structure.JavaElementCollectionFromPsiArrayUtil.typeParameters;
import static org.jetbrains.jet.lang.resolve.java.structure.JavaElementCollectionFromPsiArrayUtil.valueParameters;
public class JavaMethod extends JavaMemberImpl implements JavaTypeParameterListOwner {
public JavaMethod(@NotNull PsiMethod psiMethod) {
super(psiMethod);
}
public interface JavaMethod extends JavaMember, JavaTypeParameterListOwner {
@NotNull
@Override
public PsiMethod getPsi() {
return (PsiMethod) super.getPsi();
}
PsiMethod getPsi();
@NotNull
@Override
public Name getName() {
return Name.identifier(getPsi().getName());
}
Collection<JavaValueParameter> getValueParameters();
@NotNull
@Override
public Collection<JavaTypeParameter> getTypeParameters() {
return typeParameters(getPsi().getTypeParameters());
}
@NotNull
public Collection<JavaValueParameter> getValueParameters() {
return valueParameters(getPsi().getParameterList().getParameters());
}
public boolean hasAnnotationParameterDefaultValue() {
PsiMethod psiMethod = getPsi();
return psiMethod instanceof PsiAnnotationMethod && ((PsiAnnotationMethod) psiMethod).getDefaultValue() != null;
}
boolean hasAnnotationParameterDefaultValue();
@Nullable
public JavaType getReturnType() {
PsiType psiType = getPsi().getReturnType();
return psiType == null ? null : JavaType.create(psiType);
}
JavaType getReturnType();
public boolean isVararg() {
return getPsi().isVarArgs();
}
boolean isVararg();
public boolean isConstructor() {
// TODO: class JavaConstructor extends JavaMethod
return getPsi().isConstructor();
}
boolean isConstructor();
}
@@ -0,0 +1,83 @@
/*
* Copyright 2010-2013 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 com.intellij.psi.PsiAnnotationMethod;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.Collection;
import static org.jetbrains.jet.lang.resolve.java.structure.JavaElementCollectionFromPsiArrayUtil.typeParameters;
import static org.jetbrains.jet.lang.resolve.java.structure.JavaElementCollectionFromPsiArrayUtil.valueParameters;
public class JavaMethodImpl extends JavaMemberImpl implements JavaMethod {
public JavaMethodImpl(@NotNull PsiMethod psiMethod) {
super(psiMethod);
}
@NotNull
@Override
public PsiMethod getPsi() {
return (PsiMethod) super.getPsi();
}
@NotNull
@Override
public Name getName() {
return Name.identifier(getPsi().getName());
}
@NotNull
@Override
public Collection<JavaTypeParameter> getTypeParameters() {
return typeParameters(getPsi().getTypeParameters());
}
@Override
@NotNull
public Collection<JavaValueParameter> getValueParameters() {
return valueParameters(getPsi().getParameterList().getParameters());
}
@Override
public boolean hasAnnotationParameterDefaultValue() {
PsiMethod psiMethod = getPsi();
return psiMethod instanceof PsiAnnotationMethod && ((PsiAnnotationMethod) psiMethod).getDefaultValue() != null;
}
@Override
@Nullable
public JavaType getReturnType() {
PsiType psiType = getPsi().getReturnType();
return psiType == null ? null : JavaType.create(psiType);
}
@Override
public boolean isVararg() {
return getPsi().isVarArgs();
}
@Override
public boolean isConstructor() {
// TODO: class JavaConstructor extends JavaMethod
return getPsi().isConstructor();
}
}
@@ -59,7 +59,7 @@ public class JavaTypeParameter extends JavaClassifier implements JavaNamedElemen
PsiTypeParameterListOwner owner = getPsi().getOwner();
// TODO: a separate factory for such things
if (owner instanceof PsiMethod) {
return new JavaMethod((PsiMethod) owner);
return new JavaMethodImpl((PsiMethod) owner);
}
else if (owner instanceof PsiClass) {
return new JavaClass((PsiClass) owner);