di: required parameters
* required parameters have @NotNull annotation generated * parameters are required by default
This commit is contained in:
@@ -25,6 +25,7 @@ import org.jetbrains.jet.lang.resolve.AnnotationResolver;
|
||||
import org.jetbrains.jet.lang.resolve.TypeResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.OverloadingConflictResolver;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
|
||||
public class InjectorForMacros {
|
||||
@@ -33,7 +34,7 @@ public class InjectorForMacros {
|
||||
private final Project project;
|
||||
|
||||
public InjectorForMacros(
|
||||
Project project
|
||||
@NotNull Project project
|
||||
) {
|
||||
this.expressionTypingServices = new ExpressionTypingServices();
|
||||
this.project = project;
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.jetbrains.jet.lang.resolve.TopDownAnalysisContext;
|
||||
import org.jetbrains.jet.lang.ModuleConfiguration;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
|
||||
public class InjectorForTopDownAnalyzer {
|
||||
@@ -55,10 +56,10 @@ public class InjectorForTopDownAnalyzer {
|
||||
private final Project project;
|
||||
|
||||
public InjectorForTopDownAnalyzer(
|
||||
Project project,
|
||||
TopDownAnalysisContext topDownAnalysisContext,
|
||||
ModuleConfiguration moduleConfiguration,
|
||||
ModuleDescriptor moduleDescriptor,
|
||||
@NotNull Project project,
|
||||
@NotNull TopDownAnalysisContext topDownAnalysisContext,
|
||||
@NotNull ModuleConfiguration moduleConfiguration,
|
||||
@NotNull ModuleDescriptor moduleDescriptor,
|
||||
JetControlFlowDataTraceFactory jetControlFlowDataTraceFactory
|
||||
) {
|
||||
this.topDownAnalyzer = new TopDownAnalyzer();
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.jet.lang.resolve.AnnotationResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.OverloadingConflictResolver;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
|
||||
public class InjectorForTests {
|
||||
@@ -38,7 +39,7 @@ public class InjectorForTests {
|
||||
private final Project project;
|
||||
|
||||
public InjectorForTests(
|
||||
Project project
|
||||
@NotNull Project project
|
||||
) {
|
||||
this.descriptorResolver = new DescriptorResolver();
|
||||
this.expressionTypingServices = new ExpressionTypingServices();
|
||||
|
||||
@@ -55,7 +55,7 @@ public class AllInjectorsGenerator {
|
||||
generator.addParameter(TopDownAnalysisContext.class);
|
||||
generator.addParameter(ModuleConfiguration.class);
|
||||
generator.addParameter(ModuleDescriptor.class);
|
||||
generator.addParameter(JetControlFlowDataTraceFactory.class);
|
||||
generator.addParameter(JetControlFlowDataTraceFactory.class, false);
|
||||
|
||||
generator.generate("compiler/frontend/src", "org.jetbrains.jet.di", "InjectorForTopDownAnalyzer");
|
||||
}
|
||||
|
||||
@@ -110,16 +110,27 @@ public class DependencyInjectorGenerator {
|
||||
}
|
||||
|
||||
public void addPublicParameter(Class<?> type) {
|
||||
addParameter(true, type, var(type));
|
||||
addPublicParameter(type, true);
|
||||
}
|
||||
|
||||
public void addPublicParameter(Class<?> type, boolean required) {
|
||||
addParameter(true, type, var(type), required);
|
||||
}
|
||||
|
||||
|
||||
public void addParameter(Class<?> type) {
|
||||
addParameter(false, type, var(type));
|
||||
addParameter(type, true);
|
||||
}
|
||||
|
||||
public void addParameter(boolean reexport, @NotNull Class<?> type, @Nullable String name) {
|
||||
public void addParameter(Class<?> type, boolean required) {
|
||||
addParameter(false, type, var(type), required);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void addParameter(boolean reexport, @NotNull Class<?> type, @Nullable String name, boolean required) {
|
||||
Field field = addField(reexport, type, name, null);
|
||||
Parameter parameter = new Parameter(type, name, field);
|
||||
Parameter parameter = new Parameter(type, name, field, required);
|
||||
parameters.add(parameter);
|
||||
field.setInitialization(new ParameterExpression(parameter));
|
||||
backsParameter.add(field);
|
||||
@@ -148,6 +159,12 @@ public class DependencyInjectorGenerator {
|
||||
for (Parameter parameter : parameters) {
|
||||
generateImportDirective(out, parameter.getType(), injectorPackageName);
|
||||
}
|
||||
for (Parameter parameter : parameters) {
|
||||
if (parameter.isRequired()) {
|
||||
generateImportDirective(out, NotNull.class, injectorPackageName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void generateImportDirective(PrintStream out, Class<?> type, String injectorPackageName) {
|
||||
@@ -180,7 +197,11 @@ public class DependencyInjectorGenerator {
|
||||
out.println(" public " + injectorClassName + "(");
|
||||
for (Iterator<Parameter> iterator = parameters.iterator(); iterator.hasNext(); ) {
|
||||
Parameter parameter = iterator.next();
|
||||
out.print(indent + parameter.getType().getSimpleName() + " " + parameter.getName());
|
||||
out.print(indent);
|
||||
if (parameter.isRequired()) {
|
||||
out.print("@NotNull ");
|
||||
}
|
||||
out.print(parameter.getType().getSimpleName() + " " + parameter.getName());
|
||||
if (iterator.hasNext()) {
|
||||
out.println(",");
|
||||
}
|
||||
|
||||
@@ -23,11 +23,13 @@ class Parameter {
|
||||
private final Class<?> type;
|
||||
private final String name;
|
||||
private final Field field;
|
||||
private final boolean required;
|
||||
|
||||
Parameter(Class<?> type, String name, Field field) {
|
||||
Parameter(Class<?> type, String name, Field field, boolean required) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.field = field;
|
||||
this.required = required;
|
||||
}
|
||||
|
||||
public Class<?> getType() {
|
||||
@@ -42,6 +44,10 @@ class Parameter {
|
||||
return field;
|
||||
}
|
||||
|
||||
public boolean isRequired() {
|
||||
return required;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
||||
Reference in New Issue
Block a user