micro refactoring
- PsiCodegenPredictor moved to binding package - CodegenUtil.findSuperCall method moved to CodegenBinding = PsiCodegenPredictor unneeded bindingTrace parameter replaced by bindingContext
This commit is contained in:
@@ -34,8 +34,9 @@ import org.jetbrains.jet.codegen.state.JetTypeMapper;
|
||||
import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.psi.JetClassObject;
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
import org.jetbrains.jet.lang.psi.JetObjectDeclaration;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||
@@ -211,29 +212,6 @@ public class CodegenUtil {
|
||||
return closure.getCaptureThis() == null && closure.getCaptureReceiver() == null && closure.getCaptureVariables().isEmpty();
|
||||
}
|
||||
|
||||
public static JetDelegatorToSuperCall findSuperCall(JetElement classOrObject, BindingContext bindingContext) {
|
||||
if (!(classOrObject instanceof JetClassOrObject)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (classOrObject instanceof JetClass && ((JetClass) classOrObject).isTrait()) {
|
||||
return null;
|
||||
}
|
||||
for (JetDelegationSpecifier specifier : ((JetClassOrObject) classOrObject).getDelegationSpecifiers()) {
|
||||
if (specifier instanceof JetDelegatorToSuperCall) {
|
||||
JetType superType = bindingContext.get(BindingContext.TYPE, specifier.getTypeReference());
|
||||
assert superType != null;
|
||||
ClassDescriptor superClassDescriptor = (ClassDescriptor) superType.getConstructor().getDeclarationDescriptor();
|
||||
assert superClassDescriptor != null;
|
||||
if (!isInterface(superClassDescriptor)) {
|
||||
return (JetDelegatorToSuperCall) specifier;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void generateClosureFields(CalculatedClosure closure, ClassBuilder v, JetTypeMapper typeMapper) {
|
||||
final ClassifierDescriptor captureThis = closure.getCaptureThis();
|
||||
final int access = ACC_PUBLIC | ACC_SYNTHETIC | ACC_FINAL;
|
||||
|
||||
+1
-2
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.jet.codegen.binding;
|
||||
|
||||
import com.intellij.util.containers.Stack;
|
||||
import org.jetbrains.jet.codegen.PsiCodegenPredictor;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
@@ -70,7 +69,7 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid {
|
||||
: JetStandardClasses.getFunction(arity)).getDefaultType()), JetScope.EMPTY,
|
||||
Collections.<ConstructorDescriptor>emptySet(), null);
|
||||
|
||||
assert PsiCodegenPredictor.checkPredictedClassNameForFun(bindingTrace, funDescriptor, classDescriptor);
|
||||
assert PsiCodegenPredictor.checkPredictedClassNameForFun(bindingContext, funDescriptor, classDescriptor);
|
||||
bindingTrace.record(CLASS_FOR_FUNCTION, funDescriptor, classDescriptor);
|
||||
return classDescriptor;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.codegen.CodegenUtil;
|
||||
import org.jetbrains.jet.codegen.PsiCodegenPredictor;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
@@ -31,6 +30,7 @@ import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
import org.jetbrains.jet.util.slicedmap.Slices;
|
||||
import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
||||
@@ -132,7 +132,7 @@ public class CodegenBinding {
|
||||
|
||||
recordClosure(bindingTrace, null, classDescriptor, null, className, false);
|
||||
|
||||
assert PsiCodegenPredictor.checkPredictedClassNameForFun(bindingTrace, scriptDescriptor, classDescriptor);
|
||||
assert PsiCodegenPredictor.checkPredictedClassNameForFun(bindingTrace.getBindingContext(), scriptDescriptor, classDescriptor);
|
||||
bindingTrace.record(CLASS_FOR_FUNCTION, scriptDescriptor, classDescriptor);
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ public class CodegenBinding {
|
||||
JvmClassName name,
|
||||
boolean functionLiteral
|
||||
) {
|
||||
final JetDelegatorToSuperCall superCall = CodegenUtil.findSuperCall(element, bindingTrace.getBindingContext());
|
||||
final JetDelegatorToSuperCall superCall = findSuperCall(bindingTrace.getBindingContext(), element);
|
||||
|
||||
CallableDescriptor enclosingReceiver = null;
|
||||
if (classDescriptor.getContainingDeclaration() instanceof CallableDescriptor) {
|
||||
@@ -357,4 +357,30 @@ public class CodegenBinding {
|
||||
final CalculatedClosure closure = bindingContext.get(CLOSURE, classDescriptor);
|
||||
return closure != null && closure.getCaptureThis() != null;
|
||||
}
|
||||
|
||||
private static JetDelegatorToSuperCall findSuperCall(
|
||||
BindingContext bindingContext,
|
||||
JetElement classOrObject
|
||||
) {
|
||||
if (!(classOrObject instanceof JetClassOrObject)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (classOrObject instanceof JetClass && ((JetClass) classOrObject).isTrait()) {
|
||||
return null;
|
||||
}
|
||||
for (JetDelegationSpecifier specifier : ((JetClassOrObject) classOrObject).getDelegationSpecifiers()) {
|
||||
if (specifier instanceof JetDelegatorToSuperCall) {
|
||||
JetType superType = bindingContext.get(TYPE, specifier.getTypeReference());
|
||||
assert superType != null;
|
||||
ClassDescriptor superClassDescriptor = (ClassDescriptor) superType.getConstructor().getDeclarationDescriptor();
|
||||
assert superClassDescriptor != null;
|
||||
if (!CodegenUtil.isInterface(superClassDescriptor)) {
|
||||
return (JetDelegatorToSuperCall) specifier;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-4
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.codegen;
|
||||
package org.jetbrains.jet.codegen.binding;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -23,6 +23,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||
@@ -135,10 +136,11 @@ public final class PsiCodegenPredictor {
|
||||
}
|
||||
|
||||
public static boolean checkPredictedClassNameForFun(
|
||||
@NotNull BindingTrace bindingTrace, @NotNull DeclarationDescriptor descriptor, ClassDescriptor classDescriptor
|
||||
BindingContext bindingContext, @NotNull DeclarationDescriptor descriptor,
|
||||
ClassDescriptor classDescriptor
|
||||
) {
|
||||
PsiElement element = descriptorToDeclaration(bindingTrace.getBindingContext(), descriptor);
|
||||
PsiElement classDeclaration = descriptorToDeclaration(bindingTrace.getBindingContext(), classDescriptor);
|
||||
PsiElement element = descriptorToDeclaration(bindingContext, descriptor);
|
||||
PsiElement classDeclaration = descriptorToDeclaration(bindingContext, classDescriptor);
|
||||
if (element instanceof JetNamedFunction && classDeclaration instanceof JetDeclaration) {
|
||||
JvmClassName classNameFromPsi = getPredefinedJvmClassName((JetDeclaration) classDeclaration);
|
||||
JvmClassName classNameForFun = getPredefinedJvmClassNameForFun((JetNamedFunction) element);
|
||||
@@ -37,7 +37,11 @@ import com.intellij.util.containers.Stack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.codegen.*;
|
||||
import org.jetbrains.jet.codegen.ClassBuilder;
|
||||
import org.jetbrains.jet.codegen.ClassBuilderFactory;
|
||||
import org.jetbrains.jet.codegen.ClassBuilderMode;
|
||||
import org.jetbrains.jet.codegen.CompilationErrorHandler;
|
||||
import org.jetbrains.jet.codegen.binding.PsiCodegenPredictor;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
import org.jetbrains.jet.codegen.state.GenerationStrategy;
|
||||
import org.jetbrains.jet.lang.BuiltinsScopeExtensionMode;
|
||||
|
||||
Reference in New Issue
Block a user