GitLab will be shut down on June 25 to move to a new facility. https://www.eclipsestatus.io/incidents/5ffy27gwcbx7

Commit c8f9d90a authored by Miklos Magyari's avatar Miklos Magyari Committed by Adam Knapp
Browse files

Initial code peek and hover support for the ASN1 editor (issue #480)

parent 4187b216
......@@ -570,6 +570,12 @@
id="org.eclipse.titan.designer.editors.asn1editor.RenameRefactoring"
label="Rename refactoring">
</command>
<command
commandId="org.eclipse.titan.designer.editors.ttcn3editor.PeekDeclaration"
icon="icons/call_hierarchy_search_history.gif"
id="org.eclipse.titan.designer.editors.asn1editor.PeekDeclaration"
label="Peek Declaration">
</command>
</menuContribution>
<menuContribution
......@@ -1447,6 +1453,12 @@
contextId="org.eclipse.titan.designer.editors.TTCN3PPEditorScope"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="CTRL+F3" />
<key
commandId="org.eclipse.titan.designer.editors.ttcn3editor.PeekDeclaration"
contextId="org.eclipse.titan.designer.editors.ASN1EditorScope"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="F9">
</key>
</extension>
<extension point="org.eclipse.ui.contexts">
<context description="%context.editingText.description.testtest"
......
/******************************************************************************
* Copyright (c) 2000-2021 Ericsson Telecom AB
* Copyright (c) 2000-2022 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
......@@ -14,9 +14,11 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.SWT;
import org.eclipse.titan.designer.Activator;
import org.eclipse.titan.designer.AST.ASTVisitor;
import org.eclipse.titan.designer.AST.Assignment;
import org.eclipse.titan.designer.AST.DocumentComment;
import org.eclipse.titan.designer.AST.IReferenceChain;
import org.eclipse.titan.designer.AST.Identifier;
import org.eclipse.titan.designer.AST.Identifier.Identifier_type;
......@@ -25,16 +27,22 @@ import org.eclipse.titan.designer.AST.Module;
import org.eclipse.titan.designer.AST.ReferenceFinder;
import org.eclipse.titan.designer.AST.ReferenceFinder.Hit;
import org.eclipse.titan.designer.AST.Scope;
import org.eclipse.titan.designer.AST.TTCN3.definitions.ICommentable;
import org.eclipse.titan.designer.editors.controls.HoverContentType;
import org.eclipse.titan.designer.editors.controls.PeekSource;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
import org.eclipse.titan.designer.preferences.PreferenceConstants;
import org.eclipse.titan.designer.productUtilities.ProductConstants;
import org.eclipse.ui.IEditorPart;
/**
* Abstract class to represent ASN.1 assignments.
*
* @author Kristof Szabados
* @author Miklos Magyari
*/
public abstract class ASN1Assignment extends Assignment {
public abstract class ASN1Assignment extends Assignment implements ICommentable {
private static final String NOTPARAMETERIZEDASSIGNMENT = "`{0}'' is not a parameterized assignment";
public static final String UNREACHABLE = "The identifier `{0}'' is not reachable from TTCN-3";
......@@ -234,4 +242,47 @@ public abstract class ASN1Assignment extends Assignment {
return true;
}
@Override
public Ttcn3HoverContent getHoverContent(IEditorPart editor) {
Ttcn3HoverContent hoverContent = new Ttcn3HoverContent();
if (editor != null) {
PeekSource.addStyledSource(PeekSource.getPeekSource(editor, getLocation()), hoverContent);
}
hoverContent.addIcon(getOutlineIcon());
hoverContent.addText("ASN1 assignment").addText(" ").addStyledText(identifier.getDisplayName(), SWT.BOLD);
hoverContent.closeHeader();
hoverContent.addContent(HoverContentType.INFO);
return hoverContent;
}
@Override
public DocumentComment getDocumentComment() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean hasDocumentComment() {
// TODO Auto-generated method stub
return false;
}
@Override
public DocumentComment parseDocumentComment() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setDocumentComment(DocumentComment docComment) {
// TODO Auto-generated method stub
}
@Override
public String generateDocComment(String indentation) {
// TODO Auto-generated method stub
return null;
}
}
/******************************************************************************
* Copyright (c) 2000-2021 Ericsson Telecom AB
* Copyright (c) 2000-2022 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
......@@ -7,15 +7,36 @@
******************************************************************************/
package org.eclipse.titan.designer.editors.asn1editor;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextHoverExtension;
import org.eclipse.jface.text.ITextHoverExtension2;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.titan.designer.AST.Module;
import org.eclipse.titan.designer.AST.TTCN3.definitions.ICommentable;
import org.eclipse.titan.designer.declarationsearch.Declaration;
import org.eclipse.titan.designer.declarationsearch.IdentifierFinderVisitor;
import org.eclipse.titan.designer.editors.BaseTextHover;
import org.eclipse.titan.designer.editors.IReferenceParser;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverInfoControl;
import org.eclipse.titan.designer.parsers.GlobalParser;
import org.eclipse.titan.designer.parsers.ProjectSourceParser;
import org.eclipse.titan.designer.preferences.PreferenceConstants;
import org.eclipse.titan.designer.productUtilities.ProductConstants;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.editors.text.EditorsUI;
/**
* @author Kristof Szabados
* @author Miklos Magyari
* */
public final class TextHover extends BaseTextHover {
public final class TextHover extends BaseTextHover implements ITextHoverExtension, ITextHoverExtension2 {
private final ISourceViewer sourceViewer;
private final IEditorPart editor;
......@@ -38,4 +59,67 @@ public final class TextHover extends BaseTextHover {
protected IReferenceParser getReferenceParser() {
return new ASN1ReferenceParser();
}
/**
* ASN1 editor hover support
*
* @param textViewer
* @param hoverRegion
* @return
*/
@Override
public Object getHoverInfo2(final ITextViewer textViewer, final IRegion hoverRegion) {
final boolean enableCodeHoverPopups = Platform.getPreferencesService().getBoolean(
ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.ENABLE_CODE_HOVER_POPUPS, true, null);
if (! enableCodeHoverPopups) {
return "";
}
final IFile file = editor.getEditorInput().getAdapter(IFile.class);
final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
final Module tempModule = projectSourceParser.containedModule(file);
if (tempModule == null) {
return "";
}
Ttcn3HoverContent info = null;
final IdentifierFinderVisitor visitor = new IdentifierFinderVisitor(hoverRegion.getOffset());
tempModule.accept(visitor);
final Declaration declaration = visitor.getReferencedDeclaration();
if (declaration == null) {
return "";
}
final ICommentable commentable = declaration.getCommentable();
if (commentable == null) {
return "";
}
info = commentable.getHoverContent(editor);
if (info == null) {
return "";
}
return info;
}
/**
* Legacy interface method implemented for completeness
*
* getHoverInfo2 is used instead
*/
@Deprecated
@Override
public String getHoverInfo(final ITextViewer textViewer, final IRegion hoverRegion) {
return null;
}
@Override
public IInformationControlCreator getHoverControlCreator() {
return new IInformationControlCreator() {
@Override
public IInformationControl createInformationControl(Shell parent) {
return new Ttcn3HoverInfoControl(parent, EditorsUI.getTooltipAffordanceString());
}
};
}
}
......@@ -25,6 +25,7 @@ import org.eclipse.titan.designer.AST.Module;
import org.eclipse.titan.designer.declarationsearch.Declaration;
import org.eclipse.titan.designer.declarationsearch.IdentifierFinderVisitor;
import org.eclipse.titan.designer.editors.IEditorWithCarretOffset;
import org.eclipse.titan.designer.editors.asn1editor.ASN1Editor;
import org.eclipse.titan.designer.editors.controls.PeekSource;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverInfoControl;
......@@ -38,9 +39,14 @@ import org.eclipse.ui.PlatformUI;
/**
* Action code for peek declaration feature.
* This action is used for both {@link TTCN3Editor} and {@link TTCNPPEditor}
*
* This action is used for
* {@link TTCN3Editor}
* {@link TTCNPPEditor}
* {@link ASN1Editor}
*
* @author Miklos Magyari
* @author Adam Knapp
*
*/
public class PeekDeclaration extends AbstractHandler implements IEditorActionDelegate {
......@@ -69,8 +75,10 @@ public class PeekDeclaration extends AbstractHandler implements IEditorActionDel
IEditorPart targetEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
ISelection selection = TextSelection.emptySelection();
if (targetEditor == null || !(targetEditor instanceof TTCN3Editor) &&
!(targetEditor instanceof TTCNPPEditor)) {
if (targetEditor == null ||
!(targetEditor instanceof TTCN3Editor) &&
!(targetEditor instanceof TTCNPPEditor) &&
!(targetEditor instanceof ASN1Editor)) {
return;
}
......@@ -94,6 +102,10 @@ public class PeekDeclaration extends AbstractHandler implements IEditorActionDel
final IdentifierFinderVisitor visitor = new IdentifierFinderVisitor(offset);
module.accept(visitor);
final Declaration decl = visitor.getReferencedDeclaration();
if (decl == null) {
return;
}
Shell shell = targetEditor.getSite().getShell();
Ttcn3HoverInfoControl con = new Ttcn3HoverInfoControl(shell, null);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment