Involved in the biosynthesis of caffeine. Catalyzes the conversion of 7-methylxanthine to caffeine, likely via theobromine as an intermediate. S-adenosyl-L-methionine + theobromine = caffeine + H(+) + S-adenosyl-L-homocysteine 1,7-dimethylxanthine + S-adenosyl-L-methionine = caffeine + H(+) + S-adenosyl-L-homocysteine 7-methylxanthine + S-adenosyl-L-methionine = H(+) + S-adenosyl-L-homocysteine + theobromine Binds 1 Mg(2+) ion per subunit. Alkaloid biosynthesis. Highly expressed in developing endosperm and immature fruits (grains). Detected in young leaves and flower buds, but not in mature fruits. Tobacco plants (Nicotiana tabacum cv. Xanthi) expressing CaXMT1, CaMXMT1 and CaDXMT1 accumulate caffeine and become less appetant and toxic for caterpillars cutworms (Spodoptera litura). Caffeine also stimulates endogenous defense mechanisms against other pathogens (e.g. tobacco mosaic virus and Pseudomonas syringae) by triggering the expression of defense-related genes. Belongs to the methyltransferase superfamily. Type-7 methyltransferase family.