MemberCodegen
(move duplicate code into it)
This commit is contained in:
@@ -84,28 +84,10 @@ public abstract class ClassBodyCodegen {
|
||||
}
|
||||
|
||||
protected void generateDeclaration(PropertyCodegen propertyCodegen, JetDeclaration declaration, FunctionCodegen functionCodegen) {
|
||||
if (declaration instanceof JetProperty) {
|
||||
propertyCodegen.gen((JetProperty) declaration);
|
||||
if (declaration instanceof JetProperty || declaration instanceof JetNamedFunction) {
|
||||
state.getInjector().getMemberCodegen().generateFunctionOrProperty(
|
||||
(JetTypeParameterListOwner) declaration, context, v);
|
||||
}
|
||||
else if (declaration instanceof JetNamedFunction) {
|
||||
try {
|
||||
genNamedFunction((JetNamedFunction) declaration, functionCodegen);
|
||||
}
|
||||
catch (CompilationException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (ProcessCanceledException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
throw new RuntimeException("Error generating method " + myClass.getName() + "." + declaration.getName() + " in " + context,
|
||||
e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void genNamedFunction(JetNamedFunction declaration, FunctionCodegen functionCodegen) {
|
||||
functionCodegen.gen(declaration);
|
||||
}
|
||||
|
||||
private void generatePrimaryConstructorProperties(PropertyCodegen propertyCodegen, JetClassOrObject origin) {
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeParameterListOwner;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class MemberCodegen {
|
||||
|
||||
@NotNull
|
||||
private GenerationState state;
|
||||
|
||||
@Inject
|
||||
public void setState(@NotNull GenerationState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
|
||||
public void generateFunctionOrProperty(@NotNull JetTypeParameterListOwner functionOrProperty,
|
||||
@NotNull CodegenContext context, @NotNull ClassBuilder classBuilder) {
|
||||
FunctionCodegen functionCodegen = new FunctionCodegen(context, classBuilder, state);
|
||||
if (functionOrProperty instanceof JetNamedFunction) {
|
||||
try {
|
||||
functionCodegen.gen((JetNamedFunction) functionOrProperty);
|
||||
}
|
||||
catch (CompilationException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new CompilationException("Failed to generate function " + functionOrProperty.getName(), e, functionOrProperty);
|
||||
}
|
||||
}
|
||||
else if (functionOrProperty instanceof JetProperty) {
|
||||
try {
|
||||
new PropertyCodegen(context, classBuilder, functionCodegen, state).gen((JetProperty) functionOrProperty);
|
||||
}
|
||||
catch (CompilationException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new CompilationException("Failed to generate property " + functionOrProperty.getName(), e, functionOrProperty);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Unknown parameter: " + functionOrProperty);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -58,23 +58,10 @@ public class NamespaceCodegen {
|
||||
NamespaceDescriptor descriptor = state.getBindingContext().get(BindingContext.FILE_TO_NAMESPACE, file);
|
||||
final CodegenContext context = CodegenContexts.STATIC.intoNamespace(descriptor);
|
||||
|
||||
final FunctionCodegen functionCodegen = new FunctionCodegen(context, v, state);
|
||||
final PropertyCodegen propertyCodegen = new PropertyCodegen(context, v, functionCodegen, state);
|
||||
|
||||
for (JetDeclaration declaration : file.getDeclarations()) {
|
||||
if (declaration instanceof JetProperty) {
|
||||
propertyCodegen.gen((JetProperty) declaration);
|
||||
}
|
||||
else if (declaration instanceof JetNamedFunction) {
|
||||
try {
|
||||
functionCodegen.gen((JetNamedFunction) declaration);
|
||||
}
|
||||
catch (CompilationException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new CompilationException("Failed to generate function " + declaration.getName(), e, declaration);
|
||||
}
|
||||
if (declaration instanceof JetProperty || declaration instanceof JetNamedFunction) {
|
||||
state.getInjector().getMemberCodegen().generateFunctionOrProperty(
|
||||
(JetTypeParameterListOwner) declaration, context, v);
|
||||
}
|
||||
else if (declaration instanceof JetClassOrObject) {
|
||||
state.getInjector().getClassCodegen().generate(context, (JetClassOrObject) declaration);
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.jetbrains.jet.codegen.ClassCodegen;
|
||||
import org.jetbrains.jet.codegen.ScriptCodegen;
|
||||
import org.jetbrains.jet.codegen.intrinsics.IntrinsicMethods;
|
||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||
import org.jetbrains.jet.codegen.MemberCodegen;
|
||||
import org.jetbrains.jet.codegen.ClosureAnnotator;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
@@ -60,6 +61,7 @@ public class InjectorForJvmCodegen {
|
||||
private ScriptCodegen scriptCodegen;
|
||||
private IntrinsicMethods intrinsics;
|
||||
private ClassFileFactory classFileFactory;
|
||||
private MemberCodegen memberCodegen;
|
||||
private ClosureAnnotator closureAnnotator;
|
||||
|
||||
public InjectorForJvmCodegen(
|
||||
@@ -85,6 +87,7 @@ public class InjectorForJvmCodegen {
|
||||
this.scriptCodegen = new ScriptCodegen();
|
||||
this.intrinsics = new IntrinsicMethods();
|
||||
this.classFileFactory = new ClassFileFactory();
|
||||
this.memberCodegen = new MemberCodegen();
|
||||
this.closureAnnotator = new ClosureAnnotator();
|
||||
|
||||
this.jetTypeMapper.setBindingContext(bindingContext);
|
||||
@@ -106,6 +109,8 @@ public class InjectorForJvmCodegen {
|
||||
this.classFileFactory.setBuilderFactory(classBuilderFactory);
|
||||
this.classFileFactory.setState(generationState);
|
||||
|
||||
this.memberCodegen.setState(generationState);
|
||||
|
||||
closureAnnotator.setBindingContext(bindingContext);
|
||||
closureAnnotator.setFiles(listOfJetFile);
|
||||
|
||||
@@ -149,4 +154,8 @@ public class InjectorForJvmCodegen {
|
||||
return this.classFileFactory;
|
||||
}
|
||||
|
||||
public MemberCodegen getMemberCodegen() {
|
||||
return this.memberCodegen;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -171,6 +171,7 @@ public class AllInjectorsGenerator {
|
||||
generator.addPublicField(ScriptCodegen.class);
|
||||
generator.addField(true, IntrinsicMethods.class, "intrinsics", null);
|
||||
generator.addPublicField(ClassFileFactory.class);
|
||||
generator.addPublicField(MemberCodegen.class);
|
||||
generator.generate("compiler/backend/src", "org.jetbrains.jet.di", "InjectorForJvmCodegen");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user