use of com.google.errorprone.refaster.UStatement.UnifierWithUnconsumedStatements in project error-prone by google.
the class BlockTemplate method matchesStartingAtBeginning.
private Choice<List<BlockTemplateMatch>> matchesStartingAtBeginning(final JCBlock block, final int offset, final ImmutableList<? extends StatementTree> statements, final Context context) {
if (statements.isEmpty()) {
return Choice.none();
}
final JCStatement firstStatement = (JCStatement) statements.get(0);
Choice<UnifierWithUnconsumedStatements> choice = Choice.of(UnifierWithUnconsumedStatements.create(new Unifier(context), statements));
for (UStatement templateStatement : templateStatements()) {
choice = choice.thenChoose(templateStatement);
}
return choice.thenChoose(new Function<UnifierWithUnconsumedStatements, Choice<List<BlockTemplateMatch>>>() {
@Override
public Choice<List<BlockTemplateMatch>> apply(UnifierWithUnconsumedStatements state) {
Unifier unifier = state.unifier();
Inliner inliner = unifier.createInliner();
try {
Optional<Unifier> checkedUnifier = typecheck(unifier, inliner, new Warner(firstStatement), expectedTypes(inliner), actualTypes(inliner));
if (checkedUnifier.isPresent()) {
int consumedStatements = statements.size() - state.unconsumedStatements().size();
BlockTemplateMatch match = new BlockTemplateMatch(block, checkedUnifier.get(), offset, offset + consumedStatements);
return matchesStartingAnywhere(block, offset + consumedStatements, statements.subList(consumedStatements, statements.size()), context).transform(prepend(match));
}
} catch (CouldNotResolveImportException e) {
// fall through
}
return Choice.none();
}
});
}
use of com.google.errorprone.refaster.UStatement.UnifierWithUnconsumedStatements in project error-prone by google.
the class UBlank method apply.
@Override
public Choice<UnifierWithUnconsumedStatements> apply(final UnifierWithUnconsumedStatements state) {
int goodIndex = 0;
while (goodIndex < state.unconsumedStatements().size()) {
StatementTree stmt = state.unconsumedStatements().get(goodIndex);
if (firstNonNull(FORBIDDEN_REFERENCE_SCANNER.scan(stmt, state.unifier()), false) && ControlFlowVisitor.INSTANCE.visitStatement(stmt) == ControlFlowVisitor.Result.NEVER_EXITS) {
break;
} else {
goodIndex++;
}
}
Collection<Integer> breakPoints = ContiguousSet.create(Range.closed(0, goodIndex), DiscreteDomain.integers());
return Choice.from(breakPoints).transform(new Function<Integer, UnifierWithUnconsumedStatements>() {
@Override
public UnifierWithUnconsumedStatements apply(Integer k) {
Unifier unifier = state.unifier().fork();
unifier.putBinding(key(), state.unconsumedStatements().subList(0, k));
List<? extends StatementTree> remaining = state.unconsumedStatements().subList(k, state.unconsumedStatements().size());
return UnifierWithUnconsumedStatements.create(unifier, remaining);
}
});
}
Aggregations