Inter-field dependencies fixed for fields used as context
The problem was that when GivenExpression was used to initialize a feld, the generator did not know that there's a dependency on the receiver of the call inside the expression, so it could place the call before the initialization of the receiver, which caused a compilation error. Now dependencies are tracked explicitly
This commit is contained in:
@@ -125,8 +125,9 @@ class Field {
|
||||
Class<?> clazz = type.getClazz();
|
||||
List<Field> result = Lists.newArrayList();
|
||||
for (Method method : allGetters(clazz)) {
|
||||
DiType type = DiType.fromReflectionType(method.getGenericReturnType());
|
||||
result.add(create(false, type, var(type), new GivenExpression(this.getName() + "." + method.getName() + "()")));
|
||||
MethodCall init = new MethodCall(this, method);
|
||||
DiType initType = init.getType();
|
||||
result.add(create(false, initType, var(initType), init));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -79,6 +79,9 @@ public abstract class InjectionLogicGenerator {
|
||||
ConstructorCall call = (ConstructorCall) initialization;
|
||||
return call.getConstructorArguments();
|
||||
}
|
||||
else if (initialization instanceof MethodCall) {
|
||||
return Collections.singletonList(((MethodCall) initialization).getReceiver());
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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 java.lang.reflect.Method
|
||||
import org.jetbrains.jet.lang.types.JetType
|
||||
|
||||
public class MethodCall(
|
||||
val receiver: Field,
|
||||
val method: Method
|
||||
) : Expression {
|
||||
override fun renderAsCode(): String {
|
||||
return "${receiver.getName()}.${method.getName()}()"
|
||||
}
|
||||
|
||||
override fun getTypesToImport() = listOf<DiType>()
|
||||
|
||||
override fun getType(): DiType = DiType.fromReflectionType(method.getGenericReturnType())
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user