-
Notifications
You must be signed in to change notification settings - Fork 251
Fix #3405 Fix incorrect reuse of code mining annotations with mismatched types #3416
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
Merged
tobiasmelcher
merged 1 commit into
eclipse-platform:master
from
travkin79:feature/patch-3405-code-minings
Oct 28, 2025
Merged
Changes from all commits
Commits
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
88 changes: 88 additions & 0 deletions
88
....examples/src/org/eclipse/jface/text/examples/codemining/ReferenceCodeMiningProvider.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,88 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2025, Advantest Europe GmbH | ||
| * | ||
| * 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: | ||
| * Dietrich Travkin <dietrich.travkin@solunar.de> - Fix code mining redrawing - Issue 3405 | ||
| * | ||
| *******************************************************************************/ | ||
| package org.eclipse.jface.text.examples.codemining; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| import org.eclipse.core.runtime.IProgressMonitor; | ||
| import org.eclipse.jface.text.BadLocationException; | ||
| import org.eclipse.jface.text.IDocument; | ||
| import org.eclipse.jface.text.ITextViewer; | ||
| import org.eclipse.jface.text.codemining.AbstractCodeMiningProvider; | ||
| import org.eclipse.jface.text.codemining.ICodeMining; | ||
|
|
||
| public class ReferenceCodeMiningProvider extends AbstractCodeMiningProvider { | ||
|
|
||
| private static final String REGEX_REF = "\\[REF-X\\]|\\[REF-Y\\]"; | ||
| private static final Pattern REGEX_PATTERN = Pattern.compile(REGEX_REF); | ||
|
|
||
| private AtomicReference<Boolean> useInLineCodeMinings; | ||
|
|
||
| public ReferenceCodeMiningProvider(AtomicReference<Boolean> useInLineCodeMinings) { | ||
| this.useInLineCodeMinings = useInLineCodeMinings; | ||
| } | ||
|
|
||
| @Override | ||
| public CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextViewer viewer, | ||
| IProgressMonitor monitor) { | ||
| return CompletableFuture.supplyAsync(() -> { | ||
| IDocument document = viewer.getDocument(); | ||
|
|
||
| if (document == null) { | ||
| return Collections.emptyList(); | ||
| } | ||
|
|
||
| return createCodeMiningsFor(document); | ||
| }); | ||
| } | ||
|
|
||
| List<ICodeMining> createCodeMiningsFor(IDocument document) { | ||
| String documentContent = document.get(); | ||
| List<ICodeMining> minings = new ArrayList<>(); | ||
|
|
||
| Matcher regexMatcher = REGEX_PATTERN.matcher(documentContent); | ||
| while (regexMatcher.find()) { | ||
| String matchedText = regexMatcher.group(); | ||
| int startIndex = regexMatcher.start(); | ||
|
|
||
| String title = matchedText.endsWith("X]") ? "Plugging into Eclipse" | ||
| : "Building commercial quality plug-ins"; | ||
|
|
||
| if (useInLineCodeMinings.get()) { | ||
| minings.add(new ReferenceInLineCodeMining(title + ": ", startIndex, document, this)); | ||
| } else { | ||
| try { | ||
| int offset = startIndex; | ||
| int line = document.getLineOfOffset(offset); | ||
| int lineOffset = document.getLineOffset(line); | ||
|
|
||
| minings.add(new ReferenceLineHeaderCodeMining(title, line, offset - lineOffset, title.length(), | ||
| document, this)); | ||
| } catch (BadLocationException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return minings; | ||
| } | ||
|
|
||
| } |
30 changes: 30 additions & 0 deletions
30
...xt.examples/src/org/eclipse/jface/text/examples/codemining/ReferenceInLineCodeMining.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,30 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2025, Advantest Europe GmbH | ||
| * | ||
| * 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: | ||
| * Dietrich Travkin <dietrich.travkin@solunar.de> - Fix code mining redrawing - Issue 3405 | ||
| * | ||
| *******************************************************************************/ | ||
| package org.eclipse.jface.text.examples.codemining; | ||
|
|
||
| import org.eclipse.jface.text.IDocument; | ||
| import org.eclipse.jface.text.Position; | ||
| import org.eclipse.jface.text.codemining.ICodeMiningProvider; | ||
| import org.eclipse.jface.text.codemining.LineContentCodeMining; | ||
|
|
||
| public class ReferenceInLineCodeMining extends LineContentCodeMining { | ||
|
|
||
| public ReferenceInLineCodeMining(String label, int positionOffset, IDocument document, | ||
| ICodeMiningProvider provider) { | ||
| super(new Position(positionOffset, 1), true, provider); | ||
| this.setLabel(label); | ||
| } | ||
|
|
||
| } |
39 changes: 39 additions & 0 deletions
39
...xamples/src/org/eclipse/jface/text/examples/codemining/ReferenceLineHeaderCodeMining.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,39 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2025, Advantest Europe GmbH | ||
| * | ||
| * 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: | ||
| * Dietrich Travkin <dietrich.travkin@solunar.de> - Fix code mining redrawing - Issue 3405 | ||
| * | ||
| *******************************************************************************/ | ||
| package org.eclipse.jface.text.examples.codemining; | ||
|
|
||
| import org.eclipse.jface.text.BadLocationException; | ||
| import org.eclipse.jface.text.IDocument; | ||
| import org.eclipse.jface.text.Position; | ||
| import org.eclipse.jface.text.codemining.ICodeMiningProvider; | ||
| import org.eclipse.jface.text.codemining.LineHeaderCodeMining; | ||
| import org.eclipse.jface.text.source.inlined.Positions; | ||
|
|
||
| public class ReferenceLineHeaderCodeMining extends LineHeaderCodeMining { | ||
|
|
||
| public ReferenceLineHeaderCodeMining(String label, int beforeLineNumber, int columnInLine, int length, | ||
| IDocument document, ICodeMiningProvider provider) throws BadLocationException { | ||
| super(calculatePosition(beforeLineNumber, columnInLine, document), provider, null); | ||
| this.setLabel(label); | ||
| } | ||
|
|
||
| private static Position calculatePosition(int beforeLineNumber, int columnInLine, IDocument document) | ||
| throws BadLocationException { | ||
| Position pos = Positions.of(beforeLineNumber, document, true); | ||
| pos.setOffset(pos.offset + columnInLine); | ||
| return pos; | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.