Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions org.eclipse.jdt.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7851,4 +7851,18 @@
file-extensions="class without source">
</file-association>
</extension>
<extension
point="org.eclipse.ui.editors.stickyLinesProviders">
<stickyLinesProvider
class="org.eclipse.jdt.internal.ui.javaeditor.StickyLinesProviderJava"
id="org.eclipse.jdt.internal.ui.StickyLinesProviderJava">
<enabledWhen>
<and>
<with variable="editor">
<instanceof value="org.eclipse.jdt.internal.ui.javaeditor.JavaEditor"/>
</with>
</and>
</enabledWhen>
</stickyLinesProvider>
</extension>
</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*******************************************************************************
* Copyright (c) 2024 SAP SE.
*
* 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:
* SAP SE - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.ui.javaeditor;

import java.util.LinkedList;
import java.util.List;

import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.source.ISourceViewer;

import org.eclipse.ui.texteditor.stickyscroll.IStickyLine;
import org.eclipse.ui.texteditor.stickyscroll.IStickyLinesProvider;
import org.eclipse.ui.texteditor.stickyscroll.StickyLine;

import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.ISourceReference;
import org.eclipse.jdt.core.JavaModelException;

public class StickyLinesProviderJava implements IStickyLinesProvider {

@Override
public List<IStickyLine> getStickyLines(ISourceViewer sourceViewer, int lineNumber, StickyLinesProperties properties) {
LinkedList<IStickyLine> stickyLines= new LinkedList<>();
JavaEditor javaEditor= (JavaEditor) properties.editor();

IJavaElement element= null;
try {
element= javaEditor.getElementAt(sourceViewer.getDocument().getLineOffset(lineNumber));
} catch (BadLocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Comment on lines +42 to +43
Copy link
Contributor

@danthe1st danthe1st May 11, 2025

Choose a reason for hiding this comment

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

Just commenting as someone interested in this feature: I guess you plan to change the error handling to write the exception to the Error Log or similar?

Copy link
Contributor

Choose a reason for hiding this comment

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

Will do

}

while (element != null) {
if (element.getElementType() == IJavaElement.METHOD || element.getElementType() == IJavaElement.TYPE) {
try {
ISourceRange sourceRange= ((ISourceReference) element).getNameRange();
int offset= sourceRange.getOffset();
int stickyLineNumber= sourceViewer.getDocument().getLineOfOffset(offset);
stickyLines.addFirst(new StickyLine(stickyLineNumber, sourceViewer));
} catch (JavaModelException | BadLocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
element= element.getParent();
}

return stickyLines;
}

}
Loading