@SuppressWarnings("unchecked") // essentially depends on T being a superclass of JCExpression @Override public <T extends JCTree> T copy(T t, Void v) { if (t instanceof BinaryTree || t instanceof UnaryTree || t instanceof ConditionalExpressionTree) { return super.copy(t, v); } else { return (T) defaultNegation(t); } }
@Override public JCTree visitIdentifier(IdentifierTree node, Inliner inliner) { if (node instanceof PlaceholderParamIdent) { try { return arguments.get(((PlaceholderParamIdent) node).param).inline(inliner); } catch (CouldNotResolveImportException e) { throw new UncheckedCouldNotResolveImportException(e); } } else { return super.visitIdentifier(node, inliner); } } };
@Override public void visitReference(JCMemberReference tree) { //perform arity-based check Env<AttrContext> localEnv = env.dup(tree); JCExpression exprTree = (JCExpression)attribSpeculative(tree.getQualifierExpression(), localEnv, attr.memberReferenceQualifierResult(tree)); JCMemberReference mref2 = new TreeCopier<Void>(make).copy(tree); mref2.expr = exprTree; Symbol res = rs.getMemberReference(tree, localEnv, mref2, exprTree.type, tree.name); tree.sym = res; if (res.kind >= Kinds.ERRONEOUS || res.type.hasTag(FORALL) || (res.flags() & Flags.VARARGS) != 0 || (TreeInfo.isStaticSelector(exprTree, tree.name.table.names) && exprTree.type.isRaw())) { tree.overloadKind = JCMemberReference.OverloadKind.OVERLOADED; } else { tree.overloadKind = JCMemberReference.OverloadKind.UNOVERLOADED; } //a method reference is always a poly expression result = ArgumentExpressionKind.POLY; }
@Override public JCTree visitVariable(VariableTree node, Void p) { JCVariableDecl original = node instanceof JCVariableDecl ? (JCVariableDecl) node : null; JCVariableDecl copy = (JCVariableDecl) super.visitVariable(node, p); if (original == null) return copy; copy.sym = original.sym; if (copy.sym != null) copy.type = original.type; if (copy.type != null) { boolean wipeSymAndType = copy.type.isErroneous(); if (!wipeSymAndType) { TypeTag typeTag = TypeTag.typeTag(copy.type); wipeSymAndType = (CTC_NONE.equals(typeTag) || CTC_ERROR.equals(typeTag) || CTC_UNKNOWN.equals(typeTag) || CTC_UNDETVAR.equals(typeTag)); } if (wipeSymAndType) { copy.sym = null; copy.type = null; } } return copy; }
@Override public void visitReference(JCMemberReference tree) { //perform arity-based check Env<AttrContext> localEnv = env.dup(tree); JCExpression exprTree = (JCExpression)attribSpeculative(tree.getQualifierExpression(), localEnv, attr.memberReferenceQualifierResult(tree)); JCMemberReference mref2 = new TreeCopier<Void>(make).copy(tree); mref2.expr = exprTree; Symbol res = rs.getMemberReference(tree, localEnv, mref2, exprTree.type, tree.name); tree.sym = res; if (res.kind >= Kinds.ERRONEOUS || res.type.hasTag(FORALL) || (res.flags() & Flags.VARARGS) != 0 || (TreeInfo.isStaticSelector(exprTree, tree.name.table.names) && exprTree.type.isRaw())) { tree.overloadKind = JCMemberReference.OverloadKind.OVERLOADED; } else { tree.overloadKind = JCMemberReference.OverloadKind.UNOVERLOADED; } //a method reference is always a poly expression result = ArgumentExpressionKind.POLY; }
@Override public <T extends JCTree> T copy(T tree, Inliner inliner) { if (tree == null) { return null; } T result = super.copy(tree, inliner); if (result.toString().equals(tree.toString())) { return tree; } else { return result; } }
final JCTree newTree = new TreeCopier<Object>(make).copy(tree); Env<AttrContext> speculativeEnv = env.dup(newTree, env.info.dup(env.info.scope.dupUnshared())); speculativeEnv.info.scope.owner = env.info.scope.owner;
@Override public JCTree visitIdentifier(IdentifierTree node, Inliner inliner) { if (node instanceof PlaceholderParamIdent) { try { return arguments.get(((PlaceholderParamIdent) node).param).inline(inliner); } catch (CouldNotResolveImportException e) { throw new UncheckedCouldNotResolveImportException(e); } } else { return super.visitIdentifier(node, inliner); } } };
@Override public JCExpression inline(Inliner inliner) throws CouldNotResolveImportException { /* * Copy the original source bound to the placeholder, except anywhere we matched a placeholder * parameter, replace that with the corresponding expression in this invocation. */ try { return copier(arguments(), inliner) .copy(inliner.getBinding(placeholder().exprKey()), inliner); } catch (UncheckedCouldNotResolveImportException e) { throw e.getCause(); } }
final JCTree newTree = new TreeCopier<Object>(make).copy(tree); Env<AttrContext> speculativeEnv = env.dup(newTree, env.info.dup(env.info.scope.dupUnshared())); speculativeEnv.info.scope.owner = env.info.scope.owner;
@Override public List<JCStatement> inlineStatements(final Inliner inliner) throws CouldNotResolveImportException { try { Optional<List<JCStatement>> binding = inliner.getOptionalBinding(placeholder().blockKey()); // If a placeholder was used as an expression binding in the @BeforeTemplate, // and as a bare statement or as a return in the @AfterTemplate, we may need to convert. Optional<JCExpression> exprBinding = inliner.getOptionalBinding(placeholder().exprKey()); binding = binding.or( exprBinding.transform( (JCExpression expr) -> { switch (implementationFlow()) { case NEVER_EXITS: return List.of((JCStatement) inliner.maker().Exec(expr)); case ALWAYS_RETURNS: return List.of((JCStatement) inliner.maker().Return(expr)); default: throw new AssertionError(); } })); return UPlaceholderExpression.copier(arguments(), inliner).copy(binding.get(), inliner); } catch (UncheckedCouldNotResolveImportException e) { throw e.getCause(); } } }
boolean canLambdaBodyCompleteNormally(JCLambda tree) { JCLambda newTree = new TreeCopier<>(make).copy(tree);
JCTree inlineBody(Inliner inliner) throws CouldNotResolveImportException { if (getBody() instanceof UPlaceholderExpression) { UPlaceholderExpression body = (UPlaceholderExpression) getBody(); Optional<List<JCStatement>> blockBinding = inliner.getOptionalBinding(body.placeholder().blockKey()); if (blockBinding.isPresent()) { // this lambda is of the form args -> blockPlaceholder(); List<JCStatement> blockInlined = UPlaceholderExpression.copier(body.arguments(), inliner) .copy(blockBinding.get(), inliner); if (blockInlined.size() == 1) { if (blockInlined.get(0) instanceof JCReturn) { return ((JCReturn) blockInlined.get(0)).getExpression(); } else if (blockInlined.get(0) instanceof JCExpressionStatement) { return ((JCExpressionStatement) blockInlined.get(0)).getExpression(); } } return inliner.maker().Block(0, blockInlined); } } return getBody().inline(inliner); }
argtypes.append(Type.noType); JCMemberReference mref2 = new TreeCopier<Void>(make).copy(tree); mref2.expr = exprTree; Symbol lookupSym =
public <T extends JCTree> T copy(T t, JCTree leaf) { T t2 = super.copy(t, leaf); if (t == leaf) leafCopy = t2; return t2; } }
argtypes.append(Type.noType); JCMemberReference mref2 = new TreeCopier<Void>(make).copy(tree); mref2.expr = exprTree; Symbol lookupSym =
@Override public <T extends JCTree> T copy(T t, JCTree leaf) { T t2 = super.copy(t, leaf); if (t == leaf) leafCopy = t2; return t2; } }
public JCTree visitMethod(MethodTree node, P p) { JCMethodDecl t = (JCMethodDecl) node; JCModifiers mods = copy(t.mods, p); JCExpression restype = copy(t.restype, p); List<JCTypeParameter> typarams = copy(t.typarams, p); List<JCVariableDecl> params = copy(t.params, p); JCVariableDecl recvparam = copy(t.recvparam, p); List<JCExpression> thrown = copy(t.thrown, p); JCBlock body = copy(t.body, p); JCExpression defaultValue = copy(t.defaultValue, p); return M.at(t.pos).MethodDef(mods, t.name, restype, typarams, recvparam, params, thrown, body, defaultValue); }
public JCTree visitMethod(MethodTree node, P p) { JCMethodDecl t = (JCMethodDecl) node; JCModifiers mods = copy(t.mods, p); JCExpression restype = copy(t.restype, p); List<JCTypeParameter> typarams = copy(t.typarams, p); List<JCVariableDecl> params = copy(t.params, p); List<JCExpression> thrown = copy(t.thrown, p); JCBlock body = copy(t.body, p); JCExpression defaultValue = copy(t.defaultValue, p); return M.at(t.pos).MethodDef(mods, t.name, restype, typarams, params, thrown, body, defaultValue); }
public JCTree visitMethod(MethodTree node, P p) { JCMethodDecl t = (JCMethodDecl) node; JCModifiers mods = copy(t.mods, p); JCExpression restype = copy(t.restype, p); List<JCTypeParameter> typarams = copy(t.typarams, p); List<JCVariableDecl> params = copy(t.params, p); List<JCExpression> thrown = copy(t.thrown, p); JCBlock body = copy(t.body, p); JCExpression defaultValue = copy(t.defaultValue, p); return M.at(t.pos).MethodDef(mods, t.name, restype, typarams, params, thrown, body, defaultValue); }