Merge remote-tracking branch 'origin/master'
This commit is contained in:
Generated
+19
@@ -0,0 +1,19 @@
|
||||
<component name="ArtifactManager">
|
||||
<artifact type="jar" name="KotlinPlugin">
|
||||
<output-path>$PROJECT_DIR$/out/artifacts/KotlinPlugin</output-path>
|
||||
<root id="archive" name="KotlinPlugin.zip">
|
||||
<element id="directory" name="Kotlin">
|
||||
<element id="directory" name="lib">
|
||||
<element id="library" level="project" name="asm" />
|
||||
<element id="archive" name="kotlin-plugin.jar">
|
||||
<element id="module-output" name="backend" />
|
||||
<element id="module-output" name="frontend" />
|
||||
<element id="module-output" name="frontend.java" />
|
||||
<element id="module-output" name="idea" />
|
||||
<element id="module-output" name="jet.as.java.psi" />
|
||||
</element>
|
||||
</element>
|
||||
</element>
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
||||
Generated
+1
@@ -15,6 +15,7 @@
|
||||
<entry name="?*.tld" />
|
||||
<entry name="?*.ftl" />
|
||||
<entry name="?*.jet" />
|
||||
<entry name="?*.ft" />
|
||||
</wildcardResourcePatterns>
|
||||
<annotationProcessing enabled="false" useClasspath="true" />
|
||||
</component>
|
||||
|
||||
Generated
+1
@@ -11,6 +11,7 @@
|
||||
<module fileurl="file://$PROJECT_DIR$/compiler/frontend.java/frontend.java.iml" filepath="$PROJECT_DIR$/compiler/frontend.java/frontend.java.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/grammar/grammar.iml" filepath="$PROJECT_DIR$/grammar/grammar.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/idea/idea.iml" filepath="$PROJECT_DIR$/idea/idea.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/compiler/jet.as.java.psi/jet.as.java.psi.iml" filepath="$PROJECT_DIR$/compiler/jet.as.java.psi/jet.as.java.psi.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/stdlib/stdlib.iml" filepath="$PROJECT_DIR$/stdlib/stdlib.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/testlib/testlib.iml" filepath="$PROJECT_DIR$/testlib/testlib.iml" />
|
||||
</modules>
|
||||
|
||||
@@ -73,7 +73,10 @@
|
||||
</target>
|
||||
|
||||
<target name="dist" depends="clean,jarRT,jar">
|
||||
<echo file="${output}/build.txt" message="${build.number}"/>
|
||||
<zip destfile="${output}/${output.name}.zip">
|
||||
<zipfileset prefix="kotlinc" file="${output}/build.txt"/>
|
||||
<zipfileset prefix="kotlinc/license" dir="${basedir}/license"/>
|
||||
<zipfileset prefix="kotlinc/bin" filemode="755" dir="${basedir}/compiler/cli/bin"/>
|
||||
<zipfileset prefix="kotlinc/lib" dir="${idea.sdk}"/>
|
||||
<zipfileset prefix="kotlinc/lib" dir="${basedir}/lib"/>
|
||||
|
||||
@@ -3,11 +3,12 @@ package org.jetbrains.jet.codegen;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.java.JetSignatureUtils;
|
||||
import org.jetbrains.jet.lang.types.Variance;
|
||||
import org.jetbrains.jet.rt.signature.JetSignatureAdapter;
|
||||
import org.jetbrains.jet.rt.signature.JetSignatureReader;
|
||||
import org.jetbrains.jet.rt.signature.JetSignatureWriter;
|
||||
import org.jetbrains.jet.lang.types.Variance;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.commons.Method;
|
||||
import org.objectweb.asm.signature.SignatureVisitor;
|
||||
import org.objectweb.asm.signature.SignatureWriter;
|
||||
import org.objectweb.asm.util.CheckSignatureAdapter;
|
||||
@@ -40,6 +41,7 @@ public class BothSignatureWriter {
|
||||
TYPE_PARAMETERS,
|
||||
|
||||
PARAMETERS,
|
||||
PARAMETER,
|
||||
RETURN_TYPE,
|
||||
METHOD_END,
|
||||
|
||||
@@ -55,16 +57,26 @@ public class BothSignatureWriter {
|
||||
private String kotlinClassParameters;
|
||||
private String kotlinClassSignature;
|
||||
|
||||
private List<String> kotlinParameterTypes = new ArrayList<String>();
|
||||
private List<JvmMethodParameterSignature> kotlinParameterTypes = new ArrayList<JvmMethodParameterSignature>();
|
||||
private String kotlinReturnType;
|
||||
|
||||
private int jvmCurrentTypeArrayLevel;
|
||||
private Type jvmCurrentType;
|
||||
private Type jvmReturnType;
|
||||
|
||||
private JvmMethodParameterKind currentParameterKind;
|
||||
|
||||
private final Mode mode;
|
||||
private final boolean needGenerics;
|
||||
|
||||
private State state = State.START;
|
||||
|
||||
private boolean generic = false;
|
||||
|
||||
public BothSignatureWriter(Mode mode) {
|
||||
public BothSignatureWriter(Mode mode, boolean needGenerics) {
|
||||
this.mode = mode;
|
||||
this.needGenerics = needGenerics;
|
||||
|
||||
if (DEBUG_SIGNATURE_WRITER) {
|
||||
signatureVisitor = new CheckSignatureAdapter(mode.asmType, signatureWriter);
|
||||
} else {
|
||||
@@ -152,11 +164,27 @@ public class BothSignatureWriter {
|
||||
}
|
||||
signatureVisitor().visitBaseType(c);
|
||||
jetSignatureWriter.visitBaseType(c, nullable);
|
||||
writeAsmType0(Type.getType(String.valueOf(c)));
|
||||
}
|
||||
|
||||
private String makeArrayPrefix() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < jvmCurrentTypeArrayLevel; ++i) {
|
||||
sb.append('[');
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private void writeAsmType0(Type type) {
|
||||
if (jvmCurrentType == null) {
|
||||
jvmCurrentType = Type.getType(makeArrayPrefix() + type.getDescriptor());
|
||||
}
|
||||
}
|
||||
|
||||
public void writeClassBegin(String internalName, boolean nullable) {
|
||||
signatureVisitor().visitClassType(internalName);
|
||||
jetSignatureWriter.visitClassType(internalName, nullable);
|
||||
writeAsmType0(Type.getObjectType(internalName));
|
||||
}
|
||||
|
||||
public void writeClassEnd() {
|
||||
@@ -167,6 +195,9 @@ public class BothSignatureWriter {
|
||||
public void writeArrayType(boolean nullable) {
|
||||
push(signatureVisitor().visitArrayType());
|
||||
jetSignatureWriter.visitArrayType(nullable);
|
||||
if (jvmCurrentType == null) {
|
||||
++jvmCurrentTypeArrayLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public void writeArrayEnd() {
|
||||
@@ -183,10 +214,11 @@ public class BothSignatureWriter {
|
||||
pop();
|
||||
}
|
||||
|
||||
public void writeTypeVariable(final String name, boolean nullable) {
|
||||
public void writeTypeVariable(final String name, boolean nullable, Type asmType) {
|
||||
signatureVisitor().visitTypeVariable(name);
|
||||
jetSignatureWriter.visitTypeVariable(name, nullable);
|
||||
generic = true;
|
||||
writeAsmType0(asmType);
|
||||
}
|
||||
|
||||
public void writeFormalTypeParameter(final String name, Variance variance) {
|
||||
@@ -202,7 +234,7 @@ public class BothSignatureWriter {
|
||||
jetSignatureWriter.visitFormalTypeParameterEnd();
|
||||
}
|
||||
|
||||
public void writerFormalTypeParametersStart() {
|
||||
public void writeFormalTypeParametersStart() {
|
||||
checkTopLevel();
|
||||
transitionState(State.START, State.TYPE_PARAMETERS);
|
||||
jetSignatureWriter = new JetSignatureWriter();
|
||||
@@ -242,28 +274,59 @@ public class BothSignatureWriter {
|
||||
|
||||
public void writeParametersStart() {
|
||||
transitionState(State.TYPE_PARAMETERS, State.PARAMETERS);
|
||||
|
||||
// hacks
|
||||
jvmCurrentType = null;
|
||||
jvmCurrentTypeArrayLevel = 0;
|
||||
}
|
||||
|
||||
public void writeParametersEnd() {
|
||||
checkState(State.PARAMETERS);
|
||||
}
|
||||
|
||||
public void writeParameterType() {
|
||||
public void writeParameterType(JvmMethodParameterKind parameterKind) {
|
||||
transitionState(State.PARAMETERS, State.PARAMETER);
|
||||
|
||||
push(signatureVisitor().visitParameterType());
|
||||
jetSignatureWriter = new JetSignatureWriter();
|
||||
if (jvmCurrentType != null || jvmCurrentTypeArrayLevel != 0) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
if (currentParameterKind != null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
this.currentParameterKind = parameterKind;
|
||||
|
||||
//jetSignatureWriter.visitParameterType();
|
||||
}
|
||||
|
||||
public void writeParameterTypeEnd() {
|
||||
pop();
|
||||
|
||||
if (jvmCurrentType == null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
String signature = jetSignatureWriter.toString();
|
||||
kotlinParameterTypes.add(signature);
|
||||
kotlinParameterTypes.add(new JvmMethodParameterSignature(jvmCurrentType, signature, currentParameterKind));
|
||||
|
||||
if (DEBUG_SIGNATURE_WRITER) {
|
||||
new JetSignatureReader(signature).acceptTypeOnly(new JetSignatureAdapter());
|
||||
}
|
||||
|
||||
currentParameterKind = null;
|
||||
jvmCurrentType = null;
|
||||
jvmCurrentTypeArrayLevel = 0;
|
||||
|
||||
jetSignatureWriter = null;
|
||||
transitionState(State.PARAMETER, State.PARAMETERS);
|
||||
}
|
||||
|
||||
public void writeTypeInfoParameter() {
|
||||
writeParameterType(JvmMethodParameterKind.TYPE_INFO);
|
||||
writeAsmType(JetTypeMapper.TYPE_TYPEINFO, false);
|
||||
writeParameterTypeEnd();
|
||||
}
|
||||
|
||||
public void writeReturnType() {
|
||||
@@ -271,6 +334,10 @@ public class BothSignatureWriter {
|
||||
|
||||
jetSignatureWriter = new JetSignatureWriter();
|
||||
|
||||
if (jvmCurrentType != null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
push(signatureVisitor().visitReturnType());
|
||||
//jetSignatureWriter.visitReturnType();
|
||||
}
|
||||
@@ -280,6 +347,14 @@ public class BothSignatureWriter {
|
||||
|
||||
kotlinReturnType = jetSignatureWriter.toString();
|
||||
|
||||
if (jvmCurrentType == null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
jvmReturnType = jvmCurrentType;
|
||||
jvmCurrentType = null;
|
||||
jvmCurrentTypeArrayLevel = 0;
|
||||
|
||||
if (DEBUG_SIGNATURE_WRITER) {
|
||||
new JetSignatureReader(kotlinReturnType).acceptTypeOnly(new JetSignatureAdapter());
|
||||
}
|
||||
@@ -288,6 +363,12 @@ public class BothSignatureWriter {
|
||||
transitionState(State.RETURN_TYPE, State.METHOD_END);
|
||||
}
|
||||
|
||||
public void writeVoidReturn() {
|
||||
writeReturnType();
|
||||
writeAsmType(Type.VOID_TYPE, false);
|
||||
writeReturnTypeEnd();
|
||||
}
|
||||
|
||||
public void writeSupersStart() {
|
||||
transitionState(State.TYPE_PARAMETERS, State.SUPERS);
|
||||
jetSignatureWriter = new JetSignatureWriter();
|
||||
@@ -333,6 +414,14 @@ public class BothSignatureWriter {
|
||||
|
||||
|
||||
|
||||
@NotNull
|
||||
public Method makeAsmMethod(String name) {
|
||||
List<Type> jvmParameterTypes = new ArrayList<Type>(kotlinParameterTypes.size());
|
||||
for (JvmMethodParameterSignature p : kotlinParameterTypes) {
|
||||
jvmParameterTypes.add(p.getAsmType());
|
||||
}
|
||||
return new Method(name, jvmReturnType, jvmParameterTypes.toArray(new Type[0]));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String makeJavaString() {
|
||||
@@ -344,13 +433,13 @@ public class BothSignatureWriter {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<String> makeKotlinParameterTypes() {
|
||||
public List<JvmMethodParameterSignature> makeKotlinParameterTypes() {
|
||||
checkState(State.METHOD_END);
|
||||
// TODO: return nulls if equal to #makeJavaString
|
||||
return kotlinParameterTypes;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NotNull
|
||||
public String makeKotlinReturnTypeSignature() {
|
||||
checkState(State.METHOD_END);
|
||||
return kotlinReturnType;
|
||||
@@ -373,4 +462,19 @@ public class BothSignatureWriter {
|
||||
return kotlinClassParameters + kotlinClassSignature;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JvmMethodSignature makeJvmMethodSignature(String name) {
|
||||
if (needGenerics) {
|
||||
return new JvmMethodSignature(
|
||||
makeAsmMethod(name),
|
||||
makeJavaString(),
|
||||
makeKotlinMethodTypeParameters(),
|
||||
makeKotlinParameterTypes(),
|
||||
makeKotlinReturnTypeSignature()
|
||||
);
|
||||
} else {
|
||||
return new JvmMethodSignature(makeAsmMethod(name), makeKotlinParameterTypes());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,17 +19,15 @@ public class CallableMethod implements Callable {
|
||||
private String owner;
|
||||
private final JvmMethodSignature signature;
|
||||
private int invokeOpcode;
|
||||
private final List<Type> valueParameterTypes;
|
||||
private ClassDescriptor thisClass = null;
|
||||
|
||||
private CallableDescriptor receiverFunction = null;
|
||||
private Type generateCalleeType = null;
|
||||
|
||||
public CallableMethod(String owner, JvmMethodSignature signature, int invokeOpcode, List<Type> valueParameterTypes) {
|
||||
public CallableMethod(String owner, JvmMethodSignature signature, int invokeOpcode) {
|
||||
this.owner = owner;
|
||||
this.signature = signature;
|
||||
this.invokeOpcode = invokeOpcode;
|
||||
this.valueParameterTypes = valueParameterTypes;
|
||||
}
|
||||
|
||||
public String getOwner() {
|
||||
@@ -45,7 +43,7 @@ public class CallableMethod implements Callable {
|
||||
}
|
||||
|
||||
public List<Type> getValueParameterTypes() {
|
||||
return valueParameterTypes;
|
||||
return signature.getValueParameterTypes();
|
||||
}
|
||||
|
||||
public void setNeedsReceiver(@Nullable CallableDescriptor receiverClass) {
|
||||
|
||||
@@ -39,22 +39,40 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
|
||||
bindingContext = state.getBindingContext();
|
||||
}
|
||||
|
||||
public static Method erasedInvokeSignature(FunctionDescriptor fd) {
|
||||
public static JvmMethodSignature erasedInvokeSignature(FunctionDescriptor fd) {
|
||||
|
||||
BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, false);
|
||||
|
||||
signatureWriter.writeFormalTypeParametersStart();
|
||||
signatureWriter.writeFormalTypeParametersEnd();
|
||||
|
||||
boolean isExtensionFunction = fd.getReceiverParameter().exists();
|
||||
int paramCount = fd.getValueParameters().size();
|
||||
if (isExtensionFunction) {
|
||||
paramCount++;
|
||||
}
|
||||
|
||||
signatureWriter.writeParametersStart();
|
||||
|
||||
for (int i = 0; i < paramCount; ++i) {
|
||||
signatureWriter.writeParameterType(JvmMethodParameterKind.VALUE);
|
||||
signatureWriter.writeAsmType(JetTypeMapper.TYPE_OBJECT, true);
|
||||
signatureWriter.writeParameterTypeEnd();
|
||||
}
|
||||
|
||||
signatureWriter.writeParametersEnd();
|
||||
|
||||
Type[] args = new Type[paramCount];
|
||||
Arrays.fill(args, JetTypeMapper.TYPE_OBJECT);
|
||||
return new Method("invoke", JetTypeMapper.TYPE_OBJECT, args);
|
||||
signatureWriter.writeReturnType();
|
||||
signatureWriter.writeAsmType(JetTypeMapper.TYPE_OBJECT, true);
|
||||
signatureWriter.writeReturnTypeEnd();
|
||||
|
||||
return signatureWriter.makeJvmMethodSignature("invoke");
|
||||
}
|
||||
|
||||
public static CallableMethod asCallableMethod(FunctionDescriptor fd) {
|
||||
Method descriptor = erasedInvokeSignature(fd);
|
||||
JvmMethodSignature descriptor = erasedInvokeSignature(fd);
|
||||
String owner = getInternalClassName(fd);
|
||||
final CallableMethod result = new CallableMethod(owner, new JvmMethodSignature(descriptor, null, null, null, null), INVOKEVIRTUAL, Arrays.asList(descriptor.getArgumentTypes()));
|
||||
final CallableMethod result = new CallableMethod(owner, descriptor, INVOKEVIRTUAL);
|
||||
if (fd.getReceiverParameter().exists()) {
|
||||
result.setNeedsReceiver(fd);
|
||||
}
|
||||
@@ -62,8 +80,8 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
|
||||
return result;
|
||||
}
|
||||
|
||||
public Method invokeSignature(FunctionDescriptor fd) {
|
||||
return state.getTypeMapper().mapSignature("invoke", fd).getAsmMethod();
|
||||
public JvmMethodSignature invokeSignature(FunctionDescriptor fd) {
|
||||
return state.getTypeMapper().mapSignature("invoke", fd);
|
||||
}
|
||||
|
||||
public GeneratedAnonymousClassDescriptor gen(JetFunctionLiteralExpression fun) {
|
||||
@@ -165,18 +183,19 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
|
||||
|
||||
final CodegenContext.ClosureContext closureContext = context.intoClosure(funDescriptor, function, name, this, state.getTypeMapper());
|
||||
FunctionCodegen fc = new FunctionCodegen(closureContext, cv, state);
|
||||
fc.generateMethod(body, new JvmMethodSignature(invokeSignature(funDescriptor), null, null, null, null), funDescriptor);
|
||||
JvmMethodSignature jvmMethodSignature = invokeSignature(funDescriptor);
|
||||
fc.generateMethod(body, jvmMethodSignature, null, funDescriptor);
|
||||
return closureContext.outerWasUsed;
|
||||
}
|
||||
|
||||
private void generateBridge(String className, FunctionDescriptor funDescriptor, JetExpression fun, ClassBuilder cv) {
|
||||
final Method bridge = erasedInvokeSignature(funDescriptor);
|
||||
final Method delegate = invokeSignature(funDescriptor);
|
||||
final JvmMethodSignature bridge = erasedInvokeSignature(funDescriptor);
|
||||
final Method delegate = invokeSignature(funDescriptor).getAsmMethod();
|
||||
|
||||
if(bridge.getDescriptor().equals(delegate.getDescriptor()))
|
||||
if(bridge.getAsmMethod().getDescriptor().equals(delegate.getDescriptor()))
|
||||
return;
|
||||
|
||||
final MethodVisitor mv = cv.newMethod(fun, ACC_PUBLIC, "invoke", bridge.getDescriptor(), null, new String[0]);
|
||||
final MethodVisitor mv = cv.newMethod(fun, ACC_PUBLIC, "invoke", bridge.getAsmMethod().getDescriptor(), null, new String[0]);
|
||||
if (cv.generateCode()) {
|
||||
mv.visitCode();
|
||||
|
||||
|
||||
@@ -207,11 +207,11 @@ public abstract class CodegenContext {
|
||||
if(accessor != null)
|
||||
return accessor;
|
||||
|
||||
if(descriptor instanceof FunctionDescriptor) {
|
||||
FunctionDescriptorImpl myAccessor = new FunctionDescriptorImpl(contextType,
|
||||
if(descriptor instanceof NamedFunctionDescriptor) {
|
||||
NamedFunctionDescriptorImpl myAccessor = new NamedFunctionDescriptorImpl(contextType,
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
descriptor.getName() + "$bridge$" + accessors.size());
|
||||
FunctionDescriptor fd = (FunctionDescriptor) descriptor;
|
||||
FunctionDescriptor fd = (NamedFunctionDescriptor) descriptor;
|
||||
myAccessor.initialize(fd.getReceiverParameter().exists() ? fd.getReceiverParameter().getType() : null,
|
||||
fd.getExpectedThisObject(),
|
||||
fd.getTypeParameters(),
|
||||
@@ -241,11 +241,9 @@ public abstract class CodegenContext {
|
||||
pgd.initialize(myAccessor.getOutType());
|
||||
|
||||
PropertySetterDescriptor psd = new PropertySetterDescriptor(
|
||||
myAccessor.getModality(),
|
||||
myAccessor, Collections.<AnnotationDescriptor>emptyList(), myAccessor.getModality(),
|
||||
myAccessor.getVisibility(),
|
||||
myAccessor,
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
false, false);
|
||||
false, false);
|
||||
myAccessor.initialize(pgd, psd);
|
||||
accessor = myAccessor;
|
||||
}
|
||||
|
||||
@@ -85,9 +85,9 @@ public class CodegenUtil {
|
||||
return hasDerivedTypeInfoField(type);
|
||||
}
|
||||
|
||||
public static FunctionDescriptor createInvoke(ExpressionAsFunctionDescriptor fd) {
|
||||
public static NamedFunctionDescriptor createInvoke(ExpressionAsFunctionDescriptor fd) {
|
||||
int arity = fd.getValueParameters().size();
|
||||
FunctionDescriptorImpl invokeDescriptor = new FunctionDescriptorImpl(
|
||||
NamedFunctionDescriptorImpl invokeDescriptor = new NamedFunctionDescriptorImpl(
|
||||
fd.getExpectedThisObject().exists() ? JetStandardClasses.getReceiverFunction(arity) : JetStandardClasses.getFunction(arity),
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
"invoke");
|
||||
|
||||
@@ -1097,7 +1097,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
}
|
||||
}
|
||||
if(!(containingDeclaration instanceof JavaNamespaceDescriptor) && !(containingDeclaration instanceof JavaClassDescriptor))
|
||||
getter = typeMapper.mapGetterSignature(propertyDescriptor, OwnerKind.IMPLEMENTATION).getAsmMethod();
|
||||
getter = typeMapper.mapGetterSignature(propertyDescriptor, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
|
||||
else
|
||||
getter = null;
|
||||
}
|
||||
@@ -1107,8 +1107,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
}
|
||||
else {
|
||||
if(!(containingDeclaration instanceof JavaNamespaceDescriptor) && !(containingDeclaration instanceof JavaClassDescriptor)) {
|
||||
JvmMethodSignature jvmMethodSignature = typeMapper.mapSetterSignature(propertyDescriptor, OwnerKind.IMPLEMENTATION);
|
||||
setter = jvmMethodSignature != null ? jvmMethodSignature.getAsmMethod() : null;
|
||||
JvmPropertyAccessorSignature jvmMethodSignature = typeMapper.mapSetterSignature(propertyDescriptor, OwnerKind.IMPLEMENTATION);
|
||||
setter = jvmMethodSignature != null ? jvmMethodSignature.getJvmMethodSignature().getAsmMethod() : null;
|
||||
} else {
|
||||
setter = null;
|
||||
}
|
||||
@@ -1218,7 +1218,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
callableMethod = ClosureCodegen.asCallableMethod((FunctionDescriptor) fd);
|
||||
}
|
||||
else if (fd instanceof ExpressionAsFunctionDescriptor) {
|
||||
FunctionDescriptor invoke = CodegenUtil.createInvoke((ExpressionAsFunctionDescriptor) fd);
|
||||
NamedFunctionDescriptor invoke = CodegenUtil.createInvoke((ExpressionAsFunctionDescriptor) fd);
|
||||
callableMethod = ClosureCodegen.asCallableMethod(invoke);
|
||||
}
|
||||
else if (fd instanceof FunctionDescriptor) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
@@ -40,21 +41,22 @@ public class FunctionCodegen {
|
||||
}
|
||||
|
||||
public void gen(JetNamedFunction f) {
|
||||
final FunctionDescriptor functionDescriptor = state.getBindingContext().get(BindingContext.FUNCTION, f);
|
||||
final NamedFunctionDescriptor functionDescriptor = state.getBindingContext().get(BindingContext.FUNCTION, f);
|
||||
assert functionDescriptor != null;
|
||||
JvmMethodSignature method = typeMapper.mapToCallableMethod(functionDescriptor, false, owner.getContextKind()).getSignature();
|
||||
generateMethod(f, method, functionDescriptor);
|
||||
generateMethod(f, method, null, functionDescriptor);
|
||||
}
|
||||
|
||||
public void generateMethod(JetDeclarationWithBody f, JvmMethodSignature jvmMethod, FunctionDescriptor functionDescriptor) {
|
||||
public void generateMethod(JetDeclarationWithBody f, JvmMethodSignature jvmMethod, @Nullable String propertyTypeSignature, FunctionDescriptor functionDescriptor) {
|
||||
CodegenContext.MethodContext funContext = owner.intoFunction(functionDescriptor);
|
||||
|
||||
final JetExpression bodyExpression = f.getBodyExpression();
|
||||
generatedMethod(bodyExpression, jvmMethod, funContext, functionDescriptor, f);
|
||||
generatedMethod(bodyExpression, jvmMethod, propertyTypeSignature, funContext, functionDescriptor, f);
|
||||
}
|
||||
|
||||
private void generatedMethod(JetExpression bodyExpressions,
|
||||
JvmMethodSignature jvmSignature,
|
||||
@Nullable String propertyTypeSignature,
|
||||
CodegenContext.MethodContext context,
|
||||
FunctionDescriptor functionDescriptor, JetDeclarationWithBody fun)
|
||||
{
|
||||
@@ -91,17 +93,26 @@ public class FunctionCodegen {
|
||||
if(v.generateCode()) {
|
||||
int start = 0;
|
||||
if(kind != OwnerKind.TRAIT_IMPL) {
|
||||
AnnotationVisitor av = mv.visitAnnotation(JvmStdlibNames.JET_METHOD.getDescriptor(), true);
|
||||
if(functionDescriptor.getReturnType().isNullable()) {
|
||||
av.visit(JvmStdlibNames.JET_METHOD_NULLABLE_RETURN_TYPE_FIELD, true);
|
||||
if (functionDescriptor instanceof PropertyAccessorDescriptor) {
|
||||
PropertyCodegen.generateJetPropertyAnnotation(mv, propertyTypeSignature, jvmSignature.getKotlinTypeParameter());
|
||||
} else if (functionDescriptor instanceof NamedFunctionDescriptor) {
|
||||
if (propertyTypeSignature != null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
AnnotationVisitor av = mv.visitAnnotation(JvmStdlibNames.JET_METHOD.getDescriptor(), true);
|
||||
if(functionDescriptor.getReturnType().isNullable()) {
|
||||
av.visit(JvmStdlibNames.JET_METHOD_NULLABLE_RETURN_TYPE_FIELD, true);
|
||||
}
|
||||
if (jvmSignature.getKotlinReturnType() != null) {
|
||||
av.visit(JvmStdlibNames.JET_METHOD_RETURN_TYPE_FIELD, jvmSignature.getKotlinReturnType());
|
||||
}
|
||||
if (jvmSignature.getKotlinTypeParameter() != null) {
|
||||
av.visit(JvmStdlibNames.JET_METHOD_TYPE_PARAMETERS_FIELD, jvmSignature.getKotlinTypeParameter());
|
||||
}
|
||||
av.visitEnd();
|
||||
} else {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
if (jvmSignature.getKotlinReturnType() != null) {
|
||||
av.visit(JvmStdlibNames.JET_METHOD_RETURN_TYPE_FIELD, jvmSignature.getKotlinReturnType());
|
||||
}
|
||||
if (jvmSignature.getKotlinTypeParameter() != null) {
|
||||
av.visit(JvmStdlibNames.JET_METHOD_TYPE_PARAMETERS_FIELD, jvmSignature.getKotlinTypeParameter());
|
||||
}
|
||||
av.visitEnd();
|
||||
}
|
||||
|
||||
if(kind == OwnerKind.TRAIT_IMPL) {
|
||||
@@ -134,7 +145,7 @@ public class FunctionCodegen {
|
||||
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_NULLABLE_FIELD, true);
|
||||
}
|
||||
if (jvmSignature.getKotlinParameterTypes() != null && jvmSignature.getKotlinParameterTypes().get(i) != null) {
|
||||
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_TYPE_FIELD, jvmSignature.getKotlinParameterTypes().get(i + start));
|
||||
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_TYPE_FIELD, jvmSignature.getKotlinParameterTypes().get(i + start).getKotlinSignature());
|
||||
}
|
||||
av.visitEnd();
|
||||
}
|
||||
@@ -241,7 +252,7 @@ public class FunctionCodegen {
|
||||
|
||||
public static void endVisit(MethodVisitor mv, String description, PsiElement method) {
|
||||
try {
|
||||
mv.visitMaxs(0, 0);
|
||||
mv.visitMaxs(-1, -1);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
throw new CompilationException("wrong code generated" + (description != null ? " for " + description : "") + t.getClass().getName() + " " + t.getMessage(), t, method);
|
||||
|
||||
@@ -115,7 +115,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
|
||||
LinkedHashSet<String> superInterfacesLinkedHashSet = new LinkedHashSet<String>();
|
||||
|
||||
BothSignatureWriter signatureVisitor = new BothSignatureWriter(BothSignatureWriter.Mode.CLASS);
|
||||
// TODO: generics signature is not always needed
|
||||
BothSignatureWriter signatureVisitor = new BothSignatureWriter(BothSignatureWriter.Mode.CLASS, true);
|
||||
|
||||
|
||||
{ // type parameters
|
||||
@@ -237,50 +238,58 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
PropertyDescriptor bridge = (PropertyDescriptor) entry.getValue();
|
||||
PropertyDescriptor original = (PropertyDescriptor) entry.getKey();
|
||||
|
||||
Method method = typeMapper.mapGetterSignature(bridge, OwnerKind.IMPLEMENTATION).getAsmMethod();
|
||||
Method originalMethod = typeMapper.mapGetterSignature(original, OwnerKind.IMPLEMENTATION).getAsmMethod();
|
||||
MethodVisitor mv = v.newMethod(null, Opcodes.ACC_PUBLIC|Opcodes.ACC_BRIDGE|Opcodes.ACC_FINAL, method.getName(), method.getDescriptor(), null, null);
|
||||
mv.visitAnnotation(JvmStdlibNames.JET_PROPERTY.getDescriptor(), true).visitEnd();
|
||||
InstructionAdapter iv = null;
|
||||
if (v.generateCode()) {
|
||||
mv.visitCode();
|
||||
{
|
||||
Method method = typeMapper.mapGetterSignature(bridge, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
|
||||
JvmPropertyAccessorSignature originalSignature = typeMapper.mapGetterSignature(original, OwnerKind.IMPLEMENTATION);
|
||||
Method originalMethod = originalSignature.getJvmMethodSignature().getAsmMethod();
|
||||
MethodVisitor mv = v.newMethod(null, Opcodes.ACC_PUBLIC | Opcodes.ACC_BRIDGE | Opcodes.ACC_FINAL, method.getName(), method.getDescriptor(), null, null);
|
||||
PropertyCodegen.generateJetPropertyAnnotation(mv, originalSignature.getPropertyTypeKotlinSignature(), originalSignature.getJvmMethodSignature().getKotlinTypeParameter());
|
||||
mv.visitAnnotation(JvmStdlibNames.JET_PROPERTY.getDescriptor(), true).visitEnd();
|
||||
if (v.generateCode()) {
|
||||
mv.visitCode();
|
||||
|
||||
iv = new InstructionAdapter(mv);
|
||||
InstructionAdapter iv = new InstructionAdapter(mv);
|
||||
|
||||
iv.load(0, JetTypeMapper.TYPE_OBJECT);
|
||||
if(original.getVisibility() == Visibility.PRIVATE)
|
||||
iv.getfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), original.getName(), originalMethod.getReturnType().getDescriptor());
|
||||
else
|
||||
iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), originalMethod.getName(), originalMethod.getDescriptor());
|
||||
iv.load(0, JetTypeMapper.TYPE_OBJECT);
|
||||
if(original.getVisibility() == Visibility.PRIVATE)
|
||||
iv.getfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), original.getName(), originalMethod.getReturnType().getDescriptor());
|
||||
else
|
||||
iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), originalMethod.getName(), originalMethod.getDescriptor());
|
||||
|
||||
iv.areturn(method.getReturnType());
|
||||
FunctionCodegen.endVisit(iv, "accessor", null);
|
||||
iv.areturn(method.getReturnType());
|
||||
FunctionCodegen.endVisit(iv, "accessor", null);
|
||||
}
|
||||
}
|
||||
|
||||
method = typeMapper.mapSetterSignature(bridge, OwnerKind.IMPLEMENTATION).getAsmMethod();
|
||||
originalMethod = typeMapper.mapSetterSignature(original, OwnerKind.IMPLEMENTATION).getAsmMethod();
|
||||
mv = v.newMethod(null, Opcodes.ACC_PUBLIC|Opcodes.ACC_BRIDGE|Opcodes.ACC_FINAL, method.getName(), method.getDescriptor(), null, null);
|
||||
mv.visitAnnotation(JvmStdlibNames.JET_PROPERTY.getDescriptor(), true).visitEnd();
|
||||
if (v.generateCode()) {
|
||||
mv.visitCode();
|
||||
{
|
||||
|
||||
iv = new InstructionAdapter(mv);
|
||||
Method method = typeMapper.mapSetterSignature(bridge, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
|
||||
JvmPropertyAccessorSignature originalSignature2 = typeMapper.mapSetterSignature(original, OwnerKind.IMPLEMENTATION);
|
||||
Method originalMethod = originalSignature2.getJvmMethodSignature().getAsmMethod();
|
||||
MethodVisitor mv = v.newMethod(null, Opcodes.ACC_PUBLIC | Opcodes.ACC_BRIDGE | Opcodes.ACC_FINAL, method.getName(), method.getDescriptor(), null, null);
|
||||
PropertyCodegen.generateJetPropertyAnnotation(mv, originalSignature2.getPropertyTypeKotlinSignature(), originalSignature2.getJvmMethodSignature().getKotlinTypeParameter());
|
||||
mv.visitAnnotation(JvmStdlibNames.JET_PROPERTY.getDescriptor(), true).visitEnd();
|
||||
if (v.generateCode()) {
|
||||
mv.visitCode();
|
||||
|
||||
iv.load(0, JetTypeMapper.TYPE_OBJECT);
|
||||
Type[] argTypes = method.getArgumentTypes();
|
||||
for (int i = 0, reg = 1; i < argTypes.length; i++) {
|
||||
Type argType = argTypes[i];
|
||||
iv.load(reg, argType);
|
||||
//noinspection AssignmentToForLoopParameter
|
||||
reg += argType.getSize();
|
||||
InstructionAdapter iv = new InstructionAdapter(mv);
|
||||
|
||||
iv.load(0, JetTypeMapper.TYPE_OBJECT);
|
||||
Type[] argTypes = method.getArgumentTypes();
|
||||
for (int i = 0, reg = 1; i < argTypes.length; i++) {
|
||||
Type argType = argTypes[i];
|
||||
iv.load(reg, argType);
|
||||
//noinspection AssignmentToForLoopParameter
|
||||
reg += argType.getSize();
|
||||
}
|
||||
if(original.getVisibility() == Visibility.PRIVATE)
|
||||
iv.putfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), original.getName(), originalMethod.getArgumentTypes()[0].getDescriptor());
|
||||
else
|
||||
iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), originalMethod.getName(), originalMethod.getDescriptor());
|
||||
|
||||
iv.areturn(method.getReturnType());
|
||||
FunctionCodegen.endVisit(iv, "accessor", null);
|
||||
}
|
||||
if(original.getVisibility() == Visibility.PRIVATE)
|
||||
iv.putfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), original.getName(), originalMethod.getArgumentTypes()[0].getDescriptor());
|
||||
else
|
||||
iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), originalMethod.getName(), originalMethod.getDescriptor());
|
||||
|
||||
iv.areturn(method.getReturnType());
|
||||
FunctionCodegen.endVisit(iv, "accessor", null);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -343,17 +352,31 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
Method constructorMethod;
|
||||
CallableMethod callableMethod;
|
||||
if (constructorDescriptor == null) {
|
||||
List<Type> parameterTypes = new ArrayList<Type>();
|
||||
|
||||
BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, false);
|
||||
|
||||
signatureWriter.writeFormalTypeParametersStart();
|
||||
signatureWriter.writeFormalTypeParametersEnd();
|
||||
|
||||
signatureWriter.writeParametersStart();
|
||||
|
||||
if (CodegenUtil.hasThis0(descriptor)) {
|
||||
parameterTypes.add(typeMapper.mapType(CodegenUtil.getOuterClassDescriptor(descriptor).getDefaultType(), OwnerKind.IMPLEMENTATION));
|
||||
signatureWriter.writeParameterType(JvmMethodParameterKind.THIS0);
|
||||
typeMapper.mapType(CodegenUtil.getOuterClassDescriptor(descriptor).getDefaultType(), OwnerKind.IMPLEMENTATION, signatureWriter, false);
|
||||
signatureWriter.writeParameterTypeEnd();
|
||||
}
|
||||
|
||||
if (CodegenUtil.requireTypeInfoConstructorArg(descriptor.getDefaultType())) {
|
||||
parameterTypes.add(JetTypeMapper.TYPE_TYPEINFO);
|
||||
signatureWriter.writeTypeInfoParameter();
|
||||
}
|
||||
|
||||
constructorMethod = new Method("<init>", Type.VOID_TYPE, parameterTypes.toArray(new Type[parameterTypes.size()]));
|
||||
callableMethod = new CallableMethod("", new JvmMethodSignature(constructorMethod, null, null, null, null) /* TODO */, Opcodes.INVOKESPECIAL, Collections.<Type>emptyList());
|
||||
signatureWriter.writeParametersEnd();
|
||||
|
||||
signatureWriter.writeVoidReturn();
|
||||
|
||||
JvmMethodSignature jvmMethodSignature = signatureWriter.makeJvmMethodSignature("<init>");
|
||||
constructorMethod = jvmMethodSignature.getAsmMethod();
|
||||
callableMethod = new CallableMethod("", jvmMethodSignature, Opcodes.INVOKESPECIAL);
|
||||
}
|
||||
else {
|
||||
callableMethod = typeMapper.mapToCallableMethod(constructorDescriptor, kind);
|
||||
@@ -445,8 +468,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
|
||||
HashSet<FunctionDescriptor> overridden = new HashSet<FunctionDescriptor>();
|
||||
for (JetDeclaration declaration : myClass.getDeclarations()) {
|
||||
if (declaration instanceof JetFunction) {
|
||||
FunctionDescriptor functionDescriptor = bindingContext.get(BindingContext.FUNCTION, declaration);
|
||||
if (declaration instanceof JetNamedFunction) {
|
||||
NamedFunctionDescriptor functionDescriptor = bindingContext.get(BindingContext.FUNCTION, declaration);
|
||||
assert functionDescriptor != null;
|
||||
overridden.addAll(functionDescriptor.getOverriddenDescriptors());
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaNamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
@@ -35,27 +36,11 @@ public class JetTypeMapper {
|
||||
public static final Type TYPE_TYPEINFOPROJECTION = Type.getType(TypeInfoProjection.class);
|
||||
public static final Type TYPE_JET_OBJECT = Type.getType(JetObject.class);
|
||||
public static final Type TYPE_NOTHING = Type.getObjectType("jet/Nothing");
|
||||
public static final Type JL_INTEGER_TYPE = Type.getObjectType("java/lang/Integer");
|
||||
public static final Type JL_LONG_TYPE = Type.getObjectType("java/lang/Long");
|
||||
public static final Type JL_SHORT_TYPE = Type.getObjectType("java/lang/Short");
|
||||
public static final Type JL_BYTE_TYPE = Type.getObjectType("java/lang/Byte");
|
||||
public static final Type JL_CHAR_TYPE = Type.getObjectType("java/lang/Character");
|
||||
public static final Type JL_FLOAT_TYPE = Type.getObjectType("java/lang/Float");
|
||||
public static final Type JL_DOUBLE_TYPE = Type.getObjectType("java/lang/Double");
|
||||
public static final Type JL_BOOLEAN_TYPE = Type.getObjectType("java/lang/Boolean");
|
||||
public static final Type JL_NUMBER_TYPE = Type.getObjectType("java/lang/Number");
|
||||
public static final Type JL_STRING_BUILDER = Type.getObjectType("java/lang/StringBuilder");
|
||||
public static final Type JL_STRING_TYPE = Type.getObjectType("java/lang/String");
|
||||
private static final Type JL_COMPARABLE_TYPE = Type.getObjectType("java/lang/Comparable");
|
||||
|
||||
public static final Type ARRAY_INT_TYPE = Type.getType(int[].class);
|
||||
public static final Type ARRAY_LONG_TYPE = Type.getType(long[].class);
|
||||
public static final Type ARRAY_SHORT_TYPE = Type.getType(short[].class);
|
||||
public static final Type ARRAY_BYTE_TYPE = Type.getType(byte[].class);
|
||||
public static final Type ARRAY_CHAR_TYPE = Type.getType(char[].class);
|
||||
public static final Type ARRAY_FLOAT_TYPE = Type.getType(float[].class);
|
||||
public static final Type ARRAY_DOUBLE_TYPE = Type.getType(double[].class);
|
||||
public static final Type ARRAY_BOOL_TYPE = Type.getType(boolean[].class);
|
||||
public static final Type ARRAY_GENERIC_TYPE = Type.getType(Object[].class);
|
||||
|
||||
private final JetStandardLibrary standardLibrary;
|
||||
@@ -77,14 +62,6 @@ public class JetTypeMapper {
|
||||
public static final Type TYPE_SHARED_CHAR = Type.getObjectType("jet/runtime/SharedVar$Char");
|
||||
public static final Type TYPE_SHARED_LONG = Type.getObjectType("jet/runtime/SharedVar$Long");
|
||||
public static final Type TYPE_SHARED_BOOLEAN = Type.getObjectType("jet/runtime/SharedVar$Boolean");
|
||||
public static final Type TYPE_BOOLEAN_ITERATOR = Type.getObjectType("jet/BooleanIterator");
|
||||
public static final Type TYPE_CHAR_ITERATOR = Type.getObjectType("jet/CharIterator");
|
||||
public static final Type TYPE_BYTE_ITERATOR = Type.getObjectType("jet/ByteIterator");
|
||||
public static final Type TYPE_SHORT_ITERATOR = Type.getObjectType("jet/ShortIterator");
|
||||
public static final Type TYPE_INT_ITERATOR = Type.getObjectType("jet/IntIterator");
|
||||
public static final Type TYPE_LONG_ITERATOR = Type.getObjectType("jet/LongIterator");
|
||||
public static final Type TYPE_FLOAT_ITERATOR = Type.getObjectType("jet/FloatIterator");
|
||||
public static final Type TYPE_DOUBLE_ITERATOR = Type.getObjectType("jet/DoubleIterator");
|
||||
public static final Type TYPE_FUNCTION0 = Type.getObjectType("jet/Function0");
|
||||
public static final Type TYPE_FUNCTION1 = Type.getObjectType("jet/Function1");
|
||||
|
||||
@@ -107,28 +84,6 @@ public class JetTypeMapper {
|
||||
return type.getSort() != Type.OBJECT && type.getSort() != Type.ARRAY;
|
||||
}
|
||||
|
||||
public static Type getBoxedType(final Type type) {
|
||||
switch (type.getSort()) {
|
||||
case Type.BYTE:
|
||||
return JL_BYTE_TYPE;
|
||||
case Type.BOOLEAN:
|
||||
return JL_BOOLEAN_TYPE;
|
||||
case Type.SHORT:
|
||||
return JL_SHORT_TYPE;
|
||||
case Type.CHAR:
|
||||
return JL_CHAR_TYPE;
|
||||
case Type.INT:
|
||||
return JL_INTEGER_TYPE;
|
||||
case Type.FLOAT:
|
||||
return JL_FLOAT_TYPE;
|
||||
case Type.LONG:
|
||||
return JL_LONG_TYPE;
|
||||
case Type.DOUBLE:
|
||||
return JL_DOUBLE_TYPE;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
public static Type correctElementType(Type type) {
|
||||
String internalName = type.getInternalName();
|
||||
assert internalName.charAt(0) == '[';
|
||||
@@ -351,12 +306,13 @@ public class JetTypeMapper {
|
||||
}
|
||||
|
||||
if (descriptor instanceof TypeParameterDescriptor) {
|
||||
|
||||
Type type = mapType(((TypeParameterDescriptor) descriptor).getUpperBoundsAsType(), kind);
|
||||
if (signatureVisitor != null) {
|
||||
TypeParameterDescriptor typeParameterDescriptor = (TypeParameterDescriptor) jetType.getConstructor().getDeclarationDescriptor();
|
||||
signatureVisitor.writeTypeVariable(typeParameterDescriptor.getName(), jetType.isNullable());
|
||||
signatureVisitor.writeTypeVariable(typeParameterDescriptor.getName(), jetType.isNullable(), type);
|
||||
}
|
||||
|
||||
return mapType(((TypeParameterDescriptor) descriptor).getUpperBoundsAsType(), kind);
|
||||
return type;
|
||||
}
|
||||
|
||||
throw new UnsupportedOperationException("Unknown type " + jetType);
|
||||
@@ -378,56 +334,21 @@ public class JetTypeMapper {
|
||||
}
|
||||
|
||||
public static Type unboxType(final Type type) {
|
||||
if (type == JL_INTEGER_TYPE) {
|
||||
return Type.INT_TYPE;
|
||||
JvmPrimitiveType jvmPrimitiveType = JvmPrimitiveType.getByWrapperAsmType(type);
|
||||
if (jvmPrimitiveType != null) {
|
||||
return jvmPrimitiveType.getAsmType();
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Unboxing: " + type);
|
||||
}
|
||||
else if (type == JL_BOOLEAN_TYPE) {
|
||||
return Type.BOOLEAN_TYPE;
|
||||
}
|
||||
else if (type == JL_CHAR_TYPE) {
|
||||
return Type.CHAR_TYPE;
|
||||
}
|
||||
else if (type == JL_SHORT_TYPE) {
|
||||
return Type.SHORT_TYPE;
|
||||
}
|
||||
else if (type == JL_LONG_TYPE) {
|
||||
return Type.LONG_TYPE;
|
||||
}
|
||||
else if (type == JL_BYTE_TYPE) {
|
||||
return Type.BYTE_TYPE;
|
||||
}
|
||||
else if (type == JL_FLOAT_TYPE) {
|
||||
return Type.FLOAT_TYPE;
|
||||
}
|
||||
else if (type == JL_DOUBLE_TYPE) {
|
||||
return Type.DOUBLE_TYPE;
|
||||
}
|
||||
throw new UnsupportedOperationException("Unboxing: " + type);
|
||||
}
|
||||
|
||||
public static Type boxType(Type asmType) {
|
||||
switch (asmType.getSort()) {
|
||||
case Type.VOID:
|
||||
return Type.VOID_TYPE;
|
||||
case Type.BYTE:
|
||||
return JL_BYTE_TYPE;
|
||||
case Type.BOOLEAN:
|
||||
return JL_BOOLEAN_TYPE;
|
||||
case Type.SHORT:
|
||||
return JL_SHORT_TYPE;
|
||||
case Type.CHAR:
|
||||
return JL_CHAR_TYPE;
|
||||
case Type.INT:
|
||||
return JL_INTEGER_TYPE;
|
||||
case Type.FLOAT:
|
||||
return JL_FLOAT_TYPE;
|
||||
case Type.LONG:
|
||||
return JL_LONG_TYPE;
|
||||
case Type.DOUBLE:
|
||||
return JL_DOUBLE_TYPE;
|
||||
JvmPrimitiveType jvmPrimitiveType = JvmPrimitiveType.getByAsmType(asmType);
|
||||
if (jvmPrimitiveType != null) {
|
||||
return jvmPrimitiveType.getWrapper().getAsmType();
|
||||
} else {
|
||||
return asmType;
|
||||
}
|
||||
|
||||
return asmType;
|
||||
}
|
||||
|
||||
public CallableMethod mapToCallableMethod(FunctionDescriptor functionDescriptor, boolean superCall, OwnerKind kind) {
|
||||
@@ -435,8 +356,7 @@ public class JetTypeMapper {
|
||||
return null;
|
||||
|
||||
final DeclarationDescriptor functionParent = functionDescriptor.getContainingDeclaration();
|
||||
final List<Type> valueParameterTypes = new ArrayList<Type>();
|
||||
JvmMethodSignature descriptor = mapSignature(functionDescriptor.getOriginal(), true, valueParameterTypes, kind);
|
||||
JvmMethodSignature descriptor = mapSignature(functionDescriptor.getOriginal(), true, kind);
|
||||
String owner;
|
||||
int invokeOpcode;
|
||||
ClassDescriptor thisClass;
|
||||
@@ -463,7 +383,7 @@ public class JetTypeMapper {
|
||||
? (superCall ? Opcodes.INVOKESTATIC : Opcodes.INVOKEINTERFACE)
|
||||
: (superCall ? Opcodes.INVOKESPECIAL : Opcodes.INVOKEVIRTUAL);
|
||||
if(isInterface && superCall) {
|
||||
descriptor = mapSignature(functionDescriptor.getOriginal(), false, valueParameterTypes, OwnerKind.TRAIT_IMPL);
|
||||
descriptor = mapSignature(functionDescriptor.getOriginal(), false, OwnerKind.TRAIT_IMPL);
|
||||
}
|
||||
thisClass = (ClassDescriptor) functionParent;
|
||||
}
|
||||
@@ -471,7 +391,7 @@ public class JetTypeMapper {
|
||||
throw new UnsupportedOperationException("unknown function parent");
|
||||
}
|
||||
|
||||
final CallableMethod result = new CallableMethod(owner, descriptor, invokeOpcode, valueParameterTypes);
|
||||
final CallableMethod result = new CallableMethod(owner, descriptor, invokeOpcode);
|
||||
result.setNeedsThis(thisClass);
|
||||
if(functionDescriptor.getReceiverParameter().exists()) {
|
||||
result.setNeedsReceiver(functionDescriptor);
|
||||
@@ -480,107 +400,63 @@ public class JetTypeMapper {
|
||||
return result;
|
||||
}
|
||||
|
||||
private JvmMethodSignature mapSignature(FunctionDescriptor f, boolean needGenericSignature, List<Type> valueParameterTypes, OwnerKind kind) {
|
||||
private JvmMethodSignature mapSignature(FunctionDescriptor f, boolean needGenericSignature, OwnerKind kind) {
|
||||
|
||||
for (ValueParameterDescriptor valueParameterDescriptor : f.getValueParameters()) {
|
||||
if (valueParameterDescriptor.hasDefaultValue()) {
|
||||
// TODO
|
||||
needGenericSignature = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (kind == OwnerKind.TRAIT_IMPL) {
|
||||
needGenericSignature = false;
|
||||
}
|
||||
|
||||
BothSignatureWriter signatureVisitor = null;
|
||||
if (needGenericSignature) {
|
||||
signatureVisitor = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD);
|
||||
}
|
||||
BothSignatureWriter signatureVisitor = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, needGenericSignature);
|
||||
|
||||
writeFormalTypeParameters(f.getTypeParameters(), signatureVisitor);
|
||||
|
||||
final ReceiverDescriptor receiverTypeRef = f.getReceiverParameter();
|
||||
final JetType receiverType = !receiverTypeRef.exists() ? null : receiverTypeRef.getType();
|
||||
final List<ValueParameterDescriptor> parameters = f.getValueParameters();
|
||||
List<Type> parameterTypes = new ArrayList<Type>();
|
||||
|
||||
signatureVisitor.writeParametersStart();
|
||||
|
||||
if(kind == OwnerKind.TRAIT_IMPL) {
|
||||
ClassDescriptor containingDeclaration = (ClassDescriptor) f.getContainingDeclaration();
|
||||
JetType jetType = TraitImplBodyCodegen.getSuperClass(containingDeclaration, bindingContext);
|
||||
Type type = mapType(jetType, signatureVisitor);
|
||||
Type type = mapType(jetType);
|
||||
if(type.getInternalName().equals("java/lang/Object")) {
|
||||
jetType = containingDeclaration.getDefaultType();
|
||||
type = mapType(jetType, signatureVisitor);
|
||||
type = mapType(jetType);
|
||||
}
|
||||
valueParameterTypes.add(type);
|
||||
parameterTypes.add(type);
|
||||
|
||||
signatureVisitor.writeParameterType(JvmMethodParameterKind.THIS);
|
||||
signatureVisitor.writeAsmType(type, jetType.isNullable());
|
||||
signatureVisitor.writeParameterTypeEnd();
|
||||
}
|
||||
|
||||
if (receiverType != null) {
|
||||
if (signatureVisitor != null) {
|
||||
signatureVisitor.writeParameterType();
|
||||
}
|
||||
parameterTypes.add(mapType(receiverType, signatureVisitor));
|
||||
if (signatureVisitor != null) {
|
||||
signatureVisitor.writeParameterTypeEnd();
|
||||
}
|
||||
}
|
||||
if (signatureVisitor != null) {
|
||||
signatureVisitor.writeParametersStart();
|
||||
signatureVisitor.writeParameterType(JvmMethodParameterKind.RECEIVER);
|
||||
mapType(receiverType, signatureVisitor);
|
||||
signatureVisitor.writeParameterTypeEnd();
|
||||
}
|
||||
|
||||
for (TypeParameterDescriptor parameterDescriptor : f.getTypeParameters()) {
|
||||
if(parameterDescriptor.isReified()) {
|
||||
parameterTypes.add(TYPE_TYPEINFO);
|
||||
if (signatureVisitor != null) {
|
||||
signatureVisitor.writeParameterType();
|
||||
visitAsmType(signatureVisitor, TYPE_TYPEINFO, false);
|
||||
signatureVisitor.writeParameterTypeEnd();
|
||||
}
|
||||
signatureVisitor.writeTypeInfoParameter();
|
||||
}
|
||||
}
|
||||
for (ValueParameterDescriptor parameter : parameters) {
|
||||
if (signatureVisitor != null) {
|
||||
signatureVisitor.writeParameterType();
|
||||
}
|
||||
Type type = mapType(parameter.getOutType(), signatureVisitor);
|
||||
if (signatureVisitor != null) {
|
||||
signatureVisitor.writeParameterTypeEnd();
|
||||
}
|
||||
valueParameterTypes.add(type);
|
||||
parameterTypes.add(type);
|
||||
signatureVisitor.writeParameterType(JvmMethodParameterKind.VALUE);
|
||||
mapType(parameter.getOutType(), signatureVisitor);
|
||||
signatureVisitor.writeParameterTypeEnd();
|
||||
}
|
||||
|
||||
if (signatureVisitor != null) {
|
||||
signatureVisitor.writeParametersEnd();
|
||||
}
|
||||
|
||||
Type returnType;
|
||||
|
||||
signatureVisitor.writeParametersEnd();
|
||||
|
||||
if (f instanceof ConstructorDescriptor) {
|
||||
returnType = Type.VOID_TYPE;
|
||||
if (signatureVisitor != null) {
|
||||
signatureVisitor.writeReturnType();
|
||||
visitAsmType(signatureVisitor, Type.VOID_TYPE, false);
|
||||
signatureVisitor.writeReturnTypeEnd();
|
||||
}
|
||||
signatureVisitor.writeVoidReturn();
|
||||
} else {
|
||||
if (signatureVisitor != null) {
|
||||
signatureVisitor.writeReturnType();
|
||||
returnType = mapReturnType(f.getReturnType(), signatureVisitor);
|
||||
signatureVisitor.writeReturnTypeEnd();
|
||||
}
|
||||
else {
|
||||
returnType = mapReturnType(f.getReturnType(), null);
|
||||
}
|
||||
}
|
||||
Method method = new Method(f.getName(), returnType, parameterTypes.toArray(new Type[parameterTypes.size()]));
|
||||
if (signatureVisitor == null) {
|
||||
return new JvmMethodSignature(method, null, null, null, null);
|
||||
} else {
|
||||
return new JvmMethodSignature(method, signatureVisitor.makeJavaString(),
|
||||
signatureVisitor.makeKotlinMethodTypeParameters(),
|
||||
signatureVisitor.makeKotlinParameterTypes(),
|
||||
signatureVisitor.makeKotlinReturnTypeSignature());
|
||||
signatureVisitor.writeReturnType();
|
||||
mapReturnType(f.getReturnType(), signatureVisitor);
|
||||
signatureVisitor.writeReturnTypeEnd();
|
||||
}
|
||||
return signatureVisitor.makeJvmMethodSignature(f.getName());
|
||||
}
|
||||
|
||||
|
||||
@@ -589,7 +465,7 @@ public class JetTypeMapper {
|
||||
return;
|
||||
}
|
||||
|
||||
signatureVisitor.writerFormalTypeParametersStart();
|
||||
signatureVisitor.writeFormalTypeParametersStart();
|
||||
for (TypeParameterDescriptor typeParameterDescriptor : typeParameters) {
|
||||
writeFormalTypeParameter(typeParameterDescriptor, signatureVisitor);
|
||||
}
|
||||
@@ -640,103 +516,162 @@ public class JetTypeMapper {
|
||||
|
||||
public JvmMethodSignature mapSignature(String name, FunctionDescriptor f) {
|
||||
final ReceiverDescriptor receiver = f.getReceiverParameter();
|
||||
|
||||
BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, false);
|
||||
|
||||
writeFormalTypeParameters(f.getTypeParameters(), signatureWriter);
|
||||
|
||||
signatureWriter.writeParametersStart();
|
||||
|
||||
final List<ValueParameterDescriptor> parameters = f.getValueParameters();
|
||||
List<Type> parameterTypes = new ArrayList<Type>();
|
||||
if (receiver.exists()) {
|
||||
parameterTypes.add(mapType(receiver.getType()));
|
||||
signatureWriter.writeParameterType(JvmMethodParameterKind.RECEIVER);
|
||||
mapType(receiver.getType(), signatureWriter);
|
||||
signatureWriter.writeParameterTypeEnd();
|
||||
}
|
||||
for (ValueParameterDescriptor parameter : parameters) {
|
||||
parameterTypes.add(mapType(parameter.getOutType()));
|
||||
signatureWriter.writeParameterType(JvmMethodParameterKind.VALUE);
|
||||
mapType(parameter.getOutType(), signatureWriter);
|
||||
signatureWriter.writeParameterTypeEnd();
|
||||
}
|
||||
Type returnType = mapReturnType(f.getReturnType());
|
||||
// TODO: proper generic signature
|
||||
return new JvmMethodSignature(new Method(name, returnType, parameterTypes.toArray(new Type[parameterTypes.size()])), null, null, null, null);
|
||||
|
||||
signatureWriter.writeParametersEnd();
|
||||
|
||||
signatureWriter.writeReturnType();
|
||||
mapReturnType(f.getReturnType(), signatureWriter);
|
||||
signatureWriter.writeReturnTypeEnd();
|
||||
|
||||
return signatureWriter.makeJvmMethodSignature(name);
|
||||
}
|
||||
|
||||
|
||||
public JvmMethodSignature mapGetterSignature(PropertyDescriptor descriptor, OwnerKind kind) {
|
||||
Type returnType = mapType(descriptor.getOutType());
|
||||
|
||||
public JvmPropertyAccessorSignature mapGetterSignature(PropertyDescriptor descriptor, OwnerKind kind) {
|
||||
String name = PropertyCodegen.getterName(descriptor.getName());
|
||||
ArrayList<Type> params = new ArrayList<Type>();
|
||||
|
||||
// TODO: do not generate generics if not needed
|
||||
BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, true);
|
||||
|
||||
writeFormalTypeParameters(descriptor.getTypeParameters(), signatureWriter);
|
||||
|
||||
signatureWriter.writeParametersStart();
|
||||
|
||||
if(kind == OwnerKind.TRAIT_IMPL) {
|
||||
ClassDescriptor containingDeclaration = (ClassDescriptor) descriptor.getContainingDeclaration();
|
||||
assert containingDeclaration != null;
|
||||
params.add(mapType(containingDeclaration.getDefaultType()));
|
||||
signatureWriter.writeParameterType(JvmMethodParameterKind.THIS);
|
||||
mapType(containingDeclaration.getDefaultType(), signatureWriter);
|
||||
signatureWriter.writeParameterTypeEnd();
|
||||
}
|
||||
|
||||
if(descriptor.getReceiverParameter().exists()) {
|
||||
params.add(mapType(descriptor.getReceiverParameter().getType()));
|
||||
signatureWriter.writeParameterType(JvmMethodParameterKind.RECEIVER);
|
||||
mapType(descriptor.getReceiverParameter().getType(), signatureWriter);
|
||||
signatureWriter.writeParameterTypeEnd();
|
||||
}
|
||||
|
||||
for (TypeParameterDescriptor typeParameterDescriptor : descriptor.getTypeParameters()) {
|
||||
if(typeParameterDescriptor.isReified()) {
|
||||
params.add(TYPE_TYPEINFO);
|
||||
signatureWriter.writeTypeInfoParameter();
|
||||
}
|
||||
}
|
||||
|
||||
signatureWriter.writeParametersEnd();
|
||||
|
||||
// TODO: proper generic signature
|
||||
return new JvmMethodSignature(new Method(name, returnType, params.toArray(new Type[params.size()])), null, null, null, null);
|
||||
signatureWriter.writeReturnType();
|
||||
mapType(descriptor.getOutType(), signatureWriter);
|
||||
signatureWriter.writeReturnTypeEnd();
|
||||
|
||||
JvmMethodSignature jvmMethodSignature = signatureWriter.makeJvmMethodSignature(name);
|
||||
|
||||
return new JvmPropertyAccessorSignature(jvmMethodSignature, jvmMethodSignature.getKotlinReturnType());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JvmMethodSignature mapSetterSignature(PropertyDescriptor descriptor, OwnerKind kind) {
|
||||
public JvmPropertyAccessorSignature mapSetterSignature(PropertyDescriptor descriptor, OwnerKind kind) {
|
||||
if (!descriptor.isVar()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO: generics signature is not always needed
|
||||
BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, true);
|
||||
|
||||
writeFormalTypeParameters(descriptor.getTypeParameters(), signatureWriter);
|
||||
|
||||
JetType outType = descriptor.getOutType();
|
||||
|
||||
signatureWriter.writeParametersStart();
|
||||
|
||||
String name = PropertyCodegen.setterName(descriptor.getName());
|
||||
ArrayList<Type> params = new ArrayList<Type>();
|
||||
if(kind == OwnerKind.TRAIT_IMPL) {
|
||||
ClassDescriptor containingDeclaration = (ClassDescriptor) descriptor.getContainingDeclaration();
|
||||
assert containingDeclaration != null;
|
||||
params.add(mapType(containingDeclaration.getDefaultType()));
|
||||
signatureWriter.writeParameterType(JvmMethodParameterKind.THIS);
|
||||
mapType(containingDeclaration.getDefaultType(), signatureWriter);
|
||||
signatureWriter.writeParameterTypeEnd();
|
||||
}
|
||||
|
||||
if(descriptor.getReceiverParameter().exists()) {
|
||||
params.add(mapType(descriptor.getReceiverParameter().getType()));
|
||||
signatureWriter.writeParameterType(JvmMethodParameterKind.RECEIVER);
|
||||
mapType(descriptor.getReceiverParameter().getType(), signatureWriter);
|
||||
signatureWriter.writeParameterTypeEnd();
|
||||
}
|
||||
|
||||
for (TypeParameterDescriptor typeParameterDescriptor : descriptor.getTypeParameters()) {
|
||||
if(typeParameterDescriptor.isReified()) {
|
||||
params.add(TYPE_TYPEINFO);
|
||||
signatureWriter.writeTypeInfoParameter();
|
||||
}
|
||||
}
|
||||
|
||||
params.add(mapType(outType));
|
||||
signatureWriter.writeParameterType(JvmMethodParameterKind.VALUE);
|
||||
mapType(outType, signatureWriter);
|
||||
signatureWriter.writeParameterTypeEnd();
|
||||
|
||||
signatureWriter.writeParametersEnd();
|
||||
|
||||
signatureWriter.writeVoidReturn();
|
||||
|
||||
// TODO: proper generic signature
|
||||
return new JvmMethodSignature(new Method(name, Type.VOID_TYPE, params.toArray(new Type[params.size()])), null, null, null, null);
|
||||
JvmMethodSignature jvmMethodSignature = signatureWriter.makeJvmMethodSignature(name);
|
||||
return new JvmPropertyAccessorSignature(jvmMethodSignature, jvmMethodSignature.getKotlinParameterType(jvmMethodSignature.getParameterCount() - 1));
|
||||
}
|
||||
|
||||
private JvmMethodSignature mapConstructorSignature(ConstructorDescriptor descriptor, List<Type> valueParameterTypes) {
|
||||
private JvmMethodSignature mapConstructorSignature(ConstructorDescriptor descriptor) {
|
||||
|
||||
BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, true);
|
||||
|
||||
List<ValueParameterDescriptor> parameters = descriptor.getOriginal().getValueParameters();
|
||||
List<Type> parameterTypes = new ArrayList<Type>();
|
||||
ClassDescriptor classDescriptor = descriptor.getContainingDeclaration();
|
||||
|
||||
writeFormalTypeParameters(descriptor.getTypeParameters(), signatureWriter);
|
||||
|
||||
signatureWriter.writeParametersStart();
|
||||
|
||||
if (CodegenUtil.hasThis0(classDescriptor)) {
|
||||
parameterTypes.add(mapType(CodegenUtil.getOuterClassDescriptor(classDescriptor).getDefaultType(), OwnerKind.IMPLEMENTATION));
|
||||
signatureWriter.writeParameterType(JvmMethodParameterKind.THIS0);
|
||||
mapType(CodegenUtil.getOuterClassDescriptor(classDescriptor).getDefaultType(), OwnerKind.IMPLEMENTATION, signatureWriter);
|
||||
signatureWriter.writeParameterTypeEnd();
|
||||
}
|
||||
|
||||
if (CodegenUtil.requireTypeInfoConstructorArg(classDescriptor.getDefaultType())) {
|
||||
parameterTypes.add(TYPE_TYPEINFO);
|
||||
signatureWriter.writeTypeInfoParameter();
|
||||
}
|
||||
|
||||
for (ValueParameterDescriptor parameter : parameters) {
|
||||
final Type type = mapType(parameter.getOutType());
|
||||
parameterTypes.add(type);
|
||||
valueParameterTypes.add(type);
|
||||
signatureWriter.writeParameterType(JvmMethodParameterKind.VALUE);
|
||||
mapType(parameter.getOutType(), signatureWriter);
|
||||
signatureWriter.writeParameterTypeEnd();
|
||||
}
|
||||
|
||||
signatureWriter.writeParametersEnd();
|
||||
|
||||
signatureWriter.writeVoidReturn();
|
||||
|
||||
Method method = new Method("<init>", Type.VOID_TYPE, parameterTypes.toArray(new Type[parameterTypes.size()]));
|
||||
return new JvmMethodSignature(method, null, null, null, null); // TODO: generics signature
|
||||
return signatureWriter.makeJvmMethodSignature("<init>");
|
||||
}
|
||||
|
||||
public CallableMethod mapToCallableMethod(ConstructorDescriptor descriptor, OwnerKind kind) {
|
||||
List<Type> valueParameterTypes = new ArrayList<Type>();
|
||||
final JvmMethodSignature method = mapConstructorSignature(descriptor, valueParameterTypes);
|
||||
final JvmMethodSignature method = mapConstructorSignature(descriptor);
|
||||
String owner = mapType(descriptor.getContainingDeclaration().getDefaultType(), kind).getInternalName();
|
||||
return new CallableMethod(owner, method, INVOKESPECIAL, valueParameterTypes);
|
||||
return new CallableMethod(owner, method, INVOKESPECIAL);
|
||||
}
|
||||
|
||||
static int getAccessModifiers(JetDeclaration p, int defaultFlags) {
|
||||
@@ -802,85 +737,39 @@ public class JetTypeMapper {
|
||||
private void initKnownTypeNames() {
|
||||
knowTypeNames.put(JetStandardClasses.getAnyType(), "ANY_TYPE_INFO");
|
||||
knowTypeNames.put(JetStandardClasses.getNullableAnyType(), "NULLABLE_ANY_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getIntType(), "INT_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getNullableIntType(), "NULLABLE_INT_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getLongType(), "LONG_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getNullableLongType(), "NULLABLE_LONG_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getShortType(),"SHORT_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getNullableShortType(),"NULLABLE_SHORT_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getByteType(),"BYTE_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getNullableByteType(),"NULLABLE_BYTE_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getCharType(),"CHAR_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getNullableCharType(),"NULLABLE_CHAR_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getFloatType(),"FLOAT_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getNullableFloatType(),"NULLABLE_FLOAT_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getDoubleType(),"DOUBLE_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getNullableDoubleType(),"NULLABLE_DOUBLE_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getBooleanType(),"BOOLEAN_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getNullableBooleanType(),"NULLABLE_BOOLEAN_TYPE_INFO");
|
||||
|
||||
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
||||
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
|
||||
knowTypeNames.put(standardLibrary.getPrimitiveJetType(primitiveType), jvmPrimitiveType.name() + "_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getNullablePrimitiveJetType(primitiveType), "NULLABLE_" + jvmPrimitiveType.name() + "_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getPrimitiveArrayJetType(primitiveType), jvmPrimitiveType.name() + "_ARRAY_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getNullablePrimitiveArrayJetType(primitiveType), jvmPrimitiveType.name() + "_ARRAY_TYPE_INFO");
|
||||
}
|
||||
|
||||
knowTypeNames.put(standardLibrary.getStringType(),"STRING_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getNullableStringType(),"NULLABLE_STRING_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getTuple0Type(),"TUPLE0_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getNullableTuple0Type(),"NULLABLE_TUPLE0_TYPE_INFO");
|
||||
|
||||
knowTypeNames.put(standardLibrary.getIntArrayType(), "INT_ARRAY_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getLongArrayType(), "LONG_ARRAY_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getShortArrayType(),"SHORT_ARRAY_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getByteArrayType(),"BYTE_ARRAY_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getCharArrayType(),"CHAR_ARRAY_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getFloatArrayType(),"FLOAT_ARRAY_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getDoubleArrayType(),"DOUBLE_ARRAY_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getBooleanArrayType(),"BOOLEAN_ARRAY_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getNullableIntArrayType(), "INT_ARRAY_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getNullableLongArrayType(), "LONG_ARRAY_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getNullableShortArrayType(),"SHORT_ARRAY_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getNullableByteArrayType(),"BYTE_ARRAY_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getNullableCharArrayType(),"CHAR_ARRAY_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getNullableFloatArrayType(),"FLOAT_ARRAY_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getNullableDoubleArrayType(),"DOUBLE_ARRAY_TYPE_INFO");
|
||||
knowTypeNames.put(standardLibrary.getNullableBooleanArrayType(),"BOOLEAN_ARRAY_TYPE_INFO");
|
||||
}
|
||||
|
||||
private void initKnownTypes() {
|
||||
knowTypes.put(JetStandardClasses.getNothingType(), TYPE_NOTHING);
|
||||
knowTypes.put(JetStandardClasses.getNullableNothingType(), TYPE_NOTHING);
|
||||
|
||||
knowTypes.put(standardLibrary.getIntType(), Type.INT_TYPE);
|
||||
knowTypes.put(standardLibrary.getNullableIntType(), JL_INTEGER_TYPE);
|
||||
knowTypes.put(standardLibrary.getLongType(), Type.LONG_TYPE);
|
||||
knowTypes.put(standardLibrary.getNullableLongType(), JL_LONG_TYPE);
|
||||
knowTypes.put(standardLibrary.getShortType(),Type.SHORT_TYPE);
|
||||
knowTypes.put(standardLibrary.getNullableShortType(),JL_SHORT_TYPE);
|
||||
knowTypes.put(standardLibrary.getByteType(),Type.BYTE_TYPE);
|
||||
knowTypes.put(standardLibrary.getNullableByteType(),JL_BYTE_TYPE);
|
||||
knowTypes.put(standardLibrary.getCharType(),Type.CHAR_TYPE);
|
||||
knowTypes.put(standardLibrary.getNullableCharType(),JL_CHAR_TYPE);
|
||||
knowTypes.put(standardLibrary.getFloatType(),Type.FLOAT_TYPE);
|
||||
knowTypes.put(standardLibrary.getNullableFloatType(),JL_FLOAT_TYPE);
|
||||
knowTypes.put(standardLibrary.getDoubleType(),Type.DOUBLE_TYPE);
|
||||
knowTypes.put(standardLibrary.getNullableDoubleType(),JL_DOUBLE_TYPE);
|
||||
knowTypes.put(standardLibrary.getBooleanType(),Type.BOOLEAN_TYPE);
|
||||
knowTypes.put(standardLibrary.getNullableBooleanType(),JL_BOOLEAN_TYPE);
|
||||
|
||||
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
||||
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
|
||||
knowTypes.put(standardLibrary.getPrimitiveJetType(primitiveType), jvmPrimitiveType.getAsmType());
|
||||
knowTypes.put(standardLibrary.getNullablePrimitiveJetType(primitiveType), jvmPrimitiveType.getWrapper().getAsmType());
|
||||
}
|
||||
|
||||
knowTypes.put(standardLibrary.getStringType(),JL_STRING_TYPE);
|
||||
knowTypes.put(standardLibrary.getNullableStringType(),JL_STRING_TYPE);
|
||||
|
||||
knowTypes.put(standardLibrary.getIntArrayType(), ARRAY_INT_TYPE);
|
||||
knowTypes.put(standardLibrary.getLongArrayType(), ARRAY_LONG_TYPE);
|
||||
knowTypes.put(standardLibrary.getShortArrayType(),ARRAY_SHORT_TYPE);
|
||||
knowTypes.put(standardLibrary.getByteArrayType(),ARRAY_BYTE_TYPE);
|
||||
knowTypes.put(standardLibrary.getCharArrayType(),ARRAY_CHAR_TYPE);
|
||||
knowTypes.put(standardLibrary.getFloatArrayType(),ARRAY_FLOAT_TYPE);
|
||||
knowTypes.put(standardLibrary.getDoubleArrayType(),ARRAY_DOUBLE_TYPE);
|
||||
knowTypes.put(standardLibrary.getBooleanArrayType(),ARRAY_BOOL_TYPE);
|
||||
knowTypes.put(standardLibrary.getNullableIntArrayType(), ARRAY_INT_TYPE);
|
||||
knowTypes.put(standardLibrary.getNullableLongArrayType(), ARRAY_LONG_TYPE);
|
||||
knowTypes.put(standardLibrary.getNullableShortArrayType(),ARRAY_SHORT_TYPE);
|
||||
knowTypes.put(standardLibrary.getNullableByteArrayType(),ARRAY_BYTE_TYPE);
|
||||
knowTypes.put(standardLibrary.getNullableCharArrayType(),ARRAY_CHAR_TYPE);
|
||||
knowTypes.put(standardLibrary.getNullableFloatArrayType(),ARRAY_FLOAT_TYPE);
|
||||
knowTypes.put(standardLibrary.getNullableDoubleArrayType(),ARRAY_DOUBLE_TYPE);
|
||||
knowTypes.put(standardLibrary.getNullableBooleanArrayType(),ARRAY_BOOL_TYPE);
|
||||
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
||||
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
|
||||
knowTypes.put(standardLibrary.getPrimitiveArrayJetType(primitiveType), jvmPrimitiveType.getAsmArrayType());
|
||||
knowTypes.put(standardLibrary.getNullablePrimitiveArrayJetType(primitiveType), jvmPrimitiveType.getAsmArrayType());
|
||||
}
|
||||
}
|
||||
|
||||
public String isKnownTypeInfo(JetType jetType) {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public enum JvmMethodParameterKind {
|
||||
VALUE,
|
||||
THIS,
|
||||
/** @see CodegenUtil#hasThis0(ClassDescriptor) */
|
||||
THIS0,
|
||||
RECEIVER,
|
||||
TYPE_INFO,
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class JvmMethodParameterSignature {
|
||||
@NotNull
|
||||
private final Type asmType;
|
||||
@NotNull
|
||||
private final String kotlinSignature;
|
||||
@NotNull
|
||||
private final JvmMethodParameterKind kind;
|
||||
|
||||
public JvmMethodParameterSignature(
|
||||
@NotNull Type asmType, @NotNull String kotlinSignature, @NotNull JvmMethodParameterKind kind) {
|
||||
this.asmType = asmType;
|
||||
this.kotlinSignature = kotlinSignature;
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Type getAsmType() {
|
||||
return asmType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getKotlinSignature() {
|
||||
return kotlinSignature;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JvmMethodParameterKind getKind() {
|
||||
return kind;
|
||||
}
|
||||
}
|
||||
@@ -2,48 +2,112 @@ package org.jetbrains.jet.codegen;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.commons.Method;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class JvmMethodSignature {
|
||||
|
||||
|
||||
@NotNull
|
||||
private final Method asmMethod;
|
||||
/** Null when we don't care about type parameters */
|
||||
private final String genericsSignature;
|
||||
private final String kotlinTypeParameter;
|
||||
private final List<String> kotlinParameterTypes;
|
||||
@NotNull
|
||||
private final List<JvmMethodParameterSignature> kotlinParameterTypes;
|
||||
@NotNull
|
||||
private final String kotlinReturnType;
|
||||
|
||||
/**
|
||||
* Generics info is generated. However it can be trivial (e.g. fields are null).
|
||||
*/
|
||||
private final boolean genericsAvailable;
|
||||
|
||||
public JvmMethodSignature(@NotNull Method asmMethod, @Nullable String genericsSignature,
|
||||
@Nullable String kotlinTypeParameters, @Nullable List<String> kotlinParameterTypes, @Nullable String kotlinReturnType) {
|
||||
@Nullable String kotlinTypeParameters, @NotNull List<JvmMethodParameterSignature> kotlinParameterTypes, @NotNull String kotlinReturnType) {
|
||||
this.asmMethod = asmMethod;
|
||||
this.genericsSignature = genericsSignature;
|
||||
this.kotlinTypeParameter = kotlinTypeParameters;
|
||||
this.kotlinParameterTypes = kotlinParameterTypes;
|
||||
this.kotlinReturnType = kotlinReturnType;
|
||||
this.genericsAvailable = true;
|
||||
}
|
||||
|
||||
public JvmMethodSignature(@NotNull Method asmMethod, @NotNull List<JvmMethodParameterSignature> kotlinParameterTypes) {
|
||||
this.asmMethod = asmMethod;
|
||||
this.genericsSignature = null;
|
||||
this.kotlinTypeParameter = null;
|
||||
this.kotlinParameterTypes = kotlinParameterTypes;
|
||||
this.kotlinReturnType = "";
|
||||
this.genericsAvailable = false;
|
||||
}
|
||||
|
||||
private void checkGenericsAvailable() {
|
||||
if (!genericsAvailable) {
|
||||
// TODO: uncomment following line and fix all broken tests
|
||||
//throw new IllegalStateException("incorrect call sequence");
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Method getAsmMethod() {
|
||||
return asmMethod;
|
||||
}
|
||||
|
||||
public String getGenericsSignature() {
|
||||
checkGenericsAvailable();
|
||||
return genericsSignature;
|
||||
}
|
||||
|
||||
public String getKotlinTypeParameter() {
|
||||
checkGenericsAvailable();
|
||||
return kotlinTypeParameter;
|
||||
}
|
||||
|
||||
public List<String> getKotlinParameterTypes() {
|
||||
@Nullable
|
||||
public List<JvmMethodParameterSignature> getKotlinParameterTypes() {
|
||||
checkGenericsAvailable();
|
||||
return kotlinParameterTypes;
|
||||
}
|
||||
|
||||
public int getParameterCount() {
|
||||
// TODO: slow
|
||||
return asmMethod.getArgumentTypes().length;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getKotlinParameterType(int i) {
|
||||
checkGenericsAvailable();
|
||||
if (kotlinParameterTypes == null) {
|
||||
return "";
|
||||
} else {
|
||||
return kotlinParameterTypes.get(i).getKotlinSignature();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getKotlinReturnType() {
|
||||
checkGenericsAvailable();
|
||||
return kotlinReturnType;
|
||||
}
|
||||
|
||||
public List<Type> getValueParameterTypes() {
|
||||
List<Type> r = new ArrayList<Type>(kotlinParameterTypes.size());
|
||||
for (JvmMethodParameterSignature p : kotlinParameterTypes) {
|
||||
if (p.getKind() == JvmMethodParameterKind.VALUE) {
|
||||
r.add(p.getAsmType());
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return asmMethod.getName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class JvmPropertyAccessorSignature {
|
||||
@NotNull
|
||||
private final JvmMethodSignature jvmMethodSignature;
|
||||
@NotNull
|
||||
private final String propertyTypeKotlinSignature;
|
||||
|
||||
public JvmPropertyAccessorSignature(@NotNull JvmMethodSignature jvmMethodSignature, @NotNull String propertyTypeKotlinSignature) {
|
||||
this.jvmMethodSignature = jvmMethodSignature;
|
||||
this.propertyTypeKotlinSignature = propertyTypeKotlinSignature;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JvmMethodSignature getJvmMethodSignature() {
|
||||
return jvmMethodSignature;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getPropertyTypeKotlinSignature() {
|
||||
return propertyTypeKotlinSignature;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertySetterDescriptor;
|
||||
@@ -12,6 +13,7 @@ import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.objectweb.asm.AnnotationVisitor;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
@@ -86,7 +88,8 @@ public class PropertyCodegen {
|
||||
final JetPropertyAccessor getter = p.getGetter();
|
||||
if (getter != null) {
|
||||
if (getter.getBodyExpression() != null) {
|
||||
functionCodegen.generateMethod(getter, state.getTypeMapper().mapGetterSignature(propertyDescriptor, kind), propertyDescriptor.getGetter());
|
||||
JvmPropertyAccessorSignature signature = state.getTypeMapper().mapGetterSignature(propertyDescriptor, kind);
|
||||
functionCodegen.generateMethod(getter, signature.getJvmMethodSignature(), signature.getPropertyTypeKotlinSignature(), propertyDescriptor.getGetter());
|
||||
}
|
||||
else if (!getter.hasModifier(JetTokens.PRIVATE_KEYWORD)) {
|
||||
generateDefaultGetter(p, getter);
|
||||
@@ -107,7 +110,8 @@ public class PropertyCodegen {
|
||||
if (setter.getBodyExpression() != null) {
|
||||
final PropertySetterDescriptor setterDescriptor = propertyDescriptor.getSetter();
|
||||
assert setterDescriptor != null;
|
||||
functionCodegen.generateMethod(setter, state.getTypeMapper().mapSetterSignature(propertyDescriptor, kind), setterDescriptor);
|
||||
JvmPropertyAccessorSignature signature = state.getTypeMapper().mapSetterSignature(propertyDescriptor, kind);
|
||||
functionCodegen.generateMethod(setter, signature.getJvmMethodSignature(), signature.getPropertyTypeKotlinSignature(), setterDescriptor);
|
||||
}
|
||||
else if (!p.hasModifier(JetTokens.PRIVATE_KEYWORD)) {
|
||||
generateDefaultSetter(p, setter);
|
||||
@@ -138,10 +142,11 @@ public class PropertyCodegen {
|
||||
if(isTrait && !(kind instanceof OwnerKind.DelegateKind))
|
||||
flags |= Opcodes.ACC_ABSTRACT;
|
||||
|
||||
final String signature = state.getTypeMapper().mapGetterSignature(propertyDescriptor, kind).getAsmMethod().getDescriptor();
|
||||
JvmPropertyAccessorSignature signature = state.getTypeMapper().mapGetterSignature(propertyDescriptor, kind);
|
||||
final String descriptor = signature.getJvmMethodSignature().getAsmMethod().getDescriptor();
|
||||
String getterName = getterName(propertyDescriptor.getName());
|
||||
MethodVisitor mv = v.newMethod(origin, flags, getterName, signature, null, null);
|
||||
mv.visitAnnotation(JvmStdlibNames.JET_PROPERTY.getDescriptor(), true).visitEnd();
|
||||
MethodVisitor mv = v.newMethod(origin, flags, getterName, descriptor, null, null);
|
||||
generateJetPropertyAnnotation(mv, signature.getPropertyTypeKotlinSignature(), signature.getJvmMethodSignature().getKotlinTypeParameter());
|
||||
if (v.generateCode() && (!isTrait || kind instanceof OwnerKind.DelegateKind)) {
|
||||
mv.visitCode();
|
||||
InstructionAdapter iv = new InstructionAdapter(mv);
|
||||
@@ -152,7 +157,7 @@ public class PropertyCodegen {
|
||||
if (kind instanceof OwnerKind.DelegateKind) {
|
||||
OwnerKind.DelegateKind dk = (OwnerKind.DelegateKind) kind;
|
||||
dk.getDelegate().put(JetTypeMapper.TYPE_OBJECT, iv);
|
||||
iv.invokeinterface(dk.getOwnerClass(), getterName, signature);
|
||||
iv.invokeinterface(dk.getOwnerClass(), getterName, descriptor);
|
||||
}
|
||||
else {
|
||||
iv.visitFieldInsn(kind == OwnerKind.NAMESPACE ? Opcodes.GETSTATIC : Opcodes.GETFIELD,
|
||||
@@ -164,6 +169,17 @@ public class PropertyCodegen {
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateJetPropertyAnnotation(MethodVisitor mv, @NotNull String kotlinType, @NotNull String typeParameters) {
|
||||
AnnotationVisitor annotationVisitor = mv.visitAnnotation(JvmStdlibNames.JET_PROPERTY.getDescriptor(), true);
|
||||
if (kotlinType.length() > 0) {
|
||||
annotationVisitor.visit(JvmStdlibNames.JET_PROPERTY_TYPE_FIELD, kotlinType);
|
||||
}
|
||||
if (typeParameters.length() > 0) {
|
||||
annotationVisitor.visit(JvmStdlibNames.JET_PROPERTY_TYPE_PARAMETERS_FIELD, typeParameters);
|
||||
}
|
||||
annotationVisitor.visitEnd();
|
||||
}
|
||||
|
||||
private void generateDefaultSetter(JetProperty p, JetDeclaration declaration) {
|
||||
final PropertyDescriptor propertyDescriptor = (PropertyDescriptor) state.getBindingContext().get(BindingContext.VARIABLE, p);
|
||||
int flags = JetTypeMapper.getAccessModifiers(declaration, Opcodes.ACC_PUBLIC);
|
||||
@@ -184,9 +200,10 @@ public class PropertyCodegen {
|
||||
if(isTrait && !(kind instanceof OwnerKind.DelegateKind))
|
||||
flags |= Opcodes.ACC_ABSTRACT;
|
||||
|
||||
final String signature = state.getTypeMapper().mapSetterSignature(propertyDescriptor, kind).getAsmMethod().getDescriptor();
|
||||
MethodVisitor mv = v.newMethod(origin, flags, setterName(propertyDescriptor.getName()), signature, null, null);
|
||||
mv.visitAnnotation(JvmStdlibNames.JET_PROPERTY.getDescriptor(), true).visitEnd();
|
||||
JvmPropertyAccessorSignature signature = state.getTypeMapper().mapSetterSignature(propertyDescriptor, kind);
|
||||
final String descriptor = signature.getJvmMethodSignature().getAsmMethod().getDescriptor();
|
||||
MethodVisitor mv = v.newMethod(origin, flags, setterName(propertyDescriptor.getName()), descriptor, null, null);
|
||||
generateJetPropertyAnnotation(mv, signature.getPropertyTypeKotlinSignature(), signature.getJvmMethodSignature().getKotlinTypeParameter());
|
||||
if (v.generateCode() && (!isTrait || kind instanceof OwnerKind.DelegateKind)) {
|
||||
mv.visitCode();
|
||||
InstructionAdapter iv = new InstructionAdapter(mv);
|
||||
@@ -203,7 +220,7 @@ public class PropertyCodegen {
|
||||
dk.getDelegate().put(JetTypeMapper.TYPE_OBJECT, iv);
|
||||
|
||||
iv.load(paramCode, type);
|
||||
iv.invokeinterface(dk.getOwnerClass(), setterName(propertyDescriptor.getName()), signature);
|
||||
iv.invokeinterface(dk.getOwnerClass(), setterName(propertyDescriptor.getName()), descriptor);
|
||||
}
|
||||
else {
|
||||
iv.load(paramCode, type);
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
@@ -36,7 +37,7 @@ public abstract class StackValue {
|
||||
if (type == Type.VOID_TYPE) {
|
||||
instructionAdapter.aconst(null);
|
||||
} else {
|
||||
Type boxed = JetTypeMapper.getBoxedType(type);
|
||||
Type boxed = JetTypeMapper.boxType(type);
|
||||
instructionAdapter.invokestatic(boxed.getInternalName(), "valueOf", "(" + type.getDescriptor() + ")" + boxed.getDescriptor());
|
||||
}
|
||||
}
|
||||
@@ -209,10 +210,10 @@ public abstract class StackValue {
|
||||
else if (this.type.getSort() == Type.OBJECT && type.getSort() <= Type.DOUBLE) {
|
||||
if (this.type.equals(JetTypeMapper.TYPE_OBJECT)) {
|
||||
if (type.getSort() == Type.BOOLEAN) {
|
||||
v.checkcast(JetTypeMapper.JL_BOOLEAN_TYPE);
|
||||
v.checkcast(JvmPrimitiveType.BOOLEAN.getWrapper().getAsmType());
|
||||
}
|
||||
else if (type.getSort() == Type.CHAR) {
|
||||
v.checkcast(JetTypeMapper.JL_CHAR_TYPE);
|
||||
v.checkcast(JvmPrimitiveType.CHAR.getWrapper().getAsmType());
|
||||
}
|
||||
else {
|
||||
v.checkcast(JetTypeMapper.JL_NUMBER_TYPE);
|
||||
|
||||
@@ -10,7 +10,9 @@ import org.jetbrains.jet.lang.psi.JetCallExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
|
||||
import org.jetbrains.jet.lang.types.JetStandardLibrary;
|
||||
import org.jetbrains.jet.lang.types.PrimitiveType;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.commons.InstructionAdapter;
|
||||
|
||||
@@ -31,40 +33,16 @@ public class ArrayIterator implements IntrinsicMethod {
|
||||
codegen.generateTypeInfo(funDescriptor.getReturnType().getArguments().get(0).getType(), null);
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([Ljava/lang/Object;Ljet/TypeInfo;)Ljet/Iterator;");
|
||||
return StackValue.onStack(JetTypeMapper.TYPE_ITERATOR);
|
||||
}
|
||||
else if(containingDeclaration.equals(standardLibrary.getByteArrayClass())) {
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([B)Ljet/ByteIterator;");
|
||||
return StackValue.onStack(JetTypeMapper.TYPE_BYTE_ITERATOR);
|
||||
}
|
||||
else if(containingDeclaration.equals(standardLibrary.getShortArrayClass())) {
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([S)Ljet/ShortIterator;");
|
||||
return StackValue.onStack(JetTypeMapper.TYPE_SHORT_ITERATOR);
|
||||
}
|
||||
else if(containingDeclaration.equals(standardLibrary.getIntArrayClass())) {
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([I)Ljet/IntIterator;");
|
||||
return StackValue.onStack(JetTypeMapper.TYPE_INT_ITERATOR);
|
||||
}
|
||||
else if(containingDeclaration.equals(standardLibrary.getLongArrayClass())) {
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([J)Ljet/LongIterator;");
|
||||
return StackValue.onStack(JetTypeMapper.TYPE_LONG_ITERATOR);
|
||||
}
|
||||
else if(containingDeclaration.equals(standardLibrary.getFloatArrayClass())) {
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([F)Ljet/FloatIterator;");
|
||||
return StackValue.onStack(JetTypeMapper.TYPE_FLOAT_ITERATOR);
|
||||
}
|
||||
else if(containingDeclaration.equals(standardLibrary.getDoubleArrayClass())) {
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([D)Ljet/DoubleIterator;");
|
||||
return StackValue.onStack(JetTypeMapper.TYPE_DOUBLE_ITERATOR);
|
||||
}
|
||||
else if(containingDeclaration.equals(standardLibrary.getCharArrayClass())) {
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([C)Ljet/CharIterator;");
|
||||
return StackValue.onStack(JetTypeMapper.TYPE_CHAR_ITERATOR);
|
||||
}
|
||||
else if(containingDeclaration.equals(standardLibrary.getBooleanArrayClass())) {
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([Z)Ljet/BooleanIterator;");
|
||||
return StackValue.onStack(JetTypeMapper.TYPE_BOOLEAN_ITERATOR);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
||||
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
|
||||
ClassDescriptor arrayClass = standardLibrary.getPrimitiveArrayClassDescriptor(primitiveType);
|
||||
if (containingDeclaration.equals(arrayClass)) {
|
||||
String methodSignature = "([" + jvmPrimitiveType.getJvmLetter() + ")" + jvmPrimitiveType.getIterator().getDescriptor();
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", methodSignature);
|
||||
return StackValue.onStack(jvmPrimitiveType.getIterator().getAsmType());
|
||||
}
|
||||
}
|
||||
throw new UnsupportedOperationException(containingDeclaration.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,11 @@ import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.search.DelegatingGlobalSearchScope;
|
||||
import com.intellij.psi.search.ProjectScope;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.JetStandardClasses;
|
||||
import org.jetbrains.jet.lang.types.JetStandardLibrary;
|
||||
import org.jetbrains.jet.lang.types.PrimitiveType;
|
||||
import org.jetbrains.jet.lang.types.TypeProjection;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
@@ -118,55 +120,25 @@ public class IntrinsicMethods {
|
||||
}
|
||||
|
||||
private void declareArrayMethods() {
|
||||
|
||||
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
||||
declareArrayMethodsForPrimitive(jvmPrimitiveType);
|
||||
}
|
||||
|
||||
declareIntrinsicProperty("Array", "size", ARRAY_SIZE);
|
||||
declareIntrinsicProperty("ByteArray", "size", ARRAY_SIZE);
|
||||
declareIntrinsicProperty("ShortArray", "size", ARRAY_SIZE);
|
||||
declareIntrinsicProperty("IntArray", "size", ARRAY_SIZE);
|
||||
declareIntrinsicProperty("LongArray", "size", ARRAY_SIZE);
|
||||
declareIntrinsicProperty("FloatArray", "size", ARRAY_SIZE);
|
||||
declareIntrinsicProperty("DoubleArray", "size", ARRAY_SIZE);
|
||||
declareIntrinsicProperty("CharArray", "size", ARRAY_SIZE);
|
||||
declareIntrinsicProperty("BooleanArray", "size", ARRAY_SIZE);
|
||||
|
||||
declareIntrinsicProperty("Array", "indices", ARRAY_INDICES);
|
||||
declareIntrinsicProperty("ByteArray", "indices", ARRAY_INDICES);
|
||||
declareIntrinsicProperty("ShortArray", "indices", ARRAY_INDICES);
|
||||
declareIntrinsicProperty("IntArray", "indices", ARRAY_INDICES);
|
||||
declareIntrinsicProperty("LongArray", "indices", ARRAY_INDICES);
|
||||
declareIntrinsicProperty("FloatArray", "indices", ARRAY_INDICES);
|
||||
declareIntrinsicProperty("DoubleArray", "indices", ARRAY_INDICES);
|
||||
declareIntrinsicProperty("CharArray", "indices", ARRAY_INDICES);
|
||||
declareIntrinsicProperty("BooleanArray", "indices", ARRAY_INDICES);
|
||||
|
||||
declareIntrinsicFunction("Array", "set", 2, ARRAY_SET);
|
||||
declareIntrinsicFunction("ByteArray", "set", 2, ARRAY_SET);
|
||||
declareIntrinsicFunction("ShortArray", "set", 2, ARRAY_SET);
|
||||
declareIntrinsicFunction("IntArray", "set", 2, ARRAY_SET);
|
||||
declareIntrinsicFunction("LongArray", "set", 2, ARRAY_SET);
|
||||
declareIntrinsicFunction("FloatArray", "set", 2, ARRAY_SET);
|
||||
declareIntrinsicFunction("DoubleArray", "set", 2, ARRAY_SET);
|
||||
declareIntrinsicFunction("CharArray", "set", 2, ARRAY_SET);
|
||||
declareIntrinsicFunction("BooleanArray", "set", 2, ARRAY_SET);
|
||||
|
||||
declareIntrinsicFunction("Array", "get", 1, ARRAY_GET);
|
||||
declareIntrinsicFunction("ByteArray", "get", 1, ARRAY_GET);
|
||||
declareIntrinsicFunction("ShortArray", "get", 1, ARRAY_GET);
|
||||
declareIntrinsicFunction("IntArray", "get", 1, ARRAY_GET);
|
||||
declareIntrinsicFunction("LongArray", "get", 1, ARRAY_GET);
|
||||
declareIntrinsicFunction("FloatArray", "get", 1, ARRAY_GET);
|
||||
declareIntrinsicFunction("DoubleArray", "get", 1, ARRAY_GET);
|
||||
declareIntrinsicFunction("CharArray", "get", 1, ARRAY_GET);
|
||||
declareIntrinsicFunction("BooleanArray", "get", 1, ARRAY_GET);
|
||||
|
||||
declareIterator(myStdLib.getArray());
|
||||
declareIterator(myStdLib.getByteArrayClass());
|
||||
declareIterator(myStdLib.getShortArrayClass());
|
||||
declareIterator(myStdLib.getIntArrayClass());
|
||||
declareIterator(myStdLib.getLongArrayClass());
|
||||
declareIterator(myStdLib.getFloatArrayClass());
|
||||
declareIterator(myStdLib.getDoubleArrayClass());
|
||||
declareIterator(myStdLib.getCharArrayClass());
|
||||
declareIterator(myStdLib.getBooleanArrayClass());
|
||||
}
|
||||
|
||||
private void declareArrayMethodsForPrimitive(JvmPrimitiveType jvmPrimitiveType) {
|
||||
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
|
||||
declareIntrinsicProperty(primitiveType.getArrayTypeName(), "size", ARRAY_SIZE);
|
||||
declareIntrinsicProperty(primitiveType.getArrayTypeName(), "indices", ARRAY_INDICES);
|
||||
declareIntrinsicFunction(primitiveType.getArrayTypeName(), "set", 2, ARRAY_SET);
|
||||
declareIntrinsicFunction(primitiveType.getArrayTypeName(), "get", 1, ARRAY_GET);
|
||||
declareIterator(myStdLib.getPrimitiveArrayClassDescriptor(primitiveType));
|
||||
}
|
||||
|
||||
private void declareIterator(ClassDescriptor classDescriptor) {
|
||||
@@ -186,8 +158,8 @@ public class IntrinsicMethods {
|
||||
}
|
||||
);
|
||||
for (DeclarationDescriptor stringMember : stringMembers) {
|
||||
if (stringMember instanceof FunctionDescriptor) {
|
||||
final FunctionDescriptor stringMethod = (FunctionDescriptor) stringMember;
|
||||
if (stringMember instanceof NamedFunctionDescriptor) {
|
||||
final NamedFunctionDescriptor stringMethod = (NamedFunctionDescriptor) stringMember;
|
||||
final PsiMethod[] methods = stringPsiClass != null?
|
||||
stringPsiClass.findMethodsByName(stringMember.getName(), false) : new PsiMethod[]{};
|
||||
for (PsiMethod method : methods) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.jetbrains.jet.codegen.CallableMethod;
|
||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||
import org.jetbrains.jet.codegen.OwnerKind;
|
||||
import org.jetbrains.jet.codegen.StackValue;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamedFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.objectweb.asm.Type;
|
||||
@@ -18,9 +18,9 @@ import java.util.List;
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
public class PsiMethodCall implements IntrinsicMethod {
|
||||
private final FunctionDescriptor myMethod;
|
||||
private final NamedFunctionDescriptor myMethod;
|
||||
|
||||
public PsiMethodCall(FunctionDescriptor method) {
|
||||
public PsiMethodCall(NamedFunctionDescriptor method) {
|
||||
myMethod = method;
|
||||
}
|
||||
|
||||
|
||||
+310
-213
@@ -6,24 +6,66 @@ import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.HierarchicalMethodSignature;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiClassType;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiEllipsisType;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiJavaFile;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.psi.PsiModifierListOwner;
|
||||
import com.intellij.psi.PsiPackage;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.PsiTypeParameter;
|
||||
import com.intellij.psi.PsiTypeParameterListOwner;
|
||||
import com.intellij.psi.search.DelegatingGlobalSearchScope;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import jet.typeinfo.TypeInfoVariance;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
||||
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorVisitor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.Modality;
|
||||
import org.jetbrains.jet.lang.descriptors.NamedFunctionDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyGetterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertySetterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.Visibility;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.resolve.java.kt.JetClassAnnotation;
|
||||
import org.jetbrains.jet.lang.types.JetStandardClasses;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeConstructorImpl;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lang.types.Variance;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
import org.jetbrains.jet.rt.signature.JetSignatureAdapter;
|
||||
import org.jetbrains.jet.rt.signature.JetSignatureExceptionsAdapter;
|
||||
import org.jetbrains.jet.rt.signature.JetSignatureReader;
|
||||
import org.jetbrains.jet.rt.signature.JetSignatureVisitor;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -117,7 +159,7 @@ public class JavaDescriptorResolver {
|
||||
protected final Map<String, ResolverNamespaceData> namespaceDescriptorCacheByFqn = Maps.newHashMap();
|
||||
protected final Map<PsiElement, ResolverNamespaceData> namespaceDescriptorCache = Maps.newHashMap();
|
||||
|
||||
protected final Map<PsiTypeParameter, TypeParameterDescriptorInitialization> typeParameterDescriptorCache = Maps.newHashMap();
|
||||
private final Map<PsiTypeParameter, TypeParameterDescriptorInitialization> typeParameterDescriptorCache = Maps.newHashMap();
|
||||
protected final Map<PsiMethod, FunctionDescriptor> methodDescriptorCache = Maps.newHashMap();
|
||||
protected final Map<PsiField, VariableDescriptor> fieldDescriptorCache = Maps.newHashMap();
|
||||
protected final JavaPsiFacade javaFacade;
|
||||
@@ -259,17 +301,11 @@ public class JavaDescriptorResolver {
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (PsiMethod constructor : psiConstructors) {
|
||||
PsiAnnotation jetConstructorAnnotation =
|
||||
constructor.getModifierList().findAnnotation(JvmStdlibNames.JET_CONSTRUCTOR.getFqName());
|
||||
if (jetConstructorAnnotation != null) {
|
||||
PsiLiteralExpression hiddenExpresson = (PsiLiteralExpression) jetConstructorAnnotation.findAttributeValue(JvmStdlibNames.JET_CONSTRUCTOR_HIDDEN_FIELD);
|
||||
if (hiddenExpresson != null) {
|
||||
boolean hidden = (Boolean) hiddenExpresson.getValue();
|
||||
if (hidden) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
for (PsiMethod psiConstructor : psiConstructors) {
|
||||
PsiMethodWrapper constructor = new PsiMethodWrapper(psiConstructor);
|
||||
|
||||
if (constructor.getJetConstructor().hidden()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(
|
||||
@@ -277,17 +313,17 @@ public class JavaDescriptorResolver {
|
||||
Collections.<AnnotationDescriptor>emptyList(), // TODO
|
||||
false);
|
||||
ValueParameterDescriptors valueParameterDescriptors = resolveParameterDescriptors(constructorDescriptor,
|
||||
constructor.getParameterList().getParameters(),
|
||||
constructor.getParameters(),
|
||||
new TypeParameterListTypeVariableResolver(typeParameters) // TODO: outer too
|
||||
);
|
||||
if (valueParameterDescriptors.receiverType != null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
constructorDescriptor.initialize(typeParameters, valueParameterDescriptors.descriptors, Modality.FINAL,
|
||||
resolveVisibilityFromPsiModifiers(constructor));
|
||||
resolveVisibilityFromPsiModifiers(psiConstructor));
|
||||
constructorDescriptor.setReturnType(classData.classDescriptor.getDefaultType());
|
||||
classData.classDescriptor.addConstructor(constructorDescriptor);
|
||||
semanticServices.getTrace().record(BindingContext.CONSTRUCTOR, constructor, constructorDescriptor);
|
||||
semanticServices.getTrace().record(BindingContext.CONSTRUCTOR, psiConstructor, constructorDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,18 +333,14 @@ public class JavaDescriptorResolver {
|
||||
}
|
||||
|
||||
private List<TypeParameterDescriptor> resolveClassTypeParameters(PsiClass psiClass, ResolverClassData classData, TypeVariableResolver typeVariableResolver) {
|
||||
for (PsiAnnotation annotation : psiClass.getModifierList().getAnnotations()) {
|
||||
if (annotation.getQualifiedName().equals(JvmStdlibNames.JET_CLASS.getFqName())) {
|
||||
classData.kotlin = true;
|
||||
PsiLiteralExpression attributeValue = (PsiLiteralExpression) annotation.findAttributeValue(JvmStdlibNames.JET_CLASS_SIGNATURE);
|
||||
if (attributeValue != null) {
|
||||
String typeParametersString = (String) attributeValue.getValue();
|
||||
if (typeParametersString != null) {
|
||||
return resolveClassTypeParametersFromJetSignature(typeParametersString, psiClass, classData.classDescriptor, typeVariableResolver);
|
||||
}
|
||||
}
|
||||
}
|
||||
JetClassAnnotation jetClassAnnotation = JetClassAnnotation.get(psiClass);
|
||||
classData.kotlin = jetClassAnnotation.isDefined();
|
||||
|
||||
if (jetClassAnnotation.signature().length() > 0) {
|
||||
return resolveClassTypeParametersFromJetSignature(
|
||||
jetClassAnnotation.signature(), psiClass, classData.classDescriptor, typeVariableResolver);
|
||||
}
|
||||
|
||||
return makeUninitializedTypeParameters(classData.classDescriptor, psiClass.getTypeParameters());
|
||||
}
|
||||
|
||||
@@ -344,11 +376,12 @@ public class JavaDescriptorResolver {
|
||||
private final DeclarationDescriptor containingDeclaration;
|
||||
private final PsiTypeParameterListOwner psiOwner;
|
||||
private final String name;
|
||||
private final int index;
|
||||
private final TypeInfoVariance variance;
|
||||
private final TypeVariableResolver typeVariableResolver;
|
||||
|
||||
protected JetSignatureTypeParameterVisitor(DeclarationDescriptor containingDeclaration, PsiTypeParameterListOwner psiOwner,
|
||||
String name, TypeInfoVariance variance, TypeVariableResolver typeVariableResolver)
|
||||
String name, int index, TypeInfoVariance variance, TypeVariableResolver typeVariableResolver)
|
||||
{
|
||||
if (name.isEmpty()) {
|
||||
throw new IllegalStateException();
|
||||
@@ -357,12 +390,11 @@ public class JavaDescriptorResolver {
|
||||
this.containingDeclaration = containingDeclaration;
|
||||
this.psiOwner = psiOwner;
|
||||
this.name = name;
|
||||
this.index = index;
|
||||
this.variance = variance;
|
||||
this.typeVariableResolver = typeVariableResolver;
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
|
||||
List<JetType> upperBounds = new ArrayList<JetType>();
|
||||
List<JetType> lowerBounds = new ArrayList<JetType>();
|
||||
|
||||
@@ -397,7 +429,7 @@ public class JavaDescriptorResolver {
|
||||
true, // TODO: wrong
|
||||
JetSignatureUtils.translateVariance(variance),
|
||||
name,
|
||||
++index);
|
||||
index);
|
||||
PsiTypeParameter psiTypeParameter = getPsiTypeParameterByName(psiOwner, name);
|
||||
typeParameterDescriptorCache.put(psiTypeParameter, new TypeParameterDescriptorInitialization(typeParameter, upperBounds, lowerBounds));
|
||||
done(typeParameter);
|
||||
@@ -428,9 +460,11 @@ public class JavaDescriptorResolver {
|
||||
}
|
||||
|
||||
new JetSignatureReader(jetSignature).accept(new JetSignatureExceptionsAdapter() {
|
||||
private int formalTypeParameterIndex = 0;
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitFormalTypeParameter(final String name, final TypeInfoVariance variance) {
|
||||
return new JetSignatureTypeParameterVisitor(classDescriptor, clazz, name, variance, new MyTypeVariableResolver()) {
|
||||
return new JetSignatureTypeParameterVisitor(classDescriptor, clazz, name, formalTypeParameterIndex++, variance, new MyTypeVariableResolver()) {
|
||||
@Override
|
||||
protected void done(TypeParameterDescriptor typeParameterDescriptor) {
|
||||
r.add(typeParameterDescriptor);
|
||||
@@ -527,7 +561,10 @@ public class JavaDescriptorResolver {
|
||||
@NotNull
|
||||
private TypeParameterDescriptorInitialization resolveTypeParameter(@NotNull DeclarationDescriptor containingDeclaration, @NotNull PsiTypeParameter psiTypeParameter) {
|
||||
TypeParameterDescriptorInitialization typeParameterDescriptor = typeParameterDescriptorCache.get(psiTypeParameter);
|
||||
assert typeParameterDescriptor != null : psiTypeParameter.getText();
|
||||
if (typeParameterDescriptor == null) {
|
||||
// TODO: report properly without crashing compiler
|
||||
throw new IllegalStateException("failed to resolve type parameter: " + psiTypeParameter.getName());
|
||||
}
|
||||
return typeParameterDescriptor;
|
||||
}
|
||||
|
||||
@@ -633,21 +670,24 @@ public class JavaDescriptorResolver {
|
||||
}
|
||||
}
|
||||
|
||||
public ValueParameterDescriptors resolveParameterDescriptors(DeclarationDescriptor containingDeclaration,
|
||||
PsiParameter[] parameters, TypeVariableResolver typeVariableResolver) {
|
||||
private ValueParameterDescriptors resolveParameterDescriptors(DeclarationDescriptor containingDeclaration,
|
||||
List<PsiParameterWrapper> parameters, TypeVariableResolver typeVariableResolver) {
|
||||
List<ValueParameterDescriptor> result = new ArrayList<ValueParameterDescriptor>();
|
||||
JetType receiverType = null;
|
||||
for (int i = 0, parametersLength = parameters.length; i < parametersLength; i++) {
|
||||
PsiParameter parameter = parameters[i];
|
||||
JvmMethodParameterMeaning meaning = resolveParameterDescriptor(containingDeclaration, i, parameter, typeVariableResolver);
|
||||
int indexDelta = 0;
|
||||
for (int i = 0, parametersLength = parameters.size(); i < parametersLength; i++) {
|
||||
PsiParameterWrapper parameter = parameters.get(i);
|
||||
JvmMethodParameterMeaning meaning = resolveParameterDescriptor(containingDeclaration, i + indexDelta, parameter, typeVariableResolver);
|
||||
if (meaning.kind == JvmMethodParameterKind.TYPE_INFO) {
|
||||
// TODO
|
||||
--indexDelta;
|
||||
} else if (meaning.kind == JvmMethodParameterKind.REGULAR) {
|
||||
result.add(meaning.valueParameterDescriptor);
|
||||
} else if (meaning.kind == JvmMethodParameterKind.RECEIVER) {
|
||||
if (receiverType != null) {
|
||||
throw new IllegalStateException("more then one receiver");
|
||||
}
|
||||
--indexDelta;
|
||||
receiverType = meaning.receiverType;
|
||||
}
|
||||
}
|
||||
@@ -688,8 +728,13 @@ public class JavaDescriptorResolver {
|
||||
|
||||
@NotNull
|
||||
private JvmMethodParameterMeaning resolveParameterDescriptor(DeclarationDescriptor containingDeclaration, int i,
|
||||
PsiParameter parameter, TypeVariableResolver typeVariableResolver) {
|
||||
PsiType psiType = parameter.getType();
|
||||
PsiParameterWrapper parameter, TypeVariableResolver typeVariableResolver) {
|
||||
|
||||
if (parameter.getJetTypeParameter().isDefined()) {
|
||||
return JvmMethodParameterMeaning.typeInfo(new Object());
|
||||
}
|
||||
|
||||
PsiType psiType = parameter.getPsiParameter().getType();
|
||||
|
||||
JetType varargElementType;
|
||||
if (psiType instanceof PsiEllipsisType) {
|
||||
@@ -700,56 +745,21 @@ public class JavaDescriptorResolver {
|
||||
varargElementType = null;
|
||||
}
|
||||
|
||||
boolean changeNullable = false;
|
||||
boolean nullable = true;
|
||||
String typeFromAnnotation = null;
|
||||
|
||||
boolean receiver = false;
|
||||
boolean hasDefaultValue = false;
|
||||
|
||||
boolean nullable = parameter.getJetValueParameter().nullable();
|
||||
|
||||
// TODO: must be very slow, make it lazy?
|
||||
String name = parameter.getName() != null ? parameter.getName() : "p" + i;
|
||||
for (PsiAnnotation annotation : parameter.getModifierList().getAnnotations()) {
|
||||
String name = parameter.getPsiParameter().getName() != null ? parameter.getPsiParameter().getName() : "p" + i;
|
||||
|
||||
if (annotation.getQualifiedName().equals(JvmStdlibNames.JET_VALUE_PARAMETER.getFqName())) {
|
||||
PsiLiteralExpression nameExpression = (PsiLiteralExpression) annotation.findAttributeValue(JvmStdlibNames.JET_VALUE_PARAMETER_NAME_FIELD);
|
||||
if (nameExpression != null) {
|
||||
name = (String) nameExpression.getValue();
|
||||
}
|
||||
|
||||
PsiLiteralExpression nullableExpression = (PsiLiteralExpression) annotation.findAttributeValue(JvmStdlibNames.JET_VALUE_PARAMETER_NULLABLE_FIELD);
|
||||
if (nullableExpression != null) {
|
||||
nullable = (Boolean) nullableExpression.getValue();
|
||||
} else {
|
||||
// default value of parameter
|
||||
nullable = false;
|
||||
changeNullable = true;
|
||||
}
|
||||
|
||||
PsiLiteralExpression signatureExpression = (PsiLiteralExpression) annotation.findAttributeValue(JvmStdlibNames.JET_VALUE_PARAMETER_TYPE_FIELD);
|
||||
if (signatureExpression != null) {
|
||||
typeFromAnnotation = (String) signatureExpression.getValue();
|
||||
}
|
||||
|
||||
|
||||
PsiLiteralExpression receiverExpression = (PsiLiteralExpression) annotation.findAttributeValue(JvmStdlibNames.JET_VALUE_PARAMETER_RECEIVER_FIELD);
|
||||
if (receiverExpression != null) {
|
||||
receiver = (Boolean) receiverExpression.getValue();
|
||||
}
|
||||
|
||||
PsiLiteralExpression hasDefaultValueExpression = (PsiLiteralExpression) annotation.findAttributeValue(JvmStdlibNames.JET_VALUE_PARAMETER_HAS_DEFAULT_VALUE_FIELD);
|
||||
if (hasDefaultValueExpression != null) {
|
||||
hasDefaultValue = (Boolean) hasDefaultValueExpression.getValue();
|
||||
}
|
||||
|
||||
|
||||
} else if (annotation.getQualifiedName().equals(JvmStdlibNames.JET_TYPE_PARAMETER.getFqName())) {
|
||||
return JvmMethodParameterMeaning.typeInfo(new Object());
|
||||
}
|
||||
if (parameter.getJetValueParameter().name().length() > 0) {
|
||||
name = parameter.getJetValueParameter().name();
|
||||
}
|
||||
|
||||
String typeFromAnnotation = parameter.getJetValueParameter().type();
|
||||
boolean receiver = parameter.getJetValueParameter().receiver();
|
||||
boolean hasDefaultValue = parameter.getJetValueParameter().hasDefaultValue();
|
||||
|
||||
JetType outType;
|
||||
if (typeFromAnnotation != null && typeFromAnnotation.length() > 0) {
|
||||
if (typeFromAnnotation.length() > 0) {
|
||||
outType = semanticServices.getTypeTransformer().transformToType(typeFromAnnotation, typeVariableResolver);
|
||||
} else {
|
||||
outType = semanticServices.getTypeTransformer().transformToType(psiType);
|
||||
@@ -763,7 +773,7 @@ public class JavaDescriptorResolver {
|
||||
Collections.<AnnotationDescriptor>emptyList(), // TODO
|
||||
name,
|
||||
false,
|
||||
changeNullable ? TypeUtils.makeNullableAsSpecified(outType, nullable) : outType,
|
||||
nullable ? TypeUtils.makeNullableAsSpecified(outType, nullable) : outType,
|
||||
hasDefaultValue,
|
||||
varargElementType
|
||||
));
|
||||
@@ -797,24 +807,28 @@ public class JavaDescriptorResolver {
|
||||
private static class PropertyKey {
|
||||
@NotNull
|
||||
private final String name;
|
||||
@NotNull
|
||||
private final PsiType type;
|
||||
//@NotNull
|
||||
//private final PsiType type;
|
||||
//@Nullable
|
||||
//private final PsiType receiverType;
|
||||
|
||||
private PropertyKey(String name, PsiType type) {
|
||||
private PropertyKey(@NotNull String name /*, @NotNull PsiType type, @Nullable PsiType receiverType */) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
//this.type = type;
|
||||
//this.receiverType = receiverType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
// generated by Idea
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
PropertyKey that = (PropertyKey) o;
|
||||
|
||||
if (!name.equals(that.name)) return false;
|
||||
if (!type.equals(that.type)) return false;
|
||||
//if (receiverType != null ? !receiverType.equals(that.receiverType) : that.receiverType != null)
|
||||
// return false;
|
||||
//if (!type.equals(that.type)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -822,15 +836,19 @@ public class JavaDescriptorResolver {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = name.hashCode();
|
||||
result = 31 * result + type.hashCode();
|
||||
//result = 31 * result + type.hashCode();
|
||||
//result = 31 * result + (receiverType != null ? receiverType.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private static class MembersForProperty {
|
||||
private PsiField field;
|
||||
private PsiMethod setter;
|
||||
private PsiMethod getter;
|
||||
private PsiFieldWrapper field;
|
||||
private PsiMethodWrapper setter;
|
||||
private PsiMethodWrapper getter;
|
||||
|
||||
private PsiType type;
|
||||
private PsiType receiverType;
|
||||
}
|
||||
|
||||
private Map<PropertyKey, MembersForProperty> getMembersForProperties(@NotNull PsiClass clazz, boolean staticMembers, boolean kotlin) {
|
||||
@@ -846,51 +864,106 @@ public class JavaDescriptorResolver {
|
||||
}
|
||||
|
||||
MembersForProperty members = new MembersForProperty();
|
||||
members.field = field;
|
||||
membersMap.put(new PropertyKey(field.getName(), field.getType()), members);
|
||||
members.field = new PsiFieldWrapper(field);
|
||||
members.type = field.getType();
|
||||
membersMap.put(new PropertyKey(field.getName() /*, field.getType(), null*/), members);
|
||||
}
|
||||
}
|
||||
|
||||
for (PsiMethod method : clazz.getMethods()) {
|
||||
if (method.getModifierList().hasExplicitModifier(PsiModifier.STATIC) != staticMembers) {
|
||||
for (PsiMethod psiMethod : clazz.getMethods()) {
|
||||
PsiMethodWrapper method = new PsiMethodWrapper(psiMethod);
|
||||
|
||||
if (method.isStatic() != staticMembers) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (method.hasModifierProperty(PsiModifier.PRIVATE)) {
|
||||
if (method.isPrivate()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO: "is" prefix
|
||||
if (method.getName().startsWith(JvmAbi.GETTER_PREFIX)) {
|
||||
// TODO: some java properties too
|
||||
if (method.getModifierList().findAnnotation(JvmStdlibNames.JET_PROPERTY.getFqName()) != null) {
|
||||
if (method.getParameterList().getParametersCount() == 0) {
|
||||
if (method.getName().equals(JvmStdlibNames.JET_OBJECT_GET_TYPEINFO_METHOD)) {
|
||||
continue;
|
||||
}
|
||||
// TODO: remove getJavaClass
|
||||
if (psiMethod.getName().startsWith(JvmAbi.GETTER_PREFIX)) {
|
||||
|
||||
String propertyName = StringUtil.decapitalize(method.getName().substring(JvmAbi.GETTER_PREFIX.length()));
|
||||
PropertyKey key = new PropertyKey(propertyName, method.getReturnType());
|
||||
MembersForProperty members = membersMap.get(key);
|
||||
if (members == null) {
|
||||
members = new MembersForProperty();
|
||||
membersMap.put(key, members);
|
||||
}
|
||||
members.getter = method;
|
||||
// TODO: some java properties too
|
||||
if (method.getJetProperty().isDefined()) {
|
||||
|
||||
if (psiMethod.getName().equals(JvmStdlibNames.JET_OBJECT_GET_TYPEINFO_METHOD)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
|
||||
PsiType receiverType;
|
||||
if (i < method.getParameters().size() && method.getParameter(i).getJetValueParameter().receiver()) {
|
||||
receiverType = method.getParameter(i).getPsiParameter().getType();
|
||||
++i;
|
||||
} else {
|
||||
receiverType = null;
|
||||
}
|
||||
|
||||
while (i < method.getParameters().size() && method.getParameter(i).getJetTypeParameter().isDefined()) {
|
||||
// TODO: store is reified
|
||||
++i;
|
||||
}
|
||||
|
||||
if (i != method.getParameters().size()) {
|
||||
// TODO: report error properly
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
String propertyName = StringUtil.decapitalize(psiMethod.getName().substring(JvmAbi.GETTER_PREFIX.length()));
|
||||
PropertyKey key = new PropertyKey(propertyName /*, psiMethod.getReturnType(), receiverType*/);
|
||||
MembersForProperty members = membersMap.get(key);
|
||||
if (members == null) {
|
||||
members = new MembersForProperty();
|
||||
membersMap.put(key, members);
|
||||
}
|
||||
members.getter = new PsiMethodWrapper(psiMethod);
|
||||
|
||||
// TODO: check conflicts with setter
|
||||
members.type = psiMethod.getReturnType();
|
||||
members.receiverType = receiverType;
|
||||
}
|
||||
} else if (method.getName().startsWith(JvmAbi.SETTER_PREFIX)) {
|
||||
if (method.getModifierList().findAnnotation(JvmStdlibNames.JET_PROPERTY.getFqName()) != null) {
|
||||
if (method.getParameterList().getParametersCount() == 1) {
|
||||
String propertyName = StringUtil.decapitalize(method.getName().substring(JvmAbi.SETTER_PREFIX.length()));
|
||||
PropertyKey key = new PropertyKey(propertyName, method.getParameterList().getParameters()[0].getType());
|
||||
MembersForProperty members = membersMap.get(key);
|
||||
if (members == null) {
|
||||
members = new MembersForProperty();
|
||||
membersMap.put(key, members);
|
||||
}
|
||||
members.setter = method;
|
||||
} else if (psiMethod.getName().startsWith(JvmAbi.SETTER_PREFIX)) {
|
||||
|
||||
if (method.getJetProperty().isDefined()) {
|
||||
if (psiMethod.getParameterList().getParametersCount() == 0) {
|
||||
// TODO: report error properly
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
|
||||
PsiType receiverType = null;
|
||||
PsiParameterWrapper p1 = method.getParameter(0);
|
||||
if (p1.getJetValueParameter().receiver()) {
|
||||
receiverType = p1.getPsiParameter().getType();
|
||||
++i;
|
||||
}
|
||||
|
||||
while (i < method.getParameters().size() && method.getParameter(i).getJetTypeParameter().isDefined()) {
|
||||
++i;
|
||||
}
|
||||
|
||||
if (i + 1 != psiMethod.getParameterList().getParametersCount()) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
PsiType propertyType = psiMethod.getParameterList().getParameters()[i].getType();
|
||||
|
||||
String propertyName = StringUtil.decapitalize(psiMethod.getName().substring(JvmAbi.SETTER_PREFIX.length()));
|
||||
PropertyKey key = new PropertyKey(propertyName /*, propertyType, receiverType*/);
|
||||
MembersForProperty members = membersMap.get(key);
|
||||
if (members == null) {
|
||||
members = new MembersForProperty();
|
||||
membersMap.put(key, members);
|
||||
}
|
||||
members.setter = new PsiMethodWrapper(psiMethod);
|
||||
|
||||
// TODO: check conflicts with getter
|
||||
members.type = propertyType;
|
||||
members.receiverType = receiverType;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -930,28 +1003,29 @@ public class JavaDescriptorResolver {
|
||||
}
|
||||
|
||||
Set<VariableDescriptor> descriptors = Sets.newHashSet();
|
||||
for (Map.Entry<PropertyKey, MembersForProperty> entry : getMembersForProperties(psiClass, staticMembers, scopeData.kotlin).entrySet()) {
|
||||
Map<PropertyKey, MembersForProperty> membersForProperties = getMembersForProperties(psiClass, staticMembers, scopeData.kotlin);
|
||||
for (Map.Entry<PropertyKey, MembersForProperty> entry : membersForProperties.entrySet()) {
|
||||
//VariableDescriptor variableDescriptor = fieldDescriptorCache.get(field);
|
||||
//if (variableDescriptor != null) {
|
||||
// return variableDescriptor;
|
||||
//}
|
||||
String propertyName = entry.getKey().name;
|
||||
PsiType propertyType = entry.getKey().type;
|
||||
PsiType propertyType = entry.getValue().type;
|
||||
PsiType receiverType = entry.getValue().receiverType;
|
||||
MembersForProperty members = entry.getValue();
|
||||
|
||||
JetType type = semanticServices.getTypeTransformer().transformToType(propertyType);
|
||||
boolean isFinal;
|
||||
if (members.setter == null && members.getter == null) {
|
||||
isFinal = members.field.hasModifierProperty(PsiModifier.FINAL);
|
||||
isFinal = false;
|
||||
} else if (members.getter != null) {
|
||||
isFinal = members.getter.hasModifierProperty(PsiModifier.FINAL);
|
||||
isFinal = members.getter.isFinal();
|
||||
} else if (members.setter != null) {
|
||||
isFinal = members.setter.hasModifierProperty(PsiModifier.FINAL);
|
||||
isFinal = members.setter.isFinal();
|
||||
} else {
|
||||
isFinal = false;
|
||||
}
|
||||
|
||||
PsiMember anyMember;
|
||||
|
||||
PsiMemberWrapper anyMember;
|
||||
if (members.getter != null) {
|
||||
anyMember = members.getter;
|
||||
} else if (members.field != null) {
|
||||
@@ -973,14 +1047,64 @@ public class JavaDescriptorResolver {
|
||||
owner,
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
isFinal && !staticMembers ? Modality.FINAL : Modality.OPEN, // TODO: abstract
|
||||
resolveVisibilityFromPsiModifiers(anyMember),
|
||||
resolveVisibilityFromPsiModifiers(anyMember.psiMember),
|
||||
isVar,
|
||||
false,
|
||||
null,
|
||||
propertyName);
|
||||
|
||||
PropertyGetterDescriptor getterDescriptor = null;
|
||||
PropertySetterDescriptor setterDescriptor = null;
|
||||
if (members.getter != null) {
|
||||
getterDescriptor = new PropertyGetterDescriptor(propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), Modality.OPEN, Visibility.PUBLIC, true, false);
|
||||
}
|
||||
if (members.setter != null) {
|
||||
setterDescriptor = new PropertySetterDescriptor(propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), Modality.OPEN, Visibility.PUBLIC, true, false);
|
||||
}
|
||||
|
||||
propertyDescriptor.initialize(getterDescriptor, setterDescriptor);
|
||||
|
||||
final List<TypeParameterDescriptor> classTypeParameters;
|
||||
if (anyMember instanceof PsiMethodWrapper && !anyMember.isStatic()) {
|
||||
classTypeParameters = ((ClassDescriptor) owner).getTypeConstructor().getParameters();
|
||||
} else {
|
||||
classTypeParameters = new ArrayList<TypeParameterDescriptor>(0);
|
||||
}
|
||||
TypeParameterListTypeVariableResolver typeVariableResolver = new TypeParameterListTypeVariableResolver(classTypeParameters);
|
||||
|
||||
List<TypeParameterDescriptor> typeParameters = new ArrayList<TypeParameterDescriptor>(0);
|
||||
|
||||
if (members.setter != null) {
|
||||
// call ugly code with side effects
|
||||
typeParameters = resolveMethodTypeParameters(members.setter, propertyDescriptor.getSetter(), typeVariableResolver);
|
||||
}
|
||||
if (members.getter != null) {
|
||||
// call ugly code with side effects
|
||||
typeParameters = resolveMethodTypeParameters(members.getter, propertyDescriptor.getGetter(), typeVariableResolver);
|
||||
}
|
||||
|
||||
JetType receiverJetType;
|
||||
if (receiverType == null) {
|
||||
receiverJetType = null;
|
||||
} else {
|
||||
receiverJetType = semanticServices.getTypeTransformer().transformToType(receiverType);
|
||||
}
|
||||
|
||||
JetType type = semanticServices.getTypeTransformer().transformToType(propertyType);
|
||||
|
||||
propertyDescriptor.setType(
|
||||
type,
|
||||
typeParameters,
|
||||
DescriptorUtils.getExpectedThisObjectIfNeeded(owner),
|
||||
propertyName,
|
||||
type);
|
||||
semanticServices.getTrace().record(BindingContext.VARIABLE, anyMember, propertyDescriptor);
|
||||
receiverJetType
|
||||
);
|
||||
if (getterDescriptor != null) {
|
||||
getterDescriptor.initialize(type);
|
||||
}
|
||||
if (setterDescriptor != null) {
|
||||
// TODO: initialize
|
||||
}
|
||||
|
||||
semanticServices.getTrace().record(BindingContext.VARIABLE, anyMember.psiMember, propertyDescriptor);
|
||||
//fieldDescriptorCache.put(field, propertyDescriptor);
|
||||
descriptors.add(propertyDescriptor);
|
||||
}
|
||||
@@ -1053,14 +1177,16 @@ public class JavaDescriptorResolver {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public FunctionDescriptor resolveMethodToFunctionDescriptor(DeclarationDescriptor owner, PsiClass psiClass, TypeSubstitutor typeSubstitutorForGenericSuperclasses, PsiMethod method) {
|
||||
PsiType returnType = method.getReturnType();
|
||||
public FunctionDescriptor resolveMethodToFunctionDescriptor(DeclarationDescriptor owner, PsiClass psiClass, TypeSubstitutor typeSubstitutorForGenericSuperclasses, PsiMethod psiMethod) {
|
||||
PsiMethodWrapper method = new PsiMethodWrapper(psiMethod);
|
||||
|
||||
PsiType returnType = psiMethod.getReturnType();
|
||||
if (returnType == null) {
|
||||
return null;
|
||||
}
|
||||
FunctionDescriptor functionDescriptor = methodDescriptorCache.get(method);
|
||||
FunctionDescriptor functionDescriptor = methodDescriptorCache.get(psiMethod);
|
||||
if (functionDescriptor != null) {
|
||||
if (method.getContainingClass() != psiClass) {
|
||||
if (psiMethod.getContainingClass() != psiClass) {
|
||||
functionDescriptor = functionDescriptor.substitute(typeSubstitutorForGenericSuperclasses);
|
||||
}
|
||||
return functionDescriptor;
|
||||
@@ -1082,44 +1208,36 @@ public class JavaDescriptorResolver {
|
||||
kotlin = classData.kotlin;
|
||||
}
|
||||
|
||||
// TODO: hide getters and setters properly
|
||||
if (kotlin) {
|
||||
if (method.getName().startsWith(JvmAbi.GETTER_PREFIX) && method.getParameterList().getParametersCount() == 0) {
|
||||
if (method.getModifierList().findAnnotation(JvmStdlibNames.JET_PROPERTY.getFqName()) != null)
|
||||
return null;
|
||||
}
|
||||
if (method.getName().startsWith(JvmAbi.SETTER_PREFIX) && method.getParameterList().getParametersCount() == 1) {
|
||||
if (method.getModifierList().findAnnotation(JvmStdlibNames.JET_PROPERTY.getFqName()) != null)
|
||||
return null;
|
||||
}
|
||||
// TODO: ugly
|
||||
if (method.getJetProperty().isDefined()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
DeclarationDescriptor classDescriptor;
|
||||
final List<TypeParameterDescriptor> classTypeParameters;
|
||||
if (method.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
classDescriptor = resolveNamespace(method.getContainingClass());
|
||||
if (method.isStatic()) {
|
||||
classDescriptor = resolveNamespace(psiMethod.getContainingClass());
|
||||
classTypeParameters = Collections.emptyList();
|
||||
}
|
||||
else {
|
||||
ClassDescriptor classClassDescriptor = resolveClass(method.getContainingClass());
|
||||
ClassDescriptor classClassDescriptor = resolveClass(psiMethod.getContainingClass());
|
||||
classDescriptor = classClassDescriptor;
|
||||
classTypeParameters = classClassDescriptor.getTypeConstructor().getParameters();
|
||||
}
|
||||
if (classDescriptor == null) {
|
||||
return null;
|
||||
}
|
||||
PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
FunctionDescriptorImpl functionDescriptorImpl = new FunctionDescriptorImpl(
|
||||
NamedFunctionDescriptorImpl functionDescriptorImpl = new NamedFunctionDescriptorImpl(
|
||||
owner,
|
||||
Collections.<AnnotationDescriptor>emptyList(), // TODO
|
||||
method.getName()
|
||||
psiMethod.getName()
|
||||
);
|
||||
methodDescriptorCache.put(method, functionDescriptorImpl);
|
||||
methodDescriptorCache.put(psiMethod, functionDescriptorImpl);
|
||||
|
||||
// TODO: add outer classes
|
||||
TypeParameterListTypeVariableResolver typeVariableResolverForParameters = new TypeParameterListTypeVariableResolver(classTypeParameters);
|
||||
|
||||
final List<TypeParameterDescriptor> methodTypeParameters = resolveMethodTypeParameters(method, functionDescriptorImpl, typeVariableResolverForParameters);
|
||||
final List<TypeParameterDescriptor> methodTypeParameters = resolveMethodTypeParameters(new PsiMethodWrapper(psiMethod), functionDescriptorImpl, typeVariableResolverForParameters);
|
||||
|
||||
class MethodTypeVariableResolver implements TypeVariableResolver {
|
||||
|
||||
@@ -1141,41 +1259,37 @@ public class JavaDescriptorResolver {
|
||||
}
|
||||
|
||||
|
||||
ValueParameterDescriptors valueParameterDescriptors = resolveParameterDescriptors(functionDescriptorImpl, parameters, new MethodTypeVariableResolver());
|
||||
ValueParameterDescriptors valueParameterDescriptors = resolveParameterDescriptors(functionDescriptorImpl, method.getParameters(), new MethodTypeVariableResolver());
|
||||
functionDescriptorImpl.initialize(
|
||||
valueParameterDescriptors.receiverType,
|
||||
DescriptorUtils.getExpectedThisObjectIfNeeded(classDescriptor),
|
||||
methodTypeParameters,
|
||||
valueParameterDescriptors.descriptors,
|
||||
makeReturnType(returnType, method, new MethodTypeVariableResolver()),
|
||||
Modality.convertFromFlags(method.hasModifierProperty(PsiModifier.ABSTRACT), !method.hasModifierProperty(PsiModifier.FINAL)),
|
||||
resolveVisibilityFromPsiModifiers(method)
|
||||
Modality.convertFromFlags(psiMethod.hasModifierProperty(PsiModifier.ABSTRACT), !psiMethod.hasModifierProperty(PsiModifier.FINAL)),
|
||||
resolveVisibilityFromPsiModifiers(psiMethod)
|
||||
);
|
||||
semanticServices.getTrace().record(BindingContext.FUNCTION, method, functionDescriptorImpl);
|
||||
semanticServices.getTrace().record(BindingContext.FUNCTION, psiMethod, functionDescriptorImpl);
|
||||
FunctionDescriptor substitutedFunctionDescriptor = functionDescriptorImpl;
|
||||
if (method.getContainingClass() != psiClass) {
|
||||
if (psiMethod.getContainingClass() != psiClass) {
|
||||
substitutedFunctionDescriptor = functionDescriptorImpl.substitute(typeSubstitutorForGenericSuperclasses);
|
||||
}
|
||||
return substitutedFunctionDescriptor;
|
||||
}
|
||||
|
||||
private List<TypeParameterDescriptor> resolveMethodTypeParameters(PsiMethod method, FunctionDescriptorImpl functionDescriptorImpl, TypeVariableResolver classTypeVariableResolver) {
|
||||
for (PsiAnnotation annotation : method.getModifierList().getAnnotations()) {
|
||||
if (annotation.getQualifiedName().equals(JvmStdlibNames.JET_METHOD.getFqName())) {
|
||||
PsiLiteralExpression attributeValue = (PsiLiteralExpression) annotation.findAttributeValue(JvmStdlibNames.JET_METHOD_TYPE_PARAMETERS_FIELD);
|
||||
if (attributeValue != null) {
|
||||
String typeParametersString = (String) attributeValue.getValue();
|
||||
if (typeParametersString != null) {
|
||||
List<TypeParameterDescriptor> r = resolveMethodTypeParametersFromJetSignature(typeParametersString, method, functionDescriptorImpl, classTypeVariableResolver);
|
||||
initializeTypeParameters(method);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
}
|
||||
private List<TypeParameterDescriptor> resolveMethodTypeParameters(
|
||||
@NotNull PsiMethodWrapper method,
|
||||
@NotNull FunctionDescriptor functionDescriptor,
|
||||
@NotNull TypeVariableResolver classTypeVariableResolver) {
|
||||
if (method.getJetMethodOrProperty().typeParameters().length() > 0) {
|
||||
List<TypeParameterDescriptor> r = resolveMethodTypeParametersFromJetSignature(
|
||||
method.getJetMethodOrProperty().typeParameters(), method.getPsiMethod(), functionDescriptor, classTypeVariableResolver);
|
||||
initializeTypeParameters(method.getPsiMethod());
|
||||
return r;
|
||||
}
|
||||
|
||||
List<TypeParameterDescriptor> typeParameters = makeUninitializedTypeParameters(functionDescriptorImpl, method.getTypeParameters());
|
||||
initializeTypeParameters(method);
|
||||
|
||||
List<TypeParameterDescriptor> typeParameters = makeUninitializedTypeParameters(functionDescriptor, method.getPsiMethod().getTypeParameters());
|
||||
initializeTypeParameters(method.getPsiMethod());
|
||||
return typeParameters;
|
||||
}
|
||||
|
||||
@@ -1202,10 +1316,12 @@ public class JavaDescriptorResolver {
|
||||
}
|
||||
|
||||
new JetSignatureReader(jetSignature).acceptFormalTypeParametersOnly(new JetSignatureExceptionsAdapter() {
|
||||
private int formalTypeParameterIndex = 0;
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitFormalTypeParameter(final String name, final TypeInfoVariance variance) {
|
||||
|
||||
return new JetSignatureTypeParameterVisitor(functionDescriptor, method, name, variance, new MyTypeVariableResolver()) {
|
||||
return new JetSignatureTypeParameterVisitor(functionDescriptor, method, name, formalTypeParameterIndex++, variance, new MyTypeVariableResolver()) {
|
||||
@Override
|
||||
protected void done(TypeParameterDescriptor typeParameterDescriptor) {
|
||||
r.add(typeParameterDescriptor);
|
||||
@@ -1217,37 +1333,18 @@ public class JavaDescriptorResolver {
|
||||
return r;
|
||||
}
|
||||
|
||||
private JetType makeReturnType(PsiType returnType, PsiMethod method, TypeVariableResolver typeVariableResolver) {
|
||||
boolean changeNullable = false;
|
||||
boolean nullable = true;
|
||||
|
||||
String returnTypeFromAnnotation = null;
|
||||
private JetType makeReturnType(PsiType returnType, PsiMethodWrapper method, TypeVariableResolver typeVariableResolver) {
|
||||
|
||||
String returnTypeFromAnnotation = method.getJetMethod().returnType();
|
||||
|
||||
for (PsiAnnotation annotation : method.getModifierList().getAnnotations()) {
|
||||
if (annotation.getQualifiedName().equals(JvmStdlibNames.JET_METHOD.getFqName())) {
|
||||
PsiLiteralExpression nullableExpression = (PsiLiteralExpression) annotation.findAttributeValue(JvmStdlibNames.JET_METHOD_NULLABLE_RETURN_TYPE_FIELD);
|
||||
if (nullableExpression != null) {
|
||||
nullable = (Boolean) nullableExpression.getValue();
|
||||
} else {
|
||||
// default value of parameter
|
||||
nullable = false;
|
||||
changeNullable = true;
|
||||
}
|
||||
|
||||
PsiLiteralExpression returnTypeExpression = (PsiLiteralExpression) annotation.findAttributeValue(JvmStdlibNames.JET_METHOD_RETURN_TYPE_FIELD);
|
||||
if (returnTypeExpression != null) {
|
||||
returnTypeFromAnnotation = (String) returnTypeExpression.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
JetType transformedType;
|
||||
if (returnTypeFromAnnotation != null && returnTypeFromAnnotation.length() > 0) {
|
||||
if (returnTypeFromAnnotation.length() > 0) {
|
||||
transformedType = semanticServices.getTypeTransformer().transformToType(returnTypeFromAnnotation, typeVariableResolver);
|
||||
} else {
|
||||
transformedType = semanticServices.getTypeTransformer().transformToType(returnType);
|
||||
}
|
||||
if (changeNullable) {
|
||||
return TypeUtils.makeNullableAsSpecified(transformedType, nullable);
|
||||
if (method.getJetMethod().returnTypeNullable()) {
|
||||
return TypeUtils.makeNullableAsSpecified(transformedType, true);
|
||||
} else {
|
||||
return transformedType;
|
||||
}
|
||||
|
||||
@@ -86,14 +86,6 @@ public class JavaPackageScope extends JetScopeImpl {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
PsiField field = psiClassForPackage.findFieldByName(name, true);
|
||||
if (field == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
if (!field.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
// TODO: cache
|
||||
return semanticServices.getDescriptorResolver().resolveFieldGroupByName(containingDescriptor, psiClassForPackage, name, true);
|
||||
}
|
||||
|
||||
+15
-40
@@ -88,6 +88,7 @@ public class JavaTypeTransformer {
|
||||
if (psiClass instanceof PsiTypeParameter) {
|
||||
PsiTypeParameter typeParameter = (PsiTypeParameter) psiClass;
|
||||
TypeParameterDescriptor typeParameterDescriptor = resolver.resolveTypeParameter(typeParameter);
|
||||
// return TypeUtils.makeNullable(typeParameterDescriptor.getDefaultType());
|
||||
return typeParameterDescriptor.getDefaultType();
|
||||
}
|
||||
else {
|
||||
@@ -155,31 +156,13 @@ public class JavaTypeTransformer {
|
||||
public Map<String, JetType> getPrimitiveTypesMap() {
|
||||
if (primitiveTypesMap == null) {
|
||||
primitiveTypesMap = new HashMap<String, JetType>();
|
||||
primitiveTypesMap.put("byte", standardLibrary.getByteType());
|
||||
primitiveTypesMap.put("short", standardLibrary.getShortType());
|
||||
primitiveTypesMap.put("char", standardLibrary.getCharType());
|
||||
primitiveTypesMap.put("int", standardLibrary.getIntType());
|
||||
primitiveTypesMap.put("long", standardLibrary.getLongType());
|
||||
primitiveTypesMap.put("float", standardLibrary.getFloatType());
|
||||
primitiveTypesMap.put("double", standardLibrary.getDoubleType());
|
||||
primitiveTypesMap.put("boolean", standardLibrary.getBooleanType());
|
||||
primitiveTypesMap.put("[byte", standardLibrary.getByteArrayType());
|
||||
primitiveTypesMap.put("[short", standardLibrary.getShortArrayType());
|
||||
primitiveTypesMap.put("[char", standardLibrary.getCharArrayType());
|
||||
primitiveTypesMap.put("[int", standardLibrary.getIntArrayType());
|
||||
primitiveTypesMap.put("[long", standardLibrary.getLongArrayType());
|
||||
primitiveTypesMap.put("[float", standardLibrary.getFloatArrayType());
|
||||
primitiveTypesMap.put("[double", standardLibrary.getDoubleArrayType());
|
||||
primitiveTypesMap.put("[boolean", standardLibrary.getBooleanArrayType());
|
||||
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
||||
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
|
||||
primitiveTypesMap.put(jvmPrimitiveType.getName(), standardLibrary.getPrimitiveJetType(primitiveType));
|
||||
primitiveTypesMap.put("[" + jvmPrimitiveType.getName(), standardLibrary.getPrimitiveArrayJetType(primitiveType));
|
||||
primitiveTypesMap.put(jvmPrimitiveType.getWrapper().getFqName(), standardLibrary.getNullablePrimitiveJetType(primitiveType));
|
||||
}
|
||||
primitiveTypesMap.put("void", JetStandardClasses.getUnitType());
|
||||
primitiveTypesMap.put("java.lang.Byte", TypeUtils.makeNullable(standardLibrary.getByteType()));
|
||||
primitiveTypesMap.put("java.lang.Short", TypeUtils.makeNullable(standardLibrary.getShortType()));
|
||||
primitiveTypesMap.put("java.lang.Character", TypeUtils.makeNullable(standardLibrary.getCharType()));
|
||||
primitiveTypesMap.put("java.lang.Integer", TypeUtils.makeNullable(standardLibrary.getIntType()));
|
||||
primitiveTypesMap.put("java.lang.Long", TypeUtils.makeNullable(standardLibrary.getLongType()));
|
||||
primitiveTypesMap.put("java.lang.Float", TypeUtils.makeNullable(standardLibrary.getFloatType()));
|
||||
primitiveTypesMap.put("java.lang.Double", TypeUtils.makeNullable(standardLibrary.getDoubleType()));
|
||||
primitiveTypesMap.put("java.lang.Boolean", TypeUtils.makeNullable(standardLibrary.getBooleanType()));
|
||||
}
|
||||
return primitiveTypesMap;
|
||||
}
|
||||
@@ -187,14 +170,10 @@ public class JavaTypeTransformer {
|
||||
public Map<String, JetType> getClassTypesMap() {
|
||||
if (classTypesMap == null) {
|
||||
classTypesMap = new HashMap<String, JetType>();
|
||||
classTypesMap.put("java.lang.Byte", TypeUtils.makeNullable(standardLibrary.getByteType()));
|
||||
classTypesMap.put("java.lang.Short", TypeUtils.makeNullable(standardLibrary.getShortType()));
|
||||
classTypesMap.put("java.lang.Character", TypeUtils.makeNullable(standardLibrary.getCharType()));
|
||||
classTypesMap.put("java.lang.Integer", TypeUtils.makeNullable(standardLibrary.getIntType()));
|
||||
classTypesMap.put("java.lang.Long", TypeUtils.makeNullable(standardLibrary.getLongType()));
|
||||
classTypesMap.put("java.lang.Float", TypeUtils.makeNullable(standardLibrary.getFloatType()));
|
||||
classTypesMap.put("java.lang.Double", TypeUtils.makeNullable(standardLibrary.getDoubleType()));
|
||||
classTypesMap.put("java.lang.Boolean", TypeUtils.makeNullable(standardLibrary.getBooleanType()));
|
||||
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
||||
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
|
||||
classTypesMap.put(jvmPrimitiveType.getWrapper().getFqName(), standardLibrary.getNullablePrimitiveJetType(primitiveType));
|
||||
}
|
||||
classTypesMap.put("java.lang.Object", JetStandardClasses.getNullableAnyType());
|
||||
classTypesMap.put("java.lang.String", standardLibrary.getNullableStringType());
|
||||
}
|
||||
@@ -204,14 +183,10 @@ public class JavaTypeTransformer {
|
||||
public Map<String, ClassDescriptor> getPrimitiveWrappersClassDescriptorMap() {
|
||||
if (classDescriptorMap == null) {
|
||||
classDescriptorMap = new HashMap<String, ClassDescriptor>();
|
||||
classDescriptorMap.put("java.lang.Byte", standardLibrary.getByte());
|
||||
classDescriptorMap.put("java.lang.Short", standardLibrary.getShort());
|
||||
classDescriptorMap.put("java.lang.Character", standardLibrary.getChar());
|
||||
classDescriptorMap.put("java.lang.Integer", standardLibrary.getInt());
|
||||
classDescriptorMap.put("java.lang.Long", standardLibrary.getLong());
|
||||
classDescriptorMap.put("java.lang.Float", standardLibrary.getFloat());
|
||||
classDescriptorMap.put("java.lang.Double", standardLibrary.getDouble());
|
||||
classDescriptorMap.put("java.lang.Boolean", standardLibrary.getBoolean());
|
||||
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
||||
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
|
||||
classDescriptorMap.put(jvmPrimitiveType.getWrapper().getFqName(), standardLibrary.getPrimitiveClassDescriptor(primitiveType));
|
||||
}
|
||||
//classDescriptorMap.put("java.lang.Object", standardLibrary.get
|
||||
classDescriptorMap.put("java.lang.String", standardLibrary.getString());
|
||||
}
|
||||
|
||||
+15
-39
@@ -38,46 +38,22 @@ public abstract class JetTypeJetSignatureReader extends JetSignatureExceptionsAd
|
||||
|
||||
private JetType getPrimitiveType(char descriptor, boolean nullable) {
|
||||
if (!nullable) {
|
||||
switch (descriptor) {
|
||||
case 'Z':
|
||||
return jetStandardLibrary.getBooleanType();
|
||||
case 'C':
|
||||
return jetStandardLibrary.getCharType();
|
||||
case 'B':
|
||||
return jetStandardLibrary.getByteType();
|
||||
case 'S':
|
||||
return jetStandardLibrary.getShortType();
|
||||
case 'I':
|
||||
return jetStandardLibrary.getIntType();
|
||||
case 'F':
|
||||
return jetStandardLibrary.getFloatType();
|
||||
case 'J':
|
||||
return jetStandardLibrary.getLongType();
|
||||
case 'D':
|
||||
return jetStandardLibrary.getDoubleType();
|
||||
case 'V':
|
||||
return JetStandardClasses.getUnitType();
|
||||
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
||||
if (jvmPrimitiveType.getJvmLetter() == descriptor) {
|
||||
return jetStandardLibrary.getPrimitiveJetType(jvmPrimitiveType.getPrimitiveType());
|
||||
}
|
||||
}
|
||||
if (descriptor == 'V') {
|
||||
return JetStandardClasses.getUnitType();
|
||||
}
|
||||
} else {
|
||||
switch (descriptor) {
|
||||
case 'Z':
|
||||
return jetStandardLibrary.getNullableBooleanType();
|
||||
case 'C':
|
||||
return jetStandardLibrary.getNullableCharType();
|
||||
case 'B':
|
||||
return jetStandardLibrary.getNullableByteType();
|
||||
case 'S':
|
||||
return jetStandardLibrary.getNullableShortType();
|
||||
case 'I':
|
||||
return jetStandardLibrary.getNullableIntType();
|
||||
case 'F':
|
||||
return jetStandardLibrary.getNullableFloatType();
|
||||
case 'J':
|
||||
return jetStandardLibrary.getNullableLongType();
|
||||
case 'D':
|
||||
return jetStandardLibrary.getNullableDoubleType();
|
||||
case 'V':
|
||||
throw new IllegalStateException("incorrect signature: nullable void");
|
||||
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
||||
if (jvmPrimitiveType.getJvmLetter() == descriptor) {
|
||||
return jetStandardLibrary.getNullablePrimitiveJetType(jvmPrimitiveType.getPrimitiveType());
|
||||
}
|
||||
}
|
||||
if (descriptor == 'V') {
|
||||
throw new IllegalStateException("incorrect signature: nullable void");
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("incorrect signature");
|
||||
@@ -138,7 +114,7 @@ public abstract class JetTypeJetSignatureReader extends JetSignatureExceptionsAd
|
||||
JetType primitiveType = getPrimitiveType(descriptor, nullable);
|
||||
JetType arrayType;
|
||||
if (!nullable) {
|
||||
arrayType = jetStandardLibrary.getPrimitiveArrayType(primitiveType);
|
||||
arrayType = jetStandardLibrary.getPrimitiveArrayJetTypeByPrimitiveJetType(primitiveType);
|
||||
} else {
|
||||
arrayType = TypeUtils.makeNullableAsSpecified(jetStandardLibrary.getArrayType(primitiveType), nullable);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.jetbrains.jet.lang.resolve.java;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
@@ -39,4 +40,13 @@ public class JvmClassName {
|
||||
}
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
private Type asmType;
|
||||
|
||||
public Type getAsmType() {
|
||||
if (asmType == null) {
|
||||
asmType = Type.getType(getDescriptor());
|
||||
}
|
||||
return asmType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
package org.jetbrains.jet.lang.resolve.java;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.types.PrimitiveType;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public enum JvmPrimitiveType {
|
||||
BOOLEAN(PrimitiveType.BOOLEAN, "boolean", "java.lang.Boolean", Type.BOOLEAN_TYPE),
|
||||
CHAR(PrimitiveType.CHAR, "char", "java.lang.Character", Type.CHAR_TYPE),
|
||||
BYTE(PrimitiveType.BYTE, "byte", "java.lang.Byte", Type.BYTE_TYPE),
|
||||
SHORT(PrimitiveType.SHORT, "short", "java.lang.Short", Type.SHORT_TYPE),
|
||||
INT(PrimitiveType.INT, "int", "java.lang.Integer", Type.INT_TYPE),
|
||||
FLOAT(PrimitiveType.FLOAT, "float", "java.lang.Float", Type.FLOAT_TYPE),
|
||||
LONG(PrimitiveType.LONG, "long", "java.lang.Long", Type.LONG_TYPE),
|
||||
DOUBLE(PrimitiveType.DOUBLE, "double", "java.lang.Double", Type.DOUBLE_TYPE),
|
||||
;
|
||||
|
||||
private final PrimitiveType primitiveType;
|
||||
private final String name;
|
||||
private final JvmClassName wrapper;
|
||||
private final Type asmType;
|
||||
private final char jvmLetter;
|
||||
private final Type asmArrayType;
|
||||
private final JvmClassName iterator;
|
||||
|
||||
private JvmPrimitiveType(PrimitiveType primitiveType, String name, String wrapperClassName, Type asmType) {
|
||||
this.primitiveType = primitiveType;
|
||||
this.name = name;
|
||||
this.wrapper = new JvmClassName(wrapperClassName);
|
||||
this.asmType = asmType;
|
||||
this.jvmLetter = asmType.getDescriptor().charAt(0);
|
||||
this.asmArrayType = makeArrayType(asmType);
|
||||
this.iterator = new JvmClassName("jet." + primitiveType.getTypeName() + "Iterator");
|
||||
}
|
||||
|
||||
private static Type makeArrayType(Type type) {
|
||||
StringBuilder sb = new StringBuilder(2);
|
||||
sb.append('[');
|
||||
sb.append(type.getDescriptor());
|
||||
return Type.getType(sb.toString());
|
||||
}
|
||||
|
||||
public PrimitiveType getPrimitiveType() {
|
||||
return primitiveType;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public JvmClassName getWrapper() {
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
public Type getAsmType() {
|
||||
return asmType;
|
||||
}
|
||||
|
||||
public Type getAsmArrayType() {
|
||||
return asmArrayType;
|
||||
}
|
||||
|
||||
public JvmClassName getIterator() {
|
||||
return iterator;
|
||||
}
|
||||
|
||||
public char getJvmLetter() {
|
||||
return jvmLetter;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static class MapByAsmTypeHolder {
|
||||
private static final Map<Integer, JvmPrimitiveType> map;
|
||||
|
||||
static {
|
||||
map = new HashMap<Integer, JvmPrimitiveType>();
|
||||
for (JvmPrimitiveType jvmPrimitiveType : values()) {
|
||||
map.put(jvmPrimitiveType.getAsmType().getSort(), jvmPrimitiveType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JvmPrimitiveType getByAsmType(Type type) {
|
||||
return MapByAsmTypeHolder.map.get(type.getSort());
|
||||
}
|
||||
|
||||
|
||||
private static class MapByWrapperAsmTypeHolder {
|
||||
private static final Map<Type, JvmPrimitiveType> map;
|
||||
|
||||
static {
|
||||
map = new HashMap<Type, JvmPrimitiveType>();
|
||||
for (JvmPrimitiveType jvmPrimitiveType : values()) {
|
||||
map.put(jvmPrimitiveType.getWrapper().getAsmType(), jvmPrimitiveType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JvmPrimitiveType getByWrapperAsmType(Type type) {
|
||||
return MapByWrapperAsmTypeHolder.map.get(type);
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,9 @@ public class JvmStdlibNames {
|
||||
|
||||
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");
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.jetbrains.jet.lang.resolve.java;
|
||||
|
||||
import com.intellij.psi.PsiMember;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class PsiFieldWrapper extends PsiMemberWrapper {
|
||||
public PsiFieldWrapper(@NotNull PsiMember psiMember) {
|
||||
super(psiMember);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.jetbrains.jet.lang.resolve.java;
|
||||
|
||||
import com.intellij.psi.PsiMember;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class PsiMemberWrapper {
|
||||
|
||||
@NotNull
|
||||
protected final PsiMember psiMember;
|
||||
|
||||
public PsiMemberWrapper(@NotNull PsiMember psiMember) {
|
||||
this.psiMember = psiMember;
|
||||
}
|
||||
|
||||
public boolean isStatic() {
|
||||
return psiMember.hasModifierProperty(PsiModifier.STATIC);
|
||||
}
|
||||
|
||||
public boolean isPrivate() {
|
||||
return psiMember.hasModifierProperty(PsiModifier.PRIVATE);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class PsiMethodWrapper extends PsiMemberWrapper {
|
||||
|
||||
public PsiMethodWrapper(@NotNull PsiMethod psiMethod) {
|
||||
super(psiMethod);
|
||||
}
|
||||
|
||||
private List<PsiParameterWrapper> parameters;
|
||||
@NotNull
|
||||
public List<PsiParameterWrapper> getParameters() {
|
||||
if (parameters == null) {
|
||||
PsiParameter[] psiParameters = getPsiMethod().getParameterList().getParameters();
|
||||
parameters = new ArrayList<PsiParameterWrapper>(psiParameters.length);
|
||||
for (int i = 0; i < psiParameters.length; ++i) {
|
||||
parameters.add(new PsiParameterWrapper(psiParameters[i]));
|
||||
}
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PsiParameterWrapper getParameter(int i) {
|
||||
return getParameters().get(i);
|
||||
}
|
||||
|
||||
public boolean isFinal() {
|
||||
return psiMember.hasModifierProperty(PsiModifier.FINAL);
|
||||
}
|
||||
|
||||
private JetMethodAnnotation jetMethod;
|
||||
@NotNull
|
||||
public JetMethodAnnotation getJetMethod() {
|
||||
if (jetMethod == null) {
|
||||
jetMethod = JetMethodAnnotation.get(getPsiMethod());
|
||||
}
|
||||
return jetMethod;
|
||||
}
|
||||
|
||||
private JetConstructorAnnotation jetConstructor;
|
||||
@NotNull
|
||||
public JetConstructorAnnotation getJetConstructor() {
|
||||
if (jetConstructor == null) {
|
||||
jetConstructor = JetConstructorAnnotation.get(getPsiMethod());
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package org.jetbrains.jet.lang.resolve.java;
|
||||
|
||||
import com.intellij.psi.PsiParameter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.java.kt.JetTypeParameterAnnotation;
|
||||
import org.jetbrains.jet.lang.resolve.java.kt.JetValueParameterAnnotation;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class PsiParameterWrapper {
|
||||
private final PsiParameter psiParameter;
|
||||
|
||||
public PsiParameterWrapper(@NotNull PsiParameter psiParameter) {
|
||||
this.psiParameter = psiParameter;
|
||||
|
||||
this.jetValueParameter = JetValueParameterAnnotation.get(psiParameter);
|
||||
this.jetTypeParameter = JetTypeParameterAnnotation.get(psiParameter);
|
||||
}
|
||||
|
||||
private JetValueParameterAnnotation jetValueParameter;
|
||||
private JetTypeParameterAnnotation jetTypeParameter;
|
||||
|
||||
@NotNull
|
||||
public PsiParameter getPsiParameter() {
|
||||
return psiParameter;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetValueParameterAnnotation getJetValueParameter() {
|
||||
return jetValueParameter;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetTypeParameterAnnotation getJetTypeParameter() {
|
||||
return jetTypeParameter;
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package org.jetbrains.jet.lang.resolve.java.kt;
|
||||
|
||||
import com.intellij.psi.PsiAnnotation;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class JetClassAnnotation extends PsiAnnotationWrapper {
|
||||
|
||||
public JetClassAnnotation(@Nullable PsiAnnotation psiAnnotation) {
|
||||
super(psiAnnotation);
|
||||
}
|
||||
|
||||
private String signature;
|
||||
public String signature() {
|
||||
if (signature == null) {
|
||||
signature = getStringAttribute(JvmStdlibNames.JET_CLASS_SIGNATURE, "");
|
||||
}
|
||||
return signature;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetClassAnnotation get(PsiClass psiClass) {
|
||||
return new JetClassAnnotation(psiClass.getModifierList().findAnnotation(JvmStdlibNames.JET_CLASS.getFqName()));
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package org.jetbrains.jet.lang.resolve.java.kt;
|
||||
|
||||
import com.intellij.psi.PsiAnnotation;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class JetConstructorAnnotation extends PsiAnnotationWrapper {
|
||||
|
||||
public JetConstructorAnnotation(@Nullable PsiAnnotation psiAnnotation) {
|
||||
super(psiAnnotation);
|
||||
}
|
||||
|
||||
private boolean hidden;
|
||||
private boolean hiddenInitialized = false;
|
||||
/** @deprecated */
|
||||
public boolean hidden() {
|
||||
if (!hiddenInitialized) {
|
||||
hidden = getBooleanAttribute(JvmStdlibNames.JET_CONSTRUCTOR_HIDDEN_FIELD, false);
|
||||
hiddenInitialized = true;
|
||||
}
|
||||
return hidden;
|
||||
}
|
||||
|
||||
public static JetConstructorAnnotation get(PsiMethod constructor) {
|
||||
return new JetConstructorAnnotation(constructor.getModifierList().findAnnotation(JvmStdlibNames.JET_CONSTRUCTOR.getFqName()));
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
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 JetMethodAnnotation extends JetMethodOrPropertyAnnotation {
|
||||
|
||||
public JetMethodAnnotation(@Nullable PsiAnnotation psiAnnotation) {
|
||||
super(psiAnnotation);
|
||||
}
|
||||
|
||||
private String returnType;
|
||||
@NotNull
|
||||
public String returnType() {
|
||||
if (returnType == null) {
|
||||
returnType = getStringAttribute(JvmStdlibNames.JET_METHOD_RETURN_TYPE_FIELD, "");
|
||||
}
|
||||
return returnType;
|
||||
}
|
||||
|
||||
private boolean returnTypeNullable;
|
||||
private boolean returnTypeNullableInitialized;
|
||||
@NotNull
|
||||
public boolean returnTypeNullable() {
|
||||
if (!returnTypeNullableInitialized) {
|
||||
returnTypeNullable = getBooleanAttribute(JvmStdlibNames.JET_METHOD_NULLABLE_RETURN_TYPE_FIELD, false);
|
||||
returnTypeNullableInitialized = true;
|
||||
}
|
||||
return returnTypeNullable;
|
||||
}
|
||||
|
||||
public static JetMethodAnnotation get(PsiMethod psiMethod) {
|
||||
return new JetMethodAnnotation(psiMethod.getModifierList().findAnnotation(JvmStdlibNames.JET_METHOD.getFqName()));
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
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()));
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package org.jetbrains.jet.lang.resolve.java.kt;
|
||||
|
||||
import com.intellij.psi.PsiAnnotation;
|
||||
import com.intellij.psi.PsiParameter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class JetTypeParameterAnnotation extends PsiAnnotationWrapper {
|
||||
|
||||
protected JetTypeParameterAnnotation(@Nullable PsiAnnotation psiAnnotation) {
|
||||
super(psiAnnotation);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetTypeParameterAnnotation get(@NotNull PsiParameter psiParameter) {
|
||||
return new JetTypeParameterAnnotation(psiParameter.getModifierList().findAnnotation(JvmStdlibNames.JET_TYPE_PARAMETER.getFqName()));
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
package org.jetbrains.jet.lang.resolve.java.kt;
|
||||
|
||||
import com.intellij.psi.PsiAnnotation;
|
||||
import com.intellij.psi.PsiParameter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class JetValueParameterAnnotation extends PsiAnnotationWrapper {
|
||||
|
||||
public JetValueParameterAnnotation(@Nullable PsiAnnotation psiAnnotation) {
|
||||
super(psiAnnotation);
|
||||
}
|
||||
|
||||
private String name;
|
||||
@NotNull
|
||||
public String name() {
|
||||
if (name == null) {
|
||||
name = getStringAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_NAME_FIELD, "");
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
private String type;
|
||||
@NotNull
|
||||
public String type() {
|
||||
if (type == null) {
|
||||
type = getStringAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_TYPE_FIELD, "");
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
private boolean nullable;
|
||||
private boolean nullableInitialized = false;
|
||||
public boolean nullable() {
|
||||
if (!nullableInitialized) {
|
||||
nullable = getBooleanAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_NULLABLE_FIELD, false);
|
||||
nullableInitialized = true;
|
||||
}
|
||||
return nullable;
|
||||
}
|
||||
|
||||
private boolean receiver;
|
||||
private boolean receiverInitialized = false;
|
||||
public boolean receiver() {
|
||||
if (!receiverInitialized) {
|
||||
receiver = getBooleanAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_RECEIVER_FIELD, false);
|
||||
receiverInitialized = true;
|
||||
}
|
||||
return receiver;
|
||||
}
|
||||
|
||||
private boolean hasDefaultValue;
|
||||
private boolean hasDefaultValueInitialized = false;
|
||||
public boolean hasDefaultValue() {
|
||||
if (!hasDefaultValueInitialized) {
|
||||
hasDefaultValue = getBooleanAttribute(JvmStdlibNames.JET_VALUE_PARAMETER_HAS_DEFAULT_VALUE_FIELD, false);
|
||||
hasDefaultValueInitialized = true;
|
||||
}
|
||||
return hasDefaultValue;
|
||||
}
|
||||
|
||||
public static JetValueParameterAnnotation get(PsiParameter psiParameter) {
|
||||
return new JetValueParameterAnnotation(psiParameter.getModifierList().findAnnotation(JvmStdlibNames.JET_VALUE_PARAMETER.getFqName()));
|
||||
}
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package org.jetbrains.jet.lang.resolve.java.kt;
|
||||
|
||||
import com.intellij.psi.PsiAnnotation;
|
||||
import com.intellij.psi.PsiLiteralExpression;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class PsiAnnotationUtils {
|
||||
|
||||
@NotNull
|
||||
public static String getStringAttribute(@Nullable PsiAnnotation annotation, @NotNull String field, @NotNull String defaultValue) {
|
||||
return getAttribute(annotation, field, defaultValue);
|
||||
}
|
||||
|
||||
public static boolean getBooleanAttribute(@Nullable PsiAnnotation annotation, @NotNull String field, boolean defaultValue) {
|
||||
return getAttribute(annotation, field, defaultValue);
|
||||
}
|
||||
|
||||
private static <T> T getAttribute(@Nullable PsiAnnotation annotation, @NotNull String field, @NotNull T defaultValue) {
|
||||
if (annotation == null) {
|
||||
return defaultValue;
|
||||
} else {
|
||||
PsiLiteralExpression attributeValue = (PsiLiteralExpression) annotation.findAttributeValue(field);
|
||||
if (attributeValue != null) {
|
||||
return (T) attributeValue.getValue();
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package org.jetbrains.jet.lang.resolve.java.kt;
|
||||
|
||||
import com.intellij.psi.PsiAnnotation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public abstract class PsiAnnotationWrapper {
|
||||
|
||||
@Nullable
|
||||
private PsiAnnotation psiAnnotation;
|
||||
|
||||
protected PsiAnnotationWrapper(@Nullable PsiAnnotation psiAnnotation) {
|
||||
this.psiAnnotation = psiAnnotation;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PsiAnnotation getPsiAnnotation() {
|
||||
return psiAnnotation;
|
||||
}
|
||||
|
||||
public boolean isDefined() {
|
||||
return psiAnnotation != null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected String getStringAttribute(String name, String defaultValue) {
|
||||
return PsiAnnotationUtils.getStringAttribute(psiAnnotation, name, defaultValue);
|
||||
}
|
||||
|
||||
protected boolean getBooleanAttribute(String name, boolean defaultValue) {
|
||||
return PsiAnnotationUtils.getBooleanAttribute(psiAnnotation, name, defaultValue);
|
||||
}
|
||||
}
|
||||
+10
-33
@@ -5,7 +5,6 @@ import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.TransientReceiver;
|
||||
@@ -22,20 +21,20 @@ import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements FunctionDescriptor {
|
||||
public abstract class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements FunctionDescriptor {
|
||||
|
||||
private List<TypeParameterDescriptor> typeParameters;
|
||||
private List<ValueParameterDescriptor> unsubstitutedValueParameters;
|
||||
private JetType unsubstitutedReturnType;
|
||||
protected List<TypeParameterDescriptor> typeParameters;
|
||||
protected List<ValueParameterDescriptor> unsubstitutedValueParameters;
|
||||
protected JetType unsubstitutedReturnType;
|
||||
private ReceiverDescriptor receiver;
|
||||
private ReceiverDescriptor expectedThisObject;
|
||||
protected ReceiverDescriptor expectedThisObject;
|
||||
|
||||
private Modality modality;
|
||||
private Visibility visibility;
|
||||
protected Modality modality;
|
||||
protected Visibility visibility;
|
||||
private final Set<FunctionDescriptor> overriddenFunctions = Sets.newLinkedHashSet();
|
||||
private final FunctionDescriptor original;
|
||||
|
||||
public FunctionDescriptorImpl(
|
||||
protected FunctionDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull String name) {
|
||||
@@ -43,7 +42,7 @@ public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements
|
||||
this.original = this;
|
||||
}
|
||||
|
||||
public FunctionDescriptorImpl(
|
||||
protected FunctionDescriptorImpl(
|
||||
@NotNull FunctionDescriptor original,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull String name) {
|
||||
@@ -182,32 +181,10 @@ public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements
|
||||
return substitutedDescriptor;
|
||||
}
|
||||
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy() {
|
||||
return new FunctionDescriptorImpl(
|
||||
this,
|
||||
// TODO : safeSubstitute
|
||||
getAnnotations(),
|
||||
getName());
|
||||
}
|
||||
protected abstract FunctionDescriptorImpl createSubstitutedCopy();
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitFunctionDescriptor(this, data);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract) {
|
||||
FunctionDescriptorImpl copy = new FunctionDescriptorImpl(newOwner, Lists.newArrayList(getAnnotations()), getName());
|
||||
copy.initialize(
|
||||
getReceiverParameter().exists() ? getReceiverParameter().getType() : null,
|
||||
expectedThisObject,
|
||||
DescriptorUtils.copyTypeParameters(copy, typeParameters),
|
||||
DescriptorUtils.copyValueParameters(copy, unsubstitutedValueParameters),
|
||||
unsubstitutedReturnType,
|
||||
DescriptorUtils.convertModality(modality, makeNonAbstract),
|
||||
visibility
|
||||
);
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -27,7 +27,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
||||
private final Set<ConstructorDescriptor> constructors = Sets.newLinkedHashSet();
|
||||
private final Set<CallableMemberDescriptor> callableMembers = Sets.newHashSet();
|
||||
private final Set<PropertyDescriptor> properties = Sets.newHashSet();
|
||||
private final Set<FunctionDescriptor> functions = Sets.newHashSet();
|
||||
private final Set<NamedFunctionDescriptor> functions = Sets.newHashSet();
|
||||
private List<TypeParameterDescriptor> typeParameters = Lists.newArrayList();
|
||||
private Collection<JetType> supertypes = Lists.newArrayList();
|
||||
private Map<String, ClassDescriptor> innerClassesAndObjects = Maps.newHashMap();
|
||||
@@ -153,7 +153,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFunctionDescriptor(@NotNull FunctionDescriptor functionDescriptor) {
|
||||
public void addFunctionDescriptor(@NotNull NamedFunctionDescriptor functionDescriptor) {
|
||||
functions.add(functionDescriptor);
|
||||
callableMembers.add(functionDescriptor);
|
||||
scopeForMemberLookup.addFunctionDescriptor(functionDescriptor);
|
||||
@@ -161,7 +161,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<FunctionDescriptor> getFunctions() {
|
||||
public Set<NamedFunctionDescriptor> getFunctions() {
|
||||
return functions;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public interface NamedFunctionDescriptor extends FunctionDescriptor {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
NamedFunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract);
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class NamedFunctionDescriptorImpl extends FunctionDescriptorImpl implements NamedFunctionDescriptor {
|
||||
|
||||
public NamedFunctionDescriptorImpl(@NotNull DeclarationDescriptor containingDeclaration, @NotNull List<AnnotationDescriptor> annotations, @NotNull String name) {
|
||||
super(containingDeclaration, annotations, name);
|
||||
}
|
||||
|
||||
private NamedFunctionDescriptorImpl(@NotNull NamedFunctionDescriptor original, @NotNull List<AnnotationDescriptor> annotations, @NotNull String name) {
|
||||
super(original, annotations, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy() {
|
||||
return new NamedFunctionDescriptorImpl(
|
||||
this,
|
||||
// TODO : safeSubstitute
|
||||
getAnnotations(),
|
||||
getName());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public NamedFunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract) {
|
||||
NamedFunctionDescriptorImpl copy = new NamedFunctionDescriptorImpl(newOwner, Lists.newArrayList(getAnnotations()), getName());
|
||||
copy.initialize(
|
||||
getReceiverParameter().exists() ? getReceiverParameter().getType() : null,
|
||||
expectedThisObject,
|
||||
DescriptorUtils.copyTypeParameters(copy, typeParameters),
|
||||
DescriptorUtils.copyValueParameters(copy, unsubstitutedValueParameters),
|
||||
unsubstitutedReturnType,
|
||||
DescriptorUtils.convertModality(modality, makeNonAbstract),
|
||||
visibility
|
||||
);
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -49,7 +49,7 @@ public class NamespaceDescriptorImpl extends AbstractNamespaceDescriptorImpl imp
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFunctionDescriptor(@NotNull FunctionDescriptor functionDescriptor) {
|
||||
public void addFunctionDescriptor(@NotNull NamedFunctionDescriptor functionDescriptor) {
|
||||
memberScope.addFunctionDescriptor(functionDescriptor);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ public interface NamespaceLike extends DeclarationDescriptor {
|
||||
|
||||
void addObjectDescriptor(@NotNull MutableClassDescriptor objectDescriptor);
|
||||
|
||||
void addFunctionDescriptor(@NotNull FunctionDescriptor functionDescriptor);
|
||||
void addFunctionDescriptor(@NotNull NamedFunctionDescriptor functionDescriptor);
|
||||
|
||||
void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor);
|
||||
|
||||
|
||||
@@ -235,10 +235,8 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
newGetter.initialize(getter.getReturnType());
|
||||
}
|
||||
PropertySetterDescriptor newSetter = setter == null ? null : new PropertySetterDescriptor(
|
||||
DescriptorUtils.convertModality(setter.getModality(), makeNonAbstract), setter.getVisibility(),
|
||||
propertyDescriptor,
|
||||
Lists.newArrayList(setter.getAnnotations()),
|
||||
setter.hasBody(), setter.isDefault());
|
||||
propertyDescriptor, Lists.newArrayList(setter.getAnnotations()), DescriptorUtils.convertModality(setter.getModality(), makeNonAbstract), setter.getVisibility(),
|
||||
setter.hasBody(), setter.isDefault());
|
||||
if (newSetter != null) {
|
||||
newSetter.initialize(setter.getValueParameters().get(0).copy(newSetter));
|
||||
}
|
||||
|
||||
+7
-6
@@ -16,12 +16,13 @@ public class PropertySetterDescriptor extends PropertyAccessorDescriptor {
|
||||
|
||||
private ValueParameterDescriptor parameter;
|
||||
|
||||
public PropertySetterDescriptor(@NotNull Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
@NotNull PropertyDescriptor correspondingProperty,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
boolean hasBody,
|
||||
boolean isDefault) {
|
||||
public PropertySetterDescriptor(
|
||||
@NotNull PropertyDescriptor correspondingProperty,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
boolean hasBody,
|
||||
boolean isDefault) {
|
||||
super(modality, visibility, correspondingProperty, annotations, "set-" + correspondingProperty.getName(), hasBody, isDefault);
|
||||
if (isDefault) {
|
||||
initializeDefault();
|
||||
|
||||
@@ -42,6 +42,7 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
|
||||
return new TypeParameterDescriptor(containingDeclaration, annotations, reified, variance, name, index);
|
||||
}
|
||||
|
||||
// 0-based
|
||||
private final int index;
|
||||
private final Variance variance;
|
||||
private final Set<JetType> upperBounds;
|
||||
|
||||
+5
@@ -34,4 +34,9 @@ public class VariableAsFunctionDescriptor extends FunctionDescriptorImpl {
|
||||
public VariableAsFunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract) {
|
||||
throw new UnsupportedOperationException("Should not be copied for overriding");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
@@ -129,11 +129,11 @@ public interface Errors {
|
||||
return super.on(elementToBlame, nodeToMark, s, classDescriptor, modifierListOwner).add(DiagnosticParameters.CLASS, modifierListOwner);
|
||||
}
|
||||
};
|
||||
PsiElementOnlyDiagnosticFactory1<JetFunction, FunctionDescriptor> ABSTRACT_FUNCTION_WITH_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "A function {0} with body cannot be abstract");
|
||||
PsiElementOnlyDiagnosticFactory1<JetFunction, FunctionDescriptor> NON_ABSTRACT_FUNCTION_WITH_NO_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Method {0} without a body must be abstract");
|
||||
PsiElementOnlyDiagnosticFactory1<JetModifierListOwner, FunctionDescriptor> NON_MEMBER_ABSTRACT_FUNCTION = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Function {0} is not a class or trait member and cannot be abstract");
|
||||
PsiElementOnlyDiagnosticFactory1<JetFunction, NamedFunctionDescriptor> ABSTRACT_FUNCTION_WITH_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "A function {0} with body cannot be abstract");
|
||||
PsiElementOnlyDiagnosticFactory1<JetFunction, NamedFunctionDescriptor> NON_ABSTRACT_FUNCTION_WITH_NO_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Method {0} without a body must be abstract");
|
||||
PsiElementOnlyDiagnosticFactory1<JetModifierListOwner, NamedFunctionDescriptor> NON_MEMBER_ABSTRACT_FUNCTION = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Function {0} is not a class or trait member and cannot be abstract");
|
||||
|
||||
PsiElementOnlyDiagnosticFactory1<JetFunction, FunctionDescriptor> NON_MEMBER_FUNCTION_NO_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Function {0} must have a body");
|
||||
PsiElementOnlyDiagnosticFactory1<JetFunction, NamedFunctionDescriptor> NON_MEMBER_FUNCTION_NO_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Function {0} must have a body");
|
||||
|
||||
DiagnosticWithParameterFactory<JetNamedDeclaration, JetClass> NON_FINAL_MEMBER_IN_FINAL_CLASS = DiagnosticWithParameterFactory.create(ERROR, "Non final member in a final class", DiagnosticParameters.CLASS);
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
|
||||
private static final TokenSet TYPE_ARGUMENT_LIST_STOPPERS = TokenSet.create(
|
||||
INTEGER_LITERAL, FLOAT_LITERAL, CHARACTER_LITERAL, OPEN_QUOTE, RAW_STRING_LITERAL,
|
||||
NAMESPACE_KEYWORD, AS_KEYWORD, TYPE_KEYWORD, TRAIT_KEYWORD, CLASS_KEYWORD, THIS_KEYWORD, VAL_KEYWORD, VAR_KEYWORD,
|
||||
PACKAGE_KEYWORD, AS_KEYWORD, TYPE_KEYWORD, TRAIT_KEYWORD, CLASS_KEYWORD, THIS_KEYWORD, VAL_KEYWORD, VAR_KEYWORD,
|
||||
FUN_KEYWORD, FOR_KEYWORD, NULL_KEYWORD,
|
||||
TRUE_KEYWORD, FALSE_KEYWORD, IS_KEYWORD, THROW_KEYWORD, RETURN_KEYWORD, BREAK_KEYWORD,
|
||||
CONTINUE_KEYWORD, OBJECT_KEYWORD, IF_KEYWORD, TRY_KEYWORD, ELSE_KEYWORD, WHILE_KEYWORD, DO_KEYWORD,
|
||||
@@ -83,7 +83,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
IDENTIFIER, // SimpleName
|
||||
FIELD_IDENTIFIER, // Field reference
|
||||
|
||||
NAMESPACE_KEYWORD // for absolute qualified names
|
||||
PACKAGE_KEYWORD // for absolute qualified names
|
||||
);
|
||||
|
||||
private static final TokenSet STATEMENT_FIRST = TokenSet.orSet(
|
||||
@@ -509,7 +509,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
else if (at(HASH)) {
|
||||
parseTupleExpression();
|
||||
}
|
||||
else if (at(NAMESPACE_KEYWORD)) {
|
||||
else if (at(PACKAGE_KEYWORD)) {
|
||||
parseOneTokenExpression(ROOT_NAMESPACE);
|
||||
}
|
||||
else if (at(THIS_KEYWORD)) {
|
||||
@@ -865,7 +865,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
|
||||
myJetParsing.parseAnnotations(false);
|
||||
|
||||
if (at(NAMESPACE_KEYWORD) || at(IDENTIFIER) || at(FUN_KEYWORD) || at(THIS_KEYWORD)) {
|
||||
if (at(PACKAGE_KEYWORD) || at(IDENTIFIER) || at(FUN_KEYWORD) || at(THIS_KEYWORD)) {
|
||||
PsiBuilder.Marker rollbackMarker = mark();
|
||||
parseBinaryExpression(Precedence.ELVIS);
|
||||
if (at(HASH)) {
|
||||
|
||||
@@ -29,7 +29,7 @@ public class JetParsing extends AbstractJetParsing {
|
||||
}
|
||||
|
||||
private static final TokenSet TOPLEVEL_OBJECT_FIRST = TokenSet.create(TYPE_KEYWORD, TRAIT_KEYWORD, CLASS_KEYWORD,
|
||||
FUN_KEYWORD, VAL_KEYWORD, NAMESPACE_KEYWORD);
|
||||
FUN_KEYWORD, VAL_KEYWORD, PACKAGE_KEYWORD);
|
||||
private static final TokenSet ENUM_MEMBER_FIRST = TokenSet.create(TYPE_KEYWORD, TRAIT_KEYWORD, CLASS_KEYWORD,
|
||||
FUN_KEYWORD, VAL_KEYWORD, IDENTIFIER);
|
||||
|
||||
@@ -117,8 +117,8 @@ public class JetParsing extends AbstractJetParsing {
|
||||
PsiBuilder.Marker firstEntry = mark();
|
||||
parseModifierList(MODIFIER_LIST, true);
|
||||
|
||||
if (at(NAMESPACE_KEYWORD)) {
|
||||
advance(); // NAMESPACE_KEYWORD
|
||||
if (at(PACKAGE_KEYWORD)) {
|
||||
advance(); // PACKAGE_KEYWORD
|
||||
parseNamespaceName();
|
||||
|
||||
if (at(LBRACE)) {
|
||||
@@ -170,8 +170,8 @@ public class JetParsing extends AbstractJetParsing {
|
||||
advance(); // IMPORT_KEYWORD
|
||||
|
||||
PsiBuilder.Marker qualifiedName = mark();
|
||||
if (at(NAMESPACE_KEYWORD)) {
|
||||
advance(); // NAMESPACE_KEYWORD
|
||||
if (at(PACKAGE_KEYWORD)) {
|
||||
advance(); // PACKAGE_KEYWORD
|
||||
expect(DOT, "Expecting '.'", TokenSet.create(IDENTIFIER, MUL, SEMICOLON));
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ public class JetParsing extends AbstractJetParsing {
|
||||
|
||||
IElementType keywordToken = tt();
|
||||
JetNodeType declType = null;
|
||||
// if (keywordToken == NAMESPACE_KEYWORD) {
|
||||
// if (keywordToken == PACKAGE_KEYWORD) {
|
||||
// declType = parseNamespaceBlock();
|
||||
// }
|
||||
// else
|
||||
@@ -640,7 +640,7 @@ public class JetParsing extends AbstractJetParsing {
|
||||
parseClassBody();
|
||||
}
|
||||
else {
|
||||
expect(COLON, "Expecting ':'", TokenSet.create(IDENTIFIER, NAMESPACE_KEYWORD));
|
||||
expect(COLON, "Expecting ':'", TokenSet.create(IDENTIFIER, PACKAGE_KEYWORD));
|
||||
parseDelegationSpecifierList();
|
||||
parseClassBody();
|
||||
}
|
||||
@@ -1253,7 +1253,7 @@ public class JetParsing extends AbstractJetParsing {
|
||||
PsiBuilder.Marker typeRefMarker = mark();
|
||||
parseAnnotations(false);
|
||||
|
||||
if (at(IDENTIFIER) || at(NAMESPACE_KEYWORD)) {
|
||||
if (at(IDENTIFIER) || at(PACKAGE_KEYWORD)) {
|
||||
parseUserType();
|
||||
}
|
||||
else if (at(HASH)) {
|
||||
@@ -1340,8 +1340,8 @@ public class JetParsing extends AbstractJetParsing {
|
||||
private void parseUserType() {
|
||||
PsiBuilder.Marker userType = mark();
|
||||
|
||||
if (at(NAMESPACE_KEYWORD)) {
|
||||
advance(); // NAMESPACE_KEYWORD
|
||||
if (at(PACKAGE_KEYWORD)) {
|
||||
advance(); // PACKAGE_KEYWORD
|
||||
expect(DOT, "Expecting '.'", TokenSet.create(IDENTIFIER));
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public class JetImportDirective extends JetElement {
|
||||
}
|
||||
|
||||
public boolean isAbsoluteInRootNamespace() {
|
||||
return findChildByType(JetTokens.NAMESPACE_KEYWORD) != null;
|
||||
return findChildByType(JetTokens.PACKAGE_KEYWORD) != null;
|
||||
}
|
||||
|
||||
@Nullable @IfNotParsed
|
||||
|
||||
@@ -19,7 +19,7 @@ public class JetUserType extends JetTypeElement {
|
||||
}
|
||||
|
||||
public boolean isAbsoluteInRootNamespace() {
|
||||
return findChildByType(JetTokens.NAMESPACE_KEYWORD) != null;
|
||||
return findChildByType(JetTokens.PACKAGE_KEYWORD) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -122,7 +122,7 @@ public class AnalyzingUtils {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFunctionDescriptor(@NotNull FunctionDescriptor functionDescriptor) {
|
||||
public void addFunctionDescriptor(@NotNull NamedFunctionDescriptor functionDescriptor) {
|
||||
scope.addFunctionDescriptor(functionDescriptor);
|
||||
}
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ public interface BindingContext {
|
||||
WritableSlice<PsiElement, NamespaceDescriptor> NAMESPACE = Slices.<PsiElement, NamespaceDescriptor>sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build();
|
||||
WritableSlice<PsiElement, ClassDescriptor> CLASS = Slices.<PsiElement, ClassDescriptor>sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build();
|
||||
WritableSlice<JetTypeParameter, TypeParameterDescriptor> TYPE_PARAMETER = Slices.<JetTypeParameter, TypeParameterDescriptor>sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build();
|
||||
WritableSlice<PsiElement, FunctionDescriptor> FUNCTION = Slices.<PsiElement, FunctionDescriptor>sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build();
|
||||
WritableSlice<PsiElement, NamedFunctionDescriptor> FUNCTION = Slices.<PsiElement, NamedFunctionDescriptor>sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build();
|
||||
WritableSlice<PsiElement, ConstructorDescriptor> CONSTRUCTOR = Slices.<PsiElement, ConstructorDescriptor>sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build();
|
||||
WritableSlice<PsiElement, VariableDescriptor> VARIABLE = Slices.<PsiElement, VariableDescriptor>sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build();
|
||||
WritableSlice<JetParameter, VariableDescriptor> VALUE_PARAMETER = Slices.<JetParameter, VariableDescriptor>sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build();
|
||||
|
||||
@@ -467,9 +467,9 @@ public class BodyResolver {
|
||||
}
|
||||
|
||||
private void resolveFunctionBodies() {
|
||||
for (Map.Entry<JetNamedFunction, FunctionDescriptorImpl> entry : this.context.getFunctions().entrySet()) {
|
||||
for (Map.Entry<JetNamedFunction, NamedFunctionDescriptor> entry : this.context.getFunctions().entrySet()) {
|
||||
JetNamedFunction declaration = entry.getKey();
|
||||
FunctionDescriptor descriptor = entry.getValue();
|
||||
NamedFunctionDescriptor descriptor = entry.getValue();
|
||||
|
||||
computeDeferredType(descriptor.getReturnType());
|
||||
|
||||
|
||||
@@ -34,9 +34,9 @@ public class ControlFlowAnalyzer {
|
||||
if (!context.completeAnalysisNeeded(objectDeclaration)) continue;
|
||||
checkClassOrObject(objectDeclaration);
|
||||
}
|
||||
for (Map.Entry<JetNamedFunction, FunctionDescriptorImpl> entry : context.getFunctions().entrySet()) {
|
||||
for (Map.Entry<JetNamedFunction, NamedFunctionDescriptor> entry : context.getFunctions().entrySet()) {
|
||||
JetNamedFunction function = entry.getKey();
|
||||
FunctionDescriptorImpl functionDescriptor = entry.getValue();
|
||||
NamedFunctionDescriptor functionDescriptor = entry.getValue();
|
||||
if (!context.completeAnalysisNeeded(function)) continue;
|
||||
final JetType expectedReturnType = !function.hasBlockBody() && !function.hasDeclaredReturnType()
|
||||
? NO_EXPECTED_TYPE
|
||||
|
||||
@@ -103,7 +103,7 @@ public class DeclarationResolver {
|
||||
declaration.accept(new JetVisitorVoid() {
|
||||
@Override
|
||||
public void visitNamedFunction(JetNamedFunction function) {
|
||||
FunctionDescriptorImpl functionDescriptor = context.getDescriptorResolver().resolveFunctionDescriptor(namespaceLike, scopeForFunctions, function);
|
||||
NamedFunctionDescriptor functionDescriptor = context.getDescriptorResolver().resolveFunctionDescriptor(namespaceLike, scopeForFunctions, function);
|
||||
namespaceLike.addFunctionDescriptor(functionDescriptor);
|
||||
context.getFunctions().put(function, functionDescriptor);
|
||||
context.getDeclaringScopes().put(function, scopeForFunctions);
|
||||
|
||||
@@ -55,10 +55,10 @@ public class DeclarationsChecker {
|
||||
checkObject(objectDeclaration, objectDescriptor);
|
||||
}
|
||||
|
||||
Map<JetNamedFunction, FunctionDescriptorImpl> functions = context.getFunctions();
|
||||
for (Map.Entry<JetNamedFunction, FunctionDescriptorImpl> entry : functions.entrySet()) {
|
||||
Map<JetNamedFunction, NamedFunctionDescriptor> functions = context.getFunctions();
|
||||
for (Map.Entry<JetNamedFunction, NamedFunctionDescriptor> entry : functions.entrySet()) {
|
||||
JetNamedFunction function = entry.getKey();
|
||||
FunctionDescriptorImpl functionDescriptor = entry.getValue();
|
||||
NamedFunctionDescriptor functionDescriptor = entry.getValue();
|
||||
|
||||
if (!context.completeAnalysisNeeded(function)) continue;
|
||||
checkFunction(function, functionDescriptor);
|
||||
@@ -254,7 +254,7 @@ public class DeclarationsChecker {
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkFunction(JetNamedFunction function, FunctionDescriptor functionDescriptor) {
|
||||
protected void checkFunction(JetNamedFunction function, NamedFunctionDescriptor functionDescriptor) {
|
||||
DeclarationDescriptor containingDescriptor = functionDescriptor.getContainingDeclaration();
|
||||
PsiElement nameIdentifier = function.getNameIdentifier();
|
||||
JetModifierList modifierList = function.getModifierList();
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.jetbrains.jet.lang.resolve;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.MutableClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamedFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
@@ -49,10 +50,10 @@ public class DelegationResolver {
|
||||
context.getTrace().record(DELEGATED, copy);
|
||||
}
|
||||
}
|
||||
else if (declarationDescriptor instanceof FunctionDescriptor) {
|
||||
FunctionDescriptor functionDescriptor = (FunctionDescriptor) declarationDescriptor;
|
||||
else if (declarationDescriptor instanceof NamedFunctionDescriptor) {
|
||||
NamedFunctionDescriptor functionDescriptor = (NamedFunctionDescriptor) declarationDescriptor;
|
||||
if (functionDescriptor.getModality().isOverridable()) {
|
||||
FunctionDescriptor copy = functionDescriptor.copy(classDescriptor, true);
|
||||
NamedFunctionDescriptor copy = functionDescriptor.copy(classDescriptor, true);
|
||||
classDescriptor.addFunctionDescriptor(copy);
|
||||
context.getTrace().record(DELEGATED, copy);
|
||||
}
|
||||
|
||||
@@ -139,8 +139,8 @@ public class DescriptorResolver {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public FunctionDescriptorImpl resolveFunctionDescriptor(DeclarationDescriptor containingDescriptor, final JetScope scope, final JetNamedFunction function) {
|
||||
final FunctionDescriptorImpl functionDescriptor = new FunctionDescriptorImpl(
|
||||
public NamedFunctionDescriptor resolveFunctionDescriptor(DeclarationDescriptor containingDescriptor, final JetScope scope, final JetNamedFunction function) {
|
||||
final NamedFunctionDescriptorImpl functionDescriptor = new NamedFunctionDescriptorImpl(
|
||||
containingDescriptor,
|
||||
annotationResolver.resolveAnnotations(scope, function.getModifierList()),
|
||||
JetPsiUtil.safeName(function.getName())
|
||||
@@ -276,31 +276,12 @@ public class DescriptorResolver {
|
||||
|
||||
private JetType getVarargParameterType(JetType type) {
|
||||
JetStandardLibrary standardLibrary = semanticServices.getStandardLibrary();
|
||||
if (type.equals(standardLibrary.getByteType())) {
|
||||
return standardLibrary.getByteArrayType();
|
||||
JetType arrayType = standardLibrary.getPrimitiveArrayJetTypeByPrimitiveJetType(type);
|
||||
if (arrayType != null) {
|
||||
return arrayType;
|
||||
} else {
|
||||
return standardLibrary.getArrayType(type);
|
||||
}
|
||||
if (type.equals(standardLibrary.getCharType())) {
|
||||
return standardLibrary.getCharArrayType();
|
||||
}
|
||||
if (type.equals(standardLibrary.getShortType())) {
|
||||
return standardLibrary.getShortArrayType();
|
||||
}
|
||||
if (type.equals(standardLibrary.getIntType())) {
|
||||
return standardLibrary.getIntArrayType();
|
||||
}
|
||||
if (type.equals(standardLibrary.getLongType())) {
|
||||
return standardLibrary.getLongArrayType();
|
||||
}
|
||||
if (type.equals(standardLibrary.getFloatType())) {
|
||||
return standardLibrary.getFloatArrayType();
|
||||
}
|
||||
if (type.equals(standardLibrary.getDoubleType())) {
|
||||
return standardLibrary.getDoubleArrayType();
|
||||
}
|
||||
if (type.equals(standardLibrary.getBooleanType())) {
|
||||
return standardLibrary.getBooleanArrayType();
|
||||
}
|
||||
return standardLibrary.getArrayType(type);
|
||||
}
|
||||
|
||||
public List<TypeParameterDescriptor> resolveTypeParameters(DeclarationDescriptor containingDescriptor, WritableScope extensibleScope, List<JetTypeParameter> typeParameters) {
|
||||
@@ -668,9 +649,9 @@ public class DescriptorResolver {
|
||||
JetParameter parameter = setter.getParameter();
|
||||
|
||||
setterDescriptor = new PropertySetterDescriptor(
|
||||
resolveModalityFromModifiers(setter.getModifierList(), propertyDescriptor.getModality()),
|
||||
propertyDescriptor, annotations, resolveModalityFromModifiers(setter.getModifierList(), propertyDescriptor.getModality()),
|
||||
resolveVisibilityFromModifiers(setter.getModifierList(), propertyDescriptor.getVisibility()),
|
||||
propertyDescriptor, annotations, setter.getBodyExpression() != null, false);
|
||||
setter.getBodyExpression() != null, false);
|
||||
if (parameter != null) {
|
||||
if (parameter.isRef()) {
|
||||
// trace.getErrorHandler().genericError(parameter.getRefNode(), "Setter parameters can not be 'ref'");
|
||||
@@ -728,9 +709,9 @@ public class DescriptorResolver {
|
||||
private PropertySetterDescriptor createDefaultSetter(PropertyDescriptor propertyDescriptor) {
|
||||
PropertySetterDescriptor setterDescriptor;
|
||||
setterDescriptor = new PropertySetterDescriptor(
|
||||
propertyDescriptor.getModality(),
|
||||
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), propertyDescriptor.getModality(),
|
||||
propertyDescriptor.getVisibility(),
|
||||
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), false, true);
|
||||
false, true);
|
||||
return setterDescriptor;
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ public class OverloadResolver {
|
||||
|
||||
MultiMap<Key, FunctionDescriptor> functionsByName = MultiMap.create();
|
||||
|
||||
for (FunctionDescriptorImpl function : context.getFunctions().values()) {
|
||||
for (NamedFunctionDescriptor function : context.getFunctions().values()) {
|
||||
DeclarationDescriptor containingDeclaration = function.getContainingDeclaration();
|
||||
if (containingDeclaration instanceof NamespaceDescriptor) {
|
||||
NamespaceDescriptor namespaceDescriptor = (NamespaceDescriptor) containingDeclaration;
|
||||
|
||||
@@ -34,7 +34,7 @@ import java.util.Set;
|
||||
protected final Map<JetFile, NamespaceDescriptorImpl> namespaceDescriptors = Maps.newHashMap();
|
||||
|
||||
private final Map<JetDeclaration, JetScope> declaringScopes = Maps.newHashMap();
|
||||
private final Map<JetNamedFunction, FunctionDescriptorImpl> functions = Maps.newLinkedHashMap();
|
||||
private final Map<JetNamedFunction, NamedFunctionDescriptor> functions = Maps.newLinkedHashMap();
|
||||
private final Map<JetSecondaryConstructor, ConstructorDescriptor> constructors = Maps.newLinkedHashMap();
|
||||
private final Map<JetProperty, PropertyDescriptor> properties = Maps.newLinkedHashMap();
|
||||
private final Set<PropertyDescriptor> primaryConstructorParameterProperties = Sets.newHashSet();
|
||||
@@ -138,7 +138,7 @@ import java.util.Set;
|
||||
return declaringScopes;
|
||||
}
|
||||
|
||||
public Map<JetNamedFunction, FunctionDescriptorImpl> getFunctions() {
|
||||
public Map<JetNamedFunction, NamedFunctionDescriptor> getFunctions() {
|
||||
return functions;
|
||||
}
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ public class TopDownAnalyzer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFunctionDescriptor(@NotNull FunctionDescriptor functionDescriptor) {
|
||||
public void addFunctionDescriptor(@NotNull NamedFunctionDescriptor functionDescriptor) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
+11
@@ -18,4 +18,15 @@ public class ExpressionAsFunctionDescriptor extends FunctionDescriptorImpl {
|
||||
public ExpressionAsFunctionDescriptor(DeclarationDescriptor containingDeclaration, String name) {
|
||||
super(containingDeclaration, Collections.<AnnotationDescriptor>emptyList(), name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ public class ErrorUtils {
|
||||
private static final Set<VariableDescriptor> ERROR_PROPERTY_GROUP = Collections.singleton(ERROR_PROPERTY);
|
||||
|
||||
private static FunctionDescriptor createErrorFunction(List<TypeParameterDescriptor> typeParameters, List<JetType> positionedValueArgumentTypes) {
|
||||
FunctionDescriptorImpl functionDescriptor = new FunctionDescriptorImpl(ERROR_CLASS, Collections.<AnnotationDescriptor>emptyList(), "<ERROR FUNCTION>");
|
||||
FunctionDescriptorImpl functionDescriptor = new NamedFunctionDescriptorImpl(ERROR_CLASS, Collections.<AnnotationDescriptor>emptyList(), "<ERROR FUNCTION>");
|
||||
return functionDescriptor.initialize(
|
||||
null,
|
||||
ReceiverDescriptor.NO_RECEIVER,
|
||||
@@ -139,7 +139,7 @@ public class ErrorUtils {
|
||||
}
|
||||
|
||||
public static FunctionDescriptor createErrorFunction(int typeParameterCount, List<JetType> positionedValueParameterTypes) {
|
||||
return new FunctionDescriptorImpl(ERROR_CLASS, Collections.<AnnotationDescriptor>emptyList(), "<ERROR FUNCTION>").initialize(
|
||||
return new NamedFunctionDescriptorImpl(ERROR_CLASS, Collections.<AnnotationDescriptor>emptyList(), "<ERROR FUNCTION>").initialize(
|
||||
null,
|
||||
ReceiverDescriptor.NO_RECEIVER,
|
||||
Collections.<TypeParameterDescriptor>emptyList(), // TODO
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.psi.PsiFileFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
@@ -50,14 +51,6 @@ public class JetStandardLibrary {
|
||||
private JetScope libraryScope;
|
||||
|
||||
private ClassDescriptor numberClass;
|
||||
private ClassDescriptor byteClass;
|
||||
private ClassDescriptor charClass;
|
||||
private ClassDescriptor shortClass;
|
||||
private ClassDescriptor intClass;
|
||||
private ClassDescriptor longClass;
|
||||
private ClassDescriptor floatClass;
|
||||
private ClassDescriptor doubleClass;
|
||||
private ClassDescriptor booleanClass;
|
||||
|
||||
private ClassDescriptor stringClass;
|
||||
private ClassDescriptor arrayClass;
|
||||
@@ -65,54 +58,10 @@ public class JetStandardLibrary {
|
||||
private ClassDescriptor typeInfoClass;
|
||||
private ClassDescriptor comparableClass;
|
||||
|
||||
private JetType byteType;
|
||||
private JetType charType;
|
||||
private JetType shortType;
|
||||
private JetType intType;
|
||||
private JetType longType;
|
||||
private JetType floatType;
|
||||
private JetType doubleType;
|
||||
private JetType booleanType;
|
||||
|
||||
private JetType stringType;
|
||||
|
||||
private JetType nullableByteType;
|
||||
private JetType nullableCharType;
|
||||
private JetType nullableShortType;
|
||||
private JetType nullableIntType;
|
||||
private JetType nullableLongType;
|
||||
private JetType nullableFloatType;
|
||||
private JetType nullableDoubleType;
|
||||
private JetType nullableBooleanType;
|
||||
private JetType nullableTuple0Type;
|
||||
|
||||
private ClassDescriptor byteArrayClass;
|
||||
private ClassDescriptor charArrayClass;
|
||||
private ClassDescriptor shortArrayClass;
|
||||
private ClassDescriptor intArrayClass;
|
||||
private ClassDescriptor longArrayClass;
|
||||
private ClassDescriptor floatArrayClass;
|
||||
private ClassDescriptor doubleArrayClass;
|
||||
private ClassDescriptor booleanArrayClass;
|
||||
|
||||
private JetType byteArrayType;
|
||||
private JetType charArrayType;
|
||||
private JetType shortArrayType;
|
||||
private JetType intArrayType;
|
||||
private JetType longArrayType;
|
||||
private JetType floatArrayType;
|
||||
private JetType doubleArrayType;
|
||||
private JetType booleanArrayType;
|
||||
|
||||
private JetType nullableByteArrayType;
|
||||
private JetType nullableCharArrayType;
|
||||
private JetType nullableShortArrayType;
|
||||
private JetType nullableIntArrayType;
|
||||
private JetType nullableLongArrayType;
|
||||
private JetType nullableFloatArrayType;
|
||||
private JetType nullableDoubleArrayType;
|
||||
private JetType nullableBooleanArrayType;
|
||||
|
||||
public JetType getTuple0Type() {
|
||||
return tuple0Type;
|
||||
}
|
||||
@@ -122,6 +71,14 @@ public class JetStandardLibrary {
|
||||
|
||||
private Set<FunctionDescriptor> typeInfoFunction;
|
||||
|
||||
private EnumMap<PrimitiveType, ClassDescriptor> primitiveTypeToClass;
|
||||
private EnumMap<PrimitiveType, ClassDescriptor> primitiveTypeToArrayClass;
|
||||
private EnumMap<PrimitiveType, JetType> primitiveTypeToJetType;
|
||||
private EnumMap<PrimitiveType, JetType> primitiveTypeToNullableJetType;
|
||||
private EnumMap<PrimitiveType, JetType> primitiveTypeToArrayJetType;
|
||||
private EnumMap<PrimitiveType, JetType> primitiveTypeToNullableArrayJetType;
|
||||
private Map<JetType, JetType> primitiveJetTypeToJetArrayType;
|
||||
|
||||
private JetStandardLibrary(@NotNull Project project) {
|
||||
// TODO : review
|
||||
List<String> libraryFiles = Arrays.asList(
|
||||
@@ -168,14 +125,6 @@ public class JetStandardLibrary {
|
||||
if(libraryScope == null) {
|
||||
this.libraryScope = JetStandardClasses.STANDARD_CLASSES_NAMESPACE.getMemberScope();
|
||||
this.numberClass = (ClassDescriptor) libraryScope.getClassifier("Number");
|
||||
this.byteClass = (ClassDescriptor) libraryScope.getClassifier("Byte");
|
||||
this.charClass = (ClassDescriptor) libraryScope.getClassifier("Char");
|
||||
this.shortClass = (ClassDescriptor) libraryScope.getClassifier("Short");
|
||||
this.intClass = (ClassDescriptor) libraryScope.getClassifier("Int");
|
||||
this.longClass = (ClassDescriptor) libraryScope.getClassifier("Long");
|
||||
this.floatClass = (ClassDescriptor) libraryScope.getClassifier("Float");
|
||||
this.doubleClass = (ClassDescriptor) libraryScope.getClassifier("Double");
|
||||
this.booleanClass = (ClassDescriptor) libraryScope.getClassifier("Boolean");
|
||||
this.stringClass = (ClassDescriptor) libraryScope.getClassifier("String");
|
||||
this.arrayClass = (ClassDescriptor) libraryScope.getClassifier("Array");
|
||||
|
||||
@@ -185,59 +134,41 @@ public class JetStandardLibrary {
|
||||
this.typeInfoClass = (ClassDescriptor) libraryScope.getClassifier("TypeInfo");
|
||||
this.typeInfoFunction = libraryScope.getFunctions("typeinfo");
|
||||
|
||||
this.byteType = new JetTypeImpl(getByte());
|
||||
this.charType = new JetTypeImpl(getChar());
|
||||
this.shortType = new JetTypeImpl(getShort());
|
||||
this.intType = new JetTypeImpl(getInt());
|
||||
this.longType = new JetTypeImpl(getLong());
|
||||
this.floatType = new JetTypeImpl(getFloat());
|
||||
this.doubleType = new JetTypeImpl(getDouble());
|
||||
this.booleanType = new JetTypeImpl(getBoolean());
|
||||
|
||||
this.stringType = new JetTypeImpl(getString());
|
||||
this.nullableStringType = TypeUtils.makeNullable(stringType);
|
||||
|
||||
this.tuple0Type = new JetTypeImpl(JetStandardClasses.getTuple(0));
|
||||
this.nullableTuple0Type = TypeUtils.makeNullable(tuple0Type);
|
||||
|
||||
primitiveTypeToClass = new EnumMap<PrimitiveType, ClassDescriptor>(PrimitiveType.class);
|
||||
primitiveTypeToJetType = new EnumMap<PrimitiveType, JetType>(PrimitiveType.class);
|
||||
primitiveTypeToNullableJetType = new EnumMap<PrimitiveType, JetType>(PrimitiveType.class);
|
||||
primitiveTypeToArrayClass = new EnumMap<PrimitiveType, ClassDescriptor>(PrimitiveType.class);
|
||||
primitiveTypeToArrayJetType = new EnumMap<PrimitiveType, JetType>(PrimitiveType.class);
|
||||
primitiveTypeToNullableArrayJetType = new EnumMap<PrimitiveType, JetType>(PrimitiveType.class);
|
||||
primitiveJetTypeToJetArrayType = new HashMap<JetType, JetType>();
|
||||
|
||||
this.nullableByteType = TypeUtils.makeNullable(byteType);
|
||||
this.nullableCharType = TypeUtils.makeNullable(charType);
|
||||
this.nullableShortType = TypeUtils.makeNullable(shortType);
|
||||
this.nullableIntType = TypeUtils.makeNullable(intType);
|
||||
this.nullableLongType = TypeUtils.makeNullable(longType);
|
||||
this.nullableFloatType = TypeUtils.makeNullable(floatType);
|
||||
this.nullableDoubleType = TypeUtils.makeNullable(doubleType);
|
||||
this.nullableBooleanType = TypeUtils.makeNullable(booleanType);
|
||||
|
||||
this.byteArrayClass = (ClassDescriptor) libraryScope.getClassifier("ByteArray");
|
||||
this.charArrayClass = (ClassDescriptor) libraryScope.getClassifier("CharArray");
|
||||
this.shortArrayClass = (ClassDescriptor) libraryScope.getClassifier("ShortArray");
|
||||
this.intArrayClass = (ClassDescriptor) libraryScope.getClassifier("IntArray");
|
||||
this.longArrayClass = (ClassDescriptor) libraryScope.getClassifier("LongArray");
|
||||
this.floatArrayClass = (ClassDescriptor) libraryScope.getClassifier("FloatArray");
|
||||
this.doubleArrayClass = (ClassDescriptor) libraryScope.getClassifier("DoubleArray");
|
||||
this.booleanArrayClass = (ClassDescriptor) libraryScope.getClassifier("BooleanArray");
|
||||
|
||||
this.byteArrayType = new JetTypeImpl(byteArrayClass);
|
||||
this.charArrayType = new JetTypeImpl(charArrayClass);
|
||||
this.shortArrayType = new JetTypeImpl(shortArrayClass);
|
||||
this.intArrayType = new JetTypeImpl(intArrayClass);
|
||||
this.longArrayType = new JetTypeImpl(longArrayClass);
|
||||
this.floatArrayType = new JetTypeImpl(floatArrayClass);
|
||||
this.doubleArrayType = new JetTypeImpl(doubleArrayClass);
|
||||
this.booleanArrayType = new JetTypeImpl(booleanArrayClass);
|
||||
|
||||
this.nullableByteArrayType = TypeUtils.makeNullable(byteArrayType);
|
||||
this.nullableCharArrayType = TypeUtils.makeNullable(charArrayType);
|
||||
this.nullableShortArrayType = TypeUtils.makeNullable(shortArrayType);
|
||||
this.nullableIntArrayType = TypeUtils.makeNullable(intArrayType);
|
||||
this.nullableLongArrayType = TypeUtils.makeNullable(longArrayType);
|
||||
this.nullableFloatArrayType = TypeUtils.makeNullable(floatArrayType);
|
||||
this.nullableDoubleArrayType = TypeUtils.makeNullable(doubleArrayType);
|
||||
this.nullableBooleanArrayType = TypeUtils.makeNullable(booleanArrayType);
|
||||
for (PrimitiveType primitive : PrimitiveType.values()) {
|
||||
makePrimitive(primitive);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void makePrimitive(PrimitiveType primitiveType) {
|
||||
ClassDescriptor clazz = (ClassDescriptor) libraryScope.getClassifier(primitiveType.getTypeName());
|
||||
ClassDescriptor arrayClazz = (ClassDescriptor) libraryScope.getClassifier(primitiveType.getTypeName() + "Array");
|
||||
JetTypeImpl type = new JetTypeImpl(clazz);
|
||||
JetTypeImpl arrayType = new JetTypeImpl(arrayClazz);
|
||||
|
||||
primitiveTypeToClass.put(primitiveType, clazz);
|
||||
primitiveTypeToJetType.put(primitiveType, type);
|
||||
primitiveTypeToNullableJetType.put(primitiveType, TypeUtils.makeNullable(type));
|
||||
primitiveTypeToArrayClass.put(primitiveType, arrayClazz);
|
||||
primitiveTypeToArrayJetType.put(primitiveType, arrayType);
|
||||
primitiveTypeToNullableArrayJetType.put(primitiveType, TypeUtils.makeNullable(arrayType));
|
||||
primitiveJetTypeToJetArrayType.put(type, arrayType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getNumber() {
|
||||
initStdClasses();
|
||||
@@ -245,51 +176,49 @@ public class JetStandardLibrary {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getByte() {
|
||||
public ClassDescriptor getPrimitiveClassDescriptor(PrimitiveType primitiveType) {
|
||||
initStdClasses();
|
||||
return byteClass;
|
||||
return primitiveTypeToClass.get(primitiveType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getByte() {
|
||||
return getPrimitiveClassDescriptor(PrimitiveType.BYTE);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getChar() {
|
||||
initStdClasses();
|
||||
return charClass;
|
||||
return getPrimitiveClassDescriptor(PrimitiveType.CHAR);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getShort() {
|
||||
initStdClasses();
|
||||
return shortClass;
|
||||
return getPrimitiveClassDescriptor(PrimitiveType.SHORT);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getInt() {
|
||||
initStdClasses();
|
||||
return intClass;
|
||||
return getPrimitiveClassDescriptor(PrimitiveType.INT);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getLong() {
|
||||
initStdClasses();
|
||||
return longClass;
|
||||
return getPrimitiveClassDescriptor(PrimitiveType.LONG);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getFloat() {
|
||||
initStdClasses();
|
||||
return floatClass;
|
||||
return getPrimitiveClassDescriptor(PrimitiveType.FLOAT);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getDouble() {
|
||||
initStdClasses();
|
||||
return doubleClass;
|
||||
return getPrimitiveClassDescriptor(PrimitiveType.DOUBLE);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getBoolean() {
|
||||
initStdClasses();
|
||||
return booleanClass;
|
||||
return getPrimitiveClassDescriptor(PrimitiveType.BOOLEAN);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -338,40 +267,39 @@ public class JetStandardLibrary {
|
||||
return new JetTypeImpl(Collections.<AnnotationDescriptor>emptyList(), getTypeInfo().getTypeConstructor(), false, arguments, getTypeInfo().getMemberScope(arguments));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetType getPrimitiveJetType(PrimitiveType primitiveType) {
|
||||
return primitiveTypeToJetType.get(primitiveType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetType getIntType() {
|
||||
initStdClasses();
|
||||
return intType;
|
||||
return getPrimitiveJetType(PrimitiveType.INT);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetType getLongType() {
|
||||
initStdClasses();
|
||||
return longType;
|
||||
return getPrimitiveJetType(PrimitiveType.LONG);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetType getDoubleType() {
|
||||
initStdClasses();
|
||||
return doubleType;
|
||||
return getPrimitiveJetType(PrimitiveType.DOUBLE);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetType getFloatType() {
|
||||
initStdClasses();
|
||||
return floatType;
|
||||
return getPrimitiveJetType(PrimitiveType.FLOAT);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetType getCharType() {
|
||||
initStdClasses();
|
||||
return charType;
|
||||
return getPrimitiveJetType(PrimitiveType.CHAR);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetType getBooleanType() {
|
||||
initStdClasses();
|
||||
return booleanType;
|
||||
return getPrimitiveJetType(PrimitiveType.BOOLEAN);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -382,14 +310,12 @@ public class JetStandardLibrary {
|
||||
|
||||
@NotNull
|
||||
public JetType getByteType() {
|
||||
initStdClasses();
|
||||
return byteType;
|
||||
return getPrimitiveJetType(PrimitiveType.BYTE);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetType getShortType() {
|
||||
initStdClasses();
|
||||
return shortType;
|
||||
return getPrimitiveJetType(PrimitiveType.SHORT);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -431,168 +357,42 @@ public class JetStandardLibrary {
|
||||
return nullableStringType;
|
||||
}
|
||||
|
||||
public JetType getNullableByteType() {
|
||||
@NotNull
|
||||
public JetType getNullablePrimitiveJetType(PrimitiveType primitiveType) {
|
||||
initStdClasses();
|
||||
return nullableByteType;
|
||||
}
|
||||
|
||||
public JetType getNullableCharType() {
|
||||
initStdClasses();
|
||||
return nullableCharType;
|
||||
}
|
||||
|
||||
public JetType getNullableShortType() {
|
||||
initStdClasses();
|
||||
return nullableShortType;
|
||||
}
|
||||
|
||||
public JetType getNullableIntType() {
|
||||
initStdClasses();
|
||||
return nullableIntType;
|
||||
}
|
||||
|
||||
public JetType getNullableLongType() {
|
||||
initStdClasses();
|
||||
return nullableLongType;
|
||||
}
|
||||
|
||||
public JetType getNullableFloatType() {
|
||||
initStdClasses();
|
||||
return nullableFloatType;
|
||||
}
|
||||
|
||||
public JetType getNullableDoubleType() {
|
||||
initStdClasses();
|
||||
return nullableDoubleType;
|
||||
}
|
||||
|
||||
public JetType getNullableBooleanType() {
|
||||
initStdClasses();
|
||||
return nullableBooleanType;
|
||||
return primitiveTypeToNullableJetType.get(primitiveType);
|
||||
}
|
||||
|
||||
public JetType getNullableTuple0Type() {
|
||||
initStdClasses();
|
||||
return nullableTuple0Type;
|
||||
}
|
||||
|
||||
public JetType getBooleanArrayType() {
|
||||
initStdClasses();
|
||||
return booleanArrayType;
|
||||
}
|
||||
|
||||
public JetType getByteArrayType() {
|
||||
initStdClasses();
|
||||
return byteArrayType;
|
||||
}
|
||||
|
||||
public JetType getCharArrayType() {
|
||||
initStdClasses();
|
||||
return charArrayType;
|
||||
}
|
||||
|
||||
public JetType getShortArrayType() {
|
||||
initStdClasses();
|
||||
return shortArrayType;
|
||||
}
|
||||
|
||||
public JetType getIntArrayType() {
|
||||
initStdClasses();
|
||||
return intArrayType;
|
||||
}
|
||||
|
||||
public JetType getLongArrayType() {
|
||||
initStdClasses();
|
||||
return longArrayType;
|
||||
}
|
||||
|
||||
public JetType getFloatArrayType() {
|
||||
initStdClasses();
|
||||
return floatArrayType;
|
||||
}
|
||||
|
||||
public JetType getDoubleArrayType() {
|
||||
initStdClasses();
|
||||
return doubleArrayType;
|
||||
}
|
||||
|
||||
public JetType getPrimitiveArrayType(JetType jetType) {
|
||||
if (jetType.equals(getIntType())) {
|
||||
return getIntArrayType();
|
||||
} else {
|
||||
throw new IllegalStateException("not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
public ClassDescriptor getByteArrayClass() {
|
||||
@NotNull
|
||||
public JetType getPrimitiveArrayJetType(PrimitiveType primitiveType) {
|
||||
initStdClasses();
|
||||
return byteArrayClass;
|
||||
return primitiveTypeToArrayJetType.get(primitiveType);
|
||||
}
|
||||
|
||||
public ClassDescriptor getCharArrayClass() {
|
||||
/**
|
||||
* @return <code>null</code> if not primitive
|
||||
*/
|
||||
@Nullable
|
||||
public JetType getPrimitiveArrayJetTypeByPrimitiveJetType(JetType jetType) {
|
||||
return primitiveJetTypeToJetArrayType.get(jetType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getPrimitiveArrayClassDescriptor(PrimitiveType primitiveType) {
|
||||
initStdClasses();
|
||||
return charArrayClass;
|
||||
return primitiveTypeToArrayClass.get(primitiveType);
|
||||
}
|
||||
|
||||
public ClassDescriptor getShortArrayClass() {
|
||||
|
||||
@NotNull
|
||||
public JetType getNullablePrimitiveArrayJetType(PrimitiveType primitiveType) {
|
||||
initStdClasses();
|
||||
return shortArrayClass;
|
||||
return primitiveTypeToNullableArrayJetType.get(primitiveType);
|
||||
}
|
||||
|
||||
public ClassDescriptor getIntArrayClass() {
|
||||
initStdClasses();
|
||||
return intArrayClass;
|
||||
}
|
||||
|
||||
public ClassDescriptor getLongArrayClass() {
|
||||
initStdClasses();
|
||||
return longArrayClass;
|
||||
}
|
||||
|
||||
public ClassDescriptor getFloatArrayClass() {
|
||||
initStdClasses();
|
||||
return floatArrayClass;
|
||||
}
|
||||
|
||||
public ClassDescriptor getDoubleArrayClass() {
|
||||
initStdClasses();
|
||||
return doubleArrayClass;
|
||||
}
|
||||
|
||||
public ClassDescriptor getBooleanArrayClass() {
|
||||
initStdClasses();
|
||||
return booleanArrayClass;
|
||||
}
|
||||
|
||||
public JetType getNullableByteArrayType() {
|
||||
return nullableByteArrayType;
|
||||
}
|
||||
|
||||
public JetType getNullableCharArrayType() {
|
||||
return nullableCharArrayType;
|
||||
}
|
||||
|
||||
public JetType getNullableShortArrayType() {
|
||||
return nullableShortArrayType;
|
||||
}
|
||||
|
||||
public JetType getNullableIntArrayType() {
|
||||
return nullableIntArrayType;
|
||||
}
|
||||
|
||||
public JetType getNullableLongArrayType() {
|
||||
return nullableLongArrayType;
|
||||
}
|
||||
|
||||
public JetType getNullableFloatArrayType() {
|
||||
return nullableFloatArrayType;
|
||||
}
|
||||
|
||||
public JetType getNullableDoubleArrayType() {
|
||||
return nullableDoubleArrayType;
|
||||
}
|
||||
|
||||
public JetType getNullableBooleanArrayType() {
|
||||
return nullableBooleanArrayType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.jetbrains.jet.lang.types;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public enum PrimitiveType {
|
||||
|
||||
BOOLEAN("Boolean"),
|
||||
CHAR("Char"),
|
||||
BYTE("Byte"),
|
||||
SHORT("Short"),
|
||||
INT("Int"),
|
||||
FLOAT("Float"),
|
||||
LONG("Long"),
|
||||
DOUBLE("Double"),
|
||||
;
|
||||
|
||||
private final String typeName;
|
||||
private final String arrayTypeName;
|
||||
|
||||
private PrimitiveType(String typeName) {
|
||||
this.typeName = typeName;
|
||||
this.arrayTypeName = typeName + "Array";
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
return typeName;
|
||||
}
|
||||
|
||||
public String getArrayTypeName() {
|
||||
return arrayTypeName;
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -68,7 +68,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
|
||||
JetType expectedType = context.expectedType;
|
||||
boolean functionTypeExpected = expectedType != TypeUtils.NO_EXPECTED_TYPE && JetStandardClasses.isFunctionType(expectedType);
|
||||
|
||||
FunctionDescriptorImpl functionDescriptor = createFunctionDescriptor(expression, context, functionTypeExpected);
|
||||
NamedFunctionDescriptorImpl functionDescriptor = createFunctionDescriptor(expression, context, functionTypeExpected);
|
||||
|
||||
List<JetType> parameterTypes = Lists.newArrayList();
|
||||
List<ValueParameterDescriptor> valueParameters = functionDescriptor.getValueParameters();
|
||||
@@ -108,10 +108,10 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
|
||||
return DataFlowUtils.checkType(JetStandardClasses.getFunctionType(Collections.<AnnotationDescriptor>emptyList(), receiver, parameterTypes, safeReturnType), expression, context);
|
||||
}
|
||||
|
||||
private FunctionDescriptorImpl createFunctionDescriptor(JetFunctionLiteralExpression expression, ExpressionTypingContext context, boolean functionTypeExpected) {
|
||||
private NamedFunctionDescriptorImpl createFunctionDescriptor(JetFunctionLiteralExpression expression, ExpressionTypingContext context, boolean functionTypeExpected) {
|
||||
JetFunctionLiteral functionLiteral = expression.getFunctionLiteral();
|
||||
JetTypeReference receiverTypeRef = functionLiteral.getReceiverTypeRef();
|
||||
FunctionDescriptorImpl functionDescriptor = new FunctionDescriptorImpl(
|
||||
NamedFunctionDescriptorImpl functionDescriptor = new NamedFunctionDescriptorImpl(
|
||||
context.scope.getContainingDeclaration(), Collections.<AnnotationDescriptor>emptyList(), "<anonymous>");
|
||||
|
||||
List<ValueParameterDescriptor> valueParameterDescriptors = createValueParameterDescriptors(context, functionLiteral, functionDescriptor, functionTypeExpected);
|
||||
|
||||
+1
-1
@@ -105,7 +105,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
||||
|
||||
@Override
|
||||
public JetType visitNamedFunction(JetNamedFunction function, ExpressionTypingContext context) {
|
||||
FunctionDescriptorImpl functionDescriptor = context.getDescriptorResolver().resolveFunctionDescriptor(scope.getContainingDeclaration(), scope, function);
|
||||
NamedFunctionDescriptor functionDescriptor = context.getDescriptorResolver().resolveFunctionDescriptor(scope.getContainingDeclaration(), scope, function);
|
||||
scope.addFunctionDescriptor(functionDescriptor);
|
||||
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(context.scope, functionDescriptor, context.trace);
|
||||
context.getServices().checkFunctionReturnType(functionInnerScope, function, functionDescriptor, context.dataFlowInfo);
|
||||
|
||||
@@ -162,7 +162,7 @@ LONG_TEMPLATE_ENTRY_END=\}
|
||||
{RAW_STRING_LITERAL} { return JetTokens.RAW_STRING_LITERAL; }
|
||||
|
||||
"continue" { return JetTokens.CONTINUE_KEYWORD ;}
|
||||
"package" { return JetTokens.NAMESPACE_KEYWORD ;}
|
||||
"package" { return JetTokens.PACKAGE_KEYWORD ;}
|
||||
"return" { return JetTokens.RETURN_KEYWORD ;}
|
||||
"object" { return JetTokens.OBJECT_KEYWORD ;}
|
||||
"while" { return JetTokens.WHILE_KEYWORD ;}
|
||||
|
||||
@@ -31,7 +31,7 @@ public interface JetTokens {
|
||||
|
||||
JetToken RAW_STRING_LITERAL = new JetToken("RAW_STRING_LITERAL");
|
||||
|
||||
JetKeywordToken NAMESPACE_KEYWORD = JetKeywordToken.keyword("namespace");
|
||||
JetKeywordToken PACKAGE_KEYWORD = JetKeywordToken.keyword("package");
|
||||
JetKeywordToken AS_KEYWORD = JetKeywordToken.keyword("as");
|
||||
JetKeywordToken TYPE_KEYWORD = JetKeywordToken.keyword("type");
|
||||
JetKeywordToken CLASS_KEYWORD = JetKeywordToken.keyword("class");
|
||||
@@ -145,7 +145,7 @@ public interface JetTokens {
|
||||
// TODO: support this as an annotation on arguments. Then, they it probably can not be a soft keyword
|
||||
JetKeywordToken REF_KEYWORD = JetKeywordToken.softKeyword("ref");
|
||||
|
||||
TokenSet KEYWORDS = TokenSet.create(NAMESPACE_KEYWORD, AS_KEYWORD, TYPE_KEYWORD, CLASS_KEYWORD, TRAIT_KEYWORD,
|
||||
TokenSet KEYWORDS = TokenSet.create(PACKAGE_KEYWORD, AS_KEYWORD, TYPE_KEYWORD, CLASS_KEYWORD, TRAIT_KEYWORD,
|
||||
THIS_KEYWORD, SUPER_KEYWORD, VAL_KEYWORD, VAR_KEYWORD, FUN_KEYWORD, FOR_KEYWORD,
|
||||
NULL_KEYWORD,
|
||||
TRUE_KEYWORD, FALSE_KEYWORD, IS_KEYWORD,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* The following code was generated by JFlex 1.4.3 on 12/25/11 2:36 PM */
|
||||
/* The following code was generated by JFlex 1.4.3 on 1/12/12 7:11 PM */
|
||||
|
||||
package org.jetbrains.jet.lexer;
|
||||
|
||||
@@ -13,7 +13,7 @@ import org.jetbrains.jet.lexer.JetTokens;
|
||||
/**
|
||||
* This class is a scanner generated by
|
||||
* <a href="http://www.jflex.de/">JFlex</a> 1.4.3
|
||||
* on 12/25/11 2:36 PM from the specification file
|
||||
* on 1/12/12 7:11 PM from the specification file
|
||||
* <tt>/Users/abreslav/work/jet/compiler/frontend/src/org/jetbrains/jet/lexer/Jet.flex</tt>
|
||||
*/
|
||||
class _JetLexer implements FlexLexer {
|
||||
@@ -1006,77 +1006,77 @@ class _JetLexer implements FlexLexer {
|
||||
{ return JetTokens.MINUSEQ ;
|
||||
}
|
||||
case 138: break;
|
||||
case 96:
|
||||
{ return JetTokens.PACKAGE_KEYWORD ;
|
||||
}
|
||||
case 139: break;
|
||||
case 87:
|
||||
{ return JetTokens.THROW_KEYWORD ;
|
||||
}
|
||||
case 139: break;
|
||||
case 140: break;
|
||||
case 89:
|
||||
{ return JetTokens.SUPER_KEYWORD ;
|
||||
}
|
||||
case 140: break;
|
||||
case 141: break;
|
||||
case 92:
|
||||
{ return JetTokens.WHILE_KEYWORD ;
|
||||
}
|
||||
case 141: break;
|
||||
case 142: break;
|
||||
case 44:
|
||||
{ return JetTokens.MINUSMINUS;
|
||||
}
|
||||
case 142: break;
|
||||
case 143: break;
|
||||
case 97:
|
||||
{ return JetTokens.CONTINUE_KEYWORD ;
|
||||
}
|
||||
case 143: break;
|
||||
case 144: break;
|
||||
case 75:
|
||||
{ return JetTokens.NOT_IN;
|
||||
}
|
||||
case 144: break;
|
||||
case 145: break;
|
||||
case 38:
|
||||
{ return JetTokens.ATAT ;
|
||||
}
|
||||
case 145: break;
|
||||
case 146: break;
|
||||
case 6:
|
||||
{ return JetTokens.DIV ;
|
||||
}
|
||||
case 146: break;
|
||||
case 147: break;
|
||||
case 37:
|
||||
{ return JetTokens.LABEL_IDENTIFIER;
|
||||
}
|
||||
case 147: break;
|
||||
case 148: break;
|
||||
case 29:
|
||||
{ return JetTokens.REGULAR_STRING_PART;
|
||||
}
|
||||
case 148: break;
|
||||
case 149: break;
|
||||
case 16:
|
||||
{ return JetTokens.QUEST ;
|
||||
}
|
||||
case 149: break;
|
||||
case 150: break;
|
||||
case 60:
|
||||
{ return JetTokens.OROR ;
|
||||
}
|
||||
case 150: break;
|
||||
case 151: break;
|
||||
case 20:
|
||||
{ return JetTokens.PERC ;
|
||||
}
|
||||
case 151: break;
|
||||
case 152: break;
|
||||
case 76:
|
||||
{ return JetTokens.EXCLEQEQEQ;
|
||||
}
|
||||
case 152: break;
|
||||
case 153: break;
|
||||
case 61:
|
||||
{ return JetTokens.PERCEQ ;
|
||||
}
|
||||
case 153: break;
|
||||
case 154: break;
|
||||
case 43:
|
||||
{ return JetTokens.RANGE ;
|
||||
}
|
||||
case 154: break;
|
||||
case 155: break;
|
||||
case 1:
|
||||
{ return TokenType.BAD_CHARACTER;
|
||||
}
|
||||
case 155: break;
|
||||
case 96:
|
||||
{ return JetTokens.NAMESPACE_KEYWORD ;
|
||||
}
|
||||
case 156: break;
|
||||
case 74:
|
||||
{ return JetTokens.NOT_IS;
|
||||
|
||||
@@ -258,7 +258,7 @@ public class DescriptorRenderer implements Renderer {
|
||||
|
||||
@Override
|
||||
public Void visitNamespaceDescriptor(NamespaceDescriptor namespaceDescriptor, StringBuilder builder) {
|
||||
builder.append(renderKeyword(JetTokens.NAMESPACE_KEYWORD.getValue())).append(" ");
|
||||
builder.append(renderKeyword(JetTokens.PACKAGE_KEYWORD.getValue())).append(" ");
|
||||
renderName(namespaceDescriptor, builder);
|
||||
return super.visitNamespaceDescriptor(namespaceDescriptor, builder);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="IDEA 10.x" jdkType="IDEA JDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="backend" />
|
||||
<orderEntry type="module" module-name="frontend" />
|
||||
<orderEntry type="module" module-name="frontend.java" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @author max
|
||||
*/
|
||||
package org.jetbrains.jet.plugin.java;
|
||||
package org.jetbrains.jet.asJava;
|
||||
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.psi.*;
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @author max
|
||||
*/
|
||||
package org.jetbrains.jet.plugin.java;
|
||||
package org.jetbrains.jet.asJava;
|
||||
|
||||
import com.intellij.openapi.compiler.ex.CompilerPathsEx;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @author max
|
||||
*/
|
||||
package org.jetbrains.jet.plugin.java;
|
||||
package org.jetbrains.jet.asJava;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.psi.*;
|
||||
@@ -14,7 +14,7 @@ import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
|
||||
public class JetCodeBlockModificationListener implements PsiTreeChangePreprocessor {
|
||||
private static final Logger LOG = Logger.getInstance("#org.jetbrains.jet.plugin.java.JetCodeBlockModificationListener");
|
||||
private static final Logger LOG = Logger.getInstance("#org.jetbrains.jet.asJava.JetCodeBlockModificationListener");
|
||||
|
||||
private final PsiModificationTrackerImpl myModificationTracker;
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @author max
|
||||
*/
|
||||
package org.jetbrains.jet.plugin.java;
|
||||
package org.jetbrains.jet.asJava;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -36,7 +36,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMarker {
|
||||
private static final Logger LOG = Logger.getInstance("#org.jetbrains.jet.plugin.java.JetLightClass");
|
||||
private static final Logger LOG = Logger.getInstance("#org.jetbrains.jet.asJava.JetLightClass");
|
||||
private final static Key<CachedValue<PsiJavaFileStub>> JAVA_API_STUB = Key.create("JAVA_API_STUB");
|
||||
|
||||
private final JetFile file;
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @author max
|
||||
*/
|
||||
package org.jetbrains.jet.plugin.java;
|
||||
package org.jetbrains.jet.asJava;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.impl.compiled.InnerClassSourceStrategy;
|
||||
@@ -1,6 +1,6 @@
|
||||
JetFile: Attributes.jet
|
||||
NAMESPACE_HEADER
|
||||
PsiElement(namespace)('package')
|
||||
PsiElement(package)('package')
|
||||
PsiWhiteSpace(' ')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
JetFile: Attributes_ERR.jet
|
||||
NAMESPACE_HEADER
|
||||
PsiElement(namespace)('package')
|
||||
PsiElement(package)('package')
|
||||
PsiWhiteSpace(' ')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
JetFile: BabySteps.jet
|
||||
NAMESPACE_HEADER
|
||||
PsiElement(namespace)('package')
|
||||
PsiElement(package)('package')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
PsiWhiteSpace('\n\n')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
JetFile: BabySteps_ERR.jet
|
||||
NAMESPACE_HEADER
|
||||
PsiElement(namespace)('package')
|
||||
PsiElement(package)('package')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
PsiWhiteSpace('\n\n')
|
||||
|
||||
@@ -4,7 +4,7 @@ JetFile: FileStart_ERR.jet
|
||||
PsiErrorElement:Expecting namespace or top level declaration
|
||||
PsiElement(DIV)('/')
|
||||
PsiErrorElement:Expecting namespace or top level declaration
|
||||
PsiElement(namespace)('package')
|
||||
PsiElement(package)('package')
|
||||
PsiWhiteSpace(' ')
|
||||
MODIFIER_LIST
|
||||
ANNOTATION_ENTRY
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
JetFile: Imports.jet
|
||||
NAMESPACE_HEADER
|
||||
PsiElement(namespace)('package')
|
||||
PsiElement(package)('package')
|
||||
PsiWhiteSpace(' ')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
@@ -13,7 +13,7 @@ JetFile: Imports.jet
|
||||
IMPORT_DIRECTIVE
|
||||
PsiElement(import)('import')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(namespace)('package')
|
||||
PsiElement(package)('package')
|
||||
PsiElement(DOT)('.')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
JetFile: Imports_ERR.jet
|
||||
NAMESPACE_HEADER
|
||||
PsiElement(namespace)('package')
|
||||
PsiElement(package)('package')
|
||||
PsiWhiteSpace(' ')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
@@ -13,7 +13,7 @@ JetFile: Imports_ERR.jet
|
||||
IMPORT_DIRECTIVE
|
||||
PsiElement(import)('import')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(namespace)('package')
|
||||
PsiElement(package)('package')
|
||||
PsiErrorElement:Expecting '.'
|
||||
<empty list>
|
||||
PsiWhiteSpace(' ')
|
||||
@@ -25,7 +25,7 @@ JetFile: Imports_ERR.jet
|
||||
IMPORT_DIRECTIVE
|
||||
PsiElement(import)('import')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(namespace)('package')
|
||||
PsiElement(package)('package')
|
||||
PsiElement(DOT)('.')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiErrorElement:Expecting qualified name
|
||||
@@ -36,7 +36,7 @@ JetFile: Imports_ERR.jet
|
||||
IMPORT_DIRECTIVE
|
||||
PsiElement(import)('import')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(namespace)('package')
|
||||
PsiElement(package)('package')
|
||||
PsiElement(DOT)('.')
|
||||
PsiWhiteSpace(' ')
|
||||
REFERENCE_EXPRESSION
|
||||
|
||||
@@ -2,7 +2,7 @@ JetFile: NamespaceBlockFirst.jet
|
||||
NAMESPACE_HEADER
|
||||
<empty list>
|
||||
PsiErrorElement:Expecting namespace or top level declaration
|
||||
PsiElement(namespace)('package')
|
||||
PsiElement(package)('package')
|
||||
PsiWhiteSpace(' ')
|
||||
MODIFIER_LIST
|
||||
ANNOTATION_ENTRY
|
||||
|
||||
@@ -13,6 +13,6 @@ JetFile: NamespaceModifiers.jet
|
||||
PsiElement(IDENTIFIER)('a')
|
||||
PsiElement(RBRACKET)(']')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(namespace)('package')
|
||||
PsiElement(package)('package')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('name')
|
||||
@@ -1,6 +1,6 @@
|
||||
JetFile: RootNamespace.jet
|
||||
NAMESPACE_HEADER
|
||||
PsiElement(namespace)('package')
|
||||
PsiElement(package)('package')
|
||||
PsiWhiteSpace(' ')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
@@ -16,7 +16,7 @@ JetFile: RootNamespace.jet
|
||||
TYPE_PARAMETER_LIST
|
||||
<empty list>
|
||||
PsiErrorElement:Expecting namespace or top level declaration
|
||||
PsiElement(namespace)('package')
|
||||
PsiElement(package)('package')
|
||||
PsiWhiteSpace(' ')
|
||||
MODIFIER_LIST
|
||||
ANNOTATION_ENTRY
|
||||
@@ -48,7 +48,7 @@ JetFile: RootNamespace.jet
|
||||
DOT_QUALIFIED_EXPRESSION
|
||||
DOT_QUALIFIED_EXPRESSION
|
||||
ROOT_NAMESPACE
|
||||
PsiElement(namespace)('package')
|
||||
PsiElement(package)('package')
|
||||
PsiElement(DOT)('.')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
@@ -63,7 +63,7 @@ JetFile: RootNamespace.jet
|
||||
DOT_QUALIFIED_EXPRESSION
|
||||
DOT_QUALIFIED_EXPRESSION
|
||||
ROOT_NAMESPACE
|
||||
PsiElement(namespace)('package')
|
||||
PsiElement(package)('package')
|
||||
PsiElement(DOT)('.')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
@@ -97,7 +97,7 @@ JetFile: RootNamespace.jet
|
||||
DOT_QUALIFIED_EXPRESSION
|
||||
DOT_QUALIFIED_EXPRESSION
|
||||
ROOT_NAMESPACE
|
||||
PsiElement(namespace)('package')
|
||||
PsiElement(package)('package')
|
||||
PsiElement(DOT)('.')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
|
||||
@@ -49,7 +49,7 @@ JetFile: ShortAnnotations.jet
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('zoo')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(namespace)('package')
|
||||
PsiElement(package)('package')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('aa')
|
||||
PsiWhiteSpace('\n\n')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
JetFile: SimpleModifiers.jet
|
||||
NAMESPACE_HEADER
|
||||
PsiElement(namespace)('package')
|
||||
PsiElement(package)('package')
|
||||
PsiWhiteSpace(' ')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
JetFile: SoftKeywords.jet
|
||||
NAMESPACE_HEADER
|
||||
PsiElement(namespace)('package')
|
||||
PsiElement(package)('package')
|
||||
PsiWhiteSpace(' ')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
JetFile: TypeDef.jet
|
||||
NAMESPACE_HEADER
|
||||
PsiElement(namespace)('package')
|
||||
PsiElement(package)('package')
|
||||
PsiWhiteSpace(' ')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
|
||||
@@ -598,7 +598,7 @@ JetFile: When.jet
|
||||
DOT_QUALIFIED_EXPRESSION
|
||||
DOT_QUALIFIED_EXPRESSION
|
||||
ROOT_NAMESPACE
|
||||
PsiElement(namespace)('package')
|
||||
PsiElement(package)('package')
|
||||
PsiElement(DOT)('.')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('a')
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package test
|
||||
|
||||
val <P> P.anotherJavaClass: java.lang.Class<P>
|
||||
get() = throw Exception()
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user