-
Notifications
You must be signed in to change notification settings - Fork 126
Fix TargetPlatformPresentationReconciler: stop scanning past damage end #2284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vogella
wants to merge
2
commits into
eclipse-pde:master
Choose a base branch
from
vogella:full-qualified-access
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
...g/eclipse/pde/genericeditor/extension/tests/TargetPlatformPresentationReconcilerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2026 vogella GmbH and others | ||
| * | ||
| * This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License 2.0 | ||
| * which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Contributors: | ||
| * Lars Vogel - initial implementation | ||
| *******************************************************************************/ | ||
| package org.eclipse.pde.genericeditor.extension.tests; | ||
|
|
||
| import static org.junit.Assert.assertNotNull; | ||
|
|
||
| import org.eclipse.jface.text.Document; | ||
| import org.eclipse.jface.text.IDocument; | ||
| import org.eclipse.jface.text.IRegion; | ||
| import org.eclipse.jface.text.Region; | ||
| import org.eclipse.jface.text.TextPresentation; | ||
| import org.eclipse.jface.text.presentation.IPresentationRepairer; | ||
| import org.eclipse.pde.internal.genericeditor.target.extension.reconciler.presentation.TargetPlatformPresentationReconciler; | ||
| import org.junit.Test; | ||
|
|
||
| /** | ||
| * Tests for {@link TargetPlatformPresentationReconciler}. | ||
| * | ||
| * <p>The reconciler overrides {@code createPresentation} to scan from offset 0 | ||
| * so that multi-line rules (XML comments) are correctly recognised even when | ||
| * the damaged region is deep inside the document. These tests verify that the | ||
| * presentation is computed correctly for several representative document shapes | ||
| * and damage positions. | ||
| */ | ||
| public class TargetPlatformPresentationReconcilerTest { | ||
|
|
||
| /** Subclass that exposes the protected {@code createPresentation} for testing. */ | ||
| private static class TestableReconciler extends TargetPlatformPresentationReconciler { | ||
| TextPresentation createPresentation(IDocument document, IRegion damage) { | ||
| IPresentationRepairer repairer = getRepairer(IDocument.DEFAULT_CONTENT_TYPE); | ||
| if (repairer != null) { | ||
| repairer.setDocument(document); | ||
| } | ||
| return createPresentation(damage, document); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testCreatePresentationReturnsNonNullForSimpleDocument() { | ||
| TestableReconciler reconciler = new TestableReconciler(); | ||
| String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" //$NON-NLS-1$ | ||
| + "<target name=\"test\">\n" //$NON-NLS-1$ | ||
| + " <locations/>\n" //$NON-NLS-1$ | ||
| + "</target>\n"; //$NON-NLS-1$ | ||
| IDocument document = new Document(content); | ||
| IRegion damage = new Region(0, content.length()); | ||
|
|
||
| TextPresentation presentation = reconciler.createPresentation(document, damage); | ||
|
|
||
| assertNotNull("Expected a non-null TextPresentation for a simple document", presentation); //$NON-NLS-1$ | ||
| } | ||
|
|
||
| @Test | ||
| public void testCreatePresentationWithDamageSubsetOfDocument() { | ||
| TestableReconciler reconciler = new TestableReconciler(); | ||
| String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" //$NON-NLS-1$ | ||
| + "<target name=\"test\">\n" //$NON-NLS-1$ | ||
| + " <locations>\n" //$NON-NLS-1$ | ||
| + " </locations>\n" //$NON-NLS-1$ | ||
| + "</target>\n"; //$NON-NLS-1$ | ||
| IDocument document = new Document(content); | ||
| // Damage is only the last few characters, not the full document. | ||
| int damageOffset = content.indexOf("</target>"); //$NON-NLS-1$ | ||
| IRegion damage = new Region(damageOffset, content.length() - damageOffset); | ||
|
|
||
| TextPresentation presentation = reconciler.createPresentation(document, damage); | ||
|
|
||
| assertNotNull("Expected a non-null TextPresentation when damage covers only end of document", presentation); //$NON-NLS-1$ | ||
| } | ||
|
|
||
| @Test | ||
| public void testCreatePresentationWithMultilineCommentBeforeDamage() { | ||
| TestableReconciler reconciler = new TestableReconciler(); | ||
| // Multi-line comment appears before the damage region. The reconciler must | ||
| // scan from offset 0 so it can correctly determine the scanner state | ||
| // (comment vs normal) at the start of the damage. | ||
| String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" //$NON-NLS-1$ | ||
| + "<target name=\"test\">\n" //$NON-NLS-1$ | ||
| + "<!--\n" //$NON-NLS-1$ | ||
| + " multi-line comment\n" //$NON-NLS-1$ | ||
| + "-->\n" //$NON-NLS-1$ | ||
| + " <locations/>\n" //$NON-NLS-1$ | ||
| + "</target>\n"; //$NON-NLS-1$ | ||
| IDocument document = new Document(content); | ||
| // Damage is after the comment closes. | ||
| int damageOffset = content.indexOf("<locations/>"); //$NON-NLS-1$ | ||
| IRegion damage = new Region(damageOffset, content.length() - damageOffset); | ||
|
|
||
| TextPresentation presentation = reconciler.createPresentation(document, damage); | ||
|
|
||
| assertNotNull("Expected a non-null TextPresentation when a multi-line comment precedes the damage", //$NON-NLS-1$ | ||
| presentation); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCreatePresentationWithDamageInsideMultilineComment() { | ||
| TestableReconciler reconciler = new TestableReconciler(); | ||
| String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" //$NON-NLS-1$ | ||
| + "<target name=\"test\">\n" //$NON-NLS-1$ | ||
| + "<!--\n" //$NON-NLS-1$ | ||
| + " line one\n" //$NON-NLS-1$ | ||
| + " line two\n" //$NON-NLS-1$ | ||
| + "-->\n" //$NON-NLS-1$ | ||
| + "</target>\n"; //$NON-NLS-1$ | ||
| IDocument document = new Document(content); | ||
| // Damage is inside the comment body. | ||
| int damageOffset = content.indexOf(" line two"); //$NON-NLS-1$ | ||
| IRegion damage = new Region(damageOffset, " line two\n".length()); //$NON-NLS-1$ | ||
|
|
||
| TextPresentation presentation = reconciler.createPresentation(document, damage); | ||
|
|
||
| assertNotNull("Expected a non-null TextPresentation when damage is inside a multi-line comment", presentation); //$NON-NLS-1$ | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests only assert that
createPresentation(...)returns a non-nullTextPresentation, which would still pass even if the reconciler kept scanning to the end of the document (the original regression) or produced incorrect styling. To make this a meaningful regression test for the performance fix, consider installing a customIDocumentPartitioner(or similar hook) on theIDocumentthat records theoffset/lengthrequested byTextUtilities.computePartitioning, then assert that the computed length matchesdamage.getOffset() + damage.getLength()rather thandocument.getLength().