Dependency Injection: GUICE replaced by custom code generation
This commit is contained in:
Generated
+1
-1
@@ -20,7 +20,7 @@
|
||||
<element id="archive" name="kotlin-js-libraries.zip">
|
||||
<element id="dir-copy" path="$PROJECT_DIR$/js/js.libraries/src" />
|
||||
</element>
|
||||
<element id="library" level="project" name="guice-3.0" />
|
||||
<element id="library" level="project" name="javax.inject" />
|
||||
</element>
|
||||
<element id="directory" name="kotlinc">
|
||||
<element id="dir-copy" path="$PROJECT_DIR$/dist/kotlinc" />
|
||||
|
||||
Generated
-12
@@ -1,12 +0,0 @@
|
||||
<component name="libraryTable">
|
||||
<library name="guice-3.0">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/guice-javax.inject.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/lib/guice-3.0-no_aop.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/guice-3.0-src.zip!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
Generated
+11
@@ -0,0 +1,11 @@
|
||||
<component name="libraryTable">
|
||||
<library name="javax.inject">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/javax.inject.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/javax.inject-src.zip!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
Generated
+1
@@ -12,6 +12,7 @@
|
||||
<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$/idea_runner/idea_runner.iml" filepath="$PROJECT_DIR$/idea_runner/idea_runner.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/injector-generator/injector-generator.iml" filepath="$PROJECT_DIR$/injector-generator/injector-generator.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/j2k/j2k.iml" filepath="$PROJECT_DIR$/j2k/j2k.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/j2k/tests/j2k-tests.iml" filepath="$PROJECT_DIR$/j2k/tests/j2k-tests.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" />
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="intellij-core" level="project" />
|
||||
<orderEntry type="library" name="guice-3.0" level="project" />
|
||||
<orderEntry type="library" name="javax.inject" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2000-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.di;
|
||||
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.TypeResolver;
|
||||
import org.jetbrains.jet.lang.resolve.AnnotationResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.OverloadingConflictResolver;
|
||||
import com.intellij.openapi.project.Project;
|
||||
|
||||
/* This file is generated by org.jetbrains.jet.di.InjectorGenerator. DO NOT EDIT! */
|
||||
public class InjectorForMacros {
|
||||
|
||||
private ExpressionTypingServices expressionTypingServices;
|
||||
private final Project project;
|
||||
|
||||
public InjectorForMacros(
|
||||
Project project
|
||||
) {
|
||||
this.expressionTypingServices = new ExpressionTypingServices();
|
||||
this.project = project;
|
||||
DescriptorResolver descriptorResolver = new DescriptorResolver();
|
||||
TypeResolver typeResolver = new TypeResolver();
|
||||
AnnotationResolver annotationResolver = new AnnotationResolver();
|
||||
CallResolver callResolver = new CallResolver();
|
||||
OverloadingConflictResolver overloadingConflictResolver = new OverloadingConflictResolver();
|
||||
|
||||
this.expressionTypingServices.setDescriptorResolver(descriptorResolver);
|
||||
this.expressionTypingServices.setCallResolver(callResolver);
|
||||
this.expressionTypingServices.setTypeResolver(typeResolver);
|
||||
this.expressionTypingServices.setProject(project);
|
||||
|
||||
descriptorResolver.setExpressionTypingServices(expressionTypingServices);
|
||||
descriptorResolver.setTypeResolver(typeResolver);
|
||||
descriptorResolver.setAnnotationResolver(annotationResolver);
|
||||
|
||||
typeResolver.setDescriptorResolver(descriptorResolver);
|
||||
typeResolver.setAnnotationResolver(annotationResolver);
|
||||
|
||||
annotationResolver.setExpressionTypingServices(expressionTypingServices);
|
||||
annotationResolver.setCallResolver(callResolver);
|
||||
|
||||
callResolver.setDescriptorResolver(descriptorResolver);
|
||||
callResolver.setExpressionTypingServices(expressionTypingServices);
|
||||
callResolver.setTypeResolver(typeResolver);
|
||||
callResolver.setOverloadingConflictResolver(overloadingConflictResolver);
|
||||
|
||||
}
|
||||
|
||||
public ExpressionTypingServices getExpressionTypingServices() {
|
||||
return this.expressionTypingServices;
|
||||
}
|
||||
|
||||
public Project getProject() {
|
||||
return this.project;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* Copyright 2000-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.di;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.jet.lang.ModuleConfiguration;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.OverloadingConflictResolver;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||
|
||||
/* This file is generated by org.jetbrains.jet.di.InjectorGenerator. DO NOT EDIT! */
|
||||
public class InjectorForTopDownAnalyzer {
|
||||
|
||||
private TopDownAnalyzer topDownAnalyzer;
|
||||
private BodyResolver bodyResolver;
|
||||
private ControlFlowAnalyzer controlFlowAnalyzer;
|
||||
private DeclarationsChecker declarationsChecker;
|
||||
private DescriptorResolver descriptorResolver;
|
||||
private ExpressionTypingServices expressionTypingServices;
|
||||
private final Project project;
|
||||
|
||||
public InjectorForTopDownAnalyzer(
|
||||
Project project,
|
||||
TopDownAnalysisContext topDownAnalysisContext,
|
||||
ModuleConfiguration moduleConfiguration,
|
||||
JetControlFlowDataTraceFactory jetControlFlowDataTraceFactory,
|
||||
boolean analyzingBootstrapLibrary
|
||||
) {
|
||||
this.topDownAnalyzer = new TopDownAnalyzer();
|
||||
this.bodyResolver = new BodyResolver();
|
||||
this.controlFlowAnalyzer = new ControlFlowAnalyzer();
|
||||
this.declarationsChecker = new DeclarationsChecker();
|
||||
this.descriptorResolver = new DescriptorResolver();
|
||||
this.expressionTypingServices = new ExpressionTypingServices();
|
||||
this.project = project;
|
||||
DeclarationResolver declarationResolver = new DeclarationResolver();
|
||||
AnnotationResolver annotationResolver = new AnnotationResolver();
|
||||
CallResolver callResolver = new CallResolver();
|
||||
TypeResolver typeResolver = new TypeResolver();
|
||||
OverloadingConflictResolver overloadingConflictResolver = new OverloadingConflictResolver();
|
||||
ImportsResolver importsResolver = new ImportsResolver();
|
||||
TypeHierarchyResolver typeHierarchyResolver = new TypeHierarchyResolver();
|
||||
DelegationResolver delegationResolver = new DelegationResolver();
|
||||
OverrideResolver overrideResolver = new OverrideResolver();
|
||||
OverloadResolver overloadResolver = new OverloadResolver();
|
||||
|
||||
this.topDownAnalyzer.setDeclarationResolver(declarationResolver);
|
||||
this.topDownAnalyzer.setTypeHierarchyResolver(typeHierarchyResolver);
|
||||
this.topDownAnalyzer.setDelegationResolver(delegationResolver);
|
||||
this.topDownAnalyzer.setOverrideResolver(overrideResolver);
|
||||
this.topDownAnalyzer.setOverloadResolver(overloadResolver);
|
||||
|
||||
this.bodyResolver.setContext(topDownAnalysisContext);
|
||||
this.bodyResolver.setDescriptorResolver(descriptorResolver);
|
||||
this.bodyResolver.setExpressionTypingServices(expressionTypingServices);
|
||||
this.bodyResolver.setCallResolver(callResolver);
|
||||
|
||||
this.controlFlowAnalyzer.setContext(topDownAnalysisContext);
|
||||
this.controlFlowAnalyzer.setFlowDataTraceFactory(jetControlFlowDataTraceFactory);
|
||||
|
||||
this.declarationsChecker.setContext(topDownAnalysisContext);
|
||||
|
||||
this.descriptorResolver.setExpressionTypingServices(expressionTypingServices);
|
||||
this.descriptorResolver.setTypeResolver(typeResolver);
|
||||
this.descriptorResolver.setAnnotationResolver(annotationResolver);
|
||||
|
||||
this.expressionTypingServices.setDescriptorResolver(descriptorResolver);
|
||||
this.expressionTypingServices.setCallResolver(callResolver);
|
||||
this.expressionTypingServices.setTypeResolver(typeResolver);
|
||||
this.expressionTypingServices.setProject(project);
|
||||
|
||||
declarationResolver.setContext(topDownAnalysisContext);
|
||||
declarationResolver.setDescriptorResolver(descriptorResolver);
|
||||
declarationResolver.setAnnotationResolver(annotationResolver);
|
||||
declarationResolver.setImportsResolver(importsResolver);
|
||||
|
||||
annotationResolver.setExpressionTypingServices(expressionTypingServices);
|
||||
annotationResolver.setCallResolver(callResolver);
|
||||
|
||||
callResolver.setDescriptorResolver(descriptorResolver);
|
||||
callResolver.setExpressionTypingServices(expressionTypingServices);
|
||||
callResolver.setTypeResolver(typeResolver);
|
||||
callResolver.setOverloadingConflictResolver(overloadingConflictResolver);
|
||||
|
||||
typeResolver.setDescriptorResolver(descriptorResolver);
|
||||
typeResolver.setAnnotationResolver(annotationResolver);
|
||||
|
||||
importsResolver.setContext(topDownAnalysisContext);
|
||||
importsResolver.setConfiguration(moduleConfiguration);
|
||||
|
||||
typeHierarchyResolver.setContext(topDownAnalysisContext);
|
||||
typeHierarchyResolver.setDescriptorResolver(descriptorResolver);
|
||||
typeHierarchyResolver.setImportsResolver(importsResolver);
|
||||
typeHierarchyResolver.setConfiguration(moduleConfiguration);
|
||||
|
||||
delegationResolver.setContext(topDownAnalysisContext);
|
||||
|
||||
overrideResolver.setContext(topDownAnalysisContext);
|
||||
|
||||
overloadResolver.setContext(topDownAnalysisContext);
|
||||
|
||||
}
|
||||
|
||||
public TopDownAnalyzer getTopDownAnalyzer() {
|
||||
return this.topDownAnalyzer;
|
||||
}
|
||||
|
||||
public BodyResolver getBodyResolver() {
|
||||
return this.bodyResolver;
|
||||
}
|
||||
|
||||
public ControlFlowAnalyzer getControlFlowAnalyzer() {
|
||||
return this.controlFlowAnalyzer;
|
||||
}
|
||||
|
||||
public DeclarationsChecker getDeclarationsChecker() {
|
||||
return this.declarationsChecker;
|
||||
}
|
||||
|
||||
public DescriptorResolver getDescriptorResolver() {
|
||||
return this.descriptorResolver;
|
||||
}
|
||||
|
||||
public ExpressionTypingServices getExpressionTypingServices() {
|
||||
return this.expressionTypingServices;
|
||||
}
|
||||
|
||||
public Project getProject() {
|
||||
return this.project;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,45 +18,11 @@ package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.Inject;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.containers.Queue;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
||||
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptorUtil;
|
||||
import org.jetbrains.jet.lang.descriptors.MutableClassDescriptor;
|
||||
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.SimpleFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetClassInitializer;
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclarationWithBody;
|
||||
import org.jetbrains.jet.lang.psi.JetDelegationSpecifier;
|
||||
import org.jetbrains.jet.lang.psi.JetDelegatorByExpressionSpecifier;
|
||||
import org.jetbrains.jet.lang.psi.JetDelegatorToSuperCall;
|
||||
import org.jetbrains.jet.lang.psi.JetDelegatorToSuperClass;
|
||||
import org.jetbrains.jet.lang.psi.JetDelegatorToThisCall;
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.jet.lang.psi.JetEnumEntry;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetObjectDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetParameter;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.lang.psi.JetPropertyAccessor;
|
||||
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetSecondaryConstructor;
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeReference;
|
||||
import org.jetbrains.jet.lang.psi.JetValueArgumentList;
|
||||
import org.jetbrains.jet.lang.psi.JetVisitorVoid;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallMaker;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResults;
|
||||
@@ -65,11 +31,7 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.DeferredType;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeConstructor;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
@@ -78,29 +40,10 @@ import org.jetbrains.jet.util.Box;
|
||||
import org.jetbrains.jet.util.lazy.ReenteringLazyValueComputationException;
|
||||
import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.inject.Inject;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.ANONYMOUS_INITIALIZER_WITHOUT_CONSTRUCTOR;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.BY_IN_SECONDARY_CONSTRUCTOR;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.CONSTRUCTOR_IN_TRAIT;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.DELEGATION_IN_TRAIT;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.DELEGATION_NOT_TO_TRAIT;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.FINAL_SUPERTYPE;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.INITIALIZER_WITH_NO_ARGUMENTS;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.MANY_CALLS_TO_THIS;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.MANY_CLASSES_IN_SUPERTYPE_LIST;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.SECONDARY_CONSTRUCTOR_BUT_NO_PRIMARY;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.SECONDARY_CONSTRUCTOR_NO_INITIALIZER_LIST;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.SUPERTYPE_APPEARS_TWICE;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.SUPERTYPE_INITIALIZED_IN_TRAIT;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.SUPERTYPE_NOT_A_CLASS_OR_TRAIT;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.SUPERTYPE_NOT_INITIALIZED;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.SUPERTYPE_NOT_INITIALIZED_DEFAULT;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.TYPE_MISMATCH;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.DEFERRED_TYPE;
|
||||
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
|
||||
|
||||
@@ -16,17 +16,17 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyAccessorDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
|
||||
@@ -16,31 +16,13 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
||||
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.MutableClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.MutableClassDescriptorLite;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceLike;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetEnumEntry;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetModifierList;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetObjectDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetParameter;
|
||||
import org.jetbrains.jet.lang.psi.JetParameterList;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.lang.psi.JetSecondaryConstructor;
|
||||
import org.jetbrains.jet.lang.psi.JetVisitorVoid;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -19,12 +19,12 @@ package org.jetbrains.jet.lang.resolve;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.Inject;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.DELEGATED;
|
||||
|
||||
@@ -18,73 +18,22 @@ package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.Inject;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.LocalVariableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.Modality;
|
||||
import org.jetbrains.jet.lang.descriptors.MutableClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.MutableValueParameterDescriptor;
|
||||
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.SimpleFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptorImpl;
|
||||
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.VariableDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.Visibility;
|
||||
import javax.inject.Inject;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetDelegationSpecifier;
|
||||
import org.jetbrains.jet.lang.psi.JetEnumEntry;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetModifierList;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetNullableType;
|
||||
import org.jetbrains.jet.lang.psi.JetObjectDeclarationName;
|
||||
import org.jetbrains.jet.lang.psi.JetParameter;
|
||||
import org.jetbrains.jet.lang.psi.JetProjectionKind;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.lang.psi.JetPropertyAccessor;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.lang.psi.JetSecondaryConstructor;
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeConstraint;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeElement;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeParameter;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeParameterListOwner;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeProjection;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeReference;
|
||||
import org.jetbrains.jet.lang.psi.JetUserType;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.DeferredType;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeProjection;
|
||||
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.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
@@ -93,29 +42,9 @@ import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.util.lazy.LazyValue;
|
||||
import org.jetbrains.jet.util.lazy.LazyValueWithDefault;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.CONFLICTING_CLASS_OBJECT_UPPER_BOUNDS;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.CONFLICTING_UPPER_BOUNDS;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.FINAL_CLASS_OBJECT_UPPER_BOUND;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.FINAL_UPPER_BOUND;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.NO_GENERICS_IN_SUPERTYPE_SPECIFIER;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.NULLABLE_SUPERTYPE;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.PROJECTION_IN_IMMEDIATE_ARGUMENT_TO_SUPERTYPE;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.PROPERTY_WITH_NO_TYPE_NO_INITIALIZER;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.SETTER_PARAMETER_WITH_DEFAULT_VALUE;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.UNRESOLVED_REFERENCE;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.UPPER_BOUND_VIOLATED;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.VAL_WITH_SETTER;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.WRONG_GETTER_RETURN_TYPE;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.WRONG_SETTER_PARAMETER_TYPE;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
|
||||
@@ -20,9 +20,9 @@ import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.Inject;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import org.jetbrains.jet.lang.ModuleConfiguration;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import javax.inject.Inject;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
|
||||
@@ -19,11 +19,12 @@ package org.jetbrains.jet.lang.resolve;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.Inject;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.containers.LinkedMultiMap;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import javax.inject.Inject;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
@@ -32,7 +33,6 @@ import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.util.CommonSuppliers;
|
||||
import com.intellij.util.containers.LinkedMultiMap;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
@@ -19,27 +19,16 @@ package org.jetbrains.jet.lang.resolve;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.di.InjectorForTopDownAnalyzer;
|
||||
import org.jetbrains.jet.lang.ModuleConfiguration;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.MutableClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetObjectDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.lang.psi.JetSecondaryConstructor;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
|
||||
@@ -71,7 +60,7 @@ public class TopDownAnalysisContext {
|
||||
private final boolean analyzingBootstrapLibrary;
|
||||
private boolean declaredLocally;
|
||||
|
||||
private final Injector injector;
|
||||
private final InjectorForTopDownAnalyzer injector;
|
||||
|
||||
public TopDownAnalysisContext(
|
||||
final Project project,
|
||||
@@ -87,16 +76,7 @@ public class TopDownAnalysisContext {
|
||||
"jetControlFlowDataTraceFactory must not be passed when analyzingBootstrapLibrary and vice versa");
|
||||
}
|
||||
|
||||
injector = Guice.createInjector(new TopDownAnalysisModule(project, analyzingBootstrapLibrary) {
|
||||
@Override
|
||||
protected void configureAfter() {
|
||||
bind(TopDownAnalysisContext.class).toInstance(TopDownAnalysisContext.this);
|
||||
bind(ModuleConfiguration.class).toInstance(configuration);
|
||||
if (jetControlFlowDataTraceFactory != null) {
|
||||
bind(JetControlFlowDataTraceFactory.class).toInstance(jetControlFlowDataTraceFactory);
|
||||
}
|
||||
}
|
||||
});
|
||||
this.injector = new InjectorForTopDownAnalyzer(project, this, configuration, jetControlFlowDataTraceFactory, analyzingBootstrapLibrary);
|
||||
|
||||
this.trace = new ObservableBindingTrace(trace);
|
||||
this.analyzeCompletely = analyzeCompletely;
|
||||
@@ -104,7 +84,7 @@ public class TopDownAnalysisContext {
|
||||
this.analyzingBootstrapLibrary = analyzingBootstrapLibrary;
|
||||
}
|
||||
|
||||
public Injector getInjector() {
|
||||
public InjectorForTopDownAnalyzer getInjector() {
|
||||
return injector;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-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.lang.resolve;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public abstract class TopDownAnalysisModule extends AbstractModule {
|
||||
|
||||
@NotNull
|
||||
private final Project project;
|
||||
private final boolean analyzingStdlib;
|
||||
|
||||
protected TopDownAnalysisModule(@NotNull Project project, boolean analyzingStdlib) {
|
||||
this.project = project;
|
||||
this.analyzingStdlib = analyzingStdlib;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void configure() {
|
||||
binder().disableCircularProxies();
|
||||
|
||||
bind(Project.class).toInstance(project);
|
||||
|
||||
if (!analyzingStdlib) {
|
||||
// TODO: move outside
|
||||
JetStandardLibrary.initialize(project);
|
||||
bind(JetStandardLibrary.class).toInstance(JetStandardLibrary.getInstance());
|
||||
}
|
||||
|
||||
configureAfter();
|
||||
}
|
||||
|
||||
protected abstract void configureAfter();
|
||||
}
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.inject.Inject;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
@@ -32,6 +31,7 @@ import org.jetbrains.jet.lang.psi.JetObjectDeclaration;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -104,7 +104,7 @@ public class TopDownAnalyzer {
|
||||
@NotNull ModuleConfiguration configuration,
|
||||
boolean declaredLocally) {
|
||||
TopDownAnalysisContext context = new TopDownAnalysisContext(project, trace, analyzeCompletely, configuration, declaredLocally, false, flowDataTraceFactory);
|
||||
context.getInjector().getInstance(TopDownAnalyzer.class).doProcess(context, outerScope, owner, declarations);
|
||||
context.getInjector().getTopDownAnalyzer().doProcess(context, outerScope, owner, declarations);
|
||||
|
||||
}
|
||||
|
||||
@@ -125,9 +125,9 @@ public class TopDownAnalyzer {
|
||||
overloadResolver.process();
|
||||
|
||||
if (!context.analyzingBootstrapLibrary()) {
|
||||
context.getInjector().getInstance(BodyResolver.class).resolveBehaviorDeclarationBodies();
|
||||
context.getInjector().getInstance(ControlFlowAnalyzer.class).process();
|
||||
context.getInjector().getInstance(DeclarationsChecker.class).process();
|
||||
context.getInjector().getBodyResolver().resolveBehaviorDeclarationBodies();
|
||||
context.getInjector().getControlFlowAnalyzer().process();
|
||||
context.getInjector().getDeclarationsChecker().process();
|
||||
}
|
||||
|
||||
context.debug("Exit");
|
||||
@@ -153,7 +153,7 @@ public class TopDownAnalyzer {
|
||||
@NotNull WritableScope outerScope,
|
||||
@NotNull NamespaceDescriptorImpl standardLibraryNamespace,
|
||||
@NotNull List<JetFile> files) {
|
||||
TopDownAnalysisContext context = new TopDownAnalysisContext(project, trace, Predicates.<PsiFile>alwaysTrue(), ModuleConfiguration.EMPTY, false, true, null);
|
||||
TopDownAnalysisContext context = new TopDownAnalysisContext(project, trace, Predicates.<PsiFile>alwaysFalse(), ModuleConfiguration.EMPTY, false, true, null);
|
||||
ArrayList<JetDeclaration> toAnalyze = new ArrayList<JetDeclaration>();
|
||||
for(JetFile file : files) {
|
||||
context.getNamespaceDescriptors().put(file, standardLibraryNamespace);
|
||||
@@ -162,7 +162,7 @@ public class TopDownAnalyzer {
|
||||
}
|
||||
// context.getDeclaringScopes().put(file, outerScope);
|
||||
|
||||
context.getInjector().getInstance(TopDownAnalyzer.class).doProcess(context, outerScope, standardLibraryNamespace, toAnalyze);
|
||||
context.getInjector().getTopDownAnalyzer().doProcess(context, outerScope, standardLibraryNamespace, toAnalyze);
|
||||
}
|
||||
|
||||
public static void processObject(
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.jetbrains.jet.lang.resolve;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.Inject;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiNameIdentifierOwner;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -39,6 +38,7 @@ import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
@@ -57,11 +57,9 @@ public class TypeHierarchyResolver {
|
||||
@NotNull
|
||||
private ModuleConfiguration configuration;
|
||||
|
||||
|
||||
// state
|
||||
private LinkedList<MutableClassDescriptor> topologicalOrder;
|
||||
|
||||
|
||||
@Inject
|
||||
public void setContext(@NotNull TopDownAnalysisContext context) {
|
||||
this.context = context;
|
||||
|
||||
@@ -23,28 +23,10 @@ import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.jet.lang.psi.JetFunctionType;
|
||||
import org.jetbrains.jet.lang.psi.JetNullableType;
|
||||
import org.jetbrains.jet.lang.psi.JetParameter;
|
||||
import org.jetbrains.jet.lang.psi.JetProjectionKind;
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetTupleType;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeElement;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeProjection;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeReference;
|
||||
import org.jetbrains.jet.lang.psi.JetUserType;
|
||||
import org.jetbrains.jet.lang.psi.JetVisitorVoid;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.LazyScopeAdapter;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.JetTypeImpl;
|
||||
import org.jetbrains.jet.lang.types.TypeConstructor;
|
||||
import org.jetbrains.jet.lang.types.TypeProjection;
|
||||
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.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
import org.jetbrains.jet.util.lazy.LazyValue;
|
||||
|
||||
@@ -53,9 +35,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.UNRESOLVED_REFERENCE;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.UNSUPPORTED;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.WRONG_NUMBER_OF_TYPE_ARGUMENTS;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET;
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,10 +19,10 @@ package org.jetbrains.jet.lang.resolve.calls;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.Inject;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import javax.inject.Inject;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
|
||||
-1
@@ -30,7 +30,6 @@ import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
+2
-3
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.jet.lang.types.expressions;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Inject;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
@@ -37,11 +36,11 @@ import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.jet.lang.types.CommonSupertypes;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.TYPE_MISMATCH;
|
||||
|
||||
@@ -70,7 +70,8 @@ public class JetStandardLibrary {
|
||||
initializing = true;
|
||||
try {
|
||||
instance = new JetStandardLibrary(project);
|
||||
} catch (Throwable e) {
|
||||
}
|
||||
catch (Throwable e) {
|
||||
initializationFailed = e;
|
||||
throw new RuntimeException("builtin library initialization failed: " + e, e);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
<orderEntry type="module" module-name="cli" />
|
||||
<orderEntry type="library" name="idea-full" level="project" />
|
||||
<orderEntry type="library" name="asm" level="project" />
|
||||
<orderEntry type="library" name="guice-3.0" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright 2000-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.di;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.jet.lang.resolve.AnnotationResolver;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.TypeResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.OverloadingConflictResolver;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
|
||||
/* This file is generated by org.jetbrains.jet.di.InjectorGenerator. DO NOT EDIT! */
|
||||
public class InjectorForTests {
|
||||
|
||||
private DescriptorResolver descriptorResolver;
|
||||
private ExpressionTypingServices expressionTypingServices;
|
||||
private TypeResolver typeResolver;
|
||||
private CallResolver callResolver;
|
||||
private JetStandardLibrary jetStandardLibrary;
|
||||
private final Project project;
|
||||
|
||||
public InjectorForTests(
|
||||
Project project
|
||||
) {
|
||||
this.descriptorResolver = new DescriptorResolver();
|
||||
this.expressionTypingServices = new ExpressionTypingServices();
|
||||
this.typeResolver = new TypeResolver();
|
||||
this.callResolver = new CallResolver();
|
||||
this.jetStandardLibrary = JetStandardLibrary.getInstance();
|
||||
this.project = project;
|
||||
AnnotationResolver annotationResolver = new AnnotationResolver();
|
||||
OverloadingConflictResolver overloadingConflictResolver = new OverloadingConflictResolver();
|
||||
|
||||
this.descriptorResolver.setExpressionTypingServices(expressionTypingServices);
|
||||
this.descriptorResolver.setTypeResolver(typeResolver);
|
||||
this.descriptorResolver.setAnnotationResolver(annotationResolver);
|
||||
|
||||
this.expressionTypingServices.setDescriptorResolver(descriptorResolver);
|
||||
this.expressionTypingServices.setCallResolver(callResolver);
|
||||
this.expressionTypingServices.setTypeResolver(typeResolver);
|
||||
this.expressionTypingServices.setProject(project);
|
||||
|
||||
this.typeResolver.setDescriptorResolver(descriptorResolver);
|
||||
this.typeResolver.setAnnotationResolver(annotationResolver);
|
||||
|
||||
this.callResolver.setDescriptorResolver(descriptorResolver);
|
||||
this.callResolver.setExpressionTypingServices(expressionTypingServices);
|
||||
this.callResolver.setTypeResolver(typeResolver);
|
||||
this.callResolver.setOverloadingConflictResolver(overloadingConflictResolver);
|
||||
|
||||
annotationResolver.setExpressionTypingServices(expressionTypingServices);
|
||||
annotationResolver.setCallResolver(callResolver);
|
||||
|
||||
}
|
||||
|
||||
public DescriptorResolver getDescriptorResolver() {
|
||||
return this.descriptorResolver;
|
||||
}
|
||||
|
||||
public ExpressionTypingServices getExpressionTypingServices() {
|
||||
return this.expressionTypingServices;
|
||||
}
|
||||
|
||||
public TypeResolver getTypeResolver() {
|
||||
return this.typeResolver;
|
||||
}
|
||||
|
||||
public CallResolver getCallResolver() {
|
||||
return this.callResolver;
|
||||
}
|
||||
|
||||
public JetStandardLibrary getJetStandardLibrary() {
|
||||
return this.jetStandardLibrary;
|
||||
}
|
||||
|
||||
public Project getProject() {
|
||||
return this.project;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.jet.resolve;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
@@ -26,21 +25,21 @@ import com.intellij.psi.PsiMethod;
|
||||
import junit.framework.Test;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
import org.jetbrains.jet.di.InjectorForTests;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTraceContext;
|
||||
import org.jetbrains.jet.lang.resolve.TopDownAnalysisModule;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResults;
|
||||
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaSemanticServices;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeProjection;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||
|
||||
import java.io.File;
|
||||
@@ -134,12 +133,8 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
|
||||
List<JetType> parameterTypeList = Arrays.asList(parameterType);
|
||||
// JetTypeInferrer.Services typeInferrerServices = JetSemanticServices.createSemanticServices(getProject()).getTypeInferrerServices(new BindingTraceContext());
|
||||
|
||||
CallResolver callResolver = Guice.createInjector(new TopDownAnalysisModule(getProject(), false) {
|
||||
@Override
|
||||
protected void configureAfter() {
|
||||
}
|
||||
}).getInstance(CallResolver.class);
|
||||
|
||||
CallResolver callResolver = new InjectorForTests(getProject()).getCallResolver();
|
||||
OverloadResolutionResults<FunctionDescriptor> functions = callResolver.resolveExactSignature(
|
||||
classDescriptor.getMemberScope(typeArguments), ReceiverDescriptor.NO_RECEIVER, name, parameterTypeList);
|
||||
for (ResolvedCall<? extends FunctionDescriptor> resolvedCall : functions.getResultingCalls()) {
|
||||
|
||||
@@ -16,15 +16,13 @@
|
||||
|
||||
package org.jetbrains.jet.types;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import org.jetbrains.jet.JetLiteFixture;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.di.InjectorForTests;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.TopDownAnalysisModule;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
||||
@@ -52,13 +50,9 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
||||
private JetScope scope;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
Injector injector = Guice.createInjector(new TopDownAnalysisModule(getProject(), false) {
|
||||
@Override
|
||||
protected void configureAfter() {
|
||||
}
|
||||
});
|
||||
JetStandardLibrary library = injector.getInstance(JetStandardLibrary.class);
|
||||
descriptorResolver = injector.getInstance(DescriptorResolver.class);
|
||||
InjectorForTests injector = new InjectorForTests(getProject());
|
||||
JetStandardLibrary library = injector.getJetStandardLibrary();
|
||||
descriptorResolver = injector.getDescriptorResolver();
|
||||
scope = createScope(library.getLibraryScope());
|
||||
}
|
||||
|
||||
|
||||
@@ -16,18 +16,16 @@
|
||||
|
||||
package org.jetbrains.jet.types;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import org.jetbrains.jet.JetLiteFixture;
|
||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.di.InjectorForTests;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.OverloadUtil;
|
||||
import org.jetbrains.jet.lang.resolve.TopDownAnalysisModule;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
|
||||
/**
|
||||
@@ -42,13 +40,9 @@ public class JetOverloadTest extends JetLiteFixture {
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
Injector injector = Guice.createInjector(new TopDownAnalysisModule(getProject(), false) {
|
||||
@Override
|
||||
protected void configureAfter() {
|
||||
}
|
||||
});
|
||||
library = injector.getInstance(JetStandardLibrary.class);
|
||||
descriptorResolver = injector.getInstance(DescriptorResolver.class);
|
||||
InjectorForTests injector = new InjectorForTests(getProject());
|
||||
library = injector.getJetStandardLibrary();
|
||||
descriptorResolver = injector.getDescriptorResolver();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,18 +16,16 @@
|
||||
|
||||
package org.jetbrains.jet.types;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import org.jetbrains.jet.JetLiteFixture;
|
||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.di.InjectorForTests;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.OverridingUtil;
|
||||
import org.jetbrains.jet.lang.resolve.TopDownAnalysisModule;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
|
||||
/**
|
||||
@@ -42,13 +40,9 @@ public class JetOverridingTest extends JetLiteFixture {
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
Injector injector = Guice.createInjector(new TopDownAnalysisModule(getProject(), false) {
|
||||
@Override
|
||||
protected void configureAfter() {
|
||||
}
|
||||
});
|
||||
library = injector.getInstance(JetStandardLibrary.class);
|
||||
descriptorResolver = injector.getInstance(DescriptorResolver.class);
|
||||
InjectorForTests injector = new InjectorForTests(getProject());
|
||||
library = injector.getJetStandardLibrary();
|
||||
descriptorResolver = injector.getDescriptorResolver();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,14 +17,13 @@
|
||||
package org.jetbrains.jet.types;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetLiteFixture;
|
||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.di.InjectorForTests;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
@@ -36,7 +35,10 @@ import org.jetbrains.jet.lang.resolve.java.JavaSemanticServices;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.CommonSupertypes;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
@@ -68,15 +70,10 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
||||
library = JetStandardLibrary.getInstance();
|
||||
classDefinitions = new ClassDefinitions();
|
||||
|
||||
Injector injector = Guice.createInjector(new TopDownAnalysisModule(getProject(), false) {
|
||||
@Override
|
||||
protected void configureAfter() {
|
||||
}
|
||||
});
|
||||
descriptorResolver = injector.getInstance(DescriptorResolver.class);
|
||||
descriptorResolver = injector.getInstance(DescriptorResolver.class);
|
||||
typeResolver = injector.getInstance(TypeResolver.class);
|
||||
expressionTypingServices = injector.getInstance(ExpressionTypingServices.class);
|
||||
InjectorForTests injector = new InjectorForTests(getProject());
|
||||
descriptorResolver = injector.getDescriptorResolver();
|
||||
typeResolver = injector.getTypeResolver();
|
||||
expressionTypingServices = injector.getExpressionTypingServices();
|
||||
|
||||
scopeWithImports = addImports(classDefinitions.BASIC_SCOPE);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
<orderEntry type="library" scope="PROVIDED" name="junit-plugin" level="project" />
|
||||
<orderEntry type="module" module-name="j2k" />
|
||||
<orderEntry type="module" module-name="js.translator" />
|
||||
<orderEntry type="library" name="guice-3.0" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.jet.plugin.liveTemplates.macro;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
||||
import com.intellij.codeInsight.template.Expression;
|
||||
@@ -31,13 +30,12 @@ import com.intellij.psi.PsiNamedElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.compiler.TipsManager;
|
||||
import org.jetbrains.jet.di.InjectorForMacros;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.TopDownAnalysisModule;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingContext;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||
import org.jetbrains.jet.plugin.compiler.WholeProjectAnalyzerFacade;
|
||||
|
||||
@@ -70,11 +68,7 @@ public abstract class BaseJetVariableMacro extends Macro {
|
||||
return null;
|
||||
}
|
||||
|
||||
ExpressionTypingServices callResolverContext = Guice.createInjector(new TopDownAnalysisModule(project, false) {
|
||||
@Override
|
||||
protected void configureAfter() {
|
||||
}
|
||||
}).getInstance(ExpressionTypingServices.class);
|
||||
ExpressionTypingServices callResolverContext = new InjectorForMacros(project).getExpressionTypingServices();
|
||||
|
||||
List<VariableDescriptor> filteredDescriptors = new ArrayList<VariableDescriptor>();
|
||||
for (DeclarationDescriptor declarationDescriptor : scope.getAllDescriptors()) {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright 2000-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.
|
||||
*/
|
||||
@@ -0,0 +1,16 @@
|
||||
<?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="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="frontend" />
|
||||
<orderEntry type="module" module-name="frontend.java" />
|
||||
<orderEntry type="library" name="intellij-core" level="project" />
|
||||
<orderEntry type="library" name="javax.inject" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright 2000-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.di;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.jet.lang.ModuleConfiguration;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class AllInjectorsGenerator {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
generateProductionInjector();
|
||||
generateMacroInjector();
|
||||
generateTestInjector();
|
||||
}
|
||||
|
||||
private static void generateProductionInjector() throws IOException {
|
||||
DependencyInjectorGenerator generator = new DependencyInjectorGenerator(false);
|
||||
|
||||
// Fields
|
||||
generator.addPublicField(TopDownAnalyzer.class);
|
||||
generator.addPublicField(BodyResolver.class);
|
||||
generator.addPublicField(ControlFlowAnalyzer.class);
|
||||
generator.addPublicField(DeclarationsChecker.class);
|
||||
generator.addPublicField(DescriptorResolver.class);
|
||||
generator.addPublicField(ExpressionTypingServices.class);
|
||||
|
||||
// Parameters
|
||||
generator.addPublicParameter(Project.class);
|
||||
generator.addParameter(TopDownAnalysisContext.class);
|
||||
generator.addParameter(ModuleConfiguration.class);
|
||||
generator.addParameter(JetControlFlowDataTraceFactory.class);
|
||||
generator.addParameter(false, boolean.class, "analyzingBootstrapLibrary");
|
||||
|
||||
generator.generate("compiler/frontend/src", "org.jetbrains.jet.di", "InjectorForTopDownAnalyzer");
|
||||
}
|
||||
|
||||
private static void generateMacroInjector() throws IOException {
|
||||
DependencyInjectorGenerator generator = new DependencyInjectorGenerator(false);
|
||||
|
||||
// Fields
|
||||
generator.addPublicField(ExpressionTypingServices.class);
|
||||
|
||||
// Parameters
|
||||
generator.addPublicParameter(Project.class);
|
||||
|
||||
generator.generate("compiler/frontend/src", "org.jetbrains.jet.di", "InjectorForMacros");
|
||||
}
|
||||
|
||||
private static void generateTestInjector() throws IOException {
|
||||
DependencyInjectorGenerator generator = new DependencyInjectorGenerator(false);
|
||||
|
||||
// Fields
|
||||
generator.addPublicField(DescriptorResolver.class);
|
||||
generator.addPublicField(ExpressionTypingServices.class);
|
||||
generator.addPublicField(TypeResolver.class);
|
||||
generator.addPublicField(CallResolver.class);
|
||||
generator.addField(true, JetStandardLibrary.class, null, new GivenExpression("JetStandardLibrary.getInstance()"));
|
||||
|
||||
// Parameters
|
||||
generator.addPublicParameter(Project.class);
|
||||
|
||||
generator.generate("compiler/tests", "org.jetbrains.jet.di", "InjectorForTests");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2000-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.di;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
class ConstructorCall implements Expression {
|
||||
private final Constructor<?> constructor;
|
||||
private final List<Field> constructorArguments = Lists.newArrayList();
|
||||
|
||||
ConstructorCall(Constructor<?> constructor) {
|
||||
this.constructor = constructor;
|
||||
}
|
||||
|
||||
public List<Field> getConstructorArguments() {
|
||||
return constructorArguments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder("new " + constructor.getDeclaringClass().getSimpleName() + "(");
|
||||
for (Iterator<Field> iterator = constructorArguments.iterator(); iterator.hasNext(); ) {
|
||||
Field argument = iterator.next();
|
||||
builder.append(argument.getGetterName() + "()");
|
||||
if (iterator.hasNext()) {
|
||||
builder.append(", ");
|
||||
}
|
||||
}
|
||||
builder.append(")");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,350 @@
|
||||
/*
|
||||
* Copyright 2000-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.di;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class DependencyInjectorGenerator {
|
||||
|
||||
public static final String INDENT_STEP = " ";
|
||||
private static final String LOCK_NAME = "__lock__";
|
||||
|
||||
private final boolean lazy;
|
||||
private final Multimap<Class<?>, Field> typeToField = HashMultimap.create();
|
||||
private final Set<Field> satisfied = Sets.newHashSet();
|
||||
private final Set<Field> fields = Sets.newLinkedHashSet();
|
||||
private final Set<Parameter> parameters = Sets.newLinkedHashSet();
|
||||
|
||||
private final Set<Field> backsParameter = Sets.newHashSet();
|
||||
|
||||
public DependencyInjectorGenerator(boolean lazy) {
|
||||
this.lazy = lazy;
|
||||
}
|
||||
|
||||
public void generate(String targetSourceRoot, String injectorPackageName, String injectorClassName) throws IOException {
|
||||
String outputFileName = targetSourceRoot + "/" + injectorPackageName.replace(".", "/") + "/" + injectorClassName + ".java";
|
||||
|
||||
File file = new File(outputFileName);
|
||||
File parentFile = file.getParentFile();
|
||||
if (!parentFile.exists()) {
|
||||
if (parentFile.mkdirs()) {
|
||||
System.out.println("Directory created: " + parentFile.getAbsolutePath());
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("Cannot create directory: " + parentFile);
|
||||
}
|
||||
}
|
||||
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(file);
|
||||
System.out.println("File opened: " + file.getAbsolutePath());
|
||||
|
||||
PrintStream out = new PrintStream(fileOutputStream);
|
||||
try {
|
||||
for (Field field : Lists.newArrayList(fields)) {
|
||||
satisfyDependenciesFor(field, field);
|
||||
}
|
||||
|
||||
String copyright = "injector-generator/copyright.txt";
|
||||
out.println(FileUtil.loadFile(new File(copyright)));
|
||||
out.println();
|
||||
|
||||
out.println("package " + injectorPackageName + ";");
|
||||
out.println();
|
||||
|
||||
generateImports(out, injectorPackageName);
|
||||
out.println();
|
||||
|
||||
out.println("/* This file is generated by " + AllInjectorsGenerator.class.getName() + ". DO NOT EDIT! */");
|
||||
out.println("public class " + injectorClassName + " {");
|
||||
// Needed for double-checked locking
|
||||
// out.println();
|
||||
// out.println(" private static final Object " + LOCK_NAME + " = new Object();");
|
||||
out.println();
|
||||
generateFields(out);
|
||||
out.println();
|
||||
generateConstructor(injectorClassName, out);
|
||||
out.println();
|
||||
generateGetters(out);
|
||||
// Needed to fix double-checked locking
|
||||
// out.println();
|
||||
// generateMakeFunction(out);
|
||||
out.println("}"); // class
|
||||
}
|
||||
finally {
|
||||
fileOutputStream.close();
|
||||
System.out.println("File closed");
|
||||
}
|
||||
}
|
||||
|
||||
public void addPublicParameter(Class<?> type) {
|
||||
addParameter(true, type, var(type));
|
||||
}
|
||||
|
||||
public void addParameter(Class<?> type) {
|
||||
addParameter(false, type, var(type));
|
||||
}
|
||||
|
||||
public void addParameter(boolean reexport, @NotNull Class<?> type, @Nullable String name) {
|
||||
Field field = addField(reexport, type, name, null);
|
||||
Parameter parameter = new Parameter(type, name, field);
|
||||
parameters.add(parameter);
|
||||
field.setInitialization(new ParameterExpression(parameter));
|
||||
backsParameter.add(field);
|
||||
typeToField.put(type, field);
|
||||
}
|
||||
|
||||
public Field addPublicField(Class<?> type) {
|
||||
return addField(true, type, null, null);
|
||||
}
|
||||
|
||||
public Field addField(Class<?> type) {
|
||||
return addField(false, type, null, null);
|
||||
}
|
||||
|
||||
public Field addField(boolean isPublic, Class<?> type, @Nullable String name, @Nullable Expression init) {
|
||||
Field field = Field.create(isPublic, type, name == null ? var(type) : name, init);
|
||||
fields.add(field);
|
||||
typeToField.put(type, field);
|
||||
return field;
|
||||
}
|
||||
|
||||
private void generateImports(PrintStream out, String injectorPackageName) {
|
||||
for (Field field : fields) {
|
||||
generateImportDirective(out, field.getType(), injectorPackageName);
|
||||
}
|
||||
for (Parameter parameter : parameters) {
|
||||
generateImportDirective(out, parameter.getType(), injectorPackageName);
|
||||
}
|
||||
}
|
||||
|
||||
private void generateImportDirective(PrintStream out, Class<?> type, String injectorPackageName) {
|
||||
if (type.isPrimitive()) return;
|
||||
String importedPackageName = type.getPackage().getName();
|
||||
if ("java.lang".equals(importedPackageName)
|
||||
|| injectorPackageName.equals(importedPackageName)) {
|
||||
return;
|
||||
}
|
||||
out.println("import " + type.getCanonicalName() + ";");
|
||||
}
|
||||
|
||||
private void generateFields(PrintStream out) {
|
||||
for (Field field : fields) {
|
||||
if (lazy || field.isPublic()) {
|
||||
String _final = backsParameter.contains(field) ? "final " : "";
|
||||
out.println(" private " + _final + field.getType().getSimpleName() + " " + field.getName() + ";");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void generateConstructor(String injectorClassName, PrintStream out) {
|
||||
String indent = " ";
|
||||
|
||||
// Constructor parameters
|
||||
if (parameters.isEmpty()) {
|
||||
out.println(" public " + injectorClassName + "() {");
|
||||
}
|
||||
else {
|
||||
out.println(" public " + injectorClassName + "(");
|
||||
for (Iterator<Parameter> iterator = parameters.iterator(); iterator.hasNext(); ) {
|
||||
Parameter parameter = iterator.next();
|
||||
out.print(indent + parameter.getType().getSimpleName() + " " + parameter.getName());
|
||||
if (iterator.hasNext()) {
|
||||
out.println(",");
|
||||
}
|
||||
}
|
||||
out.println("\n ) {");
|
||||
}
|
||||
|
||||
if (lazy) {
|
||||
// Remember parameters
|
||||
for (Parameter parameter : parameters) {
|
||||
out.println(indent + "this." + parameter.getField().getName() + " = " + parameter.getName() + ";");
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Initialize fields
|
||||
for (Field field : fields) {
|
||||
if (!backsParameter.contains(field) || field.isPublic()) {
|
||||
String prefix = field.isPublic() ? "this." : field.getTypeName() + " ";
|
||||
out.println(indent + prefix + field.getName() + " = " + field.getInitialization() + ";");
|
||||
}
|
||||
}
|
||||
out.println();
|
||||
|
||||
// Call setters
|
||||
for (Field field : fields) {
|
||||
for (SetterDependency dependency : field.getDependencies()) {
|
||||
String prefix = field.isPublic() ? "this." : "";
|
||||
out.println(indent + prefix + dependency.getDependent().getName() + "." + dependency.getSetterName() + "(" + dependency.getDependency().getName() + ");");
|
||||
}
|
||||
if (!field.getDependencies().isEmpty()) {
|
||||
out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out.println(" }");
|
||||
}
|
||||
|
||||
private void generateGetters(PrintStream out) {
|
||||
String indent0 = " ";
|
||||
String indent1 = indent0 + INDENT_STEP;
|
||||
String indent2 = indent1 + INDENT_STEP;
|
||||
String indent3 = indent2 + INDENT_STEP;
|
||||
String indent4 = indent3 + INDENT_STEP;
|
||||
for (Field field : fields) {
|
||||
if (!lazy && !field.isPublic()) continue;
|
||||
String visibility = field.isPublic() ? "public" : "private";
|
||||
out.println(indent0 + visibility + " " + field.getTypeName() + " " + field.getGetterName() + "() {");
|
||||
|
||||
if (lazy && !backsParameter.contains(field)) {
|
||||
Expression initialization = field.getInitialization();
|
||||
assert initialization != null : field;
|
||||
|
||||
// Double-checked locking
|
||||
out.println(indent1 + "if (this." + field.getName() + " == null) {");
|
||||
|
||||
out.println(indent2 + "this." + field.getName() + " = " + initialization + ";");
|
||||
// Invoke setters
|
||||
for (SetterDependency dependency : field.getDependencies()) {
|
||||
out.println(indent2 + "this." + field.getName() + "." + dependency.getSetterName() + "(" + dependency.getDependency().getGetterName() + "());");
|
||||
}
|
||||
|
||||
out.println(indent1 + "}"); // Outer if
|
||||
|
||||
/*
|
||||
// Double-checked locking
|
||||
out.println(indent1 + "if (this." + field.getName() + " == null) {");
|
||||
out.println(indent2 + "synchronized (" + LOCK_NAME + ") {");
|
||||
out.println(indent3 + "if (this." + field.getName() + " == null) {");
|
||||
|
||||
out.println(indent4 + "this." + field.getName() + " = " + initialization + ";");
|
||||
// Invoke setters
|
||||
for (SetterDependency dependency : field.getDependencies()) {
|
||||
out.println(indent4 + "this." + field.getName() + "." + dependency.getSetterName() + "(" + dependency.getDependency().getGetterName() + "());");
|
||||
}
|
||||
|
||||
out.println(indent3 + "}"); // Inner if
|
||||
out.println(indent2 + "}"); // synchronized
|
||||
out.println(indent1 + "}"); // Outer if
|
||||
*/
|
||||
}
|
||||
|
||||
out.println(indent1 + "return this." + field.getName() + ";");
|
||||
out.println(indent0 + "}");
|
||||
out.println();
|
||||
}
|
||||
}
|
||||
|
||||
private void satisfyDependenciesFor(Field field, Field neededFor) {
|
||||
if (!satisfied.add(field)) return;
|
||||
if (backsParameter.contains(field)) return;
|
||||
|
||||
if (field.getInitialization() == null) {
|
||||
initializeByConstructorCall(field, neededFor);
|
||||
}
|
||||
|
||||
for (Method method : field.getType().getDeclaredMethods()) {
|
||||
if (method.getAnnotation(javax.inject.Inject.class) == null
|
||||
|| !method.getName().startsWith("set")
|
||||
|| method.getParameterTypes().length != 1) continue;
|
||||
|
||||
Class<?> parameterType = method.getParameterTypes()[0];
|
||||
|
||||
|
||||
Field dependency = findDependencyOfType(parameterType, field + ": " + method + ": " + fields, field);
|
||||
|
||||
field.getDependencies().add(new SetterDependency(field, method.getName(), dependency));
|
||||
}
|
||||
}
|
||||
|
||||
private Field findDependencyOfType(Class<?> parameterType, String errorMessage, Field neededFor) {
|
||||
Collection<Field> fields = typeToField.get(parameterType);
|
||||
Field dependency;
|
||||
if (fields.isEmpty()) {
|
||||
dependency = addField(parameterType);
|
||||
satisfyDependenciesFor(dependency, neededFor);
|
||||
}
|
||||
else if (fields.size() == 1) {
|
||||
dependency = fields.iterator().next();
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Ambiguous dependency: " + errorMessage);
|
||||
}
|
||||
return dependency;
|
||||
}
|
||||
|
||||
private void initializeByConstructorCall(Field field, Field neededFor) {
|
||||
Class<?> type = field.getType();
|
||||
|
||||
// Look for constructor
|
||||
Constructor<?>[] constructors = type.getConstructors();
|
||||
if (constructors.length == 0 || !Modifier.isPublic(constructors[0].getModifiers())) {
|
||||
throw new IllegalArgumentException("No constructor: " + type.getName() + " needed for " + neededFor);
|
||||
}
|
||||
Constructor<?> constructor = constructors[0];
|
||||
|
||||
// Find arguments
|
||||
ConstructorCall dependency = new ConstructorCall(constructor);
|
||||
Class<?>[] parameterTypes = constructor.getParameterTypes();
|
||||
for (Class<?> parameterType : parameterTypes) {
|
||||
Field fieldForParameter = findDependencyOfType(parameterType, "constructor: " + constructor + ", parameter: " + parameterType, field);
|
||||
dependency.getConstructorArguments().add(fieldForParameter);
|
||||
}
|
||||
|
||||
field.setInitialization(dependency);
|
||||
}
|
||||
|
||||
private String var(Class<?> theClass) {
|
||||
return StringUtil.decapitalize(theClass.getSimpleName());
|
||||
}
|
||||
|
||||
private void generateMakeFunction(PrintStream out) {
|
||||
out.println(" private static <T> T make(Class<T> theClass) {");
|
||||
out.println(" try { ");
|
||||
out.println(" return theClass.newInstance(); ");
|
||||
out.println(" } ");
|
||||
out.println(" catch (InstantiationException e) { ");
|
||||
out.println(" throw new IllegalStateException(e); ");
|
||||
out.println(" } ");
|
||||
out.println(" catch (IllegalAccessException e) { ");
|
||||
out.println(" throw new IllegalStateException(e); ");
|
||||
out.println(" } ");
|
||||
out.println(" } ");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2000-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.di;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
interface Expression {}
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright 2000-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.di;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
class Field {
|
||||
|
||||
public static Field create(boolean isPublic, Class<?> type, String name, @Nullable Expression init) {
|
||||
Field field = new Field(isPublic, type, name);
|
||||
field.initialization = init;
|
||||
return field;
|
||||
}
|
||||
|
||||
private final Class<?> type;
|
||||
private final String name;
|
||||
private final boolean isPublic;
|
||||
|
||||
@Nullable
|
||||
private Expression initialization;
|
||||
|
||||
private final List<SetterDependency> dependencies = Lists.newArrayList();
|
||||
|
||||
Field(boolean isPublic, Class<?> type, String name) {
|
||||
this.isPublic = isPublic;
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Class<?> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
return type.getSimpleName();
|
||||
}
|
||||
|
||||
public String getGetterName() {
|
||||
String prefix;
|
||||
if (getType() == boolean.class || getType() == Boolean.class) {
|
||||
prefix = "is";
|
||||
}
|
||||
else {
|
||||
prefix = "get";
|
||||
}
|
||||
return prefix + StringUtil.capitalize(getName());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Expression getInitialization() {
|
||||
return initialization;
|
||||
}
|
||||
|
||||
public void setInitialization(@NotNull Expression initialization) {
|
||||
this.initialization = initialization;
|
||||
}
|
||||
|
||||
public List<SetterDependency> getDependencies() {
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
public boolean isPublic() {
|
||||
return isPublic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getTypeName() + " " + getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Field field = (Field) o;
|
||||
|
||||
if (!name.equals(field.name)) return false;
|
||||
if (!type.equals(field.type)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = type.hashCode();
|
||||
result = 31 * result + name.hashCode();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2000-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.di;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
class GivenExpression implements Expression {
|
||||
private final String expression;
|
||||
|
||||
GivenExpression(String expression) {
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
public String getExpression() {
|
||||
return expression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return expression;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2000-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.di;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
class Parameter {
|
||||
private final Class<?> type;
|
||||
private final String name;
|
||||
private final Field field;
|
||||
|
||||
Parameter(Class<?> type, String name, Field field) {
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
public Class<?> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Field getField() {
|
||||
return field;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Parameter parameter = (Parameter) o;
|
||||
|
||||
if (name != null ? !name.equals(parameter.name) : parameter.name != null) return false;
|
||||
if (type != null ? !type.equals(parameter.type) : parameter.type != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = type != null ? type.hashCode() : 0;
|
||||
result = 31 * result + (name != null ? name.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2000-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.di;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class ParameterExpression implements Expression {
|
||||
private final Parameter parameter;
|
||||
|
||||
public ParameterExpression(Parameter parameter) {
|
||||
this.parameter = parameter;
|
||||
}
|
||||
|
||||
public Parameter getParameter() {
|
||||
return parameter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return parameter.getName();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2000-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.di;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
class SetterDependency {
|
||||
private final Field dependent;
|
||||
private final String setterName;
|
||||
private final Field dependency;
|
||||
|
||||
SetterDependency(Field dependent, String setterName, Field dependency) {
|
||||
this.dependent = dependent;
|
||||
this.setterName = setterName;
|
||||
this.dependency = dependency;
|
||||
}
|
||||
|
||||
public Field getDependent() {
|
||||
return dependent;
|
||||
}
|
||||
|
||||
public String getSetterName() {
|
||||
return setterName;
|
||||
}
|
||||
|
||||
public Field getDependency() {
|
||||
return dependency;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return dependent.getName() + "." + setterName + "(" + dependency.getName() + ")";
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Executable
BIN
Binary file not shown.
Regular → Executable
BIN
Binary file not shown.
Reference in New Issue
Block a user