use of org.sonar.java.model.expression.LambdaExpressionTreeImpl in project sonar-java by SonarSource.
the class TypeAndReferenceSolver method visitLambdaExpression.
@Override
public void visitLambdaExpression(LambdaExpressionTree tree) {
LambdaExpressionTreeImpl lambdaExpressionTree = (LambdaExpressionTreeImpl) tree;
if (lambdaExpressionTree.isTypeSet()) {
// type should be tied to a SAM interface
JavaType lambdaType = (JavaType) lambdaExpressionTree.symbolType();
List<JavaType> samMethodArgs = resolve.findSamMethodArgs(lambdaType);
for (int i = 0; i < samMethodArgs.size(); i++) {
VariableTree param = lambdaExpressionTree.parameters().get(i);
if (param.type().is(Tree.Kind.INFERED_TYPE)) {
JavaType inferedType = samMethodArgs.get(i);
if (inferedType.isTagged(JavaType.WILDCARD)) {
// JLS8 18.5.3
inferedType = ((WildCardType) inferedType).bound;
}
((AbstractTypedTree) param.type()).setInferedType(inferedType);
((JavaSymbol.VariableJavaSymbol) param.symbol()).type = inferedType;
}
}
super.visitLambdaExpression(tree);
if (lambdaType.isUnknown() || lambdaType.isTagged(JavaType.DEFERRED)) {
return;
}
refineLambdaType(lambdaExpressionTree, lambdaType);
} else {
registerType(tree, symbols.deferedType(lambdaExpressionTree));
}
}
Aggregations