use of com.sun.tools.javac.tree.JCTree.JCStatement in project ceylon-compiler by ceylon.
the class StatementTransformer method openOuterSubstitutionIfNeeded.
JCStatement openOuterSubstitutionIfNeeded(Value value, Type t, List<JCAnnotation> annots, int modifiers) {
JCStatement result = null;
if (value.isSpecifiedInForElse()) {
DeferredSpecification d = new DeferredSpecification(value, modifiers, annots, t);
deferredSpecifications.put(value, d);
result = d.openOuterSubstitution();
}
return result;
}
use of com.sun.tools.javac.tree.JCTree.JCStatement in project ceylon-compiler by ceylon.
the class NamedArgumentInvocation method bindMethodArgument.
private void bindMethodArgument(Tree.MethodArgument methodArg, Parameter declaredParam, Naming.SyntheticName argName) {
ListBuffer<JCStatement> statements;
Function model = methodArg.getDeclarationModel();
List<JCStatement> body;
boolean prevNoExpressionlessReturn = gen.statementGen().noExpressionlessReturn;
boolean prevSyntheticClassBody = gen.expressionGen().withinSyntheticClassBody(Decl.isMpl(model) || gen.expressionGen().isWithinSyntheticClassBody());
try {
gen.statementGen().noExpressionlessReturn = gen.isAnything(model.getType());
if (methodArg.getBlock() != null) {
body = gen.statementGen().transformBlock(methodArg.getBlock());
if (!methodArg.getBlock().getDefinitelyReturns()) {
if (gen.isAnything(model.getType())) {
body = body.append(gen.make().Return(gen.makeNull()));
} else {
body = body.append(gen.make().Return(gen.makeErroneous(methodArg.getBlock(), "compiler bug: non-void method does not definitely return")));
}
}
} else {
Expression expr = methodArg.getSpecifierExpression().getExpression();
BoxingStrategy boxing = CodegenUtil.getBoxingStrategy(model);
Type type = model.getType();
JCExpression transExpr = gen.expressionGen().transformExpression(expr, boxing, type);
JCReturn returnStat = gen.make().Return(transExpr);
body = List.<JCStatement>of(returnStat);
}
} finally {
gen.expressionGen().withinSyntheticClassBody(prevSyntheticClassBody);
gen.statementGen().noExpressionlessReturn = prevNoExpressionlessReturn;
}
Type callableType = model.appliedReference(null, Collections.<Type>emptyList()).getFullType();
CallableBuilder callableBuilder = CallableBuilder.methodArgument(gen.gen(), methodArg, model, callableType, Collections.singletonList(methodArg.getParameterLists().get(0)), gen.classGen().transformMplBody(methodArg.getParameterLists(), model, body));
JCExpression callable = callableBuilder.build();
JCExpression typeExpr = gen.makeJavaType(callableType, JT_RAW);
JCVariableDecl varDecl = gen.makeVar(argName, typeExpr, callable);
statements = ListBuffer.<JCStatement>of(varDecl);
bind(declaredParam, argName, gen.makeJavaType(callableType), statements.toList());
}
use of com.sun.tools.javac.tree.JCTree.JCStatement in project bazel by bazelbuild.
the class TreePruner method delegatingConstructor.
private static boolean delegatingConstructor(List<JCStatement> stats) {
if (stats.isEmpty()) {
return false;
}
JCStatement stat = stats.get(0);
if (stat.getKind() != Kind.EXPRESSION_STATEMENT) {
return false;
}
JCExpression expr = ((JCExpressionStatement) stat).getExpression();
if (expr.getKind() != Kind.METHOD_INVOCATION) {
return false;
}
JCExpression method = ((JCMethodInvocation) expr).getMethodSelect();
Name name;
switch(method.getKind()) {
case IDENTIFIER:
name = ((JCIdent) method).getName();
break;
case MEMBER_SELECT:
name = ((JCFieldAccess) method).getIdentifier();
break;
default:
return false;
}
return name.contentEquals("this") || name.contentEquals("super");
}
use of com.sun.tools.javac.tree.JCTree.JCStatement in project error-prone by google.
the class UPlaceholderStatement method apply.
@Override
public Choice<UnifierWithUnconsumedStatements> apply(final UnifierWithUnconsumedStatements initState) {
final PlaceholderUnificationVisitor visitor = PlaceholderUnificationVisitor.create(TreeMaker.instance(initState.unifier().getContext()), arguments());
PlaceholderVerificationVisitor verification = new PlaceholderVerificationVisitor(Collections2.transform(placeholder().requiredParameters(), Functions.forMap(arguments())), arguments().values());
// The choices where we might conceivably have a completed placeholder match.
Choice<State<ConsumptionState>> realOptions = Choice.none();
// The choice of consumption states to this point in the block.
Choice<State<ConsumptionState>> choiceToHere = Choice.of(State.create(List.<UVariableDecl>nil(), initState.unifier(), ConsumptionState.empty()));
if (verification.allRequiredMatched()) {
realOptions = choiceToHere.or(realOptions);
}
for (final StatementTree targetStatement : initState.unconsumedStatements()) {
if (!verification.scan(targetStatement, initState.unifier())) {
// we saw a variable that's not allowed to be referenced
break;
}
// Consume another statement, or if that fails, fall back to the previous choices...
choiceToHere = choiceToHere.thenChoose(new Function<State<ConsumptionState>, Choice<State<ConsumptionState>>>() {
@Override
public Choice<State<ConsumptionState>> apply(final State<ConsumptionState> consumptionState) {
return visitor.unifyStatement(targetStatement, consumptionState).transform(new Function<State<? extends JCStatement>, State<ConsumptionState>>() {
@Override
public State<ConsumptionState> apply(State<? extends JCStatement> stmtState) {
return stmtState.withResult(consumptionState.result().consume(stmtState.result()));
}
});
}
});
if (verification.allRequiredMatched()) {
realOptions = choiceToHere.or(realOptions);
}
}
return realOptions.thenOption(new Function<State<ConsumptionState>, Optional<UnifierWithUnconsumedStatements>>() {
@Override
public Optional<UnifierWithUnconsumedStatements> apply(State<ConsumptionState> consumptionState) {
if (ImmutableSet.copyOf(consumptionState.seenParameters()).containsAll(placeholder().requiredParameters())) {
Unifier resultUnifier = consumptionState.unifier().fork();
int nConsumedStatements = consumptionState.result().consumedStatements();
java.util.List<? extends StatementTree> remainingStatements = initState.unconsumedStatements().subList(nConsumedStatements, initState.unconsumedStatements().size());
UnifierWithUnconsumedStatements result = UnifierWithUnconsumedStatements.create(resultUnifier, remainingStatements);
List<JCStatement> impl = consumptionState.result().placeholderImplInReverseOrder().reverse();
ControlFlowVisitor.Result implFlow = ControlFlowVisitor.INSTANCE.visitStatements(impl);
if (implFlow == implementationFlow()) {
List<JCStatement> prevBinding = resultUnifier.getBinding(placeholder().blockKey());
if (prevBinding != null && prevBinding.toString().equals(impl.toString())) {
return Optional.of(result);
} else if (prevBinding == null) {
resultUnifier.putBinding(placeholder().blockKey(), impl);
return Optional.of(result);
}
}
}
return Optional.absent();
}
});
}
use of com.sun.tools.javac.tree.JCTree.JCStatement in project lombok by rzwitserloot.
the class JavacJavaUtilMapSingularizer method generateMethods.
@Override
public void generateMethods(SingularData data, JavacNode builderType, JCTree source, boolean fluent, boolean chain) {
if (useGuavaInstead(builderType)) {
guavaMapSingularizer.generateMethods(data, builderType, source, fluent, chain);
return;
}
JavacTreeMaker maker = builderType.getTreeMaker();
Symtab symbolTable = builderType.getSymbolTable();
JCExpression returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(symbolTable, CTC_VOID));
JCStatement returnStatement = chain ? maker.Return(maker.Ident(builderType.toName("this"))) : null;
generateSingularMethod(maker, returnType, returnStatement, data, builderType, source, fluent);
returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(symbolTable, CTC_VOID));
returnStatement = chain ? maker.Return(maker.Ident(builderType.toName("this"))) : null;
generatePluralMethod(maker, returnType, returnStatement, data, builderType, source, fluent);
returnType = chain ? cloneSelfType(builderType) : maker.Type(createVoidType(symbolTable, CTC_VOID));
returnStatement = chain ? maker.Return(maker.Ident(builderType.toName("this"))) : null;
generateClearMethod(maker, returnType, returnStatement, data, builderType, source);
}
Aggregations