merge @JetProperty and @JetMethod

because:
* have common parts
* reduce class size

Also add helper JetMethodAnnotationWriter class

And also do not generate @Jet* annotations for closures
This commit is contained in:
Stepan Koltsov
2012-01-13 23:56:13 +04:00
parent 6603a431fa
commit 133fc683a4
16 changed files with 177 additions and 164 deletions
@@ -132,12 +132,11 @@ public class JavaDescriptorResolver {
private static abstract class ResolverScopeData {
@Nullable
private Set<VariableDescriptor> properties;
private boolean kotlin;
protected boolean kotlin;
}
private static class ResolverClassData extends ResolverScopeData {
private JavaClassDescriptor classDescriptor;
private boolean kotlin;
@NotNull
public ClassDescriptor getClassDescriptor() {
@@ -147,7 +146,6 @@ public class JavaDescriptorResolver {
private static class ResolverNamespaceData extends ResolverScopeData {
private JavaNamespaceDescriptor namespaceDescriptor;
private boolean kotlin;
@NotNull
public NamespaceDescriptor getNamespaceDescriptor() {
@@ -892,7 +890,7 @@ public class JavaDescriptorResolver {
if (psiMethod.getName().startsWith(JvmAbi.GETTER_PREFIX)) {
// TODO: some java properties too
if (method.getJetProperty().isDefined()) {
if (method.getJetMethod().kind() == JvmStdlibNames.JET_METHOD_KIND_PROPERTY) {
if (psiMethod.getName().equals(JvmStdlibNames.JET_OBJECT_GET_TYPEINFO_METHOD)) {
continue;
@@ -933,7 +931,7 @@ public class JavaDescriptorResolver {
}
} else if (psiMethod.getName().startsWith(JvmAbi.SETTER_PREFIX)) {
if (method.getJetProperty().isDefined()) {
if (method.getJetMethod().kind() == JvmStdlibNames.JET_METHOD_KIND_PROPERTY) {
if (psiMethod.getParameterList().getParametersCount() == 0) {
// TODO: report error properly
throw new IllegalStateException();
@@ -1215,7 +1213,7 @@ public class JavaDescriptorResolver {
}
// TODO: ugly
if (method.getJetProperty().isDefined()) {
if (method.getJetMethod().kind() == JvmStdlibNames.JET_METHOD_KIND_PROPERTY) {
return null;
}
@@ -1308,9 +1306,9 @@ public class JavaDescriptorResolver {
@NotNull PsiMethodWrapper method,
@NotNull FunctionDescriptor functionDescriptor,
@NotNull TypeVariableResolver classTypeVariableResolver) {
if (method.getJetMethodOrProperty().typeParameters().length() > 0) {
if (method.getJetMethod().typeParameters().length() > 0) {
List<TypeParameterDescriptor> r = resolveMethodTypeParametersFromJetSignature(
method.getJetMethodOrProperty().typeParameters(), method.getPsiMethod(), functionDescriptor, classTypeVariableResolver);
method.getJetMethod().typeParameters(), method.getPsiMethod(), functionDescriptor, classTypeVariableResolver);
initializeTypeParameters(method.getPsiMethod());
return r;
}
@@ -24,15 +24,16 @@ public class JvmStdlibNames {
public static final JvmClassName JET_METHOD = new JvmClassName("jet.runtime.typeinfo.JetMethod");
public static final String JET_METHOD_KIND_FIELD = "kind";
public static final String JET_METHOD_NULLABLE_RETURN_TYPE_FIELD = "nullableReturnType";
public static final String JET_METHOD_RETURN_TYPE_FIELD = "returnType";
public static final String JET_METHOD_TYPE_PARAMETERS_FIELD = "typeParameters";
public static final String JET_METHOD_PROPERTY_TYPE_FIELD = "propertyType";
public static final int JET_METHOD_KIND_REGULAR = 0;
public static final int JET_METHOD_KIND_PROPERTY = 1;
public static final int JET_METHOD_KIND_DEFAULT = JET_METHOD_KIND_REGULAR;
public static final JvmClassName JET_PROPERTY = new JvmClassName("jet.runtime.typeinfo.JetProperty");
public static final String JET_PROPERTY_TYPE_FIELD = "type";
public static final String JET_PROPERTY_TYPE_PARAMETERS_FIELD = "typeParameters";
public static final JvmClassName JET_CONSTRUCTOR = new JvmClassName("jet.runtime.typeinfo.JetConstructor");
/**
@@ -1,14 +1,11 @@
package org.jetbrains.jet.lang.resolve.java;
import com.intellij.psi.PsiMember;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiModifier;
import com.intellij.psi.PsiParameter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.java.kt.JetConstructorAnnotation;
import org.jetbrains.jet.lang.resolve.java.kt.JetMethodAnnotation;
import org.jetbrains.jet.lang.resolve.java.kt.JetMethodOrPropertyAnnotation;
import org.jetbrains.jet.lang.resolve.java.kt.JetPropertyAnnotation;
import java.util.ArrayList;
import java.util.List;
@@ -62,23 +59,6 @@ public class PsiMethodWrapper extends PsiMemberWrapper {
return jetConstructor;
}
private JetPropertyAnnotation jetProperty;
@NotNull
public JetPropertyAnnotation getJetProperty() {
if (jetProperty == null) {
jetProperty = JetPropertyAnnotation.get(getPsiMethod());
}
return jetProperty;
}
public JetMethodOrPropertyAnnotation getJetMethodOrProperty() {
if (getJetMethod().isDefined()) {
return getJetMethod();
} else {
return getJetProperty();
}
}
@NotNull
public PsiMethod getPsiMethod() {
return (PsiMethod) psiMember;
@@ -9,11 +9,30 @@ import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
/**
* @author Stepan Koltsov
*/
public class JetMethodAnnotation extends JetMethodOrPropertyAnnotation {
public class JetMethodAnnotation extends PsiAnnotationWrapper {
public JetMethodAnnotation(@Nullable PsiAnnotation psiAnnotation) {
super(psiAnnotation);
}
private int kind;
private boolean kindInitialized;
public int kind() {
if (!kindInitialized) {
kind = getIntAttribute(JvmStdlibNames.JET_METHOD_KIND_FIELD, JvmStdlibNames.JET_METHOD_KIND_DEFAULT);
kindInitialized = true;
}
return kind;
}
private String typeParameters;
@NotNull
public String typeParameters() {
if (typeParameters == null) {
typeParameters = getStringAttribute(JvmStdlibNames.JET_METHOD_TYPE_PARAMETERS_FIELD, "");
}
return typeParameters;
}
private String returnType;
@NotNull
@@ -34,7 +53,16 @@ public class JetMethodAnnotation extends JetMethodOrPropertyAnnotation {
}
return returnTypeNullable;
}
private String propertyType;
@NotNull
public String propertyType() {
if (propertyType == null) {
propertyType = getStringAttribute(JvmStdlibNames.JET_METHOD_PROPERTY_TYPE_FIELD, "");
}
return propertyType;
}
public static JetMethodAnnotation get(PsiMethod psiMethod) {
return new JetMethodAnnotation(psiMethod.getModifierList().findAnnotation(JvmStdlibNames.JET_METHOD.getFqName()));
}
@@ -1,25 +0,0 @@
package org.jetbrains.jet.lang.resolve.java.kt;
import com.intellij.psi.PsiAnnotation;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
/**
* @author Stepan Koltsov
*/
public abstract class JetMethodOrPropertyAnnotation extends PsiAnnotationWrapper {
protected JetMethodOrPropertyAnnotation(@Nullable PsiAnnotation psiAnnotation) {
super(psiAnnotation);
}
private String typeParameters;
@NotNull
public String typeParameters() {
if (typeParameters == null) {
typeParameters = getStringAttribute(JvmStdlibNames.JET_METHOD_TYPE_PARAMETERS_FIELD, "");
}
return typeParameters;
}
}
@@ -1,21 +0,0 @@
package org.jetbrains.jet.lang.resolve.java.kt;
import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiMethod;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
/**
* @author Stepan Koltsov
*/
public class JetPropertyAnnotation extends JetMethodOrPropertyAnnotation {
protected JetPropertyAnnotation(@Nullable PsiAnnotation psiAnnotation) {
super(psiAnnotation);
}
@NotNull
public static JetPropertyAnnotation get(@NotNull PsiMethod psiMethod) {
return new JetPropertyAnnotation(psiMethod.getModifierList().findAnnotation(JvmStdlibNames.JET_PROPERTY.getFqName()));
}
}
@@ -19,6 +19,11 @@ public class PsiAnnotationUtils {
return getAttribute(annotation, field, defaultValue);
}
public static int getIntAttribute(@Nullable PsiAnnotation annotation, @NotNull String field, int defaultValue) {
return getAttribute(annotation, field, defaultValue);
}
@NotNull
private static <T> T getAttribute(@Nullable PsiAnnotation annotation, @NotNull String field, @NotNull T defaultValue) {
if (annotation == null) {
return defaultValue;
@@ -33,4 +33,9 @@ public abstract class PsiAnnotationWrapper {
protected boolean getBooleanAttribute(String name, boolean defaultValue) {
return PsiAnnotationUtils.getBooleanAttribute(psiAnnotation, name, defaultValue);
}
protected int getIntAttribute(String name, int defaultValue) {
return PsiAnnotationUtils.getIntAttribute(psiAnnotation, name, defaultValue);
}
}