Skip to content

Replace TemplateContextType.isInContext deprecated method - #545

Merged
pq merged 1 commit into
flutter:mainfrom
juan-mora-google:chore/jmora/replace-template-context-type-deprecated-override
Jul 30, 2026
Merged

Replace TemplateContextType.isInContext deprecated method#545
pq merged 1 commit into
flutter:mainfrom
juan-mora-google:chore/jmora/replace-template-context-type-deprecated-override

Conversation

@juan-mora-google

Copy link
Copy Markdown
Contributor

Description

Replaced deprecated method isInContext from TemplateContextType class in DartTemplateContextType.java file

Note: Work of this PR was originally here, but it was closed due to CLA problems.

Testing steps:

1. Run the IDE in Sandbox mode with the plugin
2. Prepare a Live Template for testing
Inside the Sandbox IDE window:

  • Go to the IDE settings (Settings / Preferences).
  • Navigate to Editor > Live Templates.
  • Click the + (Add) button and select Live Template.
  • Give it an abbreviation (e.g., dtest) and some template code (e.g., print('hello');).
  • At the bottom, you will see a red warning saying "No applicable contexts". Click Define.
  • Find Dart option (which matches the contextId registered in the plugin.xml) and check it.
  • Apply.

3. Test the "Happy Path" (It should work)

  • Create a .dart file inside the Sandbox IDE
  • Start typing the abbreviation previously defined (dtest).
  • The IDE should suggest the template. If you press Tab, the code will expand. This confirms that file.getLanguage() instanceof DartLanguage evaluated to true.

4. Test the "Negative Path" (It should not work)

  • Create a file with a different extension in the same project, for example test.java or test.txt.
  • Attempt to type the abbreviation (dtest).
  • The IDE should not suggest or expand the template, since the condition requiring it to be a DartLanguage file is not met.

Review the contribution guidelines below:

  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
  • I've included the required information in the description above.
  • I've updated CHANGELOG.md if appropriate (i.e. user-facing change) (N/A)
Contribution guidelines:
  • See the Flutter organization contributor guide for general expectations for PRs.
  • Larger or significant changes should be discussed in an issue before creating a PR.
  • Dart contributions to our repos should follow the Dart style guide and use
    dart format.
  • Java and Kotlin contributions should strive to follow Java and Kotlin best
    practices (discussion).

@google-cla

google-cla Bot commented Jul 28, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates DartTemplateContextType.java to override the newer signature of isInContext that accepts a TemplateActionContext instead of PsiFile and int offset. It extracts the file and start offset from the context object to perform the language and element checks. There are no review comments, so I have no feedback to provide.

@pq

pq commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

The testing steps are great. Thanks!

@pq
pq merged commit 28da173 into flutter:main Jul 30, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants