# US 12,182,555 B2 · Adapting existing source code snippets to new contexts

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 12,182,555 B2
- Document ID: US12182555B2
- Status: Granted
- Kind: B2
- Application number: 18/379,315
- Filed: 2023-10-12
- Published: 2024-02-01
- Granted: 2024-12-31
- Earliest claimed: 2021-01-27
- Assignees: Google Inc.
- Applicants: Google LLC
- Inventors: Qianyu Zhang; Bin Ni; Rishabh Singh; Olivia Hatalsky
- Web page: https://patentgrep.com/patent/US12182555B2

## CPC

- G06F 8/447: {Target code generation}
- G06F 8/30: Creation or generation of source code
- G06F 8/33: Intelligent editors
- G06F 8/34: Graphical or visual programming
- G06F 8/36: Software reuse
- G06F 8/51: Source to source
- G06F 8/71: Version control (security arrangements therefor G06F21/57); Configuration management
- G06F 16/00: Information retrieval; Database structures therefor; File system structures therefor
- G06N 3/044: Recurrent networks, e.g. Hopfield networks
- G06N 3/0442: characterised by memory or gating, e.g. long short-term memory [LSTM] or gated recurrent units [GRU]
- G06N 3/0455: Auto-encoder networks; Encoder-decoder networks
- G06N 3/084: Backpropagation, e.g. using gradient descent
- G06F 16/2425: {Iterative querying; Query formulation based on the results of a preceding query}
- G06N 3/045: Combinations of networks
- G06N 3/088: Non-supervised learning, e.g. competitive learning
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)
- G06N: COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS

## Abstract

Implementations are described herein for adapting existing source code snippets to new contexts. In various implementations, a command may be detected to incorporate an existing source code snippet into destination source code. An embedding may be generated based on the existing source code snippet, e.g., by processing the existing source code snippet using an encoder. The destination source code may be processed to identify one or more decoder constraints. Subject to the one or more decoder constraints, the embedding may be processed using a decoder to generate a new version of the existing source code snippet that is adapted to the destination source code.

## Claims

### Claim 1

A method implemented using one or more processors, comprising:
detecting, at an integrated development environment (IDE), a paste command to incorporate an existing source code snippet into destination source code;
assembling an input for a transformer network that includes first data indicative of the existing source code snippet, second data indicative of a first portion of the destination source code that would precede the existing source code snippet, and third data indicative of a second portion of the destination source code that would follow the existing source code snippet;
processing the input using the transformer network to generate a new version of the existing source code snippet adapted to a context of the destination source code, wherein the first and second portions of the destination source code condition the transformer to the context of the destination source code; and
causing the IDE to render visual output indicative of the new version of the existing source code snippet.

### Claim 2 (depends on 1)

The method of claim 1, wherein the existing source code snippet includes a function call, and the processing includes generating glue code to adapt the function call to the destination source code.

### Claim 3 (depends on 1)

The method of claim 1, wherein the new version of the existing source code snippet includes function names and variable names that are adapted to the destination source code.

### Claim 4 (depends on 1)

The method of claim 1, wherein the first data, second data, and third data comprise raw source code.

### Claim 5

A method implemented using one or more processors, comprising:
detecting, at an integrated development environment (IDE), a command to incorporate an existing source code snippet into destination source code;
assembling an input for a transformer network that includes first data indicative of the existing source code snippet, second data indicative of a first portion of the destination source code that would precede the existing source code snippet, and third data indicative of a second portion of the destination source code that would follow the existing source code snippet;
processing the input using the transformer network to generate a new version of the existing source code snippet adapted to a context of the destination source code, wherein the first and second portions of the destination source code condition the transformer to the context of the destination source code; and
causing the IDE to render visual output indicative of the new version of the existing source code snippet;
wherein the command comprises a command to drag-and-drop a graphical element that includes the existing source code snippet into the location within the destination source code.

### Claim 6

A method implemented using one or more processors, comprising:
detecting, at an integrated development environment (IDE), a command to incorporate an existing source code snippet into destination source code;
assembling an input for a transformer network that includes first data indicative of the existing source code snippet, second data indicative of a first portion of the destination source code that would precede the existing source code snippet, and third data indicative of a second portion of the destination source code that would follow the existing source code snippet;
processing the input using the transformer network to generate a new version of the existing source code snippet adapted to a context of the destination source code, wherein the first and second portions of the destination source code condition the transformer to the context of the destination source code; and
causing the IDE to render visual output indicative of the new version of the existing source code snippet;
wherein the first data, second data, and third data comprise, respectively, a first abstract syntax tree (AST) generated from the existing source code snippet, a second AST generated from the first portion of the destination source code, and a third AST generated from the second portion of the destination source code.

### Claim 7

A system comprising one or more processors and memory storing instructions that, in response to execution by the one or more processors, cause the one or more processors to:
detect, at an integrated development environment (IDE), a paste command to incorporate an existing source code snippet into destination source code;
assemble an input for a transformer network that includes first data indicative of the existing source code snippet, second data indicative of a first portion of the destination source code that would precede the existing source code snippet, and third data indicative of a second portion of the destination source code that would follow the existing source code snippet;
process the input using the transformer network to generate a new version of the existing source code snippet adapted to a context of the destination source code, wherein the first and second portions of the destination source code condition the transformer to the context of the destination source code; and
cause the IDE to render visual output indicative of the new version of the existing source code snippet.

### Claim 8 (depends on 7)

The system of claim 7, wherein the existing source code snippet includes a function call, and the instructions to process include instructions to generate glue code to adapt the function call to the destination source code.

### Claim 9 (depends on 7)

The system of claim 7, wherein the new version of the existing source code snippet includes function names and variable names that are adapted to the destination source code.

### Claim 10 (depends on 7)

The system of claim 7, wherein the first data, second data, and third data comprise raw source code.

### Claim 11

A system comprising one or more processors and memory storing instructions that, in response to execution by the one or more processors, cause the one or more processors to:
detect, at an integrated development environment (IDE), a command to incorporate an existing source code snippet into destination source code;
assemble an input for a transformer network that includes first data indicative of the existing source code snippet, second data indicative of a first portion of the destination source code that would precede the existing source code snippet, and third data indicative of a second portion of the destination source code that would follow the existing source code snippet;
process the input using the transformer network to generate a new version of the existing source code snippet adapted to a context of the destination source code, wherein the first and second portions of the destination source code condition the transformer to the context of the destination source code; and
cause the IDE to render visual output indicative of the new version of the existing source code snippet;
wherein the command comprises a command to drag-and-drop a graphical element that includes the existing source code snippet into the location within the destination source code.

### Claim 12

A system comprising one or more processors and memory storing instructions that, in response to execution by the one or more processors, cause the one or more processors to:
detect, at an integrated development environment (IDE), a command to incorporate an existing source code snippet into destination source code;
assemble an input for a transformer network that includes first data indicative of the existing source code snippet, second data indicative of a first portion of the destination source code that would precede the existing source code snippet, and third data indicative of a second portion of the destination source code that would follow the existing source code snippet;
process the input using the transformer network to generate a new version of the existing source code snippet adapted to a context of the destination source code, wherein the first and second portions of the destination source code condition the transformer to the context of the destination source code; and
cause the IDE to render visual output indicative of the new version of the existing source code snippet;
wherein the first data, second data, and third data comprise, respectively, a first abstract syntax tree (AST) generated from the existing source code snippet, a second AST generated from the first portion of the destination source code, and a third AST generated from the second portion of the destination source code.

### Claim 13

At least one non-transitory computer-readable medium comprising instructions that, in response to execution by one or more processors, cause the one or more processors to:
detect, at an integrated development environment (IDE), a paste command to incorporate an existing source code snippet into destination source code;
assemble an input for a transformer network that includes first data indicative of the existing source code snippet, second data indicative of a first portion of the destination source code that would precede the existing source code snippet, and third data indicative of a second portion of the destination source code that would follow the existing source code snippet;
process the input using the transformer network to generate a new version of the existing source code snippet adapted to a context of the destination source code, wherein the first and second portions of the destination source code condition the transformer to the context of the destination source code; and
cause the IDE to render visual output indicative of the new version of the existing source code snippet.

### Claim 14 (depends on 13)

The at least one non-transitory computer-readable medium of claim 13, wherein the existing source code snippet includes a function call, and the instructions to process include instructions to generate glue code to adapt the function call to the destination source code.

### Claim 15 (depends on 13)

The at least one non-transitory computer-readable medium of claim 13, wherein the new version of the existing source code snippet includes function names and variable names that are adapted to the destination source code.

### Claim 16 (depends on 13)

The at least one non-transitory computer-readable medium of claim 13, wherein the first data, second data, and third data comprise raw source code.

### Claim 17

At least one non-transitory computer-readable medium comprising instructions that, in response to execution by one or more processors, cause the one or more processors to:
detect, at an integrated development environment (IDE), a command to incorporate an existing source code snippet into destination source code;
assemble an input for a transformer network that includes first data indicative of the existing source code snippet, second data indicative of a first portion of the destination source code that would precede the existing source code snippet, and third data indicative of a second portion of the destination source code that would follow the existing source code snippet;
process the input using the transformer network to generate a new version of the existing source code snippet adapted to a context of the destination source code, wherein the first and second portions of the destination source code condition the transformer to the context of the destination source code; and
cause the IDE to render visual output indicative of the new version of the existing source code snippet;
wherein the command comprises a command to drag-and-drop a graphical element that includes the existing source code snippet into the location within the destination source code.
