-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement provider for sticky lines in JAVA
- Loading branch information
1 parent
cac5317
commit 9e4565a
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
64 changes: 64 additions & 0 deletions
64
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/StickyLinesProviderJava.java
This file contains 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,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(); | ||
} | ||
|
||
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; | ||
} | ||
|
||
} |